-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#ifndef LIBR2C2_TIMETABLE_H_
#define LIBR2C2_TIMETABLE_H_
-#include <string>
-#include <vector>
-#include <sigc++/trackable.h>
#include <msp/datafile/objectloader.h>
-#include <msp/time/timestamp.h>
+#include "trainai.h"
namespace R2C2 {
-class Block;
-class Track;
-class Train;
-class Zone;
+class Layout;
+class TrackChain;
-class Timetable: public sigc::trackable
+class Timetable: public TrainAI
{
public:
class Loader: public Msp::DataFile::ObjectLoader<Timetable>
{
+ private:
+ Layout &layout;
+
public:
- Loader(Timetable &);
+ Loader(Timetable &, Layout &);
+
private:
- void arrive();
- void goto_sensor(unsigned);
- void goto_sensor(const std::string &);
- void goto_zone(const std::string &);
- void route(const std::string &);
- void reverse();
- void speed(unsigned);
- void travel(const std::string &);
- void wait(unsigned);
- void wait_train(unsigned, unsigned);
- void wait_until(unsigned, unsigned);
+ void row();
};
enum RowType
{
- GOTO_SENSOR,
- GOTO_ZONE,
- TRAVEL,
- WAIT_TIME,
- WAIT_UNTIL,
- WAIT_TRAIN,
- ARRIVE,
- SPEED,
- REVERSE,
- ROUTE
+ ARRIVE = 1,
+ DEPART,
+ THROUGH
};
struct Row
{
- RowType type;
- std::vector<Msp::Variant> params;
+ class Loader: public Msp::DataFile::ObjectLoader<Row>
+ {
+ private:
+ Layout &layout;
- Row(RowType);
+ public:
+ Loader(Row &, Layout &);
- template<typename T>
- Row(RowType, const T &);
+ private:
+ void block(unsigned);
+ void time(Msp::Time::RawTime);
+ void zone(const std::string &, unsigned);
+ };
- template<typename T>
- const T &get_param(unsigned) const;
-
- std::string str() const;
+ RowType type;
+ TrackChain *target;
+ Msp::Time::TimeDelta time;
- Msp::DataFile::Statement save() const;
+ Row();
- static Row parse(const std::string &);
+ void save(std::list<Msp::DataFile::Statement> &) const;
};
+ sigc::signal<void, unsigned, const Row &> signal_row_added;
+ sigc::signal<void, unsigned, const Row &> signal_row_modified;
+ sigc::signal<void, unsigned> signal_row_removed;
+
private:
- Train &train;
- bool enabled;
- std::vector<Row> rows;
- unsigned current_row;
- bool executing;
- Block *pending_block;
- Train *pending_train;
- Msp::Time::TimeStamp wait_timeout;
+ std::list<Row> rows;
+ std::list<Row>::iterator current_row;
+ bool update_pending;
public:
Timetable(Train &);
- void set_enabled(bool);
- bool is_enabled() const { return enabled; }
- void reset();
+ void append_row(const Row &);
+ void insert_row(unsigned, const Row &);
+ void modify_row(unsigned, const Row &);
+ void remove_row(unsigned);
- void clear();
- void append(const Row &);
- void insert(unsigned, const Row &);
- unsigned get_n_rows() const { return rows.size(); }
+ unsigned get_length() const { return rows.size(); }
const Row &get_row(unsigned) const;
- void tick(const Msp::Time::TimeStamp &);
+ virtual void tick(const Msp::Time::TimeDelta &);
+
void save(std::list<Msp::DataFile::Statement> &) const;
+
private:
- Track &get_sensor(unsigned);
- Zone &get_zone(const std::string &);
- void sensor_event(unsigned, bool);
- void train_arrived();
+ void check_update(std::list<Row>::const_iterator);
+ void update_route();
+ void event(TrainAI &, const Message &);
+ void record_time();
};
} // namespace R2C2