2499
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6
|
|
7 #include "Timer.h"
|
|
8 #include "Keyboard.h"
|
|
9
|
|
10 #include "OSAPI.h"
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16 Timer *pMiscTimer = new Timer;
|
|
17 Timer *pEventTimer;
|
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
|
23
|
|
24 //----- (00426317) --------------------------------------------------------
|
|
25 unsigned __int64 Timer::Time()
|
|
26 {
|
|
27 unsigned __int64 v2 = TimeQuant * timeGetTime() / 1000;
|
|
28 if (v2 < uStartTime)
|
|
29 uStartTime = 0;
|
|
30 return v2;
|
|
31 }
|
|
32
|
|
33
|
|
34
|
|
35 //----- (00426349) --------------------------------------------------------
|
|
36 void Timer::Pause()
|
|
37 {
|
|
38 if (!bPaused)
|
|
39 {
|
|
40 uStopTime = Time();
|
|
41 bPaused = true;
|
|
42 }
|
|
43 }
|
|
44
|
|
45 //----- (00426363) --------------------------------------------------------
|
|
46 void Timer::Resume()
|
|
47 {
|
|
48 if (bPaused)
|
|
49 {
|
|
50 pKeyActionMap->ResetKeys();//Unhandled application exception
|
|
51
|
|
52 bPaused = 0;
|
|
53 uStartTime = Time();
|
|
54 }
|
|
55 }
|
|
56
|
|
57 //----- (00426386) --------------------------------------------------------
|
|
58 void Timer::TrackGameTime()
|
|
59 {
|
|
60 if (!bTackGameTime)
|
|
61 {
|
|
62 uGameTimeStart = Time();
|
|
63 bTackGameTime = true;
|
|
64 }
|
|
65 }
|
|
66
|
|
67
|
|
68
|
|
69 //----- (004263A0) --------------------------------------------------------
|
|
70 void Timer::StopGameTime()
|
|
71 {
|
|
72 if (bTackGameTime)
|
|
73 {
|
|
74 bTackGameTime = 0;
|
|
75 uStartTime = Time();
|
|
76 }
|
|
77 }
|
|
78
|
|
79 //----- (004263B7) --------------------------------------------------------
|
|
80 void Timer::Update()
|
|
81 {
|
|
82 //Timer *v1; // esi@1
|
|
83 //unsigned int v2; // eax@2
|
|
84 //signed int v3; // eax@3
|
|
85 //char v4; // zf@5
|
|
86
|
|
87
|
|
88 unsigned __int64 new_time = Time();
|
|
89 while (new_time <= uStartTime)
|
|
90 new_time = Time();
|
|
91
|
|
92 uTimeElapsed = new_time - uStartTime;
|
|
93 uStartTime = new_time;
|
|
94
|
|
95 if (uTimeElapsed > 32)
|
|
96 uTimeElapsed = 32;
|
|
97
|
|
98 if (!bPaused && !bTackGameTime)
|
|
99 uTotalGameTimeElapsed += uTimeElapsed;
|
|
100 dt_in_some_format = (uTimeElapsed << 16) / 128;
|
|
101 }
|
|
102
|
|
103 //----- (00426402) --------------------------------------------------------
|
|
104 void Timer::Initialize()
|
|
105 {
|
|
106 uTotalGameTimeElapsed = 0;
|
|
107 bReady = true;
|
|
108 }
|