Store animated collision objects in a separate container

openmw-38
scrawl 9 years ago
parent 36e91617c9
commit 894477849a

@ -549,6 +549,11 @@ namespace MWPhysics
return mCollisionObject.get(); return mCollisionObject.get();
} }
bool isAnimated() const
{
return !mShapeInstance->mAnimatedShapes.empty();
}
void animateCollisionShapes(btCollisionWorld* collisionWorld) void animateCollisionShapes(btCollisionWorld* collisionWorld)
{ {
if (mShapeInstance->mAnimatedShapes.empty()) if (mShapeInstance->mAnimatedShapes.empty())
@ -1015,6 +1020,9 @@ namespace MWPhysics
Object *obj = new Object(ptr, shapeInstance); Object *obj = new Object(ptr, shapeInstance);
mObjects.insert(std::make_pair(ptr, obj)); mObjects.insert(std::make_pair(ptr, obj));
if (obj->isAnimated())
mAnimatedObjects.insert(obj);
mCollisionWorld->addCollisionObject(obj->getCollisionObject(), CollisionType_World, mCollisionWorld->addCollisionObject(obj->getCollisionObject(), CollisionType_World,
CollisionType_Actor|CollisionType_HeightMap|CollisionType_Projectile); CollisionType_Actor|CollisionType_HeightMap|CollisionType_Projectile);
} }
@ -1025,6 +1033,9 @@ namespace MWPhysics
if (found != mObjects.end()) if (found != mObjects.end())
{ {
mCollisionWorld->removeCollisionObject(found->second->getCollisionObject()); mCollisionWorld->removeCollisionObject(found->second->getCollisionObject());
mAnimatedObjects.erase(found->second);
delete found->second; delete found->second;
mObjects.erase(found); mObjects.erase(found);
} }
@ -1251,8 +1262,8 @@ namespace MWPhysics
void PhysicsSystem::stepSimulation(float dt) void PhysicsSystem::stepSimulation(float dt)
{ {
for (ObjectMap::iterator it = mObjects.begin(); it != mObjects.end(); ++it) for (std::set<Object*>::iterator it = mAnimatedObjects.begin(); it != mAnimatedObjects.end(); ++it)
it->second->animateCollisionShapes(mCollisionWorld); (*it)->animateCollisionShapes(mCollisionWorld);
CProfileManager::Reset(); CProfileManager::Reset();
CProfileManager::Increment_Frame_Counter(); CProfileManager::Increment_Frame_Counter();

@ -3,6 +3,7 @@
#include <memory> #include <memory>
#include <map> #include <map>
#include <set>
#include <osg/Quat> #include <osg/Quat>
#include <osg/ref_ptr> #include <osg/ref_ptr>
@ -166,6 +167,8 @@ namespace MWPhysics
typedef std::map<MWWorld::Ptr, Object*> ObjectMap; typedef std::map<MWWorld::Ptr, Object*> ObjectMap;
ObjectMap mObjects; ObjectMap mObjects;
std::set<Object*> mAnimatedObjects; // stores pointers to elements in mObjects
typedef std::map<MWWorld::Ptr, Actor*> ActorMap; typedef std::map<MWWorld::Ptr, Actor*> ActorMap;
ActorMap mActors; ActorMap mActors;

Loading…
Cancel
Save