1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00

fix delete actor

This commit is contained in:
gugus 2011-03-23 19:17:45 +01:00
parent 1ce6405e2b
commit 1cada5032e

View File

@ -241,28 +241,37 @@ namespace Physic
void PhysicEngine::removeRigidBody(std::string name) void PhysicEngine::removeRigidBody(std::string name)
{ {
RigidBody* body = RigidBodyMap[name]; std::map<std::string,RigidBody*>::iterator it = RigidBodyMap.find(name);
if(body != NULL) if (it != RigidBodyMap.end() )
{ {
broadphase->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher); RigidBody* body = it->second;
std::map<std::string,PhysicActor*>::iterator it = PhysicActorMap.begin(); if(body != NULL)
for(;it!=PhysicActorMap.end();it++)
{ {
it->second->internalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher); broadphase->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher);
it->second->externalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher); std::map<std::string,PhysicActor*>::iterator it = PhysicActorMap.begin();
for(;it!=PhysicActorMap.end();it++)
{
it->second->internalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher);
it->second->externalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher);
}
dynamicsWorld->removeRigidBody(RigidBodyMap[name]);
} }
dynamicsWorld->removeRigidBody(RigidBodyMap[name]); }
}
} }
void PhysicEngine::deleteRigidBody(std::string name) void PhysicEngine::deleteRigidBody(std::string name)
{ {
RigidBody* body = RigidBodyMap[name]; std::map<std::string,RigidBody*>::iterator it = RigidBodyMap.find(name);
if(body != NULL) if (it != RigidBodyMap.end() )
{ {
delete body; RigidBody* body = it->second;
RigidBodyMap[name] = NULL; if(body != NULL)
} {
delete body;
RigidBodyMap[name] = NULL;
RigidBodyMap.erase(it);
}
}
} }
RigidBody* PhysicEngine::getRigidBody(std::string name) RigidBody* PhysicEngine::getRigidBody(std::string name)
@ -291,15 +300,33 @@ namespace Physic
void PhysicEngine::removeCharacter(std::string name) void PhysicEngine::removeCharacter(std::string name)
{ {
PhysicActor* act = PhysicActorMap[name]; //std::cout << "remove";
if(act != NULL) std::map<std::string,PhysicActor*>::iterator it = PhysicActorMap.find(name);
{ if (it != PhysicActorMap.end() )
dynamicsWorld->removeCollisionObject(act->externalGhostObject); {
dynamicsWorld->removeCollisionObject(act->internalGhostObject); PhysicActor* act = it->second;
dynamicsWorld->removeAction(act->mCharacter); if(act != NULL)
delete act; {
PhysicActorMap[name] = NULL; /*broadphase->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->externalGhostObject->getBroadphaseHandle(),dispatcher);
} broadphase->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->internalGhostObject->getBroadphaseHandle(),dispatcher);
std::map<std::string,PhysicActor*>::iterator it2 = PhysicActorMap.begin();
for(;it2!=PhysicActorMap.end();it++)
{
it->second->internalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->externalGhostObject->getBroadphaseHandle(),dispatcher);
it->second->externalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->externalGhostObject->getBroadphaseHandle(),dispatcher);
it->second->internalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->internalGhostObject->getBroadphaseHandle(),dispatcher);
it->second->externalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->internalGhostObject->getBroadphaseHandle(),dispatcher);
}*/
//act->externalGhostObject->
dynamicsWorld->removeCollisionObject(act->externalGhostObject);
dynamicsWorld->removeCollisionObject(act->internalGhostObject);
dynamicsWorld->removeAction(act->mCharacter);
delete act;
PhysicActorMap[name] = NULL;
PhysicActorMap.erase(it);
}
}
//std::cout << "ok";
} }
PhysicActor* PhysicEngine::getCharacter(std::string name) PhysicActor* PhysicEngine::getCharacter(std::string name)