00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WP_ANIMATIONMANAGER_H
00018 #define WP_ANIMATIONMANAGER_H
00019
00020 #include <string>
00021 #include <map>
00022 #include "WPCG.h"
00023
00024 namespace WPCG
00025 {
00044 class WP_AnimationManager
00045 {
00046 public:
00047 ~WP_AnimationManager()
00048 {
00049
00050 map<const WP_Object*, WP_ObjectAnimationInfo*>::iterator i = object_info.begin();
00051 while(i != object_info.end())
00052 {
00053 delete (*i).second;
00054 i++;
00055 }
00056 };
00057
00062 static WP_AnimationManager* getInstance()
00063 {
00064 if (!om_instance)
00065 {
00066 om_instance = new WP_AnimationManager();
00067 }
00068 return om_instance;
00069 }
00070
00071 unsigned short getCurrentFrame(const WP_Object* object)
00072 {
00073 if (object_info.count(object))
00074 {
00075 return object_info[object]->currentFrame;
00076 }
00077 return 0;
00078 }
00079
00080 string getCategory(const WP_Object* object)
00081 {
00082 if (object_info.count(object))
00083 {
00084 return object_info[object]->category;
00085 }
00086 return "";
00087 }
00088
00089 bool addObject(const WP_Object *object);
00090
00091 bool isObjectPresent(const WP_Object *object)
00092 {
00093 return object_info.count(object);
00094 }
00095
00096 bool removeObject(const WP_Object *object)
00097 {
00098 if (object_info.count(object))
00099 return false;
00100
00101 delete object_info[object];
00102 object_info.erase(object);
00103
00104 return true;
00105 }
00106
00107 void setInterpolation(float i)
00108 {
00109 interpolation = i;
00110 }
00111
00112 bool setCategory(const WP_Object *object, const string &category)
00113 {
00114 if (object_info.count(object))
00115 {
00116 WP_ObjectAnimationInfo *info = object_info[object];
00117 info->category = category;
00118 info->currentFrame = 0;
00119 info->t = 0.0;
00120 return true;
00121 }
00122 return false;
00123 }
00124
00125 void updateAnimation(const WP_Object* object);
00126
00127 bool animateObject(const WP_Object *object, unsigned short *start_frame, unsigned short *next_frame, scalar *interpolation);
00128
00129 private:
00130 WP_AnimationManager():interpolation(0.2){};
00131
00135 static WP_AnimationManager* om_instance;
00136
00137
00138 class WP_ObjectAnimationInfo
00139 {
00140 public:
00141 WP_ObjectAnimationInfo():currentFrame(0), t(0.0f){};
00142 WP_ObjectAnimationInfo(const string& c): currentFrame(0), t(0.0f), category(c){};
00143 ~WP_ObjectAnimationInfo(){};
00144
00145 unsigned short currentFrame;
00146 float t;
00147 string category;
00148 };
00149
00150 map<const WP_Object*, WP_ObjectAnimationInfo*> object_info;
00151 scalar interpolation;
00152 };
00153
00154 }
00155 #endif
00156
00157