Skip to content

Commit

Permalink
Start CWorld
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Oct 17, 2024
1 parent 0036cf3 commit dcb0f44
Show file tree
Hide file tree
Showing 16 changed files with 827 additions and 39 deletions.
2 changes: 1 addition & 1 deletion config/GM8E01_00/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ LoadRelays__FR12CInputStreamRQ24rstl44vector<Q26SRelay,Q24rstl17rmemory_allocato
__dt__11CDummyWorldFv = .text:0x800572D0; // type:function size:0xDC scope:global
fn_800573AC = .text:0x800573AC; // type:function size:0xD0
__ct__11CDummyWorldFUi = .text:0x8005747C; // type:function size:0x138 scope:global
IGetGameAreas__6CWorldCFv = .text:0x800575B4; // type:function size:0x8 scope:global
IGetAreaCount__6CWorldCFv = .text:0x800575B4; // type:function size:0x8 scope:global
IGetDefaultAudioTrack__6CWorldCFv = .text:0x800575BC; // type:function size:0x24 scope:global
ICheckWorldComplete__6CWorldFv = .text:0x800575E0; // type:function size:0x34 scope:global
IGetCurrentAreaId__6CWorldCFv = .text:0x80057614; // type:function size:0xC scope:global
Expand Down
2 changes: 1 addition & 1 deletion config/GM8E01_01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ LoadRelays__FR12CInputStreamRQ24rstl44vector<Q26SRelay,Q24rstl17rmemory_allocato
__dt__11CDummyWorldFv = .text:0x8005734C; // type:function size:0xDC scope:global
fn_800573AC = .text:0x80057428; // type:function size:0xD0 scope:global
__ct__11CDummyWorldFUi = .text:0x800574F8; // type:function size:0x138 scope:global
IGetGameAreas__6CWorldCFv = .text:0x80057630; // type:function size:0x8 scope:global
IGetAreaCount__6CWorldCFv = .text:0x80057630; // type:function size:0x8 scope:global
IGetDefaultAudioTrack__6CWorldCFv = .text:0x80057638; // type:function size:0x24 scope:global
ICheckWorldComplete__6CWorldFv = .text:0x8005765C; // type:function size:0x34 scope:global
IGetCurrentAreaId__6CWorldCFv = .text:0x80057690; // type:function size:0xC scope:global
Expand Down
10 changes: 8 additions & 2 deletions include/Kyoto/Audio/CAudioSys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Kyoto/Math/CVector3f.hpp"

class CAudioGroupSet;
class CSimplePool;

enum ETRKSampleRate {
kTSR_Zero,
Expand All @@ -30,7 +31,7 @@ class CAudioSys {
enum ESurroundModes { kSM_Mono, kSM_Stereo, kSM_Surround };
class CEmitterData {
public:
CEmitterData() : _50(0), _51(0), _52(kEmitterMedPriority){};
CEmitterData() : _50(0), _51(0), _52(kEmitterMedPriority) {};

private:
char data[0x50];
Expand Down Expand Up @@ -70,6 +71,12 @@ class CAudioSys {

static void SysSetVolume(uchar, uint, uchar);
static void SysSetSfxVolume(uchar, ushort, uchar, uchar);
static bool SysLoadGroupSet(CSimplePool*, uint);
static const rstl::string& SysGetGroupSetName(uint);
static bool SysPushGroupIntoARAM(const rstl::string& name, uchar);
static void SysPopGroupFromARAM();
static void SysUnloadGroupSet(const rstl::string& name);
static void SysUnloadSampleData(const rstl::string& name);

static void SetDefaultVolumeScale(short);
static void SetVolumeScale(short);
Expand Down Expand Up @@ -100,7 +107,6 @@ class CAudioSys {
static void S3dAddEmitter(SND_FXID fxid, const CVector3f& pos, const CVector3f& dir,
const bool b1, const bool b2, short, int);


static u32 SeqPlayEx(unsigned short, unsigned short, void*, SND_PLAYPARA*, unsigned char);
static void SeqStop(u32);
static void SeqVolume(u8, u16, u32, u8);
Expand Down
2 changes: 2 additions & 0 deletions include/Kyoto/Audio/CMidiManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CMidiManager {
short x8_songId;
bool xa_available;
};

class CMidiData {
public:
CMidiData(CInputStream& in);
Expand All @@ -36,6 +37,7 @@ class CMidiManager {
const short GetGroupId() const { return x2_groupId; }
const int GetSetupId() const { return x4_setupId; }
uchar* GetData() const { return x8_data.get(); }

private:
short x0_songId;
short x2_groupId;
Expand Down
1 change: 1 addition & 0 deletions include/Kyoto/Audio/CStreamAudioManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CStreamAudioManager {
public:
static void Update(float dt);
static void StopAll();
static void StopOneShot();
static void SetMusicVolume(uint);
static void SetSfxVolume(uint);

Expand Down
2 changes: 1 addition & 1 deletion include/Kyoto/CDvdRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CDvdRequest {
public:
virtual ~CDvdRequest(){}; // 8
virtual ~CDvdRequest() {}; // 8
virtual void WaitUntilComplete() = 0; // c
virtual bool IsComplete() = 0; // 10
virtual void PostCancelRequest() = 0; // 14
Expand Down
142 changes: 124 additions & 18 deletions include/MetroidPrime/CGameArea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,71 @@

#include "types.h"

#include "MetroidPrime/CStateManager.hpp"
#include "MetroidPrime/TGameTypes.hpp"

#include "Kyoto/Graphics/CColor.hpp"
#include "Kyoto/Graphics/CGraphics.hpp"
#include "Kyoto/IObjectStore.hpp"
#include "Kyoto/Math/CAABox.hpp"
#include "Kyoto/Math/CTransform4f.hpp"
#include "Kyoto/Math/CVector2f.hpp"

#include "WorldFormat/CMetroidModelInstance.hpp"
#include "WorldFormat/CWorldLight.hpp"

#include "rstl/auto_ptr.hpp"
#include "rstl/list.hpp"
#include "rstl/optional_object.hpp"
#include "rstl/pair.hpp"
#include "rstl/rc_ptr.hpp"
#include "rstl/reserved_vector.hpp"
#include "rstl/single_ptr.hpp"
#include "rstl/vector.hpp"

class CAreaOctTree;
class CDvdRequest;
class CPVSAreaSet;
class CScriptAreaAttributes;
class CToken;

class IGameArea {
public:
class Dock {
public:
struct SDockReference {
uint x0_area;
s16 x4_dock;
bool x6_loadOther;

SDockReference();
};

private:
int x0_referenceCount;
rstl::vector< SDockReference > x4_dockReferences;
rstl::reserved_vector< CVector3f, 4 > x14_planeVertices;
bool x48_isReferenced;

public:
const rstl::reserved_vector< CVector3f, 4 >& GetPlaneVertices() const {
return x14_planeVertices;
}
int GetReferenceCount() const { return x0_referenceCount; }
const rstl::vector< SDockReference >& GetDockRefs() const { return x4_dockReferences; }
Dock(CInputStream& in, const CTransform4f& xf);
TAreaId GetConnectedAreaId(int other) const;
s16 GetOtherDockNumber(int other) const;
bool GetShouldLoadOther(int other) const;
void SetShouldLoadOther(int other, bool should);
bool ShouldLoadOtherArea(int other) const;
CVector3f GetPoint(int idx) const;
bool IsReferenced() const { return x48_isReferenced; }
void SetReferenceCount(int v) {
x0_referenceCount = v;
x48_isReferenced = true;
}
};

virtual ~IGameArea();
virtual const CTransform4f& IGetTM() const = 0;
virtual CAssetId IGetStringTableAssetId() const = 0;
Expand All @@ -33,21 +79,36 @@ class IGameArea {
virtual rstl::pair< rstl::auto_ptr< uchar >, int > IGetScriptingMemoryAlways() const = 0;
};

enum EChain {
kC_Invalid = -1,
kC_ToDeallocate,
kC_Deallocated,
kC_Loading,
kC_Alive,
kC_AliveJudgement,
};
struct CAreaRenderOctTree {
struct Node {
ushort x0_bitmapIdx;
ushort x2_flags;
ushort x4_children[1];

class Dock;
class CToken;
class CDvdRequest;
class CScriptAreaAttributes;
class CWorldLight;
class CPVSAreaSet;
uint GetChildCount() const;
CAABox GetNodeBounds(const CAABox& curAABB, int idx) const;

void RecursiveBuildOverlaps(u32* out, const CAreaRenderOctTree& parent, const CAABox& curAABB,
const CAABox& testAABB) const;
};

const u8* x0_buf;
int x4_; // TODO
uint x8_bitmapCount;
uint xc_meshCount;
uint x10_nodeCount;
uint x14_bitmapWordCount;
CAABox x18_aabb;
const u32* x30_bitmaps;
const u32* x34_indirectionTable;
const u8* x38_entries;

explicit CAreaRenderOctTree(const u8* buf);

void FindOverlappingModels(rstl::vector< u32 >& out, const CAABox& testAABB) const;
void FindOverlappingModels(u32* out, const CAABox& testAABB) const;
};
CHECK_SIZEOF(CAreaRenderOctTree, 0x3c);

class CGameArea : public IGameArea {
public:
Expand Down Expand Up @@ -96,7 +157,15 @@ class CGameArea : public IGameArea {
enum EOcclusionState { kOS_Occluded, kOS_Visible };

struct CPostConstructed {
uchar x0_pad[0xa0];
rstl::optional_object< CAreaOctTree* > x0_collision;
int x8_; // TODO
rstl::optional_object< CAreaRenderOctTree > xc_octTree;
rstl::vector< CMetroidModelInstance > x4c_insts;
rstl::single_ptr< int > x5c_; // TODO
rstl::vector< CWorldLight > x60_lightsA;
rstl::vector< CLight > x70_gfxLightsA;
rstl::vector< CWorldLight > x80_lightsB;
rstl::vector< CLight > x90_gfxLightsB;
CPVSAreaSet* xa0_pvs;
uchar xa4_pad[0x1020];
rstl::single_ptr< CAreaFog > x10c4_areaFog;
Expand Down Expand Up @@ -136,8 +205,16 @@ class CGameArea : public IGameArea {
bool TryTakingOutOfARAM();

bool StartStreamingMainArea();
bool Invalidate(CStateManager* mgr);
void Validate(CStateManager& mgr);
void SetOcclusionState(EOcclusionState state);
void RemoveStaticGeometry();
void StartStreamIn(CStateManager& mgr);
void SetChain(CGameArea* next, int chain);

CAssetId GetAreaAssetId() const { return x84_mrea; }
const Dock& GetDock(int idx) const { return xcc_docks[idx]; }
int GetDockCount() const { return xcc_docks.size(); }
const CAreaFog* GetAreaFog() const { return x12c_postConstructed->x10c4_areaFog.get(); }
CAreaFog* AreaFog() { return x12c_postConstructed->x10c4_areaFog.get(); }
EOcclusionState GetOcclusionState() const { return x12c_postConstructed->x10dc_occlusionState; }
Expand All @@ -147,6 +224,9 @@ class CGameArea : public IGameArea {
bool IsPostConstructed() const { return xf0_24_postConstructed; } // name?
CPostConstructed* GetPostConstructed() { return x12c_postConstructed.get(); } // name?
const CPostConstructed* GetPostConstructed() const { return x12c_postConstructed.get(); } // name?
CGameArea* GetNext() { return x130_next; } // name?
CGameArea* GetPrev() { return x134_prev; } // name?
int GetCurChain() const { return x138_curChain; } // name?

private:
void AllocNewAreaData(int, int);
Expand Down Expand Up @@ -187,10 +267,36 @@ class CGameArea : public IGameArea {
int x124_secCount;
int x128_mreaDataOffset;
rstl::single_ptr< CPostConstructed > x12c_postConstructed;
CGameArea* x130_next;
CGameArea* x134_prev;
int x138_curChain;
};

NESTED_CHECK_SIZEOF(CGameArea, CPostConstructed, 0x1140)
CHECK_SIZEOF(CGameArea, 0x13c)

class CDummyGameArea final : public IGameArea {
friend class CDummyWorld;

// CHECK_SIZEOF(CGamearea::CAreaFog, 0x38)
public:
CDummyGameArea(CInputStream& in, int idx, int mlvlVersion);
rstl::pair< rstl::auto_ptr< uchar >, int > IGetScriptingMemoryAlways() const override;
int IGetAreaSaveId() const override;
CAssetId IGetAreaAssetId() const override;
bool IIsActive() const override;
TAreaId IGetAttachedAreaId(int) const override;
uint IGetNumAttachedAreas() const override;
CAssetId IGetStringTableAssetId() const override;
const CTransform4f& IGetTM() const override;

private:
int x4_mlvlVersion;
CAssetId x8_nameSTRG;
CAssetId xc_mrea;
int x10_areaId;
CTransform4f x14_transform;
rstl::vector< u16 > x44_attachedAreaIndices;
rstl::vector< Dock > x54_docks;
};
CHECK_SIZEOF(CDummyGameArea, 0x64)

#endif // _CGAMEAREA
2 changes: 2 additions & 0 deletions include/MetroidPrime/CInGameTweakManager.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _CINGAMETWEAKMANAGER
#define _CINGAMETWEAKMANAGER

#include "Kyoto/SObjectTag.hpp"
#include "types.h"

#include "rstl/string.hpp"
Expand Down Expand Up @@ -61,6 +62,7 @@ class CInGameTweakManager {
bool HasTweakValue(const rstl::string& name) const;
const CTweakValue* GetTweakValue(const rstl::string& name) const;
bool ReadFromMemoryCard(const rstl::string&);
rstl::vector< CAssetId > GetSongAssetsInWorld(CAssetId world) const;

static rstl::string sub_8021cb38(CAssetId, const rstl::string&);

Expand Down
Loading

0 comments on commit dcb0f44

Please sign in to comment.