From acd16970bc93712e7c8c3996816242a04999818b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Mar 2021 18:53:22 +0000 Subject: Introduce the Train concept as a literal collection of rail vehicles --- game/vehicles/railloco.h | 51 ++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'game/vehicles/railloco.h') diff --git a/game/vehicles/railloco.h b/game/vehicles/railloco.h index 1bc0a51..0f240e2 100644 --- a/game/vehicles/railloco.h +++ b/game/vehicles/railloco.h @@ -2,7 +2,9 @@ #include "game/vehicles/vehicle.h" #include "game/worldobject.h" #include "gfx/models/mesh.h" +#include "gfx/renderable.h" #include +#include #include #include #include @@ -32,47 +34,36 @@ private: }; using RailVehicleClassPtr = std::shared_ptr; -class RailVehicle : public Vehicle { +class Train; +class RailVehicle : public Renderable { public: - explicit RailVehicle(RailVehicleClassPtr rvc, const LinkPtr & link, float linkDist = 0) : - Vehicle {link, linkDist}, rvClass {std::move(rvc)} - { - } + explicit RailVehicle(RailVehicleClassPtr rvc) : rvClass {std::move(rvc)} { } + + void move(const Train *, float & trailBy); + void render(const Shader & shader) const override; + Location location; + RailVehicleClassPtr rvClass; std::array bogies; - - friend class RailLoco; }; +using RailVehiclePtr = std::unique_ptr; -class RailWagon : public RailVehicle { +class Train : public Vehicle, public Collection { public: - using RailVehicle::RailVehicle; - void tick(TickDuration elapsed) override; -}; -using RailWagonPtr = std::weak_ptr; + explicit Train(const LinkPtr & link, float linkDist = 0) : Vehicle {link, linkDist} { } -class RailLoco : public RailVehicle { -public: - using RailVehicle::RailVehicle; - void tick(TickDuration elapsed) override; + [[nodiscard]] const Location & + getLocation() const override + { + return objects.front()->location; + } - std::vector wagons; + void render(const Shader & shader) const override; + + void tick(TickDuration elapsed) override; -private: void move(TickDuration dur); [[nodiscard]] Location getBogiePosition(float linkDist, float dist) const; - void updateRailVehiclePosition(RailVehicle *, float trailBy) const; - void updateWagons() const; -}; - -class Brush47 : public RailLoco { -public: - explicit Brush47(const LinkPtr & p); -}; - -class Brush47Wagon : public RailWagon { -public: - explicit Brush47Wagon(const LinkPtr & p); }; -- cgit v1.2.3