X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.h;h=4c19caf01a9625a9921b4a345bd4baada65a177e;hb=f9254f57b736927a57a2fd793ee18f6c9766dd43;hp=363fb5572c9184dde7a64e339815f3fbe4f28983;hpb=6c61179fe09af2f5366d50f10aadbf5f83438087;p=r2c2.git diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 363fb55..4c19caf 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -1,44 +1,90 @@ +/* $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 Sensor; class TrafficManager; 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 + { + public: + Loader(Train &); + }; + + sigc::signal signal_name_changed; + sigc::signal signal_status_changed; + private: - struct SectionRef + struct BlockRef { - Section *section; - const Section::Endpoint *entry; + Block *block; + unsigned entry; - SectionRef(Section *s, const Section::Endpoint *e): section(s), entry(e) { } + BlockRef(Block *s, unsigned e): block(s), entry(e) { } }; - 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; unsigned target_speed; + 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; + float speed_scale; + float speed_scale_weight; + + 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); + const std::string &get_name() const { return name; } + Locomotive &get_locomotive() const { return loco; } + const std::string &get_status() const { return status; } + const Point &get_position() const { return pos; } + void place(Block *, unsigned); + bool free_block(Block *); + 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_route_changing(unsigned, Turnout *); + void turnout_route_changed(unsigned, Turnout *); + unsigned reserve_more(); + void update_speed(); + void set_status(const std::string &); + void set_position(const Block::Endpoint &); }; -typedef std::list TrainSeq; } // namespace Marklin