X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.h;h=5960c27d16b78164da022a40e0c79e7529647244;hb=a9180bc4bb7ff4c403e206cc2c785ff32544a0d6;hp=363fb5572c9184dde7a64e339815f3fbe4f28983;hpb=6c61179fe09af2f5366d50f10aadbf5f83438087;p=r2c2.git diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 363fb55..5960c27 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -1,44 +1,148 @@ +/* $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 ControlModel; +class LocoType; +class Route; +class Timetable; +class Vehicle; 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 &); + void timetable(); + }; + + sigc::signal signal_name_changed; + sigc::signal signal_control_changed; + sigc::signal signal_function_changed; + sigc::signal signal_route_changed; + sigc::signal signal_arrived; + sigc::signal signal_status_changed; + private: - struct SectionRef + struct BlockRef + { + Block *block; + unsigned entry; + + BlockRef(Block *, unsigned); + BlockRef next() const; + }; + + 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; - unsigned target_speed; + std::vector vehicles; + std::list cur_blocks; + std::list rsv_blocks; + Block *pending_block; + ControlModel *control; + Timetable *timetable; + bool active; + unsigned current_speed; + bool speed_changing; + bool reverse; + Msp::Time::TimeStamp stop_timeout; + unsigned functions; + const Route *route; + const Route *next_route; + bool end_of_route; + std::string status; + Msp::Time::TimeStamp last_entry_time; + float travel_dist; + bool pure_speed; + std::vector real_speed; + +public: + Train(Layout &, const LocoType &, unsigned); + ~Train(); + + Layout &get_layout() const { return layout; } + 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; } + ControlModel &get_control() const { return *control; } + + Vehicle &get_vehicle(unsigned); + const Vehicle &get_vehicle(unsigned) const; + + void set_control(const std::string &, float); + void set_active(bool); + void set_function(unsigned, bool); + float get_control(const std::string &) const; + bool is_active() const { return active; } + bool get_function(unsigned) const; + unsigned get_functions() const { return functions; } + + void set_route(const Route *); + void go_to(const Track &); + 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; + float get_reserved_distance() const; + + const std::string &get_status() const { return status; } + + 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(); + float get_real_speed(unsigned) const; + unsigned find_speed(float) const; + float get_travel_speed() const; + void set_status(const std::string &); + 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