**************************************************************************/
#include <map>
+#include <stdexcept>
#include <vector>
-#include <Moof/Error.hh>
-#include <Moof/Manager.hh>
-#include <Moof/Log.hh>
-#include <Moof/Script.hh>
+#include <moof/manager.hh>
+#include <moof/log.hh>
+#include <moof/script.hh>
#include "Animation.hh"
/**
* The collection of nested animation classes. The animation
- * implementation consists of an Impl class which is allocated and
+ * implementation consists of an impl class which is allocated and
* initialized with the interface object. This class contains the specific
* fields which are required to run a single instance of an animation. The
* sequence data is loaded in a different class which can be shared amongst
* multiple animation implementation instances.
*/
-class Animation::Impl
+class Animation::impl
{
public:
* animation which wants to use these loaded sequences.
*/
- class Data : public Mf::Manager<Data>
+ class Data : public moof::manager<Data>
{
public:
public:
unsigned mIndex; ///< Frame index.
- Mf::Scalar mDuration; ///< Frame duration.
+ moof::scalar mDuration; ///< Frame duration.
/**
* Construction is initialization. The frame data is loaded
* animation file.
*/
- Frame(const Mf::Script::Slot& table) :
+ Frame(const moof::script::slot& table) :
mIndex(0),
mDuration(1.0)
{
public:
std::vector<Frame> mFrames; ///< List of frames.
- Mf::Scalar mDelay; ///< Scale frame durations.
+ moof::scalar mDelay; ///< Scale frame durations.
bool mLoop; ///< Does the sequence repeat?
std::string mNext; ///< Next sequence name.
* the frame's constructor which loads each individual frame.
*/
- Sequence(const Mf::Script::Slot& table) :
+ Sequence(const moof::script::slot& table) :
mDelay(0.0),
mLoop(true)
{
// TODO - sequence class/type not yet implemented
- Mf::Script::Slot frameTable = table.pushField("frames");
- if (frameTable.isTable())
+ moof::script::slot frameTable = table.push_field("frames");
+ if (frameTable.is_table())
{
int max = frameTable.length();
for (int index = 1; index <= max; ++index)
{
- Mf::Script::Slot top = frameTable.pushField(index);
+ moof::script::slot top = frameTable.push_field(index);
- if (top.isTable())
+ if (top.is_table())
{
mFrames.push_back(Frame(top));
}
else
{
- Mf::logWarning << "invalid frame at index "
+ moof::log_warning << "invalid frame at index "
<< index << std::endl;
}
}
void init(const std::string& name)
{
- Mf::Script script;
+ moof::script script;
std::string path(name);
- if (!Animation::getPath(path))
+ if (!resource::find(path))
{
- Mf::Error(Mf::Error::RESOURCE_NOT_FOUND).raise();
+ throw std::runtime_error("cannot find resource " + name);
}
- script.importBaseLibrary();
- importLogFunctions(script);
+ script.import_base_library();
+ moof::log::import(script);
importAnimationBindings(script);
- if (script.doFile(path) != Mf::Script::SUCCESS)
+ if (script.do_file(path) != moof::script::success)
{
std::string str;
script[-1].get(str);
- Mf::logWarning(str);
+ moof::log_warning(str);
}
}
- int defineSequence(Mf::Script& script)
+ int defineSequence(moof::script& script)
{
- Mf::Script::Slot name = script[1].requireString();
- Mf::Script::Slot table = script[2].requireTable();
+ moof::script::slot name = script[1].require_string();
+ moof::script::slot table = script[2].require_table();
std::string nameStr;
name.get(nameStr);
}
- void importAnimationBindings(Mf::Script& script)
+ void importAnimationBindings(moof::script& script)
{
- script.importFunction("DefineSequence",
+ script.import_function("DefineSequence",
boost::bind(&Data::defineSequence,
this, _1));
- script.globals().setField("ATTACK", 1);
- script.globals().setField("CHARGE", 2);
- script.globals().setField("FLY", 3);
- script.globals().setField("HIT", 4);
- script.globals().setField("JUMP", 5);
- script.globals().setField("RUN", 6);
- script.globals().setField("STAND", 7);
+ script.globals().set_field("ATTACK", 1);
+ script.globals().set_field("CHARGE", 2);
+ script.globals().set_field("FLY", 3);
+ script.globals().set_field("HIT", 4);
+ script.globals().set_field("JUMP", 5);
+ script.globals().set_field("RUN", 6);
+ script.globals().set_field("STAND", 7);
}
* Construction is intialization.
*/
- Impl(const std::string& name) :
- mData(Data::getInstance(name)),
+ impl(const std::string& name) :
+ mData(Data::instance(name)),
mCurrentSequence(0),
mFrameCounter(0),
mFrameIndex(0),
* the animation essentially starts over again.
*/
- void update(Mf::Scalar t, Mf::Scalar dt)
+ void update(moof::scalar t, moof::scalar dt)
{
if (!mCurrentSequence) return;
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.
+ moof::scalar mTimeAccum; ///< Time accumulation.
+ moof::scalar mFrameDuration; ///< Scaled frame duration.
};
Animation::Animation(const std::string& name) :
// pass through
- mImpl(new Animation::Impl(name)) {}
+ impl_(new Animation::impl(name)) {}
void Animation::startSequence(const std::string& name)
{
// pass through
- mImpl->startSequence(name);
+ impl_->startSequence(name);
}
-void Animation::update(Mf::Scalar t, Mf::Scalar dt)
+void Animation::update(moof::scalar t, moof::scalar dt)
{
// pass through
- mImpl->update(t, dt);
+ impl_->update(t, dt);
}
unsigned Animation::getFrame() const
{
- return mImpl->mFrameIndex;
-}
-
-
-/**
- * Specialized search location for animation files. They can be found in
- * the "animations" subdirectory of any of the search directories.
- */
-
-bool Animation::getPath(std::string& name)
-{
- return Mf::Resource::getPath(name, "animations/", "lua");
+ return impl_->mFrameIndex;
}