Selaa lähdekoodia

Add TwoPi constant and replace magic numbers in ground renderers

- Add TwoPi and Pi constants to render_constants.h using std::numbers
- Expose TwoPi constant in ground_utils.h
- Replace 6.28... literals with MathConstants::TwoPi in:
  - firecamp_renderer.cpp
  - pine_renderer.cpp
  - stone_renderer.cpp
  - plant_renderer.cpp
  - biome_renderer.cpp
- Improve code readability and maintainability

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 kuukausi sitten
vanhempi
sitoutus
ae0fc81ad6

+ 7 - 0
render/gl/render_constants.h

@@ -1,5 +1,12 @@
 #pragma once
 
+#include <numbers>
+
+namespace Render::GL::MathConstants {
+inline constexpr float Pi = std::numbers::pi_v<float>;
+inline constexpr float TwoPi = 2.0F * Pi;
+} // namespace Render::GL::MathConstants
+
 namespace Render::GL::VertexAttrib {
 inline constexpr int Position = 0;
 inline constexpr int Normal = 1;

+ 3 - 3
render/ground/biome_renderer.cpp

@@ -275,8 +275,8 @@ void BiomeRenderer::generateGrassInstances() {
 
     float const sway_strength = remap(rand01(state), 0.75F, 1.25F);
     float const sway_speed = remap(rand01(state), 0.85F, 1.15F);
-    float const sway_phase = rand01(state) * 6.2831853F;
-    float const orientation = rand01(state) * 6.2831853F;
+    float const sway_phase = rand01(state) * MathConstants::TwoPi;
+    float const orientation = rand01(state) * MathConstants::TwoPi;
 
     GrassInstanceGpu instance;
     instance.posHeight = QVector4D(world_x, world_y, world_z, height);
@@ -436,7 +436,7 @@ void BiomeRenderer::generateGrassInstances() {
               (0.45F + 0.55F * rand01(state)) * scatter_base * tile_safe;
 
           for (int blade = 0; blade < blades; ++blade) {
-            float const angle = rand01(state) * 6.2831853F;
+            float const angle = rand01(state) * MathConstants::TwoPi;
             float const radius = scatter_radius * std::sqrt(rand01(state));
             float const gx = center_gx + std::cos(angle) * radius / tile_safe;
             float const gz = center_gz + std::sin(angle) * radius / tile_safe;

+ 1 - 1
render/ground/firecamp_renderer.cpp

@@ -299,7 +299,7 @@ void FireCampRenderer::generateFireCampInstances() {
     float const intensity = remap(rand01(state), 0.8F, 1.2F);
     float const radius = remap(rand01(state), 2.0F, 4.0F) * tile_safe;
 
-    float const phase = rand01(state) * 6.2831853F;
+    float const phase = rand01(state) * MathConstants::TwoPi;
 
     float const duration = 1.0F;
 

+ 4 - 0
render/ground/ground_utils.h

@@ -8,6 +8,10 @@ namespace Render::Ground {
 
 using std::uint32_t;
 
+namespace MathConstants {
+inline constexpr float TwoPi = ::Render::GL::MathConstants::TwoPi;
+} // namespace MathConstants
+
 namespace HashConstants {
 inline constexpr uint32_t HashPrime1 = 73856093U;
 inline constexpr uint32_t HashPrime2 = 19349663U;

+ 2 - 2
render/ground/pine_renderer.cpp

@@ -199,9 +199,9 @@ void PineRenderer::generatePineInstances() {
     QVector3D const brown_tint(0.35F, 0.30F, 0.20F);
     tint_color = tint_color * (1.0F - brown_mix) + brown_tint * brown_mix;
 
-    float const sway_phase = rand01(state) * 6.2831853F;
+    float const sway_phase = rand01(state) * MathConstants::TwoPi;
 
-    float const rotation = rand01(state) * 6.2831853F;
+    float const rotation = rand01(state) * MathConstants::TwoPi;
 
     float const silhouette_seed = rand01(state);
     float const needle_seed = rand01(state);

+ 2 - 2
render/ground/plant_renderer.cpp

@@ -275,11 +275,11 @@ void PlantRenderer::generatePlantInstances() {
     QVector3D const brown_tint(0.55F, 0.50F, 0.35F);
     tint_color = tint_color * (1.0F - brown_mix) + brown_tint * brown_mix;
 
-    float const sway_phase = rand01(state) * 6.2831853F;
+    float const sway_phase = rand01(state) * MathConstants::TwoPi;
     float const sway_strength = remap(rand01(state), 0.6F, 1.2F);
     float const sway_speed = remap(rand01(state), 0.8F, 1.3F);
 
-    float const rotation = rand01(state) * 6.2831853F;
+    float const rotation = rand01(state) * MathConstants::TwoPi;
 
     PlantInstanceGpu instance;
 

+ 1 - 1
render/ground/stone_renderer.cpp

@@ -218,7 +218,7 @@ void StoneRenderer::generateStoneInstances() {
     QVector3D const brown_tint(0.45F, 0.38F, 0.30F);
     color = color * (1.0F - brown_mix) + brown_tint * brown_mix;
 
-    float const rotation = rand01(state) * 6.2831853F;
+    float const rotation = rand01(state) * MathConstants::TwoPi;
 
     StoneInstanceGpu instance;
     instance.posScale = QVector4D(world_x, world_y + 0.01F, world_z, scale);