summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-12-24 15:02:10 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-12-24 15:02:10 +0000
commit485143ae90aa692aef47c1c7aba8775818a026aa (patch)
tree4f5781af844500d1dcff2efbce248b3020c0705b /game
parentGenerate mipmaps if min/mag filter settings use them (diff)
downloadilt-485143ae90aa692aef47c1c7aba8775818a026aa.tar.bz2
ilt-485143ae90aa692aef47c1c7aba8775818a026aa.tar.xz
ilt-485143ae90aa692aef47c1c7aba8775818a026aa.zip
Fix calculations for sleeper texture coords
Diffstat (limited to 'game')
-rw-r--r--game/network/rail.cpp22
1 files changed, 14 insertions, 8 deletions
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<float, RAIL_CROSSSECTION_VERTICES> 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<std::floating_point T> constexpr T SLEEPERS_PER_TEXTURE {5};
+ template<std::floating_point T> constexpr T TEXTURE_LENGTH {2'000};
+ template<std::floating_point T> constexpr T SLEEPER_LENGTH {T {1} / SLEEPERS_PER_TEXTURE<T>};
+
+ template<std::floating_point T>
+ constexpr auto
+ roundSleepers(const T length)
+ {
+ return round_frac(length / TEXTURE_LENGTH<T>, SLEEPER_LENGTH<T>);
+ }
}
RailLinkStraight::RailLinkStraight(NetworkLinkHolder<RailLinkStraight> & instances, const Node::Ptr & a,
@@ -106,7 +113,7 @@ RailLinkStraight::RailLinkStraight(
NetworkLinkHolder<RailLinkStraight> & 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<RailLinkCurve> & 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)}
{
}