timemgr.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/timemgr.h $*
  25. * *
  26. * $Author:: Jani_p $*
  27. * *
  28. * $Modtime:: 3/14/02 11:26a $*
  29. * *
  30. * $Revision:: 18 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef TIMEMGR_H
  36. #define TIMEMGR_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef PERSIST_H
  41. #include "persist.h"
  42. #endif
  43. class ChunkSaveClass;
  44. class ChunkLoadClass;
  45. // Framerate histogram utility class
  46. class FrameTimeHistogramClass
  47. {
  48. unsigned* Counts;
  49. unsigned SlotCount;
  50. float Step;
  51. public:
  52. FrameTimeHistogramClass(unsigned slot_count, float step); // Number of millisecond-slots, step in milliseconds
  53. ~FrameTimeHistogramClass();
  54. void Reset();
  55. void Add(float frame_time);
  56. unsigned Get_Slot_Count() const { return SlotCount; }
  57. float Get_Step() const { return Step; }
  58. void Get_Packed_Report(unsigned char* bytes); // Normalized counts, as bytes
  59. void Get_Report(unsigned* counts); // Absolute counts
  60. };
  61. /*
  62. **
  63. */
  64. // frame rate of timeGetTime()
  65. #define TICKS_PER_SECOND 1000
  66. /*
  67. **
  68. */
  69. class TimeManager {
  70. public:
  71. // Get the elapsed time this frame (technicaly last frame) in either Ticks or Seconds
  72. static float Get_Frame_Seconds( void ) { return FrameSeconds; }
  73. static float Get_Frame_Real_Seconds( void ) { return RealFrameSeconds; }
  74. static int Get_Frame_Ticks( void ) { return FrameTicks; }
  75. static float Get_Total_Seconds( void ) { return TotalSeconds; }
  76. // Get the absolute time in either Ticks or Seconds
  77. static float Get_Seconds( void ) { return (float)SystemTicks() / TICKS_PER_SECOND; }
  78. // update frame and total time
  79. static void Update_Frame_Time( void );
  80. static float Get_Average_Frame_Rate( void ) { return AveragedFPS; }
  81. // delay
  82. static void Wait_Seconds( float seconds );
  83. // Update timers
  84. static void Update( void );
  85. static void Set_Time_Scale( float scale ) { TimeScale = scale; }
  86. static void Reset(void);
  87. static FrameTimeHistogramClass& Peek_Frame_Time_Histogram();
  88. private:
  89. static int SystemTicks();
  90. static int FrameTicks; // ticks this frame
  91. static int RealFrameTicks; // ticks this frame
  92. static int LastTicks; // Last game ticks
  93. static float TimeScale; // Allow animation smoothing
  94. static float TotalSeconds;
  95. static float FrameSeconds;
  96. static float RealFrameSeconds;
  97. static float AveragedFPS;
  98. static int AveragedFPSTicks;
  99. static int AveragedFPSCounter;
  100. };
  101. #endif // TIMEMGR_H