mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 07:53:52 +00:00
Handle most state changes in the character controller when setting the movement vector
This commit is contained in:
parent
c45b4d6072
commit
007a5963de
3 changed files with 28 additions and 37 deletions
|
@ -211,8 +211,7 @@ namespace MWMechanics
|
|||
float totalDuration = mDuration;
|
||||
mDuration = 0;
|
||||
|
||||
PtrControllerMap::iterator iter(mActors.begin());
|
||||
while(iter != mActors.end())
|
||||
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();iter++)
|
||||
{
|
||||
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
||||
{
|
||||
|
@ -224,10 +223,7 @@ namespace MWMechanics
|
|||
updateNpc(iter->first, totalDuration, paused);
|
||||
|
||||
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
||||
{
|
||||
iter++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// workaround: always keep player alive for now
|
||||
|
@ -244,18 +240,14 @@ namespace MWMechanics
|
|||
}
|
||||
|
||||
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).resurrect();
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(iter->second.getState() == CharState_Dead)
|
||||
{
|
||||
iter++;
|
||||
continue;
|
||||
}
|
||||
|
||||
iter->second.setMovementVector(Ogre::Vector3::ZERO);
|
||||
iter->second.setState(CharState_Dead, false);
|
||||
iter->second.setDirection(Ogre::Vector3::ZERO);
|
||||
|
||||
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
|
||||
|
||||
|
@ -272,26 +264,8 @@ namespace MWMechanics
|
|||
if(iter->second.getState() == CharState_Dead)
|
||||
continue;
|
||||
|
||||
Ogre::Vector3 dir = MWWorld::Class::get(iter->first).getMovementVector(iter->first);
|
||||
CharacterState newstate = CharState_Idle;
|
||||
|
||||
if(dir.length() >= 0.1f)
|
||||
{
|
||||
if(std::abs(dir.x/2.0f) > std::abs(dir.y))
|
||||
{
|
||||
if(dir.x > 0.0f)
|
||||
newstate = CharState_WalkRight;
|
||||
else if(dir.x < 0.0f)
|
||||
newstate = CharState_WalkLeft;
|
||||
}
|
||||
else if(dir.y < 0.0f)
|
||||
newstate = CharState_WalkBack;
|
||||
else
|
||||
newstate = CharState_WalkForward;
|
||||
}
|
||||
|
||||
iter->second.setState(newstate, true);
|
||||
iter->second.setDirection(dir);
|
||||
Ogre::Vector3 movement = MWWorld::Class::get(iter->first).getMovementVector(iter->first);
|
||||
iter->second.setMovementVector(movement);
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string, Ogre::Vector3> > movement;
|
||||
|
|
|
@ -127,14 +127,31 @@ void CharacterController::markerEvent(float time, const std::string &evt)
|
|||
}
|
||||
|
||||
|
||||
void CharacterController::setDirection(const Ogre::Vector3 &dir)
|
||||
void CharacterController::setMovementVector(const Ogre::Vector3 &vec)
|
||||
{
|
||||
// HACK: The direction length we get is too large.
|
||||
float mult = dir.length() / 32.0f;
|
||||
mult = std::max(1.0f, mult);
|
||||
// HACK: The length we get is too large.
|
||||
float speed = std::max(1.0f, vec.length() / 32.0f);
|
||||
|
||||
if(vec.length() >= 0.1f)
|
||||
{
|
||||
if(std::abs(vec.x/2.0f) > std::abs(vec.y))
|
||||
{
|
||||
if(vec.x > 0.0f)
|
||||
setState(CharState_WalkRight, true);
|
||||
else if(vec.x < 0.0f)
|
||||
setState(CharState_WalkLeft, true);
|
||||
}
|
||||
else if(vec.y < 0.0f)
|
||||
setState(CharState_WalkBack, true);
|
||||
else
|
||||
setState(CharState_WalkForward, true);
|
||||
}
|
||||
else
|
||||
setState(CharState_Idle, true);
|
||||
|
||||
if(mAnimation)
|
||||
mAnimation->setSpeedMult(mult);
|
||||
mDirection = dir.normalisedCopy();
|
||||
mAnimation->setSpeedMult(speed);
|
||||
mDirection = vec.normalisedCopy();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
void playGroup(const std::string &groupname, int mode, int count);
|
||||
void skipAnim();
|
||||
|
||||
void setDirection(const Ogre::Vector3 &dir);
|
||||
void setMovementVector(const Ogre::Vector3 &vec);
|
||||
|
||||
void setState(CharacterState state, bool loop);
|
||||
CharacterState getState() const
|
||||
|
|
Loading…
Reference in a new issue