trainoverlord: switch from train based blocking to tag based blocking
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include <QJsonObject>
|
||||
#include "blockborder.h"
|
||||
#include "train.h"
|
||||
#include "overlorditemstore.h"
|
||||
|
||||
class BlockBorder;
|
||||
class Layout;
|
||||
@ -16,50 +17,59 @@ class Block: public QObject
|
||||
Q_OBJECT
|
||||
protected:
|
||||
static constexpr int WAIT_TYPE_BLOCK = 0;
|
||||
static constexpr int WAIT_TYPE_TRAVERSE = 1;
|
||||
static constexpr int WAIT_TYPE_TIMED_TRAVERSE = 1;
|
||||
|
||||
struct TrainWait
|
||||
struct Wait
|
||||
{
|
||||
int type;
|
||||
int direction;
|
||||
NfcUid tag;
|
||||
std::weak_ptr<Train> train;
|
||||
std::weak_ptr<Block> targetBlock;
|
||||
std::weak_ptr<BlockBorder> border;
|
||||
};
|
||||
|
||||
std::vector< std::shared_ptr<BlockBorder> > borders_;
|
||||
std::vector< std::weak_ptr<Train> > trains_;
|
||||
std::vector<TrainWait> waits_;
|
||||
std::vector<NfcUid> tags_;
|
||||
std::vector<Wait> waits_;
|
||||
uint32_t id_;
|
||||
OverlordItemStore* items_;
|
||||
|
||||
protected slots:
|
||||
void unsuspendedTrain(uint32_t id, int direction);
|
||||
void removeTraverse(std::shared_ptr<Train> train);
|
||||
|
||||
protected:
|
||||
void checkWaits(bool blocked = false);
|
||||
void updateBorders();
|
||||
void addTraverseWait(const NfcUid& tag);
|
||||
void addBlockWait(const NfcUid& tag, std::shared_ptr<Block> block, std::shared_ptr<BlockBorder> border);
|
||||
void removeTag(const NfcUid& tag);
|
||||
bool tagIsOfOwnedTrain(const NfcUid& tag);
|
||||
|
||||
public:
|
||||
Block(uint32_t id = QRandomGenerator::global()->generate());
|
||||
void addBorder(std::shared_ptr<BlockBorder> border);
|
||||
bool blocked();
|
||||
bool ownsTrain(std::weak_ptr<Train> train);
|
||||
bool ownsBorder(std::shared_ptr<BlockBorder> border);
|
||||
std::vector< std::shared_ptr<BlockBorder> > getBorders(){return borders_;}
|
||||
Block(OverlordItemStore* items, uint32_t id = QRandomGenerator::global()->generate());
|
||||
uint32_t id(){return id_;}
|
||||
void removeTrain(std::weak_ptr<Train> train);
|
||||
|
||||
void addBorder(std::shared_ptr<BlockBorder> border);
|
||||
std::vector< std::shared_ptr<BlockBorder> > getBorders(){return borders_;}
|
||||
bool ownsBorder(std::shared_ptr<BlockBorder> border);
|
||||
|
||||
bool pushTag(const NfcUid& tag);
|
||||
void addTag(const NfcUid& tag);
|
||||
void purgeTag(const NfcUid& tag);
|
||||
bool ownsTag(const NfcUid& tag);
|
||||
|
||||
bool blocked();
|
||||
|
||||
void store(QJsonObject& json);
|
||||
void load(const QJsonObject& json);
|
||||
void populate(const QJsonObject& json, Layout* layout);
|
||||
|
||||
public slots:
|
||||
bool pushTrain(std::weak_ptr<Train> train);
|
||||
void addTrain(std::weak_ptr<Train> train);
|
||||
void trainArrivedAtBorder(std::weak_ptr<BlockBorder> border, std::weak_ptr<Train> train);
|
||||
void tagArrivedAtBorder(NfcUid tag, std::weak_ptr<BlockBorder> border);
|
||||
|
||||
signals:
|
||||
void blockedChanged(bool blocked);
|
||||
void trainAddedToBlock(int blockId, std::weak_ptr<Train> train);
|
||||
};
|
||||
|
||||
#endif // BLOCK_H
|
||||
|
Reference in New Issue
Block a user