Răsfoiți Sursa

Improve constant naming with descriptive names

- Rename HashXorShift namespace to Hash for brevity
- Rename Shift5/13/17 to XorShiftAmount5/13/17 for clarity
- Rename GoldenRatioHash to GoldenRatio
- Rename HashPrime1/2/3 to SpatialHashPrime1/2/3
- Rename LcgMultiplier/Increment to LinearCongruentialMultiplier/Increment
- Rename MixConstant1/2/3 to HashMixMultiplier1/2/3
- Rename NoiseHashX/Y/Scale to NoiseFrequencyX/Y/Amplitude
- Rename TemporalHashFrequency to TemporalVariationFrequency
- Update all usages across affected files

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 lună în urmă
părinte
comite
3fc2e8e277

+ 1 - 1
render/entity/archer_renderer.cpp

@@ -528,7 +528,7 @@ private:
              v.palette.leather, nullptr, 1.0F);
              v.palette.leather, nullptr, 1.0F);
 
 
     float const j = (hash01(seed) - 0.5F) * 0.04F;
     float const j = (hash01(seed) - 0.5F) * 0.04F;
-    float const k = (hash01(seed ^ HashXorShift::GoldenRatioHash) - 0.5F) * 0.04F;
+    float const k = (hash01(seed ^ Hash::GoldenRatio) - 0.5F) * 0.04F;
 
 
     QVector3D const a1 = qTop + QVector3D(0.00F + j, 0.08F, 0.00F + k);
     QVector3D const a1 = qTop + QVector3D(0.00F + j, 0.08F, 0.00F + k);
     out.mesh(getUnitCylinder(), cylinderBetween(ctx.model, qTop, a1, 0.010F),
     out.mesh(getUnitCylinder(), cylinderBetween(ctx.model, qTop, a1, 0.010F),

+ 1 - 1
render/entity/arrow_vfx_renderer.cpp

@@ -298,7 +298,7 @@ static inline void drawQuiver(const DrawContext &p, ISubmitter &out,
            C.leather, nullptr, 1.0F);
            C.leather, nullptr, 1.0F);
 
 
   float j = (hash01(seed) - 0.5F) * 0.04F;
   float j = (hash01(seed) - 0.5F) * 0.04F;
-  float k = (hash01(seed ^ HashXorShift::GoldenRatioHash) - 0.5F) * 0.04F;
+  float k = (hash01(seed ^ Hash::GoldenRatio) - 0.5F) * 0.04F;
 
 
   QVector3D a1 = qTop + QVector3D(0.00F + j, 0.08F, 0.00F + k);
   QVector3D a1 = qTop + QVector3D(0.00F + j, 0.08F, 0.00F + k);
   out.mesh(getUnitCylinder(), cylinderBetween(p.model, qTop, a1, 0.010F),
   out.mesh(getUnitCylinder(), cylinderBetween(p.model, qTop, a1, 0.010F),

+ 6 - 6
render/gl/render_constants.h

@@ -89,9 +89,9 @@ inline constexpr float Mask24BitFloat = 16777215.0F;
 inline constexpr unsigned int Mask24BitHex = 0x01000000U;
 inline constexpr unsigned int Mask24BitHex = 0x01000000U;
 } // namespace Render::GL::BitShift
 } // namespace Render::GL::BitShift
 
 
-namespace Render::GL::HashXorShift {
-inline constexpr int Shift5 = 5;
-inline constexpr int Shift13 = 13;
-inline constexpr int Shift17 = 17;
-inline constexpr uint32_t GoldenRatioHash = 0x9E3779B9U;
-} // namespace Render::GL::HashXorShift
+namespace Render::GL::Hash {
+inline constexpr int XorShiftAmount5 = 5;
+inline constexpr int XorShiftAmount13 = 13;
+inline constexpr int XorShiftAmount17 = 17;
+inline constexpr uint32_t GoldenRatio = 0x9E3779B9U;
+} // namespace Render::GL::Hash

+ 1 - 1
render/ground/firecamp_renderer.cpp

@@ -140,7 +140,7 @@ void FireCampRenderer::submit(Renderer &renderer, ResourceManager *resources) {
         hashCoords(static_cast<int>(std::floor(camp_pos.x())),
         hashCoords(static_cast<int>(std::floor(camp_pos.x())),
                    static_cast<int>(std::floor(camp_pos.z())),
                    static_cast<int>(std::floor(camp_pos.z())),
                    static_cast<uint32_t>(radius_phase.y() *
                    static_cast<uint32_t>(radius_phase.y() *
-                                         HashConstants::TemporalHashFrequency));
+                                         HashConstants::TemporalVariationFrequency));
 
 
     const float time = params.time;
     const float time = params.time;
     const float char_amount =
     const float char_amount =

+ 31 - 30
render/ground/ground_utils.h

@@ -13,32 +13,33 @@ inline constexpr float TwoPi = ::Render::GL::MathConstants::TwoPi;
 } // namespace MathConstants
 } // namespace MathConstants
 
 
 namespace HashConstants {
 namespace HashConstants {
-inline constexpr uint32_t HashPrime1 = 73856093U;
-inline constexpr uint32_t HashPrime2 = 19349663U;
-inline constexpr uint32_t HashPrime3 = 83492791U;
-inline constexpr uint32_t LcgMultiplier = 1664525U;
-inline constexpr uint32_t LcgIncrement = 1013904223U;
-inline constexpr uint32_t XorShift17 = 17;
-inline constexpr uint32_t XorShift11 = 11;
-inline constexpr uint32_t XorShift15 = 15;
-inline constexpr uint32_t XorShift14 = 14;
-inline constexpr uint32_t MixConstant1 = 0xed5ad4bbU;
-inline constexpr uint32_t MixConstant2 = 0xac4c1b51U;
-inline constexpr uint32_t MixConstant3 = 0x31848babU;
-inline constexpr float NoiseHashX = 127.1F;
-inline constexpr float NoiseHashY = 311.7F;
-inline constexpr float NoiseHashScale = 43758.5453123F;
-inline constexpr float TemporalHashFrequency = 37.0F;
+inline constexpr uint32_t SpatialHashPrime1 = 73856093U;
+inline constexpr uint32_t SpatialHashPrime2 = 19349663U;
+inline constexpr uint32_t SpatialHashPrime3 = 83492791U;
+inline constexpr uint32_t LinearCongruentialMultiplier = 1664525U;
+inline constexpr uint32_t LinearCongruentialIncrement = 1013904223U;
+inline constexpr uint32_t XorShiftAmount17 = 17;
+inline constexpr uint32_t XorShiftAmount11 = 11;
+inline constexpr uint32_t XorShiftAmount15 = 15;
+inline constexpr uint32_t XorShiftAmount14 = 14;
+inline constexpr uint32_t HashMixMultiplier1 = 0xed5ad4bbU;
+inline constexpr uint32_t HashMixMultiplier2 = 0xac4c1b51U;
+inline constexpr uint32_t HashMixMultiplier3 = 0x31848babU;
+inline constexpr float NoiseFrequencyX = 127.1F;
+inline constexpr float NoiseFrequencyY = 311.7F;
+inline constexpr float NoiseAmplitude = 43758.5453123F;
+inline constexpr float TemporalVariationFrequency = 37.0F;
 } // namespace HashConstants
 } // namespace HashConstants
 
 
 inline auto hashCoords(int x, int z, uint32_t salt = 0U) -> uint32_t {
 inline auto hashCoords(int x, int z, uint32_t salt = 0U) -> uint32_t {
-  auto const ux = static_cast<uint32_t>(x * HashConstants::HashPrime1);
-  auto const uz = static_cast<uint32_t>(z * HashConstants::HashPrime2);
-  return ux ^ uz ^ (salt * HashConstants::HashPrime3);
+  auto const ux = static_cast<uint32_t>(x * HashConstants::SpatialHashPrime1);
+  auto const uz = static_cast<uint32_t>(z * HashConstants::SpatialHashPrime2);
+  return ux ^ uz ^ (salt * HashConstants::SpatialHashPrime3);
 }
 }
 
 
 inline auto rand01(uint32_t &state) -> float {
 inline auto rand01(uint32_t &state) -> float {
-  state = state * HashConstants::LcgMultiplier + HashConstants::LcgIncrement;
+  state = state * HashConstants::LinearCongruentialMultiplier +
+          HashConstants::LinearCongruentialIncrement;
   return static_cast<float>((state >> ::Render::GL::BitShift::Shift8) &
   return static_cast<float>((state >> ::Render::GL::BitShift::Shift8) &
                             ::Render::GL::BitShift::Mask24Bit) /
                             ::Render::GL::BitShift::Mask24Bit) /
          ::Render::GL::BitShift::Mask24BitFloat;
          ::Render::GL::BitShift::Mask24BitFloat;
@@ -49,22 +50,22 @@ inline auto remap(float value, float minOut, float maxOut) -> float {
 }
 }
 
 
 inline auto hashTo01(uint32_t h) -> float {
 inline auto hashTo01(uint32_t h) -> float {
-  h ^= h >> HashConstants::XorShift17;
-  h *= HashConstants::MixConstant1;
-  h ^= h >> HashConstants::XorShift11;
-  h *= HashConstants::MixConstant2;
-  h ^= h >> HashConstants::XorShift15;
-  h *= HashConstants::MixConstant3;
-  h ^= h >> HashConstants::XorShift14;
+  h ^= h >> HashConstants::XorShiftAmount17;
+  h *= HashConstants::HashMixMultiplier1;
+  h ^= h >> HashConstants::XorShiftAmount11;
+  h *= HashConstants::HashMixMultiplier2;
+  h ^= h >> HashConstants::XorShiftAmount15;
+  h *= HashConstants::HashMixMultiplier3;
+  h ^= h >> HashConstants::XorShiftAmount14;
   return static_cast<float>((h >> ::Render::GL::BitShift::Shift8) &
   return static_cast<float>((h >> ::Render::GL::BitShift::Shift8) &
                             ::Render::GL::BitShift::Mask24Bit) /
                             ::Render::GL::BitShift::Mask24Bit) /
          ::Render::GL::BitShift::Mask24BitFloat;
          ::Render::GL::BitShift::Mask24BitFloat;
 }
 }
 
 
 inline auto noiseHash(float x, float y) -> float {
 inline auto noiseHash(float x, float y) -> float {
-  float const n = std::sin(x * HashConstants::NoiseHashX +
-                           y * HashConstants::NoiseHashY) *
-                  HashConstants::NoiseHashScale;
+  float const n = std::sin(x * HashConstants::NoiseFrequencyX +
+                           y * HashConstants::NoiseFrequencyY) *
+                  HashConstants::NoiseAmplitude;
   return n - std::floor(n);
   return n - std::floor(n);
 }
 }
 
 

+ 2 - 2
render/ground/terrain_renderer.cpp

@@ -31,7 +31,7 @@ namespace {
 using std::uint32_t;
 using std::uint32_t;
 using namespace Render::GL::BitShift;
 using namespace Render::GL::BitShift;
 using namespace Render::GL::Geometry;
 using namespace Render::GL::Geometry;
-using namespace Render::GL::HashXorShift;
+using namespace Render::GL::Hash;
 using namespace Render::Ground;
 using namespace Render::Ground;
 
 
 const QMatrix4x4 k_identity_matrix;
 const QMatrix4x4 k_identity_matrix;
@@ -347,7 +347,7 @@ void TerrainRenderer::buildMeshes() {
       SectionData sections[3];
       SectionData sections[3];
 
 
       uint32_t const chunk_seed = hashCoords(chunk_x, chunk_z, m_noiseSeed);
       uint32_t const chunk_seed = hashCoords(chunk_x, chunk_z, m_noiseSeed);
-      uint32_t const variant_seed = chunk_seed ^ GoldenRatioHash;
+      uint32_t const variant_seed = chunk_seed ^ GoldenRatio;
       float const rotation_step =
       float const rotation_step =
           static_cast<float>((variant_seed >> 5) & 3) * 90.0F;
           static_cast<float>((variant_seed >> 5) & 3) * 90.0F;
       bool const flip = ((variant_seed >> 7) & 1U) != 0U;
       bool const flip = ((variant_seed >> 7) & 1U) != 0U;

+ 3 - 3
render/humanoid_math.h

@@ -8,9 +8,9 @@
 namespace Render::GL {
 namespace Render::GL {
 
 
 inline auto hash01(uint32_t x) -> float {
 inline auto hash01(uint32_t x) -> float {
-  x ^= x << HashXorShift::Shift13;
-  x ^= x >> HashXorShift::Shift17;
-  x ^= x << HashXorShift::Shift5;
+  x ^= x << Hash::XorShiftAmount13;
+  x ^= x >> Hash::XorShiftAmount17;
+  x ^= x << Hash::XorShiftAmount5;
   return (x & BitShift::Mask24Bit) / float(BitShift::Mask24BitHex);
   return (x & BitShift::Mask24Bit) / float(BitShift::Mask24BitHex);
 }
 }