00001 #ifndef CTIMER_H 00002 #define CTIMER_H 00003 00012 #include "globals.h" 00013 00014 #include "ccomponent.h" 00015 #include "csingletonmanager.h" 00016 00020 class CFPSTimer : public CModel { 00021 private: 00022 /* used internally. ticks_start and ticks_end are the ticks at the 00023 beginning of a frame, respectively. */ 00024 unsigned long ticks_start, ticks_end; 00025 /* the amount of time it's taken to render the current frame. the maximum amount of 00026 time this can be is MAX_FRAME_TIME, even if the game actually took longer 00027 to draw the frame. */ 00028 unsigned long frame_time; 00029 /* used internally. this tracks the number of milliseconds elapsed so far this second. */ 00030 unsigned long seconds_time; 00031 /* used internally. number of frames that have been rendered so far this second. */ 00032 unsigned long frames_this_second; 00033 /* number of frames rendered in the last second (frames per second). */ 00034 unsigned long fps; 00035 /* the maximum time a frame can take to render; if the game actually took longer 00036 to draw the frame, it is still reported as MAX_FRAME_TIME, so that 00037 finite state machines, etc have an upper bound for time intervals. */ 00038 const unsigned long MAX_FRAME_TIME; 00039 public: 00041 CFPSTimer(unsigned long max_frame_time) : MAX_FRAME_TIME(max_frame_time), fps(0) { } 00043 void restart(); 00045 void update(); 00047 unsigned long get_fps() { return fps; } 00051 unsigned long get_time_passed() { return frame_time; } 00052 }; 00053 00056 class CTimerSystem { 00057 private: 00058 /* Outlaw copy constructor and '=' operator. */ 00059 CTimerSystem(CTimerSystem &); 00060 CTimerSystem &operator=(CTimerSystem &); 00061 00062 public: 00063 CTimerSystem() { } 00064 virtual ~CTimerSystem() { } 00065 00067 virtual unsigned long get_ticks() = 0; 00068 }; 00069 00071 class CTimerSystemManager : public CSingletonManager<CTimerSystem> { }; 00072 00074 typedef CSingletonFactory<CTimerSystem> CTimerSystemFactory; 00075 00076 #endif
1.3.3