Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
systimer.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** Confidential - Westwood Studios ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Commando *
24 * *
25 * $Archive:: /Commando/Code/wwlib/systimer.h $*
26 * *
27 * $Author:: Steve_t $*
28 * *
29 * $Modtime:: 12/09/01 6:41p $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#pragma once
38#ifndef _SYSTIMER_H
39
40#include "always.h"
41#include <windows.h>
42#include "mmsys.h"
43
44#define TIMEGETTIME SystemTime.Get
45#define MS_TIMER_SECOND 1000
46
47/*
48** Class that just wraps around timeGetTime()
49**
50**
51*/
53{
54
55 public:
56
57 SysTimeClass(void); //default constructor
58 ~SysTimeClass(); //default destructor
59
60 /*
61 ** Get. Use everywhere you would use timeGetTime
62 */
63 WWINLINE unsigned long Get(void);
64 WWINLINE unsigned long operator () (void) {return(Get());}
65 WWINLINE operator unsigned long(void) {return(Get());}
66
67 /*
68 ** Use periodically (like every few days!) to make sure the timer doesn't wrap.
69 */
70 void Reset(void);
71
72 /*
73 ** See if the timer is about to wrap.
74 */
75 bool Is_Getting_Late(void);
76
77 private:
78
79 /*
80 ** Time we were first called.
81 */
82 unsigned long StartTime;
83
84 /*
85 ** Time to add after timer wraps.
86 */
87 unsigned long WrapAdd;
88
89};
90
92
93
94/***********************************************************************************************
95 * SysTimeClass::Get -- Wrapper around system timeGetTime() api call *
96 * *
97 * *
98 * *
99 * INPUT: Nothing *
100 * *
101 * OUTPUT: Current system time in ms *
102 * *
103 * WARNINGS: None *
104 * *
105 * HISTORY: *
106 * 10/25/2001 1:38PM ST : Created *
107 *=============================================================================================*/
108WWINLINE unsigned long SysTimeClass::Get(void)
109{
110 /*
111 ** This has to be static here since we don't know if we will get called in a global constructor of another object before our
112 ** constructor gets called. In fact, we don't even have a constructor because it's pointless.
113 */
114 static bool is_init = false;
115
116 if (!is_init) {
117 Reset();
118 is_init = true;
119 }
120
121 unsigned long time = timeGetTime();
122 if (time > StartTime) {
123 return(time - StartTime);
124 }
125
126 /*
127 ** Timer wrapped around. Eeek.
128 */
129 return(time + WrapAdd);
130}
131
132
133
134#ifdef timeGetTime
135#undef timeGetTime
136#define timeGetTime SystemTime.Get
137#endif //timeGetTime
138
139
140
141
142#endif //_SYSTIMER_H
#define WWINLINE
Definition always.h:172
bool Is_Getting_Late(void)
Definition systimer.cpp:118
SysTimeClass(void)
Definition systimer.cpp:56
void Reset(void)
Definition systimer.cpp:96
WWINLINE unsigned long Get(void)
Definition systimer.h:108
WWINLINE unsigned long operator()(void)
Definition systimer.h:64
SysTimeClass SystemTime
Definition systimer.cpp:39