This commit is contained in:
Jack Andersen 2017-08-10 13:14:01 -10:00
commit 5e10f2e7ad
12 changed files with 123 additions and 101 deletions

View File

@ -12,9 +12,9 @@ void CObjectList::AddObject(CEntity& entity)
if (IsQualified(entity))
{
if (x2008_firstId != -1)
x0_list[x2008_firstId].prev = entity.GetUniqueId() & 0x3ff;
TUniqueId prevFirst = x2008_firstId;
x2008_firstId = entity.GetUniqueId() & 0x3ff;
x0_list[x2008_firstId].prev = entity.GetUniqueId().Value();
s16 prevFirst = x2008_firstId;
x2008_firstId = entity.GetUniqueId().Value();
SObjectListEntry& newEnt = x0_list[x2008_firstId];
newEnt.entity = &entity;
newEnt.next = prevFirst;
@ -25,11 +25,10 @@ void CObjectList::AddObject(CEntity& entity)
void CObjectList::RemoveObject(TUniqueId uid)
{
uid = uid & 0x3ff;
SObjectListEntry& ent = x0_list[uid];
SObjectListEntry& ent = x0_list[uid.Value()];
if (!ent.entity || ent.entity->GetUniqueId() != uid)
return;
if (uid == x2008_firstId)
if (uid.Value() == x2008_firstId)
{
x2008_firstId = ent.next;
if (ent.next != -1)
@ -67,7 +66,7 @@ const CEntity* CObjectList::GetObjectById(TUniqueId uid) const
{
if (uid == kInvalidUniqueId)
return nullptr;
const SObjectListEntry& ent = x0_list[uid & 0x3ff];
const SObjectListEntry& ent = x0_list[uid.Value()];
if (ent.entity->x30_26_scriptingBlocked)
return nullptr;
return ent.entity;
@ -77,7 +76,7 @@ CEntity* CObjectList::GetObjectById(TUniqueId uid)
{
if (uid == kInvalidUniqueId)
return nullptr;
SObjectListEntry& ent = x0_list[uid & 0x3ff];
SObjectListEntry& ent = x0_list[uid.Value()];
if (ent.entity->x30_26_scriptingBlocked)
return nullptr;
return ent.entity;
@ -87,7 +86,7 @@ const CEntity* CObjectList::GetValidObjectById(TUniqueId uid) const
{
if (uid == kInvalidUniqueId)
return nullptr;
const SObjectListEntry& ent = x0_list[uid & 0x3ff];
const SObjectListEntry& ent = x0_list[uid.Value()];
if (!ent.entity)
return nullptr;
if (ent.entity->GetUniqueId() != uid)
@ -99,7 +98,7 @@ CEntity* CObjectList::GetValidObjectById(TUniqueId uid)
{
if (uid == kInvalidUniqueId)
return nullptr;
SObjectListEntry& ent = x0_list[uid & 0x3ff];
SObjectListEntry& ent = x0_list[uid.Value()];
if (!ent.entity)
return nullptr;
if (ent.entity->GetUniqueId() != uid)

View File

@ -27,41 +27,41 @@ class CObjectList
struct SObjectListEntry
{
CEntity* entity = nullptr;
TUniqueId next = kInvalidUniqueId;
TUniqueId prev = kInvalidUniqueId;
s16 next = -1;
s16 prev = -1;
};
SObjectListEntry x0_list[1024]; // was an rstl::prereserved_vector
EGameObjectList x2004_listEnum;
TUniqueId x2008_firstId = kInvalidUniqueId;
s16 x2008_firstId = -1;
u16 x200a_count = 0;
public:
class iterator
{
friend class CObjectList;
CObjectList& m_list;
TUniqueId m_id;
iterator(CObjectList& list, TUniqueId id) : m_list(list), m_id(id) {}
s16 m_id;
iterator(CObjectList& list, s16 id) : m_list(list), m_id(id) {}
public:
iterator& operator++() { m_id = m_list.GetNextObjectIndex(m_id); return *this; }
bool operator!=(const iterator& other) const { return m_id != other.m_id; }
CEntity* operator*() const { return m_list.GetObjectById(m_id); }
CEntity* operator*() const { return m_list.GetObjectByIndex(m_id); }
};
iterator begin() { return iterator(*this, x2008_firstId); }
iterator end() { return iterator(*this, kInvalidUniqueId); }
iterator end() { return iterator(*this, -1); }
class const_iterator
{
friend class CObjectList;
const CObjectList& m_list;
TUniqueId m_id;
const_iterator(const CObjectList& list, TUniqueId id) : m_list(list), m_id(id) {}
s16 m_id;
const_iterator(const CObjectList& list, s16 id) : m_list(list), m_id(id) {}
public:
const_iterator& operator++() { m_id = m_list.GetNextObjectIndex(m_id); return *this; }
bool operator!=(const iterator& other) const { return m_id != other.m_id; }
const CEntity* operator*() const { return m_list.GetObjectById(m_id); }
const CEntity* operator*() const { return m_list.GetObjectByIndex(m_id); }
};
const_iterator cbegin() const { return const_iterator(*this, x2008_firstId); }
const_iterator cend() const { return const_iterator(*this, kInvalidUniqueId); }
const_iterator cend() const { return const_iterator(*this, -1); }
CObjectList(EGameObjectList listEnum);
@ -70,12 +70,13 @@ public:
const CEntity* operator[](size_t i) const;
CEntity* operator[](size_t i);
const CEntity* GetObjectById(TUniqueId uid) const;
const CEntity* GetObjectByIndex(s32 index) const { return x0_list[index].entity; }
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);
TUniqueId GetFirstObjectIndex() const { return x2008_firstId; }
TUniqueId GetNextObjectIndex(TUniqueId prev) const { return x0_list[prev & 0x3ff].next; }
s16 GetFirstObjectIndex() const { return x2008_firstId; }
s16 GetNextObjectIndex(s16 prev) const { return x0_list[prev].next; }
virtual bool IsQualified(const CEntity&);
u16 size() const { return x200a_count; }
};

View File

@ -16,7 +16,7 @@ void CSortedListManager::Reset()
xb000_sortedLists[i].Reset();
}
void CSortedListManager::AddToLinkedList(TUniqueId nodeId, TUniqueId& headId, TUniqueId& tailId) const
void CSortedListManager::AddToLinkedList(s16 nodeId, s16& headId, s16& tailId) const
{
if (headId == -1)
{
@ -100,7 +100,7 @@ void CSortedListManager::InsertInList(ESortedList list, SNode& node)
}
/* Do insert */
sl.x0_ids[insIdx] = node.x0_actor->GetUniqueId();
sl.x0_ids[insIdx] = node.x0_actor->GetUniqueId().Value();
node.x1c_selfIdxs[int(list)] = insIdx;
++sl.x800_size;
}
@ -149,7 +149,7 @@ s16 CSortedListManager::FindInListLower(ESortedList list, float val) const
return idx;
}
TUniqueId CSortedListManager::ConstructIntersectionArray(const zeus::CAABox& aabb)
s16 CSortedListManager::ConstructIntersectionArray(const zeus::CAABox& aabb)
{
int minXa = FindInListLower(ESortedList::MinX, aabb.min.x);
int maxXa = FindInListUpper(ESortedList::MinX, aabb.max.x);
@ -186,12 +186,12 @@ TUniqueId CSortedListManager::ConstructIntersectionArray(const zeus::CAABox& aab
}
}
TUniqueId CSortedListManager::CalculateIntersections(ESortedList la, ESortedList lb, s16 a, s16 b, s16 c, s16 d,
s16 CSortedListManager::CalculateIntersections(ESortedList la, ESortedList lb, s16 a, s16 b, s16 c, s16 d,
ESortedList slA, ESortedList slB, ESortedList slC, ESortedList slD,
const zeus::CAABox& aabb)
{
TUniqueId headId = kInvalidUniqueId;
TUniqueId tailId = kInvalidUniqueId;
s16 headId = -1;
s16 tailId = -1;
for (int i=a ; i<b ; ++i)
AddToLinkedList(xb000_sortedLists[int(la)].x0_ids[i], headId, tailId);
for (int i=c ; i<d ; ++i)
@ -201,7 +201,7 @@ TUniqueId CSortedListManager::CalculateIntersections(ESortedList la, ESortedList
{
for (int i=0 ; i<a ; ++i)
{
TUniqueId id = xb000_sortedLists[int(la)].x0_ids[i];
s16 id = xb000_sortedLists[int(la)].x0_ids[i];
if (x0_nodes[id].x1c_selfIdxs[lb] > aabb[int(lb)])
AddToLinkedList(id, headId, tailId);
}
@ -210,13 +210,13 @@ TUniqueId CSortedListManager::CalculateIntersections(ESortedList la, ESortedList
{
for (int i=d ; i<xb000_sortedLists[int(lb)].x800_size ; ++i)
{
TUniqueId id = xb000_sortedLists[int(lb)].x0_ids[i];
s16 id = xb000_sortedLists[int(lb)].x0_ids[i];
if (x0_nodes[id].x1c_selfIdxs[la] < aabb[int(la)])
AddToLinkedList(id, headId, tailId);
}
}
for (TUniqueId* id = &headId ; *id != kInvalidUniqueId ;)
for (s16* id = &headId ; *id != -1 ;)
{
SNode& node = x0_nodes[*id];
if (node.x4_box[int(slA)] > aabb[int(slB)] ||
@ -226,7 +226,7 @@ TUniqueId CSortedListManager::CalculateIntersections(ESortedList la, ESortedList
{
/* Not intersecting; remove from chain */
*id = node.x28_next;
node.x28_next = kInvalidUniqueId;
node.x28_next = -1;
continue;
}
id = &node.x28_next;
@ -252,8 +252,8 @@ void CSortedListManager::BuildNearList(rstl::reserved_vector<TUniqueId, 1024>& o
const zeus::CAABox& aabb) const
{
const CMaterialFilter& filter = actor.GetMaterialFilter();
TUniqueId id = const_cast<CSortedListManager&>(*this).ConstructIntersectionArray(aabb);
while (id != kInvalidUniqueId)
s16 id = const_cast<CSortedListManager&>(*this).ConstructIntersectionArray(aabb);
while (id != -1)
{
const SNode& node = x0_nodes[id];
if (&actor != node.x0_actor && filter.Passes(node.x0_actor->GetMaterialList()) &&
@ -261,29 +261,29 @@ void CSortedListManager::BuildNearList(rstl::reserved_vector<TUniqueId, 1024>& o
out.push_back(node.x0_actor->GetUniqueId());
id = node.x28_next;
const_cast<SNode&>(node).x28_next = kInvalidUniqueId;
const_cast<SNode&>(node).x28_next = -1;
}
}
void CSortedListManager::BuildNearList(rstl::reserved_vector<TUniqueId, 1024>& out, const zeus::CAABox& aabb,
const CMaterialFilter& filter, const CActor* actor) const
{
TUniqueId id = const_cast<CSortedListManager&>(*this).ConstructIntersectionArray(aabb);
while (id != kInvalidUniqueId)
s16 id = const_cast<CSortedListManager&>(*this).ConstructIntersectionArray(aabb);
while (id != -1)
{
const SNode& node = x0_nodes[id];
if (actor != node.x0_actor && filter.Passes(node.x0_actor->GetMaterialList()))
out.push_back(node.x0_actor->GetUniqueId());
id = node.x28_next;
const_cast<SNode&>(node).x28_next = kInvalidUniqueId;
const_cast<SNode&>(node).x28_next = -1;
}
}
void CSortedListManager::Remove(const CActor* act)
{
SNode& node = x0_nodes[act->GetUniqueId() & 0x3ff];
if (node.x2a_populated == false)
SNode& node = x0_nodes[act->GetUniqueId().Value()];
if (!node.x2a_populated)
return;
RemoveFromList(ESortedList::MinX, node.x1c_selfIdxs[0]);
@ -297,7 +297,7 @@ void CSortedListManager::Remove(const CActor* act)
void CSortedListManager::Move(const CActor* act, const zeus::CAABox& aabb)
{
SNode& node = x0_nodes[act->GetUniqueId() & 0x3ff];
SNode& node = x0_nodes[act->GetUniqueId().Value()];
node.x4_box = aabb;
MoveInList(ESortedList::MinX, node.x1c_selfIdxs[0]);
@ -310,7 +310,7 @@ void CSortedListManager::Move(const CActor* act, const zeus::CAABox& aabb)
void CSortedListManager::Insert(const CActor* act, const zeus::CAABox& aabb)
{
SNode& node = x0_nodes[act->GetUniqueId() & 0x3ff];
SNode& node = x0_nodes[act->GetUniqueId().Value()];
if (node.x2a_populated)
{
Move(act, aabb);
@ -331,7 +331,7 @@ bool CSortedListManager::ActorInLists(const CActor* act) const
{
if (!act)
return false;
const SNode& node = x0_nodes[act->GetUniqueId() & 0x3ff];
const SNode& node = x0_nodes[act->GetUniqueId().Value()];
return node.x2a_populated;
}

View File

@ -19,9 +19,9 @@ enum ESortedList
struct SSortedList
{
TUniqueId x0_ids[1024];
s16 x0_ids[1024];
u32 x800_size;
void Reset() {std::fill(std::begin(x0_ids), std::end(x0_ids), kInvalidUniqueId);}
void Reset() {std::fill(std::begin(x0_ids), std::end(x0_ids), -1);}
SSortedList() {Reset();}
};
@ -33,7 +33,7 @@ class CSortedListManager
const CActor* x0_actor = nullptr;
zeus::CAABox x4_box = zeus::CAABox::skNullBox;
s16 x1c_selfIdxs[6] = {-1, -1, -1, -1, -1, -1};
TUniqueId x28_next = kInvalidUniqueId;
s16 x28_next = -1;
bool x2a_populated = false;
SNode() = default;
SNode(const CActor* act, const zeus::CAABox& aabb)
@ -42,14 +42,14 @@ class CSortedListManager
SNode x0_nodes[1024];
SSortedList xb000_sortedLists[6];
void Reset();
void AddToLinkedList(TUniqueId a, TUniqueId& b, TUniqueId& c) const;
void AddToLinkedList(s16 a, s16& b, s16& c) const;
void RemoveFromList(ESortedList, s16);
void MoveInList(ESortedList, s16);
void InsertInList(ESortedList, SNode& node);
s16 FindInListUpper(ESortedList, float) const;
s16 FindInListLower(ESortedList, float) const;
TUniqueId ConstructIntersectionArray(const zeus::CAABox&);
TUniqueId CalculateIntersections(ESortedList, ESortedList, s16, s16, s16, s16,
s16 ConstructIntersectionArray(const zeus::CAABox&);
s16 CalculateIntersections(ESortedList, ESortedList, s16, s16, s16, s16,
ESortedList, ESortedList, ESortedList, ESortedList, const zeus::CAABox&);
public:
CSortedListManager();

View File

@ -924,7 +924,7 @@ void CStateManager::PreRender()
xf7c_projectedShadow = nullptr;
x850_world->PreRender();
BuildDynamicLightListForWorld();
CGameCamera* cam = static_cast<CGameCamera*>(x870_cameraManager->GetCurrentCamera(*this));
CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this);
zeus::CFrustum frustum;
zeus::CProjection proj;
proj.setPersp(zeus::SProjPersp{zeus::degToRad(cam->GetFov()),
@ -2059,7 +2059,7 @@ void CStateManager::CrossTouchActors()
if (!ent2->GetActive() || touchAABB2)
continue;
if (visits[ent2->GetUniqueId() & 0x3ff])
if (visits[ent2->GetUniqueId().Value()])
continue;
if (touchAABB->intersects(*touchAABB2))
@ -2068,7 +2068,7 @@ void CStateManager::CrossTouchActors()
ent2->Touch(actor, *this);
}
visits[ent2->GetUniqueId() & 0x3ff] = true;
visits[ent2->GetUniqueId().Value()] = true;
}
}
}
@ -2501,10 +2501,10 @@ TUniqueId CStateManager::AllocateUniqueId()
while (GetAllObjectList().GetObjectByIndex(ourIndex) != nullptr);
x8_idArr[ourIndex] = (x8_idArr[ourIndex] + 1) & 0x3f;
if (((ourIndex | ((x8_idArr[ourIndex]) << 10)) & 0xFFFF) == kInvalidUniqueId)
x8_idArr[0] = 0;
if (TUniqueId(ourIndex, x8_idArr[ourIndex]) == kInvalidUniqueId)
x8_idArr[ourIndex] = 0;
return ((ourIndex | ((x8_idArr[ourIndex]) << 10)) & 0xFFFF);
return TUniqueId(ourIndex, x8_idArr[ourIndex]);
}
void CStateManager::DeferStateTransition(EStateManagerTransition t)

View File

@ -90,7 +90,7 @@ public:
private:
s16 x0_nextFreeIndex = 0;
TUniqueId x8_idArr[1024] = {};
u16 x8_idArr[1024] = {};
/*
std::unique_ptr<CObjectList> x80c_allObjs;

View File

@ -52,11 +52,23 @@ struct TEditorId
bool operator==(const TEditorId& other) const { return (id & 0x3ffffff) == (other.id & 0x3ffffff); }
};
using TUniqueId = s16;
struct TUniqueId
{
TUniqueId() = default;
TUniqueId(u16 value, u16 version) : id(value | (version << 10)) {}
u16 id = u16(-1);
s16 Version() const { return s16((id >> 10) & 0x3f);}
s16 Value() const { return s16(id & 0x3ff);}
bool operator<(const TUniqueId& other) const { return (id < other.id); }
bool operator!=(const TUniqueId& other) const { return (id != other.id); }
bool operator==(const TUniqueId& other) const { return (id == other.id); }
};
using TAreaId = s32;
#define kInvalidEditorId TEditorId()
#define kInvalidUniqueId TUniqueId(-1)
#define kInvalidUniqueId TUniqueId()
#define kInvalidAreaId TAreaId(-1)
}

View File

@ -779,7 +779,7 @@ void CGameArea::Validate(CStateManager& mgr)
TUniqueId id = mgr.GetIdForScript(entId);
if (id != kInvalidUniqueId)
{
CPostConstructed::MapEntry& ent = x12c_postConstructed->xa8_pvsEntityMap[id & 0x3ff];
CPostConstructed::MapEntry& ent = x12c_postConstructed->xa8_pvsEntityMap[id.Value()];
ent.x0_id = i + (pvs->GetNumFeatures() - pvs->GetNumActors());
ent.x4_uid = id;
}
@ -1097,12 +1097,12 @@ CGameArea::MREAHeader CGameArea::VerifyHeader() const
TUniqueId CGameArea::LookupPVSUniqueID(TUniqueId id) const
{
return x12c_postConstructed->xa8_pvsEntityMap[id & 0x3ff].x4_uid;
return x12c_postConstructed->xa8_pvsEntityMap[id.Value()].x4_uid;
}
s16 CGameArea::LookupPVSID(TUniqueId id) const
{
return x12c_postConstructed->xa8_pvsEntityMap[id & 0x3ff].x0_id;
return x12c_postConstructed->xa8_pvsEntityMap[id.Value()].x0_id;
}
void CGameArea::SetAreaAttributes(const CScriptAreaAttributes* areaAttributes)

View File

@ -4,8 +4,14 @@
namespace urde
{
CScriptActorRotate::CScriptActorRotate(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CVector3f& rotation, float scale, bool, bool, bool active)
const zeus::CVector3f& rotation, float f1, bool b1, bool b2, bool active)
: CEntity(uid, info, active, name)
, x34_rotation(rotation)
, x40_(f1)
, x58_24_(false)
, x58_25_(false)
, x58_26_(b1)
, x58_27_(b2)
{
}
@ -14,4 +20,9 @@ void CScriptActorRotate::Accept(IVisitor& visitor)
visitor.Visit(this);
}
void CScriptActorRotate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
CEntity::AcceptScriptMsg(msg, uid, mgr);
}
}

View File

@ -13,7 +13,8 @@ class CScriptActorRotate : public CEntity
float x44_;
std::map<TUniqueId, zeus::CTransform> x48_actors;
union {
union
{
struct
{
bool x58_24_ : 1;
@ -29,6 +30,7 @@ public:
bool);
void Accept(IVisitor& visitor);
void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&);
};
}

View File

@ -13,39 +13,39 @@ class CScriptSpecialFunction : public CActor
public:
enum class ESpecialFunction
{
What,
PlayerFollowLocator,
SpinnerController,
ObjectFollowLocator,
Four,
InventoryActivator,
MapStation,
SaveStation,
IntroBossRingController,
ViewFrustumTester,
ShotSpinnerController,
EscapeSequence,
BossEnergyBar,
EndGame,
HUDFadeIn,
CinematicSkip,
ScriptLayerController,
RainSimulator,
AreaDamage,
ObjectFollowObject,
RedundantHintSystem,
DropBomb,
TwentyTwo,
MissileStation,
Billboard,
PlayerInAreaRelay,
HUDTarget,
FogFader,
EnterLogbook,
PowerBombStation,
Ending,
FusionRelay,
WeaponSwitch,
What = 0,
PlayerFollowLocator = 1,
SpinnerController = 2,
ObjectFollowLocator = 3,
Four = 4,
InventoryActivator = 5,
MapStation = 6,
SaveStation = 7,
IntroBossRingController = 8,
ViewFrustumTester = 9,
ShotSpinnerController = 10,
EscapeSequence = 11,
BossEnergyBar = 12,
EndGame = 13,
HUDFadeIn = 14,
CinematicSkip = 15,
ScriptLayerController = 16,
RainSimulator = 17,
AreaDamage = 18,
ObjectFollowObject = 19,
RedundantHintSystem = 20,
DropBomb = 21,
TwentyTwo = 22,
MissileStation = 23,
Billboard = 24,
PlayerInAreaRelay = 25,
HUDTarget = 26,
FogFader = 27,
EnterLogbook = 28,
PowerBombStation = 29,
Ending = 30,
FusionRelay = 31,
WeaponSwitch = 32,
FogVolume = 47,
RadialDamage = 48,
EnvFxDensityController = 49,

View File

@ -1,11 +1,8 @@
#include "CWorld.hpp"
#include "CGameArea.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CStateManager.hpp"
#include "CInGameTweakManagerBase.hpp"
#include "Audio/CAudioGroupSet.hpp"
#include "Editor/ProjectResourceFactoryBase.hpp"
#include "CGameState.hpp"
#include "Graphics/CBooRenderer.hpp"