Use the osgDB::ObjectCache in BulletShapeManager

coverity_scan
scrawl 9 years ago
parent 6c1c653cba
commit 909c4d96b6

@ -17,6 +17,14 @@ BulletShape::BulletShape()
}
BulletShape::BulletShape(const BulletShape &copy, const osg::CopyOp &copyop)
: mCollisionShape(duplicateCollisionShape(copy.mCollisionShape))
, mCollisionBoxHalfExtents(copy.mCollisionBoxHalfExtents)
, mCollisionBoxTranslate(copy.mCollisionBoxTranslate)
, mAnimatedShapes(copy.mAnimatedShapes)
{
}
BulletShape::~BulletShape()
{
deleteShape(mCollisionShape);

@ -3,7 +3,7 @@
#include <map>
#include <osg/Referenced>
#include <osg/Object>
#include <osg/ref_ptr>
#include <osg/Vec3f>
@ -15,12 +15,15 @@ namespace Resource
{
class BulletShapeInstance;
class BulletShape : public osg::Referenced
class BulletShape : public osg::Object
{
public:
BulletShape();
BulletShape(const BulletShape& copy, const osg::CopyOp& copyop);
virtual ~BulletShape();
META_Object(Resource, BulletShape)
btCollisionShape* mCollisionShape;
// Used for actors. Note, ideally actors would use a separate loader - as it is
@ -42,6 +45,7 @@ namespace Resource
btCollisionShape* getCollisionShape();
private:
void deleteShape(btCollisionShape* shape);
};

@ -13,6 +13,7 @@
#include "bulletshape.hpp"
#include "scenemanager.hpp"
#include "niffilemanager.hpp"
#include "objectcache.hpp"
namespace Resource
@ -99,6 +100,7 @@ BulletShapeManager::BulletShapeManager(const VFS::Manager* vfs, SceneManager* sc
: mVFS(vfs)
, mSceneManager(sceneMgr)
, mNifFileManager(nifFileManager)
, mCache(new osgDB::ObjectCache)
{
}
@ -114,8 +116,10 @@ osg::ref_ptr<BulletShapeInstance> BulletShapeManager::createInstance(const std::
mVFS->normalizeFilename(normalized);
osg::ref_ptr<BulletShape> shape;
Index::iterator it = mIndex.find(normalized);
if (it == mIndex.end())
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
if (obj)
shape = osg::ref_ptr<BulletShape>(static_cast<BulletShape*>(obj.get()));
else
{
size_t extPos = normalized.find_last_of('.');
std::string ext;
@ -137,16 +141,19 @@ osg::ref_ptr<BulletShapeInstance> BulletShapeManager::createInstance(const std::
node->accept(visitor);
shape = visitor.getShape();
if (!shape)
{
mCache->addEntryToObjectCache(normalized, NULL);
return osg::ref_ptr<BulletShapeInstance>();
}
}
mIndex[normalized] = shape;
mCache->addEntryToObjectCache(normalized, shape);
}
else
shape = it->second;
osg::ref_ptr<BulletShapeInstance> instance = shape->makeInstance();
return instance;
if (shape)
return shape->makeInstance();
else
return osg::ref_ptr<BulletShapeInstance>();
}
}

@ -13,6 +13,11 @@ namespace VFS
class Manager;
}
namespace osgDB
{
class ObjectCache;
}
namespace Resource
{
class SceneManager;
@ -34,8 +39,7 @@ namespace Resource
SceneManager* mSceneManager;
NifFileManager* mNifFileManager;
typedef std::map<std::string, osg::ref_ptr<BulletShape> > Index;
Index mIndex;
osg::ref_ptr<osgDB::ObjectCache> mCache;
};
}

Loading…
Cancel
Save