Terminus
train.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QVector3D>
4 
5 #include <memory>
6 #include <vector>
7 
10 #include <world/world.h>
11 
12 namespace terminus
13 {
14 
15 class AbstractPlayer;
16 class Track;
17 class Camera;
18 
26 {
27 public:
28  static const float base_velocity;
29 public:
30  Train(World & world, Track * track);
31  ~Train();
32 
39  template<typename WagonType>
40  void addWagon();
41 
48  template<typename WagonType>
49  void insertWagon(int targetPos);
50 
56  void removeWagon(unsigned int index);
57 
65  void moveWagon(unsigned int wagonPos, unsigned int targetPos);
66 
72  void localUpdate() override;
73 
74  AbstractWagon *wagonAt(unsigned int index) const;
75  Track *track() const;
76 
77  void follow(Train *train);
78  float velocity() const;
79  void setVelocity(float velocity);
80 
84  float travelledDistance() const;
85 
90 
94  float travelledDistanceRelative() const;
95 
96  QVector3D headPosition() const;
97 
101  unsigned int size() const;
102 
103  // TODO FIXME remove this getter since a camera will have the ability to be
104  // bound to any AbstractGraphicsObject which then knows the camera itself.
105  AbstractPlayer &player() const;
107 
108 protected:
109  virtual bool localRenderEnabled() const override;
110 
117  void calculateWagonOffset();
118 
119  virtual void doForAllChildren(std::function<void(AbstractGraphicsObject &)> callback) override;
120 
121 protected:
129  std::vector<std::unique_ptr<AbstractWagon>> m_wagons;
130 
131  bool m_hasEngine;
132 
133  float m_velocity;
135 
138 
146 };
147 
148 }
149 
150 #include "train.hpp"
~Train()
Definition: train.cpp:29
void addWagon()
Adds a wagon of the given WagonType to the end of the train.
Definition: train.hpp:16
unsigned int size() const
Returns the number of wagons in this train.
Definition: train.cpp:137
void setVelocity(float velocity)
Definition: train.cpp:112
float m_velocity
Definition: train.h:133
AbstractPlayer * m_player
A pointer to the player that controls this train.
Definition: train.h:145
Train(World &world, Track *track)
Definition: train.cpp:17
virtual void doForAllChildren(std::function< void(AbstractGraphicsObject &)> callback) override
override this method to make child objects known
Definition: train.cpp:173
void follow(Train *train)
Definition: train.cpp:102
float travelledDistance() const
Returns the travelled distance of the train's head on the spline.
Definition: train.cpp:117
void setPlayer(AbstractPlayer *player)
Definition: train.cpp:142
bool m_hasEngine
Every train needs exactly one engine.
Definition: train.h:131
AbstractWagon * wagonAt(unsigned int index) const
Definition: train.cpp:87
void calculateWagonOffset()
Calculates offset for every wagon relative to train head.
Definition: train.cpp:159
std::vector< std::unique_ptr< AbstractWagon > > m_wagons
The vector containing all wagons.
Definition: train.h:129
AbstractPlayer & player() const
Definition: train.cpp:148
The AbstractGraphicsObject class is the root of a class hierarchy of objects that contain independen ...
Definition: abstractgraphicsobject.h:27
void insertWagon(int targetPos)
Inserts a wagon of the given WagonType at the given position.
Definition: train.hpp:22
float m_travelledDistance
Definition: train.h:136
QVector3D headPosition() const
Definition: train.cpp:132
Train * m_followedTrain
Definition: train.h:134
Track * m_track
Definition: train.h:137
The World class represents a running game instance and contains all graphical (3D) elements of the sc...
Definition: world.h:46
void moveWagon(unsigned int wagonPos, unsigned int targetPos)
Moves the wagon at position wagonPos to position targetPos.
Definition: train.cpp:44
virtual bool localRenderEnabled() const override
override this method to disable or enable rendering conditionally
Definition: train.cpp:154
float travelledDistanceRelative() const
Returns the ratio of travelled distance to track length.
Definition: train.cpp:127
Definition: eventhandler.cpp:18
Track * track() const
Definition: train.cpp:97
float velocity() const
Definition: train.cpp:108
The AbstractWagon class provides a common interface for all wagon types and contains common functiona...
Definition: abstractwagon.h:25
void removeWagon(unsigned int index)
Removes the wagon at the given index.
Definition: train.cpp:34
The Track class represents a track that a Train moves on. It is currently not rendered. The course is represented by a Polyline instance.
Definition: track.h:16
void setTravelledDistance(float travelledDistance)
Set the travelled distance of the train's head on the spline.
Definition: train.cpp:122
The AbstractPlayer class is the base class for interacting with a train and a camera.
Definition: abstractplayer.h:21
void localUpdate() override
Update train.
Definition: train.cpp:70
The Train class works as a logical container for all wagons one train consists of.
Definition: train.h:25
static const float base_velocity
Definition: train.h:28