1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-14 15:40:18 +00:00

Rename animation layers to animation states

This commit is contained in:
Chris Robinson 2013-05-10 04:01:30 -07:00
parent ccff364b52
commit 58efce5008
2 changed files with 59 additions and 62 deletions

View File

@ -20,17 +20,14 @@ namespace MWRender
Ogre::Real Animation::AnimationValue::getValue() const Ogre::Real Animation::AnimationValue::getValue() const
{ {
AnimLayerMap::const_iterator iter = mAnimation->mLayers.find(mAnimation->mAnimationName); AnimStateMap::const_iterator iter = mAnimation->mStates.find(mAnimation->mAnimationName);
if(iter != mAnimation->mLayers.end()) if(iter != mAnimation->mStates.end())
return iter->second.mTime; return iter->second.mTime;
return 0.0f; return 0.0f;
} }
void Animation::AnimationValue::setValue(Ogre::Real value) void Animation::AnimationValue::setValue(Ogre::Real)
{ {
AnimLayerMap::iterator iter = mAnimation->mLayers.find(mAnimation->mAnimationName);
if(iter != mAnimation->mLayers.end())
iter->second.mTime = value;
} }
@ -197,7 +194,7 @@ void Animation::addAnimSource(const std::string &model)
void Animation::clearAnimSources() void Animation::clearAnimSources()
{ {
mLayers.clear(); mStates.clear();
mSource = NULL; mSource = NULL;
mAnimationName.empty(); mAnimationName.empty();
@ -356,7 +353,7 @@ void Animation::updatePosition(float time, Ogre::Vector3 &position)
mAccumRoot->setPosition(-mLastPosition); mAccumRoot->setPosition(-mLastPosition);
} }
bool Animation::reset(AnimLayer &layer, const NifOgre::TextKeyMap &keys, NifOgre::NodeTargetValue<Ogre::Real> *nonaccumctrl, const std::string &groupname, const std::string &start, const std::string &stop, float startpoint) bool Animation::reset(AnimState &state, const NifOgre::TextKeyMap &keys, NifOgre::NodeTargetValue<Ogre::Real> *nonaccumctrl, const std::string &groupname, const std::string &start, const std::string &stop, float startpoint)
{ {
std::string tag = groupname+": "+start; std::string tag = groupname+": "+start;
NifOgre::TextKeyMap::const_iterator startkey(keys.begin()); NifOgre::TextKeyMap::const_iterator startkey(keys.begin());
@ -382,45 +379,45 @@ bool Animation::reset(AnimLayer &layer, const NifOgre::TextKeyMap &keys, NifOgre
if(startkey == stopkey) if(startkey == stopkey)
return false; return false;
layer.mStartKey = startkey; state.mStartKey = startkey;
layer.mLoopStartKey = startkey; state.mLoopStartKey = startkey;
layer.mStopKey = stopkey; state.mStopKey = stopkey;
layer.mNextKey = startkey; state.mNextKey = startkey;
layer.mTime = layer.mStartKey->first + ((layer.mStopKey->first - layer.mStartKey->first) * startpoint); state.mTime = state.mStartKey->first + ((state.mStopKey->first - state.mStartKey->first) * startpoint);
tag = groupname+": loop start"; tag = groupname+": loop start";
while(layer.mNextKey->first <= layer.mTime && layer.mNextKey != layer.mStopKey) while(state.mNextKey->first <= state.mTime && state.mNextKey != state.mStopKey)
{ {
if(layer.mNextKey->second == tag) if(state.mNextKey->second == tag)
layer.mLoopStartKey = layer.mNextKey; state.mLoopStartKey = state.mNextKey;
layer.mNextKey++; state.mNextKey++;
} }
if(nonaccumctrl) if(nonaccumctrl)
mLastPosition = nonaccumctrl->getTranslation(layer.mTime) * mAccumulate; mLastPosition = nonaccumctrl->getTranslation(state.mTime) * mAccumulate;
return true; return true;
} }
bool Animation::doLoop(AnimLayer &layer) bool Animation::doLoop(AnimState &state)
{ {
if(layer.mLoopCount == 0) if(state.mLoopCount == 0)
return false; return false;
layer.mLoopCount--; state.mLoopCount--;
layer.mTime = layer.mLoopStartKey->first; state.mTime = state.mLoopStartKey->first;
layer.mNextKey = layer.mLoopStartKey; state.mNextKey = state.mLoopStartKey;
layer.mNextKey++; state.mNextKey++;
layer.mPlaying = true; state.mPlaying = true;
if(mNonAccumCtrl) if(mNonAccumCtrl)
mLastPosition = mNonAccumCtrl->getTranslation(layer.mTime) * mAccumulate; mLastPosition = mNonAccumCtrl->getTranslation(state.mTime) * mAccumulate;
return true; return true;
} }
bool Animation::handleTextKey(AnimLayer &layer, const std::string &groupname, const NifOgre::TextKeyMap::const_iterator &key) bool Animation::handleTextKey(AnimState &state, const std::string &groupname, const NifOgre::TextKeyMap::const_iterator &key)
{ {
float time = key->first; float time = key->first;
const std::string &evt = key->second; const std::string &evt = key->second;
@ -449,15 +446,15 @@ bool Animation::handleTextKey(AnimLayer &layer, const std::string &groupname, co
if(evt.compare(off, len, "start") == 0 || evt.compare(off, len, "loop start") == 0) if(evt.compare(off, len, "start") == 0 || evt.compare(off, len, "loop start") == 0)
{ {
layer.mLoopStartKey = key; state.mLoopStartKey = key;
return true; return true;
} }
if(evt.compare(off, len, "loop stop") == 0 || evt.compare(off, len, "stop") == 0) if(evt.compare(off, len, "loop stop") == 0 || evt.compare(off, len, "stop") == 0)
{ {
if(doLoop(layer)) if(doLoop(state))
{ {
if(layer.mTime >= time) if(state.mTime >= time)
return false; return false;
} }
return true; return true;
@ -473,11 +470,11 @@ bool Animation::play(const std::string &groupname, const std::string &start, con
if(!mSkelBase || groupname.empty()) if(!mSkelBase || groupname.empty())
return false; return false;
AnimLayerMap::iterator layeriter = mLayers.find(groupname); AnimStateMap::iterator stateiter = mStates.find(groupname);
if(layeriter != mLayers.end()) if(stateiter != mStates.end())
mLayers.erase(layeriter); mStates.erase(stateiter);
// HACK: Don't clear all active animations // HACK: Don't clear all active animations
mLayers.clear(); mStates.clear();
bool movinganim = false; bool movinganim = false;
bool foundanim = false; bool foundanim = false;
@ -504,14 +501,14 @@ bool Animation::play(const std::string &groupname, const std::string &start, con
if(!foundanim) if(!foundanim)
{ {
AnimLayer layer; AnimState state;
if(!reset(layer, keys, nonaccumctrl, groupname, start, stop, startpoint)) if(!reset(state, keys, nonaccumctrl, groupname, start, stop, startpoint))
continue; continue;
foundanim = true; foundanim = true;
layer.mLoopCount = loops; state.mLoopCount = loops;
layer.mPlaying = true; state.mPlaying = true;
mLayers[groupname] = layer; mStates[groupname] = state;
// FIXME // FIXME
mSource = &*iter; mSource = &*iter;
@ -542,8 +539,8 @@ bool Animation::play(const std::string &groupname, const std::string &start, con
bool Animation::getInfo(const std::string &groupname, float *complete, std::string *start, std::string *stop) const bool Animation::getInfo(const std::string &groupname, float *complete, std::string *start, std::string *stop) const
{ {
AnimLayerMap::const_iterator iter = mLayers.find(groupname); AnimStateMap::const_iterator iter = mStates.find(groupname);
if(iter == mLayers.end()) if(iter == mStates.end())
{ {
if(complete) *complete = 0.0f; if(complete) *complete = 0.0f;
if(start) *start = ""; if(start) *start = "";
@ -564,31 +561,31 @@ Ogre::Vector3 Animation::runAnimation(float duration)
Ogre::Vector3 movement(0.0f); Ogre::Vector3 movement(0.0f);
duration *= mAnimSpeedMult; duration *= mAnimSpeedMult;
AnimLayerMap::iterator layeriter = mLayers.begin(); AnimStateMap::iterator stateiter = mStates.begin();
for(;layeriter != mLayers.end();layeriter++) for(;stateiter != mStates.end();stateiter++)
{ {
AnimLayer &layer = layeriter->second; AnimState &state = stateiter->second;
float timepassed = duration; float timepassed = duration;
while(layer.mPlaying) while(state.mPlaying)
{ {
float targetTime = layer.mTime + timepassed; float targetTime = state.mTime + timepassed;
if(layer.mNextKey->first > targetTime) if(state.mNextKey->first > targetTime)
{ {
layer.mTime = targetTime; state.mTime = targetTime;
if(mNonAccumCtrl) if(mNonAccumCtrl)
updatePosition(layer.mTime, movement); updatePosition(state.mTime, movement);
break; break;
} }
NifOgre::TextKeyMap::const_iterator key(layer.mNextKey++); NifOgre::TextKeyMap::const_iterator key(state.mNextKey++);
layer.mTime = key->first; state.mTime = key->first;
if(mNonAccumCtrl) if(mNonAccumCtrl)
updatePosition(layer.mTime, movement); updatePosition(state.mTime, movement);
layer.mPlaying = (key != layer.mStopKey); state.mPlaying = (key != state.mStopKey);
timepassed = targetTime - layer.mTime; timepassed = targetTime - state.mTime;
if(!handleTextKey(layer, layeriter->first, key)) if(!handleTextKey(state, stateiter->first, key))
break; break;
} }
} }

View File

@ -35,7 +35,7 @@ protected:
}; };
typedef std::vector<AnimSource> AnimSourceList; typedef std::vector<AnimSource> AnimSourceList;
struct AnimLayer { struct AnimState {
NifOgre::TextKeyMap::const_iterator mStartKey; NifOgre::TextKeyMap::const_iterator mStartKey;
NifOgre::TextKeyMap::const_iterator mLoopStartKey; NifOgre::TextKeyMap::const_iterator mLoopStartKey;
NifOgre::TextKeyMap::const_iterator mStopKey; NifOgre::TextKeyMap::const_iterator mStopKey;
@ -46,10 +46,10 @@ protected:
bool mPlaying; bool mPlaying;
size_t mLoopCount; size_t mLoopCount;
AnimLayer() : mTime(0.0f), mPlaying(false), mLoopCount(0) AnimState() : mTime(0.0f), mPlaying(false), mLoopCount(0)
{ } { }
}; };
typedef std::map<std::string,AnimLayer> AnimLayerMap; typedef std::map<std::string,AnimState> AnimStateMap;
MWWorld::Ptr mPtr; MWWorld::Ptr mPtr;
@ -66,7 +66,7 @@ protected:
float mAnimVelocity; float mAnimVelocity;
float mAnimSpeedMult; float mAnimSpeedMult;
AnimLayerMap mLayers; AnimStateMap mStates;
// Note: One per animation group (lower body, upper body, left arm, etc). // Note: One per animation group (lower body, upper body, left arm, etc).
AnimSource *mSource; AnimSource *mSource;
@ -93,14 +93,14 @@ protected:
* the marker is not found, or if the markers are the same, it returns * the marker is not found, or if the markers are the same, it returns
* false. * false.
*/ */
bool reset(AnimLayer &layer, const NifOgre::TextKeyMap &keys, bool reset(AnimState &state, const NifOgre::TextKeyMap &keys,
NifOgre::NodeTargetValue<Ogre::Real> *nonaccumctrl, NifOgre::NodeTargetValue<Ogre::Real> *nonaccumctrl,
const std::string &groupname, const std::string &start, const std::string &stop, const std::string &groupname, const std::string &start, const std::string &stop,
float startpoint); float startpoint);
bool doLoop(AnimLayer &layer); bool doLoop(AnimState &state);
bool handleTextKey(AnimLayer &layer, const std::string &groupname, const NifOgre::TextKeyMap::const_iterator &key); bool handleTextKey(AnimState &state, const std::string &groupname, const NifOgre::TextKeyMap::const_iterator &key);
void setObjectRoot(Ogre::SceneNode *node, const std::string &model, bool baseonly); void setObjectRoot(Ogre::SceneNode *node, const std::string &model, bool baseonly);
void addAnimSource(const std::string &model); void addAnimSource(const std::string &model);