X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FAnimation.cc;h=7eaec1947eb0a69f6d730a986890dbf92c268412;hp=38ffa6c9c5e5c8ca9fdb83806e46f731d9bd274b;hb=f72400af4fa3e7b54dab154b5a2b6503a6f9af18;hpb=493ddb59a8620b49dfa0ff62ce93395ebfd02e86 diff --git a/src/Moof/Animation.cc b/src/Moof/Animation.cc index 38ffa6c..7eaec19 100644 --- a/src/Moof/Animation.cc +++ b/src/Moof/Animation.cc @@ -39,15 +39,16 @@ namespace Mf { /** * 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 @@ -55,8 +56,11 @@ struct Animation::AnimationImpl * which wants to use these loaded sequences. */ - struct AnimationData : public Mippleton + class Data : public Mippleton { + friend class Impl; + friend class Mippleton; + /** * A frame of an animation sequence. A frame is merely an index which * presumably represents a "slide" or tile which should be displayed, @@ -73,15 +77,15 @@ struct Animation::AnimationImpl * frame map which is probably loaded within an animation file. */ - Frame(SerializablePtr root) : + Frame(SerializableP root) : index(0), duration(1.0) { - std::map rootObj; + Serializable::Map rootObj; if (root->get(rootObj)) { - std::map::iterator it; + Serializable::Map::iterator it; for (it = rootObj.begin(); it != rootObj.end(); ++it) { @@ -123,26 +127,26 @@ struct Animation::AnimationImpl * constructor which loads each individual frame. */ - Sequence(SerializablePtr root) : + Sequence(SerializableP root) : delay(0.0), loop(true) { - std::map rootObj; + Serializable::Map rootObj; if (root->get(rootObj)) { - std::map::iterator it; + Serializable::Map::iterator it; for (it = rootObj.begin(); it != rootObj.end(); ++it) { std::string key = (*it).first; if (key == "frames") { - std::vector framesObj; + Serializable::Array framesObj; if ((*it).second->get(framesObj)) { - std::vector::iterator jt; + Serializable::Array::iterator jt; for (jt = framesObj.begin(); jt != framesObj.end(); ++jt) @@ -182,19 +186,19 @@ struct Animation::AnimationImpl 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 rootObj; + Serializable::Map rootObj; if (root->get(rootObj)) { - std::map::iterator it; + Serializable::Map::iterator it; for (it = rootObj.begin(); it != rootObj.end(); ++it) { @@ -210,8 +214,8 @@ struct Animation::AnimationImpl * registers itself as a mippleton and then loads the animation data. */ - explicit AnimationData(const std::string& name) : - Mippleton(name) + explicit Data(const std::string& name) : + Mippleton(name) { loadFromFile(); } @@ -224,8 +228,8 @@ struct Animation::AnimationImpl * 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), @@ -241,7 +245,7 @@ struct Animation::AnimationImpl void startSequence(const std::string& name) { - std::map::iterator it; + std::map::iterator it; it = data->sequences.find(name); @@ -299,19 +303,19 @@ struct Animation::AnimationImpl } } - boost::shared_ptr data; ///< Internal data. + boost::shared_ptr 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) @@ -343,9 +347,9 @@ unsigned Animation::getFrame() const * "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"); }