diff --git a/include/Kyoto/Graphics/CTevCombiners.hpp b/include/Kyoto/Graphics/CTevCombiners.hpp index 8b218fc7..fbce52f6 100644 --- a/include/Kyoto/Graphics/CTevCombiners.hpp +++ b/include/Kyoto/Graphics/CTevCombiners.hpp @@ -95,6 +95,7 @@ public: }; extern CTevCombiners::CTevPass CTevPass_805a5ebc; +// TODO move to CGraphics extern CTevCombiners::CTevPass* PTR_skPassThru_805a8828; #endif \ No newline at end of file diff --git a/include/MetroidPrime/CEntity.hpp b/include/MetroidPrime/CEntity.hpp index d489a965..b3b83e58 100644 --- a/include/MetroidPrime/CEntity.hpp +++ b/include/MetroidPrime/CEntity.hpp @@ -17,11 +17,15 @@ public: virtual void Accept(IVisitor& visitor) = 0; virtual void PreThink(float dt, CStateManager& mgr); virtual void Think(float dt, CStateManager& mgr); - virtual void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr); + virtual void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr); virtual void SetActive(bool active); CEntity(TUniqueId id, const CEntityInfo& info, bool active, const rstl::string& name); + void SendScriptMsgs(EScriptObjectState state, CStateManager& mgr, EScriptObjectMessage msg); + TUniqueId GetUniqueId() const { return x8_uid; } + TAreaId GetAreaId() const; + static rstl::vector NullConnectionList; protected: @@ -33,7 +37,7 @@ protected: bool x30_24_active : 1; bool x30_25_inGraveyard : 1; bool x30_26_scriptingBlocked : 1; - bool x30_27_inUse : 1; + bool x30_27_notInArea : 1; }; #endif diff --git a/include/MetroidPrime/CStateManager.hpp b/include/MetroidPrime/CStateManager.hpp index 0fcfdbb8..d36e3504 100644 --- a/include/MetroidPrime/CStateManager.hpp +++ b/include/MetroidPrime/CStateManager.hpp @@ -3,6 +3,9 @@ #include "types.h" -class CStateManager {}; +class CStateManager { +public: + void SendScriptMsg(TUniqueId uid, TEditorId target, EScriptObjectMessage msg, EScriptObjectState state); +}; #endif diff --git a/include/MetroidPrime/TGameTypes.hpp b/include/MetroidPrime/TGameTypes.hpp index 8a59555d..6c9bf974 100644 --- a/include/MetroidPrime/TGameTypes.hpp +++ b/include/MetroidPrime/TGameTypes.hpp @@ -21,17 +21,33 @@ struct TAreaId { bool operator==(const TAreaId& other) const { return value == other.value; } bool operator!=(const TAreaId& other) const { return value != other.value; } }; + struct TEditorId { u32 value; TEditorId() : value(-1) {} TEditorId(u32 value) : value(value) {} + u32 Value() const { return value; } + + bool operator==(const TEditorId& other) const { return value == other.value; } + bool operator!=(const TEditorId& other) const { return value != other.value; } }; + struct TUniqueId { - u16 value; + union { + struct { + u16 version : 6; + u16 id : 10; + }; + u16 value; + }; TUniqueId() : value(-1) {} TUniqueId(u16 value) : value(value) {} + u16 Value() const { return value; } + + bool operator==(const TUniqueId& other) const { return value == other.value; } + bool operator!=(const TUniqueId& other) const { return value != other.value; } }; #endif diff --git a/src/Kyoto/CRandom16.cpp b/src/Kyoto/CRandom16.cpp index 77c0e1f3..970b7f77 100644 --- a/src/Kyoto/CRandom16.cpp +++ b/src/Kyoto/CRandom16.cpp @@ -3,6 +3,7 @@ CRandom16* CRandom16::gRandomNumber = nullptr; CGlobalRandom* CGlobalRandom::gCurrentGlobalRandom = nullptr; + CGlobalRandom::CGlobalRandom(CRandom16& rnd) : mRandom(rnd) { mIsFirst = true; mPrev = gCurrentGlobalRandom; @@ -25,6 +26,7 @@ CGlobalRandom::~CGlobalRandom() { } CRandom16* CRandom16::GetRandomNumber() { return gRandomNumber; } + void CRandom16::_SetRandomNumber(CRandom16* rnd) { gRandomNumber = rnd; } CRandom16::CRandom16(u32 seed) : mSeed(seed) {} diff --git a/src/MetroidPrime/CEntity.cpp b/src/MetroidPrime/CEntity.cpp new file mode 100644 index 00000000..fec9f593 --- /dev/null +++ b/src/MetroidPrime/CEntity.cpp @@ -0,0 +1,60 @@ +#include "MetroidPrime/CEntity.hpp" + +rstl::vector< SConnection > CEntity::NullConnectionList; + +CEntityInfo::CEntityInfo(TAreaId aid, const rstl::vector< SConnection >& conns, TEditorId eid) +: x0_areaId(aid), x4_conns(conns), x14_editorId(eid) {} + +CEntity::CEntity(TUniqueId id, const CEntityInfo& info, bool active, const rstl::string& name) +: x4_areaId(info.GetAreaId()) +, x8_uid(id) +, xc_editorId(info.GetEditorId()) +, x10_name(name) +, x20_conns(info.GetConnectionList()) +, x30_24_active(active) +, x30_25_inGraveyard(false) +, x30_26_scriptingBlocked(false) +, x30_27_notInArea(x4_areaId == kInvalidAreaId) {} + +CEntity::~CEntity() {} + +void CEntity::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) { + switch (msg) { + case kSM_Activate: + if (!x30_24_active) { + SetActive(true); + SendScriptMsgs(kSS_Active, mgr, kSM_None); + } + break; + case kSM_Deactivate: + if (x30_24_active) { + SetActive(false); + SendScriptMsgs(kSS_Inactive, mgr, kSM_None); + } + break; + case kSM_ToggleActive: + if (!x30_24_active) { + AcceptScriptMsg(kSM_Activate, uid, mgr); + } else { + AcceptScriptMsg(kSM_Deactivate, uid, mgr); + } + break; + } +} + +void CEntity::SendScriptMsgs(EScriptObjectState state, CStateManager& mgr, EScriptObjectMessage skipMsg) { + rstl::vector::const_iterator it = x20_conns.begin(); + for (; it != x20_conns.end(); ++it) { + if (it->x0_state == state && it->x4_msg != skipMsg) { + mgr.SendScriptMsg(GetUniqueId(), it->x8_objId, it->x4_msg, state); + } + } +} + +void CEntity::PreThink(float dt, CStateManager& mgr) {} + +void CEntity::Think(float dt, CStateManager& mgr) {} + +void CEntity::SetActive(bool active) { x30_24_active = active; } + +TAreaId CEntity::GetAreaId() const { return x30_27_notInArea ? kInvalidAreaId : x4_areaId; }