gee_operator.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Visual Effects Engine - VEE
00006  *
00007  * Read the "VEE-LICENSE" file for the license.
00008  *
00009  * Authors & Copyright:   
00010  *
00011  * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 
00012  * Janne Kontkanen 2001-2004
00013  *
00014  * Additional copyrights: Tekes 2003-2004
00015  *
00016  * firstname.lastname@hut.fi
00017  *
00018  */
00019 
00020 #ifndef GEE_OPERATOR_H
00021 #define GEE_OPERATOR_H
00022 
00023 #include <gee_id.h>
00024 #include <gee_interval.h>
00025 
00026 #include <vee_reference_object.h>
00027 
00028 #include <di_types.h>
00029 
00030 #include <list>
00031 #include <map>
00032 
00033 class GEE_Io;
00034 class GEE_World;
00035 class GEE_OperatorManager;
00036 class GEE_OperatorGroup;
00037 
00044 class GEE_Operator : public GEE_IdContainer
00045 {
00046 public:
00047   GEE_Operator();
00048   virtual ~GEE_Operator();
00049 
00050   virtual bool start(GEE_World *, const GEE_TimeStamp &);
00051   virtual bool act(GEE_World *, const GEE_TimeStamp &);
00052   virtual bool stop(GEE_World *, const GEE_TimeStamp &);
00053 
00054   virtual bool read(GEE_Io *);
00055   virtual bool write(GEE_Io *);
00056   virtual const char * type();
00057 
00058   bool readBasics(GEE_Io *);
00059   bool writeBasics(GEE_Io *);
00060   void copyBasics(const GEE_Operator &);
00061 
00062   const GEE_Interval & interval() const { return m_interval; }
00063   GEE_Interval & interval()             { return m_interval; }
00064 
00065   GEE_id_t group() const { return m_group; }
00066   void setGroup(GEE_id_t g) { m_group = g; }
00067 
00068   void setManager(GEE_OperatorManager * manager) { m_manager = manager; }
00069 
00070   static GEE_Operator * create(const char * type);
00071 
00072   bool keepAlive() { return m_keepAlive; }
00073   void setKeepAlive(bool keep) { m_keepAlive = keep; }
00074 
00075 protected:
00076   static void init();
00077 
00078   GEE_Interval m_interval;
00079 
00080   GEE_id_t m_group;
00083   bool     m_keepAlive;
00084 
00085   GEE_OperatorManager * m_manager;
00086 };
00087 
00090 
00096 class GEE_OperatorTimer
00097 {
00098 public:
00099   GEE_OperatorTimer() : m_id(-1) {}
00100   GEE_OperatorTimer(const GEE_Operator *a);
00101   GEE_OperatorTimer(const GEE_OperatorGroup *g);
00102 
00103   ~GEE_OperatorTimer() {}
00104 
00105   const GEE_TimeStamp & time() const { return m_time; }
00106 
00107   bool operator < (const GEE_OperatorTimer &that) const
00108   { 
00109     if(m_time != that.m_time) return m_time < that.m_time;
00110     else return m_id < that.m_id;
00111   }
00112 
00113   bool operator > (const GEE_OperatorTimer &that) const
00114   { 
00115     if(m_time != that.m_time) return m_time > that.m_time;
00116     else return m_id > that.m_id;
00117   }
00118 
00119   bool operator <= (const GEE_OperatorTimer &that) const
00120   { 
00121     if(m_time != that.m_time) return m_time <= that.m_time;
00122     else return m_id <= that.m_id;
00123   }
00124 
00125   bool operator >= (const GEE_OperatorTimer &that) const
00126   { 
00127     if(m_time != that.m_time) return m_time > that.m_time;
00128     else return m_id >= that.m_id;
00129   }
00130 
00131   bool operator == (const GEE_OperatorTimer &that) const
00132   { 
00133     return (m_time == that.m_time) && (m_id == that.m_id);
00134   }
00135 
00136 protected:
00137   GEE_TimeStamp m_time;
00138   GEE_id_t      m_id;
00139 };
00140 
00143 
00152 class GEE_OperatorGroup : public GEE_IdContainer
00153 {
00154 public:
00155   /* typedef std::multimap<GEE_TimeStamp, VEE_RefPtr<GEE_Operator> > container;
00156      typedef container::iterator iterator; */
00157 
00158   typedef std::map<GEE_OperatorTimer, VEE_RefPtr<GEE_Operator> > container;
00159   typedef container::iterator iterator;
00160 
00161   typedef std::list<VEE_RefPtr<GEE_Operator> > operatorList;
00162   typedef operatorList::iterator listIter;
00163 
00164   GEE_OperatorGroup();
00165   ~GEE_OperatorGroup();
00166 
00167   bool start(GEE_OperatorManager *, GEE_World *, const GEE_TimeStamp &);
00168   bool act(GEE_OperatorManager *, GEE_World *, const GEE_TimeStamp &);
00169   bool stop(GEE_OperatorManager *, GEE_World *, const GEE_TimeStamp &);
00170 
00171   void addOperator(VEE_RefPtr<GEE_Operator> &);
00172   void clearOperators();
00173 
00174   bool read(GEE_Io *);
00175   bool write(GEE_Io *);
00176 
00177   const GEE_TimeStamp & offset() const { return m_offset; }
00178   void setOffset(const GEE_TimeStamp &offset) { m_offset = offset; }
00180   GEE_TimeStamp endTime() { return m_offset + m_endTime * m_scale; }
00181   GEE_TimeStamp firstTime();
00182   void calculateEndTime();
00183 
00184   double scale() const { return m_scale; }
00185   void setScale(double scale) { m_scale = scale; }
00186   
00187   GEE_id_t group() const { return m_group; }
00188   void setGroup(GEE_id_t g) { m_group = g; }
00189 
00190   bool keepAlive() { return m_keepAlive; }
00191   void setKeepAlive(bool keep) { m_keepAlive = keep; }
00192 
00193   uint operatorCount() const { return m_operators.size(); }
00194 
00195 protected:
00196 
00197   void nextFrame(GEE_World *, const GEE_TimeStamp &);
00198 
00200   GEE_TimeStamp m_time;
00202   GEE_TimeStamp m_offset;
00204   GEE_TimeStamp m_endTime;
00206   double        m_scale;
00207 
00208   uint          m_frame;
00209 
00211   GEE_id_t      m_group;
00212   container     m_operators;
00213   iterator      m_nextOperator;
00214   operatorList  m_currentOperators;
00215 
00218   bool     m_keepAlive;
00219   bool     m_running;
00220 
00221   static bool m_debug;
00222 };
00223 
00224 
00227 
00230 class GEE_OperatorManager
00231 {
00232 public:
00233   typedef std::map<GEE_OperatorTimer, 
00234        VEE_RefPtr<GEE_OperatorGroup> > container;
00235   typedef container::iterator iterator;
00236 
00237   typedef std::map<GEE_id_t, VEE_RefPtr<GEE_OperatorGroup> > groupContainer;
00238   typedef groupContainer::iterator groupIterator;
00239   
00240   typedef std::list<VEE_RefPtr<GEE_OperatorGroup> > groupList;
00241   typedef groupList::iterator groupListIter;
00242   
00243   typedef std::list<VEE_RefPtr<GEE_Operator> > operatorList;
00244   typedef operatorList::iterator operatorListIter;
00245 
00246   typedef std::map<GEE_id_t, VEE_RefPtr<GEE_Operator> > operatorMap;
00247   typedef operatorMap::iterator mapIterator;
00248 
00249   GEE_OperatorManager();
00250   ~GEE_OperatorManager();
00251 
00252   bool addOperator(GEE_Operator*);
00253   bool addOperatorGroup(const GEE_OperatorGroup &);
00254   bool addOperatorGroup2(VEE_RefPtr<GEE_OperatorGroup> &);
00255   inline GEE_OperatorGroup *getOperatorGroup(GEE_id_t g);
00256 
00257   GEE_TimeStamp operatorTimeToRealTime(GEE_TimeStamp , GEE_id_t groupId);
00258   GEE_TimeStamp realTimeToOperatorTime(GEE_TimeStamp , GEE_id_t groupId);
00259 
00260   void undo(uint n = 1);
00261   void redo(uint n = 1);
00262   operatorListIter undoIterator() { return m_undoIter; }
00263   operatorListIter undoEnd() { return m_undoList.end(); }
00264 
00265   bool read(GEE_Io *, const char * dirname);
00266   bool write(GEE_Io *, const char * dirname);
00267 
00268   void collectIds(GEE_IdContainer::id_remap &);
00269   void remapIds(GEE_IdContainer::id_remap &);
00270 
00271   void collectOperators(operatorList *);
00272   
00273   void update(GEE_TimeStamp);
00274   void rewind(GEE_TimeStamp);
00275   void toBegin() { rewind(-1); }
00276   void stop();
00277 
00278   GEE_World  *world() { return m_world; }
00279   void setWorld(GEE_World *w) { m_world = w; }
00280   
00281   void clear();
00282 
00283   void merge(GEE_OperatorManager &);
00284 
00285   void rebuildPlan();
00286 
00287   uint actionCount() { return m_undoList.size(); }
00288 
00289   uint fps() const { return m_fps; }
00290 
00291 protected:
00292   // void addOperatorInternal(VEE_RefPtr<GEE_Operator> &, bool inundo);
00293   void addOperatorInternal(VEE_RefPtr<GEE_Operator> &);
00294   void nextFrame(GEE_TimeStamp);
00295 
00296 
00297   container   m_plan;
00298   iterator    m_nextGroup;
00299   bool        m_dirtyPlan;
00300   bool        m_running;
00301 
00302   // container   m_pending;
00304   groupList    m_currentGroups;
00305 
00307   groupContainer m_groups;
00308 
00309   // operatorMap  m_operatorStore;
00310   operatorList m_undoList;
00312   operatorListIter m_undoIter;
00313 
00314   GEE_TimeStamp m_time;
00315   uint          m_fps;
00316   uint          m_frame;
00317 
00318   GEE_World  *m_world;
00319 
00320   static bool m_debug;
00321 };
00322 
00323 inline GEE_OperatorGroup *GEE_OperatorManager::getOperatorGroup(GEE_id_t g)
00324 {
00325   groupIterator git = m_groups.find(g);
00326   return (git == m_groups.end()) ? 0 : (*git).second.ptr();
00327 }
00328 
00329 
00330 #endif

Generated on Mon Mar 12 21:09:00 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6