systimer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. #define MS_TIMER_SECOND 1000
  42. /*
  43. ** Class that just wraps around timeGetTime()
  44. **
  45. **
  46. */
  47. class SysTimeClass
  48. {
  49. public:
  50. SysTimeClass(void); //default constructor
  51. ~SysTimeClass(); //default destructor
  52. /*
  53. ** Get. Use everywhere you would use timeGetTime
  54. */
  55. WWINLINE unsigned long Get(void);
  56. WWINLINE unsigned long operator () (void) {return(Get());}
  57. WWINLINE operator unsigned long(void) {return(Get());}
  58. /*
  59. ** Use periodically (like every few days!) to make sure the timer doesn't wrap.
  60. */
  61. void Reset(void);
  62. /*
  63. ** See if the timer is about to wrap.
  64. */
  65. bool Is_Getting_Late(void);
  66. private:
  67. /*
  68. ** Time we were first called.
  69. */
  70. unsigned long StartTime;
  71. /*
  72. ** Time to add after timer wraps.
  73. */
  74. unsigned long WrapAdd;
  75. };
  76. extern SysTimeClass SystemTime;
  77. /***********************************************************************************************
  78. * SysTimeClass::Get -- Wrapper around system timeGetTime() api call *
  79. * *
  80. * *
  81. * *
  82. * INPUT: Nothing *
  83. * *
  84. * OUTPUT: Current system time in ms *
  85. * *
  86. * WARNINGS: None *
  87. * *
  88. * HISTORY: *
  89. * 10/25/2001 1:38PM ST : Created *
  90. *=============================================================================================*/
  91. WWINLINE unsigned long SysTimeClass::Get(void)
  92. {
  93. /*
  94. ** 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
  95. ** constructor gets called. In fact, we don't even have a constructor because it's pointless.
  96. */
  97. static bool is_init = false;
  98. if (!is_init) {
  99. Reset();
  100. is_init = true;
  101. }
  102. unsigned long time = timeGetTime();
  103. if (time > StartTime) {
  104. return(time - StartTime);
  105. }
  106. /*
  107. ** Timer wrapped around. Eeek.
  108. */
  109. return(time + WrapAdd);
  110. }
  111. #ifdef timeGetTime
  112. #undef timeGetTime
  113. #define timeGetTime SystemTime.Get
  114. #endif //timeGetTime
  115. #endif //_SYSTIMER_H