metaforce/Runtime/CObjectList.cpp

73 lines
1.7 KiB
C++
Raw Normal View History

#include "CObjectList.hpp"
namespace urde
{
CObjectList::CObjectList(EGameObjectList listEnum)
2017-01-15 03:59:37 +00:00
: x2004_listEnum(listEnum)
{}
void CObjectList::AddObject(CEntity& entity)
{
if (IsQualified(entity))
{
2017-01-15 03:59:37 +00:00
if (x2008_firstId != -1)
x0_list[x2008_firstId].prev = entity.GetUniqueId() & 0x3ff;
TUniqueId prevFirst = x2008_firstId;
x2008_firstId = entity.GetUniqueId() & 0x3ff;
SObjectListEntry& newEnt = x0_list[x2008_firstId];
newEnt.entity = &entity;
newEnt.next = prevFirst;
newEnt.prev = -1;
2017-01-15 03:59:37 +00:00
++x200a_count;
}
}
void CObjectList::RemoveObject(TUniqueId uid)
{
uid = uid & 0x3ff;
2017-01-15 03:59:37 +00:00
SObjectListEntry& ent = x0_list[uid];
if (!ent.entity || ent.entity->GetUniqueId() != uid)
return;
2017-01-15 03:59:37 +00:00
if (uid == x2008_firstId)
{
2017-01-15 03:59:37 +00:00
x2008_firstId = ent.next;
if (ent.next != -1)
2017-01-15 03:59:37 +00:00
x0_list[ent.next].prev = -1;
}
else
{
if (ent.next != -1)
2017-01-15 03:59:37 +00:00
x0_list[ent.next].prev = -1;
x0_list[ent.prev].next = -1;
}
ent.entity = nullptr;
ent.next = -1;
ent.prev = -1;
2017-01-15 03:59:37 +00:00
--x200a_count;
}
const CEntity* CObjectList::GetObjectById(TUniqueId uid) const
{
if (!uid)
return nullptr;
2017-01-15 03:59:37 +00:00
const SObjectListEntry& ent = x0_list[uid & 0x3ff];
if (ent.entity->x30_26_scriptingBlocked)
return nullptr;
return ent.entity;
}
CEntity* CObjectList::GetObjectById(TUniqueId uid)
{
if (!uid)
return nullptr;
2017-01-15 03:59:37 +00:00
SObjectListEntry& ent = x0_list[uid & 0x3ff];
if (ent.entity->x30_26_scriptingBlocked)
return nullptr;
return ent.entity;
}
bool CObjectList::IsQualified(const CEntity&) {return true;}
}