]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.h
Major architecture rework
[r2c2.git] / source / libmarklin / train.h
index 530d0209015a6217165d5fe4217637a239aae024..60a0c0824ade3030e52497ee0ec6a19b4f79f679 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -15,11 +15,8 @@ Distributed under the GPL
 
 namespace Marklin {
 
-class Locomotive;
+class LocoType;
 class Route;
-class Sensor;
-class TrafficManager;
-class Turnout;
 
 class Train: public sigc::trackable
 {
@@ -41,6 +38,9 @@ public:
 
        sigc::signal<void, const std::string &> signal_name_changed;
        sigc::signal<void, unsigned> signal_target_speed_changed;
+       sigc::signal<void, unsigned> signal_speed_changed;
+       sigc::signal<void, bool> signal_reverse_changed;
+       sigc::signal<void, unsigned, bool> signal_function_changed;
        sigc::signal<void, const Route *> signal_route_changed;
        sigc::signal<void, const std::string &> signal_status_changed;
 
@@ -62,13 +62,18 @@ private:
                void add(float, float);
        };
 
-       TrafficManager &trfc_mgr;
+       Layout &layout;
+       const LocoType &loco_type;
+       unsigned address;
        std::string name;
-       Locomotive &loco;
        std::list<BlockRef> cur_blocks;
        std::list<BlockRef> 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;
 
@@ -84,29 +89,41 @@ private:
        Point pos;
 
 public:
-       Train(TrafficManager &, Locomotive &);
+       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_route(const Route *);
-       const std::string &get_name() const { return name; }
-       Locomotive &get_locomotive() const { return loco; }
+       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; }
-       const std::string &get_status() const { return status; }
-       const Point &get_position() const { return pos; }
        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<Msp::DataFile::Statement> &) const;
 private:
-       void locomotive_reverse_changed(bool);
-       void sensor_event(bool, Sensor *);
-       void turnout_path_changing(unsigned, Turnout *);
-       void turnout_path_changed(unsigned, Turnout *);
+       void loco_speed_event(unsigned, unsigned, bool);
+       void loco_func_event(unsigned, unsigned, bool);
+       void sensor_event(unsigned, bool);
+       void turnout_event(unsigned, bool);
        void block_reserved(const Block &, const Train *);
        unsigned reserve_more();
        void update_speed();