Isle
Loading...
Searching...
No Matches
mxticklethread.cpp
Go to the documentation of this file.
1#include "mxticklethread.h"
2
3#include "decomp.h"
4#include "mxmisc.h"
5#include "mxtimer.h"
6
8
9// FUNCTION: LEGO1 0x100b8bb0
10MxTickleThread::MxTickleThread(MxCore* p_target, MxS32 p_frequencyMS)
11{
12 m_target = p_target;
13 m_frequencyMS = p_frequencyMS;
14}
15
16// Match except for register allocation
17// FUNCTION: LEGO1 0x100b8c90
19{
20 MxTimer* timer = Timer();
21 MxS32 lastTickled = -m_frequencyMS;
22
23 while (IsRunning()) {
24 MxLong currentTime = timer->GetTime();
25
26 if (currentTime < lastTickled) {
27 lastTickled = -m_frequencyMS;
28 }
29
30 MxS32 timeRemainingMS = (m_frequencyMS - currentTime) + lastTickled;
31 if (timeRemainingMS <= 0) {
33 timeRemainingMS = 0;
34 lastTickled = currentTime;
35 }
36
37 Sleep(timeRemainingMS);
38 }
39
40 return MxThread::Run();
41}
[AI] Base virtual class for all Mindscape engine (Mx) objects.
Definition: mxcore.h:15
virtual MxResult Tickle()
[AI] Called by tickle managers to allow the object to update itself.
Definition: mxcore.h:31
MxCore * m_target
[AI] Pointer to the target object (optional, typically the object being processed by the thread)....
Definition: mxthread.h:90
virtual MxResult Run()
[AI] Virtual function executed when the thread runs.
Definition: mxthread.cpp:63
void Sleep(MxS32 p_milliseconds)
[AI] Sleeps the current thread for the given duration in milliseconds.
Definition: mxthread.cpp:44
MxBool IsRunning()
[AI] Returns whether the thread is currently running.
Definition: mxthread.h:56
MxTickleThread periodically calls Tickle() on a target MxCore object in a separate thread.
MxResult Run() override
[AI] Thread entry point.
Timer class for measuring elapsed time or frame time.
Definition: mxtimer.h:14
MxLong GetTime()
Returns the current timer value in ms, depending on running state.
Definition: mxtimer.h:50
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
MxTimer * Timer()
[AI] Returns the global simulation timer.
Definition: mxmisc.cpp:33
MxLong MxResult
[AI]
Definition: mxtypes.h:106
int MxLong
[AI]
Definition: mxtypes.h:83
signed int MxS32
[AI]
Definition: mxtypes.h:38