2016-04-16 21:49:47 +00:00
|
|
|
#include "CObjectList.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CObjectList::CObjectList(EGameObjectList listEnum)
|
|
|
|
: m_listEnum(listEnum)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void CObjectList::AddObject(CEntity& entity)
|
|
|
|
{
|
|
|
|
if (IsQualified())
|
|
|
|
{
|
2016-08-14 21:11:44 +00:00
|
|
|
if (m_firstId != -1)
|
|
|
|
m_list[m_firstId].prev = entity.GetUniqueId() & 0x3ff;
|
|
|
|
TUniqueId prevFirst = m_firstId;
|
|
|
|
m_firstId = entity.GetUniqueId() & 0x3ff;
|
|
|
|
SObjectListEntry& newEnt = m_list[m_firstId];
|
2016-04-16 21:49:47 +00:00
|
|
|
newEnt.entity = &entity;
|
2016-08-14 21:11:44 +00:00
|
|
|
newEnt.next = prevFirst;
|
|
|
|
newEnt.prev = -1;
|
2016-04-16 21:49:47 +00:00
|
|
|
++m_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CObjectList::RemoveObject(TUniqueId uid)
|
|
|
|
{
|
|
|
|
uid = uid & 0x3ff;
|
|
|
|
SObjectListEntry& ent = m_list[uid];
|
|
|
|
if (!ent.entity || ent.entity->GetUniqueId() != uid)
|
|
|
|
return;
|
2016-08-14 21:11:44 +00:00
|
|
|
if (uid == m_firstId)
|
2016-04-16 21:49:47 +00:00
|
|
|
{
|
2016-08-14 21:11:44 +00:00
|
|
|
m_firstId = ent.next;
|
|
|
|
if (ent.next != -1)
|
|
|
|
m_list[ent.next].prev = -1;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-14 21:11:44 +00:00
|
|
|
if (ent.next != -1)
|
|
|
|
m_list[ent.next].prev = -1;
|
|
|
|
m_list[ent.prev].next = -1;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
ent.entity = nullptr;
|
|
|
|
ent.next = -1;
|
2016-08-14 21:11:44 +00:00
|
|
|
ent.prev = -1;
|
2016-04-16 21:49:47 +00:00
|
|
|
--m_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CEntity* CObjectList::GetObjectById(TUniqueId uid) const
|
|
|
|
{
|
|
|
|
if (!uid)
|
|
|
|
return nullptr;
|
2016-08-14 21:11:44 +00:00
|
|
|
const SObjectListEntry& ent = m_list[uid & 0x3ff];
|
|
|
|
if (ent.entity->x30_26_scriptingBlocked)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CEntity* CObjectList::GetObjectById(TUniqueId uid)
|
|
|
|
{
|
|
|
|
if (!uid)
|
|
|
|
return nullptr;
|
2016-08-14 21:11:44 +00:00
|
|
|
SObjectListEntry& ent = m_list[uid & 0x3ff];
|
|
|
|
if (ent.entity->x30_26_scriptingBlocked)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CObjectList::IsQualified() {return true;}
|
|
|
|
|
|
|
|
}
|