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/geoData.h | 33 +++++++++++++++++---------------- game/network/link.h | 12 ++++++------ game/network/network.h | 42 +++++++++++++++++++++--------------------- game/network/network.impl.h | 12 ++++++------ game/network/rail.h | 10 +++++----- game/selectable.h | 3 ++- game/vehicles/railVehicle.h | 2 +- game/vehicles/train.h | 2 +- 8 files changed, 59 insertions(+), 57 deletions(-) (limited to 'game') diff --git a/game/geoData.h b/game/geoData.h index f9a7d7b..b3ec51d 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include #include #include @@ -16,47 +17,47 @@ public: float height {-1.5F}; }; - using Quad = std::array; + using Quad = std::array; - using Limits = std::pair; + using Limits = std::pair, glm::vec<2, int>>; explicit GeoData(Limits limit, float scale = 10.F); void generateRandom(); void loadFromImages(const std::filesystem::path &, float scale); - [[nodiscard]] glm::vec3 positionAt(glm::vec2) const; - [[nodiscard]] std::optional intersectRay(const Ray &) const; + [[nodiscard]] Position3D positionAt(Position2D) const; + [[nodiscard]] std::optional intersectRay(const Ray &) const; - [[nodiscard]] unsigned int at(glm::ivec2) const; + [[nodiscard]] unsigned int at(glm::vec<2, int>) const; [[nodiscard]] unsigned int at(int x, int y) const; - [[nodiscard]] Quad quad(glm::vec2) const; + [[nodiscard]] Quad quad(Position2D) const; [[nodiscard]] Limits getLimit() const; - [[nodiscard]] glm::uvec2 getSize() const; + [[nodiscard]] glm::vec<2, unsigned int> getSize() const; [[nodiscard]] float getScale() const; [[nodiscard]] std::span getNodes() const; class RayTracer { public: - RayTracer(glm::vec2 p0, glm::vec2 p1); + RayTracer(Position2D p0, Position2D p1); - glm::vec2 next(); + Position2D next(); private: - RayTracer(glm::vec2 p0, glm::vec2 p1, glm::vec2 d); - RayTracer(glm::vec2 p0, glm::vec2 d, std::pair, std::pair); - static std::pair byAxis(glm::vec2 p0, glm::vec2 p1, glm::vec2 d, glm::length_t); + RayTracer(Position2D p0, Position2D p1, Position2D d); + RayTracer(Position2D p0, Position2D d, std::pair, std::pair); + static std::pair byAxis(Position2D p0, Position2D p1, Position2D d, glm::length_t); - glm::vec2 p; - const glm::vec2 d; + Position2D p; + const Position2D d; float error; - glm::vec2 inc; + Position2D inc; }; protected: Limits limit {}; // Base grid limits first(x,y) -> second(x,y) - glm::uvec2 size {}; + glm::vec<2, unsigned> size {}; float scale {1}; std::vector nodes; }; 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; diff --git a/game/selectable.h b/game/selectable.h index 31287d8..9732dca 100644 --- a/game/selectable.h +++ b/game/selectable.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include #include @@ -11,5 +12,5 @@ public: virtual ~Selectable() = default; DEFAULT_MOVE_COPY(Selectable); - [[nodiscard]] virtual bool intersectRay(const Ray &, glm::vec2 *, float *) const = 0; + [[nodiscard]] virtual bool intersectRay(const Ray &, Position2D *, float *) const = 0; }; diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index be88142..e034852 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -17,7 +17,7 @@ public: void move(const Train *, float & trailBy); - [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; + [[nodiscard]] bool intersectRay(const Ray &, Position2D *, float *) const override; RailVehicleClassPtr rvClass; using LV = RailVehicleClass::LocationVertex; diff --git a/game/vehicles/train.h b/game/vehicles/train.h index 20c3bc4..7f0bb99 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -27,7 +27,7 @@ public: return objects.front()->location; } - [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; + [[nodiscard]] bool intersectRay(const Ray &, Position2D *, float *) const override; void tick(TickDuration elapsed) override; void doActivity(Go *, TickDuration) override; -- cgit v1.2.3