#include <map>
#include <vector>
+#include <Moof/Library.hh>
#include <Moof/Log.hh>
-#include <Moof/Mippleton.hh>
#include <Moof/Script.hh>
#include "Animation.hh"
* which wants to use these loaded sequences.
*/
- class Data : public Mf::Mippleton<Data>
+ class Data : public Mf::Library<Data>
{
friend class Impl;
- friend class Mf::Mippleton<Data>;
+ friend class Mf::Library<Data>;
/**
* A frame of an animation sequence. A frame is merely an index which
* and the duration that is how long the slide will be shown.
*/
- struct Frame
+ class Frame
{
- unsigned index; ///< Frame index.
- Mf::Scalar duration; ///< Frame duration.
+ friend class Impl;
+
+ unsigned mIndex; ///< Frame index.
+ Mf::Scalar mDuration; ///< Frame duration.
/**
* Construction is initialization. The frame data is loaded from a
*/
Frame(Mf::Script& script, Mf::Script::Value table) :
- index(0),
- duration(1.0)
+ mIndex(0),
+ mDuration(1.0)
{
table.pushField("index");
- script[-1].get(index);
+ script[-1].get(mIndex);
script.pop();
table.pushField("duration");
- script[-1].get(duration);
+ script[-1].get(mDuration);
script.pop();
}
};
struct Sequence
{
- std::vector<Frame> frames; ///< List of frames.
- Mf::Scalar delay; ///< Scale frame durations.
- bool loop; ///< Does the sequence repeat?
- std::string next; ///< Next sequence name.
+ friend class Impl;
+
+ std::vector<Frame> mFrames; ///< List of frames.
+ Mf::Scalar mDelay; ///< Scale frame durations.
+ bool mLoop; ///< Does the sequence repeat?
+ std::string mNext; ///< Next sequence name.
/**
* Construction is initialization. The constructor loads sequence
*/
Sequence(Mf::Script& script, Mf::Script::Value table) :
- delay(0.0),
- loop(true)
+ mDelay(0.0),
+ mLoop(true)
{
table.pushField("delay");
- script[-1].get(delay);
+ script[-1].get(mDelay);
script.pop();
table.pushField("loop");
- script[-1].get(loop);
+ script[-1].get(mLoop);
script.pop();
table.pushField("next");
- script[-1].get(next);
+ script[-1].get(mNext);
script.pop();
// TODO - sequence class/type not yet implemented
script.push(index);
frameTable.pushField();
- if (top.isTable()) frames.push_back(Frame(script, top));
+ if (top.isTable()) mFrames.push_back(Frame(script, top));
else break;
++index;
Mf::Script script;
std::string filePath = Animation::getPath(getName());
- script.importStandardLibraries();
- importLogScript(script);
+ script.importBaseLibrary();
+ importLogPrintFunction(script);
importAnimationBindings(script);
if (script.doFile(filePath) != Mf::Script::SUCCESS)
*/
explicit Data(const std::string& name) :
- Mf::Mippleton<Data>(name)
+ Mf::Library<Data>(name)
{
loadFromFile();
}
*/
Impl(const std::string& name) :
- data(Data::getInstance(name)),
- currentSequence(0),
- frameCounter(0),
- frameIndex(0),
- timeAccum(0),
- frameDuration(0) {}
+ mData(Data::getInstance(name)),
+ mCurrentSequence(0),
+ mFrameCounter(0),
+ mFrameIndex(0),
+ mTimeAccum(0),
+ mFrameDuration(0) {}
/**
{
std::map<std::string,Data::Sequence>::iterator it;
- it = data->sequences.find(name);
+ it = mData->sequences.find(name);
- if (it != data->sequences.end())
+ if (it != mData->sequences.end())
{
- currentSequence = &(*it).second;
- frameCounter = 0;
- frameIndex = currentSequence->frames[0].index;
- timeAccum = 0.0;
- frameDuration = currentSequence->delay *
- currentSequence->frames[0].duration;
+ mCurrentSequence = &(*it).second;
+ mFrameCounter = 0;
+ mFrameIndex = mCurrentSequence->mFrames[0].mIndex;
+ mTimeAccum = 0.0;
+ mFrameDuration = mCurrentSequence->mDelay *
+ mCurrentSequence->mFrames[0].mDuration;
}
}
void update(Mf::Scalar t, Mf::Scalar dt)
{
- if (currentSequence)
+ if (mCurrentSequence)
{
- timeAccum += dt;
+ mTimeAccum += dt;
- if (timeAccum >= frameDuration)
+ if (mTimeAccum >= mFrameDuration)
{
- if (++frameCounter >= currentSequence->frames.size())
+ if (++mFrameCounter >= mCurrentSequence->mFrames.size())
{
- if (!currentSequence->next.empty())
+ if (!mCurrentSequence->mNext.empty())
{
- startSequence(currentSequence->next);
+ startSequence(mCurrentSequence->mNext);
}
- else if (currentSequence->loop)
+ else if (mCurrentSequence->mLoop)
{
- frameCounter = 0;
+ mFrameCounter = 0;
}
else
{
- frameCounter--;
- currentSequence = 0;
+ mFrameCounter--;
+ mCurrentSequence = 0;
}
}
- frameIndex = currentSequence->frames[frameCounter].index;
- timeAccum = frameDuration - timeAccum;
- frameDuration = currentSequence->delay *
- currentSequence->frames[frameCounter].duration;
+ mFrameIndex = mCurrentSequence->mFrames[mFrameCounter].mIndex;
+ mTimeAccum = mFrameDuration - mTimeAccum;
+ mFrameDuration = mCurrentSequence->mDelay *
+ mCurrentSequence->mFrames[mFrameCounter].mDuration;
}
}
}
- boost::shared_ptr<Data> data; ///< Internal data.
+ boost::shared_ptr<Data> mData; ///< Internal data.
- Data::Sequence* currentSequence; ///< Active sequence.
- unsigned frameCounter; ///< Current frame.
- unsigned frameIndex; ///< Index of current frame.
- Mf::Scalar timeAccum; ///< Time accumulation.
- Mf::Scalar frameDuration; ///< Scaled frame duration.
+ Data::Sequence* mCurrentSequence; ///< Active sequence.
+ unsigned mFrameCounter; ///< Current frame.
+ unsigned mFrameIndex; ///< Index of current frame.
+ Mf::Scalar mTimeAccum; ///< Time accumulation.
+ Mf::Scalar mFrameDuration; ///< Scaled frame duration.
};
Animation::Animation(const std::string& name) :
// pass through
- impl_(new Animation::Impl(name)) {}
+ mImpl(new Animation::Impl(name)) {}
void Animation::startSequence(const std::string& name)
{
// pass through
- impl_->startSequence(name);
+ mImpl->startSequence(name);
}
void Animation::update(Mf::Scalar t, Mf::Scalar dt)
{
// pass through
- impl_->update(t, dt);
+ mImpl->update(t, dt);
}
unsigned Animation::getFrame() const
{
- return impl_->frameIndex;
+ return mImpl->mFrameIndex;
}