Timing.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //******************************************************************************************
  2. // timing.h - This file contains the externs for the timing variables
  3. //
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. #ifndef TIMING_H
  8. #define TIMING_H
  9. //----------------------------------------------------------------------------------
  10. // Include Files
  11. #ifndef DSTD_H
  12. #include "dstd.h"
  13. #endif
  14. //----------------------------------------------------------------------------------
  15. extern bool gamePaused; //Is the game paused?
  16. extern long turn; //What frame of the scenario is it?
  17. extern float frameLength; //Duration of last frame in seconds.
  18. extern float scenarioTime; //Time scenario has been running.
  19. extern DWORD LastTimeGetTime; //Stores Interval since timeGetTime last called.
  20. extern bool dynamicFrameTiming; //This flag determines if we are using frameLength
  21. //To time a frame. This is FALSE when something
  22. //puches a frame length dramatically over 4fps.
  23. //Like a cache hit. It insures all frames get played.
  24. //----------------------------------------------------------------------------------
  25. // Macro Definitions
  26. #define MAX_TIMERS 32
  27. //----------------------------------------------------------------------------------
  28. class Timer
  29. {
  30. protected:
  31. float startTime;
  32. float currentTime;
  33. bool expired;
  34. bool updateWhilePaused;
  35. public:
  36. Timer (void)
  37. {
  38. init();
  39. }
  40. ~Timer (void)
  41. {
  42. destroy();
  43. }
  44. void init (void)
  45. {
  46. startTime = 0.0;
  47. currentTime = 0.0;
  48. expired = TRUE;
  49. updateWhilePaused = FALSE;
  50. }
  51. void destroy (void)
  52. {
  53. }
  54. void update (void)
  55. {
  56. if (updateWhilePaused || !gamePaused)
  57. {
  58. currentTime -= frameLength;
  59. if (currentTime < 0.0)
  60. expired = TRUE;
  61. else
  62. expired = FALSE;
  63. }
  64. }
  65. bool isExpired (void)
  66. {
  67. return expired;
  68. }
  69. void setTimer (float newTime)
  70. {
  71. startTime = newTime;
  72. currentTime = newTime;
  73. expired = (newTime > 0.0);
  74. }
  75. void setUpdateWhilePaused (bool val)
  76. {
  77. updateWhilePaused = val;
  78. }
  79. float getCurrentTime (void)
  80. {
  81. return currentTime;
  82. }
  83. };
  84. typedef Timer *TimerPtr;
  85. //----------------------------------------------------------------------------------
  86. class TimerManager
  87. {
  88. protected:
  89. Timer timers[MAX_TIMERS];
  90. public:
  91. TimerManager (void)
  92. {
  93. init();
  94. }
  95. ~TimerManager (void)
  96. {
  97. destroy();
  98. }
  99. void init (void)
  100. {
  101. for (long i=0;i<MAX_TIMERS;i++)
  102. {
  103. timers[i].init();
  104. }
  105. }
  106. void destroy (void)
  107. {
  108. for (long i=0;i<MAX_TIMERS;i++)
  109. {
  110. timers[i].init();
  111. }
  112. }
  113. TimerPtr getTimer (long index)
  114. {
  115. if ((index >= 0) && (index < MAX_TIMERS))
  116. return &(timers[index]);
  117. return NULL;
  118. }
  119. void update (void)
  120. {
  121. for (long i=0;i<MAX_TIMERS;i++)
  122. {
  123. timers[i].update();
  124. }
  125. }
  126. };
  127. typedef TimerManager *TimerManagerPtr;
  128. //----------------------------------------------------------------------------------
  129. extern TimerManagerPtr timerManager;
  130. extern char *monthName[];
  131. //----------------------------------------------------------------------------------
  132. // Find out actual system time
  133. typedef struct _MC_SYSTEMTIME
  134. {
  135. DWORD dwYear;
  136. DWORD dwMonth;
  137. DWORD dwDayOfWeek;
  138. DWORD dwDay;
  139. DWORD dwHour;
  140. DWORD dwMinute;
  141. DWORD dwSecond;
  142. DWORD dwMilliseconds;
  143. void copyFromSystemTime (void *systemTime);
  144. } MC_SYSTEMTIME;
  145. DWORD MCTiming_GetTimeZoneInforation(void *timeData);
  146. DWORD MCTiming_GetTimeZoneInformationSize (void);
  147. void MCTiming_GetUTCSystemTimeFromInformation(DWORD daylightInfo, void *timeData, MC_SYSTEMTIME *systemTime);
  148. //----------------------------------------------------------------------------------
  149. #endif