mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 10:23:53 +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;
|
float totalDuration = mDuration;
|
||||||
mDuration = 0;
|
mDuration = 0;
|
||||||
|
|
||||||
PtrControllerMap::iterator iter(mActors.begin());
|
for(PtrControllerMap::iterator iter(mActors.begin());iter != mActors.end();iter++)
|
||||||
while(iter != mActors.end())
|
|
||||||
{
|
{
|
||||||
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
||||||
{
|
{
|
||||||
|
@ -224,10 +223,7 @@ namespace MWMechanics
|
||||||
updateNpc(iter->first, totalDuration, paused);
|
updateNpc(iter->first, totalDuration, paused);
|
||||||
|
|
||||||
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
if(!MWWorld::Class::get(iter->first).getCreatureStats(iter->first).isDead())
|
||||||
{
|
|
||||||
iter++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// workaround: always keep player alive for now
|
// workaround: always keep player alive for now
|
||||||
|
@ -244,18 +240,14 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
|
|
||||||
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).resurrect();
|
MWWorld::Class::get(iter->first).getCreatureStats(iter->first).resurrect();
|
||||||
++iter;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(iter->second.getState() == CharState_Dead)
|
if(iter->second.getState() == CharState_Dead)
|
||||||
{
|
|
||||||
iter++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
|
iter->second.setMovementVector(Ogre::Vector3::ZERO);
|
||||||
iter->second.setState(CharState_Dead, false);
|
iter->second.setState(CharState_Dead, false);
|
||||||
iter->second.setDirection(Ogre::Vector3::ZERO);
|
|
||||||
|
|
||||||
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
|
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];
|
||||||
|
|
||||||
|
@ -272,26 +264,8 @@ namespace MWMechanics
|
||||||
if(iter->second.getState() == CharState_Dead)
|
if(iter->second.getState() == CharState_Dead)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Ogre::Vector3 dir = MWWorld::Class::get(iter->first).getMovementVector(iter->first);
|
Ogre::Vector3 movement = MWWorld::Class::get(iter->first).getMovementVector(iter->first);
|
||||||
CharacterState newstate = CharState_Idle;
|
iter->second.setMovementVector(movement);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<std::string, Ogre::Vector3> > 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.
|
// HACK: The length we get is too large.
|
||||||
float mult = dir.length() / 32.0f;
|
float speed = std::max(1.0f, vec.length() / 32.0f);
|
||||||
mult = std::max(1.0f, mult);
|
|
||||||
|
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)
|
if(mAnimation)
|
||||||
mAnimation->setSpeedMult(mult);
|
mAnimation->setSpeedMult(speed);
|
||||||
mDirection = dir.normalisedCopy();
|
mDirection = vec.normalisedCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
void playGroup(const std::string &groupname, int mode, int count);
|
void playGroup(const std::string &groupname, int mode, int count);
|
||||||
void skipAnim();
|
void skipAnim();
|
||||||
|
|
||||||
void setDirection(const Ogre::Vector3 &dir);
|
void setMovementVector(const Ogre::Vector3 &vec);
|
||||||
|
|
||||||
void setState(CharacterState state, bool loop);
|
void setState(CharacterState state, bool loop);
|
||||||
CharacterState getState() const
|
CharacterState getState() const
|
||||||
|
|
Loading…
Reference in a new issue