Add CPlayerGun::PreRender/CPlayerGun::AddToRenderer

Former-commit-id: 6d2ab5775d
This commit is contained in:
Henrique Gemignani Passos Lima 2022-10-06 14:37:57 +03:00
parent 4295307cbb
commit 758feb2c59
15 changed files with 142 additions and 6 deletions

View File

@ -61,11 +61,12 @@ Metaforce -> decomp
- `std::max` -> `rstl::max_val`
- `std::clamp` -> `CMath::Clamp` (depends on context)
### Converting Vector / Transforms
### Converting globals and getters
Metaforce -> decomp
- `zeus::CTransform::frontVector()` -> `CTransform4f::GetForward()`
- `zeus::skForward` -> `CVector3f::Forward`
- `g_Renderer` -> `gpRender`
### Class definitions & constructors

View File

@ -88,6 +88,9 @@ public:
virtual void SetWorldLightFadeLevel();
virtual void Something();
virtual void PrepareDynamicLights();
void AllocatePhazonSuitMaskTexture();
};
extern CCubeRenderer* gpRender;

View File

@ -22,10 +22,16 @@ public:
~CActorLights();
void BuildConstantAmbientLighting();
void BuildConstantAmbientLighting(const CColor&);
bool BuildAreaLightList(const CStateManager& mgr, const CGameArea& area, const CAABox& bounds);
void BuildDynamicLightList(const CStateManager& mgr, const CAABox& bounds);
bool GetNeedsRelight() const { return x298_24_dirty == TRUE; }
bool HasShadowLight() const { return x29c_shadowLightArrIdx != -1; }
s32 GetShadowLightIndex() const { return x2a0_shadowLightIdx; }
void SetFindShadowLight(bool v) { x298_27_findShadowLight = v; }
void SetShadowDynamicRangeThreshold(float t) { x2d0_shadowDynamicRangeThreshold = t; }
private:
rstl::reserved_vector< CLight, 4 > x0_areaLights;

View File

@ -120,6 +120,9 @@ public:
TUniqueId GetIdForScript(TEditorId eid) const;
TIdListResult GetIdListForScript(TEditorId) const;
TAreaId GetNextAreaId() const { return x8cc_nextAreaId; }
void SetCurrentAreaId(TAreaId);
CMazeState* CurrentMaze();
const CMazeState* GetCurrentMaze() const;
void SetCurrentMaze(rstl::single_ptr< CMazeState > maze);

View File

@ -24,6 +24,12 @@ class CWorldShadow {
public:
CWorldShadow(uint w, uint h, bool rgba8);
~CWorldShadow();
void EnableModelProjectedShadow(const CTransform4f& pos, uint lightIdx, float f1);
void DisableModelProjectedShadow();
void BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid, uint lightIdx, const CAABox& aabb,
bool motionBlur, bool lighten);
void ResetBlur();
};
CHECK_SIZEOF(CWorldShadow, 0x8c)

View File

@ -10,8 +10,19 @@ public:
CGrappleArm(const CVector3f& scale);
~CGrappleArm();
void PreRender(CStateManager& mgr, const CFrustumPlanes& frustum, const CVector3f& camPos);
bool GetActive() const { return x3b2_24_active; }
private:
u8 x0_pad[0x3b4];
u8 x0_pad[0x3b0];
s16 x3b0_rumbleHandle;
bool x3b2_24_active : 1;
bool x3b2_25_beamActive : 1;
bool x3b2_26_grappleHit : 1;
bool x3b2_27_armMoving : 1;
bool x3b2_28_isGrappling : 1;
bool x3b2_29_suitLoading : 1;
};
CHECK_SIZEOF(CGrappleArm, 0x3b4)

View File

@ -95,6 +95,9 @@ public:
CPlayerGun(TUniqueId);
~CPlayerGun();
void AddToRenderer(const CFrustumPlanes& frustum, const CStateManager& mgr) const;
void PreRender(CStateManager&, const CFrustumPlanes&, const CVector3f&);
void InitBeamData();
void InitBombData();
void InitMuzzleData();

View File

@ -5,6 +5,7 @@
#include "types.h"
#include "MetroidPrime/Player/CPlayerState.hpp"
#include "MetroidPrime/Weapons/WeaponCommon.hpp"
#include "MetroidPrime/Weapons/WeaponTypes.hpp"
#include "Kyoto/Math/CVector3f.hpp"
@ -59,6 +60,29 @@ public:
kFFT_Thawed,
};
// Virtual Methods
virtual void Reset(CStateManager& mgr);
virtual void PlayAnim(NWeaponTypes::EGunAnimType type, bool loop);
virtual void PreRenderGunFx(const CStateManager& mgr, const CTransform4f& xf);
virtual void PostRenderGunFx(const CStateManager& mgr, const CTransform4f& xf);
virtual void UpdateGunFx(bool shotSmoke, float dt, const CStateManager& mgr, const CTransform4f& xf);
virtual void Fire(bool underwater, float dt, EChargeState chargeState, const CTransform4f& xf, CStateManager& mgr,
TUniqueId homingTarget, float chargeFactor1, float chargeFactor2);
virtual void EnableFx(bool enable);
virtual void EnableSecondaryFx(ESecondaryFxType type);
virtual void Draw(bool drawSuitArm, const CStateManager& mgr, const CTransform4f& xf, const CModelFlags& flags,
const CActorLights* lights);
virtual void DrawMuzzleFx(const CStateManager& mgr) const;
virtual void Update(float dt, CStateManager& mgr);
virtual void Load(CStateManager& mgr, bool subtypeBasePose);
virtual void Unload(CStateManager& mgr);
virtual bool IsLoaded() const;
rstl::optional_object< CModelData >& SolidModelData() { return x10_solidModelData; }
CAABox GetBounds() const;
CAABox GetBounds(const CTransform4f& xf) const;
private:
// x0 is vtable
CVector3f x4_scale;

View File

@ -7,7 +7,7 @@ class CIceBeam : public CGunWeapon {
public:
CIceBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId,
EMaterialTypes playerMaterial, const CVector3f& scale);
~CIceBeam();
private:
u8 x21c_pad[0x30];
};

View File

@ -7,7 +7,7 @@ class CPhazonBeam : public CGunWeapon {
public:
CPhazonBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId,
EMaterialTypes playerMaterial, const CVector3f& scale);
~CPhazonBeam();
private:
u8 x21c_pad[0x60];
};

View File

@ -7,7 +7,7 @@ class CPlasmaBeam : public CGunWeapon {
public:
CPlasmaBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId,
EMaterialTypes playerMaterial, const CVector3f& scale);
~CPlasmaBeam();
private:
u8 x21c_pad[0x24];
};

View File

@ -7,6 +7,7 @@ class CPowerBeam : public CGunWeapon {
public:
CPowerBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId,
EMaterialTypes playerMaterial, const CVector3f& scale);
~CPowerBeam();
private:
u8 x21c_pad[0x2C];

View File

@ -7,7 +7,7 @@ class CWaveBeam : public CGunWeapon {
public:
CWaveBeam(CAssetId characterId, EWeaponType type, TUniqueId playerId,
EMaterialTypes playerMaterial, const CVector3f& scale);
~CWaveBeam();
private:
u8 x21c_pad[0x40];
};

View File

@ -0,0 +1,22 @@
#ifndef _WEAPONCOMMON_HPP
#define _WEAPONCOMMON_HPP
namespace NWeaponTypes {
enum EGunAnimType {
kGAT_BasePosition,
kGAT_Shoot,
kGAT_ChargeUp,
kGAT_ChargeLoop,
kGAT_ChargeShoot,
kGAT_FromMissile,
kGAT_ToMissile,
kGAT_MissileShoot,
kGAT_MissileReload,
kGAT_FromBeam,
kGAT_ToBeam
};
}
#endif _WEAPONCOMMON_HPP

View File

@ -1,8 +1,11 @@
#include "MetroidPrime/Player/CPlayerGun.hpp"
#include "MetroidPrime/CAnimData.hpp"
#include "MetroidPrime/CAnimRes.hpp"
#include "MetroidPrime/CRainSplashGenerator.hpp"
#include "MetroidPrime/CWorldShadow.hpp"
#include "MetroidPrime/CStateManager.hpp"
#include "MetroidPrime/CWorld.hpp"
#include "MetroidPrime/Player/CGrappleArm.hpp"
#include "MetroidPrime/Tweaks/CTweakGunRes.hpp"
#include "MetroidPrime/Tweaks/CTweakPlayerGun.hpp"
@ -15,12 +18,15 @@
#include "MetroidPrime/Weapons/GunController/CGunMotion.hpp"
#include "MetroidPrime/Weapons/WeaponTypes.hpp"
#include "Kyoto/Math/CMath.hpp"
#include "Kyoto/Graphics/CModelFlags.hpp"
#include "Kyoto/Particles/CElementGen.hpp"
#include "Collision/CMaterialFilter.hpp"
#include "Collision/CMaterialList.hpp"
#include "MetaRender/CCubeRenderer.hpp"
static float kVerticalAngleTable[3] = {-30.f, 0.f, 30.f};
static float kHorizontalAngleTable[3] = {30.f, 30.f, 30.f};
static float kVerticalVarianceTable[3] = {30.f, 30.f, 30.f};
@ -275,3 +281,53 @@ CPlayerGun::CPlayerGun(TUniqueId playerId)
}
CPlayerGun::~CPlayerGun() {}
void CPlayerGun::AddToRenderer(const CFrustumPlanes& frustum, const CStateManager&) const {
rstl::optional_object< CModelData >& model = x72c_currentBeam->SolidModelData();
if (model)
model->RenderParticles(frustum);
}
void CPlayerGun::PreRender(CStateManager& mgr, const CFrustumPlanes& frustum, const CVector3f& camPos) {
const CPlayerState& playerState = *mgr.GetPlayerState();
if (playerState.GetCurrentVisor() == CPlayerState::kPV_Scan)
return;
CPlayerState::EPlayerVisor activeVisor = playerState.GetActiveVisor(mgr);
switch (activeVisor) {
case CPlayerState::kPV_Thermal:
float rgb = CMath::Clamp(0.6f, 0.5f * x380_shotSmokeTimer + 0.6f - x378_shotSmokeStartTimer, 1.f);
x0_lights.BuildConstantAmbientLighting(CColor(rgb, rgb, rgb, 1.f));
break;
case CPlayerState::kPV_Combat: {
CAABox aabb = x72c_currentBeam->GetBounds(CTransform4f::Translate(camPos) * x4a8_gunWorldXf);
if (mgr.GetNextAreaId() != kInvalidAreaId) {
x0_lights.SetFindShadowLight(true);
x0_lights.SetShadowDynamicRangeThreshold(0.25f);
x0_lights.BuildAreaLightList(mgr, mgr.GetWorld()->GetAreaAlways(mgr.GetNextAreaId()), aabb);
}
x0_lights.BuildDynamicLightList(mgr, aabb);
if (x0_lights.HasShadowLight()) {
if (x72c_currentBeam->IsLoaded()) {
x82c_shadow->BuildLightShadowTexture(mgr, mgr.GetNextAreaId(), x0_lights.GetShadowLightIndex(), aabb, true,
false);
}
} else {
x82c_shadow->ResetBlur();
}
break;
}
default:
break;
}
if (x740_grappleArm->GetActive())
x740_grappleArm->PreRender(mgr, frustum, camPos);
if (x678_morph.GetGunState() != CGunMorph::kGS_OutWipeDone || activeVisor == CPlayerState::kPV_XRay)
x6e0_rightHandModel.AnimationData()->PreRender();
if (x833_28_phazonBeamActive)
gpRender->AllocatePhazonSuitMaskTexture();
}