#ifndef RAILLINKS_H #define RAILLINKS_H #include "collection.hpp" #include "game/worldobject.h" #include "gfx/models/mesh.h" #include "gfx/models/vertex.hpp" #include "gfx/renderable.h" #include "link.h" #include #include #include #include #include #include #include class Shader; class Texture; // A piece of rail track class RailLink : public Link, public Renderable { public: using Link::Link; void render(const Shader &) const override; protected: void defaultMesh(); Collection meshes; std::vector vertices; std::vector indices; }; class RailLinkStraight : public RailLink { public: RailLinkStraight(const NodePtr &, const NodePtr &); private: RailLinkStraight(NodePtr, NodePtr, const glm::vec3 & diff); }; class RailLinkCurve : public RailLink { public: RailLinkCurve(const NodePtr &, const NodePtr &, glm::vec2); private: RailLinkCurve(const NodePtr &, const NodePtr &, glm::vec3, const Arc); glm::vec3 centreBase; }; template concept RailLinkConcept = std::is_base_of_v; class RailLinks : public Renderable, public WorldObject { public: RailLinks(); template std::shared_ptr addLink(glm::vec3 a, glm::vec3 b, Params &&... params) { const auto node1 = *nodes.insert(std::make_shared(a)).first; const auto node2 = *nodes.insert(std::make_shared(b)).first; auto l = links.create(node1, node2, std::forward(params)...); joinLinks(l); return l; } private: using Nodes = std::set>; Collection links; Nodes nodes; void render(const Shader &) const override; void tick(TickDuration elapsed) override; void joinLinks(LinkPtr) const; std::shared_ptr texture; }; #endif