X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.h;h=3fc71316371bb5fb3a11d59ddb434005bccdc174;hb=93ca5f1774e218c313edd88024f82c80714d8e7c;hp=96f487066fb7e6ef5affa1228d8502c2fe35e5fb;hpb=78bc40c2d1a5fcc5715143bd2326716fbb143730;p=r2c2.git diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 96f4870..3fc7131 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -1,44 +1,113 @@ +/* $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 + { + public: + Loader(Train &); + private: + void real_speed(unsigned, float, float); + }; + + 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, const Block::Endpoint *e): block(s), entry(e) { } + BlockRef(Block *s, unsigned e): block(s), entry(e) { } + }; + + struct RealSpeed + { + float speed; + float weight; + + 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; + + Msp::Time::TimeStamp last_entry_time; + float travel_dist; + unsigned travel_speed; + bool pure_speed; + std::vector real_speed; - void sensor_event(unsigned, bool); - bool reserve_more(); + 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 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_reserved_blocks(); }; -typedef std::list TrainSeq; } // namespace Marklin