1 // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 // This file is part of the "Irrlicht Engine". 3 // For conditions of distribution and use, see copyright notice in irrlicht.h 4 5 #ifndef __C_IRR_C_TIMER_H_INCLUDED__ 6 #define __C_IRR_C_TIMER_H_INCLUDED__ 7 8 #include "ITimer.h" 9 #include "os.h" 10 11 namespace irr 12 { 13 //! Device independent implementation of the timer 14 class CTimer : public ITimer 15 { 16 public: 17 18 CTimer(bool usePerformanceTimer=true) 19 { 20 os::Timer::initTimer(usePerformanceTimer); 21 } 22 23 //! Returns current real time in milliseconds of the system. 24 /** This value does not start with 0 when the application starts. 25 For example in one implementation the value returned could be the 26 amount of milliseconds which have elapsed since the system was started. */ getRealTime()27 virtual u32 getRealTime() const 28 { 29 return os::Timer::getRealTime(); 30 } 31 32 //! Get current time and date in calendar form getRealTimeAndDate()33 virtual RealTimeDate getRealTimeAndDate() const 34 { 35 return os::Timer::getRealTimeAndDate(); 36 } 37 38 //! Returns current virtual time in milliseconds. 39 /** This value starts with 0 and can be manipulated using setTime(), stopTimer(), 40 startTimer(), etc. This value depends on the set speed of the timer if the timer 41 is stopped, etc. If you need the system time, use getRealTime() */ getTime()42 virtual u32 getTime() const 43 { 44 return os::Timer::getTime(); 45 } 46 47 //! sets current virtual time setTime(u32 time)48 virtual void setTime(u32 time) 49 { 50 os::Timer::setTime(time); 51 } 52 53 //! Stops the game timer. 54 /** The timer is reference counted, which means everything which calls 55 stopTimer() will also have to call startTimer(), otherwise the timer may not start/stop 56 corretly again. */ stop()57 virtual void stop() 58 { 59 os::Timer::stopTimer(); 60 } 61 62 //! Starts the game timer. 63 /** The timer is reference counted, which means everything which calls 64 stopTimer() will also have to call startTimer(), otherwise the timer may not start/stop 65 corretly again. */ start()66 virtual void start() 67 { 68 os::Timer::startTimer(); 69 } 70 71 //! Sets the speed of the timer 72 /** The speed is the factor with which the time is running faster or slower then the 73 real system time. */ 74 virtual void setSpeed(f32 speed = 1.0f) 75 { 76 os::Timer::setSpeed(speed); 77 } 78 79 //! Returns current speed of the timer 80 /** The speed is the factor with which the time is running faster or slower then the 81 real system time. */ getSpeed()82 virtual f32 getSpeed() const 83 { 84 return os::Timer::getSpeed(); 85 } 86 87 //! Returns if game timer is currently stopped isStopped()88 virtual bool isStopped() const 89 { 90 bool ret = os::Timer::isStopped(); 91 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 92 return ret; 93 } 94 95 //! Advances the virtual time 96 /** Makes the virtual timer update the time value based on the real time. This is 97 called automaticly when calling IrrlichtDevice::run(), but you can call it manually 98 if you don't use this method. */ tick()99 virtual void tick() 100 { 101 os::Timer::tick(); 102 } 103 }; 104 105 } // end namespace 106 107 #endif 108 109