Implement LegoTestTimer (#1732)
Some checks failed
Analyze / ${{ matrix.who }} annotations (CONFIG) (push) Has been cancelled
Analyze / ${{ matrix.who }} annotations (ISLE) (push) Has been cancelled
Analyze / ${{ matrix.who }} annotations (LEGO1) (push) Has been cancelled
Build / Download original binaries (push) Has been cancelled
Build / Current ${{ matrix.toolchain.name }} (map[clang-tidy:true msys-env:mingw-w64-i686 msystem:mingw32 name:msys2 mingw32 shell:msys2 {0} werror:true]) (push) Has been cancelled
Build / Current ${{ matrix.toolchain.name }} (map[name:MSVC setup-cmake:true setup-msvc:true setup-ninja:true shell:sh]) (push) Has been cancelled
Build / MSVC 4.20 (push) Has been cancelled
Build / MSVC 4.20 (BETA10) (push) Has been cancelled
Format / C++ (push) Has been cancelled
Naming / C++ (push) Has been cancelled
Build / Verify decomp (push) Has been cancelled
Build / Upload artifacts (push) Has been cancelled

* Implement LegoTestTimer

* Fix variable name

* Use override
This commit is contained in:
MS 2026-01-27 13:21:56 -05:00 committed by GitHub
parent 99a0c3964e
commit 935be9de55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 206 additions and 0 deletions

View File

@ -371,6 +371,7 @@ function(add_lego_libraries NAME)
LEGO1/lego/legoomni/src/worlds/police.cpp LEGO1/lego/legoomni/src/worlds/police.cpp
LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp
LEGO1/lego/legoomni/src/entity/legopovcontroller.cpp LEGO1/lego/legoomni/src/entity/legopovcontroller.cpp
LEGO1/lego/legoomni/src/common/legotesttimer.cpp
LEGO1/lego/legoomni/src/common/legotextureinfo.cpp LEGO1/lego/legoomni/src/common/legotextureinfo.cpp
LEGO1/lego/legoomni/src/actors/doors.cpp LEGO1/lego/legoomni/src/actors/doors.cpp
LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp

View File

@ -41,8 +41,13 @@ class LegoEventNotificationParam : public MxNotificationParam {
{ {
} }
// FUNCTION: BETA10 0x10026070
LegoROI* GetROI() { return m_roi; } LegoROI* GetROI() { return m_roi; }
// FUNCTION: BETA10 0x1006aab0
MxU8 GetModifier() { return m_modifier; } MxU8 GetModifier() { return m_modifier; }
// FUNCTION: BETA10 0x100179a0
MxU8 GetKey() const { return m_key; } MxU8 GetKey() const { return m_key; }
// FUNCTION: LEGO1 0x10012190 // FUNCTION: LEGO1 0x10012190

View File

@ -0,0 +1,44 @@
#ifndef LEGOTESTTIMER_H
#define LEGOTESTTIMER_H
#include "decomp.h"
#include "misc/legotypes.h"
#include "mxcore.h"
#include "mxparam.h"
// VTABLE: BETA10 0x101bed08
// SIZE 0x24
class LegoTestTimer : public MxCore {
public:
LegoTestTimer(LegoS32 p_numTimers, LegoS32 p_interval, LegoS32 p_numBins, LegoS32 p_type);
~LegoTestTimer() override; // vtable+00
MxLong Notify(MxParam& p_param) override; // vtable+04
// FUNCTION: BETA10 0x100d18e0
static const char* HandlerClassName() { return "LegoTestTimer"; }
// FUNCTION: BETA10 0x100d18b0
const char* ClassName() const override // vtable+0c
{
return HandlerClassName();
}
void Tick(LegoS32 p_timer);
void ResetAtNextTick();
void Print();
// SYNTHETIC: BETA10 0x100d1900
// LegoTestTimer::`scalar deleting destructor'
private:
LegoS32** m_timers; // 0x08
LegoS32* m_lastTime; // 0x0c
LegoS32* m_totalTime; // 0x10
LegoS32 m_numTimers; // 0x14
LegoS32 m_numBins; // 0x18
LegoS32 m_interval; // 0x1c
MxBool m_enable; // 0x20
MxBool m_keyRegistered; // 0x21
};
#endif // LEGOTESTTIMER_H

View File

@ -0,0 +1,156 @@
#include "legotesttimer.h"
#include "legoeventnotificationparam.h"
#include "legoinputmanager.h"
#include "misc.h"
#include "mxnotificationparam.h"
#include <stdio.h>
// FUNCTION: BETA10 0x100d1030
LegoTestTimer::LegoTestTimer(LegoS32 p_numTimers, LegoS32 p_interval, LegoS32 p_numBins, LegoS32 p_type)
{
m_enable = FALSE;
m_keyRegistered = FALSE;
if (p_interval > 0) {
m_numTimers = p_numTimers;
m_interval = p_interval;
m_numBins = p_numBins / m_interval;
m_lastTime = new LegoS32[m_numTimers];
m_totalTime = new LegoS32[m_numTimers];
m_timers = new LegoS32*[m_numTimers];
for (int i = 0; i < m_numTimers; i++) {
m_lastTime[i] = -1;
m_timers[i] = new LegoS32[m_numBins];
for (int j = 0; j < m_numBins; j++) {
m_timers[i][j] = 0;
}
}
}
else {
m_numTimers = 0;
m_interval = 0;
m_numBins = 0;
m_lastTime = NULL;
m_totalTime = NULL;
m_timers = NULL;
}
}
// FUNCTION: BETA10 0x100d11ee
LegoTestTimer::~LegoTestTimer()
{
if (m_keyRegistered && InputManager()) {
InputManager()->UnRegister(this);
}
m_enable = FALSE;
if (m_numTimers != 0) {
delete[] m_lastTime;
delete[] m_totalTime;
for (int i = 0; i < m_numTimers; i++) {
delete m_timers[i];
}
delete[] m_timers;
}
}
// FUNCTION: BETA10 0x100d132c
void LegoTestTimer::Tick(LegoS32 p_timer)
{
if (m_enable) {
MxULong time = timeGetTime();
LegoS32 prev = p_timer ? p_timer - 1 : 0;
if (m_lastTime[p_timer] == -1) {
m_lastTime[p_timer] = time;
m_totalTime[p_timer] = 0;
for (int i = 0; i < m_numBins; i++) {
m_timers[p_timer][i] = 0;
}
}
else {
LegoS32 dtim = time - m_lastTime[prev];
if (dtim < 0) {
dtim = 0;
}
m_lastTime[p_timer] = time;
LegoS32 binIndex = dtim / m_interval;
if (binIndex >= m_numBins) {
binIndex = m_numBins - 1;
}
m_timers[p_timer][binIndex]++;
m_totalTime[p_timer] += dtim;
}
}
else if (!m_keyRegistered) {
InputManager()->Register(this);
m_keyRegistered = TRUE;
}
}
// FUNCTION: BETA10 0x100d148f
void LegoTestTimer::Print()
{
FILE* f = fopen("\\TEST_TIME.TXT", "w");
if (f) {
int i;
fprintf(f, "timer");
for (i = 0; i < m_numTimers; i++) {
fprintf(f, "%8d ", i);
}
fprintf(f, "\n");
for (int k = 0; k < m_numBins; k++) {
fprintf(f, "%3d: ", m_interval * (k + 1));
for (int j = 0; j < m_numTimers; j++) {
fprintf(f, "%8d ", m_timers[j][k]);
}
fprintf(f, "\n");
}
fprintf(f, "ttime");
for (i = 0; i < m_numTimers; i++) {
fprintf(f, "%8d ", m_totalTime[i]);
}
fclose(f);
}
ResetAtNextTick();
}
// FUNCTION: BETA10 0x100d161e
void LegoTestTimer::ResetAtNextTick()
{
for (int i = 0; i < m_numTimers; i++) {
m_lastTime[i] = -1;
}
}
// FUNCTION: BETA10 0x100d1667
MxLong LegoTestTimer::Notify(MxParam& p_param)
{
if (((MxNotificationParam&) p_param).GetNotification() == c_notificationKeyPress) {
MxU8 key = ((LegoEventNotificationParam&) p_param).GetKey();
if (key == 's' || key == 'S') {
ResetAtNextTick();
m_enable = TRUE;
}
else if (key == 'p' || key == 'P') {
m_enable = FALSE;
Print();
}
}
return 0;
}