2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/CObjectList.hpp"
|
2016-04-16 21:49:47 +00:00
|
|
|
|
2020-03-07 17:14:07 +00:00
|
|
|
#include <logvisor/logvisor.hpp>
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2020-03-07 17:14:07 +00:00
|
|
|
namespace {
|
2021-04-10 08:42:06 +00:00
|
|
|
logvisor::Module Log("metaforce::CObjectList");
|
2020-03-07 17:14:07 +00:00
|
|
|
}
|
2016-04-16 21:49:47 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CObjectList::CObjectList(EGameObjectList listEnum) : x2004_listEnum(listEnum) {}
|
2016-04-16 21:49:47 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CObjectList::AddObject(CEntity& entity) {
|
|
|
|
if (IsQualified(entity)) {
|
2020-03-07 17:14:07 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if (x0_list[entity.GetUniqueId().Value()].entity != nullptr &&
|
|
|
|
x0_list[entity.GetUniqueId().Value()].entity != &entity)
|
2021-06-07 19:29:18 +00:00
|
|
|
Log.report(logvisor::Level::Fatal,
|
|
|
|
FMT_STRING("INVALID USAGE DETECTED: Attempting to assign entity '{} ({})' to existing node '{}'!!!"),
|
2020-03-07 17:14:07 +00:00
|
|
|
entity.GetName(), entity.GetEditorId(), entity.GetUniqueId().Value());
|
|
|
|
#endif
|
|
|
|
s16 prevFirst = -1;
|
|
|
|
if (x2008_firstId != -1) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x0_list[x2008_firstId].prev = entity.GetUniqueId().Value();
|
2020-03-07 17:14:07 +00:00
|
|
|
prevFirst = x2008_firstId;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x2008_firstId = entity.GetUniqueId().Value();
|
|
|
|
SObjectListEntry& newEnt = x0_list[x2008_firstId];
|
|
|
|
newEnt.entity = &entity;
|
|
|
|
newEnt.next = prevFirst;
|
|
|
|
newEnt.prev = -1;
|
|
|
|
++x200a_count;
|
|
|
|
}
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CObjectList::RemoveObject(TUniqueId uid) {
|
|
|
|
SObjectListEntry& ent = x0_list[uid.Value()];
|
|
|
|
if (!ent.entity || ent.entity->GetUniqueId() != uid)
|
|
|
|
return;
|
|
|
|
if (uid.Value() == x2008_firstId) {
|
|
|
|
x2008_firstId = ent.next;
|
|
|
|
if (ent.next != -1)
|
|
|
|
x0_list[ent.next].prev = -1;
|
|
|
|
} else {
|
|
|
|
x0_list[ent.prev].next = ent.next;
|
|
|
|
if (ent.next != -1)
|
|
|
|
x0_list[ent.next].prev = ent.prev;
|
|
|
|
}
|
|
|
|
ent.entity = nullptr;
|
|
|
|
ent.next = -1;
|
|
|
|
ent.prev = -1;
|
|
|
|
--x200a_count;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CEntity* CObjectList::operator[](size_t i) const {
|
|
|
|
const SObjectListEntry& ent = x0_list[i];
|
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* CObjectList::operator[](size_t i) {
|
|
|
|
SObjectListEntry& ent = x0_list[i];
|
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2017-02-14 04:27:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CEntity* CObjectList::GetObjectById(TUniqueId uid) const {
|
|
|
|
if (uid == kInvalidUniqueId)
|
|
|
|
return nullptr;
|
|
|
|
const SObjectListEntry& ent = x0_list[uid.Value()];
|
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* CObjectList::GetObjectById(TUniqueId uid) {
|
|
|
|
if (uid == kInvalidUniqueId)
|
|
|
|
return nullptr;
|
|
|
|
SObjectListEntry& ent = x0_list[uid.Value()];
|
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CEntity* CObjectList::GetValidObjectById(TUniqueId uid) const {
|
|
|
|
if (uid == kInvalidUniqueId)
|
|
|
|
return nullptr;
|
|
|
|
const SObjectListEntry& ent = x0_list[uid.Value()];
|
|
|
|
if (!ent.entity)
|
|
|
|
return nullptr;
|
|
|
|
if (ent.entity->GetUniqueId() != uid)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* CObjectList::GetValidObjectById(TUniqueId uid) {
|
|
|
|
if (uid == kInvalidUniqueId)
|
|
|
|
return nullptr;
|
|
|
|
SObjectListEntry& ent = x0_list[uid.Value()];
|
|
|
|
if (!ent.entity)
|
|
|
|
return nullptr;
|
|
|
|
if (ent.entity->GetUniqueId() != uid)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 09:36:24 +00:00
|
|
|
bool CObjectList::IsQualified(const CEntity&) const { return true; }
|
2016-04-16 21:49:47 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|