Skip to content

Commit 935be9d

Browse files
authored
Implement LegoTestTimer (isledecomp#1732)
* Implement LegoTestTimer * Fix variable name * Use override
1 parent 99a0c39 commit 935be9d

4 files changed

Lines changed: 206 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ function(add_lego_libraries NAME)
371371
LEGO1/lego/legoomni/src/worlds/police.cpp
372372
LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp
373373
LEGO1/lego/legoomni/src/entity/legopovcontroller.cpp
374+
LEGO1/lego/legoomni/src/common/legotesttimer.cpp
374375
LEGO1/lego/legoomni/src/common/legotextureinfo.cpp
375376
LEGO1/lego/legoomni/src/actors/doors.cpp
376377
LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp

LEGO1/lego/legoomni/include/legoeventnotificationparam.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ class LegoEventNotificationParam : public MxNotificationParam {
4141
{
4242
}
4343

44+
// FUNCTION: BETA10 0x10026070
4445
LegoROI* GetROI() { return m_roi; }
46+
47+
// FUNCTION: BETA10 0x1006aab0
4548
MxU8 GetModifier() { return m_modifier; }
49+
50+
// FUNCTION: BETA10 0x100179a0
4651
MxU8 GetKey() const { return m_key; }
4752

4853
// FUNCTION: LEGO1 0x10012190
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef LEGOTESTTIMER_H
2+
#define LEGOTESTTIMER_H
3+
4+
#include "decomp.h"
5+
#include "misc/legotypes.h"
6+
#include "mxcore.h"
7+
#include "mxparam.h"
8+
9+
// VTABLE: BETA10 0x101bed08
10+
// SIZE 0x24
11+
class LegoTestTimer : public MxCore {
12+
public:
13+
LegoTestTimer(LegoS32 p_numTimers, LegoS32 p_interval, LegoS32 p_numBins, LegoS32 p_type);
14+
~LegoTestTimer() override; // vtable+00
15+
MxLong Notify(MxParam& p_param) override; // vtable+04
16+
17+
// FUNCTION: BETA10 0x100d18e0
18+
static const char* HandlerClassName() { return "LegoTestTimer"; }
19+
20+
// FUNCTION: BETA10 0x100d18b0
21+
const char* ClassName() const override // vtable+0c
22+
{
23+
return HandlerClassName();
24+
}
25+
26+
void Tick(LegoS32 p_timer);
27+
void ResetAtNextTick();
28+
void Print();
29+
30+
// SYNTHETIC: BETA10 0x100d1900
31+
// LegoTestTimer::`scalar deleting destructor'
32+
33+
private:
34+
LegoS32** m_timers; // 0x08
35+
LegoS32* m_lastTime; // 0x0c
36+
LegoS32* m_totalTime; // 0x10
37+
LegoS32 m_numTimers; // 0x14
38+
LegoS32 m_numBins; // 0x18
39+
LegoS32 m_interval; // 0x1c
40+
MxBool m_enable; // 0x20
41+
MxBool m_keyRegistered; // 0x21
42+
};
43+
44+
#endif // LEGOTESTTIMER_H
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#include "legotesttimer.h"
2+
3+
#include "legoeventnotificationparam.h"
4+
#include "legoinputmanager.h"
5+
#include "misc.h"
6+
#include "mxnotificationparam.h"
7+
8+
#include <stdio.h>
9+
10+
// FUNCTION: BETA10 0x100d1030
11+
LegoTestTimer::LegoTestTimer(LegoS32 p_numTimers, LegoS32 p_interval, LegoS32 p_numBins, LegoS32 p_type)
12+
{
13+
m_enable = FALSE;
14+
m_keyRegistered = FALSE;
15+
16+
if (p_interval > 0) {
17+
m_numTimers = p_numTimers;
18+
m_interval = p_interval;
19+
m_numBins = p_numBins / m_interval;
20+
21+
m_lastTime = new LegoS32[m_numTimers];
22+
m_totalTime = new LegoS32[m_numTimers];
23+
m_timers = new LegoS32*[m_numTimers];
24+
25+
for (int i = 0; i < m_numTimers; i++) {
26+
m_lastTime[i] = -1;
27+
m_timers[i] = new LegoS32[m_numBins];
28+
for (int j = 0; j < m_numBins; j++) {
29+
m_timers[i][j] = 0;
30+
}
31+
}
32+
}
33+
else {
34+
m_numTimers = 0;
35+
m_interval = 0;
36+
m_numBins = 0;
37+
m_lastTime = NULL;
38+
m_totalTime = NULL;
39+
m_timers = NULL;
40+
}
41+
}
42+
43+
// FUNCTION: BETA10 0x100d11ee
44+
LegoTestTimer::~LegoTestTimer()
45+
{
46+
if (m_keyRegistered && InputManager()) {
47+
InputManager()->UnRegister(this);
48+
}
49+
50+
m_enable = FALSE;
51+
if (m_numTimers != 0) {
52+
delete[] m_lastTime;
53+
delete[] m_totalTime;
54+
55+
for (int i = 0; i < m_numTimers; i++) {
56+
delete m_timers[i];
57+
}
58+
59+
delete[] m_timers;
60+
}
61+
}
62+
63+
// FUNCTION: BETA10 0x100d132c
64+
void LegoTestTimer::Tick(LegoS32 p_timer)
65+
{
66+
if (m_enable) {
67+
MxULong time = timeGetTime();
68+
LegoS32 prev = p_timer ? p_timer - 1 : 0;
69+
if (m_lastTime[p_timer] == -1) {
70+
m_lastTime[p_timer] = time;
71+
m_totalTime[p_timer] = 0;
72+
73+
for (int i = 0; i < m_numBins; i++) {
74+
m_timers[p_timer][i] = 0;
75+
}
76+
}
77+
else {
78+
LegoS32 dtim = time - m_lastTime[prev];
79+
if (dtim < 0) {
80+
dtim = 0;
81+
}
82+
83+
m_lastTime[p_timer] = time;
84+
LegoS32 binIndex = dtim / m_interval;
85+
if (binIndex >= m_numBins) {
86+
binIndex = m_numBins - 1;
87+
}
88+
89+
m_timers[p_timer][binIndex]++;
90+
m_totalTime[p_timer] += dtim;
91+
}
92+
}
93+
else if (!m_keyRegistered) {
94+
InputManager()->Register(this);
95+
m_keyRegistered = TRUE;
96+
}
97+
}
98+
99+
// FUNCTION: BETA10 0x100d148f
100+
void LegoTestTimer::Print()
101+
{
102+
FILE* f = fopen("\\TEST_TIME.TXT", "w");
103+
if (f) {
104+
int i;
105+
106+
fprintf(f, "timer");
107+
for (i = 0; i < m_numTimers; i++) {
108+
fprintf(f, "%8d ", i);
109+
}
110+
111+
fprintf(f, "\n");
112+
for (int k = 0; k < m_numBins; k++) {
113+
fprintf(f, "%3d: ", m_interval * (k + 1));
114+
for (int j = 0; j < m_numTimers; j++) {
115+
fprintf(f, "%8d ", m_timers[j][k]);
116+
}
117+
fprintf(f, "\n");
118+
}
119+
120+
fprintf(f, "ttime");
121+
for (i = 0; i < m_numTimers; i++) {
122+
fprintf(f, "%8d ", m_totalTime[i]);
123+
}
124+
125+
fclose(f);
126+
}
127+
128+
ResetAtNextTick();
129+
}
130+
131+
// FUNCTION: BETA10 0x100d161e
132+
void LegoTestTimer::ResetAtNextTick()
133+
{
134+
for (int i = 0; i < m_numTimers; i++) {
135+
m_lastTime[i] = -1;
136+
}
137+
}
138+
139+
// FUNCTION: BETA10 0x100d1667
140+
MxLong LegoTestTimer::Notify(MxParam& p_param)
141+
{
142+
if (((MxNotificationParam&) p_param).GetNotification() == c_notificationKeyPress) {
143+
MxU8 key = ((LegoEventNotificationParam&) p_param).GetKey();
144+
145+
if (key == 's' || key == 'S') {
146+
ResetAtNextTick();
147+
m_enable = TRUE;
148+
}
149+
else if (key == 'p' || key == 'P') {
150+
m_enable = FALSE;
151+
Print();
152+
}
153+
}
154+
155+
return 0;
156+
}

0 commit comments

Comments
 (0)