Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

WP_AnimationManager.h

Go to the documentation of this file.
00001 /* Copyright (C) 2001-2003 W.P. van Paassen - peter@paassen.tmfweb.nl
00002 
00003    This program is free software; you can redistribute it and/or modify it under
00004    the terms of the GNU General Public License as published by the Free
00005    Software Foundation; either version 2 of the License, or (at your
00006    option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful, but WITHOUT
00009    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00010    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00011    for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; see the file COPYING.  If not, write to the Free
00015    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
00016 
00017 #ifndef WP_ANIMATIONMANAGER_H
00018 #define WP_ANIMATIONMANAGER_H
00019 
00020 #include <string>
00021 #include <map>
00022 #include "WPCG.h" //FIXME don't include all headers!
00023 
00024 namespace WPCG
00025 {
00044 class WP_AnimationManager
00045 {
00046 public:
00047   ~WP_AnimationManager()
00048     {
00049       //empty map
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   //nested class 
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; //FIXME it could be faster to store total frame number
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 

Generated on Tue Jan 28 20:26:32 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002