chiark / gitweb /
before throw away copy-without-segments-of-this-train
authorian <ian>
Sun, 13 Feb 2005 11:52:29 +0000 (11:52 +0000)
committerian <ian>
Sun, 13 Feb 2005 11:52:29 +0000 (11:52 +0000)
hostside/safety.c
hostside/safety.h

index d0f51c93e150650123f8aeaf9d5615956b9809b2..cc8ffac1b4305ffa946a6c9a55dda618c42ad07d 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "safety.h"
 
-State safety_actual;
+State *s, safety_buf[2];
 
 typedef struct TrackLocation TrackLocation;
 struct TrackLocation {
@@ -18,10 +18,22 @@ void trackfollow_further(TrackLocation *tloc, Distance *remain_io);
    * *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 : 
 
@@ -31,7 +43,6 @@ s->trais[trai]
   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];
index f552218a3a3c336dd3768abb5fb5c191b3bcc0d9..bf6d27663c0553d4499526050169b12d92779b5d 100644 (file)
@@ -5,8 +5,9 @@
 
 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;
@@ -22,15 +23,15 @@ typedef struct {
     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;
 
@@ -40,8 +41,7 @@ typedef struct {
 
 typedef struct {
   Speed maxspeed;
-  int n_detections;
-  const Distance *detections; /* incremental distances from rear */
+  Distance tail, detectable, head;
 } TrainInfo;