mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 11:23:51 +00:00
Store iterators for start and stop keys
This commit is contained in:
parent
1b1f9f7921
commit
4ce98e9bd6
2 changed files with 24 additions and 34 deletions
|
@ -38,11 +38,10 @@ Animation::Animation(const MWWorld::Ptr &ptr)
|
||||||
, mNonAccumRoot(NULL)
|
, mNonAccumRoot(NULL)
|
||||||
, mAccumulate(0.0f)
|
, mAccumulate(0.0f)
|
||||||
, mLastPosition(0.0f)
|
, mLastPosition(0.0f)
|
||||||
|
, mCurrentAnim(NULL)
|
||||||
, mCurrentControllers(NULL)
|
, mCurrentControllers(NULL)
|
||||||
, mCurrentKeys(NULL)
|
, mCurrentKeys(NULL)
|
||||||
, mCurrentAnim(NULL)
|
|
||||||
, mCurrentTime(0.0f)
|
, mCurrentTime(0.0f)
|
||||||
, mStopTime(0.0f)
|
|
||||||
, mPlaying(false)
|
, mPlaying(false)
|
||||||
, mLooping(false)
|
, mLooping(false)
|
||||||
, mAnimVelocity(0.0f)
|
, mAnimVelocity(0.0f)
|
||||||
|
@ -313,35 +312,26 @@ Ogre::Vector3 Animation::updatePosition()
|
||||||
|
|
||||||
void Animation::reset(const std::string &start, const std::string &stop)
|
void Animation::reset(const std::string &start, const std::string &stop)
|
||||||
{
|
{
|
||||||
mNextKey = mCurrentKeys->begin();
|
mStartKey = mCurrentKeys->begin();
|
||||||
|
|
||||||
while(mNextKey != mCurrentKeys->end() && mNextKey->second != start)
|
while(mStartKey != mCurrentKeys->end() && mStartKey->second != start)
|
||||||
mNextKey++;
|
mStartKey++;
|
||||||
if(mNextKey != mCurrentKeys->end())
|
if(mStartKey != mCurrentKeys->end())
|
||||||
mCurrentTime = mNextKey->first;
|
mCurrentTime = mStartKey->first;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mNextKey = mCurrentKeys->begin();
|
mStartKey = mCurrentKeys->begin();
|
||||||
while(mNextKey != mCurrentKeys->end() && mNextKey->second != "start")
|
mCurrentTime = mStartKey->first;
|
||||||
mNextKey++;
|
|
||||||
if(mNextKey != mCurrentKeys->end())
|
|
||||||
mCurrentTime = mNextKey->first;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mNextKey = mCurrentKeys->begin();
|
|
||||||
mCurrentTime = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
mNextKey = mStartKey;
|
||||||
|
|
||||||
if(stop.length() > 0)
|
if(stop.length() > 0)
|
||||||
{
|
{
|
||||||
NifOgre::TextKeyMap::const_iterator stopKey = mNextKey;
|
mStopKey = mStartKey;
|
||||||
while(stopKey != mCurrentKeys->end() && stopKey->second != stop)
|
while(mStopKey != mCurrentKeys->end() && mStopKey->second != stop)
|
||||||
stopKey++;
|
mStopKey++;
|
||||||
if(stopKey != mCurrentKeys->end())
|
if(mStopKey == mCurrentKeys->end())
|
||||||
mStopTime = stopKey->first;
|
mStopKey--;
|
||||||
else
|
|
||||||
mStopTime = mCurrentAnim->getLength();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mNonAccumRoot)
|
if(mNonAccumRoot)
|
||||||
|
@ -390,7 +380,7 @@ bool Animation::handleEvent(float time, const std::string &evt)
|
||||||
{
|
{
|
||||||
if(mLooping)
|
if(mLooping)
|
||||||
{
|
{
|
||||||
reset("loop start", "");
|
reset("loop start");
|
||||||
if(mCurrentTime >= time)
|
if(mCurrentTime >= time)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -400,7 +390,7 @@ bool Animation::handleEvent(float time, const std::string &evt)
|
||||||
{
|
{
|
||||||
if(mLooping)
|
if(mLooping)
|
||||||
{
|
{
|
||||||
reset("loop start", "");
|
reset("loop start");
|
||||||
if(mCurrentTime >= time)
|
if(mCurrentTime >= time)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -455,13 +445,11 @@ Ogre::Vector3 Animation::runAnimation(float timepassed)
|
||||||
while(mCurrentAnim && mPlaying)
|
while(mCurrentAnim && mPlaying)
|
||||||
{
|
{
|
||||||
float targetTime = mCurrentTime + timepassed;
|
float targetTime = mCurrentTime + timepassed;
|
||||||
if(mNextKey == mCurrentKeys->end() || mNextKey->first > targetTime)
|
if(mNextKey->first > targetTime)
|
||||||
{
|
{
|
||||||
mCurrentTime = std::min(mStopTime, targetTime);
|
mCurrentTime = targetTime;
|
||||||
if(mNonAccumRoot)
|
if(mNonAccumRoot)
|
||||||
movement += updatePosition();
|
movement += updatePosition();
|
||||||
mPlaying = (mLooping || mStopTime > mCurrentTime);
|
|
||||||
timepassed = targetTime - mCurrentTime;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +460,8 @@ Ogre::Vector3 Animation::runAnimation(float timepassed)
|
||||||
mCurrentTime = time;
|
mCurrentTime = time;
|
||||||
if(mNonAccumRoot)
|
if(mNonAccumRoot)
|
||||||
movement += updatePosition();
|
movement += updatePosition();
|
||||||
mPlaying = (mLooping || mStopTime > mCurrentTime);
|
|
||||||
|
mPlaying = (mLooping || mStopKey->first > mCurrentTime);
|
||||||
timepassed = targetTime - mCurrentTime;
|
timepassed = targetTime - mCurrentTime;
|
||||||
|
|
||||||
if(!handleEvent(time, evt))
|
if(!handleEvent(time, evt))
|
||||||
|
|
|
@ -50,13 +50,14 @@ protected:
|
||||||
Ogre::Bone *mNonAccumRoot;
|
Ogre::Bone *mNonAccumRoot;
|
||||||
Ogre::Vector3 mAccumulate;
|
Ogre::Vector3 mAccumulate;
|
||||||
Ogre::Vector3 mLastPosition;
|
Ogre::Vector3 mLastPosition;
|
||||||
|
Ogre::Animation *mCurrentAnim;
|
||||||
|
|
||||||
std::vector<Ogre::Controller<Ogre::Real> > *mCurrentControllers;
|
std::vector<Ogre::Controller<Ogre::Real> > *mCurrentControllers;
|
||||||
NifOgre::TextKeyMap *mCurrentKeys;
|
NifOgre::TextKeyMap *mCurrentKeys;
|
||||||
|
NifOgre::TextKeyMap::const_iterator mStartKey;
|
||||||
|
NifOgre::TextKeyMap::const_iterator mStopKey;
|
||||||
NifOgre::TextKeyMap::const_iterator mNextKey;
|
NifOgre::TextKeyMap::const_iterator mNextKey;
|
||||||
Ogre::Animation *mCurrentAnim;
|
|
||||||
float mCurrentTime;
|
float mCurrentTime;
|
||||||
float mStopTime;
|
|
||||||
bool mPlaying;
|
bool mPlaying;
|
||||||
bool mLooping;
|
bool mLooping;
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ protected:
|
||||||
* moving anything, and set the end time to the specified stop marker. If
|
* moving anything, and set the end time to the specified stop marker. If
|
||||||
* the marker is not found, it resets to the beginning or end respectively.
|
* the marker is not found, it resets to the beginning or end respectively.
|
||||||
*/
|
*/
|
||||||
void reset(const std::string &start, const std::string &stop);
|
void reset(const std::string &start, const std::string &stop=std::string());
|
||||||
|
|
||||||
bool handleEvent(float time, const std::string &evt);
|
bool handleEvent(float time, const std::string &evt);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue