X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.h;h=530d0209015a6217165d5fe4217637a239aae024;hb=bc8ac89bbe774bb133b758416182aa18e5e0a5a5;hp=363fb5572c9184dde7a64e339815f3fbe4f28983;hpb=6c61179fe09af2f5366d50f10aadbf5f83438087;p=r2c2.git diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 363fb55..530d020 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -1,44 +1,123 @@ +/* $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 "section.h" +#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(Section *, const Section::Endpoint *); - bool free_section(Section *); - void tick(); + class Loader: public Msp::DataFile::BasicLoader + { + private: + Block *prev_block; + + public: + Loader(Train &); + private: + void block(unsigned); + void block_hint(unsigned); + void name(const std::string &); + 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 SectionRef + struct BlockRef + { + Block *block; + unsigned entry; + + BlockRef(Block *s, unsigned e): block(s), entry(e) { } + }; + + struct RealSpeed { - Section *section; - const Section::Endpoint *entry; + float speed; + float weight; - SectionRef(Section *s, const Section::Endpoint *e): section(s), entry(e) { } + RealSpeed(); + void add(float, float); }; - typedef std::list SectRefSeq; TrafficManager &trfc_mgr; std::string name; Locomotive &loco; - SectRefSeq cur_sections; - SectRefSeq rsv_sections; + std::list cur_blocks; + std::list rsv_blocks; + Block *pending_block; unsigned target_speed; + const Route *route; + 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 *); + void block_reserved(const Block &, const Train *); + 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 release_blocks(std::list &, std::list::iterator, std::list::iterator); + void reverse_blocks(std::list &) const; }; -typedef std::list TrainSeq; } // namespace Marklin