/**
* The collection of nested animation classes. The animation implementation
- * 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.
+ * 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.
*/
-struct Animation::AnimationImpl
+class Animation::Impl
{
+ friend class Animation;
/**
* Contains "global" animation data for the various animations which get
* which wants to use these loaded sequences.
*/
- struct AnimationData : public Mippleton<AnimationData>
+ class Data : public Mippleton<Data>
{
+ friend class Impl;
+ friend class Mippleton<Data>;
+
/**
* A frame of an animation sequence. A frame is merely an index which
* presumably represents a "slide" or tile which should be displayed,
* frame map which is probably loaded within an animation file.
*/
- Frame(SerializablePtr root) :
+ Frame(SerializableP root) :
index(0),
duration(1.0)
{
- std::map<std::string,SerializablePtr> rootObj;
+ Serializable::Map rootObj;
if (root->get(rootObj))
{
- std::map<std::string,SerializablePtr>::iterator it;
+ Serializable::Map::iterator it;
for (it = rootObj.begin(); it != rootObj.end(); ++it)
{
* constructor which loads each individual frame.
*/
- Sequence(SerializablePtr root) :
+ Sequence(SerializableP root) :
delay(0.0),
loop(true)
{
- std::map<std::string,SerializablePtr> rootObj;
+ Serializable::Map rootObj;
if (root->get(rootObj))
{
- std::map<std::string,SerializablePtr>::iterator it;
+ Serializable::Map::iterator it;
for (it = rootObj.begin(); it != rootObj.end(); ++it)
{
std::string key = (*it).first;
if (key == "frames")
{
- std::vector<SerializablePtr> framesObj;
+ Serializable::Array framesObj;
if ((*it).second->get(framesObj))
{
- std::vector<SerializablePtr>::iterator jt;
+ Serializable::Array::iterator jt;
for (jt = framesObj.begin();
jt != framesObj.end(); ++jt)
void loadFromFile()
{
- std::string filePath = Animation::getPathToResource(getName());
+ std::string filePath = Animation::getPath(getName());
Deserializer deserializer(filePath);
- SerializablePtr root = deserializer.deserialize();
+ SerializableP root = deserializer.deserialize();
if (root)
{
- std::map<std::string,SerializablePtr> rootObj;
+ Serializable::Map rootObj;
if (root->get(rootObj))
{
- std::map<std::string,SerializablePtr>::iterator it;
+ Serializable::Map::iterator it;
for (it = rootObj.begin(); it != rootObj.end(); ++it)
{
* registers itself as a mippleton and then loads the animation data.
*/
- explicit AnimationData(const std::string& name) :
- Mippleton<AnimationData>(name)
+ explicit Data(const std::string& name) :
+ Mippleton<Data>(name)
{
loadFromFile();
}
* Construction is intialization.
*/
- AnimationImpl(const std::string& name) :
- data(AnimationData::retain(name), &AnimationData::release),
+ Impl(const std::string& name) :
+ data(Data::getInstance(name)),
currentSequence(0),
frameCounter(0),
frameIndex(0),
void startSequence(const std::string& name)
{
- std::map<std::string,AnimationData::Sequence>::iterator it;
+ std::map<std::string,Data::Sequence>::iterator it;
it = data->sequences.find(name);
}
}
- boost::shared_ptr<AnimationData> data; ///< Internal data.
+ boost::shared_ptr<Data> data; ///< Internal data.
- AnimationData::Sequence* currentSequence; ///< Active sequence.
- unsigned frameCounter; ///< Current frame.
- unsigned frameIndex; ///< Index of current frame.
- Scalar timeAccum; ///< Time accumulation.
- Scalar frameDuration; ///< Scaled frame duration.
+ Data::Sequence* currentSequence; ///< Active sequence.
+ unsigned frameCounter; ///< Current frame.
+ unsigned frameIndex; ///< Index of current frame.
+ Scalar timeAccum; ///< Time accumulation.
+ Scalar frameDuration; ///< Scaled frame duration.
};
Animation::Animation(const std::string& name) :
// pass through
- impl_(new Animation::AnimationImpl(name)) {}
+ impl_(new Animation::Impl(name)) {}
void Animation::startSequence(const std::string& name)
* "animations" subdirectory of any of the searched directories.
*/
-std::string Animation::getPathToResource(const std::string& name)
+std::string Animation::getPath(const std::string& name)
{
- return Resource::getPathToResource("animations/" + name + ".json");
+ return Resource::getPath("animations/" + name + ".json");
}