chiark / gitweb /
realtime: when reversing, a train's initial location may be unsuitable, eg because...
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 9 Jan 2011 22:07:45 +0000 (22:07 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 9 Jan 2011 22:07:45 +0000 (22:07 +0000)
hostside/safety.c
hostside/safety.h

index 97e32a948c62734d5da7fb9607e284157151267d..a85037f5d414256776c88966a554f74bd8f75be1 100644 (file)
@@ -434,6 +434,16 @@ static int initpresent_nextseg(TrackLocation *t, TrackAdvanceContext *c,
                               const TrackLocation *before) {
   PredictUserContext *u= c->u;
   pred_callback_debug(" initpresent_nextseg",t,c,before);
+
+  /* it had better be set for where we came from */
+  if (before) {
+    assert(SOMEP(*mpc_io));
+    const SegPosCombInfo *pci= &t->seg->i->poscombs[*mpc_io];
+    const SegmentLinkInfo *link= &pci->link[!t->backwards];
+    if (!SOMEP(link->next) || &segments[link->next] != before->seg)
+      return predict_problem(u, t->seg, "route set against proposed location");
+  }
+
   t->seg->now_present= t->seg->pred_present= t->seg->will_polarise= 1;
   t->seg->tr_backwards= !t->backwards;
   t->seg->until= 0;
@@ -821,7 +831,10 @@ ErrorCode predict(Train *tra, struct timeval tnow, unsigned flags,
   u.tail= u.fdet;
 
   ec= trackloc_reverse_exact(&u.tail,&u.tailc);  assert(!ec);
-  ec= trackloc_advance(&u.tail,&u.tailc);        assert(!ec);
+
+  ec= trackloc_advance(&u.tail,&u.tailc);
+  if (ec) { assert(flags & PREDF_INITQUEST); return ec; }
+
   ec= trackloc_reverse_exact(&u.tail,&u.tailc);  assert(!ec);
 
   u.hindmost= u.tail.seg;
@@ -1194,7 +1207,7 @@ ErrorCode safety_setdirection(Train *tra, int backwards,
   newfdet.seg->tr_backwards ^= 1;
   tra->plan_lookahead_nsegs= INT_MAX;
   
-  ec= predict(tra,tnow, PREDF_OLDPLAN, 0,0, 0,ppc,ppcu);
+  ec= predict(tra,tnow, PREDF_OLDPLAN|PREDF_INITQUEST, 0,0, 0,ppc,ppcu);
   if (!ec) {
     /* yay! */
     report_train_position(tra);
index 9ae0caaec0772bc1ef60e017278e87e4326912e6..78447c79e3fd4a75383bf8052432a2c4b1a4eb65 100644 (file)
@@ -137,6 +137,9 @@ ErrorCode safety_setdirection(Train *tra, int backwards,
 #define PREDF_OLDPLAN 002u
    /* the old plan is necessarily sufficient as we are not intending
     * to accelerate, change a movpos, etc. */
+#define PREDF_INITQUEST 004u
+   /* the initial location is questionable (ie, the initial present
+    * marking is allowed to fail) */
 
 typedef struct {
   unsigned stopping:1;