mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-08 09:37:53 +00:00
Avoid using a specific type for stored ref_ptr to extend lifetime
This commit is contained in:
parent
b770373491
commit
c91ef34a70
@ -23,35 +23,35 @@ namespace DetourNavigator
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const Resource::BulletShapeInstance>& instance,
|
||||
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder,
|
||||
const btCompoundShape& shape, const AreaType areaType)
|
||||
{
|
||||
std::vector<RecastMeshObject> result;
|
||||
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
|
||||
{
|
||||
const CollisionShape collisionShape {instance, *shape.getChildShape(i)};
|
||||
const CollisionShape collisionShape {holder, *shape.getChildShape(i)};
|
||||
result.emplace_back(collisionShape, shape.getChildTransform(i), areaType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const Resource::BulletShapeInstance>& instance,
|
||||
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder,
|
||||
const btCollisionShape& shape, const AreaType areaType)
|
||||
{
|
||||
if (shape.isCompound())
|
||||
return makeChildrenObjects(std::move(instance), static_cast<const btCompoundShape&>(shape), areaType);
|
||||
return makeChildrenObjects(holder, static_cast<const btCompoundShape&>(shape), areaType);
|
||||
return std::vector<RecastMeshObject>();
|
||||
}
|
||||
}
|
||||
|
||||
RecastMeshObject::RecastMeshObject(const CollisionShape& shape, const btTransform& transform,
|
||||
const AreaType areaType)
|
||||
: mShapeInstance(shape.getShapeInstance())
|
||||
: mHolder(shape.getHolder())
|
||||
, mShape(shape.getShape())
|
||||
, mTransform(transform)
|
||||
, mAreaType(areaType)
|
||||
, mLocalScaling(mShape.get().getLocalScaling())
|
||||
, mChildren(makeChildrenObjects(mShapeInstance, mShape.get(), mAreaType))
|
||||
, mChildren(makeChildrenObjects(mHolder, mShape.get(), mAreaType))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,10 @@
|
||||
|
||||
#include "areatype.hpp"
|
||||
|
||||
#include <components/resource/bulletshape.hpp>
|
||||
|
||||
#include <LinearMath/btTransform.h>
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Referenced>
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
@ -20,16 +19,16 @@ namespace DetourNavigator
|
||||
class CollisionShape
|
||||
{
|
||||
public:
|
||||
CollisionShape(osg::ref_ptr<const Resource::BulletShapeInstance> instance, const btCollisionShape& shape)
|
||||
: mShapeInstance(std::move(instance))
|
||||
CollisionShape(osg::ref_ptr<const osg::Referenced> holder, const btCollisionShape& shape)
|
||||
: mHolder(std::move(holder))
|
||||
, mShape(shape)
|
||||
{}
|
||||
|
||||
const osg::ref_ptr<const Resource::BulletShapeInstance>& getShapeInstance() const { return mShapeInstance; }
|
||||
const osg::ref_ptr<const osg::Referenced>& getHolder() const { return mHolder; }
|
||||
const btCollisionShape& getShape() const { return mShape; }
|
||||
|
||||
private:
|
||||
osg::ref_ptr<const Resource::BulletShapeInstance> mShapeInstance;
|
||||
osg::ref_ptr<const osg::Referenced> mHolder;
|
||||
std::reference_wrapper<const btCollisionShape> mShape;
|
||||
};
|
||||
|
||||
@ -56,7 +55,7 @@ namespace DetourNavigator
|
||||
}
|
||||
|
||||
private:
|
||||
osg::ref_ptr<const Resource::BulletShapeInstance> mShapeInstance;
|
||||
osg::ref_ptr<const osg::Referenced> mHolder;
|
||||
std::reference_wrapper<const btCollisionShape> mShape;
|
||||
btTransform mTransform;
|
||||
AreaType mAreaType;
|
||||
|
Loading…
Reference in New Issue
Block a user