chiark / gitweb /
do not always use current position when predicting; do do so when reporting initially
authorian <ian>
Sat, 17 May 2008 18:19:13 +0000 (18:19 +0000)
committerian <ian>
Sat, 17 May 2008 18:19:13 +0000 (18:19 +0000)
hostside/safety.c

index d014f39b44fcff86072b9f72f226d35a5849a9ce..ca5886b52ff8a9df86fd7fc0d9d6f066875ac812 100644 (file)
@@ -247,7 +247,7 @@ typedef struct {
     need_polarise:1, /* when we commit */
     train_polarity_inverted:1, /* right now, or if know_best, the best */
     know_best_polarity:1, /* longest-lasting into the future */
-   alwaysusemotions:1; /* for report_train_ownerships only */
+    alwaysusemotions:1; /* for report_train_ownerships only */
   TrackLocation nose, fdet, tail;
   TrackAdvanceContext nosec, tailc, fdetc;
   TimeInterval elapsed; /* from now, minimum */
@@ -356,7 +356,9 @@ static int pred_getmovpos(TrackLocation *t, TrackAdvanceContext *c,
                          MovPosComb *use_io) {
   PredictUserContext *u= c->u;
   if (u->usecurrentposn) return 0;
-  if (t->seg->motion) *use_io= movpos_change_intent(t->seg->motion);
+  if (t->seg->motion)
+    if (t->seg->moving || t->seg->pred_vacated || u->alwaysusemotions)
+      *use_io= movpos_change_intent(t->seg->motion);
   if (*use_io<0) safety_panic(u->train, t->seg,
                              "track route unexpectedly not known");
   return 0;
@@ -541,11 +543,11 @@ static int fdet_nextseg(TrackLocation *t, TrackAdvanceContext *c,
   }
 
   /* Now we have advanced the nose and have recorded any appropriate
-   * motion(s).  But we advancing the nose has updated the segment's
+   * motion(s).  Advancing the nose has updated the segment's
    * notion of the motion but not trackloc_advance's cached version of
-   * the movposcomb in *mpc_io.  That doesn't matter because we don't
-   * actually use it ourselves and trackloc_advance will call
-   * getmovpos. */
+   * the movposcomb in *mpc_io - but trackloc_advance will call
+   * pred_getmovpos right after we return so we do not need to worry.
+   */
 
   /* Check polarity */
 
@@ -664,8 +666,8 @@ ErrorCode predict(Train *tra, int accelerate, struct timeval tnow,
   assert(foredet);
 
   u.walk_compute_polarise= 1;
-  u.train_polarity_inverted= foredet->seg_inverted ^ foredet->tr_backwards;
   u.usecurrentposn= 1;
+  u.train_polarity_inverted= foredet->seg_inverted ^ foredet->tr_backwards;
 
   /*----- find the train's foredetect (rearmost possibility) -----*/
   /*
@@ -709,6 +711,7 @@ ErrorCode predict(Train *tra, int accelerate, struct timeval tnow,
 
   /*----- find the train's nose (rearmost possibility) -----*/
 
+  u.usecurrentposn= 0;
   u.nosec.u= &u;
   u.nosec.getmovpos= pred_getmovpos;
   u.nosec.nextseg= nose_nextseg;