diff --git a/Runtime/World/CFluidPlaneCPU.cpp b/Runtime/World/CFluidPlaneCPU.cpp index f30ad5efc..1d1bb52d0 100644 --- a/Runtime/World/CFluidPlaneCPU.cpp +++ b/Runtime/World/CFluidPlaneCPU.cpp @@ -128,11 +128,11 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManag const CScriptWater* water) { CFluidPlaneShader::RenderSetupInfo out; - float uvT = mgr.GetFluidPlaneManager()->GetUVT(); - bool hasBumpMap = HasBumpMap() && kEnableWaterBumpMaps; + const float uvT = mgr.GetFluidPlaneManager()->GetUVT(); + const bool hasBumpMap = HasBumpMap() && kEnableWaterBumpMaps; bool doubleLightmapBlend = false; - bool hasEnvMap = mgr.GetCameraManager()->GetFluidCounter() == 0 && HasEnvMap(); - bool hasEnvBumpMap = HasEnvBumpMap(); + const bool hasEnvMap = mgr.GetCameraManager()->GetFluidCounter() == 0 && HasEnvMap(); + const bool hasEnvBumpMap = HasEnvBumpMap(); InitializeSineWave(); CGraphics::SetModelMatrix(xf); @@ -165,8 +165,7 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManag curTex++; } - float fluidUVs[3][2]; - x4c_uvMotion.CalculateFluidTextureOffset(uvT, fluidUVs); + const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT); out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); diff --git a/Runtime/World/CFluidPlaneDoor.cpp b/Runtime/World/CFluidPlaneDoor.cpp index 339d321bd..b97a94f28 100644 --- a/Runtime/World/CFluidPlaneDoor.cpp +++ b/Runtime/World/CFluidPlaneDoor.cpp @@ -18,11 +18,10 @@ CFluidPlaneShader::RenderSetupInfo CFluidPlaneDoor::RenderSetup(const CStateMana bool noNormals) { CFluidPlaneShader::RenderSetupInfo out; - float uvT = mgr.GetFluidPlaneManager()->GetUVT(); + const float uvT = mgr.GetFluidPlaneManager()->GetUVT(); CGraphics::SetModelMatrix(xf); - float fluidUVs[3][2]; - x4c_uvMotion.CalculateFluidTextureOffset(uvT, fluidUVs); + const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT); out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); diff --git a/Runtime/World/CFluidUVMotion.cpp b/Runtime/World/CFluidUVMotion.cpp index 81c2cdb0a..e8ad7cc6e 100644 --- a/Runtime/World/CFluidUVMotion.cpp +++ b/Runtime/World/CFluidUVMotion.cpp @@ -25,15 +25,16 @@ CFluidUVMotion::CFluidUVMotion(float timeToWrap, float orientation) x0_fluidLayers[2].x8_orientation = 0.78539819f; } -void CFluidUVMotion::CalculateFluidTextureOffset(float t, float offsets[3][2]) const { - float totalYOffset = t * x4c_ooTimeToWrap * std::cos(x50_orientation); - float totalXOffset = t * x4c_ooTimeToWrap * std::sin(x50_orientation); +CFluidUVMotion::FluidOffsets CFluidUVMotion::CalculateFluidTextureOffset(float t) const { + FluidOffsets offsets; + 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]; - float speedT = t * layer.x4_ooTimeToWrap; - float cycleT = speedT - std::floor(speedT); + const float speedT = t * layer.x4_ooTimeToWrap; + const float cycleT = speedT - std::floor(speedT); float localY; float localX; switch (layer.x0_motion) { @@ -42,7 +43,7 @@ void CFluidUVMotion::CalculateFluidTextureOffset(float t, float offsets[3][2]) c localY = 0.f; } break; case EFluidUVMotion::Circular: { - float angle = (M_PIF * 2) * cycleT; + const float angle = (M_PIF * 2) * cycleT; localY = layer.xc_magnitude * std::sin(angle); localX = layer.xc_magnitude * std::cos(angle); } break; @@ -55,11 +56,13 @@ void CFluidUVMotion::CalculateFluidTextureOffset(float t, float offsets[3][2]) c break; } - 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 x = localX * std::sin(layer.x8_orientation) + localY * std::cos(layer.x8_orientation) + totalXOffset; + 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][1] = y - std::floor(y); } + + return offsets; } } // namespace urde diff --git a/Runtime/World/CFluidUVMotion.hpp b/Runtime/World/CFluidUVMotion.hpp index fd506bcfc..e8d1eb8dd 100644 --- a/Runtime/World/CFluidUVMotion.hpp +++ b/Runtime/World/CFluidUVMotion.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" @@ -38,6 +40,8 @@ private: float x50_orientation; public: + using FluidOffsets = std::array, 3>; + CFluidUVMotion(float timeToWrap, float orientation, const SFluidLayerMotion& colorLayer, const SFluidLayerMotion& pattern1Layer, const SFluidLayerMotion& pattern2Layer); CFluidUVMotion(float timeToWrap, float orientation); @@ -45,6 +49,8 @@ public: const rstl::reserved_vector& GetFluidLayers() const { return x0_fluidLayers; } float GetOrientation() const { return x50_orientation; } 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