Remove old BulletShapeManager

c++11
scrawl 10 years ago
parent 0da1e0e905
commit 48ffeab191

@ -533,9 +533,7 @@ namespace MWWorld
PhysicsSystem::PhysicsSystem(osg::ref_ptr<osg::Group> parentNode) :
mEngine(0), mTimeAccum(0.0f), mWaterEnabled(false), mWaterHeight(0), mDebugDrawEnabled(false), mParentNode(parentNode)
{
// Create physics. shapeLoader is deleted by the physic engine
//NifBullet::ManualBulletShapeLoader* shapeLoader = new NifBullet::ManualBulletShapeLoader();
mEngine = new OEngine::Physic::PhysicEngine(0);//shapeLoader);
mEngine = new OEngine::Physic::PhysicEngine;
}
PhysicsSystem::~PhysicsSystem()
@ -543,7 +541,6 @@ namespace MWWorld
if (mWaterCollisionObject.get())
mEngine->mDynamicsWorld->removeCollisionObject(mWaterCollisionObject.get());
delete mEngine;
//delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
}
bool PhysicsSystem::toggleDebugRendering()

@ -168,6 +168,10 @@ class Drawable : public osg::Drawable {
glDrawArrays(GL_TRIANGLES, 0, batch.mVertexCount);
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
state->unbindVertexBufferObject();
state->dirtyAllVertexArrays();
state->disableAllVertexArrays();

@ -323,15 +323,6 @@ void ManualBulletShapeLoader::handleNiTriShape(const Nif::NiTriShape *shape, int
}
}
void ManualBulletShapeLoader::load(const std::string &name,const std::string &group)
{
// Check if the resource already exists
Ogre::ResourcePtr ptr = OEngine::Physic::BulletShapeManager::getSingleton().getByName(name, group);
if (!ptr.isNull())
return;
OEngine::Physic::BulletShapeManager::getSingleton().create(name,group,true,this);
}
bool findBoundingBox (const Nif::Node* node, Ogre::Vector3& halfExtents, Ogre::Vector3& translation, Ogre::Quaternion& orientation)
{
if(node->hasBounds)

@ -66,7 +66,7 @@ struct TriangleMeshShape : public btBvhTriangleMeshShape
/**
*Load bulletShape from NIF files.
*/
class ManualBulletShapeLoader : public OEngine::Physic::BulletShapeLoader
class ManualBulletShapeLoader
{
public:
ManualBulletShapeLoader(bool showMarkers=false)
@ -96,13 +96,6 @@ public:
*/
void loadResource(Ogre::Resource *resource);
/**
*This function load a new bulletShape from a NIF file into the BulletShapeManager.
*When the file is loaded, you can then use BulletShapeManager::getByName() to retrive the bulletShape.
*Warning: this function will just crash if the resourceGroup doesn't exist!
*/
void load(const std::string &name,const std::string &group);
private:
btVector3 getbtVector(Ogre::Vector3 const &v);

@ -62,93 +62,5 @@ size_t BulletShape::calculateSize() const
return 1;
}
//=============================================================================================================
BulletShapeManager *BulletShapeManager::sThis = 0;
BulletShapeManager *BulletShapeManager::getSingletonPtr()
{
return sThis;
}
BulletShapeManager &BulletShapeManager::getSingleton()
{
assert(sThis);
return(*sThis);
}
BulletShapeManager::BulletShapeManager()
{
assert(!sThis);
sThis = this;
mResourceType = "BulletShape";
// low, because it will likely reference other resources
mLoadOrder = 30.0f;
// this is how we register the ResourceManager with OGRE
Ogre::ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
}
BulletShapeManager::~BulletShapeManager()
{
// and this is how we unregister it
Ogre::ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
sThis = 0;
}
BulletShapePtr BulletShapeManager::getByName(const Ogre::String& name, const Ogre::String& groupName)
{
return getResourceByName(name, groupName).staticCast<BulletShape>();
}
BulletShapePtr BulletShapeManager::create (const Ogre::String& name, const Ogre::String& group,
bool isManual, Ogre::ManualResourceLoader* loader,
const Ogre::NameValuePairList* createParams)
{
return createResource(name,group,isManual,loader,createParams).staticCast<BulletShape>();
}
Ogre::ResourcePtr BulletShapeManager::load(const Ogre::String &name, const Ogre::String &group,
bool isManual, Ogre::ManualResourceLoader *loader, const Ogre::NameValuePairList *loadParams,
bool backgroundThread)
{
return this->load(name, group);
}
BulletShapePtr BulletShapeManager::load(const Ogre::String &name, const Ogre::String &group)
{
BulletShapePtr textf = getByName(name);
if (textf.isNull())
textf = create(name, group);
textf->load();
return textf;
}
Ogre::Resource *BulletShapeManager::createImpl(const Ogre::String &name, Ogre::ResourceHandle handle,
const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader,
const Ogre::NameValuePairList *createParams)
{
BulletShape* res = new BulletShape(this, name, handle, group, isManual, loader);
//if(isManual)
//{
//loader->loadResource(res);
//}
return res;
}
//====================================================================
void BulletShapeLoader::loadResource(Ogre::Resource *resource)
{}
void BulletShapeLoader::load(const std::string &name,const std::string &group)
{}
}
}

@ -53,84 +53,6 @@ public:
*/
typedef Ogre::SharedPtr<BulletShape> BulletShapePtr;
/**
*Hold any BulletShape that was created by the ManualBulletShapeLoader.
*
*To get a bulletShape, you must load it first.
*First, create a manualBulletShapeLoader. Then call ManualBulletShapeManager->load(). This create an "empty" resource.
*Then use BulletShapeManager->load(). This will fill the resource with the required info.
*To get the resource,use BulletShapeManager::getByName.
*When you use the resource no more, just use BulletShapeManager->unload(). It won't completly delete the resource, but it will
*"empty" it.This allow a better management of memory: when you are leaving a cell, just unload every useless shape.
*
*Alternatively, you can call BulletShape->load() in order to actually load the resource.
*When you are finished with it, just call BulletShape->unload().
*
*IMO: prefere the first methode, i am not completly sure about the 2nd.
*
*Important Note: i have no idea of what happen if you try to load two time the same resource without unloading.
*It won't crash, but it might lead to memory leaks(I don't know how Ogre handle this). So don't do it!
*/
class BulletShapeManager : public Ogre::ResourceManager
{
protected:
// must implement this from ResourceManager's interface
Ogre::Resource *createImpl(const Ogre::String &name, Ogre::ResourceHandle handle,
const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader,
const Ogre::NameValuePairList *createParams);
static BulletShapeManager *sThis;
private:
/** \brief Explicit private copy constructor. This is a forbidden operation.*/
BulletShapeManager(const BulletShapeManager &);
/** \brief Private operator= . This is a forbidden operation. */
BulletShapeManager& operator=(const BulletShapeManager &);
// Not intended to be used, declared here to keep the compiler from complaining
// about hidden virtual methods.
virtual Ogre::ResourcePtr load(const Ogre::String &name, const Ogre::String &group,
bool isManual, Ogre::ManualResourceLoader *loader, const Ogre::NameValuePairList *loadParams,
bool backgroundThread);
public:
BulletShapeManager();
virtual ~BulletShapeManager();
/// Get a resource by name
/// @see ResourceManager::getByName
BulletShapePtr getByName(const Ogre::String& name,
const Ogre::String& groupName = Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
/// Create a new shape
/// @see ResourceManager::createResource
BulletShapePtr create (const Ogre::String& name, const Ogre::String& group,
bool isManual = false, Ogre::ManualResourceLoader* loader = 0,
const Ogre::NameValuePairList* createParams = 0);
virtual BulletShapePtr load(const Ogre::String &name, const Ogre::String &group);
static BulletShapeManager &getSingleton();
static BulletShapeManager *getSingletonPtr();
};
class BulletShapeLoader : public Ogre::ManualResourceLoader
{
public:
BulletShapeLoader(){};
virtual ~BulletShapeLoader() {}
virtual void loadResource(Ogre::Resource *resource);
virtual void load(const std::string &name,const std::string &group);
};
}
}

@ -235,27 +235,25 @@ namespace Physic
PhysicEngine::PhysicEngine(BulletShapeLoader* shapeLoader)
PhysicEngine::PhysicEngine()
{
// Set up the collision configuration and dispatcher
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
mCollisionConfiguration = new btDefaultCollisionConfiguration();
mDispatcher = new btCollisionDispatcher(mCollisionConfiguration);
// The actual physics solver
solver = new btSequentialImpulseConstraintSolver;
mSolver = new btSequentialImpulseConstraintSolver;
broadphase = new btDbvtBroadphase();
mBroadphase = new btDbvtBroadphase();
// The world.
mDynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
mDynamicsWorld = new btDiscreteDynamicsWorld(mDispatcher,mBroadphase,mSolver,mCollisionConfiguration);
// Don't update AABBs of all objects every frame. Most objects in MW are static, so we don't need this.
// Should a "static" object ever be moved, we have to update its AABB manually using DynamicsWorld::updateSingleAabb.
mDynamicsWorld->setForceUpdateAllAabbs(false);
mDynamicsWorld->setGravity(btVector3(0,0,-10));
mShapeLoader = shapeLoader;
}
PhysicEngine::~PhysicEngine()
@ -294,11 +292,10 @@ namespace Physic
}
delete mDynamicsWorld;
delete solver;
delete collisionConfiguration;
delete dispatcher;
delete broadphase;
delete mShapeLoader;
delete mSolver;
delete mCollisionConfiguration;
delete mDispatcher;
delete mBroadphase;
}
void PhysicEngine::addHeightField(float* heights,
@ -382,9 +379,8 @@ namespace Physic
std::string outputstring = mesh + sid;
//get the shape from the .nif
mShapeLoader->load(outputstring,"General");
BulletShapeManager::getSingletonPtr()->load(outputstring,"General");
BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General");
//mShapeLoader->load(outputstring,"General");
//BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General");
//adjustRigidBody(body, position, rotation, shape->mBoxTranslation * scale, shape->mBoxRotation);
}
@ -397,9 +393,8 @@ namespace Physic
std::string outputstring = mesh + sid;
//get the shape from the .nif
mShapeLoader->load(outputstring,"General");
BulletShapeManager::getSingletonPtr()->load(outputstring,"General");
BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General");
//mShapeLoader->load(outputstring,"General");
BulletShapePtr shape;// = BulletShapeManager::getSingleton().getByName(outputstring,"General");
// TODO: add option somewhere to enable collision for placeable meshes

@ -197,7 +197,7 @@ namespace Physic
/**
* Note that the shapeLoader IS destroyed by the phyic Engine!!
*/
PhysicEngine(BulletShapeLoader* shapeLoader);
PhysicEngine();
/**
* It DOES destroy the shape loader!
@ -290,15 +290,12 @@ namespace Physic
btCollisionObject *object);
//Bullet Stuff
btBroadphaseInterface* broadphase;
btDefaultCollisionConfiguration* collisionConfiguration;
btSequentialImpulseConstraintSolver* solver;
btCollisionDispatcher* dispatcher;
btBroadphaseInterface* mBroadphase;
btDefaultCollisionConfiguration* mCollisionConfiguration;
btSequentialImpulseConstraintSolver* mSolver;
btCollisionDispatcher* mDispatcher;
btDiscreteDynamicsWorld* mDynamicsWorld;
//the NIF file loader.
BulletShapeLoader* mShapeLoader;
typedef std::map<std::string, HeightField> HeightFieldContainer;
HeightFieldContainer mHeightFieldMap;
@ -318,24 +315,6 @@ namespace Physic
};
struct MyRayResultCallback : public btCollisionWorld::RayResultCallback
{
virtual btScalar addSingleResult( btCollisionWorld::LocalRayResult& rayResult, bool bNormalInWorldSpace)
{
results.push_back( std::make_pair(rayResult.m_hitFraction, rayResult.m_collisionObject) );
return rayResult.m_hitFraction;
}
static bool cmp( const std::pair<float, std::string>& i, const std::pair<float, std::string>& j )
{
if( i.first > j.first ) return false;
if( j.first > i.first ) return true;
return false;
}
std::vector < std::pair<float, const btCollisionObject*> > results;
};
}}
#endif

Loading…
Cancel
Save