chiark / gitweb /
realtime: resolve: do not mess improperly with tr_backwards
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 19 Jan 2011 23:10:29 +0000 (23:10 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 19 Jan 2011 23:22:47 +0000 (23:22 +0000)
Previously we would attempt to sort out Segment.tr_backwards in
resmain_getmovpos.  This is wrong because *_getmovpos shouldn't have
that kind of side-effect.

Furthermore the actual code was wrong: it wasn't idempotent: the
number of times tr_backwards would be inverted for a backwards train
would depend on how many times resmain_getmovpos was called.

Actually, for backwards trains not resolving at home, there is no need
to mess with tr_backwards.  The existing tr_backwards for the segments
it owns is fine.  For trains resolving at home, we need to explicitly
clear the train's direction too, and we should do this in a dedicated
piece of code.

Fixes:
@2011-01-10 20:28:23 GMT info save-dump +dump.2011-01-10T20-28-23+0000
traversed santafe forwards from B8 to B7 when B7/J1

hostside/TODO
hostside/resolve.c

index 4ea3dd893b2a39cf7de271fcd1cf35e3bd30b21a..7bba58594e417f0f8cc1041001860aca4278c84c 100644 (file)
@@ -1,7 +1,4 @@
 
-@2011-01-10 20:28:23 GMT info save-dump +dump.2011-01-10T20-28-23+0000
-       traversed santafe forwards from B8 to B7 when B7/J1
-
 @2011-01-10 22:42:18 GMT info save-dump +dump.2011-01-10T22-42-18+0000
        shinkansen 2nd bogie only derailed at B9, running anticlockwise
        first bogie went correctly to C9; 2nd bogie appears to
index 7c0b3b7b63fbf5f79ca9b4b970e316a30dc1e5a4..7e3507ee3520249d881fda7fa15b3d4692aac0d7 100644 (file)
@@ -161,11 +161,9 @@ static int resmain_getmovpos(TrackLocation *t, TrackAdvanceContext *c,
   const char *pn= d->i->pname;
 
   if (d->home && d->home->resolution == RR_H) {
-    d->tr_backwards= d->ho_backwards;
     *use_io= 0; /* a bit kludgey */
     DPRINTF(resolving,main, "getmovpos %s H\n", pn);
   } else if (d->owner) {
-    d->tr_backwards ^= d->owner->backwards;
     *use_io= d->movposcomb;
     DPRINTF(resolving,main, "getmovpos %s E %d\n", pn, *use_io);
   } else if (!d->res_movposset) {
@@ -327,6 +325,15 @@ static int resolve_complete_main(void) {
       problems++;
     }
   }
+
+  FOR_TRAIN(t,NOOP,NOOP) {
+    if (t->resolution == RR_H)
+      t->backwards= 0;
+  }
+  FOR_SEGMENT(d,NOOP,NOOP) {
+    if (d->home && d->home->resolution == RR_H)
+      d->tr_backwards= d->ho_backwards;
+  }
     
   TrackAdvanceContext tac;
   MovPosComb target;