TIMER.H 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. ** Command & Conquer Red Alert(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. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : Timer Class Functions *
  23. * *
  24. * File Name : TIMER.H *
  25. * *
  26. * Programmer : Scott K. Bowen *
  27. * *
  28. * Start Date : July 6, 1994 *
  29. * *
  30. * Last Update : July 12, 1994 [SKB] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef TIMER_H
  36. #define TIMER_H
  37. #define WIN32 1
  38. #ifndef _WIN32 // Denzil 6/2/98 Watcom 11.0 complains without this check
  39. #define _WIN32
  40. #endif // _WIN32
  41. #include <windows.h>
  42. #include <windowsx.h>
  43. /*=========================================================================*/
  44. /* The following prototypes are for the file: TIMERA.ASM */
  45. /*=========================================================================*/
  46. //////////////////////////////////////////////////////////////////////////////////////////////
  47. //////////////////////////////////////// Externs /////////////////////////////////////////////
  48. extern BOOL TimerSystemOn;
  49. extern HANDLE TimerThreadHandle; //Handle of timer thread
  50. extern int InTimerCallback; //true if we are currently in a callback
  51. /*=========================================================================*/
  52. typedef enum BaseTimerEnum {
  53. BT_SYSTEM, // System timer (60 / second).
  54. BT_USER // User controllable timer (? / second).
  55. } BaseTimerEnum;
  56. class TimerClass {
  57. public:
  58. // Constructor. Timers set before low level init has been done will not
  59. // be able to be 'Started' or 'on' until timer system is in place.
  60. TimerClass(BaseTimerEnum timer=BT_SYSTEM, BOOL start=FALSE);
  61. // No destructor.
  62. ~TimerClass(void){}
  63. //
  64. long Set(long value, BOOL start=TRUE); // Set initial timer value.
  65. long Stop(void); // Pause timer.
  66. long Start(void); // Resume timer.
  67. long Reset(BOOL start=TRUE); // Reset timer to zero.
  68. long Time(void); // Fetch current timer value.
  69. protected:
  70. long Started; // Time last started (0 == not paused).
  71. long Accumulated; // Total accumulated ticks.
  72. private:
  73. // long (*Get_Ticks)(void); // System timer fetch.
  74. BaseTimerEnum TickType;
  75. long Get_Ticks (void);
  76. };
  77. inline long TimerClass::Reset(BOOL start)
  78. {
  79. return(Set(0, start));
  80. }
  81. class CountDownTimerClass : private TimerClass {
  82. public:
  83. // Constructor. Timers set before low level init has been done will not
  84. // be able to be 'Started' or 'on' until timer system is in place.
  85. CountDownTimerClass(BaseTimerEnum timer, long set, int on=FALSE);
  86. CountDownTimerClass(BaseTimerEnum timer=BT_SYSTEM, int on=FALSE);
  87. // No destructor.
  88. ~CountDownTimerClass(void){}
  89. // Public functions
  90. long Set(long set, BOOL start=TRUE); // Set count down value.
  91. long Reset(BOOL start=TRUE); // Reset timer to zero.
  92. long Stop(void); // Pause timer.
  93. long Start(void); // Resume timer.
  94. long Time(void); // Fetch current count down value.
  95. protected:
  96. long DelayTime; // Ticks remaining before countdown timer expires.
  97. };
  98. inline long CountDownTimerClass::Stop(void)
  99. {
  100. TimerClass::Stop();
  101. return(Time());
  102. }
  103. inline long CountDownTimerClass::Start(void)
  104. {
  105. TimerClass::Start();
  106. return(Time());
  107. }
  108. inline long CountDownTimerClass::Reset(BOOL start)
  109. {
  110. return (TimerClass::Reset(start));
  111. }
  112. class WinTimerClass {
  113. public:
  114. WinTimerClass ( UINT freq=60 , BOOL partial=0 );
  115. ~WinTimerClass();
  116. void Update_Tick_Count ( void );
  117. unsigned Get_System_Tick_Count ( void );
  118. unsigned Get_User_Tick_Count ( void );
  119. private:
  120. unsigned TimerHandle; //Handle for windows timer event
  121. unsigned Frequency; //Frequency of our windows timer in ticks per second
  122. unsigned TrueRate; //True rate of clock. (only use word)
  123. unsigned SysTicks; //Tick count of timer.
  124. unsigned UserTicks; //Tick count of timer.
  125. unsigned UserRate; //Desired rate of timer.
  126. };
  127. extern WinTimerClass *WindowsTimer;
  128. //////////////////////////////////////////////////////////////////////////////////////////////
  129. //////////////////////////////////////// externs //////////////////////////////////////////
  130. #ifndef FUNCTION_H
  131. extern TimerClass TickCount;
  132. #endif
  133. extern CountDownTimerClass CountDown;
  134. //////////////////////////////////////////////////////////////////////////////////////////////
  135. //////////////////////////////////////// Prototypes //////////////////////////////////////////
  136. extern "C" {
  137. long __cdecl Get_System_Tick_Count(void);
  138. long __cdecl Get_User_Tick_Count(void);
  139. void far __cdecl Timer_Interrupt_Func(void);
  140. // long Get_Num_Interrupts(unsigned int realmode);
  141. void __cdecl Disable_Timer_Interrupt(void);
  142. void __cdecl Enable_Timer_Interrupt(void);
  143. }
  144. /*=========================================================================*/
  145. /* The following prototypes are for the file: TIMER.CPP */
  146. /*=========================================================================*/
  147. BOOL __cdecl Init_Timer_System(unsigned int freq, int partial = FALSE);
  148. BOOL __cdecl Remove_Timer_System(VOID);
  149. #endif // TIMER_H