X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrain.h;h=dff9aae666fa3f301b02bf21203024c578a677dc;hb=ecd7af790bd3ab7c7e768f68968379e1feea56a9;hp=90b2a72dc5ce94e3795d2a3d232d932fed22d484;hpb=34f8bf04e4bdffefeceea59b186386b51c542b9d;p=r2c2.git diff --git a/source/libr2c2/train.h b/source/libr2c2/train.h index 90b2a72..dff9aae 100644 --- a/source/libr2c2/train.h +++ b/source/libr2c2/train.h @@ -1,34 +1,27 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #ifndef LIBR2C2_TRAIN_H_ #define LIBR2C2_TRAIN_H_ #include #include -#include -#include "block.h" -#include "blockiter.h" +#include +#include +#include "blockallocator.h" #include "controller.h" +#include "sensor.h" #include "trainai.h" namespace R2C2 { class ArticleNumber; -class Route; +class Block; class SpeedQuantizer; class Vehicle; class VehicleType; -class Zone; class Train: public sigc::trackable { public: - class Loader: public Msp::DataFile::BasicLoader + class Loader: public Msp::DataFile::ObjectLoader { private: Block *prev_block; @@ -38,63 +31,44 @@ public: Loader(Train &); private: virtual void finish(); - void block(unsigned); - void block_hint(unsigned); + void blocks(); void name(const std::string &); void quantized_speed(); - void route(const std::string &); + void router(); void timetable(); - void vehicle(ArticleNumber); + void vehicle(const std::string &); }; sigc::signal signal_name_changed; sigc::signal signal_control_changed; sigc::signal signal_function_changed; sigc::signal signal_ai_event; - sigc::signal signal_route_changed; sigc::signal signal_advanced; - sigc::signal signal_arrived; - sigc::signal signal_status_changed; + sigc::signal signal_rear_advanced; + sigc::signal signal_vehicle_added; + sigc::signal signal_vehicle_removed; private: - struct RouteRef - { - const Route *route; - unsigned diversion; - - RouteRef(const Route *, unsigned = 0); - }; - - typedef std::list BlockList; - Layout &layout; const VehicleType &loco_type; unsigned address; std::string protocol; + unsigned loco_id; std::string name; - int priority; - const Train *yielding_to; const Train *preceding_train; std::vector vehicles; - BlockList blocks; - BlockList::iterator cur_blocks_end; - BlockList::iterator clear_blocks_end; - Block *pending_block; - bool reserving; + BlockAllocator allocator; bool advancing; Controller *controller; std::list ais; - bool active; unsigned current_speed_step; bool speed_changing; bool reverse; - Msp::Time::TimeStamp stop_timeout; + Msp::Time::TimeDelta stop_timeout; unsigned functions; - std::list routes; - bool end_of_route; - Msp::Time::TimeStamp last_entry_time; - float travel_dist; + BlockIter last_entry_block; + Msp::Time::TimeDelta travel_time; bool pure_speed; SpeedQuantizer *speed_quantizer; bool accurate_position; @@ -110,9 +84,6 @@ public: const std::string &get_protocol() const { return protocol; } void set_name(const std::string &); const std::string &get_name() const { return name; } - void set_priority(int); - void yield_to(const Train &); - int get_priority() const { return priority; } const Train *get_preceding_train() const { return preceding_train; } Controller &get_controller() const { return *controller; } @@ -123,54 +94,52 @@ public: 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; float get_speed() const; float get_quantized_speed() const; unsigned get_speed_step() const { return current_speed_step; } - bool is_active() const { return active; } + float get_maximum_speed() const; bool get_function(unsigned) const; unsigned get_functions() const { return functions; } void add_ai(TrainAI &); void remove_ai(TrainAI &); - TrainAI *get_tagged_ai(const std::string &) const; void ai_message(const TrainAI::Message &); - bool set_route(const Route *); - bool go_to(Track &); - bool go_to(const Zone &); - bool divert(Track &); - const Route *get_route() const; - void place(Block &, unsigned); + template + T *get_ai_of_type() const + { + for(std::list::const_iterator i=ais.begin(); i!=ais.end(); ++i) + if(T *ai = dynamic_cast(*i)) + return ai; + return 0; + } + + bool place(const BlockIter &); void unplace(); - bool is_placed() const { return !blocks.empty(); } - bool free_block(Block &); - void free_noncritical_blocks(); - int get_entry_to_block(Block &) const; + bool is_placed() const { return !allocator.empty(); } + void stop_at(Block *); + bool is_block_critical(const Block &) const; + BlockIter get_last_critical_block() const; +private: + BlockIter check_critical_blocks(const Block *) const; +public: + void refresh_blocks_from(Block &); + const BlockAllocator &get_block_allocator() const { return allocator; } float get_reserved_distance() const; - void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &); + void tick(const Msp::Time::TimeDelta &); void save(std::list &) const; private: void control_changed(const Controller::Control &); void loco_speed_event(unsigned, unsigned, bool); void loco_func_event(unsigned, unsigned, bool); - void sensor_event(unsigned, bool); - void turnout_path_changed(Track &); + void advanced(Block &, Sensor *); void halt_event(bool); void block_reserved(const Block &, const Train *); - void reserve_more(); - void check_turnout_paths(bool); - float get_reserved_distance_until(const Block *, bool) const; - void release_blocks(); - void release_blocks(BlockList::iterator, BlockList::iterator); - void reverse_blocks(BlockList &) const; - bool advance_route(std::list::iterator &, Track &); - Route *create_lead_route(Route *, const Route *); - bool is_valid_diversion(const Route &, const TrackIter &); + float get_reserved_distance_until(const Block *) const; }; } // namespace R2C2