1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-30 09:36:43 +00:00

Check if the actor still exists /first/

This commit is contained in:
Assumeru 2016-10-26 11:04:54 +02:00
parent a72cd896ca
commit 25d64989b3

View file

@ -1309,12 +1309,16 @@ namespace MWPhysics
PtrVelocityList::iterator iter = mMovementQueue.begin(); PtrVelocityList::iterator iter = mMovementQueue.begin();
for(;iter != mMovementQueue.end();++iter) for(;iter != mMovementQueue.end();++iter)
{ {
ActorMap::iterator foundActor = mActors.find(iter->first);
if (foundActor == mActors.end()) // actor was already removed from the scene
continue;
Actor* physicActor = foundActor->second;
float waterlevel = -std::numeric_limits<float>::max(); float waterlevel = -std::numeric_limits<float>::max();
const MWWorld::CellStore *cell = iter->first.getCell(); const MWWorld::CellStore *cell = iter->first.getCell();
if(cell->getCell()->hasWater()) if(cell->getCell()->hasWater())
waterlevel = cell->getWaterLevel(); waterlevel = cell->getWaterLevel();
const MWMechanics::MagicEffects& effects = iter->first.getClass().getCreatureStats(iter->first).getMagicEffects(); const MWMechanics::MagicEffects& effects = iter->first.getClass().getCreatureStats(iter->first).getMagicEffects();
bool waterCollision = false; bool waterCollision = false;
@ -1322,35 +1326,25 @@ namespace MWPhysics
{ {
if (!world->isUnderwater(iter->first.getCell(), osg::Vec3f(iter->first.getRefData().getPosition().asVec3()))) if (!world->isUnderwater(iter->first.getCell(), osg::Vec3f(iter->first.getRefData().getPosition().asVec3())))
waterCollision = true; waterCollision = true;
else else if (physicActor->getCollisionMode())
{ {
Actor *actor = getActor(iter->first); const osg::Vec3f actorPosition = physicActor->getPosition();
// Actor can collide const osg::Vec3f destinationPosition(actorPosition.x(), actorPosition.y(), waterlevel);
if (actor->getCollisionMode()) ActorTracer tracer;
tracer.doTrace(physicActor->getCollisionObject(), actorPosition, destinationPosition, mCollisionWorld);
if (tracer.mFraction >= 1.0f)
{ {
const osg::Vec3f actorPosition = actor->getPosition(); waterCollision = true;
const osg::Vec3f destinationPosition(actorPosition.x(), actorPosition.y(), waterlevel); physicActor->setPosition(destinationPosition);
ActorTracer tracer; }
tracer.doTrace(actor->getCollisionObject(), actorPosition, destinationPosition, mCollisionWorld); else
if (tracer.mFraction >= 1.0f) {
{ //Remove the effect to remove the performance hit of casting in a weird spot
waterCollision = true; //probably makes that Tribunal quest where the water rises a bit safer
actor->setPosition(destinationPosition); iter->first.getClass().getCreatureStats(iter->first).getActiveSpells().purgeEffect(ESM::MagicEffect::WaterWalking);
}
else
{
//Remove the effect to remove the performance hit of casting in a weird spot
//probably makes that Tribunal quest where the water rises a bit safer
iter->first.getClass().getCreatureStats(iter->first).getActiveSpells().purgeEffect(ESM::MagicEffect::WaterWalking);
}
} }
} }
} }
ActorMap::iterator foundActor = mActors.find(iter->first);
if (foundActor == mActors.end()) // actor was already removed from the scene
continue;
Actor* physicActor = foundActor->second;
physicActor->setCanWaterWalk(waterCollision); physicActor->setCanWaterWalk(waterCollision);
// Slow fall reduces fall speed by a factor of (effect magnitude / 200) // Slow fall reduces fall speed by a factor of (effect magnitude / 200)