Isle
Loading...
Searching...
No Matches
mxticklemanager.cpp
Go to the documentation of this file.
1#include "mxticklemanager.h"
2
3#include "decomp.h"
4#include "mxmisc.h"
5#include "mxtimer.h"
6#include "mxtypes.h"
7
8#include <assert.h>
9
10#define TICKLE_MANAGER_FLAG_DESTROY 0x01
11
14
15// FUNCTION: LEGO1 0x100bdd10
17{
18 m_flags = 0;
19 m_client = p_client;
20 m_interval = p_interval;
21 m_lastUpdateTime = -m_interval;
22}
23
24// FUNCTION: LEGO1 0x100bdd30
26{
27 while (m_clients.size() != 0) {
28 MxTickleClient* client = m_clients.front();
29 m_clients.pop_front();
30 delete client;
31 }
32}
33
34// FUNCTION: LEGO1 0x100bdde0
35// FUNCTION: BETA10 0x1013eb1f
37{
38 MxTime time = Timer()->GetTime();
39 MxTickleClientPtrList::iterator it;
40
41 for (it = m_clients.begin(); !(it == m_clients.end());) {
42 MxTickleClient* client = *it;
43
45 m_clients.erase(it++);
46 delete client;
47 }
48 else {
49 it++;
50
51 if (client->GetLastUpdateTime() > time) {
52 client->SetLastUpdateTime(-client->GetTickleInterval());
53 }
54
55 if ((client->GetTickleInterval() + client->GetLastUpdateTime()) < time) {
56 client->GetClient()->Tickle();
57 client->SetLastUpdateTime(time);
58 }
59 }
60 }
61
62 return SUCCESS;
63}
64
65// FUNCTION: LEGO1 0x100bde80
66// FUNCTION: BETA10 0x1013ec5f
68{
69 MxTime interval = GetClientTickleInterval(p_client);
70 if (interval == TICKLE_MANAGER_NOT_FOUND) {
71 MxTickleClient* client = new MxTickleClient(p_client, p_interval);
72 if (client != NULL) {
73 m_clients.push_back(client);
74 }
75 }
76}
77
78// FUNCTION: LEGO1 0x100bdf60
79// FUNCTION: BETA10 0x1013edd0
81{
82 MxTickleClientPtrList::iterator it = m_clients.begin();
83 while (it != m_clients.end()) {
84 MxTickleClient* client = *it;
85 if (client->GetClient() == p_client) {
87 return;
88 }
89
90 it++;
91 }
92}
93
94// FUNCTION: LEGO1 0x100bdfa0
95// FUNCTION: BETA10 0x1013ee6d
97{
98 for (MxTickleClientPtrList::iterator it = m_clients.begin(); it != m_clients.end(); it++) {
99 MxTickleClient* client = *it;
100 if ((client->GetClient() == p_client) && ((client->GetFlags() & TICKLE_MANAGER_FLAG_DESTROY) == 0)) {
101 client->SetTickleInterval(p_interval);
102 return;
103 }
104 }
105}
106
107// FUNCTION: LEGO1 0x100be000
108// FUNCTION: BETA10 0x1013ef2d
110{
111 MxTickleClientPtrList::iterator it = m_clients.begin();
112 while (it != m_clients.end()) {
113 MxTickleClient* client = *it;
114 if ((client->GetClient() == p_client) && ((client->GetFlags() & TICKLE_MANAGER_FLAG_DESTROY) == 0)) {
115 return client->GetTickleInterval();
116 }
117
118 it++;
119 }
120
122}
[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
[AI] Associates an MxCore object with tickle timing/interval information.
MxCore * GetClient() const
[AI] Returns the managed MxCore object.
MxTime GetLastUpdateTime() const
[AI] Returns the timestamp of the last tickle.
void SetFlags(MxU16 p_flags)
[AI] Sets the flags for this client (e.g., destruction flag).
MxTime GetTickleInterval() const
[AI] Returns the tickle interval in milliseconds.
MxU16 GetFlags() const
[AI] Returns the internal flags for this tickle client.
MxTickleClient(MxCore *p_client, MxTime p_interval)
[AI] Constructs a tickle client for the given object and interval.
void SetLastUpdateTime(MxTime p_lastUpdateTime)
[AI] Sets the last tickle time (updates the timestamp).
void SetTickleInterval(MxTime p_interval)
[AI] Sets the tickle interval for this client.
[AI] Manages ticking ("tickling") a set of MxCore objects at specified intervals.
virtual void UnregisterClient(MxCore *p_client)
[AI] Unregisters (marks for destruction) a previously registered client.
virtual void SetClientTickleInterval(MxCore *p_client, MxTime p_interval)
[AI] Changes the tickle interval of an already registered client.
MxResult Tickle() override
[AI] Iterates over registered clients and invokes their Tickle() methods as needed.
virtual MxTime GetClientTickleInterval(MxCore *p_client)
[AI] Looks up the tickle interval of a registered client.
virtual void RegisterClient(MxCore *p_client, MxTime p_interval)
[AI] Registers an MxCore object to receive periodic tickles.
~MxTickleManager() override
[AI] Destroys the tickle manager, unregistering and freeing all clients.
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
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
MxTimer * Timer()
[AI] Returns the global simulation timer.
Definition: mxmisc.cpp:33
#define TICKLE_MANAGER_FLAG_DESTROY
#define TICKLE_MANAGER_NOT_FOUND
[AI] Returned by GetClientTickleInterval when the client is not found. [AI]
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
MxS32 MxTime
[AI]
Definition: mxtypes.h:100