summaryrefslogtreecommitdiff
path: root/game/network/link.h
blob: 725e023950d812d8e25ba0f34abd728e39ada1c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once

#include <array>
#include <glm/glm.hpp>
#include <location.h>
#include <maths.h>
#include <special_members.h>
#include <stdTypeDefs.h>
#include <utility>
#include <vector>

template<typename> class Ray;

// Generic network node
// something that can be travelled to
// it has location
class Node : public StdTypeDefs<Node> {
public:
	explicit Node(GlobalPosition3D p) noexcept : pos(p) {};
	virtual ~Node() noexcept = default;
	NO_COPY(Node);
	NO_MOVE(Node);

	GlobalPosition3D pos;
};

// Generic network link
// something that can be travelled along
// it joins 2 nodes
class Link : public StdTypeDefs<Link> {
public:
	using Next = std::pair<WPtr, unsigned char /*end*/>;
	using Nexts = std::vector<Next>;

	struct End {
		Node::Ptr node;
		float dir;
		Nexts nexts {};
	};

	Link(End, End, float);
	virtual ~Link() = default;
	NO_COPY(Link);
	NO_MOVE(Link);

	[[nodiscard]] virtual Location positionAt(RelativeDistance dist, unsigned char start) const = 0;
	[[nodiscard]] virtual bool intersectRay(const Ray<GlobalPosition3D> &) const = 0;

	std::array<End, 2> ends;
	float length;

protected:
	[[nodiscard]] virtual RelativePosition3D
	vehiclePositionOffset() const
	{
		return {};
	}
};

bool operator<(const GlobalPosition3D & a, const GlobalPosition3D & b);
bool operator<(const Node & a, const Node & b);

class LinkStraight : public virtual Link {
public:
	LinkStraight() = default;
	inline ~LinkStraight() override = 0;
	NO_COPY(LinkStraight);
	NO_MOVE(LinkStraight);

	[[nodiscard]] Location positionAt(RelativeDistance dist, unsigned char start) const override;
	[[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &) const override;
};

LinkStraight::~LinkStraight() = default;

class LinkCurve : public virtual Link {
public:
	inline ~LinkCurve() override = 0;
	LinkCurve(GlobalPosition3D, RelativeDistance, Arc);
	NO_COPY(LinkCurve);
	NO_MOVE(LinkCurve);

	[[nodiscard]] Location positionAt(RelativeDistance dist, unsigned char start) const override;
	[[nodiscard]] bool intersectRay(const Ray<GlobalPosition3D> &) const override;

	GlobalPosition3D centreBase;
	RelativeDistance radius;
	Arc arc;
};

LinkCurve::~LinkCurve() = default;