#include "safety.h"
-State safety_actual;
+State *s, safety_buf[2];
typedef struct TrackLocation TrackLocation;
struct TrackLocation {
* *remain_io becomes zero, or tloc->segi changes. */
void safety_train_changed(TrainIx trai) {
- State *s = &safety_actual;
TrainState *tra = s->tras[trai];
+ State *try = &safety_buf[!(s-safety_buf)];
TrackLocation tloc;
+ try->tras= s->tras;
+ for (lsegi=0, dlseg=try->segs, slseg=s->segs;
+ lsegi < NUM_SEGMENTS;
+ lsegi++, dlseg++, slseg++) {
+ *dlseg = *slseg;
+ if (dlseg->owner == trai) {
+ dlseg->owner = NO_TRAIN;
+ dlseg->present_now = dlseg->present_future =
+ dlseg->detectable_now = dlseg->detectable_future =
+ dlseg->autostop = 0;
+
+
tloc.segi= tra->foredetect;
tloc.into= tra->justarrived ? JUSTARRIVED_DIST :
SegmentState *seg = s->seg[segi];
void safety_notify_detection(SegmentIx segi) {
- State *s = &safety_actual;
SegmentState *seg = s->seg[segi];
TrainIx trai = segs->owner;
TrainState *tra = s->tras[trai];
typedef unsigned short TrainIx;
typedef unsigned short SegmentIx;
-typedef unsigned short Distance;
-typedef unsigned char Speed; /* non-negative, units of 4mm/s */
+typedef unsigned short LocationIx;
+typedef short Distance;
+typedef char Speed; /* non-negative, units of 4mm/s */
typedef struct {
SegmentIx foredetect;
detectable_now:1, detectable_future:1, /* owning train draws current */
reverse:1, /* owning train's motion is (would be) backwards wrt track */
sideways:1, /* for segment with points, points are set to `alternative' */
- autostop:1; /* owning train is slow and should stop on detection */
- TrainIx owner;
+ autostop:1, /* owning train is slow and wants to stop on detection */
+ updated:1; /* for use by safety_train_changed etc.; otherwise 0 */
/*polarity?*/
} SegmentState;
-
typedef struct {
unsigned next_rev:1;
SegmentIx next;
+ SegmentIx clashing;
Distance dist;
} SegmentLink;
typedef struct {
Speed maxspeed;
- int n_detections;
- const Distance *detections; /* incremental distances from rear */
+ Distance tail, detectable, head;
} TrainInfo;