Timer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Copyright (c) 2006-2013 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #ifndef LOVE_TIMER_SDL_TIMER_H
  21. #define LOVE_TIMER_SDL_TIMER_H
  22. // LOVE
  23. #include "timer/Timer.h"
  24. namespace love
  25. {
  26. namespace timer
  27. {
  28. namespace sdl
  29. {
  30. /**
  31. * An SDL timer module. Can keep track of time between certain function
  32. * calls, and provides access to a FPS metric which updates once each second.
  33. **/
  34. class Timer : public love::timer::Timer
  35. {
  36. public:
  37. /**
  38. * Constructor. Initializes the SDL/timer subsystem.
  39. **/
  40. Timer();
  41. /**
  42. * Destructor.
  43. **/
  44. virtual ~Timer();
  45. const char *getName() const;
  46. void step();
  47. void sleep(double seconds) const;
  48. double getDelta() const;
  49. int getFPS() const;
  50. double getAverageDelta() const;
  51. double getTime() const;
  52. private:
  53. // Frame delta vars.
  54. double currTime;
  55. double prevTime;
  56. double prevFpsUpdate;
  57. // Updated with a certain frequency.
  58. int fps;
  59. double averageDelta;
  60. // The frequency by which to update the FPS.
  61. double fpsUpdateFrequency;
  62. // Frames since last FPS update.
  63. int frames;
  64. // The current timestep.
  65. double dt;
  66. // The timer period (reciprocal of the frequency.)
  67. const double timerPeriod;
  68. // Returns the timer period on some platforms.
  69. static double getTimerPeriod();
  70. }; // Timer
  71. } // sdl
  72. } // timer
  73. } // love
  74. #endif // LOVE_TIMER_SDL_TIMER_H