annotate Timer.cpp @ 2439:daf7807d0a86

Merge
author a.parshin
date Thu, 24 Jul 2014 00:32:18 +0300
parents d922225a6081
children 1e1b2728b3d3
rev   line source
2415
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
1 #define _CRTDBG_MAP_ALLOC
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
2 #include <stdlib.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
3 #include <crtdbg.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
4
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
5 #define _CRT_SECURE_NO_WARNINGS
2044
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
6
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
7 #include "Timer.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
8 #include "Keyboard.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
9 #include "Log.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
10
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
11 #include "OSAPI.h"
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
12
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
13
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
14
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 Timer *pMiscTimer = new Timer;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
18 Timer *pEventTimer;
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
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
22
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
23
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
24
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
25 //----- (00426317) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
26 unsigned __int64 Timer::Time()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
27 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
28 unsigned __int64 v2 = TimeQuant * timeGetTime() / 1000;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
29 if (v2 < uStartTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
30 uStartTime = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
31 return v2;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
32 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
33
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
34
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
35
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
36 //----- (00426349) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
37 void Timer::Pause()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
38 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
39 if (!bPaused)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
40 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
41 uStopTime = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
42 bPaused = true;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
43 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
44 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
45
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
46
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
47 //----- (00426363) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
48 void Timer::Resume()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
49 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
50 if (bPaused)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
51 {
2425
d922225a6081 Hot key for mm7 main menu
Ritor1
parents: 2415
diff changeset
52 pKeyActionMap->ResetKeys();//Unhandled application exception
d922225a6081 Hot key for mm7 main menu
Ritor1
parents: 2415
diff changeset
53
2044
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
54 bPaused = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
55 uStartTime = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
56 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
57 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
58
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
59 //----- (00426386) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
60 void Timer::TrackGameTime()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
61 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
62 if (!bTackGameTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
63 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
64 uGameTimeStart = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
65 bTackGameTime = true;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
66 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
67 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
68
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
69
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
70
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
71 //----- (004263A0) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
72 void Timer::StopGameTime()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
73 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
74 if (bTackGameTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
75 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
76 bTackGameTime = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
77 uStartTime = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
78 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
79 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
80
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
81 //----- (004263B7) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
82 void Timer::Update()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
83 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
84 //Timer *v1; // esi@1
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
85 //unsigned int v2; // eax@2
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
86 //signed int v3; // eax@3
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
87 //char v4; // zf@5
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
88
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
89
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
90 unsigned __int64 new_time = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
91 while (new_time <= uStartTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
92 new_time = Time();
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
93
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
94 uTimeElapsed = new_time - uStartTime;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
95 uStartTime = new_time;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
96
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
97 if (uTimeElapsed > 32)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
98 uTimeElapsed = 32;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
99
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
100 if (!bPaused && !bTackGameTime)
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
101 uTotalGameTimeElapsed += uTimeElapsed;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
102 dt_in_some_format = (uTimeElapsed << 16) / 128;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
103 }
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
104
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
105 //----- (00426402) --------------------------------------------------------
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
106 void Timer::Initialize()
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
107 {
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
108 uTotalGameTimeElapsed = 0;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
109 bReady = true;
28cb79ae2f6f Time.h rename
Ritor1
parents:
diff changeset
110 }