2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2015-08-19 05:48:57 +00:00
|
|
|
|
2020-03-18 02:36:44 +00:00
|
|
|
#include <array>
|
|
|
|
|
2019-09-22 21:52:05 +00:00
|
|
|
#include "Runtime/RetroTypes.hpp"
|
|
|
|
#include "Runtime/World/CEntity.hpp"
|
2015-08-19 05:48:57 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2015-08-19 05:48:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
enum class EGameObjectList {
|
|
|
|
Invalid = -1,
|
|
|
|
All,
|
|
|
|
Actor,
|
|
|
|
PhysicsActor,
|
|
|
|
GameCamera,
|
|
|
|
GameLight,
|
|
|
|
ListeningAi,
|
|
|
|
AiWaypoint,
|
|
|
|
PlatformAndDoor,
|
2015-08-19 05:48:57 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class CObjectList {
|
|
|
|
friend class CGameArea;
|
|
|
|
|
|
|
|
struct SObjectListEntry {
|
|
|
|
CEntity* entity = nullptr;
|
|
|
|
s16 next = -1;
|
|
|
|
s16 prev = -1;
|
|
|
|
};
|
2020-03-18 02:36:44 +00:00
|
|
|
std::array<SObjectListEntry, 1024> x0_list; // was an rstl::prereserved_vector
|
2018-12-08 05:30:43 +00:00
|
|
|
EGameObjectList x2004_listEnum;
|
|
|
|
s16 x2008_firstId = -1;
|
|
|
|
u16 x200a_count = 0;
|
2016-08-07 00:20:02 +00:00
|
|
|
|
2015-08-19 05:48:57 +00:00
|
|
|
public:
|
2018-12-08 05:30:43 +00:00
|
|
|
class iterator {
|
|
|
|
friend class CObjectList;
|
|
|
|
CObjectList& m_list;
|
|
|
|
s16 m_id;
|
|
|
|
iterator(CObjectList& list, s16 id) : m_list(list), m_id(id) {}
|
2016-08-15 20:58:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
public:
|
|
|
|
iterator& operator++() {
|
|
|
|
m_id = m_list.GetNextObjectIndex(m_id);
|
|
|
|
return *this;
|
|
|
|
}
|
2020-05-07 12:25:53 +00:00
|
|
|
bool operator==(const iterator& other) const { return m_id == other.m_id; }
|
|
|
|
bool operator!=(const iterator& other) const { return !operator==(other); }
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* operator*() const { return m_list.GetObjectByIndex(m_id); }
|
|
|
|
};
|
2017-08-08 22:12:14 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
class const_iterator {
|
|
|
|
friend class CObjectList;
|
|
|
|
const CObjectList& m_list;
|
|
|
|
s16 m_id;
|
|
|
|
const_iterator(const CObjectList& list, s16 id) : m_list(list), m_id(id) {}
|
2015-08-19 05:48:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
public:
|
|
|
|
const_iterator& operator++() {
|
|
|
|
m_id = m_list.GetNextObjectIndex(m_id);
|
|
|
|
return *this;
|
|
|
|
}
|
2020-05-07 12:25:53 +00:00
|
|
|
bool operator==(const iterator& other) const { return m_id == other.m_id; }
|
|
|
|
bool operator!=(const iterator& other) const { return !operator==(other); }
|
2018-12-08 05:30:43 +00:00
|
|
|
const CEntity* operator*() const { return m_list.GetObjectByIndex(m_id); }
|
|
|
|
};
|
2020-05-07 12:21:03 +00:00
|
|
|
|
|
|
|
[[nodiscard]] iterator begin() { return iterator(*this, x2008_firstId); }
|
|
|
|
[[nodiscard]] iterator end() { return iterator(*this, -1); }
|
|
|
|
[[nodiscard]] const_iterator begin() const { return const_iterator(*this, x2008_firstId); }
|
|
|
|
[[nodiscard]] const_iterator end() const { return const_iterator(*this, -1); }
|
2020-05-08 04:25:18 +00:00
|
|
|
[[nodiscard]] const_iterator cbegin() const { return begin(); }
|
|
|
|
[[nodiscard]] const_iterator cend() const { return end(); }
|
2015-08-19 05:48:57 +00:00
|
|
|
|
2020-05-07 12:22:52 +00:00
|
|
|
explicit CObjectList(EGameObjectList listEnum);
|
2018-12-08 05:30:43 +00:00
|
|
|
virtual ~CObjectList() = default;
|
|
|
|
|
|
|
|
void AddObject(CEntity& entity);
|
|
|
|
void RemoveObject(TUniqueId uid);
|
|
|
|
const CEntity* operator[](size_t i) const;
|
|
|
|
CEntity* operator[](size_t i);
|
|
|
|
const CEntity* GetObjectById(TUniqueId uid) const;
|
|
|
|
const CEntity* GetObjectByIndex(s16 index) const { return x0_list[index].entity; }
|
|
|
|
CEntity* GetObjectByIndex(s16 index) { return x0_list[index].entity; }
|
|
|
|
CEntity* GetObjectById(TUniqueId uid);
|
|
|
|
const CEntity* GetValidObjectById(TUniqueId uid) const;
|
|
|
|
CEntity* GetValidObjectById(TUniqueId uid);
|
|
|
|
s16 GetFirstObjectIndex() const { return x2008_firstId; }
|
|
|
|
s16 GetNextObjectIndex(s16 prev) const { return x0_list[prev].next; }
|
2020-03-06 09:36:24 +00:00
|
|
|
virtual bool IsQualified(const CEntity&) const;
|
2018-12-08 05:30:43 +00:00
|
|
|
u16 size() const { return x200a_count; }
|
|
|
|
};
|
2015-08-19 05:48:57 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|