From 0c0552a428d8ace179b91f7a7f95de45680cc7a4 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Thu, 4 Jun 2026 19:46:01 +0200 Subject: [PATCH] Replace M_PI with C++ numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C++20 added π (pi) to the standard, replace the C macro globally. Signed-off-by: Ralph Sennhauser --- source/graphics/CameraController.cpp | 10 +++++----- source/graphics/LightEnv.h | 6 +++--- source/graphics/MapWriter.cpp | 5 +++-- source/graphics/MiniMapTexture.cpp | 5 +++-- source/graphics/TerrainProperties.cpp | 5 +++-- source/lib/sysdep/os/win/wposix/wposix.h | 8 +------- source/maths/MathUtil.h | 8 +++++--- source/maths/Quaternion.cpp | 7 ++++--- source/maths/tests/test_Bound.h | 7 ++++--- source/maths/tests/test_Fixed.h | 15 ++++++++------- source/maths/tests/test_Matrix3d.h | 5 +++-- source/renderer/DebugRenderer.cpp | 5 +++-- source/renderer/SkyManager.cpp | 5 +++-- source/renderer/TerrainRenderer.cpp | 2 +- source/renderer/TexturedLineRData.cpp | 5 +++-- source/simulation2/components/CCmpPosition.cpp | 15 ++++++++------- .../components/CCmpTerritoryManager.cpp | 5 +++-- .../components/tests/test_ObstructionManager.h | 7 ++++--- source/simulation2/helpers/CinemaPath.cpp | 5 +++-- source/simulation2/helpers/Render.cpp | 11 ++++++----- source/simulation2/helpers/VertexPathfinder.cpp | 4 +++- source/soundmanager/scripting/SoundGroup.cpp | 5 +++-- .../Sections/Environment/Environment.cpp | 7 ++++--- .../ScenarioEditor/Tools/ActorViewerTool.cpp | 9 +++++---- .../AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp | 7 ++++--- .../Handlers/EnvironmentHandlers.cpp | 7 ++++--- 26 files changed, 99 insertions(+), 81 deletions(-) diff --git a/source/graphics/CameraController.cpp b/source/graphics/CameraController.cpp index 482d811dff..d1bcc9cfde 100644 --- a/source/graphics/CameraController.cpp +++ b/source/graphics/CameraController.cpp @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include @@ -258,7 +258,7 @@ void CCameraController::Update(const float deltaRealTime) cmpPosition->GetInterpolatedPosition2D(frameOffset, x, z, angle); float height = 4.f; m_Camera.m_Orientation.SetIdentity(); - m_Camera.m_Orientation.RotateX(static_cast(M_PI) / 24.f); + m_Camera.m_Orientation.RotateX(std::numbers::pi_v / 24.f); m_Camera.m_Orientation.RotateY(angle); m_Camera.m_Orientation.Translate(pos.X, pos.Y + height, pos.Z); @@ -305,7 +305,7 @@ void CCameraController::Update(const float deltaRealTime) if (m_ConstrainCamera) { if (m_BirdsEyeView) - m_RotateX.ClampSmoothly(static_cast(M_PI_2), static_cast(M_PI_2)); + m_RotateX.ClampSmoothly(std::numbers::pi_v / 2.f, std::numbers::pi_v / 2.f); else m_RotateX.ClampSmoothly(DEGTORAD(m_ViewRotateXMin), DEGTORAD(m_ViewRotateXMax)); } @@ -423,7 +423,7 @@ void CCameraController::Update(const float deltaRealTime) } */ - m_RotateY.Wrap(-static_cast(M_PI), static_cast(M_PI)); + m_RotateY.Wrap(-std::numbers::pi_v, std::numbers::pi_v); // Update the camera matrix SetCameraProjection(); @@ -567,7 +567,7 @@ void CCameraController::ResetCameraAngleZoom() void CCameraController::ToggleBirdsEyeView() { m_BirdsEyeView = !m_BirdsEyeView; - float angle = m_BirdsEyeView ? M_PI / 2 : DEGTORAD(m_ViewRotateXDefault); + float angle = m_BirdsEyeView ? std::numbers::pi_v / 2.f : DEGTORAD(m_ViewRotateXDefault); m_RotateX.SetValueSmoothly(angle); } diff --git a/source/graphics/LightEnv.h b/source/graphics/LightEnv.h index 3dd830b320..2d01eaceff 100644 --- a/source/graphics/LightEnv.h +++ b/source/graphics/LightEnv.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -104,14 +104,14 @@ private: /** * Height of sun above the horizon, in radians. - * For example, an elevation of M_PI/2 means the sun is straight up. + * For example, an elevation of PI/2 means the sun is straight up. */ float m_Elevation; /** * Direction of sun on the compass, in radians. * For example, a rotation of zero means the sun is in the direction (0,0,-1) - * and a rotation of M_PI/2 means the sun is in the direction (1,0,0) (not taking + * and a rotation of PI/2 means the sun is in the direction (1,0,0) (not taking * elevation into account). */ float m_Rotation; diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index 794bf4d6c5..aa1d74c1f7 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -307,7 +308,7 @@ void CMapWriter::WriteXML(const VfsPath& filename, CVector3D in = pCamera->GetOrientation().GetIn(); // Convert to spherical coordinates float rotation = atan2(in.X, in.Z); - float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - static_cast(M_PI / 2); + float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - std::numbers::pi_v / 2.f; { XMLWriter_Element rotationTag(xmlMapFile, "Rotation"); diff --git a/source/graphics/MiniMapTexture.cpp b/source/graphics/MiniMapTexture.cpp index c248aa0297..1e7ebbda7e 100644 --- a/source/graphics/MiniMapTexture.cpp +++ b/source/graphics/MiniMapTexture.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include namespace @@ -282,8 +283,8 @@ CMiniMapTexture::CMiniMapTexture(Renderer::Backend::IDevice* device, CSimulation m_InstanceAttributePosition.GetIterator(); for (size_t segment = 0; segment < numberOfCircleSegments; ++segment) { - const float currentAngle = static_cast(segment) / numberOfCircleSegments * 2.0f * M_PI; - const float nextAngle = static_cast(segment + 1) / numberOfCircleSegments * 2.0f * M_PI; + const float currentAngle = static_cast(segment) / numberOfCircleSegments * 2.0f * std::numbers::pi_v; + const float nextAngle = static_cast(segment + 1) / numberOfCircleSegments * 2.0f * std::numbers::pi_v; (*attributePosition)[0] = 0.0f; (*attributePosition)[1] = 0.0f; diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp index 3504459ad0..86161fcae5 100644 --- a/source/graphics/TerrainProperties.cpp +++ b/source/graphics/TerrainProperties.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -36,13 +36,14 @@ #include #include #include +#include #include CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent): m_pParent(parent), m_BaseColor(0), m_HasBaseColor(false), - m_TextureAngle((float)M_PI / 4.f), + m_TextureAngle(std::numbers::pi_v / 4.f), m_TextureSize(32.f) { if (m_pParent) diff --git a/source/lib/sysdep/os/win/wposix/wposix.h b/source/lib/sysdep/os/win/wposix/wposix.h index 856de9b982..a21e87bff7 100644 --- a/source/lib/sysdep/os/win/wposix/wposix.h +++ b/source/lib/sysdep/os/win/wposix/wposix.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -60,12 +60,6 @@ int setenv(const char* envname, const char* envval, int overwrite); // // (missing on MSVC) -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifndef M_PI_2 -#define M_PI_2 1.57079632679489661923 -#endif #ifndef INFINITY #define INFINITY (std::numeric_limits::infinity()) #endif diff --git a/source/maths/MathUtil.h b/source/maths/MathUtil.h index b9e77a5c80..c7b3ba61d1 100644 --- a/source/maths/MathUtil.h +++ b/source/maths/MathUtil.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,8 +18,10 @@ #ifndef INCLUDED_MATHUTIL #define INCLUDED_MATHUTIL -#define DEGTORAD(a) ((a) * ((float)M_PI/180.0f)) -#define RADTODEG(a) ((a) * (180.0f/(float)M_PI)) +#include + +#define DEGTORAD(a) ((a) * (std::numbers::pi_v / 180.0f)) +#define RADTODEG(a) ((a) * (180.0f / std::numbers::pi_v)) #define SQR(x) ((x) * (x)) template diff --git a/source/maths/Quaternion.cpp b/source/maths/Quaternion.cpp index 4d0a040523..21c7bd285c 100644 --- a/source/maths/Quaternion.cpp +++ b/source/maths/Quaternion.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include "maths/Vector3D.h" #include +#include const float EPSILON=0.0001f; @@ -136,13 +137,13 @@ CVector3D CQuaternion::ToEulerAngles() if (test > (.5f-EPSILON)*unit) { // singularity at north pole heading = 2 * atan2( m_V.X, m_W); - attitude = (float)M_PI/2; + attitude = std::numbers::pi_v / 2.f; bank = 0; } else if (test < (-.5f+EPSILON)*unit) { // singularity at south pole heading = -2 * atan2(m_V.X, m_W); - attitude = -(float)M_PI/2; + attitude = -std::numbers::pi_v / 2.f; bank = 0; } else diff --git a/source/maths/tests/test_Bound.h b/source/maths/tests/test_Bound.h index b9959dfdab..6d8bc2609f 100644 --- a/source/maths/tests/test_Bound.h +++ b/source/maths/tests/test_Bound.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -23,6 +23,7 @@ #include "maths/Vector3D.h" #include +#include #define TS_ASSERT_VEC_DELTA(v, x, y, z, delta) \ TS_ASSERT_DELTA(v.X, x, delta); \ @@ -107,7 +108,7 @@ public: CBoundingBoxAligned aabb(CVector3D(3, -1.5f, -1.5f), CVector3D(7, 1.5f, 1.5f)); CMatrix3D rotation; - rotation.SetZRotation(float(M_PI)/2.f); + rotation.SetZRotation(std::numbers::pi_v / 2.f); CBoundingBoxOriented result; aabb.Transform(rotation, result); @@ -128,7 +129,7 @@ public: CMatrix3D rotate; CMatrix3D translateBack; translate.SetTranslation(-2.f, 0, 0); - rotate.SetZRotation(-float(M_PI)/4.f); + rotate.SetZRotation(-std::numbers::pi_v / 4.f); translateBack.SetTranslation(2.f, 0, 0); CMatrix3D transform; diff --git a/source/maths/tests/test_Fixed.h b/source/maths/tests/test_Fixed.h index d48e0bed47..183b1438fa 100644 --- a/source/maths/tests/test_Fixed.h +++ b/source/maths/tests/test_Fixed.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -30,6 +30,7 @@ #include #include #include +#include class TestFixed : public CxxTest::TestSuite { @@ -254,10 +255,10 @@ public: void test_Atan2() { // Special cases from atan2 man page: - TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(0), fixed::FromInt(-1)).ToDouble(), M_PI, 0.01); + TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(0), fixed::FromInt(-1)).ToDouble(), std::numbers::pi, 0.01); TS_ASSERT_EQUALS(atan2_approx(fixed::FromInt(0), fixed::FromInt(+1)).ToDouble(), 0); - TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(-1), fixed::FromInt(0)).ToDouble(), -M_PI_2, 0.01); - TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(+1), fixed::FromInt(0)).ToDouble(), +M_PI_2, 0.01); + TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(-1), fixed::FromInt(0)).ToDouble(), -std::numbers::pi / 2., 0.01); + TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(+1), fixed::FromInt(0)).ToDouble(), +std::numbers::pi / 2., 0.01); TS_ASSERT_EQUALS(atan2_approx(fixed::FromInt(0), fixed::FromInt(0)).ToDouble(), 0); // Test that it approximately matches libc's atan2 @@ -308,15 +309,15 @@ public: TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.00005); TS_ASSERT_EQUALS(c, fixed::FromInt(-1)); - sincos_approx(fixed::FromDouble(M_PI*2.0), s, c); + sincos_approx(fixed::FromDouble(std::numbers::pi * 2.0), s, c); TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.0001); TS_ASSERT_DELTA(c.ToDouble(), 1.0, 0.0001); - sincos_approx(fixed::FromDouble(M_PI*100.0), s, c); + sincos_approx(fixed::FromDouble(std::numbers::pi * 100.0), s, c); TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.004); TS_ASSERT_DELTA(c.ToDouble(), 1.0, 0.004); - sincos_approx(fixed::FromDouble(M_PI*-100.0), s, c); + sincos_approx(fixed::FromDouble(std::numbers::pi * -100.0), s, c); TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.004); TS_ASSERT_DELTA(c.ToDouble(), 1.0, 0.004); diff --git a/source/maths/tests/test_Matrix3d.h b/source/maths/tests/test_Matrix3d.h index b4b8020bbe..3eed948344 100644 --- a/source/maths/tests/test_Matrix3d.h +++ b/source/maths/tests/test_Matrix3d.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -23,6 +23,7 @@ #include "maths/Vector3D.h" #include +#include #include class TestMatrix : public CxxTest::TestSuite @@ -285,7 +286,7 @@ public: for (int j = 0; j < 16; ++j) { - float a = 2 * M_PI * distribution01(m_Engine) - M_PI; + float a = 2 * std::numbers::pi * distribution01(m_Engine) - std::numbers::pi; m.SetYRotation(a); TS_ASSERT_DELTA(m.GetYRotation(), a, m_Epsilon); } diff --git a/source/renderer/DebugRenderer.cpp b/source/renderer/DebugRenderer.cpp index 6bf5ebea60..b69b111374 100644 --- a/source/renderer/DebugRenderer.cpp +++ b/source/renderer/DebugRenderer.cpp @@ -40,6 +40,7 @@ #include #include +#include void CDebugRenderer::Initialize() { @@ -156,9 +157,9 @@ void CDebugRenderer::DrawCircle( constexpr size_t segments = 16; for (size_t idx = 0; idx <= segments; ++idx) { - const float angle = M_PI * 2.0f * idx / segments; + const float angle = std::numbers::pi_v * 2.0f * idx / segments; const CVector3D offset = cameraUp * sin(angle) - cameraLeft * cos(angle); - const float nextAngle = M_PI * 2.0f * (idx + 1) / segments; + const float nextAngle = std::numbers::pi_v * 2.0f * (idx + 1) / segments; const CVector3D nextOffset = cameraUp * sin(nextAngle) - cameraLeft * cos(nextAngle); ADD(origin) ADD(origin + offset * radius) diff --git a/source/renderer/SkyManager.cpp b/source/renderer/SkyManager.cpp index 235491a735..22896bf75b 100644 --- a/source/renderer/SkyManager.cpp +++ b/source/renderer/SkyManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -262,7 +263,7 @@ void SkyManager::RenderSky( // each skymap, is in the direction of the sun from our light // environment. CMatrix3D rotate; - rotate.SetYRotation(M_PI + g_Renderer.GetSceneRenderer().GetLightEnv().GetRotation()); + rotate.SetYRotation(std::numbers::pi_v + g_Renderer.GetSceneRenderer().GetLightEnv().GetRotation()); const CMatrix3D transform = camera.GetViewProjection() * translate * rotate * scale; deviceCommandContext->SetUniform( diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 35bd2d4ebc..c9875f016f 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -600,7 +600,7 @@ bool TerrainRenderer::RenderFancyWater( // TODO: check that this rotates in the right direction. CMatrix3D skyBoxRotation; skyBoxRotation.SetIdentity(); - skyBoxRotation.RotateY(M_PI + lightEnv.GetRotation()); + skyBoxRotation.RotateY(std::numbers::pi_v + lightEnv.GetRotation()); deviceCommandContext->SetUniform( fancyWaterShader->GetBindingSlot(str_skyBoxRot), skyBoxRotation.AsFloatArray()); diff --git a/source/renderer/TexturedLineRData.cpp b/source/renderer/TexturedLineRData.cpp index 35dc50a5a9..7e23608cd3 100644 --- a/source/renderer/TexturedLineRData.cpp +++ b/source/renderer/TexturedLineRData.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -43,6 +43,7 @@ #include #include #include +#include /* Note: this implementation uses CVertexBufferManager directly rather than access it through the nicer VertexArray interface, * because it allows you to work with variable amounts of vertices and indices more easily. New code should prefer @@ -410,7 +411,7 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C // To please OpenGL's winding order, this angle needs to be negated depending on whether we start rotating from // the (center -> corner1) or (center -> corner2) vector. For the (center -> corner2) vector, we apparently need to use // the negated angle. - float stepAngle = -(float)(M_PI/(roundCapPoints-1)); + float stepAngle = -std::numbers::pi_v / (roundCapPoints-1); // Push the vertices in triangle fan order (easy to generate GL_TRIANGLES indices for afterwards) // Note that we're manually adding the corner vertices instead of having them be generated by the rotating vector. diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp index b34677ccd5..5d05b4a012 100644 --- a/source/simulation2/components/CCmpPosition.cpp +++ b/source/simulation2/components/CCmpPosition.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -748,7 +749,7 @@ public: pos.Y += GetConstructionProgressOffset(pos); - m.RotateY(rotY + (float)M_PI); + m.RotateY(rotY + std::numbers::pi_v); m.Translate(pos); return m; @@ -808,14 +809,14 @@ public: { float rotYSpeed = m_RotYSpeed.ToFloat(); float delta = rotY - m_InterpolatedRotY; - // Wrap delta to -M_PI..M_PI - delta = fmodf(delta + (float)M_PI, 2*(float)M_PI); // range -2PI..2PI - if (delta < 0) delta += 2*(float)M_PI; // range 0..2PI - delta -= (float)M_PI; // range -M_PI..M_PI + // Wrap delta to -PI..PI + delta = fmodf(delta + std::numbers::pi_v, 2.f * std::numbers::pi_v); // range -2PI..2PI + if (delta < 0) delta += 2.f * std::numbers::pi_v; // range 0..2PI + delta -= std::numbers::pi_v; // range -PI..PI // Clamp to max rate float deltaClamped = Clamp(delta, -rotYSpeed*msgData.deltaSimTime, +rotYSpeed*msgData.deltaSimTime); // Calculate new orientation, in a peculiar way in order to make sure the - // result gets close to m_orientation (rather than being n*2*M_PI out) + // result gets close to m_orientation (rather than being n*2*PI out) m_InterpolatedRotY = rotY + deltaClamped - delta; // update the visual XZ rotation diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index 1a3a5d077c..c99ed562e3 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -747,7 +748,7 @@ void CCmpTerritoryManager::Interpolate(float frameTime, float /*frameOffset*/) if (m_BoundaryLines[i].blinking) { CColor c = m_BoundaryLines[i].color; - c.a *= 0.2f + 0.8f * fabsf((float)cos(m_AnimTime * M_PI)); // TODO: should let artists tweak this + c.a *= 0.2f + 0.8f * fabsf(static_cast(cos(m_AnimTime * std::numbers::pi))); // TODO: should let artists tweak this m_BoundaryLines[i].overlay.m_Color = c; } } diff --git a/source/simulation2/components/tests/test_ObstructionManager.h b/source/simulation2/components/tests/test_ObstructionManager.h index b19c10486b..5d719f759d 100644 --- a/source/simulation2/components/tests/test_ObstructionManager.h +++ b/source/simulation2/components/tests/test_ObstructionManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -413,7 +414,7 @@ public: ent4z = fixed::Zero(), ent4w = fixed::FromInt(1), ent4h = fixed::FromInt(1); - entity_angle_t ent4a = fixed::FromDouble(M_PI/3); + entity_angle_t ent4a = fixed::FromDouble(std::numbers::pi / 3.); cmp->AddStaticShape(ent4, ent4x, ent4z, ent4a, ent4w, ent4h, ICmpObstructionManager::FLAG_BLOCK_PATHFINDING, ent4g1, ent4g2); cmp->SetStaticControlGroup(shape1, ent1g1, ent1g2_new); @@ -470,7 +471,7 @@ public: // Collision-test a shape that is perfectly adjacent to shape3. This should be counted as a hit according to // the code at the time of writing. - entity_angle_t ent4a = fixed::FromDouble(M_PI); // rotated 180 degrees, should not affect collision test + entity_angle_t ent4a = fixed::FromDouble(std::numbers::pi); // rotated 180 degrees, should not affect collision test entity_pos_t ent4w = fixed::FromInt(2), ent4h = fixed::FromInt(1), ent4x = ent3x + ent3c + ent4w/2, // make ent4 adjacent to ent3 diff --git a/source/simulation2/helpers/CinemaPath.cpp b/source/simulation2/helpers/CinemaPath.cpp index 5e2961e956..cd01c7e90c 100644 --- a/source/simulation2/helpers/CinemaPath.cpp +++ b/source/simulation2/helpers/CinemaPath.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -29,6 +29,7 @@ #include "ps/CStr.h" #include +#include #include #include @@ -196,7 +197,7 @@ float CCinemaPath::EaseCircle(float t) const float CCinemaPath::EaseSine(float t) const { - t = 1.0f - cos(t * (float)M_PI/2); + t = 1.0f - cos(t * std::numbers::pi_v / 2.f); if (m_GrowthCount > 1.0f) { --m_GrowthCount; diff --git a/source/simulation2/helpers/Render.cpp b/source/simulation2/helpers/Render.cpp index 16ea27c750..ed47c739cd 100644 --- a/source/simulation2/helpers/Render.cpp +++ b/source/simulation2/helpers/Render.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -39,6 +39,7 @@ #include #include +#include #include void SimRender::ConstructLineOnGround(const CSimContext& context, const std::vector& xz, @@ -128,7 +129,7 @@ void SimRender::ConstructCircleOnGround( const CSimContext& context, float x, float z, float radius, SOverlayLine& overlay, bool floating, float heightOffset) { - ConstructCircleOrClosedArc(context, x, z, radius, true, 0.0f, 2.0f*(float)M_PI, overlay, floating, heightOffset); + ConstructCircleOrClosedArc(context, x, z, radius, true, 0.0f, 2.0f * std::numbers::pi_v, overlay, floating, heightOffset); } void SimRender::ConstructClosedArcOnGround( @@ -260,7 +261,7 @@ void SimRender::ConstructGimbal(const CVector3D& center, float radius, SOverlayL out.m_Coords.clear(); size_t fullCircleSteps = numSteps; - const float angleIncrement = 2.f*M_PI/fullCircleSteps; + const float angleIncrement = 2.f * std::numbers::pi_v / fullCircleSteps; const CVector3D X_UNIT(1, 0, 0); const CVector3D Y_UNIT(0, 1, 0); @@ -625,10 +626,10 @@ void SimRender::ConstructTexturedLineCircle(SOverlayTexturedLine& overlay, const { const float radius = overlay_radius + overlay.m_Thickness / 3.f; - size_t numSteps = ceilf(float(2 * M_PI) * radius / (TERRAIN_TILE_SIZE / 3.f)); + size_t numSteps = ceilf(2.f * std::numbers::pi_v * radius / (TERRAIN_TILE_SIZE / 3.f)); for (size_t i = 0; i < numSteps; ++i) { - float angle = i * float(2 * M_PI) / numSteps; + float angle = i * 2.f * std::numbers::pi_v / numSteps; float px = origin.X + radius * sinf(angle); float pz = origin.Y + radius * cosf(angle); diff --git a/source/simulation2/helpers/VertexPathfinder.cpp b/source/simulation2/helpers/VertexPathfinder.cpp index 8522091f32..3f60048d43 100644 --- a/source/simulation2/helpers/VertexPathfinder.cpp +++ b/source/simulation2/helpers/VertexPathfinder.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include namespace @@ -975,7 +976,8 @@ void VertexPathfinderDebugOverlay::DebugRenderGraph(const CSimContext& simContex m_DebugOverlayShortPathLines.back(), true); else SimRender::ConstructClosedArcOnGround(simContext, x, z, 0.5f, - a0 * ((float)M_PI*2.0f), a1 * ((float)M_PI*2.0f), + a0 * (2.0f * std::numbers::pi_v), + a1 * (2.0f * std::numbers::pi_v), m_DebugOverlayShortPathLines.back(), true); } diff --git a/source/soundmanager/scripting/SoundGroup.cpp b/source/soundmanager/scripting/SoundGroup.cpp index 809eca59b2..061019f54f 100644 --- a/source/soundmanager/scripting/SoundGroup.cpp +++ b/source/soundmanager/scripting/SoundGroup.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -54,6 +54,7 @@ extern CGame *g_Game; #include #include +#include #include constexpr ALfloat DEFAULT_ROLLOFF = 0.5f; @@ -123,7 +124,7 @@ void CSoundGroup::SetDefaultValues() m_MinDist = CConfigDB::GetIfInitialised("sound.mindistance", 1.f); m_MaxDist = CConfigDB::GetIfInitialised("sound.maxdistance", 350.f); // This is more than the default camera FOV: for now, our soundscape is not realistic anyways. - m_MaxStereoAngle = CConfigDB::GetIfInitialised("sound.maxstereoangle", static_cast(M_PI / 6)); + m_MaxStereoAngle = CConfigDB::GetIfInitialised("sound.maxstereoangle", std::numbers::pi_v / 6.f); } CSoundGroup::CSoundGroup() diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp index 04c9d95e6e..ea9e021f6c 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -267,7 +268,7 @@ EnvironmentSidebar::EnvironmentSidebar( waterSizer->Add(new VariableSliderBox( waterBox, _("Water murkiness"), g_EnvironmentSettings.watermurkiness, 0.f, 1.f), wxSizerFlags().Expand()); waterSizer->Add(new VariableSliderBox( - waterBox, _("Wind angle"), g_EnvironmentSettings.windangle, -static_cast(M_PI), static_cast(M_PI)), wxSizerFlags().Expand()); + waterBox, _("Wind angle"), g_EnvironmentSettings.windangle, -std::numbers::pi_v, std::numbers::pi_v), wxSizerFlags().Expand()); waterSizer->Add(new VariableColorBox( waterBox, _("Water color"), g_EnvironmentSettings.watercolor), wxSizerFlags().Expand()); waterSizer->Add(new VariableColorBox( @@ -286,9 +287,9 @@ EnvironmentSidebar::EnvironmentSidebar( sunBoxSizer->Add(sunSizer, wxSizerFlags().Expand().Border(wxALL, 5)); sunSizer->Add(new VariableSliderBox( - sunBox, _("Sun rotation"), g_EnvironmentSettings.sunrotation, -static_cast(M_PI), static_cast(M_PI)), wxSizerFlags().Expand()); + sunBox, _("Sun rotation"), g_EnvironmentSettings.sunrotation, -std::numbers::pi_v, std::numbers::pi_v), wxSizerFlags().Expand()); sunSizer->Add(new VariableSliderBox( - sunBox, _("Sun elevation"), g_EnvironmentSettings.sunelevation, -static_cast(M_PI) / 2.0f, static_cast(M_PI) / 2.0f), wxSizerFlags().Expand()); + sunBox, _("Sun elevation"), g_EnvironmentSettings.sunelevation, -std::numbers::pi_v / 2.0f, std::numbers::pi_v / 2.0f), wxSizerFlags().Expand()); sunSizer->Add(new VariableSliderBox( sunBox, _("Sun overbrightness"), g_EnvironmentSettings.sunoverbrightness, 1.0f, 3.0f), wxSizerFlags().Expand()); sunSizer->Add(new LightControl( diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp index f81aeb770c..04acb7d93c 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,7 @@ class ActorViewerTool : public StateDrivenTool public: ActorViewerTool() : - m_Distance(20.f), m_Angle(0.f), m_Elevation((float)M_PI / 6.f), + m_Distance(20.f), m_Angle(0.f), m_Elevation(std::numbers::pi_v / 6.f), m_LastIsValid(false) { } @@ -132,12 +133,12 @@ public: obj->m_LastX = evt.GetX(); obj->m_LastY = evt.GetY(); - obj->m_Angle += dx * M_PI/256.f * ScenarioEditor::GetSpeedModifier(); + obj->m_Angle += dx * std::numbers::pi_v / 256.f * ScenarioEditor::GetSpeedModifier(); if (evt.ButtonIsDown(wxMOUSE_BTN_LEFT)) obj->m_Distance += dy / 8.f * ScenarioEditor::GetSpeedModifier(); else // evt.ButtonIsDown(wxMOUSE_BTN_RIGHT)) - obj->m_Elevation += dy * M_PI/256.f * ScenarioEditor::GetSpeedModifier(); + obj->m_Elevation += dy * std::numbers::pi_v / 256.f * ScenarioEditor::GetSpeedModifier(); camera_changed = true; } diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp index e00f3c6641..2137f7fe47 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -39,7 +40,7 @@ using AtlasMessage::Position; -static float g_DefaultAngle = (float)(M_PI*3.0/4.0); +static float g_DefaultAngle = std::numbers::pi_v * 3.f / 4.f; class PlaceObject : public StateDrivenTool { @@ -150,7 +151,7 @@ public: { if (m_RotationDirection) { - float speed = M_PI/2.f * ScenarioEditor::GetSpeedModifier(); // radians per second + float speed = std::numbers::pi_v / 2.f * ScenarioEditor::GetSpeedModifier(); // radians per second g_DefaultAngle += (m_RotationDirection * dt * speed); SendObjectMsg(true); } diff --git a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp index ffea3f6091..115f87a107 100644 --- a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -42,6 +42,7 @@ #include "tools/atlas/GameInterface/SharedTypes.h" #include +#include #include #include @@ -69,8 +70,8 @@ sEnvironmentSettings GetSettings() #undef COLOR float sunrotation = g_LightEnv.GetRotation(); - if (sunrotation > (float)M_PI) - sunrotation -= (float)M_PI*2; + if (sunrotation > std::numbers::pi_v) + sunrotation -= 2.f * std::numbers::pi_v; s.sunrotation = sunrotation; s.sunelevation = g_LightEnv.GetElevation();