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

Store a pointer to the character controller in the map

This commit is contained in:
Chris Robinson 2013-07-08 14:05:53 -07:00
parent a3c67389df
commit 7883087586
2 changed files with 20 additions and 14 deletions

View File

@ -172,16 +172,19 @@ namespace MWMechanics
MWRender::Animation *anim = MWBase::Environment::get().getWorld()->getAnimation(ptr); MWRender::Animation *anim = MWBase::Environment::get().getWorld()->getAnimation(ptr);
if(!MWWorld::Class::get(ptr).getCreatureStats(ptr).isDead()) if(!MWWorld::Class::get(ptr).getCreatureStats(ptr).isDead())
mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Idle))); mActors.insert(std::make_pair(ptr, new CharacterController(ptr, anim, CharState_Idle)));
else else
mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Death1))); mActors.insert(std::make_pair(ptr, new CharacterController(ptr, anim, CharState_Death1)));
} }
void Actors::removeActor (const MWWorld::Ptr& ptr) void Actors::removeActor (const MWWorld::Ptr& ptr)
{ {
PtrControllerMap::iterator iter = mActors.find(ptr); PtrControllerMap::iterator iter = mActors.find(ptr);
if(iter != mActors.end()) if(iter != mActors.end())
{
delete iter->second;
mActors.erase(iter); mActors.erase(iter);
}
} }
void Actors::updateActor(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr) void Actors::updateActor(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr)
@ -189,10 +192,10 @@ namespace MWMechanics
PtrControllerMap::iterator iter = mActors.find(old); PtrControllerMap::iterator iter = mActors.find(old);
if(iter != mActors.end()) if(iter != mActors.end())
{ {
CharacterController ctrl = iter->second; CharacterController *ctrl = iter->second;
mActors.erase(iter); mActors.erase(iter);
ctrl.updatePtr(ptr); ctrl->updatePtr(ptr);
mActors.insert(std::make_pair(ptr, ctrl)); mActors.insert(std::make_pair(ptr, ctrl));
} }
} }
@ -203,7 +206,10 @@ namespace MWMechanics
while(iter != mActors.end()) while(iter != mActors.end())
{ {
if(iter->first.getCell()==cellStore) if(iter->first.getCell()==cellStore)
{
delete iter->second;
mActors.erase(iter++); mActors.erase(iter++);
}
else else
++iter; ++iter;
} }
@ -222,8 +228,8 @@ namespace MWMechanics
{ {
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead()) if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
{ {
if(iter->second.getState() >= CharState_Death1) if(iter->second->getState() >= CharState_Death1)
iter->second.setState(CharState_Idle); iter->second->setState(CharState_Idle);
updateActor(iter->first, totalDuration); updateActor(iter->first, totalDuration);
if(iter->first.getTypeName() == typeid(ESM::NPC).name()) if(iter->first.getTypeName() == typeid(ESM::NPC).name())
@ -250,10 +256,10 @@ namespace MWMechanics
continue; continue;
} }
if(iter->second.getState() >= CharState_Death1) if(iter->second->getState() >= CharState_Death1)
continue; continue;
iter->second.setState(CharState_Death1); iter->second->setState(CharState_Death1);
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)]; ++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
@ -270,7 +276,7 @@ namespace MWMechanics
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();++iter) for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();++iter)
{ {
Movement movement; Movement movement;
iter->second.update(duration, movement); iter->second->update(duration, movement);
mMovement.push_back(std::make_pair(iter->first, movement)); mMovement.push_back(std::make_pair(iter->first, movement));
} }
MWBase::Environment::get().getWorld()->doPhysics(mMovement, duration); MWBase::Environment::get().getWorld()->doPhysics(mMovement, duration);
@ -297,27 +303,27 @@ namespace MWMechanics
{ {
PtrControllerMap::iterator iter = mActors.find(ptr); PtrControllerMap::iterator iter = mActors.find(ptr);
if(iter != mActors.end()) if(iter != mActors.end())
iter->second.forceStateUpdate(); iter->second->forceStateUpdate();
} }
void Actors::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number) void Actors::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number)
{ {
PtrControllerMap::iterator iter = mActors.find(ptr); PtrControllerMap::iterator iter = mActors.find(ptr);
if(iter != mActors.end()) if(iter != mActors.end())
iter->second.playGroup(groupName, mode, number); iter->second->playGroup(groupName, mode, number);
} }
void Actors::skipAnimation(const MWWorld::Ptr& ptr) void Actors::skipAnimation(const MWWorld::Ptr& ptr)
{ {
PtrControllerMap::iterator iter = mActors.find(ptr); PtrControllerMap::iterator iter = mActors.find(ptr);
if(iter != mActors.end()) if(iter != mActors.end())
iter->second.skipAnim(); iter->second->skipAnim();
} }
bool Actors::checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName) bool Actors::checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName)
{ {
PtrControllerMap::iterator iter = mActors.find(ptr); PtrControllerMap::iterator iter = mActors.find(ptr);
if(iter != mActors.end()) if(iter != mActors.end())
return iter->second.isAnimPlaying(groupName); return iter->second->isAnimPlaying(groupName);
return false; return false;
} }
} }

View File

@ -25,7 +25,7 @@ namespace MWMechanics
{ {
class Actors class Actors
{ {
typedef std::map<MWWorld::Ptr,CharacterController> PtrControllerMap; typedef std::map<MWWorld::Ptr,CharacterController*> PtrControllerMap;
PtrControllerMap mActors; PtrControllerMap mActors;
MWWorld::PtrMovementList mMovement; MWWorld::PtrMovementList mMovement;