Add & link CEntity.cpp

Former-commit-id: 0b6ce7f781
This commit is contained in:
Luke Street 2022-08-10 22:33:46 -04:00
parent e2206fc47d
commit 4ad9b20d1a
6 changed files with 90 additions and 4 deletions

View File

@ -95,6 +95,7 @@ public:
};
extern CTevCombiners::CTevPass CTevPass_805a5ebc;
// TODO move to CGraphics
extern CTevCombiners::CTevPass* PTR_skPassThru_805a8828;
#endif

View File

@ -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<SConnection> 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

View File

@ -3,6 +3,9 @@
#include "types.h"
class CStateManager {};
class CStateManager {
public:
void SendScriptMsg(TUniqueId uid, TEditorId target, EScriptObjectMessage msg, EScriptObjectState state);
};
#endif

View File

@ -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

View File

@ -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) {}

View File

@ -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<SConnection>::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; }