systimer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/wwlib/systimer.h $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 12/09/01 6:41p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #pragma once
  36. #ifndef _SYSTIMER_H
  37. #include "always.h"
  38. #include <windows.h>
  39. #include "mmsys.h"
  40. #define TIMEGETTIME SystemTime.Get
  41. /*
  42. ** Class that just wraps around timeGetTime()
  43. **
  44. **
  45. */
  46. class SysTimeClass
  47. {
  48. public:
  49. /*
  50. ** Get. Use everywhere you would use timeGetTime
  51. */
  52. __forceinline unsigned long Get(void);
  53. __forceinline unsigned long operator () (void) {return(Get());}
  54. __forceinline operator unsigned long(void) {return(Get());}
  55. /*
  56. ** Use periodically (like every few days!) to make sure the timer doesn't wrap.
  57. */
  58. void Reset(void);
  59. /*
  60. ** See if the timer is about to wrap.
  61. */
  62. bool Is_Getting_Late(void);
  63. private:
  64. /*
  65. ** Time we were first called.
  66. */
  67. unsigned long StartTime;
  68. /*
  69. ** Time to add after timer wraps.
  70. */
  71. unsigned long WrapAdd;
  72. };
  73. extern SysTimeClass SystemTime;
  74. /***********************************************************************************************
  75. * SysTimeClass::Get -- Wrapper around system timeGetTime() api call *
  76. * *
  77. * *
  78. * *
  79. * INPUT: Nothing *
  80. * *
  81. * OUTPUT: Current system time in ms *
  82. * *
  83. * WARNINGS: None *
  84. * *
  85. * HISTORY: *
  86. * 10/25/2001 1:38PM ST : Created *
  87. *=============================================================================================*/
  88. __forceinline unsigned long SysTimeClass::Get(void)
  89. {
  90. /*
  91. ** This has to be static here since we don't know if we will get called in a global constructor of another object before our
  92. ** constructor gets called. In fact, we don't even have a constructor because it's pointless.
  93. */
  94. static bool is_init = false;
  95. if (!is_init) {
  96. Reset();
  97. is_init = true;
  98. }
  99. unsigned long time = timeGetTime();
  100. if (time > StartTime) {
  101. return(time - StartTime);
  102. }
  103. /*
  104. ** Timer wrapped around. Eeek.
  105. */
  106. return(time + WrapAdd);
  107. }
  108. #ifdef timeGetTime
  109. #undef timeGetTime
  110. #define timeGetTime SystemTime.Get
  111. #endif //timeGetTime
  112. #endif //_SYSTIMER_H