From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- game/network/link.h | 12 ++++++------ game/network/network.h | 42 +++++++++++++++++++++--------------------- game/network/network.impl.h | 12 ++++++------ game/network/rail.h | 10 +++++----- 4 files changed, 38 insertions(+), 38 deletions(-) (limited to 'game/network') diff --git a/game/network/link.h b/game/network/link.h index 0d66c42..78d3e91 100644 --- a/game/network/link.h +++ b/game/network/link.h @@ -17,12 +17,12 @@ class Ray; // it has location class Node : public StdTypeDefs { public: - explicit Node(glm::vec3 p) noexcept : pos(p) {}; + explicit Node(Position3D p) noexcept : pos(p) {}; virtual ~Node() noexcept = default; NO_COPY(Node); NO_MOVE(Node); - glm::vec3 pos; + Position3D pos; }; // Generic network link @@ -51,14 +51,14 @@ public: float length; protected: - [[nodiscard]] virtual glm::vec3 + [[nodiscard]] virtual Position3D vehiclePositionOffset() const { return {}; } }; -bool operator<(const glm::vec3 & a, const glm::vec3 & b); +bool operator<(const Position3D & a, const Position3D & b); bool operator<(const Node & a, const Node & b); class LinkStraight : public virtual Link { @@ -77,14 +77,14 @@ LinkStraight::~LinkStraight() = default; class LinkCurve : public virtual Link { public: inline ~LinkCurve() override = 0; - LinkCurve(glm::vec3, float, Arc); + LinkCurve(Position3D, float, Arc); NO_COPY(LinkCurve); NO_MOVE(LinkCurve); [[nodiscard]] Location positionAt(float dist, unsigned char start) const override; [[nodiscard]] bool intersectRay(const Ray &) const override; - glm::vec3 centreBase; + Position3D centreBase; float radius; Arc arc; }; diff --git a/game/network/network.h b/game/network/network.h index b9316eb..02f8c30 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(glm::vec3) const; - [[nodiscard]] Node::Ptr nodeAt(glm::vec3); + [[nodiscard]] Node::Ptr findNodeAt(Position3D) const; + [[nodiscard]] Node::Ptr nodeAt(Position3D); enum class NodeIs { InNetwork, NotInNetwork }; using NodeInsertion = std::pair; - [[nodiscard]] NodeInsertion newNodeAt(glm::vec3); - [[nodiscard]] NodeInsertion candidateNodeAt(glm::vec3) const; + [[nodiscard]] NodeInsertion newNodeAt(Position3D); + [[nodiscard]] NodeInsertion candidateNodeAt(Position3D) const; [[nodiscard]] virtual Link::Ptr intersectRayLinks(const Ray &) const = 0; [[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray &) const; - [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, glm::vec3) const; + [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, Position3D) const; [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const Node::Ptr &) const; - virtual Link::CCollection candidateStraight(glm::vec3, glm::vec3) = 0; - virtual Link::CCollection candidateJoins(glm::vec3, glm::vec3) = 0; - virtual Link::CCollection candidateExtend(glm::vec3, glm::vec3) = 0; - virtual Link::CCollection addStraight(glm::vec3, glm::vec3) = 0; - virtual Link::CCollection addJoins(glm::vec3, glm::vec3) = 0; - virtual Link::CCollection addExtend(glm::vec3, glm::vec3) = 0; + 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; [[nodiscard]] virtual float findNodeDirection(Node::AnyCPtr) const = 0; protected: static void joinLinks(const Link::Ptr & l, const Link::Ptr & ol); - static GenCurveDef genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir); + static GenCurveDef genCurveDef(const Position3D & start, const Position3D & end, float startDir); static std::pair genCurveDef( - const glm::vec3 & start, const glm::vec3 & end, float startDir, float endDir); + const Position3D & start, const Position3D & end, float startDir, float endDir); using Nodes = std::set>; Nodes nodes; @@ -71,7 +71,7 @@ protected: public: template std::shared_ptr - candidateLink(glm::vec3 a, glm::vec3 b, Params &&... params) + candidateLink(Position3D a, Position3D b, Params &&... params) requires std::is_base_of_v { const auto node1 = candidateNodeAt(a).first, node2 = candidateNodeAt(b).first; @@ -80,7 +80,7 @@ public: template std::shared_ptr - addLink(glm::vec3 a, glm::vec3 b, Params &&... params) + addLink(Position3D a, Position3D b, Params &&... params) requires std::is_base_of_v { const auto node1 = nodeAt(a), node2 = nodeAt(b); @@ -89,12 +89,12 @@ public: return l; } - Link::CCollection candidateStraight(glm::vec3 n1, glm::vec3 n2) override; - Link::CCollection candidateJoins(glm::vec3, glm::vec3) override; - Link::CCollection candidateExtend(glm::vec3, glm::vec3) override; - Link::CCollection addStraight(glm::vec3 n1, glm::vec3 n2) override; - Link::CCollection addJoins(glm::vec3, glm::vec3) override; - Link::CCollection addExtend(glm::vec3, glm::vec3) override; + 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; [[nodiscard]] float findNodeDirection(Node::AnyCPtr) const override; diff --git a/game/network/network.impl.h b/game/network/network.impl.h index 045335f..8e9e85c 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -54,14 +54,14 @@ NetworkOf::findNodeDirection(Node::AnyCPtr n) const template Link::CCollection -NetworkOf::candidateStraight(glm::vec3 n1, glm::vec3 n2) +NetworkOf::candidateStraight(Position3D n1, Position3D n2) { return {candidateLink(n1, n2)}; } template Link::CCollection -NetworkOf::candidateJoins(glm::vec3 start, glm::vec3 end) +NetworkOf::candidateJoins(Position3D start, Position3D end) { if (glm::distance(start, end) < 2.F) { return {}; @@ -75,7 +75,7 @@ NetworkOf::candidateJoins(glm::vec3 start, glm::vec3 end) template Link::CCollection -NetworkOf::candidateExtend(glm::vec3 start, glm::vec3 end) +NetworkOf::candidateExtend(Position3D start, Position3D end) { const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(candidateNodeAt(start).first)); return {candidateLink(cstart, cend, centre)}; @@ -83,14 +83,14 @@ NetworkOf::candidateExtend(glm::vec3 start, glm::vec3 end) template Link::CCollection -NetworkOf::addStraight(glm::vec3 n1, glm::vec3 n2) +NetworkOf::addStraight(Position3D n1, Position3D n2) { return {addLink(n1, n2)}; } template Link::CCollection -NetworkOf::addJoins(glm::vec3 start, glm::vec3 end) +NetworkOf::addJoins(Position3D start, Position3D end) { if (glm::distance(start, end) < 2.F) { return {}; @@ -103,7 +103,7 @@ NetworkOf::addJoins(glm::vec3 start, glm::vec3 end) template Link::CCollection -NetworkOf::addExtend(glm::vec3 start, glm::vec3 end) +NetworkOf::addExtend(Position3D start, Position3D end) { const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(nodeAt(start))); return {addLink(cstart, cend, centre)}; diff --git a/game/network/rail.h b/game/network/rail.h index 6684801..4a1932f 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -32,7 +32,7 @@ public: NO_MOVE(RailLink); protected: - [[nodiscard]] glm::vec3 vehiclePositionOffset() const override; + [[nodiscard]] Position3D vehiclePositionOffset() const override; [[nodiscard]] static Mesh::Ptr defaultMesh(const std::span vertices); Mesh::Ptr mesh; @@ -45,22 +45,22 @@ public: RailLinkStraight(const Node::Ptr &, const Node::Ptr &); private: - RailLinkStraight(Node::Ptr, Node::Ptr, const glm::vec3 & diff); + RailLinkStraight(Node::Ptr, Node::Ptr, const Position3D & diff); }; class RailLinkCurve : public RailLink, public LinkCurve { public: - RailLinkCurve(const Node::Ptr &, const Node::Ptr &, glm::vec2); + RailLinkCurve(const Node::Ptr &, const Node::Ptr &, Position2D); private: - RailLinkCurve(const Node::Ptr &, const Node::Ptr &, glm::vec3, const Arc); + RailLinkCurve(const Node::Ptr &, const Node::Ptr &, Position3D, const Arc); }; class RailLinks : public NetworkOf, public WorldObject { public: RailLinks(); - std::shared_ptr addLinksBetween(glm::vec3 start, glm::vec3 end); + std::shared_ptr addLinksBetween(Position3D start, Position3D end); private: void tick(TickDuration elapsed) override; -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- game/network/link.cpp | 14 +++++++------- game/network/network.cpp | 18 +++++++++--------- game/network/rail.cpp | 30 +++++++++++++++--------------- 3 files changed, 31 insertions(+), 31 deletions(-) (limited to 'game/network') diff --git a/game/network/link.cpp b/game/network/link.cpp index bb27a52..498afe4 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -8,10 +8,10 @@ Link::Link(End a, End b, float l) : ends {{std::move(a), std::move(b)}}, length {l} { } -LinkCurve::LinkCurve(glm::vec3 c, float r, Arc a) : centreBase {c}, radius {r}, arc {std::move(a)} { } +LinkCurve::LinkCurve(Position3D c, float r, Arc a) : centreBase {c}, radius {r}, arc {std::move(a)} { } bool -operator<(const glm::vec3 & a, const glm::vec3 & b) +operator<(const Position3D & a, const Position3D & b) { // NOLINTNEXTLINE(hicpp-use-nullptr,modernize-use-nullptr) return std::tie(a.x, a.y, a.z) < std::tie(b.x, b.y, b.z); @@ -48,7 +48,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const const auto ang {as.first + ((as.second - as.first) * frac)}; const auto relPos {!sincosf(ang) * radius}; const auto relClimb {vehiclePositionOffset() - + glm::vec3 {0, 0, es.first->pos.z - centreBase.z + ((es.second->pos.z - es.first->pos.z) * frac)}}; + + Position3D {0, 0, es.first->pos.z - centreBase.z + ((es.second->pos.z - es.first->pos.z) * frac)}}; const auto pitch {vector_pitch({0, 0, (es.second->pos.z - es.first->pos.z) / length})}; return Location {relPos + relClimb + centreBase, {pitch, normalize(ang + dirOffset[start]), 0}}; } @@ -60,14 +60,14 @@ LinkCurve::intersectRay(const Ray & 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 {glm::vec3 {arc_length(arc), e1p.z - e0p.z, slength} / segs}; + const auto step {Position3D {arc_length(arc), e1p.z - e0p.z, slength} / segs}; const auto trans {glm::translate(centreBase)}; auto segCount = static_cast(std::lround(segs)) + 1; - std::vector points; + std::vector points; points.reserve(segCount); - for (glm::vec3 swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) { - const auto t {trans * glm::rotate(half_pi - swing.x, up) * glm::translate(glm::vec3 {radius, 0.F, swing.y})}; + for (Position3D swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) { + const auto t {trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})}; points.emplace_back(t * glm::vec4 {0, 0, 0, 1}); } return ray.passesCloseToEdges(points, 1.F); diff --git a/game/network/network.cpp b/game/network/network.cpp index 083b08e..d18345c 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -14,13 +14,13 @@ Network::Network(const std::string & tn) : texture {Texture::cachedTexture.get(tn)} { } Node::Ptr -Network::nodeAt(glm::vec3 pos) +Network::nodeAt(Position3D pos) { return newNodeAt(pos).first; } Network::NodeInsertion -Network::newNodeAt(glm::vec3 pos) +Network::newNodeAt(Position3D pos) { if (auto [n, i] = candidateNodeAt(pos); i == NodeIs::NotInNetwork) { return {*nodes.insert(std::move(n)).first, i}; @@ -31,7 +31,7 @@ Network::newNodeAt(glm::vec3 pos) } Node::Ptr -Network::findNodeAt(glm::vec3 pos) const +Network::findNodeAt(Position3D pos) const { if (const auto n = nodes.find(pos); n != nodes.end()) { return *n; @@ -40,7 +40,7 @@ Network::findNodeAt(glm::vec3 pos) const } Network::NodeInsertion -Network::candidateNodeAt(glm::vec3 pos) const +Network::candidateNodeAt(Position3D pos) const { if (const auto n = nodes.find(pos); n != nodes.end()) { return {*n, NodeIs::InNetwork}; @@ -54,7 +54,7 @@ Network::intersectRayNodes(const Ray & ray) const // Click within 2m of a node if (const auto node = std::find_if(nodes.begin(), nodes.end(), [&ray](const Node::Ptr & node) { - glm::vec3 ipos, inorm; + Position3D ipos, inorm; return glm::intersectRaySphere(ray.start, ray.direction, node->pos, 2.F, ipos, inorm); }); node != nodes.end()) { @@ -79,7 +79,7 @@ Network::joinLinks(const Link::Ptr & l, const Link::Ptr & ol) } Link::Nexts -Network::routeFromTo(const Link::End & start, glm::vec3 dest) const +Network::routeFromTo(const Link::End & start, Position3D dest) const { auto destNode {findNodeAt(dest)}; if (!destNode) { @@ -95,7 +95,7 @@ Network::routeFromTo(const Link::End & end, const Node::Ptr & dest) const } GenCurveDef -Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir) +Network::genCurveDef(const Position3D & start, const Position3D & end, float startDir) { const auto diff {end - start}; const auto vy {vector_yaw(diff)}; @@ -111,11 +111,11 @@ Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float start } std::pair -Network::genCurveDef(const glm::vec3 & start, const glm::vec3 & end, float startDir, float endDir) +Network::genCurveDef(const Position3D & start, const Position3D & end, float startDir, float endDir) { startDir += pi; endDir += pi; - const glm::vec2 flatStart {!start}, flatEnd {!end}; + const Position2D flatStart {!start}, flatEnd {!end}; 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))); diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 5a4f1e1..f46504b 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -18,7 +18,7 @@ template class NetworkOf; constexpr auto RAIL_CROSSSECTION_VERTICES {5U}; -constexpr glm::vec3 RAIL_HEIGHT {0, 0, .25F}; +constexpr Size3D RAIL_HEIGHT {0, 0, .25F}; RailLinks::RailLinks() : NetworkOf {"rails.jpg"} { } @@ -28,7 +28,7 @@ RailLinks::tick(TickDuration) } std::shared_ptr -RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end) +RailLinks::addLinksBetween(Position3D start, Position3D end) { auto node1ins = newNodeAt(start), node2ins = newNodeAt(end); if (node1ins.second == NodeIs::NotInNetwork && node2ins.second == NodeIs::NotInNetwork) { @@ -45,7 +45,7 @@ RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end) if (dir == vector_yaw(end - start)) { return addLink(start, end); } - const glm::vec2 flatStart {!start}, flatEnd {!end}; + const Position2D flatStart {!start}, flatEnd {!end}; if (node2ins.second == NodeIs::InNetwork) { auto midheight = [&](auto mid) { const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid); @@ -100,7 +100,7 @@ RailLink::render(const SceneShader &) const mesh->Draw(); } -constexpr const std::array, RAIL_CROSSSECTION_VERTICES> railCrossSection {{ +constexpr const std::array, RAIL_CROSSSECTION_VERTICES> railCrossSection {{ // ___________ // _/ \_ // left to right @@ -122,7 +122,7 @@ RailLinkStraight::RailLinkStraight(const Node::Ptr & a, const Node::Ptr & b) : R { } -RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const glm::vec3 & diff) : +RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & diff) : Link({std::move(a), vector_yaw(diff)}, {std::move(b), vector_yaw(-diff)}, glm::length(diff)) { if (glGenVertexArrays) { @@ -133,20 +133,20 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const glm::vec3 & d for (auto ei : {1U, 0U}) { const auto trans {glm::translate(ends[ei].node->pos) * e}; for (const auto & rcs : railCrossSection) { - const glm::vec3 m {(trans * glm::vec4 {rcs.first, 1})}; - vertices.emplace_back(m, glm::vec2 {rcs.second, len * static_cast(ei)}, up); + const Position3D m {(trans * glm::vec4 {rcs.first, 1})}; + vertices.emplace_back(m, Position2D {rcs.second, len * static_cast(ei)}, up); } } mesh = defaultMesh(vertices); } } -RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec2 c) : +RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position2D c) : RailLinkCurve(a, b, c ^ a->pos.z, {!c, a->pos, b->pos}) { } -RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec3 c, const Arc arc) : +RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position3D c, const Arc arc) : Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)}, (glm::length(a->pos - c)) * arc_length(arc)), LinkCurve {c, glm::length(ends[0].node->pos - c), arc} @@ -156,25 +156,25 @@ RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec3 const auto & e1p {ends[1].node->pos}; const auto slength = round_sleepers(length / 2.F); const auto segs = std::round(15.F * slength / std::pow(radius, 0.7F)); - const auto step {glm::vec3 {arc_length(arc), e1p.z - e0p.z, slength} / segs}; + const auto step {Position3D {arc_length(arc), e1p.z - e0p.z, slength} / segs}; const auto trans {glm::translate(centreBase)}; auto segCount = static_cast(std::lround(segs)) + 1; std::vector vertices; vertices.reserve(segCount * railCrossSection.size()); - for (glm::vec3 swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) { + for (Position3D swing = {arc.first, centreBase.z - e0p.z, 0.F}; segCount; swing += step, --segCount) { const auto t { - trans * glm::rotate(half_pi - swing.x, up) * glm::translate(glm::vec3 {radius, 0.F, swing.y})}; + trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})}; for (const auto & rcs : railCrossSection) { - const glm::vec3 m {(t * glm::vec4 {rcs.first, 1})}; - vertices.emplace_back(m, glm::vec2 {rcs.second, swing.z}, up); + const Position3D m {(t * glm::vec4 {rcs.first, 1})}; + vertices.emplace_back(m, Position2D {rcs.second, swing.z}, up); } } mesh = defaultMesh(vertices); } } -glm::vec3 +Position3D RailLink::vehiclePositionOffset() const { return RAIL_HEIGHT; -- cgit v1.2.3 From d771fbda2c171cfbc36cc0eb3122c1a02ffbb081 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 01:57:27 +0000 Subject: WIP typedefing just about everything else --- game/network/network.h | 2 +- game/network/rail.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'game/network') diff --git a/game/network/network.h b/game/network/network.h index 02f8c30..8af06a9 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -16,7 +16,7 @@ class Texture; class SceneShader; class Ray; -template using GenDef = std::tuple...>; +template using GenDef = std::tuple...>; using GenCurveDef = GenDef<3, 3, 2>; class Network { diff --git a/game/network/rail.cpp b/game/network/rail.cpp index f46504b..cc61db9 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -133,7 +133,7 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & for (auto ei : {1U, 0U}) { const auto trans {glm::translate(ends[ei].node->pos) * e}; for (const auto & rcs : railCrossSection) { - const Position3D m {(trans * glm::vec4 {rcs.first, 1})}; + const Position3D m {(trans * (rcs.first ^ 1))}; vertices.emplace_back(m, Position2D {rcs.second, len * static_cast(ei)}, up); } } @@ -166,7 +166,7 @@ RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position3 const auto t { trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})}; for (const auto & rcs : railCrossSection) { - const Position3D m {(t * glm::vec4 {rcs.first, 1})}; + const Position3D m {(t * (rcs.first ^ 1))}; vertices.emplace_back(m, Position2D {rcs.second, swing.z}, up); } } -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- game/network/rail.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'game/network') diff --git a/game/network/rail.cpp b/game/network/rail.cpp index cc61db9..ff101d4 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -18,7 +18,7 @@ template class NetworkOf; constexpr auto RAIL_CROSSSECTION_VERTICES {5U}; -constexpr Size3D RAIL_HEIGHT {0, 0, .25F}; +constexpr Size3D RAIL_HEIGHT {0, 0, 250.F}; RailLinks::RailLinks() : NetworkOf {"rails.jpg"} { } @@ -104,11 +104,11 @@ constexpr const std::array, RAIL_CROSSSECTION_VERTI // ___________ // _/ \_ // left to right - {{-1.9F, 0.F, 0.F}, 0.F}, - {{-.608F, 0.F, RAIL_HEIGHT.z}, 0.34F}, - {{0, 0.F, RAIL_HEIGHT.z * .7F}, 0.5F}, - {{.608F, 0.F, RAIL_HEIGHT.z}, 0.66F}, - {{1.9F, 0.F, 0.F}, 1.F}, + {{-1900.F, 0.F, 0.F}, 0.F}, + {{-608.F, 0.F, RAIL_HEIGHT.z}, .34F}, + {{0, 0.F, RAIL_HEIGHT.z * .7F}, .5F}, + {{608.F, 0.F, RAIL_HEIGHT.z}, .66F}, + {{1900.F, 0.F, 0.F}, 1.F}, }}; constexpr auto sleepers {5.F}; // There are 5 repetitions of sleepers in the texture @@ -128,7 +128,7 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & if (glGenVertexArrays) { std::vector vertices; vertices.reserve(2 * railCrossSection.size()); - const auto len = round_sleepers(length / 2.F); + const auto len = round_sleepers(length / 2000.F); const auto e {flat_orientation(diff)}; for (auto ei : {1U, 0U}) { const auto trans {glm::translate(ends[ei].node->pos) * e}; @@ -155,8 +155,8 @@ RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position3 const auto & e0p {ends[0].node->pos}; const auto & e1p {ends[1].node->pos}; const auto slength = round_sleepers(length / 2.F); - const auto segs = std::round(15.F * slength / std::pow(radius, 0.7F)); - const auto step {Position3D {arc_length(arc), e1p.z - e0p.z, slength} / segs}; + const auto segs = std::round(slength / std::pow(radius, 0.7F)); + const auto step {Position3D {arc_length(arc), e1p.z - e0p.z, slength / 1000.F} / segs}; const auto trans {glm::translate(centreBase)}; auto segCount = static_cast(std::lround(segs)) + 1; -- cgit v1.2.3 From 0841ead91c49a212134f19f7c0b411984b0fda29 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 29 Dec 2023 13:20:55 +0000 Subject: Remove weird operator! on vec2/3 --- game/network/link.cpp | 2 +- game/network/network.cpp | 4 ++-- game/network/rail.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'game/network') diff --git a/game/network/link.cpp b/game/network/link.cpp index 498afe4..d8479dd 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -46,7 +46,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const const auto es {std::make_pair(ends[start].node.get(), ends[1 - start].node.get())}; const auto as {std::make_pair(arc[start], arc[1 - start])}; const auto ang {as.first + ((as.second - as.first) * frac)}; - const auto relPos {!sincosf(ang) * radius}; + const auto relPos {sincosf(ang) ^ 0.F * radius}; const auto relClimb {vehiclePositionOffset() + Position3D {0, 0, es.first->pos.z - centreBase.z + ((es.second->pos.z - es.first->pos.z) * frac)}}; const auto pitch {vector_pitch({0, 0, (es.second->pos.z - es.first->pos.z) / length})}; diff --git a/game/network/network.cpp b/game/network/network.cpp index d18345c..5de2f5d 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -100,7 +100,7 @@ Network::genCurveDef(const Position3D & start, const Position3D & end, float sta const auto diff {end - start}; const auto vy {vector_yaw(diff)}; const auto dir = pi + startDir; - const auto flatStart {!start}, flatEnd {!end}; + const auto flatStart {start.xy()}, flatEnd {end.xy()}; const auto n2ed {(vy * 2) - dir - pi}; const auto centre {find_arc_centre(flatStart, dir, flatEnd, n2ed)}; @@ -115,7 +115,7 @@ Network::genCurveDef(const Position3D & start, const Position3D & end, float sta { startDir += pi; endDir += pi; - const Position2D flatStart {!start}, flatEnd {!end}; + const Position2D 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))); diff --git a/game/network/rail.cpp b/game/network/rail.cpp index ff101d4..545a728 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -45,7 +45,7 @@ RailLinks::addLinksBetween(Position3D start, Position3D end) if (dir == vector_yaw(end - start)) { return addLink(start, end); } - const Position2D flatStart {!start}, flatEnd {!end}; + const Position2D flatStart {start.xy()}, flatEnd {end.xy()}; if (node2ins.second == NodeIs::InNetwork) { auto midheight = [&](auto mid) { const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid); @@ -142,7 +142,7 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & } RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position2D c) : - RailLinkCurve(a, b, c ^ a->pos.z, {!c, a->pos, b->pos}) + RailLinkCurve(a, b, c ^ a->pos.z, {c ^ 0.F, a->pos, b->pos}) { } -- cgit v1.2.3 From 048f18e2a0b32044525cef41fa053984433c74b9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 29 Dec 2023 14:12:40 +0000 Subject: Remove misleading power operator^ on vec2/3 --- game/network/link.cpp | 2 +- game/network/network.cpp | 4 ++-- game/network/rail.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'game/network') diff --git a/game/network/link.cpp b/game/network/link.cpp index d8479dd..703a1ca 100644 --- a/game/network/link.cpp +++ b/game/network/link.cpp @@ -46,7 +46,7 @@ LinkCurve::positionAt(float dist, unsigned char start) const const auto es {std::make_pair(ends[start].node.get(), ends[1 - start].node.get())}; const auto as {std::make_pair(arc[start], arc[1 - start])}; const auto ang {as.first + ((as.second - as.first) * frac)}; - const auto relPos {sincosf(ang) ^ 0.F * radius}; + const auto relPos {(sincosf(ang) || 0.F) * radius}; const auto relClimb {vehiclePositionOffset() + Position3D {0, 0, es.first->pos.z - centreBase.z + ((es.second->pos.z - es.first->pos.z) * frac)}}; const auto pitch {vector_pitch({0, 0, (es.second->pos.z - es.first->pos.z) / length})}; diff --git a/game/network/network.cpp b/game/network/network.cpp index 5de2f5d..1ff5b26 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -125,7 +125,7 @@ Network::genCurveDef(const Position3D & start, const Position3D & end, float sta 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 midh = mid ^ midheight(mid); + const auto midh = mid || midheight(mid); return {{start, midh, c1}, {end, midh, c2}}; } else { @@ -133,7 +133,7 @@ Network::genCurveDef(const Position3D & start, const Position3D & end, float sta 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 midh = mid ^ midheight(mid); + const auto midh = mid || midheight(mid); return {{midh, start, c1}, {midh, end, c2}}; } } diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 545a728..303f1c8 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -57,7 +57,7 @@ RailLinks::addLinksBetween(Position3D start, Position3D end) const auto c1 = flatStart + sincosf(dir + half_pi) * radius; const auto c2 = flatEnd + sincosf(dir2 + half_pi) * radius; const auto mid = (c1 + c2) / 2.F; - const auto midh = mid ^ midheight(mid); + const auto midh = mid || midheight(mid); addLink(start, midh, c1); return addLink(end, midh, c2); } @@ -66,7 +66,7 @@ RailLinks::addLinksBetween(Position3D start, Position3D end) const auto c1 = flatStart + sincosf(dir - half_pi) * radius; const auto c2 = flatEnd + sincosf(dir2 - half_pi) * radius; const auto mid = (c1 + c2) / 2.F; - const auto midh = mid ^ midheight(mid); + const auto midh = mid || midheight(mid); addLink(midh, start, c1); return addLink(midh, end, c2); } @@ -133,7 +133,7 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & for (auto ei : {1U, 0U}) { const auto trans {glm::translate(ends[ei].node->pos) * e}; for (const auto & rcs : railCrossSection) { - const Position3D m {(trans * (rcs.first ^ 1))}; + const Position3D m {(trans * (rcs.first || 1.F))}; vertices.emplace_back(m, Position2D {rcs.second, len * static_cast(ei)}, up); } } @@ -142,7 +142,7 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & } RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position2D c) : - RailLinkCurve(a, b, c ^ a->pos.z, {c ^ 0.F, a->pos, b->pos}) + RailLinkCurve(a, b, c || a->pos.z, {c || 0.F, a->pos, b->pos}) { } @@ -166,7 +166,7 @@ RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position3 const auto t { trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})}; for (const auto & rcs : railCrossSection) { - const Position3D m {(t * (rcs.first ^ 1))}; + const Position3D m {(t * (rcs.first || 1.F))}; vertices.emplace_back(m, Position2D {rcs.second, swing.z}, up); } } -- cgit v1.2.3