UGDK
src/ugdk/action/animation.h
Go to the documentation of this file.
00001 #ifndef UGDK_ACTION_ANIMATION_H_
00002 #define UGDK_ACTION_ANIMATION_H_
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <ugdk/portable/tr1.h>
00007 #include FROM_TR1(functional)
00008 #include <ugdk/action.h>
00009 #include <ugdk/graphic.h>
00010 #include <ugdk/action/animationframe.h> // FIXME: not necessary.
00011 
00012 
00013 #define DEFAULT_PERIOD 0.1
00014 
00015 namespace ugdk {
00016 
00017 namespace action {
00018 
00019 class Observer;
00020 class AnimationSet;
00021 
00022 /*TODO
00023  * Represents a sprite's current animation.
00024  *
00025  * An AnimationManager object contains a sequence of information describing a sprite's visual behavior
00026  * (animation spreadsheet frames, position, rotation, transparency, etc) throughout a corresponding sequence
00027  * of the game's update frames. This per-frame information is represented by the class
00028  * AnimationManager::AnimationFrame, and the sequence of this information by the AnimationManager::Animation
00029  * type.
00030  *
00031  * Also, an AnimationManager object contains a set of all the possible animations the sprite may need.
00032  * This set is represented by the AnimationSet class. Thus, a sprite needs but one AnimationManager object
00033  * to access any of the animations it requires, as long as these are all properly registered
00034  * in the AnimationSet object given to the AnimationManager object.
00035  */
00036 class AnimationManager {
00037 
00038   public:
00039     AnimationManager(double fps, AnimationSet *set);/*TODO: remove fps*/
00040     ~AnimationManager();
00041 
00042     void set_slowdown_factor(const double factor) { period_scaling_factor_ = factor; }
00043     //Note: try to use set_slowdown_factor() instead whenever you can.
00044     void set_speedup_factor(const double factor) { set_slowdown_factor(1.0/factor); }
00045 
00046     //Note: try to use period() instead whenever you can.
00047     double    fps() const;
00048     double period() const;
00049     unsigned int n_frames() const;
00050 
00051     int GetFrame() const;
00052     void set_default_frame(int default_frame) { default_frame_ = default_frame; }
00053     const graphic::Modifier* get_current_modifier() const;
00054     void Select(const std::string& name);
00055     void Select(int index);
00056     void Update(double delta_t);
00057     void AddObserver(Observer* observer);
00058     void AddTickFunction(std::tr1::function<void (void)> tick);
00059 
00060   private:
00061     double period_scaling_factor_;
00062 
00063     Animation *current_animation_;
00064     AnimationSet *animation_set_;
00065     int current_frame_;
00066     int default_frame_;
00067     double elapsed_time_;
00068 
00069     std::vector<Observer *> observers_;
00070     std::vector< std::tr1::function<void (void)> > ticks_;
00071     void NotifyAllObservers();
00072 
00073 };
00074 
00075 } /* namespace action */
00076 
00077 } /* namespace ugdk */
00078 
00079 #endif /* UGDK_ACTION_ANIMATION_H_ */
00080 
00081 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines