#include <map>
#include <vector>
-#include "serializable.hh"
-#include "mippleton.hh"
-#include "animation.hh"
+#include "Animation.hh"
+#include "Mippleton.hh"
+#include "Serializable.hh"
-namespace dc {
+namespace Mf {
/**
* The collection of nested animation classes. The animation implementation
- * consists of an animation_impl classes which is allocated and initialized with
+ * consists of an AnimationImpl classes 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 difference class which can be shared amongst multiple animation
* implementation instances.
*/
-struct animation::animation_impl
+struct Animation::AnimationImpl
{
/**
* which wants to use these loaded sequences.
*/
- struct animation_data : public mippleton<animation_data>
+ struct AnimationData : public Mippleton<AnimationData>
{
/**
* 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
+ struct Frame
{
unsigned index; ///< Frame index.
- scalar duration; ///< Frame duration.
+ Scalar duration; ///< Frame duration.
/**
* Construction is initialization. The frame data is loaded from a
* frame map which is probably loaded within an animation file.
*/
- frame(serializable_ptr root) :
+ Frame(SerializablePtr root) :
index(0),
duration(1.0)
{
- std::map<std::string,serializable_ptr> rootObj;
+ std::map<std::string,SerializablePtr> rootObj;
if (root->get(rootObj))
{
- std::map<std::string,serializable_ptr>::iterator i;
- for (i = rootObj.begin(); i != rootObj.end(); i++)
+ std::map<std::string,SerializablePtr>::iterator it;
+
+ for (it = rootObj.begin(); it != rootObj.end(); it++)
{
- std::string key = (*i).first;
+ std::string key = (*it).first;
if (key == "index")
{
long value = 0;
- (*i).second->get(value);
+ (*it).second->get(value);
index = unsigned(value);
}
else if (key == "duration")
{
double value = 0.0;
- (*i).second->getNumber(value);
- duration = scalar(value);
+ (*it).second->getNumber(value);
+ duration = Scalar(value);
}
}
}
* that they should be played.
*/
- struct sequence
+ struct Sequence
{
- std::vector<frame> frames; ///< List of frames.
- scalar delay; ///< Scale frame durations.
+ std::vector<Frame> frames; ///< List of frames.
+ Scalar delay; ///< Scale frame durations.
bool loop; ///< Does the sequence repeat?
std::string next; ///< Next sequence name.
* constructor which loads each individual frame.
*/
- sequence(serializable_ptr root) :
+ Sequence(SerializablePtr root) :
delay(0.0),
loop(true)
{
- std::map<std::string,serializable_ptr> rootObj;
+ std::map<std::string,SerializablePtr> rootObj;
if (root->get(rootObj))
{
- std::map<std::string,serializable_ptr>::iterator i;
- for (i = rootObj.begin(); i != rootObj.end(); i++)
+ std::map<std::string,SerializablePtr>::iterator it;
+ for (it = rootObj.begin(); it != rootObj.end(); it++)
{
- std::string key = (*i).first;
+ std::string key = (*it).first;
if (key == "frames")
{
- std::vector<serializable_ptr> framesObj;
+ std::vector<SerializablePtr> framesObj;
- if ((*i).second->get(framesObj))
+ if ((*it).second->get(framesObj))
{
- std::vector<serializable_ptr>::iterator j;
+ std::vector<SerializablePtr>::iterator jt;
- for (j = framesObj.begin();
- j != framesObj.end(); j++)
+ for (jt = framesObj.begin();
+ jt != framesObj.end(); jt++)
{
- if (*j)
+ if (*jt)
{
- frames.push_back(frame(*j));
+ frames.push_back(Frame(*jt));
}
}
}
else if (key == "delay")
{
double value;
- (*i).second->getNumber(value);
- delay = scalar(value);
+ (*it).second->getNumber(value);
+ delay = Scalar(value);
}
else if (key == "loop")
{
- (*i).second->get(loop);
+ (*it).second->get(loop);
}
else if (key == "next")
{
- (*i).second->get(next);
+ (*it).second->get(next);
}
}
}
void loadFromFile()
{
- std::string filePath = animation::getPathToResource(getName());
+ std::string filePath = Animation::getPathToResource(getName());
- deserializer in(filePath);
+ Deserializer deserializer(filePath);
- serializable_ptr root = in.deserialize();
+ SerializablePtr root = deserializer.deserialize();
if (root)
{
- std::map<std::string,serializable_ptr> rootObj;
+ std::map<std::string,SerializablePtr> rootObj;
if (root->get(rootObj))
{
- std::map<std::string,serializable_ptr>::iterator i;
+ std::map<std::string,SerializablePtr>::iterator it;
- for (i = rootObj.begin(); i != rootObj.end(); i++)
+ for (it = rootObj.begin(); it != rootObj.end(); it++)
{
- sequences.insert(std::pair<std::string,sequence>((*i).first,
- sequence((*i).second)));
+ sequences.insert(std::pair<std::string,Sequence>((*it).first,
+ Sequence((*it).second)));
}
}
}
* registers itself as a mippleton and then loads the animation data.
*/
- explicit animation_data(const std::string& name) :
- mippleton<animation_data>(name)
+ explicit AnimationData(const std::string& name) :
+ Mippleton<AnimationData>(name)
{
loadFromFile();
}
- std::map<std::string,sequence> sequences; ///< List of sequences.
+ std::map<std::string,Sequence> sequences; ///< List of sequences.
};
* Construction is intialization.
*/
- animation_impl(const std::string& name) :
- data(animation_data::retain(name), &animation_data::release),
+ AnimationImpl(const std::string& name) :
+ data(AnimationData::retain(name), &AnimationData::release),
currentSequence(0),
frameCounter(0),
frameIndex(0),
* updates will progress the new sequence.
*/
- void startSequence(const std::string& sequenceName)
+ void startSequence(const std::string& name)
{
- std::map<std::string,animation_data::sequence>::iterator i;
+ std::map<std::string,AnimationData::Sequence>::iterator it;
- i = data->sequences.find(sequenceName);
+ it = data->sequences.find(name);
- if (i != data->sequences.end())
+ if (it != data->sequences.end())
{
- currentSequence = &(*i).second;
+ currentSequence = &(*it).second;
frameCounter = 0;
frameIndex = currentSequence->frames[0].index;
timeAccum = 0.0;
* starts over again.
*/
- void update(scalar t, scalar dt)
+ void update(Scalar t, Scalar dt)
{
if (currentSequence)
{
}
}
- boost::shared_ptr<animation_data> data; ///< Internal data.
+ boost::shared_ptr<AnimationData> data; ///< Internal data.
- animation_data::sequence* currentSequence; ///< Active sequence.
+ AnimationData::Sequence* currentSequence; ///< Active sequence.
unsigned frameCounter; ///< Current frame.
unsigned frameIndex; ///< Index of current frame.
- scalar timeAccum; ///< Time accumulation.
- scalar frameDuration; ///< Scaled frame duration.
+ Scalar timeAccum; ///< Time accumulation.
+ Scalar frameDuration; ///< Scaled frame duration.
};
-animation::animation(const std::string& name) :
+Animation::Animation(const std::string& name) :
// pass through
- impl(new animation::animation_impl(name)) {}
+ impl_(new Animation::AnimationImpl(name)) {}
-void animation::startSequence(const std::string& sequenceName)
+void Animation::startSequence(const std::string& name)
{
// pass through
- impl->startSequence(sequenceName);
+ impl_->startSequence(name);
}
-void animation::update(scalar t, scalar dt)
+void Animation::update(Scalar t, Scalar dt)
{
// pass through
- impl->update(t, dt);
+ impl_->update(t, dt);
}
* drawing code which will draw the correct current frame.
*/
-unsigned animation::getFrame() const
+unsigned Animation::getFrame() const
{
- return impl->frameIndex;
+ return impl_->frameIndex;
}
* "animations" subdirectory of any of the searched directories.
*/
-std::string animation::getPathToResource(const std::string& name)
+std::string Animation::getPathToResource(const std::string& name)
{
- return resource::getPathToResource("animations/" + name + ".json");
+ return Resource::getPathToResource("animations/" + name + ".json");
}
-} // namespace dc
+} // namespace Mf
/** vim: set ts=4 sw=4 tw=80: *************************************************/