From f83dfe3a388a9f137432eb1173384559cd7a8204 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 6 Feb 2010 21:42:22 +0000 Subject: [PATCH] Only allowing setting of points when choice possible --- include/ITrackSegment.hpp | 10 +++++++--- src/CrossoverTrack.cpp | 3 ++- src/CurvedTrack.cpp | 3 ++- src/IterateTrack.cpp | 8 +++++++- src/Points.cpp | 18 +++++++++--------- src/StraightTrack.cpp | 3 ++- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/include/ITrackSegment.hpp b/include/ITrackSegment.hpp index 96e92e6..58fb864 100644 --- a/include/ITrackSegment.hpp +++ b/include/ITrackSegment.hpp @@ -55,11 +55,15 @@ namespace track { // Position of entry Position position; - // A function that transforms the location of the train - // so it will render in the correct place for this track segment - // The functions assumes that it is initially placed at the origin + // A function that transforms the location of the train so it will + // render in the correct place for this track segment The functions + // assumes that it is initially placed at the origin TransformFunc transformer; + // Number of possible exits from this track segment given the direction + // we are travelling in + int numExits; + // Wrapper for the above void transform(double aDelta) const { diff --git a/src/CrossoverTrack.cpp b/src/CrossoverTrack.cpp index 1910872..c91c325 100644 --- a/src/CrossoverTrack.cpp +++ b/src/CrossoverTrack.cpp @@ -111,7 +111,8 @@ CrossoverTrack::getTravelToken(track::Position aPosition, track::TravelToken tok = { aDirection, aPosition, - bind(&CrossoverTrack::transform, this, _1, _2) + bind(&CrossoverTrack::transform, this, _1, _2), + 1 }; return tok; } diff --git a/src/CurvedTrack.cpp b/src/CurvedTrack.cpp index 03e0328..0cf8030 100644 --- a/src/CurvedTrack.cpp +++ b/src/CurvedTrack.cpp @@ -93,7 +93,8 @@ CurvedTrack::getTravelToken(track::Position aPosition, track::TravelToken tok = { aDirection, aPosition, - bind(&CurvedTrack::transform, this, _1, _2) + bind(&CurvedTrack::transform, this, _1, _2), + 1 }; return tok; } diff --git a/src/IterateTrack.cpp b/src/IterateTrack.cpp index b6d01e7..4dd9d73 100644 --- a/src/IterateTrack.cpp +++ b/src/IterateTrack.cpp @@ -17,6 +17,8 @@ #include "IterateTrack.hpp" +#include + // Find the next piece of track TrackIterator TrackIterator::next() const { @@ -62,8 +64,12 @@ TrackIterator iterateTrack(IMapPtr aMap, track::Position aPosition, break; } - if (it.track->hasMultipleStates()) + if (it.token.numExits > 1) { + assert(it.track->hasMultipleStates()); it.status = TRACK_CHOICE; + } + else + assert(it.token.numExits == 1); return it; } diff --git a/src/Points.cpp b/src/Points.cpp index a17dbbe..0d65310 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -179,22 +179,22 @@ double Points::segmentLength(const track::TravelToken& aToken) const return 3.0; } -track::TravelToken Points::getTravelToken(track::Position aPosition, - track::Direction aDirection) const +track::TravelToken Points::getTravelToken(track::Position position, + track::Direction direction) const { using namespace placeholders; - ensureValidDirection(aDirection); + ensureValidDirection(direction); + const int nExits = position.x == myX && position.y == myY ? 2 : 1; + track::TravelToken tok = { - aDirection, - aPosition, - bind(&Points::transform, this, _1, _2) + direction, + position, + bind(&Points::transform, this, _1, _2), + nExits }; - //if (aPosition.x == myX && aPosition.y == myY) - // tok.choices.insert(track::CHOOSE_GO_RIGHT); - return tok; } diff --git a/src/StraightTrack.cpp b/src/StraightTrack.cpp index fd1675a..ac17dbd 100644 --- a/src/StraightTrack.cpp +++ b/src/StraightTrack.cpp @@ -86,7 +86,8 @@ StraightTrack::getTravelToken(track::Position aPosition, track::TravelToken tok = { aDirection, aPosition, - bind(&StraightTrack::transform, this, _1, _2) + bind(&StraightTrack::transform, this, _1, _2), + 1 }; return tok; } -- 2.39.2