X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.h;h=60a0c0824ade3030e52497ee0ec6a19b4f79f679;hb=651698847d5293cfb15b6fb23a394701388c0151;hp=363fb5572c9184dde7a64e339815f3fbe4f28983;hpb=6c61179fe09af2f5366d50f10aadbf5f83438087;p=r2c2.git diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 363fb55..60a0c08 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -1,44 +1,140 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2010 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 TrafficManager; +class LocoType; +class Route; 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_speed_changed; + sigc::signal signal_reverse_changed; + sigc::signal signal_function_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; + Layout &layout; + const LocoType &loco_type; + unsigned address; 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; + unsigned current_speed; + bool reverse; + Msp::Time::TimeStamp stop_timeout; + unsigned functions; + const Route *route; + std::string status; + 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(Layout &, const LocoType &, unsigned); + ~Train(); + + const LocoType &get_locomotive_type() const { return loco_type; } + unsigned get_address() const { return address; } + void set_name(const std::string &); + const std::string &get_name() const { return name; } + + void set_speed(unsigned); + void set_reverse(bool); + void set_function(unsigned, bool); + unsigned get_target_speed() const { return target_speed; } + unsigned get_speed() const { return current_speed; } + bool get_reverse() const { return reverse; } + bool get_function(unsigned) const; + unsigned get_functions() const { return functions; } + + void set_route(const Route *); + const Route *get_route() const { return route; } + void place(Block &, unsigned); + bool is_placed() const { return !cur_blocks.empty(); } + bool free_block(Block &); + int get_entry_to_block(Block &) const; + + const std::string &get_status() const { return status; } + const Point &get_position() const { return pos; } + + void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &); + + void save(std::list &) const; +private: + void loco_speed_event(unsigned, unsigned, bool); + void loco_func_event(unsigned, unsigned, bool); void sensor_event(unsigned, bool); - bool reserve_more(); + void turnout_event(unsigned, bool); + 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