00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __SIM_TIMER_H__
00018 #define __SIM_TIMER_H__
00019
00020 #include "nommgr.h"
00021 #include <queue>
00022 #include "mmgr.h"
00029 class Entity;
00030 class Event;
00031
00032 class Timer
00033 {
00034 public:
00035 static Timer* getInstance ();
00036
00037 public:
00038 ~Timer ();
00039
00040 public:
00041 void initialize ();
00042 void shutdown ();
00043
00044 public:
00045 void clearEvents (Entity* entity);
00046 void addEvent (Entity* entity, Event* event, Real deltaTime, int ID=-1, unsigned int syncIndex=0);
00047 void clearEvents ();
00048
00049 public:
00050 void beginFrame ();
00051 void frame ();
00052 void endFrame ();
00053
00054 public:
00055 int queueSize();
00056 void print();
00057 bool isEmpty(unsigned int syncIndex);
00058
00059 protected:
00060 Timer ();
00061
00062 protected:
00063 struct Node
00064 {
00065 Entity* entity;
00066 Event* event;
00067 Real endTime;
00068
00069 Node (Entity* entity, Event* event, Real endTime);
00070 void print ();
00071 #ifndef TIMERDYN
00072 bool operator > (const Node& node) const;
00073 #else
00074 bool operator > (const Node * node) const;
00075 #endif
00076 };
00077
00078 protected:
00079 bool isInitialized;
00080 bool isShutdown;
00081 int qs;
00082 #ifndef TIMERDYN
00083 std::priority_queue<Node, std::vector<Node>, std::greater<Node> > queue;
00084 #else
00085 std::priority_queue<Node *, std::vector<Node *>, std::greater<Node *> > queue;
00086 #endif
00087 };
00088
00089 #endif