Timing.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //******************************************************************************************
  2. // timing.cpp - This file contains the declarations for the timing variables
  3. //
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. //----------------------------------------------------------------------------------
  8. // Include Files
  9. #ifndef TIMING_H
  10. #include "timing.h"
  11. #endif
  12. #include <windows.h>
  13. #include <winbase.h>
  14. #include <math.h>
  15. //----------------------------------------------------------------------------------
  16. long turn = 0;
  17. float frameLength = 0.05f;
  18. float scenarioTime = 0.0;
  19. DWORD LastTimeGetTime = 0;
  20. bool dynamicFrameTiming = TRUE;
  21. char *monthName[12] =
  22. {
  23. "Jan",
  24. "Feb",
  25. "Mar",
  26. "Apr",
  27. "May",
  28. "Jun",
  29. "Jul",
  30. "Aug",
  31. "Sep",
  32. "Oct",
  33. "Nov",
  34. "Dec"
  35. };
  36. //----------------------------------------------------------------------------------
  37. DWORD MCTiming_GetTimeZoneInforation(void *timeData)
  38. {
  39. // Get Time Zone information for this machine to calculate
  40. // Astronomy correctly.
  41. DWORD daylightSavingsInfo = GetTimeZoneInformation((TIME_ZONE_INFORMATION *)timeData);
  42. return daylightSavingsInfo;
  43. }
  44. //----------------------------------------------------------------------------------
  45. DWORD MCTiming_GetTimeZoneInformationSize (void)
  46. {
  47. return sizeof(TIME_ZONE_INFORMATION);
  48. }
  49. //----------------------------------------------------------------------------------
  50. void MC_SYSTEMTIME::copyFromSystemTime (void *systemTime)
  51. {
  52. SYSTEMTIME *sysTime = (SYSTEMTIME *)systemTime;
  53. dwYear = sysTime->wYear;
  54. dwMonth = sysTime->wMonth;
  55. dwDayOfWeek = sysTime->wDayOfWeek;
  56. dwDay = sysTime->wDay;
  57. dwHour = sysTime->wHour;
  58. dwMinute = sysTime->wMinute;
  59. dwSecond = sysTime->wSecond;
  60. dwMilliseconds = sysTime->wMilliseconds;
  61. }
  62. //----------------------------------------------------------------------------------
  63. void MCTiming_GetUTCSystemTimeFromInformation(DWORD daylightInfo, void *timeData, MC_SYSTEMTIME *systemTime)
  64. {
  65. TIME_ZONE_INFORMATION *tzInfo = (TIME_ZONE_INFORMATION *)timeData;
  66. SYSTEMTIME sysTime;
  67. GetSystemTime(&sysTime);
  68. long bias = tzInfo->Bias;
  69. if (daylightInfo == TIME_ZONE_ID_STANDARD)
  70. {
  71. bias += tzInfo->StandardBias;
  72. }
  73. else if (daylightInfo == TIME_ZONE_ID_DAYLIGHT)
  74. {
  75. bias += tzInfo->DaylightBias;
  76. }
  77. else //Assume Standard
  78. {
  79. bias += tzInfo->StandardBias;
  80. }
  81. systemTime->copyFromSystemTime(&(sysTime));
  82. }
  83. //----------------------------------------------------------------------------------