Use the UnrefQueue to delete BulletShapeInstances

This commit is contained in:
scrawl 2016-02-09 19:04:59 +01:00
parent afe533e670
commit 1457a0de78
5 changed files with 29 additions and 2 deletions

View file

@ -22,6 +22,7 @@
#include <components/esm/loadgmst.hpp> #include <components/esm/loadgmst.hpp>
#include <components/sceneutil/positionattitudetransform.hpp> #include <components/sceneutil/positionattitudetransform.hpp>
#include <components/sceneutil/unrefqueue.hpp>
#include <components/nifosg/particle.hpp> // FindRecIndexVisitor #include <components/nifosg/particle.hpp> // FindRecIndexVisitor
@ -533,6 +534,11 @@ namespace MWPhysics
setOrigin(btVector3(pos[0], pos[1], pos[2])); setOrigin(btVector3(pos[0], pos[1], pos[2]));
} }
const Resource::BulletShapeInstance* getShapeInstance() const
{
return mShapeInstance.get();
}
void setScale(float scale) void setScale(float scale)
{ {
mShapeInstance->getCollisionShape()->setLocalScaling(btVector3(scale,scale,scale)); mShapeInstance->getCollisionShape()->setLocalScaling(btVector3(scale,scale,scale));
@ -690,6 +696,11 @@ namespace MWPhysics
delete mBroadphase; delete mBroadphase;
} }
void PhysicsSystem::setUnrefQueue(SceneUtil::UnrefQueue *unrefQueue)
{
mUnrefQueue = unrefQueue;
}
Resource::BulletShapeManager *PhysicsSystem::getShapeManager() Resource::BulletShapeManager *PhysicsSystem::getShapeManager()
{ {
return mShapeManager.get(); return mShapeManager.get();
@ -1109,6 +1120,9 @@ namespace MWPhysics
{ {
mCollisionWorld->removeCollisionObject(found->second->getCollisionObject()); mCollisionWorld->removeCollisionObject(found->second->getCollisionObject());
if (mUnrefQueue.get())
mUnrefQueue->push(found->second->getShapeInstance());
mAnimatedObjects.erase(found->second); mAnimatedObjects.erase(found->second);
delete found->second; delete found->second;

View file

@ -25,11 +25,12 @@ namespace MWRender
namespace Resource namespace Resource
{ {
class BulletShapeManager; class BulletShapeManager;
class ResourceSystem;
} }
namespace Resource namespace SceneUtil
{ {
class ResourceSystem; class UnrefQueue;
} }
class btCollisionWorld; class btCollisionWorld;
@ -53,6 +54,8 @@ namespace MWPhysics
PhysicsSystem (Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Group> parentNode); PhysicsSystem (Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Group> parentNode);
~PhysicsSystem (); ~PhysicsSystem ();
void setUnrefQueue(SceneUtil::UnrefQueue* unrefQueue);
Resource::BulletShapeManager* getShapeManager(); Resource::BulletShapeManager* getShapeManager();
void enableWater(float height); void enableWater(float height);
@ -165,6 +168,8 @@ namespace MWPhysics
void updateWater(); void updateWater();
osg::ref_ptr<SceneUtil::UnrefQueue> mUnrefQueue;
btBroadphaseInterface* mBroadphase; btBroadphaseInterface* mBroadphase;
btDefaultCollisionConfiguration* mCollisionConfiguration; btDefaultCollisionConfiguration* mCollisionConfiguration;
btCollisionDispatcher* mDispatcher; btCollisionDispatcher* mDispatcher;

View file

@ -263,6 +263,11 @@ namespace MWRender
return mWorkQueue.get(); return mWorkQueue.get();
} }
SceneUtil::UnrefQueue *RenderingManager::getUnrefQueue()
{
return mUnrefQueue.get();
}
void RenderingManager::preloadCommonAssets() void RenderingManager::preloadCommonAssets()
{ {
osg::ref_ptr<PreloadCommonAssetsWorkItem> workItem (new PreloadCommonAssetsWorkItem(mResourceSystem)); osg::ref_ptr<PreloadCommonAssetsWorkItem> workItem (new PreloadCommonAssetsWorkItem(mResourceSystem));

View file

@ -72,6 +72,7 @@ namespace MWRender
Resource::ResourceSystem* getResourceSystem(); Resource::ResourceSystem* getResourceSystem();
SceneUtil::WorkQueue* getWorkQueue(); SceneUtil::WorkQueue* getWorkQueue();
SceneUtil::UnrefQueue* getUnrefQueue();
void preloadCommonAssets(); void preloadCommonAssets();

View file

@ -466,6 +466,8 @@ namespace MWWorld
mPreloader.reset(new CellPreloader(rendering.getResourceSystem(), physics->getShapeManager())); mPreloader.reset(new CellPreloader(rendering.getResourceSystem(), physics->getShapeManager()));
mPreloader->setWorkQueue(mRendering.getWorkQueue()); mPreloader->setWorkQueue(mRendering.getWorkQueue());
mPhysics->setUnrefQueue(rendering.getUnrefQueue());
float cacheExpiryDelay = Settings::Manager::getFloat("cache expiry delay", "Cells"); float cacheExpiryDelay = Settings::Manager::getFloat("cache expiry delay", "Cells");
rendering.getResourceSystem()->setExpiryDelay(cacheExpiryDelay); rendering.getResourceSystem()->setExpiryDelay(cacheExpiryDelay);
mPreloader->setExpiryDelay(cacheExpiryDelay); mPreloader->setExpiryDelay(cacheExpiryDelay);