From b32c6018e8abcf52cffd0ea2ac4df55adf3c431a Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 19 Sep 2022 00:19:46 -0400 Subject: [PATCH] CPlayer header, more CScriptPlatform, renaming Former-commit-id: 5d9f7afa3b4905c5d9c402c89723a9425d301dda --- asm/MetroidPrime/CCollisionActor.s | 4 +- asm/MetroidPrime/CExplosion.s | 2 +- asm/MetroidPrime/CStateManager.s | 8 +- asm/MetroidPrime/Cameras/CCinematicCamera.s | 2 +- asm/MetroidPrime/Enemies/CDrone.s | 4 +- asm/MetroidPrime/Enemies/CMetroidPrimeExo.s | 2 +- .../ScriptObjects/CScriptColorModulate.s | 2 +- .../ScriptObjects/CScriptGenerator.s | 2 +- .../ScriptObjects/CScriptPlatform.s | 12 +- asm/MetroidPrime/Weapons/CIceImpact.s | 2 +- asm/MetroidPrime/Weapons/CShockWave.s | 2 +- include/Kyoto/Math/CQuaternion.hpp | 26 ++ include/Kyoto/Math/CTransform4f.hpp | 2 +- include/Kyoto/Math/CVector3f.hpp | 2 +- include/MetroidPrime/CActor.hpp | 4 +- include/MetroidPrime/CAnimRes.hpp | 21 + include/MetroidPrime/CEntity.hpp | 3 + include/MetroidPrime/CGameCollision.hpp | 17 + include/MetroidPrime/CPhysicsActor.hpp | 3 +- include/MetroidPrime/CStateManager.hpp | 4 + include/MetroidPrime/Player/CPlayer.hpp | 383 ++++++++++++++++++ .../Player/CPlayerEnergyDrain.hpp | 29 ++ include/MetroidPrime/Player/CPlayerState.hpp | 20 + .../ScriptObjects/CScriptPlatform.hpp | 7 + include/MetroidPrime/TCastTo.hpp | 2 +- include/MetroidPrime/TGameTypes.hpp | 3 +- include/rstl/pointer_iterator.hpp | 47 ++- include/rstl/reserved_vector.hpp | 8 +- include/rstl/vector.hpp | 1 + include/static_assert.hpp | 1 + .../ScriptObjects/CScriptMazeNode.cpp | 31 +- .../ScriptObjects/CScriptPlatform.cpp | 80 +++- src/MetroidPrime/main.cpp | 1 - 33 files changed, 674 insertions(+), 63 deletions(-) create mode 100644 include/MetroidPrime/CAnimRes.hpp create mode 100644 include/MetroidPrime/CGameCollision.hpp create mode 100644 include/MetroidPrime/Player/CPlayer.hpp create mode 100644 include/MetroidPrime/Player/CPlayerEnergyDrain.hpp diff --git a/asm/MetroidPrime/CCollisionActor.s b/asm/MetroidPrime/CCollisionActor.s index 5e3a7625..8d1ed6c3 100644 --- a/asm/MetroidPrime/CCollisionActor.s +++ b/asm/MetroidPrime/CCollisionActor.s @@ -556,7 +556,7 @@ lbl_801A8DD0: /* 801A8DE8 001A5D48 A0 1C 02 5C */ lhz r0, 0x25c(r28) /* 801A8DEC 001A5D4C B0 E1 00 0C */ sth r7, 0xc(r1) /* 801A8DF0 001A5D50 B0 01 00 14 */ sth r0, 0x14(r1) -/* 801A8DF4 001A5D54 4B E9 B0 61 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 801A8DF4 001A5D54 4B E9 B0 61 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage .global lbl_801A8DF8 lbl_801A8DF8: /* 801A8DF8 001A5D58 A0 1E 00 00 */ lhz r0, 0(r30) @@ -639,7 +639,7 @@ Touch__15CCollisionActorFR6CActorR13CStateManager: /* 801A8F00 001A5E60 7D 03 43 78 */ mr r3, r8 /* 801A8F04 001A5E64 B0 E1 00 08 */ sth r7, 8(r1) /* 801A8F08 001A5E68 B0 01 00 10 */ sth r0, 0x10(r1) -/* 801A8F0C 001A5E6C 4B E9 AF 49 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 801A8F0C 001A5E6C 4B E9 AF 49 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 801A8F10 001A5E70 80 01 00 24 */ lwz r0, 0x24(r1) /* 801A8F14 001A5E74 7C 08 03 A6 */ mtlr r0 /* 801A8F18 001A5E78 38 21 00 20 */ addi r1, r1, 0x20 diff --git a/asm/MetroidPrime/CExplosion.s b/asm/MetroidPrime/CExplosion.s index f8a0e02f..7755c6c1 100644 --- a/asm/MetroidPrime/CExplosion.s +++ b/asm/MetroidPrime/CExplosion.s @@ -334,7 +334,7 @@ lbl_8005A4D4: /* 8005A514 00057474 38 A1 00 10 */ addi r5, r1, 0x10 /* 8005A518 00057478 A0 1C 00 EC */ lhz r0, 0xec(r28) /* 8005A51C 0005747C B0 01 00 14 */ sth r0, 0x14(r1) -/* 8005A520 00057480 4B FE 99 35 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 8005A520 00057480 4B FE 99 35 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage lbl_8005A524: /* 8005A524 00057484 BA E1 00 AC */ lmw r23, 0xac(r1) /* 8005A528 00057488 80 01 00 D4 */ lwz r0, 0xd4(r1) diff --git a/asm/MetroidPrime/CStateManager.s b/asm/MetroidPrime/CStateManager.s index 8790ee9c..9828b4ac 100644 --- a/asm/MetroidPrime/CStateManager.s +++ b/asm/MetroidPrime/CStateManager.s @@ -478,8 +478,8 @@ lbl_80043E38: /* 80043E4C 00040DAC 38 21 00 20 */ addi r1, r1, 0x20 /* 80043E50 00040DB0 4E 80 00 20 */ blr -.global SendScriptMsgAlways__13CStateManagerF9TUniqueId -SendScriptMsgAlways__13CStateManagerF9TUniqueId: +.global SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage +SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage: /* 80043E54 00040DB4 94 21 FF E0 */ stwu r1, -0x20(r1) /* 80043E58 00040DB8 7C 08 02 A6 */ mflr r0 /* 80043E5C 00040DBC 90 01 00 24 */ stw r0, 0x24(r1) @@ -5303,7 +5303,7 @@ lbl_800480E0: /* 80048128 00045088 38 A1 00 08 */ addi r5, r1, 8 /* 8004812C 0004508C B0 01 00 10 */ sth r0, 0x10(r1) /* 80048130 00045090 38 C0 00 23 */ li r6, 0x23 -/* 80048134 00045094 4B FF BD 21 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 80048134 00045094 4B FF BD 21 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage lbl_80048138: /* 80048138 00045098 3B FF 00 04 */ addi r31, r31, 4 /* 8004813C 0004509C 3B DE 00 01 */ addi r30, r30, 1 @@ -8844,7 +8844,7 @@ lbl_8004B37C: /* 8004B39C 000482FC A0 07 00 08 */ lhz r0, 8(r7) /* 8004B3A0 00048300 B0 01 00 0C */ sth r0, 0xc(r1) /* 8004B3A4 00048304 B0 01 00 10 */ sth r0, 0x10(r1) -/* 8004B3A8 00048308 4B FF 8A AD */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 8004B3A8 00048308 4B FF 8A AD */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 8004B3AC 0004830C 48 00 00 34 */ b lbl_8004B3E0 lbl_8004B3B0: /* 8004B3B0 00048310 80 1C 08 4C */ lwz r0, 0x84c(r28) diff --git a/asm/MetroidPrime/Cameras/CCinematicCamera.s b/asm/MetroidPrime/Cameras/CCinematicCamera.s index fc3bfd05..6b25892c 100644 --- a/asm/MetroidPrime/Cameras/CCinematicCamera.s +++ b/asm/MetroidPrime/Cameras/CCinematicCamera.s @@ -2224,7 +2224,7 @@ SendArrivedMsg__16CCinematicCameraCF9TUniqueIdR13CStateManager: /* 8009491C 0009187C 38 A1 00 0C */ addi r5, r1, 0xc /* 80094920 00091880 B0 E1 00 0C */ sth r7, 0xc(r1) /* 80094924 00091884 B0 01 00 10 */ sth r0, 0x10(r1) -/* 80094928 00091888 4B FA F5 2D */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 80094928 00091888 4B FA F5 2D */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 8009492C 0009188C 80 01 00 24 */ lwz r0, 0x24(r1) /* 80094930 00091890 7C 08 03 A6 */ mtlr r0 /* 80094934 00091894 38 21 00 20 */ addi r1, r1, 0x20 diff --git a/asm/MetroidPrime/Enemies/CDrone.s b/asm/MetroidPrime/Enemies/CDrone.s index c9e23cb2..5d8cf3af 100644 --- a/asm/MetroidPrime/Enemies/CDrone.s +++ b/asm/MetroidPrime/Enemies/CDrone.s @@ -8552,7 +8552,7 @@ lbl_801662E8: /* 801662FC 0016325C 7D 03 43 78 */ mr r3, r8 /* 80166300 00163260 B0 E1 00 08 */ sth r7, 8(r1) /* 80166304 00163264 B0 01 00 10 */ sth r0, 0x10(r1) -/* 80166308 00163268 4B ED DB 4D */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 80166308 00163268 4B ED DB 4D */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 8016630C 0016326C 80 01 00 24 */ lwz r0, 0x24(r1) /* 80166310 00163270 7C 08 03 A6 */ mtlr r0 /* 80166314 00163274 38 21 00 20 */ addi r1, r1, 0x20 @@ -9364,7 +9364,7 @@ lbl_80166EDC: /* 80166EF0 00163E50 7D 03 43 78 */ mr r3, r8 /* 80166EF4 00163E54 B0 E1 00 08 */ sth r7, 8(r1) /* 80166EF8 00163E58 B0 01 00 10 */ sth r0, 0x10(r1) -/* 80166EFC 00163E5C 4B ED CF 59 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 80166EFC 00163E5C 4B ED CF 59 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 80166F00 00163E60 80 01 00 24 */ lwz r0, 0x24(r1) /* 80166F04 00163E64 7C 08 03 A6 */ mtlr r0 /* 80166F08 00163E68 38 21 00 20 */ addi r1, r1, 0x20 diff --git a/asm/MetroidPrime/Enemies/CMetroidPrimeExo.s b/asm/MetroidPrime/Enemies/CMetroidPrimeExo.s index 4f09a758..47f0d4dc 100644 --- a/asm/MetroidPrime/Enemies/CMetroidPrimeExo.s +++ b/asm/MetroidPrime/Enemies/CMetroidPrimeExo.s @@ -1955,7 +1955,7 @@ lbl_80272258: /* 80272318 0026F278 A0 07 00 08 */ lhz r0, 8(r7) /* 8027231C 0026F27C B0 01 00 10 */ sth r0, 0x10(r1) /* 80272320 0026F280 B0 01 00 14 */ sth r0, 0x14(r1) -/* 80272324 0026F284 4B DD 1B 31 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 80272324 0026F284 4B DD 1B 31 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 80272328 0026F288 80 BF 08 4C */ lwz r5, 0x84c(r31) /* 8027232C 0026F28C 38 61 00 28 */ addi r3, r1, 0x28 /* 80272330 0026F290 C0 1E 00 50 */ lfs f0, 0x50(r30) diff --git a/asm/MetroidPrime/ScriptObjects/CScriptColorModulate.s b/asm/MetroidPrime/ScriptObjects/CScriptColorModulate.s index 86e3e350..ce45eedc 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptColorModulate.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptColorModulate.s @@ -721,7 +721,7 @@ lbl_80201584: /* 802015A8 001FE508 A0 1E 00 34 */ lhz r0, 0x34(r30) /* 802015AC 001FE50C B0 E1 00 10 */ sth r7, 0x10(r1) /* 802015B0 001FE510 B0 01 00 18 */ sth r0, 0x18(r1) -/* 802015B4 001FE514 4B E4 28 A1 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 802015B4 001FE514 4B E4 28 A1 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage lbl_802015B8: /* 802015B8 001FE518 7F C3 F3 78 */ mr r3, r30 /* 802015BC 001FE51C 7F E5 FB 78 */ mr r5, r31 diff --git a/asm/MetroidPrime/ScriptObjects/CScriptGenerator.s b/asm/MetroidPrime/ScriptObjects/CScriptGenerator.s index 27b8fb45..8a1db5b1 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptGenerator.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptGenerator.s @@ -236,7 +236,7 @@ lbl_800B47C4: /* 800B47D8 000B1738 B0 C1 00 30 */ sth r6, 0x30(r1) /* 800B47DC 000B173C B0 01 00 28 */ sth r0, 0x28(r1) /* 800B47E0 000B1740 80 DB 00 04 */ lwz r6, 4(r27) -/* 800B47E4 000B1744 4B F8 F6 71 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 800B47E4 000B1744 4B F8 F6 71 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage lbl_800B47E8: /* 800B47E8 000B1748 3B 7B 00 0C */ addi r27, r27, 0xc lbl_800B47EC: diff --git a/asm/MetroidPrime/ScriptObjects/CScriptPlatform.s b/asm/MetroidPrime/ScriptObjects/CScriptPlatform.s index affc9e34..67eba210 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptPlatform.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptPlatform.s @@ -1455,8 +1455,8 @@ lbl_800B1DDC: /* 800B1DFC 000AED5C 38 21 00 60 */ addi r1, r1, 0x60 /* 800B1E00 000AED60 4E 80 00 20 */ blr -.global sub_800b1e04 -sub_800b1e04: +.global "erase__Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>FQ24rstl106pointer_iterator<7SRiders,Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>" +"erase__Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>FQ24rstl106pointer_iterator<7SRiders,Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>": /* 800B1E04 000AED64 94 21 FF E0 */ stwu r1, -0x20(r1) /* 800B1E08 000AED68 7C 08 02 A6 */ mflr r0 /* 800B1E0C 000AED6C 90 01 00 24 */ stw r0, 0x24(r1) @@ -2242,7 +2242,7 @@ lbl_800B28D0: /* 800B28D8 000AF838 38 9C 03 38 */ addi r4, r28, 0x338 /* 800B28DC 000AF83C 38 A1 00 10 */ addi r5, r1, 0x10 /* 800B28E0 000AF840 90 01 00 10 */ stw r0, 0x10(r1) -/* 800B28E4 000AF844 4B FF F5 21 */ bl sub_800b1e04 +/* 800B28E4 000AF844 4B FF F5 21 */ bl "erase__Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>FQ24rstl106pointer_iterator<7SRiders,Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>" /* 800B28E8 000AF848 80 01 00 14 */ lwz r0, 0x14(r1) /* 800B28EC 000AF84C 90 01 00 18 */ stw r0, 0x18(r1) lbl_800B28F0: @@ -2992,7 +2992,7 @@ lbl_800B3274: /* 800B33C8 000B0328 38 61 00 18 */ addi r3, r1, 0x18 /* 800B33CC 000B032C 38 A1 00 14 */ addi r5, r1, 0x14 /* 800B33D0 000B0330 90 01 00 14 */ stw r0, 0x14(r1) -/* 800B33D4 000B0334 4B FF EA 31 */ bl sub_800b1e04 +/* 800B33D4 000B0334 4B FF EA 31 */ bl "erase__Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>FQ24rstl106pointer_iterator<7SRiders,Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>" /* 800B33D8 000B0338 48 00 00 B8 */ b lbl_800B3490 lbl_800B33DC: /* 800B33DC 000B033C 7F C3 F3 78 */ mr r3, r30 @@ -3151,13 +3151,13 @@ lbl_800B35E4: /* 800B3618 000B0578 38 C0 00 1F */ li r6, 0x1f /* 800B361C 000B057C A0 07 00 00 */ lhz r0, 0(r7) /* 800B3620 000B0580 B0 01 00 0C */ sth r0, 0xc(r1) -/* 800B3624 000B0584 4B F9 08 31 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 800B3624 000B0584 4B F9 08 31 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 800B3628 000B0588 80 01 00 18 */ lwz r0, 0x18(r1) /* 800B362C 000B058C 7F C4 F3 78 */ mr r4, r30 /* 800B3630 000B0590 38 61 00 14 */ addi r3, r1, 0x14 /* 800B3634 000B0594 38 A1 00 10 */ addi r5, r1, 0x10 /* 800B3638 000B0598 90 01 00 10 */ stw r0, 0x10(r1) -/* 800B363C 000B059C 4B FF E7 C9 */ bl sub_800b1e04 +/* 800B363C 000B059C 4B FF E7 C9 */ bl "erase__Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>FQ24rstl106pointer_iterator<7SRiders,Q24rstl43vector<7SRiders,Q24rstl17rmemory_allocator>,Q24rstl17rmemory_allocator>" /* 800B3640 000B05A0 48 00 00 10 */ b lbl_800B3650 lbl_800B3644: /* 800B3644 000B05A4 80 61 00 18 */ lwz r3, 0x18(r1) diff --git a/asm/MetroidPrime/Weapons/CIceImpact.s b/asm/MetroidPrime/Weapons/CIceImpact.s index b97237f2..aaf4b504 100644 --- a/asm/MetroidPrime/Weapons/CIceImpact.s +++ b/asm/MetroidPrime/Weapons/CIceImpact.s @@ -1611,7 +1611,7 @@ lbl_801B71B4: /* 801B71F4 001B4154 38 A1 00 10 */ addi r5, r1, 0x10 /* 801B71F8 001B4158 A0 1C 00 EC */ lhz r0, 0xec(r28) /* 801B71FC 001B415C B0 01 00 14 */ sth r0, 0x14(r1) -/* 801B7200 001B4160 4B E8 CC 55 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 801B7200 001B4160 4B E8 CC 55 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage lbl_801B7204: /* 801B7204 001B4164 BA E1 00 AC */ lmw r23, 0xac(r1) /* 801B7208 001B4168 80 01 00 D4 */ lwz r0, 0xd4(r1) diff --git a/asm/MetroidPrime/Weapons/CShockWave.s b/asm/MetroidPrime/Weapons/CShockWave.s index 9bee6efa..f0433796 100644 --- a/asm/MetroidPrime/Weapons/CShockWave.s +++ b/asm/MetroidPrime/Weapons/CShockWave.s @@ -267,7 +267,7 @@ lbl_80231930: /* 80231960 0022E8C0 38 A1 00 10 */ addi r5, r1, 0x10 /* 80231964 0022E8C4 A0 1C 09 80 */ lhz r0, 0x980(r28) /* 80231968 0022E8C8 B0 01 00 14 */ sth r0, 0x14(r1) -/* 8023196C 0022E8CC 4B E1 24 E9 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId +/* 8023196C 0022E8CC 4B E1 24 E9 */ bl SendScriptMsgAlways__13CStateManagerF9TUniqueId9TUniqueId20EScriptObjectMessage /* 80231970 0022E8D0 BA E1 00 AC */ lmw r23, 0xac(r1) /* 80231974 0022E8D4 80 01 00 D4 */ lwz r0, 0xd4(r1) /* 80231978 0022E8D8 7C 08 03 A6 */ mtlr r0 diff --git a/include/Kyoto/Math/CQuaternion.hpp b/include/Kyoto/Math/CQuaternion.hpp index 8bc428b1..d1f18a31 100644 --- a/include/Kyoto/Math/CQuaternion.hpp +++ b/include/Kyoto/Math/CQuaternion.hpp @@ -3,6 +3,9 @@ #include "types.h" +#include "Kyoto/Math/CMatrix3f.hpp" +#include "Kyoto/Math/CTransform4f.hpp" + class CQuaternion { public: CQuaternion(f32 w, f32 x, f32 y, f32 z) : w(w), x(x), y(y), z(z) {} @@ -12,6 +15,29 @@ public: // , y(other.y) // , z(other.z) {} + CQuaternion operator*(const CQuaternion&) const; + // Slerp__11CQuaternionFRC11CQuaternionRC11CQuaternionf + // ShortestRotationArc__11CQuaternionFRC9CVector3fRC9CVector3f + // LookAt__11CQuaternionFRC13CUnitVector3fRC13CUnitVector3fRC9CRelAngle + // normalize_angle__Ff + // IsValidQuaternion__11CQuaternionCFf + // SlerpLocal__11CQuaternionFRC11CQuaternionRC11CQuaternionf + // AngleFrom__11CQuaternionCFRC11CQuaternion + // BuildEquivalent__11CQuaternionCFv + // BuildNormalized__11CQuaternionCFv + // AxisAngle__11CQuaternionFRC13CUnitVector3fRC9CRelAngle + // Transform__11CQuaternionCFRC9CVector3f + // XRotation__11CQuaternionFRC9CRelAngle + // YRotation__11CQuaternionFRC9CRelAngle + // ZRotation__11CQuaternionFRC9CRelAngle + // BuildTransform__11CQuaternionCFv + CTransform4f BuildTransform4f() const; + CTransform4f BuildTransform4f(const CVector3f&) const; + + static CQuaternion FromMatrixRows(const CVector3f&, const CVector3f&, const CVector3f&); + static CQuaternion FromMatrix(const CMatrix3f&); + static CQuaternion FromMatrix(const CTransform4f&); + static const CQuaternion& NoRotation() { return sNoRotation; } private: diff --git a/include/Kyoto/Math/CTransform4f.hpp b/include/Kyoto/Math/CTransform4f.hpp index 9cb5317a..81a71df9 100644 --- a/include/Kyoto/Math/CTransform4f.hpp +++ b/include/Kyoto/Math/CTransform4f.hpp @@ -59,7 +59,7 @@ public: // MakeRotationsBasedOnY__12CTransform4fFRC13CUnitVector3f CTransform4f MultiplyIgnoreTranslation(const CTransform4f& other) const; // Orthonormalize__12CTransform4fFv - // Rotate__12CTransform4fCFRC9CVector3f + CVector3f Rotate(const CVector3f& in) const; // RotateLocalX__12CTransform4fFRC9CRelAngle // RotateLocalY__12CTransform4fFRC9CRelAngle // RotateLocalZ__12CTransform4fFRC9CRelAngle diff --git a/include/Kyoto/Math/CVector3f.hpp b/include/Kyoto/Math/CVector3f.hpp index 893b13b2..398ffa22 100644 --- a/include/Kyoto/Math/CVector3f.hpp +++ b/include/Kyoto/Math/CVector3f.hpp @@ -52,7 +52,7 @@ public: // f32 operator[](int i) const { return *(&mX + i); } bool IsNonZero() const { return mX != 0.f || mY != 0.f || mZ != 0.f; } - void DropZ() { mZ = 0.f; } + CVector3f DropZ() const { return CVector3f(mX, mY, 0.f); } CVector3f& operator+=(const CVector3f& other) { mX += other.mX; diff --git a/include/MetroidPrime/CActor.hpp b/include/MetroidPrime/CActor.hpp index 0505b00c..4e5d8f32 100644 --- a/include/MetroidPrime/CActor.hpp +++ b/include/MetroidPrime/CActor.hpp @@ -254,7 +254,6 @@ public: void DrawTouchBounds() const; bool IsModelOpaque(const CStateManager& mgr) const; void RenderInternal(const CStateManager& mgr) const; - void SetMaterialFilter(const CMaterialFilter& filter); const CTransform4f& GetTransform() const { return x34_transform; } void SetTransform(const CTransform4f& xf) { @@ -293,6 +292,9 @@ public: const CMaterialList& GetMaterialList() const { return x68_material; } CMaterialList& MaterialList() { return x68_material; } + const CMaterialFilter& GetMaterialFilter() const; + void SetMaterialFilter(const CMaterialFilter& filter); + bool GetTransformDirty() const { return xe4_27_notInSortedLists; } bool GetTransformDirtySpare() const { return xe4_28_transformDirty; } bool GetPreRenderHasMoved() const { return xe4_29_actorLightsDirty; } diff --git a/include/MetroidPrime/CAnimRes.hpp b/include/MetroidPrime/CAnimRes.hpp new file mode 100644 index 00000000..56f2b1dc --- /dev/null +++ b/include/MetroidPrime/CAnimRes.hpp @@ -0,0 +1,21 @@ +#ifndef _CANIMRES_HPP +#define _CANIMRES_HPP + +#include "types.h" + +#include "MetroidPrime/TGameTypes.hpp" + +#include "Kyoto/IObjectStore.hpp" +#include "Kyoto/Math/CVector3f.hpp" + +class CAnimRes { +private: + CAssetId x0_ancsId; + int x4_charIdx; + CVector3f x8_scale; + bool x14_canLoop; + int x18_defaultAnim; +}; +CHECK_SIZEOF(CAnimRes, 0x1c) + +#endif \ No newline at end of file diff --git a/include/MetroidPrime/CEntity.hpp b/include/MetroidPrime/CEntity.hpp index 15a24802..ff9c5946 100644 --- a/include/MetroidPrime/CEntity.hpp +++ b/include/MetroidPrime/CEntity.hpp @@ -30,6 +30,9 @@ public: TUniqueId GetUniqueId() const { return x8_uid; } TAreaId GetAreaId() const; bool GetActive() const { return x30_24_active; } + + // might be fake? + rstl::vector< SConnection >& ConnectionList() { return x20_conns; } const rstl::vector< SConnection >& GetConnectionList() const { return x20_conns; } static rstl::vector< SConnection > NullConnectionList; diff --git a/include/MetroidPrime/CGameCollision.hpp b/include/MetroidPrime/CGameCollision.hpp new file mode 100644 index 00000000..1fd0394c --- /dev/null +++ b/include/MetroidPrime/CGameCollision.hpp @@ -0,0 +1,17 @@ +#ifndef _CGAMECOLLISION_HPP +#define _CGAMECOLLISION_HPP + +#include "types.h" + +class CStateManager; +class CCollisionPrimitive; +class CTransform4f; +class CMaterialFilter; + +class CGameCollision { +public: + static bool DetectStaticCollisionBoolean(const CStateManager&, const CCollisionPrimitive&, + const CTransform4f&, const CMaterialFilter&); +}; + +#endif \ No newline at end of file diff --git a/include/MetroidPrime/CPhysicsActor.hpp b/include/MetroidPrime/CPhysicsActor.hpp index 6690fb81..a3a085af 100644 --- a/include/MetroidPrime/CPhysicsActor.hpp +++ b/include/MetroidPrime/CPhysicsActor.hpp @@ -61,11 +61,12 @@ public: virtual const CCollisionPrimitive* GetCollisionPrimitive() const; virtual CTransform4f GetPrimitiveTransform() const; virtual void CollidedWith(TUniqueId id, const CCollisionInfoList& list, CStateManager& mgr); - virtual f32 GetStepUpHeight() const; virtual f32 GetStepDownHeight() const; + virtual f32 GetStepUpHeight() const; virtual f32 GetWeight() const; CAABox GetBoundingBox() const; + void MoveCollisionPrimitive(const CVector3f&); bool GetMovable() const { return xf8_24_movable; } void SetMovable(bool v) { xf8_24_movable = v; } diff --git a/include/MetroidPrime/CStateManager.hpp b/include/MetroidPrime/CStateManager.hpp index f7bb500a..4ee5d175 100644 --- a/include/MetroidPrime/CStateManager.hpp +++ b/include/MetroidPrime/CStateManager.hpp @@ -39,11 +39,15 @@ namespace SL { class CSortedListManager; } // namespace SL +#define kMaxEntities 1024 +typedef rstl::reserved_vector< TUniqueId, kMaxEntities > TEntityList; + class CStateManager { public: void SendScriptMsg(TUniqueId uid, TEditorId target, EScriptObjectMessage msg, EScriptObjectState state); void SendScriptMsg(CEntity* ent, TUniqueId target, EScriptObjectMessage msg); + void SendScriptMsgAlways(TUniqueId uid, TUniqueId src, EScriptObjectMessage msg); bool AddDrawableActor(const CActor& actor, const CVector3f& pos, const CAABox& bounds) const; void SetupParticleHook(const CActor& actor) const; void FreeScriptObject(TUniqueId uid); diff --git a/include/MetroidPrime/Player/CPlayer.hpp b/include/MetroidPrime/Player/CPlayer.hpp new file mode 100644 index 00000000..9a35f6f5 --- /dev/null +++ b/include/MetroidPrime/Player/CPlayer.hpp @@ -0,0 +1,383 @@ +#ifndef _CPLAYER_HPP +#define _CPLAYER_HPP + +#include "types.h" + +#include "MetroidPrime/CAnimRes.hpp" +#include "MetroidPrime/CPhysicsActor.hpp" +#include "MetroidPrime/Player/CPlayerEnergyDrain.hpp" +#include "MetroidPrime/Player/CPlayerState.hpp" + +#include "Kyoto/TReservedAverage.hpp" + +#include "rstl/auto_ptr.hpp" +#include "rstl/vector.hpp" + +class CPlayerGun; +class CFailsafeTest; +class CMorphBall; +class CPlayerCameraBob; + +namespace NPlayer { +enum EPlayerMovementState { + kMS_OnGround, + kMS_Jump, + kMS_ApplyJump, + kMS_Falling, + kMS_FallingMorphed, +}; +}; + +class CPlayer : public CPhysicsActor { +public: + enum EPlayerOrbitState { + kOS_NoOrbit, + kOS_OrbitObject, + kOS_OrbitPoint, + kOS_OrbitCarcass, + kOS_ForcedOrbitObject, // For CMetroidBeta attack + kOS_Grapple, + }; + enum ESurfaceRestraints { + kSR_Normal, + kSR_Air, + kSR_Ice, + kSR_Organic, + kSR_Water, + kSR_Lava, + kSR_Phazon, + kSR_Shrubbery, + }; + enum EPlayerCameraState { + kCS_FirstPerson, + kCS_Ball, + kCS_Two, + kCS_Transitioning, + kCS_Spawned, + }; + enum EPlayerMorphBallState { + kMS_Unmorphed, + kMS_Morphed, + kMS_Morphing, + kMS_Unmorphing, + }; + enum EPlayerOrbitType { + kOT_Close, + kOT_Far, + kOT_Default, + }; + enum EPlayerOrbitRequest { + kOR_StopOrbit, + kOR_Respawn, + kOR_EnterMorphBall, + kOR_Default, + kOR_Four, + kOR_Five, + kOR_InvalidateTarget, + kOR_BadVerticalAngle, + kOR_ActivateOrbitSource, + kOR_ProjectileCollide, + kOR_Freeze, + kOR_DamageOnGrapple, + kOR_LostGrappleLineOfSight, + }; + enum EPlayerZoneInfo { + kZI_Targeting, + kZI_Scan, + }; + enum EPlayerZoneType { + kZT_Always = -1, + kZT_Box, + kZT_Ellipse, + }; + enum EPlayerScanState { + kSS_NotScanning, + kSS_Scanning, + kSS_ScanComplete, + }; + enum EGrappleState { + kGS_None, + kGS_Firing, + kGS_Pull, + kGS_Swinging, + kGS_JumpOff, + }; + enum EFootstepSfx { + kFS_None, + kFS_Left, + kFS_Right, + }; + enum EGunHolsterState { + kGH_Holstered, + kGH_Drawing, + kGH_Drawn, + kGH_Holstering, + }; + + // CEntity + ~CPlayer() override; + void Accept(IVisitor& visitor) override; + void PreThink(f32 dt, CStateManager& mgr) override; + void Think(f32 dt, CStateManager& mgr) override; + void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) override; + + // CActor + void PreRender(CStateManager&, const CFrustumPlanes&) override; + void AddToRenderer(const CFrustumPlanes&, const CStateManager&) const override; + void Render(const CStateManager&) const override; + bool CanRenderUnsorted(const CStateManager&) const override; + void CalculateRenderBounds() override; + CHealthInfo* HealthInfo(CStateManager&) override; + const CDamageVulnerability* GetDamageVulnerability() const override; + const CDamageVulnerability* GetDamageVulnerability(const CVector3f&, const CVector3f&, + const CDamageInfo&) const override; + rstl::optional_object< CAABox > GetTouchBounds() const override; + void Touch(CActor&, CStateManager&) override; + CVector3f GetAimPosition(const CStateManager&, float) const override; + CVector3f GetHomingPosition(const CStateManager&, float) const override; + void FluidFXThink(EFluidState, CScriptWater&, CStateManager&) override; + + // CPhysicsActor + const CCollisionPrimitive* GetCollisionPrimitive() const override; + CTransform4f GetPrimitiveTransform() const override; + void CollidedWith(TUniqueId id, const CCollisionInfoList& list, CStateManager& mgr) override; + f32 GetStepDownHeight() const override; + f32 GetStepUpHeight() const override; + f32 GetWeight() const override; + + // CPlayer + virtual bool IsTransparent(); + + EPlayerOrbitState GetOrbitState() const { return x304_orbitState; } + +private: + struct CVisorSteam { + f32 x0_curTargetAlpha; + f32 x4_curAlphaInDur; + f32 x8_curAlphaOutDur; + CAssetId xc_tex; + f32 x10_nextTargetAlpha; + f32 x14_nextAlphaInDur; + f32 x18_nextAlphaOutDur; + CAssetId x1c_txtr; + f32 x20_alpha; + f32 x24_delayTimer; + bool x28_affectsThermal; + + public: + CVisorSteam(f32 targetAlpha, f32 alphaInDur, f32 alphaOutDur, CAssetId tex) + : x0_curTargetAlpha(targetAlpha) + , x4_curAlphaInDur(alphaInDur) + , x8_curAlphaOutDur(alphaOutDur) + , xc_tex(tex) {} + CAssetId GetTextureId() const; + void SetSteam(f32 targetAlpha, f32 alphaInDur, f32 alphaOutDur, CAssetId txtr, + bool affectsThermal); + void Update(f32 dt); + f32 GetAlpha() const { return x20_alpha; } + bool AffectsThermal() const { return x28_affectsThermal; } + }; + + NPlayer::EPlayerMovementState x258_movementState; + rstl::vector< CToken > x25c_ballTransitionsRes; + TUniqueId x26c_attachedActor; + f32 x270_attachedActorTime; + CPlayerEnergyDrain x274_energyDrain; + f32 x288_startingJumpTimeout; + f32 x28c_sjTimer; + f32 x290_minJumpTimeout; + f32 x294_jumpCameraTimer; + uint x298_jumpPresses; + f32 x29c_fallCameraTimer; + f32 x2a0_; + bool x2a4_cancelCameraPitch; + f32 x2a8_timeSinceJump; + ESurfaceRestraints x2ac_surfaceRestraint; + uint x2b0_outOfWaterTicks; + rstl::reserved_vector< f32, 6 > x2b4_accelerationTable; + uint x2d0_curAcceleration; + f32 x2d4_accelerationChangeTimer; + CAABox x2d8_fpBounds; + f32 x2f0_ballTransHeight; + EPlayerCameraState x2f4_cameraState; + EPlayerMorphBallState x2f8_morphBallState; + EPlayerMorphBallState x2fc_spawnedMorphBallState; + f32 x300_fallingTime; + EPlayerOrbitState x304_orbitState; + EPlayerOrbitType x308_orbitType; + EPlayerOrbitRequest x30c_orbitRequest; + TUniqueId x310_orbitTargetId; + CVector3f x314_orbitPoint; + CVector3f x320_orbitVector; + f32 x32c_orbitModeTimer; + EPlayerZoneInfo x330_orbitZoneMode; + EPlayerZoneType x334_orbitType; + uint x338_; + TUniqueId x33c_orbitNextTargetId; + bool m_deferredOrbitObject; + f32 x340_; + rstl::vector< TUniqueId > x344_nearbyOrbitObjects; + rstl::vector< TUniqueId > x354_onScreenOrbitObjects; + rstl::vector< TUniqueId > x364_offScreenOrbitObjects; + bool x374_orbitLockEstablished; + f32 x378_orbitPreventionTimer; + bool x37c_sidewaysDashing; + f32 x380_strafeInputAtDash; + f32 x384_dashTimer; + f32 x388_dashButtonHoldTime; + bool x38c_doneSidewaysDashing; + uint x390_orbitSource; + bool x394_orbitingEnemy; + f32 x398_dashSpeedMultiplier; + bool x39c_noStrafeDashBlend; + f32 x3a0_dashDuration; + f32 x3a4_strafeDashBlendDuration; + EPlayerScanState x3a8_scanState; + f32 x3ac_scanningTime; + f32 x3b0_curScanTime; + TUniqueId x3b4_scanningObject; + EGrappleState x3b8_grappleState; + f32 x3bc_grappleSwingTimer; + CVector3f x3c0_grappleSwingAxis; + f32 x3cc_; + f32 x3d0_; + f32 x3d4_; + f32 x3d8_grappleJumpTimeout; + bool x3dc_inFreeLook; + bool x3dd_lookButtonHeld; + bool x3de_lookAnalogHeld; + f32 x3e0_curFreeLookCenteredTime; + f32 x3e4_freeLookYawAngle; + f32 x3e8_horizFreeLookAngleVel; + f32 x3ec_freeLookPitchAngle; + f32 x3f0_vertFreeLookAngleVel; + TUniqueId x3f4_aimTarget; + CVector3f x3f8_targetAimPosition; + TReservedAverage< CVector3f, 10 > x404_aimTargetAverage; + CVector3f x480_assistedTargetAim; + f32 x48c_aimTargetTimer; + rstl::single_ptr< CPlayerGun > x490_gun; + f32 x494_gunAlpha; + EGunHolsterState x498_gunHolsterState; + f32 x49c_gunHolsterRemTime; + rstl::single_ptr< CFailsafeTest > x4a0_failsafeTest; + TReservedAverage< f32, 20 > x4a4_moveSpeedAvg; + f32 x4f8_moveSpeed; + f32 x4fc_flatMoveSpeed; + CVector3f x500_lookDir; + CVector3f x50c_moveDir; + CVector3f x518_leaveMorphDir; + CVector3f x524_lastPosForDirCalc; + CVector3f x530_gunDir; + f32 x53c_timeMoving; + CVector3f x540_controlDir; + CVector3f x54c_controlDirFlat; + bool x558_wasDamaged; + f32 x55c_damageAmt; + f32 x560_prevDamageAmt; + CVector3f x564_damageLocation; + f32 x570_immuneTimer; + f32 x574_morphTime; + f32 x578_morphDuration; + uint x57c_; + uint x580_; + int x584_ballTransitionAnim; + f32 x588_alpha; + f32 x58c_transitionVel; + bool x590_leaveMorphballAllowed; + TReservedAverage< CTransform4f, 4 > x594_transisionBeamXfs; + TReservedAverage< CTransform4f, 4 > x658_transitionModelXfs; + TReservedAverage< f32, 4 > x71c_transitionModelAlphas; + rstl::vector< rstl::auto_ptr< CModelData > > x730_transitionModels; + f32 x740_staticTimer; + f32 x744_staticOutSpeed; + f32 x748_staticInSpeed; + f32 x74c_visorStaticAlpha; + f32 x750_frozenTimeout; + s32 x754_iceBreakJumps; + f32 x758_frozenTimeoutBias; + s32 x75c_additionalIceBreakJumps; + bool x760_controlsFrozen; + f32 x764_controlsFrozenTimeout; + rstl::single_ptr< CMorphBall > x768_morphball; + rstl::single_ptr< CPlayerCameraBob > x76c_cameraBob; + CSfxHandle x770_damageLoopSfx; + f32 x774_samusVoiceTimeout; + CSfxHandle x778_dashSfx; + CSfxHandle x77c_samusVoiceSfx; + int x780_samusVoicePriority; + f32 x784_damageSfxTimer; + u16 x788_damageLoopSfxId; + f32 x78c_footstepSfxTimer; + EFootstepSfx x790_footstepSfxSel; + CVector3f x794_lastVelocity; + CVisorSteam x7a0_visorSteam; + CPlayerState::EPlayerSuit x7cc_transitionSuit; + rstl::auto_ptr< CAnimRes > x7d0_animRes; + CVector3f x7d8_beamScale; + bool x7e4_; + uint x7e8_; + CPlayerState::EBeamId x7ec_beam; + rstl::single_ptr< CModelData > x7f0_ballTransitionBeamModel; + CTransform4f x7f4_gunWorldXf; + f32 x824_transitionFilterTimer; + f32 x828_distanceUnderWater; + bool x82c_inLava; + TUniqueId x82e_ridingPlatform; + TUniqueId x830_playerHint; + uint x834_playerHintPriority; + rstl::reserved_vector< rstl::pair< uint, TUniqueId >, 32 > x838_playerHints; + rstl::reserved_vector< TUniqueId, 32 > x93c_playerHintsToRemove; + rstl::reserved_vector< TUniqueId, 32 > x980_playerHintsToAdd; + bool x9c4_24_visorChangeRequested : 1; + bool x9c4_25_showCrosshairs : 1; + bool x9c4_26_ : 1; + bool x9c4_27_canEnterMorphBall : 1; + bool x9c4_28_canLeaveMorphBall : 1; + bool x9c4_29_spiderBallControlXY : 1; + bool x9c4_30_controlDirOverride : 1; + bool x9c4_31_inWaterMovement : 1; + bool x9c5_24_ : 1; + bool x9c5_25_splashUpdated : 1; + bool x9c5_26_ : 1; + bool x9c5_27_camSubmerged : 1; + bool x9c5_28_slidingOnWall : 1; + bool x9c5_29_hitWall : 1; + bool x9c5_30_selectFluidBallSound : 1; + bool x9c5_31_stepCameraZBiasDirty : 1; + bool x9c6_24_extendTargetDistance : 1; + bool x9c6_25_interpolatingControlDir : 1; + bool x9c6_26_outOfBallLookAtHint : 1; + bool x9c6_27_aimingAtProjectile : 1; + bool x9c6_28_aligningGrappleSwingTurn : 1; + bool x9c6_29_disableInput : 1; + bool x9c6_30_newScanScanning : 1; + bool x9c6_31_overrideRadarRadius : 1; + bool x9c7_24_noDamageLoopSfx : 1; + bool x9c7_25_outOfBallLookAtHintActor : 1; + f32 x9c8_eyeZBias; + f32 x9cc_stepCameraZBias; + uint x9d0_bombJumpCount; + s32 x9d4_bombJumpCheckDelayFrames; + CVector3f x9d8_controlDirOverrideDir; + rstl::reserved_vector< TUniqueId, 5 > x9e4_orbitDisableList; + f32 x9f4_deathTime; + f32 x9f8_controlDirInterpTime; + f32 x9fc_controlDirInterpDur; + TUniqueId xa00_deathPowerBomb; + f32 xa04_preThinkDt; + CAssetId xa08_steamTextureId; + CAssetId xa0c_iceTextureId; + uint xa10_envDmgCounter; + f32 xa14_envDmgCameraShakeTimer; + f32 xa18_phazonDamageLag; + f32 xa1c_threatOverride; + f32 xa20_radarXYRadiusOverride; + f32 xa24_radarZRadiusOverride; + f32 xa28_attachedActorStruggle; + int xa2c_damageLoopSfxDelayTicks; + f32 xa30_samusExhaustedVoiceTimer; +}; +CHECK_SIZEOF(CPlayer, 0xa38) + +#endif \ No newline at end of file diff --git a/include/MetroidPrime/Player/CPlayerEnergyDrain.hpp b/include/MetroidPrime/Player/CPlayerEnergyDrain.hpp new file mode 100644 index 00000000..42960262 --- /dev/null +++ b/include/MetroidPrime/Player/CPlayerEnergyDrain.hpp @@ -0,0 +1,29 @@ +#ifndef _CPLAYERENERGYDRAIN_HPP +#define _CPLAYERENERGYDRAIN_HPP + +#include "types.h" + +#include "MetroidPrime/TGameTypes.hpp" + +#include "rstl/vector.hpp" + +class CEnergyDrainSource { +public: + CEnergyDrainSource(TUniqueId src, f32 intensity); + TUniqueId GetEnergyDrainSourceId() const { return x0_source; } + void SetEnergyDrainIntensity(f32 in) { x4_intensity = in; } + f32 GetEnergyDrainIntensity() const { return x4_intensity; } + +private: + TUniqueId x0_source; + f32 x4_intensity; +}; + +class CPlayerEnergyDrain { +private: + rstl::vector< CEnergyDrainSource > x0_sources; + f32 x10_energyDrainTime; +}; +CHECK_SIZEOF(CPlayerEnergyDrain, 0x14) + +#endif \ No newline at end of file diff --git a/include/MetroidPrime/Player/CPlayerState.hpp b/include/MetroidPrime/Player/CPlayerState.hpp index 237ff513..808f6aca 100644 --- a/include/MetroidPrime/Player/CPlayerState.hpp +++ b/include/MetroidPrime/Player/CPlayerState.hpp @@ -13,6 +13,26 @@ public: kPV_Scan, kPV_Thermal, }; + enum EPlayerSuit { + kPS_Invalid = -1, + kPS_Power, + kPS_Gravity, + kPS_Varia, + kPS_Phazon, + kPS_FusionPower, + kPS_FusionGravity, + kPS_FusionVaria, + kPS_FusionPhazon, + }; + enum EBeamId { + kBI_Invalid = -1, + kBI_Power, + kBI_Ice, + kBI_Wave, + kBI_Plasma, + kBI_Phazon, + kBI_Phazon2 = 27, + }; EPlayerVisor GetActiveVisor(const CStateManager& mgr) const; diff --git a/include/MetroidPrime/ScriptObjects/CScriptPlatform.hpp b/include/MetroidPrime/ScriptObjects/CScriptPlatform.hpp index a9185eed..0ef2931b 100644 --- a/include/MetroidPrime/ScriptObjects/CScriptPlatform.hpp +++ b/include/MetroidPrime/ScriptObjects/CScriptPlatform.hpp @@ -69,6 +69,13 @@ public: static void AddRider(rstl::vector< SRiders >& riders, TUniqueId riderId, const CPhysicsActor* ridee, CStateManager& mgr); + static TEntityList BuildNearListFromRiders(CStateManager& mgr, + const rstl::vector< SRiders >& riders); + static void DecayRiders(rstl::vector< SRiders >& riders, f32 dt, CStateManager& mgr); + static void MoveRiders(CStateManager& mgr, f32 dt, bool active, rstl::vector< SRiders >& riders, + rstl::vector< SRiders >& collidedRiders, const CTransform4f& oldXf, + const CTransform4f& newXf, const CVector3f& dragDelta, + CQuaternion rotDelta); private: TUniqueId x258_currentWaypoint; diff --git a/include/MetroidPrime/TCastTo.hpp b/include/MetroidPrime/TCastTo.hpp index 68b54e55..f4e98aa5 100644 --- a/include/MetroidPrime/TCastTo.hpp +++ b/include/MetroidPrime/TCastTo.hpp @@ -103,7 +103,7 @@ inline const T* TCastToConstPtr(const CEntity* p) { } template < typename T > inline const T* TCastToConstPtr(const CEntity& p) { - return TCastToPtr< T >(const_cast< CEntity* >(&p)); + return TCastToPtr< T >(const_cast< CEntity& >(p)); } #endif diff --git a/include/MetroidPrime/TGameTypes.hpp b/include/MetroidPrime/TGameTypes.hpp index 42494353..66f891b2 100644 --- a/include/MetroidPrime/TGameTypes.hpp +++ b/include/MetroidPrime/TGameTypes.hpp @@ -2,7 +2,6 @@ #define _TGAMETYPES_HPP #include "types.h" - class CInputStream; class COutputStream; @@ -66,4 +65,6 @@ private: u8 x0_id; }; +#define ALIGN_UP(x, a) (((x) + (a - 1)) & ~(a - 1)) + #endif diff --git a/include/rstl/pointer_iterator.hpp b/include/rstl/pointer_iterator.hpp index 2df71254..bff4846e 100644 --- a/include/rstl/pointer_iterator.hpp +++ b/include/rstl/pointer_iterator.hpp @@ -20,24 +20,38 @@ public: const_pointer_iterator() : current(nullptr) {} const_pointer_iterator(const T* begin) : current(const_cast< T* >(begin)) {} const_pointer_iterator& operator++() { - ++current; + ++this->current; return *this; } const_pointer_iterator& operator--() { - --current; + --this->current; return *this; } + const_pointer_iterator& operator+=(int v) { + this->current += v; + return *this; + } + const_pointer_iterator& operator-=(int v) { + this->current -= v; + return *this; + } + const_pointer_iterator operator+(int v) const { + return const_pointer_iterator(this->current + v); + } + const_pointer_iterator operator-(int v) const { + return const_pointer_iterator(this->current - v); + } const T& operator*() const { return *current; } const T* operator->() const { return current; } bool operator==(const const_pointer_iterator& other) { return current == other.current; } bool operator!=(const const_pointer_iterator& other) { return current != other.current; } - friend const_pointer_iterator operator+(const const_pointer_iterator& x, int v) { - return const_pointer_iterator(x.current + v); - } - friend const_pointer_iterator operator-(const const_pointer_iterator& x, int v) { - return const_pointer_iterator(x.current - v); - } + // friend const_pointer_iterator operator+(const const_pointer_iterator& x, int v) { + // return const_pointer_iterator(x.current + v); + // } + // friend const_pointer_iterator operator-(const const_pointer_iterator& x, int v) { + // return const_pointer_iterator(x.current - v); + // } protected: T* current; @@ -64,12 +78,19 @@ public: --this->current; return *this; } - - friend pointer_iterator operator+(const pointer_iterator& x, int v) { - return pointer_iterator(x.current + v); + pointer_iterator& operator+=(int v) { + this->current += v; + return *this; } - friend pointer_iterator operator-(const pointer_iterator& x, int v) { - return pointer_iterator(x.current - v); + pointer_iterator& operator-=(int v) { + this->current -= v; + return *this; + } + pointer_iterator operator+(int v) const { + return pointer_iterator(this->current + v); + } + pointer_iterator operator-(int v) const { + return pointer_iterator(this->current - v); } }; } // namespace rstl diff --git a/include/rstl/reserved_vector.hpp b/include/rstl/reserved_vector.hpp index e093f1a5..628f5110 100644 --- a/include/rstl/reserved_vector.hpp +++ b/include/rstl/reserved_vector.hpp @@ -46,11 +46,9 @@ public: ~reserved_vector() { clear(); } void push_back(const T& in) { - if (x0_count < N) { - iterator out = begin() + x0_count; - out = in; - ++x0_count; - } + iterator out = begin() + x0_count; + out = in; + ++x0_count; } inline T* data() { return reinterpret_cast< T* >(x4_data); } diff --git a/include/rstl/vector.hpp b/include/rstl/vector.hpp index 05f701d4..d450cf37 100644 --- a/include/rstl/vector.hpp +++ b/include/rstl/vector.hpp @@ -62,6 +62,7 @@ public: } void reserve(int size); + iterator erase(iterator it); void push_back(const T& in) { if (x4_count >= x8_capacity) { diff --git a/include/static_assert.hpp b/include/static_assert.hpp index 17d33d52..c05db8ab 100644 --- a/include/static_assert.hpp +++ b/include/static_assert.hpp @@ -27,4 +27,5 @@ typedef unsigned long size_t; extern int cls##_check_offset##[_n_is_equal< offsetof(cls, member), offset >::value]; #else #define CHECK_SIZEOF(cls, size) +#define CHECK_OFFSETOF(cls, member, offset) #endif diff --git a/src/MetroidPrime/ScriptObjects/CScriptMazeNode.cpp b/src/MetroidPrime/ScriptObjects/CScriptMazeNode.cpp index 760eb32e..ed4f9600 100644 --- a/src/MetroidPrime/ScriptObjects/CScriptMazeNode.cpp +++ b/src/MetroidPrime/ScriptObjects/CScriptMazeNode.cpp @@ -256,27 +256,27 @@ CScriptMazeNode::CScriptMazeNode(TUniqueId uid, const rstl::string& name, const void CScriptMazeNode::Accept(IVisitor& visitor) { visitor.Visit(*this); } -static inline TUniqueId GenerateObject(CStateManager& mgr, const TEditorId& eid) { - bool wasGeneratingObject = mgr.IsGeneratingObject(); - mgr.SetIsGeneratingObject(true); - TUniqueId objUid = mgr.GenerateObject(eid).second; - mgr.SetIsGeneratingObject(wasGeneratingObject); - return objUid; -} +// static inline TUniqueId GenerateObject(CStateManager& mgr, const TEditorId& eid) { +// bool wasGeneratingObject = mgr.IsGeneratingObject(); +// mgr.SetIsGeneratingObject(true); +// TUniqueId objUid = mgr.GenerateObject(eid).second; +// mgr.SetIsGeneratingObject(wasGeneratingObject); +// return objUid; +// } // TODO non-matching // https://decomp.me/scratch/IvHBz void CScriptMazeNode::GenerateObjects(CStateManager& mgr) { - rstl::vector< SConnection >::const_iterator conn = GetConnectionList().begin(); - for (; conn != GetConnectionList().end(); ++conn) { + rstl::vector< SConnection >::iterator conn = ConnectionList().begin(); + for (; conn != ConnectionList().end(); ++conn) { if (conn->x0_state != kSS_MaxReached || conn->x4_msg != kSM_Activate) { continue; } - CEntity* ent = mgr.ObjectById(mgr.GetIdForScript(conn->x8_objId)); - CScriptEffect* scriptEffect = TCastToPtr< CScriptEffect >(ent); - CScriptActor* scriptActor = TCastToPtr< CScriptActor >(ent); - CScriptTrigger* scriptTrigger = TCastToPtr< CScriptTrigger >(ent); + const CEntity* ent = mgr.ObjectById(mgr.GetIdForScript(conn->x8_objId)); + const CScriptEffect* scriptEffect = TCastToConstPtr< CScriptEffect >(ent); + const CScriptActor* scriptActor = TCastToConstPtr< CScriptActor >(ent); + const CScriptTrigger* scriptTrigger = TCastToConstPtr< CScriptTrigger >(ent); if (!scriptEffect && !scriptActor && !scriptTrigger) { continue; } @@ -434,8 +434,8 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C } } CObjectList& list = mgr.GetObjectListById(kOL_All); - int objIdx = list.GetFirstObjectIndex(); - while (objIdx != -1) { + for (int objIdx = list.GetFirstObjectIndex(); objIdx != -1; + objIdx = list.GetNextObjectIndex(objIdx)) { if (CScriptMazeNode* node = TCastToPtr< CScriptMazeNode >(list[objIdx])) { if (node->xe8_col == xe8_col - 1 && node->xec_row == xec_row && node->xf0_side == CMazeState::kS_Right) { @@ -474,7 +474,6 @@ void CScriptMazeNode::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, C } } } - objIdx = list.GetNextObjectIndex(objIdx); } } } diff --git a/src/MetroidPrime/ScriptObjects/CScriptPlatform.cpp b/src/MetroidPrime/ScriptObjects/CScriptPlatform.cpp index 101fc844..fc623351 100644 --- a/src/MetroidPrime/ScriptObjects/CScriptPlatform.cpp +++ b/src/MetroidPrime/ScriptObjects/CScriptPlatform.cpp @@ -2,6 +2,8 @@ #include "MetroidPrime/CActorParameters.hpp" #include "MetroidPrime/CAnimData.hpp" +#include "MetroidPrime/CGameCollision.hpp" +#include "MetroidPrime/Player/CPlayer.hpp" #include "MetroidPrime/ScriptObjects/CScriptWaypoint.hpp" #include "Kyoto/Graphics/CGX.hpp" @@ -143,7 +145,8 @@ void CScriptPlatform::AddRider(rstl::vector< SRiders >& riders, TUniqueId riderI SRiders rider(riderId); if (CPhysicsActor* act = TCastToPtr< CPhysicsActor >(mgr.ObjectById(riderId))) { CVector3f rideePos = ridee->GetTranslation(); - rider.x8_transform.SetTranslation(ridee->GetTransform().TransposeRotate(act->GetTranslation() - rideePos)); + rider.x8_transform.SetTranslation( + ridee->GetTransform().TransposeRotate(act->GetTranslation() - rideePos)); mgr.SendScriptMsg(act, ridee->GetUniqueId(), kSM_AddPlatformRider); } riders.reserve(riders.size() + 1); @@ -152,3 +155,78 @@ void CScriptPlatform::AddRider(rstl::vector< SRiders >& riders, TUniqueId riderI it->x4_decayTimer = 1.f / 6.f; } } + +TEntityList CScriptPlatform::BuildNearListFromRiders(CStateManager& mgr, + const rstl::vector< SRiders >& riders) { + TEntityList result; + rstl::vector< SRiders >::const_iterator it = riders.begin(); + for (; it != riders.end(); ++it) { + if (CActor* actor = TCastToPtr< CActor >(mgr.ObjectById(it->x0_uid))) { + result.push_back(actor->GetUniqueId()); + } + } + return result; +} + +void CScriptPlatform::DecayRiders(rstl::vector< SRiders >& riders, f32 dt, CStateManager& mgr) { + rstl::vector< SRiders >::iterator it = riders.begin(); + while (it != riders.end()) { + it->x4_decayTimer -= dt; + if (it->x4_decayTimer <= 0.f) { + mgr.SendScriptMsgAlways(it->x0_uid, kInvalidUniqueId, kSM_AddPlatformRider); +#ifdef NON_MATCHING + it = riders.erase(it); +#else + // Oops, forgot to reassign the iterator + riders.erase(it); +#endif + } else { + it = it + 1; + } + } +} + +// TODO: minor regswap +void CScriptPlatform::MoveRiders(CStateManager& mgr, f32 dt, bool active, + rstl::vector< SRiders >& riders, + rstl::vector< SRiders >& collidedRiders, const CTransform4f& oldXf, + const CTransform4f& newXf, const CVector3f& dragDelta, + CQuaternion rotDelta) { + rstl::vector< SRiders >::iterator it = riders.begin(); + while (it != riders.end()) { + if (active) { + CPhysicsActor* act = TCastToPtr< CPhysicsActor >(mgr.ObjectById(it->x0_uid)); + if (act == nullptr || !act->GetActive()) { + ++it; + continue; + } + const CTransform4f& xf = it->x8_transform; + CVector3f diff = newXf.Rotate(xf.GetTranslation()) - oldXf.Rotate(xf.GetTranslation()); + diff.SetZ(0.f); + CVector3f delta = dragDelta + diff; + CVector3f newPos = act->GetTranslation() + delta; + act->MoveCollisionPrimitive(delta); + bool collision = CGameCollision::DetectStaticCollisionBoolean( + mgr, *act->GetCollisionPrimitive(), act->GetPrimitiveTransform(), + act->GetMaterialFilter()); + act->MoveCollisionPrimitive(CVector3f::Zero()); + if (collision) { + AddRider(collidedRiders, act->GetUniqueId(), act, mgr); +#ifdef NON_MATCHING + it = riders.erase(it); +#else + // Oops, forgot to reassign the iterator (again) + riders.erase(it); +#endif + continue; + } + act->SetTranslation(newPos); + const CPlayer* player = TCastToConstPtr< CPlayer >(*act); + if (player == nullptr || player->GetOrbitState() == CPlayer::kOS_NoOrbit) { + const CQuaternion& rot = rotDelta * CQuaternion::FromMatrix(act->GetTransform()); + act->SetTransform(rot.BuildTransform4f(act->GetTranslation())); + } + } + ++it; + } +} diff --git a/src/MetroidPrime/main.cpp b/src/MetroidPrime/main.cpp index bc19530c..d7beb543 100644 --- a/src/MetroidPrime/main.cpp +++ b/src/MetroidPrime/main.cpp @@ -149,7 +149,6 @@ CMain::CMain() CMain::~CMain() {} -#define ALIGN_UP(x, a) (((x) + (a - 1)) & ~(a - 1)) #define UNUSED_STACK_VAL 0x7337D00D void CMain::InitializeSubsystems() {