ezEngine  Milestone 7
Time_win.h
1 
2 static double g_fInvQpcFrequency;
3 
4 void ezTime::Initialize()
5 {
6  LARGE_INTEGER frequency;
7  QueryPerformanceFrequency(&frequency);
8 
9  g_fInvQpcFrequency = 1.0 / double(frequency.QuadPart);
10 }
11 
12 #if EZ_ENABLED(EZ_COMPILE_FOR_DEVELOPMENT)
13  static ezAtomicInteger64 s_LastTime;
14 #endif
15 
17 {
18 #if EZ_ENABLED(EZ_COMPILE_FOR_DEVELOPMENT)
19  ezInt64 LastTime = s_LastTime;
20 #endif
21 
22  LARGE_INTEGER temp;
23  QueryPerformanceCounter(&temp);
24 
25 #if EZ_ENABLED(EZ_COMPILE_FOR_DEVELOPMENT)
26  EZ_ASSERT_DEV(LastTime <= temp.QuadPart, "Serious problem, Steve. This is like \"Houston, forget that other thing\".\n\n\n"
27  "When this happens the PC timer is unreliable. It was probably called from different threads and the clocks on different CPU cores seem to return different results.\n"
28  "Under these conditions the engine cannot run reliably, it might crash or act weird.");
29  while (!s_LastTime.TestAndSet(LastTime, ezMath::Max(LastTime, temp.QuadPart)))
30  {
31  LastTime = s_LastTime;
32  }
33 #endif
34 
35  return ezTime::Seconds(double(temp.QuadPart) * g_fInvQpcFrequency);
36 }
37