1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-01 06:39:43 +00:00

Use unique_ptr to manage Bone lifetime

This commit is contained in:
elsid 2022-07-17 12:12:17 +02:00
parent f393fee9d1
commit e4f599575e
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
2 changed files with 6 additions and 17 deletions

View file

@ -80,15 +80,16 @@ Bone* Skeleton::getBone(const std::string &name)
{
if (bone->mChildren[i]->mNode == matrixTransform)
{
child = bone->mChildren[i];
child = bone->mChildren[i].get();
break;
}
}
if (!child)
if (child == nullptr)
{
child = new Bone;
bone->mChildren.push_back(child);
auto childBone = std::make_unique<Bone>();
child = childBone.get();
bone->mChildren.push_back(std::move(childBone));
mNeedToUpdateBoneMatrices = true;
}
bone = child;
@ -165,13 +166,6 @@ Bone::Bone()
{
}
Bone::~Bone()
{
for (unsigned int i=0; i<mChildren.size(); ++i)
delete mChildren[i];
mChildren.clear();
}
void Bone::update(const osg::Matrixf* parentMatrixInSkeletonSpace)
{
if (!mNode)

View file

@ -15,20 +15,15 @@ namespace SceneUtil
{
public:
Bone();
~Bone();
osg::Matrixf mMatrixInSkeletonSpace;
osg::MatrixTransform* mNode;
std::vector<Bone*> mChildren;
std::vector<std::unique_ptr<Bone>> mChildren;
/// Update the skeleton-space matrix of this bone and all its children.
void update(const osg::Matrixf* parentMatrixInSkeletonSpace);
private:
Bone(const Bone&);
void operator=(const Bone&);
};
/// @brief Handles the bone matrices for any number of child RigGeometries.