From 9e6832c6a982ca751db5cef2f33225b59e123a91 Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Tue, 20 Jul 2021 13:03:56 -0700 Subject: [PATCH] Remove `BaseObject` as a base class from `NodeGroup` Nothing uses the use count that the `BaseObject` base class provides, so there's no reason to keep it. Signed-off-by: Chris Burel --- .../Source/NodeGroupCommands.cpp | 31 +++------- .../CommandSystem/Source/NodeGroupCommands.h | 2 +- .../EMotionFX/Code/EMotionFX/Source/Actor.cpp | 6 +- .../Source/Importer/ChunkProcessors.cpp | 2 +- .../Code/EMotionFX/Source/NodeGroup.cpp | 57 ++---------------- .../Code/EMotionFX/Source/NodeGroup.h | 58 ++----------------- 6 files changed, 21 insertions(+), 135 deletions(-) diff --git a/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.cpp b/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.cpp index fe4a3e1ca9..229ad34f19 100644 --- a/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.cpp @@ -24,7 +24,6 @@ namespace CommandSystem // constructor CommandAdjustNodeGroup::CommandAdjustNodeGroup(MCore::Command* orgCommand) : MCore::Command("AdjustNodeGroup", orgCommand) - , mOldNodeGroup(nullptr) { } @@ -32,10 +31,7 @@ namespace CommandSystem // destructor CommandAdjustNodeGroup::~CommandAdjustNodeGroup() { - if (mOldNodeGroup) - { - mOldNodeGroup->Destroy(); - } + delete mOldNodeGroup; } @@ -65,10 +61,7 @@ namespace CommandSystem } // copy the old node group for undo - if (mOldNodeGroup) - { - mOldNodeGroup->Destroy(); - } + delete mOldNodeGroup; mOldNodeGroup = aznew EMotionFX::NodeGroup(*nodeGroup); @@ -235,11 +228,8 @@ namespace CommandSystem } } - // delete the old node group - if (mOldNodeGroup) - { - mOldNodeGroup->Destroy(); - } + delete mOldNodeGroup; + mOldNodeGroup = nullptr; // set the dirty flag back to the old value @@ -304,7 +294,7 @@ namespace CommandSystem } // add new node group to the actor - EMotionFX::NodeGroup* nodeGroup = EMotionFX::NodeGroup::Create(name.c_str()); + EMotionFX::NodeGroup* nodeGroup = aznew EMotionFX::NodeGroup(name); actor->AddNodeGroup(nodeGroup); // save the current dirty flag and tell the actor that something got changed @@ -374,10 +364,7 @@ namespace CommandSystem // destructor CommandRemoveNodeGroup::~CommandRemoveNodeGroup() { - if (mOldNodeGroup) - { - mOldNodeGroup->Destroy(); - } + delete mOldNodeGroup; } @@ -407,11 +394,7 @@ namespace CommandSystem } // copy the old node group for undo - if (mOldNodeGroup) - { - mOldNodeGroup->Destroy(); - } - + delete mOldNodeGroup; mOldNodeGroup = aznew EMotionFX::NodeGroup(*nodeGroup); // remove the node group diff --git a/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.h b/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.h index e87ce2d62d..1931b6842e 100644 --- a/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.h +++ b/Gems/EMotionFX/Code/EMotionFX/CommandSystem/Source/NodeGroupCommands.h @@ -22,7 +22,7 @@ namespace CommandSystem // adjust a node group MCORE_DEFINECOMMAND_START(CommandAdjustNodeGroup, "Adjust node group", true) bool mOldDirtyFlag; - EMotionFX::NodeGroup* mOldNodeGroup; + EMotionFX::NodeGroup* mOldNodeGroup = nullptr; MCORE_DEFINECOMMAND_END diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/Actor.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/Actor.cpp index 973d8eb460..c6b210da58 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/Actor.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/Actor.cpp @@ -1015,7 +1015,7 @@ namespace EMotionFX const uint32 numGroups = mNodeGroups.GetLength(); for (uint32 i = 0; i < numGroups; ++i) { - mNodeGroups[i]->Destroy(); + delete mNodeGroups[i]; } mNodeGroups.Clear(); } @@ -2085,7 +2085,7 @@ namespace EMotionFX { if (delFromMem) { - mNodeGroups[index]->Destroy(); + delete mNodeGroups[index]; } mNodeGroups.Remove(index); @@ -2097,7 +2097,7 @@ namespace EMotionFX mNodeGroups.RemoveByValue(group); if (delFromMem) { - group->Destroy(); + delete group; } } diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/Importer/ChunkProcessors.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/Importer/ChunkProcessors.cpp index 7e7a9ae1c2..3cec3b599c 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/Importer/ChunkProcessors.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/Importer/ChunkProcessors.cpp @@ -1469,7 +1469,7 @@ namespace EMotionFX } // create the new group inside the actor - NodeGroup* newGroup = NodeGroup::Create(groupName, fileGroup.mNumNodes, fileGroup.mDisabledOnDefault ? false : true); + NodeGroup* newGroup = aznew NodeGroup(groupName, fileGroup.mNumNodes, fileGroup.mDisabledOnDefault ? false : true); // read the node numbers uint16 nodeIndex; diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.cpp index d73926a166..e22ad5f064 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.cpp @@ -17,63 +17,16 @@ namespace EMotionFX AZ_CLASS_ALLOCATOR_IMPL(NodeGroup, NodeAllocator, 0) - // default constructor - NodeGroup::NodeGroup() - : BaseObject() + NodeGroup::NodeGroup(const AZStd::string& groupName, uint16 numNodes, bool enabledOnDefault) + : mName(groupName) + , mNodes(numNodes) + , mEnabledOnDefault(enabledOnDefault) { - SetIsEnabledOnDefault(true); - } - - - // extended constructor - NodeGroup::NodeGroup(const char* groupName, bool enabledOnDefault) - : BaseObject() - { - SetName(groupName); - SetIsEnabledOnDefault(enabledOnDefault); - } - - - // another extended constructor - NodeGroup::NodeGroup(const char* groupName, uint16 numNodes, bool enabledOnDefault) - : BaseObject() - { - SetName(groupName); - SetNumNodes(numNodes); - SetIsEnabledOnDefault(enabledOnDefault); - } - - - // destructor - NodeGroup::~NodeGroup() - { - mNodes.Clear(); - } - - - // create - NodeGroup* NodeGroup::Create() - { - return aznew NodeGroup(); - } - - - // create - NodeGroup* NodeGroup::Create(const char* groupName, bool enabledOnDefault) - { - return aznew NodeGroup(groupName, enabledOnDefault); - } - - - // create - NodeGroup* NodeGroup::Create(const char* groupName, uint16 numNodes, bool enabledOnDefault) - { - return aznew NodeGroup(groupName, numNodes, enabledOnDefault); } // set the name of the group - void NodeGroup::SetName(const char* groupName) + void NodeGroup::SetName(const AZStd::string& groupName) { mName = groupName; } diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.h b/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.h index c6dc86273b..dfe876c86a 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.h +++ b/Gems/EMotionFX/Code/EMotionFX/Source/NodeGroup.h @@ -30,38 +30,19 @@ namespace EMotionFX * might contain incorrect or even uninitialized data. */ class EMFX_API NodeGroup - : public BaseObject { public: AZ_CLASS_ALLOCATOR_DECL - /** - * The default creation method. - * This does not assign a name and there will be nodes inside this group on default. - * Also the default enabled state is set to true. - */ - static NodeGroup* Create(); - - /** - * Extended creation. - * @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor. - * @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default. - */ - static NodeGroup* Create(const char* groupName, bool enabledOnDefault = true); - /** - * Another extended constructor. - * @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor. - * @param numNodes The number of nodes to create inside the group. This will have all uninitialized values for the node indices in the group, so be sure that you - * set them all to some valid node index using the NodeGroup::SetNode(...) method. This method automatically calls the SetNumNodes(...) method. - * @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default. - */ - static NodeGroup* Create(const char* groupName, uint16 numNodes, bool enabledOnDefault = true); + NodeGroup(const AZStd::string& groupName = {}, uint16 numNodes = 0, bool enabledOnDefault = true); + NodeGroup(const NodeGroup& aOther); + NodeGroup& operator=(const NodeGroup& aOther); /** * Set the name of the group. Please keep in mind that group names must be unique inside the Actor objects. So you should not have two or more groups with the same name. * @param groupName The name of the group. */ - void SetName(const char* groupName); + void SetName(const AZStd::string& groupName); /** * Get the name of the group as null terminated character buffer. @@ -172,37 +153,6 @@ namespace EMotionFX */ void SetIsEnabledOnDefault(bool enabledOnDefault); - /** - * The default constructor. - * This does not assign a name and there will be nodes inside this group on default. - * Also the default enabled state is set to true. - */ - NodeGroup(); - - /** - * Extended constructor. - * @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor. - * @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default. - */ - NodeGroup(const char* groupName, bool enabledOnDefault = true); - - /** - * Another extended constructor. - * @param groupName The name of the group. Please keep in mind that it is not allowed to have two groups with the same name inside an Actor. - * @param numNodes The number of nodes to create inside the group. This will have all uninitialized values for the node indices in the group, so be sure that you - * set them all to some valid node index using the NodeGroup::SetNode(...) method. This method automatically calls the SetNumNodes(...) method. - * @param enabledOnDefault Set to true (default) when the nodes inside this group should be enabled on default. - */ - NodeGroup(const char* groupName, uint16 numNodes, bool enabledOnDefault = true); - - /** - * The destructor. - */ - ~NodeGroup(); - - NodeGroup(const NodeGroup& aOther); - NodeGroup& operator=(const NodeGroup& aOther); - private: AZStd::string mName; /**< The name of the group. */ MCore::SmallArray mNodes; /**< The node index numbers that are inside this group. */