Skip to content

Commit

Permalink
Main: OgreAnimation - range loop refactoring (OGRECave#3225)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joilnen authored Sep 14, 2024
1 parent 1dd386e commit be41d2a
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions OgreMain/src/OgreAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ THE SOFTWARE.
namespace Ogre {

Animation::InterpolationMode Animation::msDefaultInterpolationMode = Animation::IM_LINEAR;
Animation::RotationInterpolationMode
Animation::RotationInterpolationMode
Animation::msDefaultRotationInterpolationMode = Animation::RIM_LINEAR;
//---------------------------------------------------------------------
Animation::Animation(const String& name, Real length)
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace Ogre {
{
if (hasNodeTrack(handle))
{
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
"Node track with the specified handle " +
StringConverter::toString(handle) + " already exists",
"Animation::createNodeTrack");
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace Ogre {

if (i == mNodeTrackList.end())
{
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"Cannot find node track with the specified handle " +
StringConverter::toString(handle),
"Animation::getNodeTrack");
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace Ogre {
{
if (hasNumericTrack(handle))
{
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
"Numeric track with the specified handle " +
StringConverter::toString(handle) + " already exists",
"Animation::createNumericTrack");
Expand Down Expand Up @@ -168,7 +168,7 @@ namespace Ogre {

if (i == mNumericTrackList.end())
{
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"Cannot find numeric track with the specified handle " +
StringConverter::toString(handle),
"Animation::getNumericTrack");
Expand Down Expand Up @@ -200,12 +200,12 @@ namespace Ogre {
_keyFrameListChanged();
}
//---------------------------------------------------------------------
VertexAnimationTrack* Animation::createVertexTrack(unsigned short handle,
VertexAnimationTrack* Animation::createVertexTrack(unsigned short handle,
VertexAnimationType animType)
{
if (hasVertexTrack(handle))
{
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
"Vertex track with the specified handle " +
StringConverter::toString(handle) + " already exists",
"Animation::createVertexTrack");
Expand All @@ -218,7 +218,7 @@ namespace Ogre {

}
//---------------------------------------------------------------------
VertexAnimationTrack* Animation::createVertexTrack(unsigned short handle,
VertexAnimationTrack* Animation::createVertexTrack(unsigned short handle,
VertexData* data, VertexAnimationType animType)
{
VertexAnimationTrack* ret = createVertexTrack(handle, animType);
Expand All @@ -244,7 +244,7 @@ namespace Ogre {

if (i == mVertexTrackList.end())
{
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
"Cannot find vertex track with the specified handle " +
StringConverter::toString(handle),
"Animation::getVertexTrack");
Expand All @@ -268,10 +268,9 @@ namespace Ogre {
//---------------------------------------------------------------------
void Animation::destroyAllVertexTracks(void)
{
VertexTrackList::iterator i;
for (i = mVertexTrackList.begin(); i != mVertexTrackList.end(); ++i)
for (auto& v : mVertexTrackList)
{
OGRE_DELETE i->second;
OGRE_DELETE v.second;
}
mVertexTrackList.clear();
_keyFrameListChanged();
Expand Down Expand Up @@ -323,7 +322,7 @@ namespace Ogre {
}
}
//---------------------------------------------------------------------
void Animation::apply(Skeleton* skel, Real timePos, Real weight,
void Animation::apply(Skeleton* skel, Real timePos, Real weight,
Real scale)
{
_applyBaseKeyFrame();
Expand All @@ -333,7 +332,7 @@ namespace Ogre {

for (auto& t : mNodeTrackList)
{
// get bone to apply to
// get bone to apply to
Bone* b = skel->getBone(t.first);
t.second->applyToNode(b, timeIndex, weight, scale);
}
Expand All @@ -356,7 +355,7 @@ namespace Ogre {
}
}
//---------------------------------------------------------------------
void Animation::apply(Entity* entity, Real timePos, Real weight,
void Animation::apply(Entity* entity, Real timePos, Real weight,
bool software, bool hardware)
{
_applyBaseKeyFrame();
Expand Down Expand Up @@ -394,13 +393,13 @@ namespace Ogre {
if (software)
{
track->setTargetMode(VertexAnimationTrack::TM_SOFTWARE);
track->applyToVertexData(swVertexData, timeIndex, weight,
track->applyToVertexData(swVertexData, timeIndex, weight,
&(entity->getMesh()->getPoseList()));
}
if (hardware)
{
track->setTargetMode(VertexAnimationTrack::TM_HARDWARE);
track->applyToVertexData(hwVertexData, timeIndex, weight,
track->applyToVertexData(hwVertexData, timeIndex, weight,
&(entity->getMesh()->getPoseList()));
}
}
Expand All @@ -423,7 +422,7 @@ namespace Ogre {
void Animation::applyToVertexData(VertexData* data, Real timePos, float weight)
{
_applyBaseKeyFrame();

// Calculate time index for fast keyframe search
TimeIndex timeIndex = _getTimeIndex(timePos);

Expand Down Expand Up @@ -493,7 +492,7 @@ namespace Ogre {
{
optimiseNodeTracks(discardIdentityNodeTracks);
optimiseVertexTracks();

}
//-----------------------------------------------------------------------
void Animation::_collectIdentityNodeTracks(TrackHandleList& tracks) const
Expand Down Expand Up @@ -571,7 +570,7 @@ namespace Ogre {
Animation* newAnim = OGRE_NEW Animation(newName, mLength);
newAnim->mInterpolationMode = mInterpolationMode;
newAnim->mRotationInterpolationMode = mRotationInterpolationMode;

// Clone all tracks
for (auto i : mNodeTrackList)
{
Expand Down Expand Up @@ -684,49 +683,49 @@ namespace Ogre {
Animation* baseAnim = this;
if (!mBaseKeyFrameAnimationName.empty() && mContainer)
baseAnim = mContainer->getAnimation(mBaseKeyFrameAnimationName);

if (baseAnim)
{
for (auto& i : mNodeTrackList)
{
NodeAnimationTrack* track = i.second;

NodeAnimationTrack* baseTrack;
if (baseAnim == this)
baseTrack = track;
else
baseTrack = baseAnim->getNodeTrack(track->getHandle());

TransformKeyFrame kf(baseTrack, mBaseKeyFrameTime);
baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
track->_applyBaseKeyFrame(&kf);
}

for (auto& i : mVertexTrackList)
{
VertexAnimationTrack* track = i.second;

if (track->getAnimationType() == VAT_POSE)
{
VertexAnimationTrack* baseTrack;
if (baseAnim == this)
baseTrack = track;
else
baseTrack = baseAnim->getVertexTrack(track->getHandle());

VertexPoseKeyFrame kf(baseTrack, mBaseKeyFrameTime);
baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
track->_applyBaseKeyFrame(&kf);

}
}

}

// Re-base has been done, this is a one-way translation
mUseBaseKeyFrame = false;
}

}
//-----------------------------------------------------------------------
void Animation::_notifyContainer(AnimationContainer* c)
Expand Down

0 comments on commit be41d2a

Please sign in to comment.