diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b7cbf0e..519f26c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -371,6 +371,7 @@ function(add_lego_libraries NAME) LEGO1/lego/legoomni/src/worlds/police.cpp LEGO1/lego/legoomni/src/common/legoanimationmanager.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/actors/doors.cpp LEGO1/lego/legoomni/src/entity/legoworldpresenter.cpp diff --git a/LEGO1/lego/legoomni/include/legoeventnotificationparam.h b/LEGO1/lego/legoomni/include/legoeventnotificationparam.h index 7cfa28f9..a12c5afd 100644 --- a/LEGO1/lego/legoomni/include/legoeventnotificationparam.h +++ b/LEGO1/lego/legoomni/include/legoeventnotificationparam.h @@ -41,8 +41,13 @@ class LegoEventNotificationParam : public MxNotificationParam { { } + // FUNCTION: BETA10 0x10026070 LegoROI* GetROI() { return m_roi; } + + // FUNCTION: BETA10 0x1006aab0 MxU8 GetModifier() { return m_modifier; } + + // FUNCTION: BETA10 0x100179a0 MxU8 GetKey() const { return m_key; } // FUNCTION: LEGO1 0x10012190 diff --git a/LEGO1/lego/legoomni/include/legotesttimer.h b/LEGO1/lego/legoomni/include/legotesttimer.h new file mode 100644 index 00000000..51d17d16 --- /dev/null +++ b/LEGO1/lego/legoomni/include/legotesttimer.h @@ -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 diff --git a/LEGO1/lego/legoomni/src/common/legotesttimer.cpp b/LEGO1/lego/legoomni/src/common/legotesttimer.cpp new file mode 100644 index 00000000..e40d9a62 --- /dev/null +++ b/LEGO1/lego/legoomni/src/common/legotesttimer.cpp @@ -0,0 +1,156 @@ +#include "legotesttimer.h" + +#include "legoeventnotificationparam.h" +#include "legoinputmanager.h" +#include "misc.h" +#include "mxnotificationparam.h" + +#include + +// 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; +}