From 894477849a4fdd48509b3c0337136776c020bf9c Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 19 Nov 2015 23:33:08 +0100 Subject: [PATCH] Store animated collision objects in a separate container --- apps/openmw/mwphysics/physicssystem.cpp | 15 +++++++++++++-- apps/openmw/mwphysics/physicssystem.hpp | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 5734f4827..71a155392 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -549,6 +549,11 @@ namespace MWPhysics return mCollisionObject.get(); } + bool isAnimated() const + { + return !mShapeInstance->mAnimatedShapes.empty(); + } + void animateCollisionShapes(btCollisionWorld* collisionWorld) { if (mShapeInstance->mAnimatedShapes.empty()) @@ -1015,6 +1020,9 @@ namespace MWPhysics Object *obj = new Object(ptr, shapeInstance); mObjects.insert(std::make_pair(ptr, obj)); + if (obj->isAnimated()) + mAnimatedObjects.insert(obj); + mCollisionWorld->addCollisionObject(obj->getCollisionObject(), CollisionType_World, CollisionType_Actor|CollisionType_HeightMap|CollisionType_Projectile); } @@ -1025,6 +1033,9 @@ namespace MWPhysics if (found != mObjects.end()) { mCollisionWorld->removeCollisionObject(found->second->getCollisionObject()); + + mAnimatedObjects.erase(found->second); + delete found->second; mObjects.erase(found); } @@ -1251,8 +1262,8 @@ namespace MWPhysics void PhysicsSystem::stepSimulation(float dt) { - for (ObjectMap::iterator it = mObjects.begin(); it != mObjects.end(); ++it) - it->second->animateCollisionShapes(mCollisionWorld); + for (std::set::iterator it = mAnimatedObjects.begin(); it != mAnimatedObjects.end(); ++it) + (*it)->animateCollisionShapes(mCollisionWorld); CProfileManager::Reset(); CProfileManager::Increment_Frame_Counter(); diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index 1ccfb21cd..83729d7ae 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -166,6 +167,8 @@ namespace MWPhysics typedef std::map ObjectMap; ObjectMap mObjects; + std::set mAnimatedObjects; // stores pointers to elements in mObjects + typedef std::map ActorMap; ActorMap mActors;