annotate Timer.cpp @ 2315:58be29479e75

add files
author Ritor1
date Wed, 19 Mar 2014 10:09:42 +0600
parents aff7a7b072b7
children f4af3b203f65
rev   line source
2253
aff7a7b072b7 adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents: 2044
diff changeset
1 #define _CRT_SECURE_NO_WARNINGS
2044
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
2
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
3 #include "Timer.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
4 #include "Keyboard.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
5 #include "Log.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
6
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
7 #include "OSAPI.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
8
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
9
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
10
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
11
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
12
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
13 Timer *pMiscTimer = new Timer;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
14 Timer *pEventTimer;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
15
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
16
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
17
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
18
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
19
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
20
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
21 //----- (00426317) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
22 unsigned __int64 Timer::Time()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
23 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
24 unsigned __int64 v2 = TimeQuant * timeGetTime() / 1000;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
25 if (v2 < uStartTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
26 uStartTime = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
27 return v2;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
28 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
29
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
30
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
31
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
32 //----- (00426349) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
33 void Timer::Pause()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
34 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
35 if (!bPaused)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
36 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
37 uStopTime = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
38 bPaused = true;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
39 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
40 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
41
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
42
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
43 //----- (00426363) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
44 void Timer::Resume()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
45 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
46 if (bPaused)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
47 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
48 pKeyActionMap->ResetKeys();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
49 bPaused = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
50 uStartTime = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
51 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
52 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
53
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
54 //----- (00426386) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
55 void Timer::TrackGameTime()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
56 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
57 if (!bTackGameTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
58 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
59 uGameTimeStart = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
60 bTackGameTime = true;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
61 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
62 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
63
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
64
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
65
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
66 //----- (004263A0) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
67 void Timer::StopGameTime()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
68 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
69 if (bTackGameTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
70 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
71 bTackGameTime = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
72 uStartTime = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
73 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
74 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
75
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
76 //----- (004263B7) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
77 void Timer::Update()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
78 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
79 //Timer *v1; // esi@1
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
80 //unsigned int v2; // eax@2
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
81 //signed int v3; // eax@3
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
82 //char v4; // zf@5
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
83
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
84
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
85 unsigned __int64 new_time = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
86 while (new_time <= uStartTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
87 new_time = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
88
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
89 uTimeElapsed = new_time - uStartTime;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
90 uStartTime = new_time;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
91
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
92 if (uTimeElapsed > 32)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
93 uTimeElapsed = 32;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
94
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
95 if (!bPaused && !bTackGameTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
96 uTotalGameTimeElapsed += uTimeElapsed;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
97 dt_in_some_format = (uTimeElapsed << 16) / 128;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
98 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
99
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
100 //----- (00426402) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
101 void Timer::Initialize()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
102 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
103 uTotalGameTimeElapsed = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
104 bReady = true;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
105 }