mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 15:36:41 +00:00
Use a struct to hold the current animation times and remaining loop count
This commit is contained in:
parent
fd1e3f6ec5
commit
13ab2baef0
2 changed files with 42 additions and 42 deletions
|
@ -15,7 +15,6 @@ Animation::Animation(OEngine::Render::OgreRenderer& _rend)
|
||||||
: mInsert(NULL)
|
: mInsert(NULL)
|
||||||
, mRend(_rend)
|
, mRend(_rend)
|
||||||
, mTime(0.0f)
|
, mTime(0.0f)
|
||||||
, mAnimate(0)
|
|
||||||
, mSkipFrame(false)
|
, mSkipFrame(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -36,22 +35,17 @@ struct checklow {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Animation::findGroupTimes(const std::string &groupname, float *starttime, float *stoptime, float *loopstarttime, float *loopstoptime)
|
bool Animation::findGroupTimes(const std::string &groupname, Animation::GroupTimes *times)
|
||||||
{
|
{
|
||||||
const std::string &start = groupname+": start";
|
const std::string &start = groupname+": start";
|
||||||
const std::string &startloop = groupname+": loop start";
|
const std::string &startloop = groupname+": loop start";
|
||||||
const std::string &stop = groupname+": stop";
|
const std::string &stop = groupname+": stop";
|
||||||
const std::string &stoploop = groupname+": loop stop";
|
const std::string &stoploop = groupname+": loop stop";
|
||||||
|
|
||||||
*starttime = -1.0f;
|
|
||||||
*stoptime = -1.0f;
|
|
||||||
*loopstarttime = -1.0f;
|
|
||||||
*loopstoptime = -1.0f;
|
|
||||||
|
|
||||||
NifOgre::TextKeyMap::const_iterator iter;
|
NifOgre::TextKeyMap::const_iterator iter;
|
||||||
for(iter = mTextKeys.begin();iter != mTextKeys.end();iter++)
|
for(iter = mTextKeys.begin();iter != mTextKeys.end();iter++)
|
||||||
{
|
{
|
||||||
if(*starttime >= 0.0f && *stoptime >= 0.0f && *loopstarttime >= 0.0f && *loopstoptime >= 0.0f)
|
if(times->mStart >= 0.0f && times->mLoopStart >= 0.0f && times->mLoopStop >= 0.0f && times->mStop >= 0.0f)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
std::string::const_iterator strpos = iter->second.begin();
|
std::string::const_iterator strpos = iter->second.begin();
|
||||||
|
@ -66,28 +60,28 @@ bool Animation::findGroupTimes(const std::string &groupname, float *starttime, f
|
||||||
((striter=std::mismatch(strpos, strend, start.begin(), checklow()).first) == strend ||
|
((striter=std::mismatch(strpos, strend, start.begin(), checklow()).first) == strend ||
|
||||||
*striter == '\r' || *striter == '\n'))
|
*striter == '\r' || *striter == '\n'))
|
||||||
{
|
{
|
||||||
*starttime = iter->first;
|
times->mStart = iter->first;
|
||||||
*loopstarttime = iter->first;
|
times->mLoopStart = iter->first;
|
||||||
}
|
}
|
||||||
else if(startloop.size() <= strlen &&
|
else if(startloop.size() <= strlen &&
|
||||||
((striter=std::mismatch(strpos, strend, startloop.begin(), checklow()).first) == strend ||
|
((striter=std::mismatch(strpos, strend, startloop.begin(), checklow()).first) == strend ||
|
||||||
*striter == '\r' || *striter == '\n'))
|
*striter == '\r' || *striter == '\n'))
|
||||||
{
|
{
|
||||||
*loopstarttime = iter->first;
|
times->mLoopStart = iter->first;
|
||||||
}
|
}
|
||||||
else if(stoploop.size() <= strlen &&
|
else if(stoploop.size() <= strlen &&
|
||||||
((striter=std::mismatch(strpos, strend, stoploop.begin(), checklow()).first) == strend ||
|
((striter=std::mismatch(strpos, strend, stoploop.begin(), checklow()).first) == strend ||
|
||||||
*striter == '\r' || *striter == '\n'))
|
*striter == '\r' || *striter == '\n'))
|
||||||
{
|
{
|
||||||
*loopstoptime = iter->first;
|
times->mLoopStop = iter->first;
|
||||||
}
|
}
|
||||||
else if(stop.size() <= strlen &&
|
else if(stop.size() <= strlen &&
|
||||||
((striter=std::mismatch(strpos, strend, stop.begin(), checklow()).first) == strend ||
|
((striter=std::mismatch(strpos, strend, stop.begin(), checklow()).first) == strend ||
|
||||||
*striter == '\r' || *striter == '\n'))
|
*striter == '\r' || *striter == '\n'))
|
||||||
{
|
{
|
||||||
*stoptime = iter->first;
|
times->mStop = iter->first;
|
||||||
if(*loopstoptime < 0.0f)
|
if(times->mLoopStop < 0.0f)
|
||||||
*loopstoptime = iter->first;
|
times->mLoopStop = iter->first;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,18 +91,19 @@ bool Animation::findGroupTimes(const std::string &groupname, float *starttime, f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*starttime >= 0.0f && *stoptime >= 0.0f && *loopstarttime >= 0.0f && *loopstoptime >= 0.0f);
|
return (times->mStart >= 0.0f && times->mLoopStart >= 0.0f && times->mLoopStop >= 0.0f && times->mStop >= 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Animation::playGroup(std::string groupname, int mode, int loops)
|
void Animation::playGroup(std::string groupname, int mode, int loops)
|
||||||
{
|
{
|
||||||
float start, stop, loopstart, loopstop;
|
GroupTimes times;
|
||||||
|
times.mLoops = loops;
|
||||||
|
|
||||||
if(groupname == "all")
|
if(groupname == "all")
|
||||||
{
|
{
|
||||||
start = loopstart = 0.0f;
|
times.mStart = times.mLoopStart = 0.0f;
|
||||||
loopstop = stop = 0.0f;
|
times.mLoopStop = times.mStop = 0.0f;
|
||||||
|
|
||||||
if(mEntityList.mSkelBase)
|
if(mEntityList.mSkelBase)
|
||||||
{
|
{
|
||||||
|
@ -117,25 +112,21 @@ void Animation::playGroup(std::string groupname, int mode, int loops)
|
||||||
while(as.hasMoreElements())
|
while(as.hasMoreElements())
|
||||||
{
|
{
|
||||||
Ogre::AnimationState *state = as.getNext();
|
Ogre::AnimationState *state = as.getNext();
|
||||||
loopstop = stop = state->getLength();
|
times.mLoopStop = times.mStop = state->getLength();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!findGroupTimes(groupname, &start, &stop, &loopstart, &loopstop))
|
else if(!findGroupTimes(groupname, ×))
|
||||||
throw std::runtime_error("Failed to find animation group "+groupname);
|
throw std::runtime_error("Failed to find animation group "+groupname);
|
||||||
|
|
||||||
// FIXME: mode = 0 not yet supported
|
// FIXME: mode = 0 not yet supported
|
||||||
if(mode == 0)
|
if(mode == 0)
|
||||||
mode = 1;
|
mode = 1;
|
||||||
|
|
||||||
mStartTime = start;
|
mCurGroup = times;
|
||||||
mStopTime = stop;
|
|
||||||
mLoopStartTime = loopstart;
|
|
||||||
mLoopStopTime = loopstop;
|
|
||||||
|
|
||||||
mAnimate = loops;
|
mTime = ((mode==1) ? mCurGroup.mStart : mCurGroup.mLoopStart);
|
||||||
mTime = ((mode==1) ? mStartTime : mLoopStartTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::skipAnim()
|
void Animation::skipAnim()
|
||||||
|
@ -145,20 +136,20 @@ void Animation::skipAnim()
|
||||||
|
|
||||||
void Animation::runAnimation(float timepassed)
|
void Animation::runAnimation(float timepassed)
|
||||||
{
|
{
|
||||||
if(mAnimate > 0 && !mSkipFrame)
|
if(mCurGroup.mLoops > 0 && !mSkipFrame)
|
||||||
{
|
{
|
||||||
mTime += timepassed;
|
mTime += timepassed;
|
||||||
if(mTime >= mLoopStopTime)
|
if(mTime >= mCurGroup.mLoopStop)
|
||||||
{
|
{
|
||||||
if(mAnimate > 1)
|
if(mCurGroup.mLoops > 1)
|
||||||
{
|
{
|
||||||
mAnimate--;
|
mCurGroup.mLoops--;
|
||||||
mTime = mTime - mLoopStopTime + mLoopStartTime;
|
mTime = mTime - mCurGroup.mLoopStop + mCurGroup.mLoopStart;
|
||||||
}
|
}
|
||||||
else if(mTime >= mStopTime)
|
else if(mTime >= mCurGroup.mStop)
|
||||||
{
|
{
|
||||||
mAnimate--;
|
mCurGroup.mLoops--;
|
||||||
mTime = mStopTime;
|
mTime = mCurGroup.mStop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,24 +15,33 @@
|
||||||
namespace MWRender {
|
namespace MWRender {
|
||||||
|
|
||||||
class Animation {
|
class Animation {
|
||||||
|
struct GroupTimes {
|
||||||
|
float mStart;
|
||||||
|
float mStop;
|
||||||
|
float mLoopStart;
|
||||||
|
float mLoopStop;
|
||||||
|
|
||||||
|
size_t mLoops;
|
||||||
|
|
||||||
|
GroupTimes()
|
||||||
|
: mStart(-1.0f), mStop(-1.0f), mLoopStart(-1.0f), mLoopStop(-1.0f),
|
||||||
|
mLoops(0)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Ogre::SceneNode* mInsert;
|
Ogre::SceneNode* mInsert;
|
||||||
OEngine::Render::OgreRenderer &mRend;
|
OEngine::Render::OgreRenderer &mRend;
|
||||||
|
|
||||||
float mTime;
|
float mTime;
|
||||||
float mStartTime;
|
GroupTimes mCurGroup;
|
||||||
float mStopTime;
|
|
||||||
float mLoopStartTime;
|
|
||||||
float mLoopStopTime;
|
|
||||||
|
|
||||||
int mAnimate;
|
|
||||||
bool mSkipFrame;
|
bool mSkipFrame;
|
||||||
|
|
||||||
NifOgre::EntityList mEntityList;
|
NifOgre::EntityList mEntityList;
|
||||||
NifOgre::TextKeyMap mTextKeys;
|
NifOgre::TextKeyMap mTextKeys;
|
||||||
|
|
||||||
bool findGroupTimes(const std::string &groupname, float *starttime, float *stoptime,
|
bool findGroupTimes(const std::string &groupname, GroupTimes *times);
|
||||||
float *loopstarttime, float *loopstoptime);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Animation(OEngine::Render::OgreRenderer& _rend);
|
Animation(OEngine::Render::OgreRenderer& _rend);
|
||||||
|
|
Loading…
Reference in a new issue