diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-13 20:34:25 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-10-13 20:34:25 +0100 |
commit | 6ad0230b50be3e867e4ea1a1e33fd30c7487ec4a (patch) | |
tree | 00c0e894d00c17a8f7634df6f3c465b4023975b1 /game | |
parent | Standard typedefs for Node (diff) | |
download | ilt-6ad0230b50be3e867e4ea1a1e33fd30c7487ec4a.tar.bz2 ilt-6ad0230b50be3e867e4ea1a1e33fd30c7487ec4a.tar.xz ilt-6ad0230b50be3e867e4ea1a1e33fd30c7487ec4a.zip |
Standard typedefs for Link
Diffstat (limited to 'game')
-rw-r--r-- | game/network/link.h | 9 | ||||
-rw-r--r-- | game/network/network.cpp | 2 | ||||
-rw-r--r-- | game/network/network.h | 18 | ||||
-rw-r--r-- | game/network/network.impl.h | 8 | ||||
-rw-r--r-- | game/vehicles/linkHistory.cpp | 2 | ||||
-rw-r--r-- | game/vehicles/linkHistory.h | 6 | ||||
-rw-r--r-- | game/vehicles/train.h | 2 | ||||
-rw-r--r-- | game/vehicles/vehicle.cpp | 2 | ||||
-rw-r--r-- | game/vehicles/vehicle.h | 2 |
9 files changed, 23 insertions, 28 deletions
diff --git a/game/network/link.h b/game/network/link.h index 2beb808..1f6b780 100644 --- a/game/network/link.h +++ b/game/network/link.h @@ -28,13 +28,9 @@ public: // Generic network link // something that can be travelled along // it joins 2 nodes -class Link; -using LinkPtr = std::shared_ptr<Link>; -using LinkCPtr = std::shared_ptr<const Link>; -using LinkWPtr = std::weak_ptr<const Link>; -class Link { +class Link : public StdTypeDefs<Link> { public: - using Next = std::pair<LinkWPtr, unsigned char /*end*/>; + using Next = std::pair<WPtr, unsigned char /*end*/>; using Nexts = std::vector<Next>; struct End { @@ -61,7 +57,6 @@ protected: return {}; } }; -using CLinks = std::vector<LinkCPtr>; bool operator<(const glm::vec3 & a, const glm::vec3 & b); bool operator<(const Node & a, const Node & b); diff --git a/game/network/network.cpp b/game/network/network.cpp index 25dc384..d78f672 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -63,7 +63,7 @@ Network::intersectRayNodes(const Ray & ray) const } void -Network::joinLinks(const LinkPtr & l, const LinkPtr & ol) +Network::joinLinks(const Link::Ptr & l, const Link::Ptr & ol) { if (l != ol) { for (const auto oe : {0U, 1U}) { diff --git a/game/network/network.h b/game/network/network.h index 4ef6a4f..60d9a02 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -17,7 +17,7 @@ class Ray; class Network { public: - using LinkEnd = std::pair<LinkPtr, unsigned char>; + using LinkEnd = std::pair<Link::Ptr, unsigned char>; explicit Network(const std::string & textureName); virtual ~Network() = default; @@ -25,17 +25,17 @@ public: [[nodiscard]] Node::Ptr nodeAt(glm::vec3); [[nodiscard]] std::pair<Node::Ptr, bool> newNodeAt(glm::vec3); [[nodiscard]] std::pair<Node::Ptr, bool> candidateNodeAt(glm::vec3) const; - [[nodiscard]] virtual LinkPtr intersectRayLinks(const Ray &) const = 0; + [[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 &, const Node::Ptr &) const; - virtual LinkCPtr addStraight(glm::vec3, glm::vec3) = 0; - virtual CLinks addJoins(glm::vec3, glm::vec3) = 0; + virtual Link::CPtr addStraight(glm::vec3, glm::vec3) = 0; + virtual Link::CCollection addJoins(glm::vec3, glm::vec3) = 0; protected: - static void joinLinks(const LinkPtr & l, const LinkPtr & ol); + static void joinLinks(const Link::Ptr & l, const Link::Ptr & ol); using Nodes = std::set<Node::Ptr, PtrMemberSorter<Node::Ptr, &Node::pos>>; Nodes nodes; @@ -47,10 +47,10 @@ protected: using Network::Network; Collection<T> links; - void joinLinks(const LinkPtr &) const; + void joinLinks(const Link::Ptr &) const; protected: - [[nodiscard]] LinkPtr intersectRayLinks(const Ray &) const override; + [[nodiscard]] Link::Ptr intersectRayLinks(const Ray &) const override; public: template<typename L, typename... Params> @@ -64,8 +64,8 @@ public: return l; } - LinkCPtr addStraight(glm::vec3 n1, glm::vec3 n2) override; - CLinks addJoins(glm::vec3, glm::vec3) override; + Link::CPtr addStraight(glm::vec3 n1, glm::vec3 n2) override; + Link::CCollection addJoins(glm::vec3, glm::vec3) override; void render(const Shader &) const override; }; diff --git a/game/network/network.impl.h b/game/network/network.impl.h index 4e2b37e..68da5d9 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -15,7 +15,7 @@ NetworkOf<T>::render(const Shader & shader) const template<typename T> void -NetworkOf<T>::joinLinks(const LinkPtr & l) const +NetworkOf<T>::joinLinks(const Link::Ptr & l) const { for (const auto & ol : links.objects) { Network::joinLinks(l, ol); @@ -23,7 +23,7 @@ NetworkOf<T>::joinLinks(const LinkPtr & l) const } template<typename T> -LinkPtr +Link::Ptr NetworkOf<T>::intersectRayLinks(const Ray & ray) const { // Click link @@ -38,14 +38,14 @@ NetworkOf<T>::intersectRayLinks(const Ray & ray) const } template<typename T> -LinkCPtr +Link::CPtr NetworkOf<T>::addStraight(glm::vec3 n1, glm::vec3 n2) { return addLink<typename T::StraightLink>(n1, n2); } template<typename T> -CLinks +Link::CCollection NetworkOf<T>::addJoins(glm::vec3 n1, glm::vec3 n2) { return {addLink<typename T::StraightLink>(n1, n2)}; diff --git a/game/vehicles/linkHistory.cpp b/game/vehicles/linkHistory.cpp index 4fac4ba..2802109 100644 --- a/game/vehicles/linkHistory.cpp +++ b/game/vehicles/linkHistory.cpp @@ -3,7 +3,7 @@ #include <memory> LinkHistory::Entry -LinkHistory::add(const LinkWPtr & l, unsigned char d) +LinkHistory::add(const Link::WPtr & l, unsigned char d) { links.insert(links.begin(), {l, d}); const auto lp = l.lock(); diff --git a/game/vehicles/linkHistory.h b/game/vehicles/linkHistory.h index 6944727..cc57fe0 100644 --- a/game/vehicles/linkHistory.h +++ b/game/vehicles/linkHistory.h @@ -6,9 +6,9 @@ class LinkHistory { public: - using WEntry = std::pair<LinkWPtr, unsigned char /*dir*/>; - using Entry = std::pair<LinkCPtr, unsigned char /*dir*/>; - Entry add(const LinkWPtr &, unsigned char); + using WEntry = std::pair<Link::WPtr, unsigned char /*dir*/>; + using Entry = std::pair<Link::CPtr, unsigned char /*dir*/>; + Entry add(const Link::WPtr &, unsigned char); [[nodiscard]] Entry getCurrent() const; [[nodiscard]] Entry getAt(float, float *) const; diff --git a/game/vehicles/train.h b/game/vehicles/train.h index 0c6a741..58e5e29 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -18,7 +18,7 @@ class Ray; class Train : public Vehicle, public Collection<RailVehicle, false>, public Can<Go>, public Can<Idle> { public: - explicit Train(const LinkPtr & link, float linkDist = 0) : Vehicle {link, linkDist} { } + explicit Train(const Link::Ptr & link, float linkDist = 0) : Vehicle {link, linkDist} { } [[nodiscard]] const Location & getLocation() const override diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp index 53450f6..6dc8371 100644 --- a/game/vehicles/vehicle.cpp +++ b/game/vehicles/vehicle.cpp @@ -15,7 +15,7 @@ #include <utility> #include <vector> -Vehicle::Vehicle(const LinkPtr & l, float ld) : linkDist {ld} +Vehicle::Vehicle(const Link::Ptr & l, float ld) : linkDist {ld} { linkHist.add(l, 0); currentActivity = std::make_unique<Idle>(); diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h index 24557b5..3fa3092 100644 --- a/game/vehicles/vehicle.h +++ b/game/vehicles/vehicle.h @@ -14,7 +14,7 @@ class Location; class Vehicle : public WorldObject, public Renderable, public Selectable { public: - explicit Vehicle(const LinkPtr & link, float linkDist = 0); + explicit Vehicle(const Link::Ptr & link, float linkDist = 0); float linkDist; // distance along current link float speed {}; // speed in m/s (~75 km/h) |