From 485143ae90aa692aef47c1c7aba8775818a026aa Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 24 Dec 2024 15:02:10 +0000 Subject: Fix calculations for sleeper texture coords --- game/network/rail.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'game') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index dc62cf3..baf48f3 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -91,10 +91,17 @@ constexpr const std::array railTexturePos { }; constexpr auto sleepers {5.F}; // There are 5 repetitions of sleepers in the texture -inline auto -round_sleepers(const float v) -{ - return round_frac(v, sleepers); +namespace { + template constexpr T SLEEPERS_PER_TEXTURE {5}; + template constexpr T TEXTURE_LENGTH {2'000}; + template constexpr T SLEEPER_LENGTH {T {1} / SLEEPERS_PER_TEXTURE}; + + template + constexpr auto + roundSleepers(const T length) + { + return round_frac(length / TEXTURE_LENGTH, SLEEPER_LENGTH); + } } RailLinkStraight::RailLinkStraight(NetworkLinkHolder & instances, const Node::Ptr & a, @@ -106,7 +113,7 @@ RailLinkStraight::RailLinkStraight( NetworkLinkHolder & instances, Node::Ptr a, Node::Ptr b, const RelativePosition3D & diff) : Link({std::move(a), vector_yaw(diff)}, {std::move(b), vector_yaw(-diff)}, glm::length(diff)), instance {instances.vertices.acquire( - ends[0].node->pos, ends[1].node->pos, flat_orientation(diff), round_sleepers(length / 2000.F))} + ends[0].node->pos, ends[1].node->pos, flat_orientation(diff), roundSleepers(length))} { } @@ -120,9 +127,8 @@ RailLinkCurve::RailLinkCurve(NetworkLinkHolder & instances, const GlobalPosition3D c, RelativeDistance radius, const Arc arc) : Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)}, glm::length(RelativePosition2D {radius * arc.length(), difference(a->pos, b->pos).z})), - LinkCurve {c, radius, arc}, - instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, round_sleepers(length / 2000.F), - half_pi - arc.first, half_pi - arc.second, radius)} + LinkCurve {c, radius, arc}, instance {instances.vertices.acquire(ends[0].node->pos, ends[1].node->pos, c, + roundSleepers(length), half_pi - arc.first, half_pi - arc.second, radius)} { } -- cgit v1.2.3