From 1e7a924874050674a103f6927f4a3c5ef6459222 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 13 Jun 2025 21:53:32 +0100 Subject: Create a list of snap points for the existing network These form key positions in the world to ease neat creation. --- game/network/network.h | 14 ++++++++++++++ game/network/rail.cpp | 16 ++++++++++++++++ game/network/rail.h | 1 + 3 files changed, 31 insertions(+) (limited to 'game') diff --git a/game/network/network.h b/game/network/network.h index d3370b3..7bfd2ce 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -35,6 +35,19 @@ struct CreationDefinition { CreationDefinitionEnd toEnd; }; +struct SnapPoint : CreationDefinitionEnd { + template + requires std::is_constructible_v + explicit SnapPoint(GlobalPosition3D snapPosition, CDE &&... cde) : + CreationDefinitionEnd {std::forward(cde)...}, snapPosition(snapPosition) + { + } + + GlobalPosition3D snapPosition; +}; + +using SnapPoints = std::vector; + class Network { public: using LinkEnd = std::pair; @@ -55,6 +68,7 @@ public: [[nodiscard]] static Link::Nexts routeFromTo(const Link::End &, const Node::Ptr &); [[nodiscard]] virtual float findNodeDirection(Node::AnyCPtr) const = 0; + [[nodiscard]] virtual SnapPoints getSnapPoints() const = 0; [[nodiscard]] Link::Collection create(const GeoData *, const CreationDefinition &); [[nodiscard]] Link::Collection createChain(const GeoData *, std::span); diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 342a2ad..45d55d6 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -137,3 +137,19 @@ RailLinks::getBaseWidth() const static constexpr auto BASE_WIDTH = 5'700; return BASE_WIDTH; } + +SnapPoints +RailLinks::getSnapPoints() const +{ + static constexpr auto EXTENSION_SNAP_DIST = 1'200.F; + SnapPoints out; + for (const auto & link : links) { + for (const auto & end : link->ends) { + // Link end node; directionless, suitable crossings + out.emplace_back(end.node->pos, end.node->pos, std::nullopt); + // Link end; with direction, suitable for continuing/joining + out.emplace_back(end.node->pos - ((sincos(end.dir) * EXTENSION_SNAP_DIST) || 0.F), end.node->pos, end.dir); + } + } + return out; +} diff --git a/game/network/rail.h b/game/network/rail.h index 15b9ae4..48b1410 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -78,6 +78,7 @@ public: [[nodiscard]] const Surface * getBaseSurface() const override; [[nodiscard]] RelativeDistance getBaseWidth() const override; + [[nodiscard]] SnapPoints getSnapPoints() const override; private: void tick(TickDuration elapsed) override; -- cgit v1.2.3