X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FAnimation.cc;fp=src%2Fanimation.cc;h=3c418f7052027b17f32bb3305e821563be151667;hp=c03a49d7195a08e4f3d0252f1581eb18f3b00855;hb=c2321281bf12a7efaedde930422c7ddbc92080d4;hpb=87bc17e55b0c1dc73ecc66df856d3f08fd7a7724 diff --git a/src/animation.cc b/src/Moof/Animation.cc similarity index 67% rename from src/animation.cc rename to src/Moof/Animation.cc index c03a49d..3c418f7 100644 --- a/src/animation.cc +++ b/src/Moof/Animation.cc @@ -29,24 +29,24 @@ #include #include -#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 { /** @@ -55,7 +55,7 @@ struct animation::animation_impl * which wants to use these loaded sequences. */ - struct animation_data : public mippleton + struct AnimationData : public Mippleton { /** * A frame of an animation sequence. A frame is merely an index which @@ -63,39 +63,40 @@ struct animation::animation_impl * 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 rootObj; + std::map rootObj; if (root->get(rootObj)) { - std::map::iterator i; - for (i = rootObj.begin(); i != rootObj.end(); i++) + std::map::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); } } } @@ -108,10 +109,10 @@ struct animation::animation_impl * that they should be played. */ - struct sequence + struct Sequence { - std::vector frames; ///< List of frames. - scalar delay; ///< Scale frame durations. + std::vector frames; ///< List of frames. + Scalar delay; ///< Scale frame durations. bool loop; ///< Does the sequence repeat? std::string next; ///< Next sequence name. @@ -122,33 +123,33 @@ struct animation::animation_impl * constructor which loads each individual frame. */ - sequence(serializable_ptr root) : + Sequence(SerializablePtr root) : delay(0.0), loop(true) { - std::map rootObj; + std::map rootObj; if (root->get(rootObj)) { - std::map::iterator i; - for (i = rootObj.begin(); i != rootObj.end(); i++) + std::map::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 framesObj; + std::vector framesObj; - if ((*i).second->get(framesObj)) + if ((*it).second->get(framesObj)) { - std::vector::iterator j; + std::vector::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)); } } } @@ -156,16 +157,16 @@ struct animation::animation_impl 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); } } } @@ -181,24 +182,24 @@ struct animation::animation_impl 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 rootObj; + std::map rootObj; if (root->get(rootObj)) { - std::map::iterator i; + std::map::iterator it; - for (i = rootObj.begin(); i != rootObj.end(); i++) + for (it = rootObj.begin(); it != rootObj.end(); it++) { - sequences.insert(std::pair((*i).first, - sequence((*i).second))); + sequences.insert(std::pair((*it).first, + Sequence((*it).second))); } } } @@ -209,13 +210,13 @@ struct animation::animation_impl * registers itself as a mippleton and then loads the animation data. */ - explicit animation_data(const std::string& name) : - mippleton(name) + explicit AnimationData(const std::string& name) : + Mippleton(name) { loadFromFile(); } - std::map sequences; ///< List of sequences. + std::map sequences; ///< List of sequences. }; @@ -223,8 +224,8 @@ struct animation::animation_impl * 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), @@ -238,15 +239,15 @@ struct animation::animation_impl * updates will progress the new sequence. */ - void startSequence(const std::string& sequenceName) + void startSequence(const std::string& name) { - std::map::iterator i; + std::map::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; @@ -265,7 +266,7 @@ struct animation::animation_impl * starts over again. */ - void update(scalar t, scalar dt) + void update(Scalar t, Scalar dt) { if (currentSequence) { @@ -298,31 +299,31 @@ struct animation::animation_impl } } - boost::shared_ptr data; ///< Internal data. + boost::shared_ptr 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); } @@ -331,9 +332,9 @@ void animation::update(scalar t, scalar dt) * drawing code which will draw the correct current frame. */ -unsigned animation::getFrame() const +unsigned Animation::getFrame() const { - return impl->frameIndex; + return impl_->frameIndex; } @@ -342,13 +343,13 @@ unsigned animation::getFrame() const * "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: *************************************************/