From: Ian Jackson Date: Sun, 9 Jan 2011 22:07:45 +0000 (+0000) Subject: realtime: when reversing, a train's initial location may be unsuitable, eg because... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=050c67bd4eb2ad641707f5602cf9aec4b5925791;p=trains.git realtime: when reversing, a train's initial location may be unsuitable, eg because moveable features of to-become-owned segments are set wrong --- diff --git a/hostside/safety.c b/hostside/safety.c index 97e32a9..a85037f 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -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); diff --git a/hostside/safety.h b/hostside/safety.h index 9ae0caa..78447c7 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -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;