From 45e9cdeb71989d9fe6efd0bbbb4e30379c9a8415 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Thu, 24 Nov 2022 18:29:09 +0200 Subject: [PATCH] Add CBeamProjectile Former-commit-id: 7de5f08127bc4bd43f03a466bc93f957fc89e1cb --- asm/MetroidPrime/CGameProjectile.s | 4 +- asm/MetroidPrime/Weapons/CBeamProjectile.s | 24 ++-- asm/MetroidPrime/Weapons/CEnergyProjectile.s | 2 +- asm/MetroidPrime/Weapons/CFlameThrower.s | 2 +- asm/MetroidPrime/Weapons/CNewFlameThrower.s | 2 +- asm/MetroidPrime/Weapons/CPlasmaProjectile.s | 4 +- asm/MetroidPrime/Weapons/CWaveBuster.s | 2 +- configure.py | 2 +- .../MetroidPrime/Weapons/CBeamProjectile.hpp | 13 +- .../MetroidPrime/Weapons/CGameProjectile.hpp | 13 +- include/MetroidPrime/Weapons/CWeapon.hpp | 1 + libc/math.h | 11 +- src/MetroidPrime/Weapons/CBeamProjectile.cpp | 116 ++++++++++++++++++ 13 files changed, 168 insertions(+), 28 deletions(-) create mode 100644 src/MetroidPrime/Weapons/CBeamProjectile.cpp diff --git a/asm/MetroidPrime/CGameProjectile.s b/asm/MetroidPrime/CGameProjectile.s index 9caff5ee..a8d93c5f 100644 --- a/asm/MetroidPrime/CGameProjectile.s +++ b/asm/MetroidPrime/CGameProjectile.s @@ -3516,8 +3516,8 @@ Render__15CGameProjectileCFRC13CStateManager: /* 8003A47C 000373DC 38 21 00 10 */ addi r1, r1, 0x10 /* 8003A480 000373E0 4E 80 00 20 */ blr -.global "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>sb" -"__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>sb": +.global "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>Usb" +"__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>Usb": /* 8003A484 000373E4 94 21 FE D0 */ stwu r1, -0x130(r1) /* 8003A488 000373E8 7C 08 02 A6 */ mflr r0 /* 8003A48C 000373EC 90 01 01 34 */ stw r0, 0x134(r1) diff --git a/asm/MetroidPrime/Weapons/CBeamProjectile.s b/asm/MetroidPrime/Weapons/CBeamProjectile.s index 4c1affdf..53bd706d 100644 --- a/asm/MetroidPrime/Weapons/CBeamProjectile.s +++ b/asm/MetroidPrime/Weapons/CBeamProjectile.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E4648 -lbl_803E4648: +.global __vt__15CBeamProjectile +__vt__15CBeamProjectile: # ROM: 0x3E1648 .4byte 0 .4byte 0 @@ -23,7 +23,7 @@ lbl_803E4648: .4byte GetDamageVulnerability__6CActorCFv .4byte GetDamageVulnerability__6CActorCFRC9CVector3fRC9CVector3fRC11CDamageInfo .4byte GetTouchBounds__15CBeamProjectileCFv - .4byte nullsub_142 + .4byte Touch__15CBeamProjectileFR6CActorR13CStateManager .4byte GetOrbitPosition__6CActorCFRC13CStateManager .4byte GetAimPosition__6CActorCFRC13CStateManagerf .4byte GetHomingPosition__6CActorCFRC13CStateManagerf @@ -263,7 +263,7 @@ lbl_80198E8C: /* 80199118 00196078 38 C1 00 14 */ addi r6, r1, 0x14 /* 8019911C 0019607C B0 01 00 14 */ sth r0, 0x14(r1) /* 80199120 00196080 38 80 00 01 */ li r4, 1 -/* 80199124 00196084 48 00 01 9D */ bl SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeRC14CRayCastResult +/* 80199124 00196084 48 00 01 9D */ bl SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeR14CRayCastResult9TUniqueId /* 80199128 00196088 88 1C 04 64 */ lbz r0, 0x464(r28) /* 8019912C 0019608C 54 00 D7 FF */ rlwinm. r0, r0, 0x1a, 0x1f, 0x1f /* 80199130 00196090 41 82 01 08 */ beq lbl_80199238 @@ -286,7 +286,7 @@ lbl_80199158: /* 80199170 001960D0 38 C1 00 10 */ addi r6, r1, 0x10 /* 80199174 001960D4 B0 01 00 10 */ sth r0, 0x10(r1) /* 80199178 001960D8 38 80 00 02 */ li r4, 2 -/* 8019917C 001960DC 48 00 01 45 */ bl SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeRC14CRayCastResult +/* 8019917C 001960DC 48 00 01 45 */ bl SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeR14CRayCastResult9TUniqueId /* 80199180 001960E0 88 1C 04 64 */ lbz r0, 0x464(r28) /* 80199184 001960E4 54 00 D7 FF */ rlwinm. r0, r0, 0x1a, 0x1f, 0x1f /* 80199188 001960E8 41 82 00 B0 */ beq lbl_80199238 @@ -375,8 +375,8 @@ lbl_80199298: /* 801992B8 00196218 38 21 09 F0 */ addi r1, r1, 0x9f0 /* 801992BC 0019621C 4E 80 00 20 */ blr -.global SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeRC14CRayCastResult -SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeRC14CRayCastResult: +.global SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeR14CRayCastResult9TUniqueId +SetCollisionResultData__15CBeamProjectileFQ215CBeamProjectile11EDamageTypeR14CRayCastResult9TUniqueId: /* 801992C0 00196220 94 21 FF F0 */ stwu r1, -0x10(r1) /* 801992C4 00196224 7C 08 02 A6 */ mflr r0 /* 801992C8 00196228 2C 04 00 01 */ cmpwi r4, 1 @@ -419,8 +419,8 @@ ResetBeam__15CBeamProjectileFR13CStateManagerb: /* 80199348 001962A8 D0 03 03 00 */ stfs f0, 0x300(r3) /* 8019934C 001962AC 4E 80 00 20 */ blr -.global nullsub_142 -nullsub_142: +.global Touch__15CBeamProjectileFR6CActorR13CStateManager +Touch__15CBeamProjectileFR6CActorR13CStateManager: /* 80199350 001962B0 4E 80 00 20 */ blr .global Accept__15CBeamProjectileFR8IVisitor @@ -571,7 +571,7 @@ lbl_80199484: /* 80199560 001964C0 93 01 00 24 */ stw r24, 0x24(r1) /* 80199564 001964C4 93 21 00 28 */ stw r25, 0x28(r1) /* 80199568 001964C8 90 01 00 2C */ stw r0, 0x2c(r1) -/* 8019956C 001964CC 4B EA 0F 19 */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>sb" +/* 8019956C 001964CC 4B EA 0F 19 */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>Usb" /* 80199570 001964D0 88 01 00 4C */ lbz r0, 0x4c(r1) /* 80199574 001964D4 28 00 00 00 */ cmplwi r0, 0 /* 80199578 001964D8 41 82 00 1C */ beq lbl_80199594 @@ -583,9 +583,9 @@ lbl_80199484: /* 80199590 001964F0 48 1A 78 B1 */ bl __dt__6CTokenFv lbl_80199594: /* 80199594 001964F4 38 00 00 00 */ li r0, 0 -/* 80199598 001964F8 3C 60 80 3E */ lis r3, lbl_803E4648@ha +/* 80199598 001964F8 3C 60 80 3E */ lis r3, __vt__15CBeamProjectile@ha /* 8019959C 001964FC 98 01 00 4C */ stb r0, 0x4c(r1) -/* 801995A0 00196500 38 03 46 48 */ addi r0, r3, lbl_803E4648@l +/* 801995A0 00196500 38 03 46 48 */ addi r0, r3, __vt__15CBeamProjectile@l /* 801995A4 00196504 7F C3 F3 78 */ mr r3, r30 /* 801995A8 00196508 90 1A 00 00 */ stw r0, 0(r26) /* 801995AC 0019650C 48 1F 38 71 */ bl abs diff --git a/asm/MetroidPrime/Weapons/CEnergyProjectile.s b/asm/MetroidPrime/Weapons/CEnergyProjectile.s index 3c2db626..f0fef93b 100644 --- a/asm/MetroidPrime/Weapons/CEnergyProjectile.s +++ b/asm/MetroidPrime/Weapons/CEnergyProjectile.s @@ -2007,7 +2007,7 @@ lbl_80215680: /* 8021576C 002126CC 93 C1 00 24 */ stw r30, 0x24(r1) /* 80215770 002126D0 93 E1 00 28 */ stw r31, 0x28(r1) /* 80215774 002126D4 91 E1 00 2C */ stw r15, 0x2c(r1) -/* 80215778 002126D8 4B E2 4D 0D */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>sb" +/* 80215778 002126D8 4B E2 4D 0D */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>Usb" /* 8021577C 002126DC 38 61 00 40 */ addi r3, r1, 0x40 /* 80215780 002126E0 48 12 83 61 */ bl "internal_dereference__Q24rstl66basic_string,Q24rstl17rmemory_allocator>Fv" /* 80215784 002126E4 3C 60 80 3E */ lis r3, __vt__17CEnergyProjectile@ha diff --git a/asm/MetroidPrime/Weapons/CFlameThrower.s b/asm/MetroidPrime/Weapons/CFlameThrower.s index 649b8166..01bde36c 100644 --- a/asm/MetroidPrime/Weapons/CFlameThrower.s +++ b/asm/MetroidPrime/Weapons/CFlameThrower.s @@ -1639,7 +1639,7 @@ lbl_80198AE8: /* 80198BB0 00195B10 91 61 00 24 */ stw r11, 0x24(r1) /* 80198BB4 00195B14 90 01 00 28 */ stw r0, 0x28(r1) /* 80198BB8 00195B18 92 A1 00 2C */ stw r21, 0x2c(r1) -/* 80198BBC 00195B1C 4B EA 18 C9 */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>sb" +/* 80198BBC 00195B1C 4B EA 18 C9 */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>Usb" /* 80198BC0 00195B20 88 01 00 70 */ lbz r0, 0x70(r1) /* 80198BC4 00195B24 28 00 00 00 */ cmplwi r0, 0 /* 80198BC8 00195B28 41 82 00 1C */ beq lbl_80198BE4 diff --git a/asm/MetroidPrime/Weapons/CNewFlameThrower.s b/asm/MetroidPrime/Weapons/CNewFlameThrower.s index 9eec7a76..3abe8e26 100644 --- a/asm/MetroidPrime/Weapons/CNewFlameThrower.s +++ b/asm/MetroidPrime/Weapons/CNewFlameThrower.s @@ -3798,7 +3798,7 @@ GetTouchBounds__16CNewFlameThrowerCFv: /* 802644D4 00261434 91 61 00 24 */ stw r11, 0x24(r1) /* 802644D8 00261438 90 01 00 28 */ stw r0, 0x28(r1) /* 802644DC 0026143C 93 01 00 2C */ stw r24, 0x2c(r1) -/* 802644E0 00261440 4B DD 5F A5 */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>sb" +/* 802644E0 00261440 4B DD 5F A5 */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>Usb" /* 802644E4 00261444 88 01 00 DC */ lbz r0, 0xdc(r1) /* 802644E8 00261448 28 00 00 00 */ cmplwi r0, 0 /* 802644EC 0026144C 41 82 00 1C */ beq lbl_80264508 diff --git a/asm/MetroidPrime/Weapons/CPlasmaProjectile.s b/asm/MetroidPrime/Weapons/CPlasmaProjectile.s index adc0407c..0e4a69e2 100644 --- a/asm/MetroidPrime/Weapons/CPlasmaProjectile.s +++ b/asm/MetroidPrime/Weapons/CPlasmaProjectile.s @@ -203,9 +203,9 @@ __dt__15CBeamProjectileFv: /* 80176D2C 00173C8C 93 C1 00 08 */ stw r30, 8(r1) /* 80176D30 00173C90 7C 9E 23 78 */ mr r30, r4 /* 80176D34 00173C94 41 82 00 E4 */ beq lbl_80176E18 -/* 80176D38 00173C98 3C 60 80 3E */ lis r3, lbl_803E4648@ha +/* 80176D38 00173C98 3C 60 80 3E */ lis r3, __vt__15CBeamProjectile@ha /* 80176D3C 00173C9C 34 1F 04 00 */ addic. r0, r31, 0x400 -/* 80176D40 00173CA0 38 03 46 48 */ addi r0, r3, lbl_803E4648@l +/* 80176D40 00173CA0 38 03 46 48 */ addi r0, r3, __vt__15CBeamProjectile@l /* 80176D44 00173CA4 90 1F 00 00 */ stw r0, 0(r31) /* 80176D48 00173CA8 41 82 00 58 */ beq lbl_80176DA0 /* 80176D4C 00173CAC 80 BF 04 00 */ lwz r5, 0x400(r31) diff --git a/asm/MetroidPrime/Weapons/CWaveBuster.s b/asm/MetroidPrime/Weapons/CWaveBuster.s index 4ca729ff..de159055 100644 --- a/asm/MetroidPrime/Weapons/CWaveBuster.s +++ b/asm/MetroidPrime/Weapons/CWaveBuster.s @@ -3040,7 +3040,7 @@ sub_801c0144: /* 801C025C 001BD1BC 91 81 00 24 */ stw r12, 0x24(r1) /* 801C0260 001BD1C0 91 61 00 28 */ stw r11, 0x28(r1) /* 801C0264 001BD1C4 90 01 00 2C */ stw r0, 0x2c(r1) -/* 801C0268 001BD1C8 4B E7 A2 1D */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>sb" +/* 801C0268 001BD1C8 4B E7 A2 1D */ bl "__ct__15CGameProjectileFbRC28TToken<18CWeaponDescription>RCQ24rstl66basic_string,Q24rstl17rmemory_allocator>11EWeaponTypeRC12CTransform4f14EMaterialTypesRC11CDamageInfo9TUniqueId7TAreaId9TUniqueId9TUniqueIdUibRC9CVector3fRCQ24rstl50optional_object<31TLockedToken<15CGenDescription>>Usb" /* 801C026C 001BD1CC 88 01 00 A4 */ lbz r0, 0xa4(r1) /* 801C0270 001BD1D0 28 00 00 00 */ cmplwi r0, 0 /* 801C0274 001BD1D4 41 82 00 1C */ beq lbl_801C0290 diff --git a/configure.py b/configure.py index 50e1175d..e4a63c34 100755 --- a/configure.py +++ b/configure.py @@ -252,7 +252,7 @@ LIBS = [ ["MetroidPrime/ScriptObjects/CScriptEMPulse", False], "MetroidPrime/HUD/CHudDecoInterface", "MetroidPrime/Weapons/CFlameThrower", - "MetroidPrime/Weapons/CBeamProjectile", + ["MetroidPrime/Weapons/CBeamProjectile", False], "MetroidPrime/CFluidPlaneCPU", "MetroidPrime/CFluidPlaneDoor", ["MetroidPrime/ScriptObjects/CScriptRoomAcoustics", True], diff --git a/include/MetroidPrime/Weapons/CBeamProjectile.hpp b/include/MetroidPrime/Weapons/CBeamProjectile.hpp index 943c8e11..23374a6a 100644 --- a/include/MetroidPrime/Weapons/CBeamProjectile.hpp +++ b/include/MetroidPrime/Weapons/CBeamProjectile.hpp @@ -19,8 +19,17 @@ public: const CTransform4f& xf, int maxLength, float beamRadius, float travelSpeed, EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, TUniqueId owner, EProjectileAttrib attribs, bool growingBeam); - ~CBeamProjectile() override; + // CEntity + ~CBeamProjectile() override; + void Accept(IVisitor& visitor) override; + + // CActor + rstl::optional_object GetTouchBounds() const override; + void Touch(CActor&, CStateManager&) override; + void CalculateRenderBounds() override; + + // CBeamProjectile virtual void UpdateFx(const CTransform4f&, float, CStateManager&); virtual void ResetBeam(CStateManager&, bool); virtual void Fire(const CTransform4f&, CStateManager&, bool) = 0; @@ -51,6 +60,8 @@ private: rstl::reserved_vector< CVector3f, 8 > x400_pointCache; bool x464_24_growingBeam : 1; bool x464_25_enableTouchDamage : 1; + + void SetCollisionResultData(EDamageType dType, CRayCastResult& res, TUniqueId id); }; CHECK_SIZEOF(CBeamProjectile, 0x468) diff --git a/include/MetroidPrime/Weapons/CGameProjectile.hpp b/include/MetroidPrime/Weapons/CGameProjectile.hpp index 6c19a0a7..180e1e42 100644 --- a/include/MetroidPrime/Weapons/CGameProjectile.hpp +++ b/include/MetroidPrime/Weapons/CGameProjectile.hpp @@ -3,6 +3,7 @@ #include "types.h" +#include "MetroidPrime/CStateManager.hpp" #include "MetroidPrime/Weapons/CProjectileWeapon.hpp" #include "MetroidPrime/Weapons/CWeapon.hpp" @@ -16,7 +17,13 @@ class CProjectileTouchResult; class CGameProjectile : public CWeapon { public: - // TODO ctor + CGameProjectile(bool active, const TToken< CWeaponDescription >&, const rstl::string& name, + EWeaponType wType, const CTransform4f& xf, EMaterialTypes excludeMat, + const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, TUniqueId owner, + TUniqueId homingTarget, uint attribs, bool underwater, + const CVector3f& scale, + const rstl::optional_object< TLockedToken< CGenDescription > >& visorParticle, + ushort visorSfx, bool sendCollideMsg); // CEntity ~CGameProjectile() override; @@ -41,6 +48,10 @@ public: bool GetWeaponActive() const { return x2e4_24_active; } void DeleteProjectileLight(CStateManager&); + void ApplyDamageToActors(CStateManager& mgr, const CDamageInfo& dInfo); + CRayCastResult RayCollisionCheckWithWorld(TUniqueId& idOut, const CVector3f& start, const CVector3f& end, + float mag, const TEntityList& nearList, CStateManager& mgr); + protected: rstl::optional_object< TLockedToken< CGenDescription > > x158_visorParticle; ushort x168_visorSfx; diff --git a/include/MetroidPrime/Weapons/CWeapon.hpp b/include/MetroidPrime/Weapons/CWeapon.hpp index 01341ec1..4281de7d 100644 --- a/include/MetroidPrime/Weapons/CWeapon.hpp +++ b/include/MetroidPrime/Weapons/CWeapon.hpp @@ -30,6 +30,7 @@ public: EProjectileAttrib GetAttribField() const { return xe8_projectileAttribs; } TUniqueId GetOwnerId() const { return xec_ownerId; } EWeaponType GetWeaponType() const { return xf0_weaponType; } + CMaterialFilter GetFilter() const { return xf8_filter; } CDamageInfo& OrigDamageInfo() { return x110_origDamageInfo; } protected: diff --git a/libc/math.h b/libc/math.h index b56dde1c..b75eb4fb 100644 --- a/libc/math.h +++ b/libc/math.h @@ -43,15 +43,16 @@ typedef int _INT32; typedef unsigned int _UINT32; #endif +int abs(int n); #ifdef __MWERKS__ -#define abs(n) __abs(n) +// #define abs(n) __abs(n) #define labs(n) __labs(n) static inline double fabs(double x) { return __fabs(x); } #else -static inline int abs(int n) { - int mask = n >> 31; - return (n + mask) ^ mask; -} +// static inline int abs(int n) { +// int mask = n >> 31; +// return (n + mask) ^ mask; +// } #endif extern _INT32 __float_huge[]; diff --git a/src/MetroidPrime/Weapons/CBeamProjectile.cpp b/src/MetroidPrime/Weapons/CBeamProjectile.cpp new file mode 100644 index 00000000..ca4dd1f9 --- /dev/null +++ b/src/MetroidPrime/Weapons/CBeamProjectile.cpp @@ -0,0 +1,116 @@ +#include "MetroidPrime/Weapons/CBeamProjectile.hpp" + +#include "Collision/CRayCastResult.hpp" +#include "Kyoto/Audio/CSfxManager.hpp" + +CBeamProjectile::CBeamProjectile(const TToken< CWeaponDescription >& wDesc, + const rstl::string& name, EWeaponType wType, + const CTransform4f& xf, int maxLength, float beamRadius, + float travelSpeed, EMaterialTypes matType, + const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, + TUniqueId owner, EProjectileAttrib attribs, bool growingBeam) +: CGameProjectile(false, wDesc, name, wType, xf, matType, dInfo, uid, aid, owner, kInvalidUniqueId, + attribs, false, CVector3f(1.f, 1.f, 1.f), rstl::optional_object_null(), + CSfxManager::kInternalInvalidSfxId, false) +, x2e8_intMaxLength(CMath::AbsI(maxLength)) +, x2ec_maxLength(x2e8_intMaxLength) +, x2f0_invMaxLength(1.f / x2ec_maxLength) +, x2f4_beamRadius(beamRadius) +, x2f8_damageType(kDT_None) +, x2fc_(kInvalidUniqueId) +, x2fe_collisionActorId(kInvalidUniqueId) +, x300_intBeamLength(growingBeam ? 0.f : x2ec_maxLength) +, x304_beamLength(x2ec_maxLength) +, x308_travelSpeed(travelSpeed) +, x30c_collisionNormal(CVector3f::Up()) +, x318_collisionPoint(CVector3f::Zero()) +, x324_xf(CTransform4f::Identity()) +, x354_(CAABox::Identity()) +, x36c_(CAABox::Identity()) +, x384_(CVector3f::Zero()) +, x400_pointCache(CVector3f::Zero()) +, x464_24_growingBeam(growingBeam) +, x464_25_enableTouchDamage(false) {} + +rstl::optional_object< CAABox > CBeamProjectile::GetTouchBounds() const { + if (!GetActive() || !x464_25_enableTouchDamage) { + return rstl::optional_object_null(); + } + const CVector3f pos = GetTranslation(); + return CAABox(pos.GetX() - 0.1f, pos.GetY() - 0.1f, pos.GetZ() - 0.1f, pos.GetX() + 0.1f, + pos.GetY() + 0.1f, pos.GetZ() + 0.1f); +} + +void CBeamProjectile::CalculateRenderBounds() { + SetRenderBounds(x354_.GetTransformedAABox(x324_xf)); +} + +void CBeamProjectile::Accept(IVisitor& visitor) { visitor.Visit(*this); } + +void CBeamProjectile::Touch(CActor&, CStateManager&) {} + +void CBeamProjectile::ResetBeam(CStateManager&, bool) { + if (x464_24_growingBeam) + x300_intBeamLength = 0.f; +} + + +void CBeamProjectile::SetCollisionResultData(EDamageType dType, CRayCastResult& res, TUniqueId id) { + x2f8_damageType = dType; + x304_beamLength = res.GetTime(); + x318_collisionPoint = res.GetPoint(); + x30c_collisionNormal = res.GetPlane().GetNormal(); + x2fe_collisionActorId = dType == kDT_Actor ? id : kInvalidUniqueId; + SetTranslation(res.GetPoint()); +} + +void CBeamProjectile::UpdateFx(const CTransform4f& xf, float dt, CStateManager& mgr) { + if (!GetActive()) + return; + + SetTransform(xf.GetRotation()); + if (x464_24_growingBeam) { + x300_intBeamLength += x308_travelSpeed * dt; + if (x300_intBeamLength > x2ec_maxLength) + x300_intBeamLength = x2ec_maxLength; + } + x304_beamLength = x300_intBeamLength; + x2f8_damageType = kDT_None; + CVector3f beamEnd = xf.GetColumn(kDY).AsNormalized() * x300_intBeamLength + xf.GetTranslation(); + x298_previousPos = xf.GetTranslation(); + SetTranslation(beamEnd); + + x354_ = CAABox(-x2f4_beamRadius, 0.f, -x2f4_beamRadius, x2f4_beamRadius, x304_beamLength, + x2f4_beamRadius); + + x36c_ = CAABox(CVector3f(-x2f4_beamRadius, 0.f, -x2f4_beamRadius), + CVector3f(x2f4_beamRadius, x300_intBeamLength, x2f4_beamRadius)) + .GetTransformedAABox(xf); + + TUniqueId collideId = kInvalidUniqueId; + TEntityList nearList; + mgr.BuildNearList(nearList, x36c_, + CMaterialFilter::MakeExclude(CMaterialList(kMT_ProjectilePassthrough)), + this); + + CRayCastResult res = RayCollisionCheckWithWorld(collideId, x298_previousPos, beamEnd, + x300_intBeamLength, nearList, mgr); + + if (TCastToConstPtr< CActor >(mgr.ObjectById(collideId))) { + SetCollisionResultData(kDT_Actor, res, collideId); + if (x464_25_enableTouchDamage) + ApplyDamageToActors(mgr, CDamageInfo(x12c_curDamageInfo, dt)); + + } else if (res.IsValid()) { + SetCollisionResultData(kDT_World, res, kInvalidUniqueId); + if (x464_25_enableTouchDamage) { + CMaterialFilter filter(GetFilter()); + CDamageInfo dmg(x12c_curDamageInfo, dt); + mgr.ApplyDamageToWorld(GetOwnerId(), *this, res.GetPoint(), dmg, filter); + } + } else { + x318_collisionPoint = xf * CVector3f(x2f4_beamRadius, x304_beamLength, x2f4_beamRadius); + SetTranslation(x318_collisionPoint); + } + x324_xf = xf; +}