X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.h;h=5ef23537a4710b9f3e4e8832f9056d73c10e2813;hb=4d84248a4990e913a56f013e67a608ad9698233e;hp=96f487066fb7e6ef5affa1228d8502c2fe35e5fb;hpb=78bc40c2d1a5fcc5715143bd2326716fbb143730;p=r2c2.git diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 96f4870..5ef2353 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -1,44 +1,121 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #ifndef LIBMARKLIN_TRAIN_H_ #define LIBMARKLIN_TRAIN_H_ +#include #include +#include #include "block.h" namespace Marklin { class Locomotive; +class Route; +class Sensor; class TrafficManager; +class Turnout; class Train: public sigc::trackable { public: - Train(TrafficManager &, Locomotive &); - const std::string &get_name() const { return name; } - void set_speed(unsigned); - void place(Block *, const Block::Endpoint *); - bool free_block(Block *); - void tick(); + class Loader: public Msp::DataFile::BasicLoader + { + private: + Block *prev_block; + + public: + Loader(Train &); + private: + void block(unsigned); + void block_hint(unsigned); + void real_speed(unsigned, float, float); + void route(const std::string &); + }; + + sigc::signal signal_name_changed; + sigc::signal signal_target_speed_changed; + sigc::signal signal_route_changed; + sigc::signal signal_status_changed; + private: struct BlockRef { Block *block; - const Block::Endpoint *entry; + unsigned entry; + + BlockRef(Block *s, unsigned e): block(s), entry(e) { } + }; + + struct RealSpeed + { + float speed; + float weight; - BlockRef(Block *s, const Block::Endpoint *e): block(s), entry(e) { } + RealSpeed(); + void add(float, float); }; - typedef std::list BlockRefSeq; TrafficManager &trfc_mgr; std::string name; Locomotive &loco; - BlockRefSeq cur_blocks; - BlockRefSeq rsv_blocks; + std::list cur_blocks; + std::list rsv_blocks; + Block *pending_block; unsigned target_speed; + const Route *route; + Msp::Time::TimeStamp try_reserve; + std::string status; - void sensor_event(unsigned, bool); - bool reserve_more(); + Msp::Time::TimeStamp last_entry_time; + float travel_dist; + unsigned travel_speed; + bool pure_speed; + std::vector real_speed; + + Track *cur_track; + unsigned cur_track_ep; + float offset; + Point pos; + +public: + Train(TrafficManager &, Locomotive &); + + void set_name(const std::string &); + void set_speed(unsigned); + void set_reverse(bool); + void set_route(const Route *); + const std::string &get_name() const { return name; } + Locomotive &get_locomotive() const { return loco; } + unsigned get_target_speed() const { return target_speed; } + const Route *get_route() const { return route; } + const std::string &get_status() const { return status; } + const Point &get_position() const { return pos; } + void place(Block &, unsigned); + bool is_placed() const { return !cur_blocks.empty(); } + bool free_block(Block &); + int get_entry_to_block(Block &) const; + void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &); + void save(std::list &) const; +private: + void locomotive_reverse_changed(bool); + void sensor_event(bool, Sensor *); + void turnout_path_changing(unsigned, Turnout *); + void turnout_path_changed(unsigned, Turnout *); + unsigned reserve_more(); + void update_speed(); + float get_real_speed(unsigned) const; + unsigned find_speed(float) const; + void set_status(const std::string &); + void set_position(const Block::Endpoint &); + void release_blocks(std::list &); + void reverse_blocks(std::list &) const; }; -typedef std::list TrainSeq; } // namespace Marklin