CTimer.h 3.0 KB

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