summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
Diffstat (limited to 'game')
-rw-r--r--game/geoData.h33
-rw-r--r--game/network/link.h12
-rw-r--r--game/network/network.h42
-rw-r--r--game/network/network.impl.h12
-rw-r--r--game/network/rail.h10
-rw-r--r--game/selectable.h3
-rw-r--r--game/vehicles/railVehicle.h2
-rw-r--r--game/vehicles/train.h2
8 files changed, 59 insertions, 57 deletions
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 <array>
#include <filesystem>
#include <glm/glm.hpp>
@@ -16,47 +17,47 @@ public:
float height {-1.5F};
};
- using Quad = std::array<glm::vec3, 4>;
+ using Quad = std::array<Position3D, 4>;
- using Limits = std::pair<glm::ivec2, glm::ivec2>;
+ using Limits = std::pair<glm::vec<2, int>, 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<glm::vec3> intersectRay(const Ray &) const;
+ [[nodiscard]] Position3D positionAt(Position2D) const;
+ [[nodiscard]] std::optional<Position3D> 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<const Node> 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<float, float>, std::pair<float, float>);
- static std::pair<float, float> 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<float, float>, std::pair<float, float>);
+ static std::pair<float, float> 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<Node> 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<Node> {
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<Node::Ptr, NodeIs>;
- [[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, GenCurveDef> 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<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(glm::vec3 a, glm::vec3 b, Params &&... params)
+ candidateLink(Position3D a, Position3D 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(glm::vec3 a, glm::vec3 b, Params &&... params)
+ addLink(Position3D a, Position3D 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(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<T>::findNodeDirection(Node::AnyCPtr n) const
template<typename T>
Link::CCollection
-NetworkOf<T>::candidateStraight(glm::vec3 n1, glm::vec3 n2)
+NetworkOf<T>::candidateStraight(Position3D n1, Position3D n2)
{
return {candidateLink<typename T::StraightLink>(n1, n2)};
}
template<typename T>
Link::CCollection
-NetworkOf<T>::candidateJoins(glm::vec3 start, glm::vec3 end)
+NetworkOf<T>::candidateJoins(Position3D start, Position3D end)
{
if (glm::distance(start, end) < 2.F) {
return {};
@@ -75,7 +75,7 @@ NetworkOf<T>::candidateJoins(glm::vec3 start, glm::vec3 end)
template<typename T>
Link::CCollection
-NetworkOf<T>::candidateExtend(glm::vec3 start, glm::vec3 end)
+NetworkOf<T>::candidateExtend(Position3D start, Position3D end)
{
const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(candidateNodeAt(start).first));
return {candidateLink<typename T::CurveLink>(cstart, cend, centre)};
@@ -83,14 +83,14 @@ NetworkOf<T>::candidateExtend(glm::vec3 start, glm::vec3 end)
template<typename T>
Link::CCollection
-NetworkOf<T>::addStraight(glm::vec3 n1, glm::vec3 n2)
+NetworkOf<T>::addStraight(Position3D n1, Position3D n2)
{
return {addLink<typename T::StraightLink>(n1, n2)};
}
template<typename T>
Link::CCollection
-NetworkOf<T>::addJoins(glm::vec3 start, glm::vec3 end)
+NetworkOf<T>::addJoins(Position3D start, Position3D end)
{
if (glm::distance(start, end) < 2.F) {
return {};
@@ -103,7 +103,7 @@ NetworkOf<T>::addJoins(glm::vec3 start, glm::vec3 end)
template<typename T>
Link::CCollection
-NetworkOf<T>::addExtend(glm::vec3 start, glm::vec3 end)
+NetworkOf<T>::addExtend(Position3D start, Position3D end)
{
const auto [cstart, cend, centre] = genCurveDef(start, end, findNodeDirection(nodeAt(start)));
return {addLink<typename T::CurveLink>(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<Vertex> 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<RailLink>, public WorldObject {
public:
RailLinks();
- std::shared_ptr<RailLink> addLinksBetween(glm::vec3 start, glm::vec3 end);
+ std::shared_ptr<RailLink> 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 <glm/glm.hpp>
#include <special_members.h>
@@ -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;