mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-15 06:46:08 +00:00
CFluidPlane: Make use of std::array where applicable
Makes all the arrays strongly typed. We can also use type aliases to greatly shorten some type definitions.
This commit is contained in:
@@ -110,14 +110,15 @@ void CFluidPlaneCPU::CalculateLightmapMatrix(const zeus::CTransform& areaXf, con
|
||||
}
|
||||
|
||||
static bool sSineWaveInitialized = false;
|
||||
static float sGlobalSineWave[256] = {};
|
||||
static const float* InitializeSineWave() {
|
||||
if (sSineWaveInitialized)
|
||||
return sGlobalSineWave;
|
||||
for (int i = 0; i < 256; ++i)
|
||||
sGlobalSineWave[i] = std::sin(2.f * M_PIF * (i / 256.f));
|
||||
static CFluidPlaneCPU::SineTable sGlobalSineWave{};
|
||||
static void InitializeSineWave() {
|
||||
if (sSineWaveInitialized) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < sGlobalSineWave.size(); ++i) {
|
||||
sGlobalSineWave[i] = std::sin(2.f * M_PIF * (float(i) / 256.f));
|
||||
}
|
||||
sSineWaveInitialized = true;
|
||||
return sGlobalSineWave;
|
||||
}
|
||||
|
||||
#define kEnableWaterBumpMaps true
|
||||
@@ -303,8 +304,7 @@ bool CFluidPlaneCPU::PrepareRipple(const CRipple& ripple, const CFluidPlaneRende
|
||||
return !(rippleOut.x14_gfromX > rippleOut.x18_gtoX || rippleOut.x1c_gfromY > rippleOut.x20_gtoY);
|
||||
}
|
||||
|
||||
void CFluidPlaneCPU::ApplyTurbulence(float t, CFluidPlaneRender::SHFieldSample (&heights)[46][46],
|
||||
const u8 (&flags)[9][9], const float sineWave[256],
|
||||
void CFluidPlaneCPU::ApplyTurbulence(float t, Heights& heights, const Flags& flags, const SineTable& sineWave,
|
||||
const CFluidPlaneRender::SPatchInfo& info,
|
||||
const zeus::CVector3f& areaCenter) const {
|
||||
if (!HasTurbulence()) {
|
||||
@@ -334,9 +334,8 @@ void CFluidPlaneCPU::ApplyTurbulence(float t, CFluidPlaneRender::SHFieldSample (
|
||||
}
|
||||
}
|
||||
|
||||
void CFluidPlaneCPU::ApplyRipple(const CFluidPlaneRender::SRippleInfo& rippleInfo,
|
||||
CFluidPlaneRender::SHFieldSample (&heights)[46][46], u8 (&flags)[9][9],
|
||||
const float sineWave[256], const CFluidPlaneRender::SPatchInfo& info) const {
|
||||
void CFluidPlaneCPU::ApplyRipple(const CFluidPlaneRender::SRippleInfo& rippleInfo, Heights& heights, Flags& flags,
|
||||
const SineTable& sineWave, const CFluidPlaneRender::SPatchInfo& info) const {
|
||||
float lookupT = 256.f *
|
||||
(1.f - rippleInfo.x0_ripple.GetTime() * rippleInfo.x0_ripple.GetOOTimeFalloff() *
|
||||
rippleInfo.x0_ripple.GetOOTimeFalloff()) *
|
||||
@@ -409,8 +408,9 @@ void CFluidPlaneCPU::ApplyRipple(const CFluidPlaneRender::SRippleInfo& rippleInf
|
||||
|
||||
float divDist = (divDistSq != 0.f) ? std::sqrt(divDistSq) : 0.f;
|
||||
if (u8 rippleV = CFluidPlaneManager::RippleValues[lifeIdx][int(divDist * distFalloff)]) {
|
||||
heights[k][l].height += rippleV * rippleInfo.x0_ripple.GetLookupAmplitude() *
|
||||
sineWave[int(divDist * rippleInfo.x0_ripple.GetLookupPhase() + lookupT) & 0xff];
|
||||
heights[k][l].height +=
|
||||
rippleV * rippleInfo.x0_ripple.GetLookupAmplitude() *
|
||||
sineWave[size_t(divDist * rippleInfo.x0_ripple.GetLookupPhase() + lookupT) & 0xff];
|
||||
} else {
|
||||
heights[k][l].height += 0.f;
|
||||
}
|
||||
@@ -460,8 +460,9 @@ void CFluidPlaneCPU::ApplyRipple(const CFluidPlaneRender::SRippleInfo& rippleInf
|
||||
|
||||
float divDist = (divDistSq != 0.f) ? std::sqrt(divDistSq) : 0.f;
|
||||
if (u8 rippleV = CFluidPlaneManager::RippleValues[lifeIdx][int(divDist * distFalloff)]) {
|
||||
heights[k][l].height += rippleV * rippleInfo.x0_ripple.GetLookupAmplitude() *
|
||||
sineWave[int(divDist * rippleInfo.x0_ripple.GetLookupPhase() + lookupT) & 0xff];
|
||||
heights[k][l].height +=
|
||||
rippleV * rippleInfo.x0_ripple.GetLookupAmplitude() *
|
||||
sineWave[size_t(divDist * rippleInfo.x0_ripple.GetLookupPhase() + lookupT) & 0xff];
|
||||
} else {
|
||||
heights[k][l].height += 0.f;
|
||||
}
|
||||
@@ -485,8 +486,8 @@ void CFluidPlaneCPU::ApplyRipple(const CFluidPlaneRender::SRippleInfo& rippleInf
|
||||
}
|
||||
|
||||
void CFluidPlaneCPU::ApplyRipples(const rstl::reserved_vector<CFluidPlaneRender::SRippleInfo, 32>& rippleInfos,
|
||||
CFluidPlaneRender::SHFieldSample (&heights)[46][46], u8 (&flags)[9][9],
|
||||
const float sineWave[256], const CFluidPlaneRender::SPatchInfo& info) const {
|
||||
Heights& heights, Flags& flags, const SineTable& sineWave,
|
||||
const CFluidPlaneRender::SPatchInfo& info) const {
|
||||
for (const CFluidPlaneRender::SRippleInfo& rippleInfo : rippleInfos)
|
||||
ApplyRipple(rippleInfo, heights, flags, sineWave, info);
|
||||
for (int i = 0; i < CFluidPlaneRender::numTilesInHField; ++i)
|
||||
@@ -499,7 +500,7 @@ void CFluidPlaneCPU::ApplyRipples(const rstl::reserved_vector<CFluidPlaneRender:
|
||||
flags[CFluidPlaneRender::numTilesInHField + 1][i + 1] |= 2;
|
||||
}
|
||||
|
||||
void CFluidPlaneCPU::UpdatePatchNoNormals(CFluidPlaneRender::SHFieldSample (&heights)[46][46], const u8 (&flags)[9][9],
|
||||
void CFluidPlaneCPU::UpdatePatchNoNormals(Heights& heights, const Flags& flags,
|
||||
const CFluidPlaneRender::SPatchInfo& info) {
|
||||
for (int i = 1; i <= (info.x1_ySubdivs + CFluidPlaneRender::numSubdivisionsInTile - 2) /
|
||||
CFluidPlaneRender::numSubdivisionsInTile;
|
||||
@@ -558,8 +559,8 @@ void CFluidPlaneCPU::UpdatePatchNoNormals(CFluidPlaneRender::SHFieldSample (&hei
|
||||
}
|
||||
}
|
||||
|
||||
void CFluidPlaneCPU::UpdatePatchWithNormals(CFluidPlaneRender::SHFieldSample (&heights)[46][46],
|
||||
const u8 (&flags)[9][9], const CFluidPlaneRender::SPatchInfo& info) {
|
||||
void CFluidPlaneCPU::UpdatePatchWithNormals(Heights& heights, const Flags& flags,
|
||||
const CFluidPlaneRender::SPatchInfo& info) {
|
||||
float normalScale = -(2.f * info.x18_rippleResolution);
|
||||
float nz = 0.25f * 2.f * info.x18_rippleResolution;
|
||||
int curGridY = info.x2e_tileY * info.x2a_gridDimX - 1 + info.x28_tileX;
|
||||
@@ -696,11 +697,9 @@ void CFluidPlaneCPU::UpdatePatchWithNormals(CFluidPlaneRender::SHFieldSample (&h
|
||||
}
|
||||
}
|
||||
|
||||
bool CFluidPlaneCPU::UpdatePatch(float time, const CFluidPlaneRender::SPatchInfo& info,
|
||||
CFluidPlaneRender::SHFieldSample (&heights)[46][46], u8 (&flags)[9][9],
|
||||
const zeus::CVector3f& areaCenter,
|
||||
const std::optional<CRippleManager>& rippleManager, int fromX, int toX,
|
||||
int fromY, int toY) const {
|
||||
bool CFluidPlaneCPU::UpdatePatch(float time, const CFluidPlaneRender::SPatchInfo& info, Heights& heights, Flags& flags,
|
||||
const zeus::CVector3f& areaCenter, const std::optional<CRippleManager>& rippleManager,
|
||||
int fromX, int toX, int fromY, int toY) const {
|
||||
rstl::reserved_vector<CFluidPlaneRender::SRippleInfo, 32> rippleInfos;
|
||||
if (rippleManager) {
|
||||
for (const CRipple& ripple : rippleManager->GetRipples()) {
|
||||
@@ -730,10 +729,10 @@ bool CFluidPlaneCPU::UpdatePatch(float time, const CFluidPlaneRender::SPatchInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Used to be part of locked cache
|
||||
* These are too big for stack allocation */
|
||||
static CFluidPlaneRender::SHFieldSample lc_heights[46][46] = {};
|
||||
static u8 lc_flags[9][9] = {};
|
||||
// Used to be part of locked cache
|
||||
// These are too big for stack allocation
|
||||
static CFluidPlane::Heights lc_heights{};
|
||||
static CFluidPlane::Flags lc_flags{};
|
||||
|
||||
void CFluidPlaneCPU::Render(const CStateManager& mgr, float alpha, const zeus::CAABox& aabb, const zeus::CTransform& xf,
|
||||
const zeus::CTransform& areaXf, bool noNormals, const zeus::CFrustum& frustum,
|
||||
|
||||
Reference in New Issue
Block a user