2023-08-03 14:19:05 -04:00
|
|
|
#include "mxticklemanager.h"
|
|
|
|
|
|
|
|
#include "decomp.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
#include "mxomni.h"
|
|
|
|
#include "mxtimer.h"
|
|
|
|
#include "mxtypes.h"
|
2023-08-03 14:19:05 -04:00
|
|
|
|
|
|
|
#define TICKLE_MANAGER_FLAG_DESTROY 0x1
|
|
|
|
|
|
|
|
DECOMP_SIZE_ASSERT(MxTickleClient, 0x10);
|
|
|
|
DECOMP_SIZE_ASSERT(MxTickleManager, 0x14);
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bdd10
|
2023-10-24 19:38:27 -04:00
|
|
|
MxTickleClient::MxTickleClient(MxCore* p_client, MxTime p_interval)
|
2023-08-03 14:19:05 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
m_flags = 0;
|
|
|
|
m_client = p_client;
|
|
|
|
m_interval = p_interval;
|
|
|
|
m_lastUpdateTime = -m_interval;
|
2023-08-03 14:19:05 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bdd30
|
2023-08-03 14:19:05 -04:00
|
|
|
MxTickleManager::~MxTickleManager()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
while (m_clients.size() != 0) {
|
|
|
|
MxTickleClient* client = m_clients.front();
|
|
|
|
m_clients.pop_front();
|
|
|
|
delete client;
|
|
|
|
}
|
2023-08-03 14:19:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Match.
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bdde0
|
2023-08-03 14:19:05 -04:00
|
|
|
MxResult MxTickleManager::Tickle()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxTime time = Timer()->GetTime();
|
|
|
|
|
|
|
|
MxTickleClientPtrList::iterator it = m_clients.begin();
|
|
|
|
|
|
|
|
while (it != m_clients.end()) {
|
|
|
|
MxTickleClient* client = *it;
|
|
|
|
if ((client->GetFlags() & TICKLE_MANAGER_FLAG_DESTROY) == 0) {
|
|
|
|
if (client->GetLastUpdateTime() >= time)
|
|
|
|
client->SetLastUpdateTime(-client->GetTickleInterval());
|
|
|
|
|
|
|
|
if ((client->GetTickleInterval() + client->GetLastUpdateTime()) < time) {
|
|
|
|
client->GetClient()->Tickle();
|
|
|
|
client->SetLastUpdateTime(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_clients.erase(it++);
|
|
|
|
delete client;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCESS;
|
2023-08-03 14:19:05 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bde80
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxTickleManager::RegisterClient(MxCore* p_client, MxTime p_interval)
|
2023-08-03 14:19:05 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxTime interval = GetClientTickleInterval(p_client);
|
|
|
|
if (interval == TICKLE_MANAGER_NOT_FOUND) {
|
|
|
|
MxTickleClient* client = new MxTickleClient(p_client, p_interval);
|
|
|
|
if (client != NULL)
|
|
|
|
m_clients.push_back(client);
|
|
|
|
}
|
2023-08-03 14:19:05 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bdf60
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxTickleManager::UnregisterClient(MxCore* p_client)
|
2023-08-03 14:19:05 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxTickleClientPtrList::iterator it = m_clients.begin();
|
|
|
|
while (it != m_clients.end()) {
|
|
|
|
MxTickleClient* client = *it;
|
|
|
|
if (client->GetClient() == p_client) {
|
|
|
|
client->SetFlags(client->GetFlags() | TICKLE_MANAGER_FLAG_DESTROY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
2023-08-03 14:19:05 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100bdfa0
|
2023-10-24 19:38:27 -04:00
|
|
|
void MxTickleManager::SetClientTickleInterval(MxCore* p_client, MxTime p_interval)
|
2023-08-03 14:19:05 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
for (MxTickleClientPtrList::iterator it = m_clients.begin(); it != m_clients.end(); it++) {
|
|
|
|
MxTickleClient* client = *it;
|
|
|
|
if ((client->GetClient() == p_client) && ((client->GetFlags() & TICKLE_MANAGER_FLAG_DESTROY) == 0)) {
|
|
|
|
client->SetTickleInterval(p_interval);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-08-03 14:19:05 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x100be000
|
2023-10-24 19:38:27 -04:00
|
|
|
MxTime MxTickleManager::GetClientTickleInterval(MxCore* p_client)
|
2023-08-03 14:19:05 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxTickleClientPtrList::iterator it = m_clients.begin();
|
|
|
|
while (it != m_clients.end()) {
|
|
|
|
MxTickleClient* client = *it;
|
|
|
|
if ((client->GetClient() == p_client) && ((client->GetFlags() & TICKLE_MANAGER_FLAG_DESTROY) == 0))
|
|
|
|
return client->GetTickleInterval();
|
2023-08-03 14:19:05 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
it++;
|
|
|
|
}
|
2023-08-03 14:19:05 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return TICKLE_MANAGER_NOT_FOUND;
|
2023-08-03 14:19:05 -04:00
|
|
|
}
|