From: ian Date: Sun, 4 May 2008 22:11:43 +0000 (+0000) Subject: no really proper tail-eating X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=d0fc7aabe33c7587b84f9d93d618b0c4609117e6;p=trains.git no really proper tail-eating --- diff --git a/hostside/resolve.c b/hostside/resolve.c index 4b0350d..63ba1f6 100644 --- a/hostside/resolve.c +++ b/hostside/resolve.c @@ -506,7 +506,7 @@ static int resolve_complete_ends_train(Train *tra) { } report_train_position(tra); - report_train_ownerships(tra, u.furthest, 0); + report_train_ownerships(tra, t.seg, 1); return 0; } diff --git a/hostside/safety.c b/hostside/safety.c index 859465d..c4ef91c 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -235,7 +235,7 @@ typedef struct { count_time:1, accelerating:1, usecurrentposn:1, /* for pred_getmovpos */ - forceusemotions:1, /* for report_train_ownerships only */ + alwaysusemotions:1, /* for report_train_ownerships only */ walk_compute_polarise:1, /* nose_nextseg still needs to worry */ need_polarise:1, /* when we commit */ train_polarity_inverted:1, /* right now, or if know_best, the best */ @@ -244,7 +244,7 @@ typedef struct { TrackAdvanceContext nosec, tailc, fdetc; TimeInterval elapsed; /* from now, minimum */ Distance was_distance; - Segment *furthest; + Segment *hindmost; PredictionProblemCallback *problem_callback; void *problem_callback_u; @@ -292,7 +292,7 @@ static void pred_callback_debug(const char *what, TrackLocation *t, PredictUserContext *u= c->u; oprintf(DUPO("safety") " predict %s" - " %s%s until=%ld dist=%d (was %d) %c%c%c.%c %c%c%c%c.%c%c%c%c" + " %s%s until=%ld dist=%d (was %d) %c%c%c.%c %c%c%c.%c%c%c%c" " elapsed=%ld nit=%d,%d\n", what, t->backwards?"-":"", t->seg->i->pname, (long)t->seg->until, @@ -307,7 +307,6 @@ static void pred_callback_debug(const char *what, TrackLocation *t, "-t"[ u->count_time ], "-a"[ u->accelerating ], "-c"[ u->usecurrentposn ], - "-f"[ u->forceusemotions ], "-w"[ u->walk_compute_polarise ], "-n"[ u->need_polarise ], @@ -444,7 +443,6 @@ static int nose_nextseg(TrackLocation *t, TrackAdvanceContext *c, t->seg->tr_backwards= t->backwards; t->seg->pred_present= 1; t->seg->until= u->elapsed; - u->furthest= t->seg; return 0; /* yay! */ } @@ -592,9 +590,8 @@ static int report_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, int r; if (t->seg->owner != u->train) return -1; - if (t->seg == u->furthest) { - /* We've gone back past our own tail into the place where our - * head is going to be in the far future. */ + if (t->seg == u->hindmost && t->seg->tr_backwards == t->backwards) { + /* We've looped the loop. */ oprintf(UPO, " ..."); return -1; } @@ -607,10 +604,10 @@ static int report_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, strcat(flags,"."); if (t->seg == u->train->foredetect) { strcat(flags,"!"); - u->usecurrentposn=u->forceusemotions; + u->usecurrentposn= 0; } - oprintf(UPO," %s%s", t->seg->tr_backwards?"-":"", t->seg->i->pname); + oprintf(UPO," %s%s", t->backwards?"-":"", t->seg->i->pname); if (t->seg->i->n_poscombs > 1) { r= pred_getmovpos(t,c,mpc); assert(!r); assert(*mpc>=0); @@ -621,35 +618,35 @@ static int report_nextseg(TrackLocation *t, struct TrackAdvanceContext *c, return 0; } -void report_train_ownerships(Train *tra, Segment *furthest, - int force_use_motions) { +void report_train_ownerships(Train *tra, Segment *hindmost, + int always_use_motions) { PredictUserContext u; MovPosComb mpc; int r; memset(&u,0,sizeof(u)); u.train= tra; - u.furthest= 0; - u.usecurrentposn= 0; - u.forceusemotions= force_use_motions; + u.hindmost= 0; + u.alwaysusemotions= always_use_motions; + u.usecurrentposn= !always_use_motions; - /* Walk backwards along the train printing its segments: */ + /* Walk along the train printing its segments: */ oprintf(UPO, "train %s has", tra->pname); - u.tail.seg= furthest; - u.tail.remain= 0; - u.tail.backwards= !u.tail.seg->tr_backwards; + u.nose.seg= hindmost; + u.nose.remain= 0; + u.nose.backwards= hindmost->tr_backwards; - u.tailc.distance= TL_DIST_INF;; - u.tailc.nextseg= report_nextseg; - u.tailc.getmovpos= pred_getmovpos; - u.tailc.u= &u; + u.nosec.distance= TL_DIST_INF;; + u.nosec.nextseg= report_nextseg; + u.nosec.getmovpos= pred_getmovpos; + u.nosec.u= &u; - mpc= furthest->movposcomb; - r= report_nextseg(&u.tail,&u.tailc,&mpc,0); assert(!r); + mpc= u.nose.seg->movposcomb; + r= report_nextseg(&u.nose,&u.nosec,&mpc,0); assert(!r); - u.furthest= furthest; - trackloc_advance(&u.tail,&u.tailc); + u.hindmost= hindmost; + trackloc_advance(&u.nose,&u.nosec); oprintf(UPO, "\n"); } @@ -690,7 +687,6 @@ ErrorCode predict(Train *tra, int accelerate, u.accelerating= accelerate; u.walk_compute_polarise= 1; u.train_polarity_inverted= foredet->seg_inverted ^ foredet->tr_backwards; - u.furthest= tra->foredetect; u.usecurrentposn= 1; u.fdetc.getmovpos= pred_getmovpos; @@ -717,6 +713,8 @@ ErrorCode predict(Train *tra, int accelerate, ec= trackloc_advance(&u.tail,&u.tailc); assert(!ec); trackloc_reverse_exact(&u.tail,0); + u.hindmost= u.tail.seg; + /* find the train's nose */ u.nose= u.fdet; @@ -790,7 +788,7 @@ ErrorCode predict(Train *tra, int accelerate, if (u.need_polarise) actual_inversions_done(); - report_train_ownerships(tra,u.furthest,0); + report_train_ownerships(tra,u.hindmost,0); return 0; xproblem: diff --git a/hostside/safety.h b/hostside/safety.h index 458494d..520867b 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -117,7 +117,7 @@ ErrorCode predict(Train *tra, int accelerate, void report_train_position(Train *tra); void report_train_ownerships(Train *tra, Segment *furthest, - int force_use_motions); + int always_use_motions); /* ... for use by things which update these only, which * is basically safety.c and resolve.c */