summaryrefslogtreecommitdiff
path: root/game/network
diff options
context:
space:
mode:
Diffstat (limited to 'game/network')
-rw-r--r--game/network/link.h5
-rw-r--r--game/network/rail.cpp17
-rw-r--r--game/network/rail.h5
3 files changed, 26 insertions, 1 deletions
diff --git a/game/network/link.h b/game/network/link.h
index 287ba14..c9fbedb 100644
--- a/game/network/link.h
+++ b/game/network/link.h
@@ -6,6 +6,7 @@
#include <memory>
#include <special_members.hpp>
#include <utility>
+#include <vector>
// Generic network node
// something that can be travelled to
@@ -24,6 +25,8 @@ using NodePtr = std::shared_ptr<Node>;
// Generic network link
// something that can be travelled along
// it joins 2 nodes
+class Link;
+using LinkPtr = std::shared_ptr<Link>;
class Link {
public:
using End = std::pair<NodePtr, float /*dir*/>;
@@ -35,6 +38,8 @@ public:
std::array<End, 2> ends;
float length;
+ using Next = std::pair<LinkPtr, unsigned char /*end*/>;
+ std::array<std::vector<Next>, 2> nexts;
};
bool operator<(const glm::vec3 & a, const glm::vec3 & b);
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index fd2ea08..a66bf65 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -16,6 +16,23 @@ RailLinks::RailLinks() : texture {Texture::cachedTexture.get("rails.jpg")} { }
void RailLinks::tick(TickDuration) { }
void
+RailLinks::joinLinks(LinkPtr l) const
+{
+ for (const auto & ol : links.objects) {
+ if (l != ol) {
+ for (const auto oe : {0, 1}) {
+ for (const auto te : {0, 1}) {
+ if (l->ends[te].first == ol->ends[oe].first) {
+ l->nexts[te].emplace_back(ol.get(), oe);
+ ol->nexts[oe].emplace_back(l.get(), te);
+ }
+ }
+ }
+ }
+ }
+}
+
+void
RailLinks::render(const Shader & shader) const
{
shader.setModel(glm::identity<glm::mat4>());
diff --git a/game/network/rail.h b/game/network/rail.h
index 5fea713..a501f32 100644
--- a/game/network/rail.h
+++ b/game/network/rail.h
@@ -61,7 +61,9 @@ public:
{
const auto node1 = *nodes.insert(std::make_shared<Node>(a)).first;
const auto node2 = *nodes.insert(std::make_shared<Node>(b)).first;
- return links.create<T>(node1, node2, std::forward<Params>(params)...);
+ auto l = links.create<T>(node1, node2, std::forward<Params>(params)...);
+ joinLinks(l);
+ return l;
}
private:
@@ -70,6 +72,7 @@ private:
Nodes nodes;
void render(const Shader &) const override;
void tick(TickDuration elapsed) override;
+ void joinLinks(LinkPtr) const;
std::shared_ptr<Texture> texture;
};