World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
Time.cpp
См. документацию.
1 #include "Engine/Time.h"
2 
3 #include <chrono>
4 
5 #include "IO/Keyboard.h"
6 
9 
10 //----- (00426317) --------------------------------------------------------
12  std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
13  uint64_t v2 = TIME_QUANT * ms.count() / 1000;
14  if (v2 < uStartTime) uStartTime = 0;
15  return v2;
16 }
17 
18 //----- (00426349) --------------------------------------------------------
19 void Timer::Pause() {
20  if (!bPaused) {
21  uStopTime = Time();
22  bPaused = true;
23  }
24 }
25 
26 //----- (00426363) --------------------------------------------------------
27 void Timer::Resume() {
28  if (bPaused) {
29  pKeyActionMap->ResetKeys(); // Unhandled application exception
30 
31  bPaused = 0;
32  uStartTime = Time();
33  }
34 }
35 
36 //----- (00426386) --------------------------------------------------------
38  if (!bTackGameTime) {
39  uGameTimeStart = Time();
40  bTackGameTime = true;
41  }
42 }
43 
44 //----- (004263A0) --------------------------------------------------------
46  if (bTackGameTime) {
47  bTackGameTime = 0;
48  uStartTime = Time();
49  }
50 }
51 
52 //----- (004263B7) --------------------------------------------------------
53 void Timer::Update() {
54  // Timer *v1; // esi@1
55  // unsigned int v2; // eax@2
56  // signed int v3; // eax@3
57  // char v4; // zf@5
58 
59  uint64_t new_time = Time();
60  while (new_time <= uStartTime) new_time = Time();
61 
62  uTimeElapsed = new_time - uStartTime;
63  uStartTime = new_time;
64 
65  if (uTimeElapsed > 32) uTimeElapsed = 32;
66 
68  dt_in_some_format = (uTimeElapsed << 16) / 128;
69 }
70 
71 //----- (00426402) --------------------------------------------------------
74  bReady = true;
75 }
Timer::TrackGameTime
void TrackGameTime()
Definition: Time.cpp:37
Timer::Time
uint64_t Time()
Definition: Time.cpp:11
Timer::uTimeElapsed
unsigned int uTimeElapsed
Definition: Time.h:133
Timer::Update
void Update()
Definition: Time.cpp:53
Timer::Initialize
void Initialize()
Definition: Time.cpp:72
Timer::Resume
void Resume()
Definition: Time.cpp:27
Timer::bPaused
unsigned int bPaused
Definition: Time.h:127
uint64_t
unsigned __int64 uint64_t
Definition: alext.h:32
Timer::bTackGameTime
int bTackGameTime
Definition: Time.h:128
Timer::uStopTime
unsigned int uStopTime
Definition: Time.h:130
Timer::dt_in_some_format
int dt_in_some_format
Definition: Time.h:134
Timer::uGameTimeStart
int uGameTimeStart
Definition: Time.h:131
Timer::Pause
void Pause()
Definition: Time.cpp:19
KeyboardActionMapping::ResetKeys
void ResetKeys()
Definition: Keyboard.cpp:176
Timer::bReady
unsigned int bReady
Definition: Time.h:126
pMiscTimer
Timer * pMiscTimer
Definition: Time.cpp:7
Timer::StopGameTime
void StopGameTime()
Definition: Time.cpp:45
Timer
Definition: Time.h:104
pKeyActionMap
struct KeyboardActionMapping * pKeyActionMap
Definition: Keyboard.cpp:35
v2
GLfloat GLfloat GLfloat v2
Definition: SDL_opengl_glext.h:695
Timer::uStartTime
unsigned int uStartTime
Definition: Time.h:129
Timer::uTotalGameTimeElapsed
unsigned int uTotalGameTimeElapsed
Definition: Time.h:135
Keyboard.h
pEventTimer
Timer * pEventTimer
Definition: Time.cpp:8
Time.h