forked from teamnwah/openmw-tes3coop
Use the osgDB::ObjectCache in BulletShapeManager
This commit is contained in:
parent
6c1c653cba
commit
909c4d96b6
4 changed files with 34 additions and 11 deletions
|
@ -17,6 +17,14 @@ BulletShape::BulletShape()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BulletShape::BulletShape(const BulletShape ©, const osg::CopyOp ©op)
|
||||||
|
: mCollisionShape(duplicateCollisionShape(copy.mCollisionShape))
|
||||||
|
, mCollisionBoxHalfExtents(copy.mCollisionBoxHalfExtents)
|
||||||
|
, mCollisionBoxTranslate(copy.mCollisionBoxTranslate)
|
||||||
|
, mAnimatedShapes(copy.mAnimatedShapes)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
BulletShape::~BulletShape()
|
BulletShape::~BulletShape()
|
||||||
{
|
{
|
||||||
deleteShape(mCollisionShape);
|
deleteShape(mCollisionShape);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <osg/Referenced>
|
#include <osg/Object>
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
#include <osg/Vec3f>
|
#include <osg/Vec3f>
|
||||||
|
|
||||||
|
@ -15,12 +15,15 @@ namespace Resource
|
||||||
{
|
{
|
||||||
|
|
||||||
class BulletShapeInstance;
|
class BulletShapeInstance;
|
||||||
class BulletShape : public osg::Referenced
|
class BulletShape : public osg::Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BulletShape();
|
BulletShape();
|
||||||
|
BulletShape(const BulletShape& copy, const osg::CopyOp& copyop);
|
||||||
virtual ~BulletShape();
|
virtual ~BulletShape();
|
||||||
|
|
||||||
|
META_Object(Resource, BulletShape)
|
||||||
|
|
||||||
btCollisionShape* mCollisionShape;
|
btCollisionShape* mCollisionShape;
|
||||||
|
|
||||||
// Used for actors. Note, ideally actors would use a separate loader - as it is
|
// Used for actors. Note, ideally actors would use a separate loader - as it is
|
||||||
|
@ -42,6 +45,7 @@ namespace Resource
|
||||||
btCollisionShape* getCollisionShape();
|
btCollisionShape* getCollisionShape();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void deleteShape(btCollisionShape* shape);
|
void deleteShape(btCollisionShape* shape);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "bulletshape.hpp"
|
#include "bulletshape.hpp"
|
||||||
#include "scenemanager.hpp"
|
#include "scenemanager.hpp"
|
||||||
#include "niffilemanager.hpp"
|
#include "niffilemanager.hpp"
|
||||||
|
#include "objectcache.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace Resource
|
namespace Resource
|
||||||
|
@ -99,6 +100,7 @@ BulletShapeManager::BulletShapeManager(const VFS::Manager* vfs, SceneManager* sc
|
||||||
: mVFS(vfs)
|
: mVFS(vfs)
|
||||||
, mSceneManager(sceneMgr)
|
, mSceneManager(sceneMgr)
|
||||||
, mNifFileManager(nifFileManager)
|
, mNifFileManager(nifFileManager)
|
||||||
|
, mCache(new osgDB::ObjectCache)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -114,8 +116,10 @@ osg::ref_ptr<BulletShapeInstance> BulletShapeManager::createInstance(const std::
|
||||||
mVFS->normalizeFilename(normalized);
|
mVFS->normalizeFilename(normalized);
|
||||||
|
|
||||||
osg::ref_ptr<BulletShape> shape;
|
osg::ref_ptr<BulletShape> shape;
|
||||||
Index::iterator it = mIndex.find(normalized);
|
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(normalized);
|
||||||
if (it == mIndex.end())
|
if (obj)
|
||||||
|
shape = osg::ref_ptr<BulletShape>(static_cast<BulletShape*>(obj.get()));
|
||||||
|
else
|
||||||
{
|
{
|
||||||
size_t extPos = normalized.find_last_of('.');
|
size_t extPos = normalized.find_last_of('.');
|
||||||
std::string ext;
|
std::string ext;
|
||||||
|
@ -137,16 +141,19 @@ osg::ref_ptr<BulletShapeInstance> BulletShapeManager::createInstance(const std::
|
||||||
node->accept(visitor);
|
node->accept(visitor);
|
||||||
shape = visitor.getShape();
|
shape = visitor.getShape();
|
||||||
if (!shape)
|
if (!shape)
|
||||||
|
{
|
||||||
|
mCache->addEntryToObjectCache(normalized, NULL);
|
||||||
return osg::ref_ptr<BulletShapeInstance>();
|
return osg::ref_ptr<BulletShapeInstance>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mIndex[normalized] = shape;
|
mCache->addEntryToObjectCache(normalized, shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shape)
|
||||||
|
return shape->makeInstance();
|
||||||
else
|
else
|
||||||
shape = it->second;
|
return osg::ref_ptr<BulletShapeInstance>();
|
||||||
|
|
||||||
osg::ref_ptr<BulletShapeInstance> instance = shape->makeInstance();
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,11 @@ namespace VFS
|
||||||
class Manager;
|
class Manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace osgDB
|
||||||
|
{
|
||||||
|
class ObjectCache;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Resource
|
namespace Resource
|
||||||
{
|
{
|
||||||
class SceneManager;
|
class SceneManager;
|
||||||
|
@ -34,8 +39,7 @@ namespace Resource
|
||||||
SceneManager* mSceneManager;
|
SceneManager* mSceneManager;
|
||||||
NifFileManager* mNifFileManager;
|
NifFileManager* mNifFileManager;
|
||||||
|
|
||||||
typedef std::map<std::string, osg::ref_ptr<BulletShape> > Index;
|
osg::ref_ptr<osgDB::ObjectCache> mCache;
|
||||||
Index mIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue