mirror of https://github.com/AxioDL/metaforce.git
CFluidUVMotion: Return std::array by value from CalculateFluidTextureOffset()
Same behavior, but allows for easier use of API and makes it harder to misuse. It also makes it easier for analysis to determine out of bounds, given we leverage std::array rather than a pointer that causes arrays to decay and lose their size information.
This commit is contained in:
parent
3c8619ba44
commit
14f6dd2cd8
|
@ -128,11 +128,11 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManag
|
||||||
const CScriptWater* water) {
|
const CScriptWater* water) {
|
||||||
CFluidPlaneShader::RenderSetupInfo out;
|
CFluidPlaneShader::RenderSetupInfo out;
|
||||||
|
|
||||||
float uvT = mgr.GetFluidPlaneManager()->GetUVT();
|
const float uvT = mgr.GetFluidPlaneManager()->GetUVT();
|
||||||
bool hasBumpMap = HasBumpMap() && kEnableWaterBumpMaps;
|
const bool hasBumpMap = HasBumpMap() && kEnableWaterBumpMaps;
|
||||||
bool doubleLightmapBlend = false;
|
bool doubleLightmapBlend = false;
|
||||||
bool hasEnvMap = mgr.GetCameraManager()->GetFluidCounter() == 0 && HasEnvMap();
|
const bool hasEnvMap = mgr.GetCameraManager()->GetFluidCounter() == 0 && HasEnvMap();
|
||||||
bool hasEnvBumpMap = HasEnvBumpMap();
|
const bool hasEnvBumpMap = HasEnvBumpMap();
|
||||||
InitializeSineWave();
|
InitializeSineWave();
|
||||||
CGraphics::SetModelMatrix(xf);
|
CGraphics::SetModelMatrix(xf);
|
||||||
|
|
||||||
|
@ -165,8 +165,7 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManag
|
||||||
curTex++;
|
curTex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fluidUVs[3][2];
|
const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT);
|
||||||
x4c_uvMotion.CalculateFluidTextureOffset(uvT, fluidUVs);
|
|
||||||
|
|
||||||
out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
||||||
out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
||||||
|
|
|
@ -18,11 +18,10 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneDoor::RenderSetup(const CStateMana
|
||||||
bool noNormals) {
|
bool noNormals) {
|
||||||
CFluidPlaneShader::RenderSetupInfo out;
|
CFluidPlaneShader::RenderSetupInfo out;
|
||||||
|
|
||||||
float uvT = mgr.GetFluidPlaneManager()->GetUVT();
|
const float uvT = mgr.GetFluidPlaneManager()->GetUVT();
|
||||||
CGraphics::SetModelMatrix(xf);
|
CGraphics::SetModelMatrix(xf);
|
||||||
|
|
||||||
float fluidUVs[3][2];
|
const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT);
|
||||||
x4c_uvMotion.CalculateFluidTextureOffset(uvT, fluidUVs);
|
|
||||||
|
|
||||||
out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
||||||
out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale();
|
||||||
|
|
|
@ -25,15 +25,16 @@ CFluidUVMotion::CFluidUVMotion(float timeToWrap, float orientation)
|
||||||
x0_fluidLayers[2].x8_orientation = 0.78539819f;
|
x0_fluidLayers[2].x8_orientation = 0.78539819f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFluidUVMotion::CalculateFluidTextureOffset(float t, float offsets[3][2]) const {
|
CFluidUVMotion::FluidOffsets CFluidUVMotion::CalculateFluidTextureOffset(float t) const {
|
||||||
float totalYOffset = t * x4c_ooTimeToWrap * std::cos(x50_orientation);
|
FluidOffsets offsets;
|
||||||
float totalXOffset = t * x4c_ooTimeToWrap * std::sin(x50_orientation);
|
const float totalYOffset = t * x4c_ooTimeToWrap * std::cos(x50_orientation);
|
||||||
|
const float totalXOffset = t * x4c_ooTimeToWrap * std::sin(x50_orientation);
|
||||||
|
|
||||||
for (u32 i = 0; i < x0_fluidLayers.size(); ++i) {
|
for (size_t i = 0; i < x0_fluidLayers.size(); ++i) {
|
||||||
const SFluidLayerMotion& layer = x0_fluidLayers[i];
|
const SFluidLayerMotion& layer = x0_fluidLayers[i];
|
||||||
|
|
||||||
float speedT = t * layer.x4_ooTimeToWrap;
|
const float speedT = t * layer.x4_ooTimeToWrap;
|
||||||
float cycleT = speedT - std::floor(speedT);
|
const float cycleT = speedT - std::floor(speedT);
|
||||||
float localY;
|
float localY;
|
||||||
float localX;
|
float localX;
|
||||||
switch (layer.x0_motion) {
|
switch (layer.x0_motion) {
|
||||||
|
@ -42,7 +43,7 @@ void CFluidUVMotion::CalculateFluidTextureOffset(float t, float offsets[3][2]) c
|
||||||
localY = 0.f;
|
localY = 0.f;
|
||||||
} break;
|
} break;
|
||||||
case EFluidUVMotion::Circular: {
|
case EFluidUVMotion::Circular: {
|
||||||
float angle = (M_PIF * 2) * cycleT;
|
const float angle = (M_PIF * 2) * cycleT;
|
||||||
localY = layer.xc_magnitude * std::sin(angle);
|
localY = layer.xc_magnitude * std::sin(angle);
|
||||||
localX = layer.xc_magnitude * std::cos(angle);
|
localX = layer.xc_magnitude * std::cos(angle);
|
||||||
} break;
|
} break;
|
||||||
|
@ -55,11 +56,13 @@ void CFluidUVMotion::CalculateFluidTextureOffset(float t, float offsets[3][2]) c
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
float x = localX * std::sin(layer.x8_orientation) + localY * std::cos(layer.x8_orientation) + totalXOffset;
|
const float x = localX * std::sin(layer.x8_orientation) + localY * std::cos(layer.x8_orientation) + totalXOffset;
|
||||||
float y = localY * std::sin(layer.x8_orientation) + localX * std::cos(layer.x8_orientation) + totalYOffset;
|
const float y = localY * std::sin(layer.x8_orientation) + localX * std::cos(layer.x8_orientation) + totalYOffset;
|
||||||
|
|
||||||
offsets[i][0] = x - std::floor(x);
|
offsets[i][0] = x - std::floor(x);
|
||||||
offsets[i][1] = y - std::floor(y);
|
offsets[i][1] = y - std::floor(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return offsets;
|
||||||
}
|
}
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "Runtime/RetroTypes.hpp"
|
#include "Runtime/RetroTypes.hpp"
|
||||||
#include "Runtime/rstl.hpp"
|
#include "Runtime/rstl.hpp"
|
||||||
|
|
||||||
|
@ -38,6 +40,8 @@ private:
|
||||||
float x50_orientation;
|
float x50_orientation;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using FluidOffsets = std::array<std::array<float, 2>, 3>;
|
||||||
|
|
||||||
CFluidUVMotion(float timeToWrap, float orientation, const SFluidLayerMotion& colorLayer,
|
CFluidUVMotion(float timeToWrap, float orientation, const SFluidLayerMotion& colorLayer,
|
||||||
const SFluidLayerMotion& pattern1Layer, const SFluidLayerMotion& pattern2Layer);
|
const SFluidLayerMotion& pattern1Layer, const SFluidLayerMotion& pattern2Layer);
|
||||||
CFluidUVMotion(float timeToWrap, float orientation);
|
CFluidUVMotion(float timeToWrap, float orientation);
|
||||||
|
@ -45,6 +49,8 @@ public:
|
||||||
const rstl::reserved_vector<SFluidLayerMotion, 3>& GetFluidLayers() const { return x0_fluidLayers; }
|
const rstl::reserved_vector<SFluidLayerMotion, 3>& GetFluidLayers() const { return x0_fluidLayers; }
|
||||||
float GetOrientation() const { return x50_orientation; }
|
float GetOrientation() const { return x50_orientation; }
|
||||||
float GetOOTimeToWrapTexPage() const { return x4c_ooTimeToWrap; }
|
float GetOOTimeToWrapTexPage() const { return x4c_ooTimeToWrap; }
|
||||||
void CalculateFluidTextureOffset(float, float[3][2]) const;
|
|
||||||
|
// In game binaries this uses an out pointer instead of return by value.
|
||||||
|
FluidOffsets CalculateFluidTextureOffset(float t) const;
|
||||||
};
|
};
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
Loading…
Reference in New Issue