forked from mirror/openmw-tes3mp
Move getStateInfo into the character controller
This commit is contained in:
parent
05060e57ec
commit
4b15da076b
3 changed files with 28 additions and 19 deletions
|
@ -89,17 +89,21 @@ static const struct {
|
||||||
};
|
};
|
||||||
static const size_t sStateListSize = sizeof(sStateList)/sizeof(sStateList[0]);
|
static const size_t sStateListSize = sizeof(sStateList)/sizeof(sStateList[0]);
|
||||||
|
|
||||||
static void getStateInfo(CharacterState state, std::string *group)
|
void CharacterController::getCurrentGroup(std::string &group) const
|
||||||
{
|
{
|
||||||
for(size_t i = 0;i < sStateListSize;i++)
|
for(size_t i = 0;i < sStateListSize;i++)
|
||||||
{
|
{
|
||||||
if(sStateList[i].state == state)
|
if(sStateList[i].state == mCharState)
|
||||||
{
|
{
|
||||||
*group = sStateList[i].groupname;
|
group = sStateList[i].groupname;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(state));
|
if(group.empty())
|
||||||
|
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mCharState));
|
||||||
|
|
||||||
|
if(!mAnimation->hasAnimation(group))
|
||||||
|
group = std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,8 +120,6 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
|
||||||
if(!mAnimation)
|
if(!mAnimation)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string group;
|
|
||||||
getStateInfo(mCharState, &group);
|
|
||||||
if(MWWorld::Class::get(mPtr).isActor())
|
if(MWWorld::Class::get(mPtr).isActor())
|
||||||
{
|
{
|
||||||
/* Accumulate along X/Y only for now, until we can figure out how we should
|
/* Accumulate along X/Y only for now, until we can figure out how we should
|
||||||
|
@ -129,8 +131,10 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
|
||||||
/* Don't accumulate with non-actors. */
|
/* Don't accumulate with non-actors. */
|
||||||
mAnimation->setAccumulation(Ogre::Vector3(0.0f));
|
mAnimation->setAccumulation(Ogre::Vector3(0.0f));
|
||||||
}
|
}
|
||||||
if(mAnimation->hasAnimation(group))
|
|
||||||
mMovingAnim = mAnimation->play(group, "start", "stop", 1.0f, loop ? (~(size_t)0) : 0);
|
std::string group;
|
||||||
|
getCurrentGroup(group);
|
||||||
|
mMovingAnim = mAnimation->play(group, "start", "stop", 1.0f, loop ? (~(size_t)0) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CharacterController::~CharacterController()
|
CharacterController::~CharacterController()
|
||||||
|
@ -149,7 +153,7 @@ void CharacterController::update(float duration, Movement &movement)
|
||||||
float speed = 0.0f;
|
float speed = 0.0f;
|
||||||
if(!(getState() >= CharState_Death1))
|
if(!(getState() >= CharState_Death1))
|
||||||
{
|
{
|
||||||
const MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
||||||
|
|
||||||
bool onground = world->isOnGround(mPtr);
|
bool onground = world->isOnGround(mPtr);
|
||||||
|
@ -161,23 +165,23 @@ void CharacterController::update(float duration, Movement &movement)
|
||||||
speed = cls.getSpeed(mPtr);
|
speed = cls.getSpeed(mPtr);
|
||||||
|
|
||||||
// advance athletics
|
// advance athletics
|
||||||
if (vec.squaredLength() > 0 && mPtr == MWBase::Environment::get().getWorld()->getPlayer().getPlayer())
|
if (vec.squaredLength() > 0 && mPtr == world->getPlayer().getPlayer())
|
||||||
{
|
{
|
||||||
if (inwater)
|
if (inwater)
|
||||||
{
|
{
|
||||||
mSecondsOfSwimming += duration;
|
mSecondsOfSwimming += duration;
|
||||||
while (mSecondsOfSwimming > 1)
|
while(mSecondsOfSwimming > 1)
|
||||||
{
|
{
|
||||||
MWWorld::Class::get(mPtr).skillUsageSucceeded(mPtr, ESM::Skill::Athletics, 1);
|
cls.skillUsageSucceeded(mPtr, ESM::Skill::Athletics, 1);
|
||||||
mSecondsOfSwimming -= 1;
|
mSecondsOfSwimming -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isrunning)
|
else if (isrunning)
|
||||||
{
|
{
|
||||||
mSecondsOfRunning += duration;
|
mSecondsOfRunning += duration;
|
||||||
while (mSecondsOfRunning > 1)
|
while(mSecondsOfRunning > 1)
|
||||||
{
|
{
|
||||||
MWWorld::Class::get(mPtr).skillUsageSucceeded(mPtr, ESM::Skill::Athletics, 0);
|
cls.skillUsageSucceeded(mPtr, ESM::Skill::Athletics, 0);
|
||||||
mSecondsOfRunning -= 1;
|
mSecondsOfRunning -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,10 +318,9 @@ void CharacterController::forceStateUpdate()
|
||||||
return;
|
return;
|
||||||
mAnimQueue.clear();
|
mAnimQueue.clear();
|
||||||
|
|
||||||
std::string anim;
|
std::string group;
|
||||||
getStateInfo(mCharState, &anim);
|
getCurrentGroup(group);
|
||||||
if((mMovingAnim=mAnimation->hasAnimation(anim)) != false)
|
mMovingAnim = mAnimation->play(group, "start", "stop", 0.0f, mLooping ? (~(size_t)0) : 0);
|
||||||
mMovingAnim = mAnimation->play(anim, "start", "stop", 0.0f, mLooping ? (~(size_t)0) : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,9 @@ class CharacterController
|
||||||
|
|
||||||
bool mMovingAnim;
|
bool mMovingAnim;
|
||||||
|
|
||||||
|
// Gets an animation group name from the current character state.
|
||||||
|
void getCurrentGroup(std::string &group) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop);
|
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop);
|
||||||
virtual ~CharacterController();
|
virtual ~CharacterController();
|
||||||
|
|
|
@ -572,6 +572,9 @@ bool Animation::play(const std::string &groupname, const std::string &start, con
|
||||||
mLayer[layeridx].mLoopCount = 0;
|
mLayer[layeridx].mLoopCount = 0;
|
||||||
mLayer[layeridx].mPlaying = false;
|
mLayer[layeridx].mPlaying = false;
|
||||||
|
|
||||||
|
if(groupname.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
bool movinganim = false;
|
bool movinganim = false;
|
||||||
bool foundanim = false;
|
bool foundanim = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue