annotate Engine/Timer.cpp @ 2520:9f7908a4d8e6

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