Initial work on CActor.cpp

This commit is contained in:
2022-08-12 21:26:00 -04:00
parent e418784c51
commit 44b17813bd
109 changed files with 1295 additions and 335 deletions

View File

@@ -0,0 +1,32 @@
#ifndef _CMATERIALFILTER_HPP
#define _CMATERIALFILTER_HPP
#include "types.h"
#include "Collision/CMaterialList.hpp"
class CMaterialFilter {
public:
enum EFilterType {
kFT_Always,
kFT_Include,
kFT_Exclude,
kFT_IncludeExclude,
};
CMaterialFilter() : type(kFT_Always) {}
CMaterialFilter(const CMaterialList& include, const CMaterialList& exclude, EFilterType type)
: include(include), exclude(exclude), type(type) {}
static CMaterialFilter MakeIncludeExclude(const CMaterialList& include, const CMaterialList& exclude) {
return CMaterialFilter(include, exclude, kFT_IncludeExclude);
}
private:
CMaterialList include;
CMaterialList exclude;
EFilterType type;
};
CHECK_SIZEOF(CMaterialFilter, 0x18)
#endif

View File

@@ -0,0 +1,91 @@
#ifndef _CMATERIALLIST_HPP
#define _CMATERIALLIST_HPP
#include "types.h"
enum EMaterialTypes {
kMT_NoStepLogic = 0,
kMT_Stone = 1,
kMT_Metal = 2,
kMT_Grass = 3,
kMT_Ice = 4,
kMT_Pillar = 5,
kMT_MetalGrating = 6,
kMT_Phazon = 7,
kMT_Dirt = 8,
kMT_Lava = 9,
kMT_LavaStone = 10,
kMT_Snow = 11,
kMT_MudSlow = 12,
kMT_HalfPipe = 13,
kMT_Mud = 14,
kMT_Glass = 15,
kMT_Shield = 16,
kMT_Sand = 17,
kMT_ProjectilePassthrough = 18,
kMT_Solid = 19,
kMT_NoPlatformCollision = 20,
kMT_CameraPassthrough = 21,
kMT_Wood = 22,
kMT_Organic = 23,
kMT_NoEdgeCollision = 24,
kMT_RedundantEdgeOrFlippedTri = 25,
kMT_SeeThrough = 26,
kMT_ScanPassthrough = 27,
kMT_AIPassthrough = 28,
kMT_Ceiling = 29,
kMT_Wall = 30,
kMT_Floor = 31,
kMT_Player = 32,
kMT_Character = 33,
kMT_Trigger = 34,
kMT_Projectile = 35,
kMT_Bomb = 36,
kMT_GroundCollider = 37,
kMT_NoStaticCollision = 38,
kMT_Scannable = 39,
kMT_Target = 40,
kMT_Orbit = 41,
kMT_Occluder = 42,
kMT_Immovable = 43,
kMT_Debris = 44,
kMT_PowerBomb = 45,
kMT_Unknown46 = 46,
kMT_CollisionActor = 47,
kMT_AIBlock = 48,
kMT_Platform = 49,
kMT_NonSolidDamageable = 50,
kMT_RadarObject = 51,
kMT_PlatformSlave = 52,
kMT_AIJoint = 53,
kMT_Unknown54 = 54,
kMT_SolidCharacter = 55,
kMT_ExcludeFromLineOfSightTest = 56,
kMT_ExcludeFromRadar = 57,
kMT_NoPlayerCollision = 58,
kMT_SixtyThree = 63
};
// TODO: how else would they end up in .data?
static EMaterialTypes SolidMaterial = kMT_Solid;
class CMaterialList {
public:
CMaterialList() : value(0) {}
CMaterialList(EMaterialTypes material) : value(u64(1) << material) {}
CMaterialList(u64 value) : value(value) {}
void Add(EMaterialTypes material) {
value |= u64(1) << material;
}
const CMaterialList& Union(const CMaterialList& other) {
value |= other.value;
return *this;
}
private:
u64 value;
};
CHECK_SIZEOF(CMaterialList, 0x8)
#endif

View File

@@ -0,0 +1,11 @@
#ifndef _CAUDIOSYS_HPP
#define _CAUDIOSYS_HPP
#include "types.h"
class CAudioSys {
public:
static const u8 kMaxVolume;
};
#endif

View File

@@ -3,7 +3,7 @@
#include "types.h"
#include "Kyoto/CToken.hpp"
#include "Kyoto/TToken.hpp"
#include "Kyoto/IObjectStore.hpp"
#include "Kyoto/Streams/CInputStream.hpp"
@@ -21,7 +21,7 @@ public:
// : obj(TToken< T >::GetIObjObjectFor(ptr).release()) {}
private:
rstl::auto_ptr< TObjOwnerDerivedFromIObjUntyped > obj;
rstl::auto_ptr< CObjOwnerDerivedFromIObjUntyped > obj;
};
CFactoryFnReturn FStringTableFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& xfer);

View File

@@ -5,11 +5,20 @@
#include "rstl/map.hpp"
#include "Kyoto/CToken.hpp"
#include "Kyoto/IObjectStore.hpp"
class CSimplePool {
public:
virtual ~CSimplePool() {}
virtual CToken GetObj(const SObjectTag& tag, CVParamTransfer xfer);
virtual CToken GetObj(const SObjectTag& tag);
virtual CToken GetObj(const char* name);
virtual CToken GetObj(const char* name, CVParamTransfer xfer);
virtual bool HasObject(const SObjectTag& tag);
virtual bool ObjectIsLive(const SObjectTag& tag);
virtual unkptr GetFactory();
virtual void Flush();
virtual void ObjectUnreferenced(const SObjectTag& tag);
private:
u8 x4_;

View File

@@ -5,58 +5,18 @@
#include "Kyoto/IObjectStore.hpp"
#include "rstl/auto_ptr.hpp"
class CToken {
public:
CToken() {}
CToken(IObj* obj) : x0_objRef(new CObjectReference(obj)), x4_lockHeld(false) {}
CToken(const CToken& other);
~CToken();
void Lock();
private:
CObjectReference* x0_objRef;
bool x4_lockHeld;
};
class IObj {
public:
virtual ~IObj() {}
};
class TObjOwnerDerivedFromIObjUntyped : public IObj {
public:
template < typename T >
TObjOwnerDerivedFromIObjUntyped(const rstl::auto_ptr< T >& obj) : m_objPtr(obj.release()) {}
protected:
void* m_objPtr;
};
template < typename T >
class TObjOwnerDerivedFromIObj : public TObjOwnerDerivedFromIObjUntyped {
TObjOwnerDerivedFromIObj(const rstl::auto_ptr< T >& obj) : TObjOwnerDerivedFromIObjUntyped(obj) {}
public:
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(const rstl::auto_ptr< T >& obj) {
return new TObjOwnerDerivedFromIObj< T >(obj);
}
~TObjOwnerDerivedFromIObj() override { delete Owned(); }
T* Owned() { return static_cast< T* >(m_objPtr); }
};
template < typename T >
class TToken : public CToken {
public:
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetIObjObjectFor(const rstl::auto_ptr< T >& obj) {
return TObjOwnerDerivedFromIObj< T >::GetNewDerivedObject(obj);
}
};
template < typename T >
class TCachedToken : public TToken< T > {
private:
T* x8_item;
};
template < typename T >
class TLockedToken : public TCachedToken< T > {};
#endif

View File

@@ -7,8 +7,10 @@
class CColor {
public:
CColor() {}
CColor(u32 col) : mRgba(col) {}
CColor(f32 r, f32 g, f32 b, f32 a = 1.f) : mR(r * 255.f), mG(g * 255.f), mB(b * 255.f), mA(a * 255.f) {}
CColor(f32 r, f32 g, f32 b, f32 a = 1.f);
// : mR(r * 255.f), mG(g * 255.f), mB(b * 255.f), mA(a * 255.f) {}
static const CColor& Black();
static const CColor& White();

View File

@@ -3,7 +3,7 @@
#include "types.h"
#include "Kyoto/Math/CColor.hpp"
#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Math/CVector3f.hpp"
#include "Kyoto/Graphics/CTevCombiners.hpp"

38
include/Kyoto/IObj.hpp Normal file
View File

@@ -0,0 +1,38 @@
#ifndef _IOBJ_HPP
#define _IOBJ_HPP
#include "types.h"
#include "rstl/auto_ptr.hpp"
class IObj {
public:
virtual ~IObj() {}
};
class CObjOwnerDerivedFromIObjUntyped : public IObj {
public:
template < typename T >
CObjOwnerDerivedFromIObjUntyped(T* obj) : m_objPtr(obj) {}
template < typename T >
CObjOwnerDerivedFromIObjUntyped(const rstl::auto_ptr< T >& obj) : m_objPtr(obj.release()) {}
protected:
void* m_objPtr;
};
template < typename T >
class TObjOwnerDerivedFromIObj : public CObjOwnerDerivedFromIObjUntyped {
TObjOwnerDerivedFromIObj(T* obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
TObjOwnerDerivedFromIObj(const rstl::auto_ptr< T >& obj) : CObjOwnerDerivedFromIObjUntyped(obj) {}
public:
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(T* obj) { return new TObjOwnerDerivedFromIObj< T >(obj); }
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetNewDerivedObject(const rstl::auto_ptr< T >& obj) {
return new TObjOwnerDerivedFromIObj< T >(obj);
}
~TObjOwnerDerivedFromIObj() override { delete Owned(); }
T* Owned() { return static_cast< T* >(m_objPtr); }
};
#endif

View File

@@ -3,8 +3,11 @@
#include "types.h"
#include "rstl/auto_ptr.hpp"
#include "rstl/rc_ptr.hpp"
#define kInvalidAssetId 0xFFFFFFFFu
typedef u32 CAssetId;
typedef u32 FourCC;
@@ -12,17 +15,36 @@ struct SObjectTag {
FourCC type;
CAssetId id;
SObjectTag() {}
SObjectTag(FourCC type, CAssetId id) : type(type), id(id) {}
SObjectTag(const SObjectTag& other) : type(other.type), id(other.id) {}
};
class IObjectStore;
class IObj;
class CVParamTransfer {
public:
static CVParamTransfer Null();
private:
rstl::rc_ptr< void > x0_;
};
class CObjectReference {
public:
CObjectReference(const rstl::auto_ptr< IObj >& obj);
// : x0_refCount(0)
// , x2_locked(false)
// , x2_lockCount(0)
// , xc_objectStore(nullptr)
// , x10_object(obj.release())
// , x14_params(CVParamTransfer::Null()) {}
CObjectReference(IObjectStore* store, const rstl::auto_ptr< IObj >& obj, SObjectTag tag, CVParamTransfer xfer);
private:
u16 x0_refCount;
u16 x2_lockCount;
bool x2_locked : 1;
u16 x2_lockCount : 15;
SObjectTag x4_objTag;
IObjectStore* xc_objectStore;
IObj* x10_object;

View File

@@ -4,8 +4,18 @@
#include "Kyoto/Math/CVector3f.hpp"
class CAABox {
CVector3f min;
CVector3f max;
public:
CAABox() {
// TODO
}
static CAABox mskInvertedBox;
static CAABox mskNullBox;
private:
CVector3f min;
CVector3f max;
};
CHECK_SIZEOF(CAABox, 0x18)
#endif // __CAABOX_HPP__

View File

@@ -13,8 +13,15 @@ public:
f32 posY;
CVector3f m2;
f32 posZ;
CTransform4f() {
// TODO
}
CTransform4f(const CTransform4f& other);
};
extern CTransform4f skIdentity4f;
CHECK_SIZEOF(CTransform4f, 0x30)
#endif // __CTRANSFORM4F_HPP__

View File

@@ -5,6 +5,7 @@
class CVector3f {
public:
CVector3f() : mX(0.f), mY(0.f), mZ(0.f) {}
explicit CVector3f(f32 x, f32 y, f32 z) : mX(x), mY(y), mZ(z) {}
f32 GetX() const { return mX; }

View File

@@ -1,11 +1,11 @@
#ifndef _CPARTICLEGEN_HPP
#define _CPARTICLEGEN_HPP
#include "Kyoto/Math/CTransform4f.hpp"
#include "Kyoto/Math/CVector3f.hpp"
#include "Kyoto/Math/CAABox.hpp"
#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Graphics/CLight.hpp"
#include "Kyoto/Math/CAABox.hpp"
#include "Kyoto/Math/CTransform4f.hpp"
#include "Kyoto/Math/CVector3f.hpp"
class CWarp;
class CParticleGen {

45
include/Kyoto/TToken.hpp Normal file
View File

@@ -0,0 +1,45 @@
#ifndef _TTOKEN_HPP
#define _TTOKEN_HPP
#include "types.h"
#include "Kyoto/CSimplePool.hpp"
#include "Kyoto/CToken.hpp"
#include "Kyoto/IObj.hpp"
#include "rstl/auto_ptr.hpp"
template < typename T >
class TToken : public CToken {
public:
TToken() {}
TToken(const CToken& token) : CToken(token) {}
TToken(T* obj) : CToken(GetIObjObjectFor(obj).release()) {}
TToken(const rstl::auto_ptr< T >& obj) : CToken(GetIObjObjectFor(obj).release()) {}
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetIObjObjectFor(T* obj) {
return TObjOwnerDerivedFromIObj< T >::GetNewDerivedObject(obj);
}
static rstl::auto_ptr< TObjOwnerDerivedFromIObj< T > > GetIObjObjectFor(const rstl::auto_ptr< T >& obj) {
return TObjOwnerDerivedFromIObj< T >::GetNewDerivedObject(obj);
}
};
template < typename T >
class TCachedToken : public TToken< T > {
public:
TCachedToken() {}
TCachedToken(const CToken& token) : TToken(token), x8_item(nullptr) {}
private:
T* x8_item;
};
template < typename T >
class TLockedToken : public TCachedToken< T > {
public:
TLockedToken() {}
TLockedToken(const CToken& token) : TCachedToken(token) { Lock(); }
};
#endif

View File

@@ -4,7 +4,7 @@
#include "gx_enum.h"
#include "types.h"
#include "Kyoto/Math/CColor.hpp"
#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Math/CTransform4f.hpp"
#include "Kyoto/Math/CVector2f.hpp"
#include "rstl/pair.hpp"

View File

@@ -0,0 +1,98 @@
#ifndef _CACTOR_HPP
#define _CACTOR_HPP
#include "types.h"
#include "Collision/CMaterialFilter.hpp"
#include "Collision/CMaterialList.hpp"
#include "MetroidPrime/CEntity.hpp"
#include "MetroidPrime/CModelFlags.hpp"
#include "MetroidPrime/CSfxHandle.hpp"
#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Math/CAABox.hpp"
#include "Kyoto/Math/CTransform4f.hpp"
#include "Kyoto/TToken.hpp"
#include "rstl/pair.hpp"
#include "rstl/reserved_vector.hpp"
#include "rstl/single_ptr.hpp"
class CActorLights;
class CActorParameters;
class CModelData;
class CScannableObjectInfo;
class CSimpleShadow;
// TODO move
struct SAdvancementDeltas {};
class CActor : public CEntity {
public:
enum EThermalFlags {
kTF_None = 0,
kTF_Cold = 1,
kTF_Hot = 2,
};
CActor(TUniqueId uid, bool active, const rstl::string& name, const CEntityInfo& info, const CTransform4f& xf, const CModelData& mData,
const CMaterialList& list, const CActorParameters& params, TUniqueId nextDrawNode);
~CActor();
SAdvancementDeltas UpdateAnimation(float dt, CStateManager& mgr, bool advTree);
void UpdateSfxEmitters();
void RemoveEmitter();
const CTransform4f& GetTransform() const { return x34_transform; }
protected:
CTransform4f x34_transform;
rstl::single_ptr< CModelData > x64_modelData;
CMaterialList x68_material;
CMaterialFilter x70_materialFilter;
TSfxId x88_sfxId;
CSfxHandle x8c_loopingSfxHandle;
rstl::single_ptr< CActorLights > x90_actorLights;
rstl::single_ptr< CSimpleShadow > x94_simpleShadow;
rstl::single_ptr< TCachedToken< CScannableObjectInfo > > x98_scanObjectInfo;
CAABox x9c_renderBounds;
CModelFlags xb4_drawFlags;
f32 xbc_time;
u32 xc0_pitchBend;
TUniqueId xc4_fluidId;
TUniqueId xc6_nextDrawNode;
s32 xc8_drawnToken;
s32 xcc_addedToken;
f32 xd0_damageMag;
u8 xd4_maxVol;
rstl::reserved_vector< CSfxHandle, 2 > xd8_nonLoopingSfxHandles;
u32 xe4_24_nextNonLoopingSfxHandle : 3;
u32 xe4_27_notInSortedLists : 1;
u32 xe4_28_transformDirty : 1;
u32 xe4_29_actorLightsDirty : 1;
u32 xe4_30_outOfFrustum : 1;
u32 xe4_31_calculateLighting : 1;
u32 xe5_24_shadowEnabled : 1;
u32 xe5_25_shadowDirty : 1;
u32 xe5_26_muted : 1;
u32 xe5_27_useInSortedLists : 1;
u32 xe5_28_callTouch : 1;
u32 xe5_29_globalTimeProvider : 1;
u32 xe5_30_renderUnsorted : 1;
u32 xe5_31_pointGeneratorParticles : 1;
u32 xe6_24_fluidCounter : 3;
EThermalFlags xe6_27_thermalVisorFlags : 2;
u32 xe6_29_renderParticleDBInside : 1;
u32 xe6_30_enablePitchBend : 1;
u32 xe6_31_targetableVisorFlags : 4;
u32 xe7_27_enableRender : 1;
u32 xe7_28_worldLightingDirty : 1;
u32 xe7_29_drawEnabled : 1;
u32 xe7_30_doTargetDistanceTest : 1;
u32 xe7_31_targetable : 1;
};
CHECK_SIZEOF(CActor, 0xe8)
#endif

View File

@@ -0,0 +1,11 @@
#ifndef _CACTORLIGHTS_HPP
#define _CACTORLIGHTS_HPP
#include "types.h"
class CActorLights {
public:
~CActorLights();
};
#endif

View File

@@ -0,0 +1,132 @@
#ifndef _CACTORPARAMETERS_HPP
#define _CACTORPARAMETERS_HPP
#include "types.h"
#include "Kyoto/IObjectStore.hpp"
#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Math/CVector3f.hpp"
#include "rstl/auto_ptr.hpp"
#include "rstl/pair.hpp"
class CActorLights;
class CLightParameters {
public:
enum EShadowTesselation {
kST_Invalid = -1,
kST_Zero,
};
enum EWorldLightingOptions {
kLO_Zero,
kLO_NormalWorld,
kLO_NoShadowCast,
kLO_DisableWorld,
};
enum ELightRecalculationOptions {
kLR_LargeFrameCount,
kLR_EightFrames,
kLR_FourFrames,
kLR_OneFrame,
};
CLightParameters() {
// TODO
}
virtual ~CLightParameters();
const CColor& GetAmbientColor() const { return x18_noLightsAmbient; }
bool ShouldMakeLights() const { return x1c_makeLights; }
s32 GetMaxAreaLights() const { return x3c_maxAreaLights; }
rstl::auto_ptr< CActorLights > MakeActorLights() const;
private:
bool x4_castShadow;
f32 x8_shadowScale;
EShadowTesselation xc_shadowTesselation;
f32 x10_shadowAlpha;
f32 x14_maxShadowHeight;
CColor x18_noLightsAmbient;
bool x1c_makeLights;
bool x1d_ambientChannelOverflow;
EWorldLightingOptions x20_worldLightingOptions;
ELightRecalculationOptions x24_lightRecalcOpts;
s32 x28_layerIdx;
CVector3f x2c_actorPosBias;
s32 x38_maxDynamicLights;
s32 x3c_maxAreaLights;
};
CHECK_SIZEOF(CLightParameters, 0x40)
class CScannableParameters {
public:
CScannableParameters() {}
CScannableParameters(CAssetId scanId) : x0_scanId(scanId) {}
CAssetId GetScannableObject0() const { return x0_scanId; }
private:
CAssetId x0_scanId;
};
CHECK_SIZEOF(CScannableParameters, 0x4)
class CVisorParameters {
public:
CVisorParameters() {
// TODO
}
CVisorParameters(u8 mask, bool b1, bool scanPassthrough) : x0_mask(mask), x0_4_b1(b1), x0_5_scanPassthrough(scanPassthrough) {}
u8 GetMask() const { return x0_mask; }
// TODO: GetIsBlockXRay__16CVisorParametersCFv?
bool GetBool1() const { return x0_4_b1; }
bool GetScanPassthrough() const { return x0_5_scanPassthrough; }
static CVisorParameters None();
private:
u32 x0_mask : 4;
u32 x0_4_b1 : 1;
u32 x0_5_scanPassthrough : 1;
};
CHECK_SIZEOF(CVisorParameters, 0x4)
class CActorParameters {
public:
CActorParameters() {
// TODO
}
const CLightParameters& GetLighting() const { return x0_lightParams; }
const CScannableParameters& GetScannable() const { return x40_scanParams; }
const rstl::pair< CAssetId, CAssetId >& GetXRay() const { return x44_xrayAssets; }
const rstl::pair< CAssetId, CAssetId >& GetInfra() const { return x4c_thermalAssets; }
const CVisorParameters& GetVisorParameters() const { return x54_visorParams; }
f32 GetThermalMag() const { return x64_thermalMag; }
bool GetUseGlobalRenderTime() const { return x58_24_globalTimeProvider; }
bool IsHotInThermal() const { return x58_25_thermalHeat; }
bool ForceRenderUnsorted() const { return x58_26_renderUnsorted; }
bool NoSortThermal() const { return x58_27_noSortThermal; }
private:
CLightParameters x0_lightParams;
CScannableParameters x40_scanParams;
rstl::pair< CAssetId, CAssetId > x44_xrayAssets;
rstl::pair< CAssetId, CAssetId > x4c_thermalAssets;
CVisorParameters x54_visorParams;
bool x58_24_globalTimeProvider : 1;
bool x58_25_thermalHeat : 1;
bool x58_26_renderUnsorted : 1;
bool x58_27_noSortThermal : 1;
f32 x5c_fadeInTime;
f32 x60_fadeOutTime;
f32 x64_thermalMag;
};
CHECK_SIZEOF(CActorParameters, 0x68)
#endif

View File

@@ -0,0 +1,10 @@
#ifndef _CANIMDATA_HPP
#define _CANIMDATA_HPP
#include "types.h"
class CAnimData {
// TODO
};
#endif

View File

@@ -0,0 +1,30 @@
#ifndef _CAREAFOG_HPP
#define _CAREAFOG_HPP
#include "types.h"
#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Math/CVector2f.hpp"
enum ERglFogMode {
// TODO
};
class CAreaFog {
private:
ERglFogMode x0_fogMode;
CVector2f x4_rangeCur;
CVector2f xc_rangeTarget;
CVector2f x14_rangeDelta;
CColor x1c_colorCur;
unkptr x20_;
unkptr x24_;
CColor x28_colorTarget;
unkptr x2c_;
unkptr x30_;
f32 x34_colorDelta;
};
CHECK_SIZEOF(CAreaFog, 0x38)
#endif

View File

@@ -40,4 +40,6 @@ protected:
bool x30_27_notInArea : 1;
};
CHECK_SIZEOF(CEntity, 0x34)
#endif

View File

@@ -0,0 +1,51 @@
#ifndef _CMODELDATA_HPP
#define _CMODELDATA_HPP
#include "types.h"
#include "MetroidPrime/TGameTypes.hpp"
#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Math/CVector3f.hpp"
#include "Kyoto/Math/CTransform4f.hpp"
#include "Kyoto/TToken.hpp"
#include "rstl/auto_ptr.hpp"
#include "rstl/optional_object.hpp"
#include "rstl/pair.hpp"
class CAnimData;
class CModel;
class CModelData {
public:
bool IsStaticModel() const { return xc_animData.get() == nullptr && !x1c_normalModel; }
CModelData() {
// TODO
}
CModelData(const CModelData& other);
~CModelData();
SAdvancementDeltas AdvanceAnimation(float dt, CStateManager& mgr, TAreaId aid, bool advTree);
void AdvanceParticles(const CTransform4f& xf, float dt, CStateManager& mgr);
rstl::auto_ptr< CAnimData >& GetAnimData() { return xc_animData; }
void SetXRayModel(const rstl::pair< CAssetId, CAssetId >& assets);
void SetInfraModel(const rstl::pair< CAssetId, CAssetId >& assets);
void SetAmbientColor(const CColor& color) { x18_ambientColor = color; }
void SetSortThermal(bool b) { x14_25_sortThermal = b; }
private:
CVector3f x0_scale;
rstl::auto_ptr< CAnimData > xc_animData;
bool x14_24_renderSorted : 1;
bool x14_25_sortThermal : 1;
CColor x18_ambientColor;
rstl::optional_object< TCachedToken< CModel > > x1c_normalModel;
rstl::optional_object< TCachedToken< CModel > > x2c_xrayModel;
rstl::optional_object< TCachedToken< CModel > > x3c_infraModel;
};
#endif

View File

@@ -0,0 +1,73 @@
#ifndef _CMODELFLAGS_HPP
#define _CMODELFLAGS_HPP
#include "types.h"
#include "Kyoto/Graphics/CColor.hpp"
class CModelFlags {
public:
enum ETrans {
kT_Opaque = 0,
kT_Blend = 5,
kT_Additive = 7,
};
enum EFlags {
kF_DepthCompare = 0x1,
kF_DepthUpdate = 0x2,
kF_NoTextureLock = 0x4,
kF_DepthGreater = 0x8,
kF_DepthNonInclusive = 0x10,
kF_DrawNormal = 0x20,
kF_ThermalUnsortedOnly = 0x40,
};
CModelFlags(ETrans trans, f32 rgba)
: x0_blendMode(trans), x1_matSetIdx(0), x2_flags(kF_DepthCompare | kF_DepthUpdate), x4_color(rgba, rgba, rgba, rgba) {}
CModelFlags(ETrans trans, CColor color)
: x0_blendMode(trans), x1_matSetIdx(0), x2_flags(kF_DepthCompare | kF_DepthUpdate), x4_color(color) {}
CModelFlags(const CModelFlags& flags, u32 otherFlags)
: x0_blendMode(flags.x0_blendMode), x1_matSetIdx(flags.x1_matSetIdx), x2_flags(otherFlags), x4_color(flags.x4_color) {}
CModelFlags(const CModelFlags& flags, bool b /* TODO what's this? */, s32 shaderSet)
: x0_blendMode(flags.x0_blendMode), x1_matSetIdx(shaderSet), x2_flags(flags.x2_flags), x4_color(flags.x4_color) {}
CModelFlags UseShaderSet(s32 matSet) { return CModelFlags(*this, false, matSet); }
CModelFlags DontLoadTextures() { return CModelFlags(*this, GetOtherFlags() | kF_NoTextureLock); }
CModelFlags DepthCompareUpdate(bool compare, bool update) {
u32 flags = GetOtherFlags();
if (compare) {
flags |= kF_DepthCompare;
} else {
flags &= ~kF_DepthCompare;
}
if (update) {
flags |= kF_DepthUpdate;
} else {
flags &= ~kF_DepthUpdate;
}
return CModelFlags(*this, flags);
}
CModelFlags DepthBackwards() { return CModelFlags(*this, GetOtherFlags() | kF_DepthGreater); }
ETrans GetTrans() const { return static_cast< ETrans >(x0_blendMode); }
s32 GetShaderSet() const { return x1_matSetIdx; }
u32 GetOtherFlags() const { return x2_flags; }
CColor GetColor() const { return x4_color; }
static CModelFlags Normal() { return CModelFlags(kT_Opaque, 1.f); }
static CModelFlags AlphaBlended(f32 f);
static CModelFlags AlphaBlended(const CColor& color);
static CModelFlags Additive(f32 f);
static CModelFlags Additive(const CColor& color);
static CModelFlags AdditiveRGB(const CColor& color);
static CModelFlags ColorModulate(const CColor& color);
private:
u8 x0_blendMode;
u8 x1_matSetIdx;
u16 x2_flags;
CColor x4_color;
};
CHECK_SIZEOF(CModelFlags, 0x8)
#endif

View File

@@ -1,7 +1,12 @@
#ifndef __COBJECTLIST_HPP__
#define __COBJECTLIST_HPP__
#include "types.h"
#include "MetroidPrime/TGameTypes.hpp"
#define kMaxObjects 1024
enum EGameObjectList {
kGOL_Invalid = -1,
kGOL_All,
@@ -25,7 +30,7 @@ class CObjectList {
public:
CObjectList(EGameObjectList list);
bool IsQualified(CEntity& ent);
bool IsQualified(CEntity& ent);
void AddObject(CEntity& ent);
void RemoveObject(TUniqueId uid);
CEntity* GetObjectById();
@@ -36,11 +41,12 @@ public:
const CEntity* operator[](s32 idx) const;
const CEntity* GetValidObjectByIndex(s32 idx) const;
s32 size() const { return mCount; }
private:
SObjectListEntry mObjects[1024];
EGameObjectList mListType;
s16 mFirstId = -1;
s16 mCount = 0;
}
};
#endif // __COBJECTLIST_HPP__

View File

@@ -0,0 +1,16 @@
#ifndef _CSFXHANDLE_HPP
#define _CSFXHANDLE_HPP
#include "types.h"
class CSfxHandle {
public:
CSfxHandle() : value(0) {}
CSfxHandle(u32 value) : value(value) {}
private:
u32 value;
};
CHECK_SIZEOF(CSfxHandle, 0x4)
#endif

View File

@@ -3,9 +3,31 @@
#include "types.h"
#include "MetroidPrime/CEntityInfo.hpp"
#include "MetroidPrime/TGameTypes.hpp"
#include "rstl/auto_ptr.hpp"
#include "rstl/list.hpp"
#include "rstl/reserved_vector.hpp"
#include "rstl/single_ptr.hpp"
class CObjectList;
class CPlayer;
class CWorld;
class CStateManagerContainer;
class CStateManager {
public:
void SendScriptMsg(TUniqueId uid, TEditorId target, EScriptObjectMessage msg, EScriptObjectState state);
private:
u16 x0_nextFreeIndex;
rstl::reserved_vector< u16, 1024 > x8_objectIndexArray;
rstl::reserved_vector< rstl::auto_ptr< CObjectList >, 8 > x808_objectLists;
CPlayer* x84c_player;
rstl::single_ptr< CWorld > x850_world;
rstl::list< rstl::reserved_vector< TUniqueId, 32 > > x854_graveyard;
rstl::single_ptr< CStateManagerContainer > x86c_stateManagerContainer;
};
#endif

View File

@@ -0,0 +1,24 @@
#ifndef _CSTATEMANAGERCONTAINER_HPP
#define _CSTATEMANAGERCONTAINER_HPP
#include "types.h"
#include "MetroidPrime/TGameTypes.hpp"
#include "MetroidPrime/Cameras/CCameraManager.hpp"
#include "rstl/reserved_vector.hpp"
class CStateManagerContainer {
CCameraManager x0_cameraManager;
SL::CSortedListManager x3c0_sortedListManager;
CWeaponMgr xe3d8_weaponManager;
CFluidPlaneManager xe3ec_fluidPlaneManager;
CEnvFxManager xe510_envFxManager;
CActorModelParticles xf168_actorModelParticles;
CRumbleManager xf250_rumbleManager;
rstl::reserved_vector< TUniqueId, 20 > xf344_;
rstl::reserved_vector< TUniqueId, 20 > xf370_;
rstl::reserved_vector< TUniqueId, 20 > xf39c_renderLast;
};
#endif

View File

@@ -3,7 +3,7 @@
#include "types.h"
#include "Kyoto/Math/CColor.hpp"
#include "Kyoto/Graphics/CColor.hpp"
#include "CTexture.hpp"

View File

@@ -0,0 +1,56 @@
#ifndef _CCAMERAMANAGER_HPP
#define _CCAMERAMANAGER_HPP
#include "types.h"
#include "MetroidPrime/CAreaFog.hpp"
#include "MetroidPrime/TGameTypes.hpp"
#include "Kyoto/Math/CVector3f.hpp"
#include "rstl/list.hpp"
#include "rstl/pair.hpp"
#include "rstl/reserved_vector.hpp"
#include "rstl/vector.hpp"
class CBallCamera;
class CCameraShakeData;
class CFirstPersonCamera;
class CInterpolationCamera;
class CCameraManager {
private:
TUniqueId x0_curCameraId;
rstl::vector< TUniqueId > x4_cineCameras;
rstl::list< CCameraShakeData > x14_shakers;
u32 x2c_lastShakeId;
CVector3f x30_shakeOffset;
CAreaFog x3c_fog;
s32 x74_fluidCounter;
TUniqueId x78_fluidId;
CFirstPersonCamera* x7c_fpCamera;
CBallCamera* x80_ballCamera;
s32 x84_rumbleId;
CInterpolationCamera* x88_interpCamera;
f32 x90_rumbleCooldown;
f32 x94_fogDensityFactor;
f32 x98_fogDensitySpeed;
f32 x9c_fogDensityFactorTarget;
bool xa0_24_pendingRumble : 1;
bool xa0_25_rumbling : 1;
bool xa0_26_inWater : 1;
TUniqueId xa2_spindleCamId;
TUniqueId xa4_pathCamId;
TUniqueId xa6_camHintId;
s32 xa8_hintPriority;
rstl::reserved_vector< rstl::pair< s32, TUniqueId >, 64 > xac_cameraHints;
rstl::reserved_vector< TUniqueId, 64 > x2b0_inactiveCameraHints;
rstl::reserved_vector< TUniqueId, 64 > x334_activeCameraHints;
bool x3b8_24_ : 1;
bool x3b8_25_ : 1;
float x3bc_curFov;
};
CHECK_SIZEOF(CCameraManager, 0x3c0)
#endif

View File

@@ -0,0 +1,44 @@
#ifndef _CCAMERASHAKEDATA_HPP
#define _CCAMERASHAKEDATA_HPP
#include "types.h"
#include "Kyoto/Math/CVector3f.hpp"
struct SCameraShakePoint {
bool x0_useEnvelope;
f32 x4_value;
f32 x8_magnitude;
f32 xc_attackTime;
f32 x10_sustainTime;
f32 x14_duration;
};
CHECK_SIZEOF(SCameraShakePoint, 0x18)
class CCameraShakerComponent {
public:
virtual ~CCameraShakerComponent();
private:
bool x4_useModulation;
SCameraShakePoint x8_am;
SCameraShakePoint x20_fm;
f32 x38_value;
};
CHECK_SIZEOF(CCameraShakerComponent, 0x3c)
class CCameraShakeData {
private:
f32 x0_duration;
f32 x4_curTime;
CCameraShakerComponent x8_shakerX;
CCameraShakerComponent x44_shakerY;
CCameraShakerComponent x80_shakerZ;
u32 xbc_shakerId;
u32 xc0_flags;
CVector3f xc4_sfxPos;
f32 xd0_sfxDist;
};
CHECK_SIZEOF(CCameraShakeData, 0xd4)
#endif

View File

@@ -21,6 +21,7 @@ struct TAreaId {
bool operator==(const TAreaId& other) const { return value == other.value; }
bool operator!=(const TAreaId& other) const { return value != other.value; }
};
CHECK_SIZEOF(TAreaId, 0x4)
struct TEditorId {
u32 value;
@@ -32,6 +33,7 @@ struct TEditorId {
bool operator==(const TEditorId& other) const { return value == other.value; }
bool operator!=(const TEditorId& other) const { return value != other.value; }
};
CHECK_SIZEOF(TEditorId, 0x4)
struct TUniqueId {
union {
@@ -49,5 +51,9 @@ struct TUniqueId {
bool operator==(const TUniqueId& other) const { return value == other.value; }
bool operator!=(const TUniqueId& other) const { return value != other.value; }
};
CHECK_SIZEOF(TUniqueId, 0x2)
typedef u16 TSfxId;
static TSfxId InvalidSfxId = 0xFFFFu;
#endif

View File

@@ -28,11 +28,14 @@ public:
// other.x0_has = false;
// }
T* get() { return x4_item; }
const T* get() const { return x4_item; }
T* operator->() { return get(); }
const T* operator->() const { return get(); }
T* release() const {
x0_has = false;
return x4_item;
}
operator bool() const { return x0_has; }
};
} // namespace rstl

View File

@@ -72,6 +72,13 @@ inline void uninitialized_copy_n(D* dest, S* src, size_t count) {
}
// destroy(src, src + count); ??
}
template < typename D, typename S >
inline void uninitialized_fill_n(D dest, int count, const S& value) {
for (int i = 0; i < count; ++dest, ++i) {
construct(dest, value);
}
}
} // namespace rstl
#endif

View File

@@ -10,17 +10,19 @@ namespace rstl {
template < typename T, size_t N >
class reserved_vector {
size_t x0_count;
T x4_items[N];
u8 x4_data[N * sizeof(T)];
public:
typedef pointer_iterator< T, reserved_vector< T, N >, void > iterator;
typedef const_pointer_iterator< T, reserved_vector< T, N >, void > const_iterator;
inline iterator begin() { return iterator(x4_items); }
inline const_iterator begin() const { return const_iterator(x4_items); }
inline iterator end() { return iterator(x4_items + x0_count); }
inline const_iterator end() const { return const_iterator(x4_items + x0_count); }
inline iterator begin() { return iterator(data()); }
inline const_iterator begin() const { return const_iterator(data()); }
inline iterator end() { return iterator(data() + x0_count); }
inline const_iterator end() const { return const_iterator(data() + x0_count); }
reserved_vector() : x0_count(0) {}
reserved_vector(const T& value) : x0_count(N) { rstl::uninitialized_fill_n(data(), N, value); }
reserved_vector(const reserved_vector& other) {
x0_count = other.size();
rstl::uninitialized_copy_n(data(), other.data(), size());
@@ -35,14 +37,12 @@ public:
}
void clear() {
for (size_t i = 0; i < x0_count; ++i) {
rstl::destroy(&x4_items[i]);
rstl::destroy(&data()[i]);
}
x0_count = 0;
}
~reserved_vector() {
clear();
}
~reserved_vector() { clear(); }
void push_back(const T& in) {
if (x0_count < N) {
@@ -52,14 +52,14 @@ public:
}
}
inline T* data() { return x4_items; }
inline const T* data() const { return x4_items; }
inline T* data() { return reinterpret_cast< T* >(x4_data); }
inline const T* data() const { return reinterpret_cast< const T* >(x4_data); }
inline size_t size() const { return x0_count; }
inline size_t capacity() const { return N; }
inline T& front() { return x4_items[0]; }
inline const T& front() const { return x4_items[0]; }
inline T& back() { return x4_items[x0_count - 1]; }
inline const T& back() const { return x4_items[x0_count - 1]; }
inline T& front() { return data()[0]; }
inline const T& front() const { return data()[0]; }
inline T& back() { return data()[x0_count - 1]; }
inline const T& back() const { return data()[x0_count - 1]; }
inline T& operator[](size_t idx) { return data()[idx]; }
inline const T& operator[](size_t idx) const { return data()[idx]; }
};

View File

@@ -19,7 +19,13 @@ public:
delete x0_ptr;
x0_ptr = ptr;
}
operator bool() const { return x0_ptr != nullptr; }
T& operator*() { return *x0_ptr; }
const T& operator*() const { return *x0_ptr; }
};
typedef single_ptr<void> unk_singleptr;
CHECK_SIZEOF(unk_singleptr, 0x4);
} // namespace rstl
#endif

View File

@@ -115,6 +115,8 @@ string string_l(const char* data);
// {
// return string(string::literal_t(), data);
// }
CHECK_SIZEOF(string, 0x10)
} // namespace rstl
#endif

View File

@@ -106,6 +106,9 @@ void vector< T, Alloc >::reserve(size_t size) {
xc_items = newData;
x8_capacity = size;
}
typedef vector<void> unk_vector;
CHECK_SIZEOF(unk_vector, 0x10)
} // namespace rstl
#endif

33
include/static_assert.hpp Normal file
View File

@@ -0,0 +1,33 @@
// C++98 static assert
template < bool expr >
struct do_static_assert;
template <>
struct do_static_assert< true > {
static const char test;
};
struct false_type {
static const bool value = false;
};
struct true_type {
static const bool value = true;
};
template < int A, int B >
struct _n_is_equal : false_type {};
template < int A >
struct _n_is_equal< A, A > : true_type {};
template < class T, int N >
struct check_sizeof : _n_is_equal< sizeof(T), N > {};
#ifdef __MWERKS__
#define CHECK_SIZEOF(cls, size) \
static void cls##_check() { do_static_assert< check_sizeof< cls, size >::value >::test; }
#else
#define CHECK_SIZEOF(cls, size)
#endif

View File

@@ -2,6 +2,8 @@
#define __TYPES_H__
#ifdef __cplusplus
#include "static_assert.hpp"
extern "C" {
#endif