summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/network/link.cpp5
-rw-r--r--game/network/network.cpp34
-rw-r--r--game/network/network.h42
-rw-r--r--game/network/network.impl.h16
4 files changed, 49 insertions, 48 deletions
diff --git a/game/network/link.cpp b/game/network/link.cpp
index dc9aecc..932fc67 100644
--- a/game/network/link.cpp
+++ b/game/network/link.cpp
@@ -63,12 +63,13 @@ LinkCurve::intersectRay(const Ray<GlobalPosition3D> & ray) const
const auto & e1p {ends[1].node->pos};
const auto slength = round_frac(length / 2.F, 5.F);
const auto segs = std::round(15.F * slength / std::pow(radius, 0.7F));
- const auto step {Position2D {arc_length(arc), e1p.z - e0p.z} / segs};
+ const auto step {glm::vec<2, RelativeDistance> {arc_length(arc), e1p.z - e0p.z} / segs};
auto segCount = static_cast<std::size_t>(std::lround(segs)) + 1;
std::vector<GlobalPosition3D> points;
points.reserve(segCount);
- for (Position2D swing = {arc.first, centreBase.z - e0p.z}; segCount; swing += step, --segCount) {
+ for (std::remove_const_t<decltype(step)> swing = {arc.first, centreBase.z - e0p.z}; segCount;
+ swing += step, --segCount) {
points.emplace_back(centreBase + GlobalPosition3D((sincosf(swing.x) * radius) || swing.y));
}
return ray.passesCloseToEdges(points, 1.F);
diff --git a/game/network/network.cpp b/game/network/network.cpp
index d52e804..8aa9adb 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -6,7 +6,6 @@
#include <game/network/link.h>
#include <gfx/models/texture.h>
#include <glm/gtx/intersect.hpp>
-#include <initializer_list>
#include <ray.h>
#include <stdexcept>
#include <utility>
@@ -14,13 +13,13 @@
Network::Network(const std::string & tn) : texture {Texture::cachedTexture.get(tn)} { }
Node::Ptr
-Network::nodeAt(Position3D pos)
+Network::nodeAt(GlobalPosition3D pos)
{
return newNodeAt(pos).first;
}
Network::NodeInsertion
-Network::newNodeAt(Position3D pos)
+Network::newNodeAt(GlobalPosition3D pos)
{
if (auto [n, i] = candidateNodeAt(pos); i == NodeIs::NotInNetwork) {
return {*nodes.insert(std::move(n)).first, i};
@@ -31,7 +30,7 @@ Network::newNodeAt(Position3D pos)
}
Node::Ptr
-Network::findNodeAt(Position3D pos) const
+Network::findNodeAt(GlobalPosition3D pos) const
{
if (const auto n = nodes.find(pos); n != nodes.end()) {
return *n;
@@ -40,7 +39,7 @@ Network::findNodeAt(Position3D pos) const
}
Network::NodeInsertion
-Network::candidateNodeAt(Position3D pos) const
+Network::candidateNodeAt(GlobalPosition3D pos) const
{
if (const auto n = nodes.find(pos); n != nodes.end()) {
return {*n, NodeIs::InNetwork};
@@ -80,7 +79,7 @@ Network::joinLinks(const Link::Ptr & l, const Link::Ptr & ol)
}
Link::Nexts
-Network::routeFromTo(const Link::End & start, Position3D dest) const
+Network::routeFromTo(const Link::End & start, GlobalPosition3D dest) const
{
auto destNode {findNodeAt(dest)};
if (!destNode) {
@@ -96,7 +95,7 @@ Network::routeFromTo(const Link::End & end, const Node::Ptr & dest) const
}
GenCurveDef
-Network::genCurveDef(const Position3D & start, const Position3D & end, float startDir)
+Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir)
{
const auto diff {end - start};
const auto vy {vector_yaw(diff)};
@@ -112,28 +111,29 @@ Network::genCurveDef(const Position3D & start, const Position3D & end, float sta
}
std::pair<GenCurveDef, GenCurveDef>
-Network::genCurveDef(const Position3D & start, const Position3D & end, float startDir, float endDir)
+Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir, float endDir)
{
startDir += pi;
endDir += pi;
- const Position2D flatStart {start.xy()}, flatEnd {end.xy()};
+ const auto flatStart {start.xy()}, flatEnd {end.xy()};
auto midheight = [&](auto mid) {
- const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid);
- return start.z + ((end.z - start.z) * (sm / (sm + em)));
+ const auto sm = glm::length(RelativePosition2D(flatStart - mid)),
+ em = glm::length(RelativePosition2D(flatEnd - mid));
+ return start.z + GlobalDistance(RelativeDistance(end.z - start.z) * (sm / (sm + em)));
};
if (const auto radii = find_arcs_radius(flatStart, startDir, flatEnd, endDir); radii.first < radii.second) {
const auto radius {radii.first};
- const auto c1 = flatStart + sincosf(startDir + half_pi) * radius;
- const auto c2 = flatEnd + sincosf(endDir + half_pi) * radius;
- const auto mid = (c1 + c2) / 2.F;
+ const auto c1 = flatStart + GlobalPosition2D(sincosf(startDir + half_pi) * radius);
+ const auto c2 = flatEnd + GlobalPosition2D(sincosf(endDir + half_pi) * radius);
+ const auto mid = (c1 + c2) / 2;
const auto midh = mid || midheight(mid);
return {{start, midh, c1}, {end, midh, c2}};
}
else {
const auto radius {radii.second};
- const auto c1 = flatStart + sincosf(startDir - half_pi) * radius;
- const auto c2 = flatEnd + sincosf(endDir - half_pi) * radius;
- const auto mid = (c1 + c2) / 2.F;
+ const auto c1 = flatStart + GlobalPosition2D(sincosf(startDir - half_pi) * radius);
+ const auto c2 = flatEnd + GlobalPosition2D(sincosf(endDir - half_pi) * radius);
+ const auto mid = (c1 + c2) / 2;
const auto midh = mid || midheight(mid);
return {{midh, start, c1}, {midh, end, c2}};
}
diff --git a/game/network/network.h b/game/network/network.h
index 9ce6e81..fa311ac 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -26,32 +26,32 @@ public:
virtual ~Network() = default;
DEFAULT_MOVE_NO_COPY(Network);
- [[nodiscard]] Node::Ptr findNodeAt(Position3D) const;
- [[nodiscard]] Node::Ptr nodeAt(Position3D);
+ [[nodiscard]] Node::Ptr findNodeAt(GlobalPosition3D) const;
+ [[nodiscard]] Node::Ptr nodeAt(GlobalPosition3D);
enum class NodeIs { InNetwork, NotInNetwork };
using NodeInsertion = std::pair<Node::Ptr, NodeIs>;
- [[nodiscard]] NodeInsertion newNodeAt(Position3D);
- [[nodiscard]] NodeInsertion candidateNodeAt(Position3D) const;
+ [[nodiscard]] NodeInsertion newNodeAt(GlobalPosition3D);
+ [[nodiscard]] NodeInsertion candidateNodeAt(GlobalPosition3D) const;
[[nodiscard]] virtual Link::Ptr intersectRayLinks(const Ray<GlobalPosition3D> &) const = 0;
[[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray<GlobalPosition3D> &) const;
- [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, Position3D) const;
+ [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, GlobalPosition3D) const;
[[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const Node::Ptr &) const;
- virtual Link::CCollection candidateStraight(Position3D, Position3D) = 0;
- virtual Link::CCollection candidateJoins(Position3D, Position3D) = 0;
- virtual Link::CCollection candidateExtend(Position3D, Position3D) = 0;
- virtual Link::CCollection addStraight(Position3D, Position3D) = 0;
- virtual Link::CCollection addJoins(Position3D, Position3D) = 0;
- virtual Link::CCollection addExtend(Position3D, Position3D) = 0;
+ virtual Link::CCollection candidateStraight(GlobalPosition3D, GlobalPosition3D) = 0;
+ virtual Link::CCollection candidateJoins(GlobalPosition3D, GlobalPosition3D) = 0;
+ virtual Link::CCollection candidateExtend(GlobalPosition3D, GlobalPosition3D) = 0;
+ virtual Link::CCollection addStraight(GlobalPosition3D, GlobalPosition3D) = 0;
+ virtual Link::CCollection addJoins(GlobalPosition3D, GlobalPosition3D) = 0;
+ virtual Link::CCollection addExtend(GlobalPosition3D, GlobalPosition3D) = 0;
[[nodiscard]] virtual float findNodeDirection(Node::AnyCPtr) const = 0;
protected:
static void joinLinks(const Link::Ptr & l, const Link::Ptr & ol);
- static GenCurveDef genCurveDef(const Position3D & start, const Position3D & end, float startDir);
+ static GenCurveDef genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir);
static std::pair<GenCurveDef, GenCurveDef> genCurveDef(
- const Position3D & start, const Position3D & end, float startDir, float endDir);
+ const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir, float endDir);
using Nodes = std::set<Node::Ptr, PtrMemberSorter<Node::Ptr, &Node::pos>>;
Nodes nodes;
@@ -71,7 +71,7 @@ protected:
public:
template<typename L, typename... Params>
std::shared_ptr<L>
- candidateLink(Position3D a, Position3D b, Params &&... params)
+ candidateLink(GlobalPosition3D a, GlobalPosition3D b, Params &&... params)
requires std::is_base_of_v<T, L>
{
const auto node1 = candidateNodeAt(a).first, node2 = candidateNodeAt(b).first;
@@ -80,7 +80,7 @@ public:
template<typename L, typename... Params>
std::shared_ptr<L>
- addLink(Position3D a, Position3D b, Params &&... params)
+ addLink(GlobalPosition3D a, GlobalPosition3D b, Params &&... params)
requires std::is_base_of_v<T, L>
{
const auto node1 = nodeAt(a), node2 = nodeAt(b);
@@ -89,12 +89,12 @@ public:
return l;
}
- Link::CCollection candidateStraight(Position3D n1, Position3D n2) override;
- Link::CCollection candidateJoins(Position3D, Position3D) override;
- Link::CCollection candidateExtend(Position3D, Position3D) override;
- Link::CCollection addStraight(Position3D n1, Position3D n2) override;
- Link::CCollection addJoins(Position3D, Position3D) override;
- Link::CCollection addExtend(Position3D, Position3D) override;
+ Link::CCollection candidateStraight(GlobalPosition3D n1, GlobalPosition3D n2) override;
+ Link::CCollection candidateJoins(GlobalPosition3D, GlobalPosition3D) override;
+ Link::CCollection candidateExtend(GlobalPosition3D, GlobalPosition3D) override;
+ Link::CCollection addStraight(GlobalPosition3D n1, GlobalPosition3D n2) override;
+ Link::CCollection addJoins(GlobalPosition3D, GlobalPosition3D) override;
+ Link::CCollection addExtend(GlobalPosition3D, GlobalPosition3D) override;
[[nodiscard]] float findNodeDirection(Node::AnyCPtr) const override;
diff --git a/game/network/network.impl.h b/game/network/network.impl.h
index 4acbb6d..f9595ed 100644
--- a/game/network/network.impl.h
+++ b/game/network/network.impl.h
@@ -54,16 +54,16 @@ NetworkOf<T>::findNodeDirection(Node::AnyCPtr n) const
template<typename T>
Link::CCollection
-NetworkOf<T>::candidateStraight(Position3D n1, Position3D n2)
+NetworkOf<T>::candidateStraight(GlobalPosition3D n1, GlobalPosition3D n2)
{
return {candidateLink<typename T::StraightLink>(n1, n2)};
}
template<typename T>
Link::CCollection
-NetworkOf<T>::candidateJoins(Position3D start, Position3D end)
+NetworkOf<T>::candidateJoins(GlobalPosition3D start, GlobalPosition3D end)
{
- if (glm::distance(start, end) < 2.F) {
+ if (glm::length(RelativePosition3D(start - end)) < 2000.F) {
return {};
}
const auto defs = genCurveDef(
@@ -75,7 +75,7 @@ NetworkOf<T>::candidateJoins(Position3D start, Position3D end)
template<typename T>
Link::CCollection
-NetworkOf<T>::candidateExtend(Position3D start, Position3D end)
+NetworkOf<T>::candidateExtend(GlobalPosition3D start, GlobalPosition3D end)
{
const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(candidateNodeAt(start).first));
return {candidateLink<typename T::CurveLink>(cstart, cend, centre)};
@@ -83,16 +83,16 @@ NetworkOf<T>::candidateExtend(Position3D start, Position3D end)
template<typename T>
Link::CCollection
-NetworkOf<T>::addStraight(Position3D n1, Position3D n2)
+NetworkOf<T>::addStraight(GlobalPosition3D n1, GlobalPosition3D n2)
{
return {addLink<typename T::StraightLink>(n1, n2)};
}
template<typename T>
Link::CCollection
-NetworkOf<T>::addJoins(Position3D start, Position3D end)
+NetworkOf<T>::addJoins(GlobalPosition3D start, GlobalPosition3D end)
{
- if (glm::distance(start, end) < 2.F) {
+ if (glm::length(RelativePosition3D(start - end)) < 2000.F) {
return {};
}
const auto defs = genCurveDef(start, end, findNodeDirection(nodeAt(start)), findNodeDirection(nodeAt(end)));
@@ -103,7 +103,7 @@ NetworkOf<T>::addJoins(Position3D start, Position3D end)
template<typename T>
Link::CCollection
-NetworkOf<T>::addExtend(Position3D start, Position3D end)
+NetworkOf<T>::addExtend(GlobalPosition3D start, GlobalPosition3D end)
{
const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(nodeAt(start)));
return {addLink<typename T::CurveLink>(cstart, cend, centre)};