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