00001 #include "ctimer.h" 00002 00003 /* The statically allocated pointer to the CTimerSystem singleton. */ 00004 CTimerSystem *CSingletonManager<CTimerSystem>::unique_instance = 0; 00005 00006 /* Restart the FPS timer. */ 00007 void CFPSTimer::restart() 00008 { 00009 ticks_start = CTimerSystemManager::get_instance().get_ticks(); 00010 ticks_end = 0; 00011 frame_time = 0; 00012 seconds_time = 0; 00013 frames_this_second = 0; 00014 fps = 0; 00015 } 00016 00017 /* Update the FPS timer. */ 00018 void CFPSTimer::update() 00019 { 00020 ticks_end = CTimerSystemManager::get_instance().get_ticks(); 00021 frame_time = ticks_end - ticks_start; 00022 seconds_time += frame_time; 00023 if (seconds_time > 1000) { 00024 fps = frames_this_second; 00025 frames_this_second = 0; 00026 seconds_time = 0; 00027 notify(); 00028 } else { 00029 frames_this_second++; 00030 } 00031 ticks_start = ticks_end; 00032 /* Now that we've made the FPS calculation, retroactively truncate 00033 the frame time to its max if needed. */ 00034 if (frame_time > MAX_FRAME_TIME) frame_time = MAX_FRAME_TIME; 00035 }
1.3.3