From fc9a405dc5897f335c5317b36296cbffa2cf57b0 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 30 Oct 2021 03:16:21 +0200 Subject: [PATCH] Make BulletShape::makeInstance free function --- components/resource/bulletshape.cpp | 5 ++--- components/resource/bulletshape.hpp | 5 ++--- components/resource/bulletshapemanager.cpp | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/components/resource/bulletshape.cpp b/components/resource/bulletshape.cpp index e52e68ca07..4b074ee146 100644 --- a/components/resource/bulletshape.cpp +++ b/components/resource/bulletshape.cpp @@ -99,10 +99,9 @@ bool BulletShape::isAnimated() const return !mAnimatedShapes.empty(); } -osg::ref_ptr BulletShape::makeInstance() const +osg::ref_ptr makeInstance(osg::ref_ptr source) { - osg::ref_ptr instance (new BulletShapeInstance(this)); - return instance; + return {new BulletShapeInstance(std::move(source))}; } BulletShapeInstance::BulletShapeInstance(osg::ref_ptr source) diff --git a/components/resource/bulletshape.hpp b/components/resource/bulletshape.hpp index 369aed18a0..bf249cb364 100644 --- a/components/resource/bulletshape.hpp +++ b/components/resource/bulletshape.hpp @@ -21,7 +21,6 @@ namespace Resource using CollisionShapePtr = std::unique_ptr; - class BulletShapeInstance; class BulletShape : public osg::Object { public: @@ -48,8 +47,6 @@ namespace Resource // we store the node's record index mapped to the child index of the shape in the btCompoundShape. std::map mAnimatedShapes; - osg::ref_ptr makeInstance() const; - btCollisionShape* getCollisionShape() const; btCollisionShape* getAvoidCollisionShape() const; @@ -71,6 +68,8 @@ namespace Resource osg::ref_ptr mSource; }; + osg::ref_ptr makeInstance(osg::ref_ptr source); + // Subclass btBhvTriangleMeshShape to auto-delete the meshInterface struct TriangleMeshShape : public btBvhTriangleMeshShape { diff --git a/components/resource/bulletshapemanager.cpp b/components/resource/bulletshapemanager.cpp index cde069837a..ae6f3659a5 100644 --- a/components/resource/bulletshapemanager.cpp +++ b/components/resource/bulletshapemanager.cpp @@ -193,9 +193,8 @@ osg::ref_ptr BulletShapeManager::createInstance(const std:: { osg::ref_ptr shape = getShape(name); if (shape) - return shape->makeInstance(); - else - return osg::ref_ptr(); + return makeInstance(std::move(shape)); + return osg::ref_ptr(); } void BulletShapeManager::updateCache(double referenceTime)