From 019bfd0f43c09bf15f95052084f550ef41f08b97 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 6 Feb 2010 21:08:06 +0000 Subject: [PATCH] Remove choice code --- include/IController.hpp | 33 ++++++++++-------------- include/ITrackSegment.hpp | 13 ---------- src/CrossoverTrack.cpp | 2 -- src/CurvedTrack.cpp | 2 -- src/Engine.cpp | 19 -------------- src/Game.cpp | 6 ++--- src/IterateTrack.cpp | 4 +-- src/Points.cpp | 16 ++++++------ src/StraightTrack.cpp | 2 -- src/Train.cpp | 53 ++++++--------------------------------- 10 files changed, 34 insertions(+), 116 deletions(-) diff --git a/include/IController.hpp b/include/IController.hpp index b635e90..bdd0cd5 100644 --- a/include/IController.hpp +++ b/include/IController.hpp @@ -23,33 +23,26 @@ // Actions the user can send enum Action { - BRAKE_TOGGLE, - SHOVEL_COAL, - THROTTLE_UP, - THROTTLE_DOWN, - TOGGLE_REVERSE, - GO_STRAIGHT_ON, - GO_LEFT, - GO_RIGHT, + BRAKE_TOGGLE, + SHOVEL_COAL, + THROTTLE_UP, + THROTTLE_DOWN, + TOGGLE_REVERSE, }; // Interface to something that can be controlled by the user struct IController { - virtual ~IController() {} + virtual ~IController() {} - virtual void actOn(Action anAction) = 0; - - // Return the choice for the next section of track and reset - // it to the default - virtual track::Choice consumeChoice() = 0; + virtual void actOn(Action anAction) = 0; - // Get current values for the display - virtual int throttle() const = 0; - virtual bool brakeOn() const = 0; - virtual double pressure() const = 0; - virtual double temp() const = 0; + // Get current values for the display + virtual int throttle() const = 0; + virtual bool brakeOn() const = 0; + virtual double pressure() const = 0; + virtual double temp() const = 0; - virtual bool stopped() const = 0; + virtual bool stopped() const = 0; }; typedef shared_ptr IControllerPtr; diff --git a/include/ITrackSegment.hpp b/include/ITrackSegment.hpp index def8e26..96e92e6 100644 --- a/include/ITrackSegment.hpp +++ b/include/ITrackSegment.hpp @@ -46,13 +46,6 @@ namespace track { struct TravelToken; typedef function TransformFunc; - // Choices that the player may make for a track segment - enum Choice { - CHOOSE_STRAIGHT_ON, - CHOOSE_GO_LEFT, - CHOOSE_GO_RIGHT - }; - // Sums up all the information required to travel along a piece // of track struct TravelToken { @@ -62,9 +55,6 @@ namespace track { // Position of entry Position position; - // Default choice - Choice activeChoice; - // 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 @@ -75,9 +65,6 @@ namespace track { { transformer(*this, aDelta); } - - // Choices available to the player - set choices; }; } diff --git a/src/CrossoverTrack.cpp b/src/CrossoverTrack.cpp index ad8dfba..1910872 100644 --- a/src/CrossoverTrack.cpp +++ b/src/CrossoverTrack.cpp @@ -111,10 +111,8 @@ CrossoverTrack::getTravelToken(track::Position aPosition, track::TravelToken tok = { aDirection, aPosition, - track::CHOOSE_STRAIGHT_ON, bind(&CrossoverTrack::transform, this, _1, _2) }; - tok.choices.insert(track::CHOOSE_STRAIGHT_ON); return tok; } diff --git a/src/CurvedTrack.cpp b/src/CurvedTrack.cpp index 0dc684f..03e0328 100644 --- a/src/CurvedTrack.cpp +++ b/src/CurvedTrack.cpp @@ -93,10 +93,8 @@ CurvedTrack::getTravelToken(track::Position aPosition, track::TravelToken tok = { aDirection, aPosition, - track::CHOOSE_STRAIGHT_ON, bind(&CurvedTrack::transform, this, _1, _2) }; - tok.choices.insert(track::CHOOSE_STRAIGHT_ON); return tok; } diff --git a/src/Engine.cpp b/src/Engine.cpp index 757c8a4..3b520b3 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -76,7 +76,6 @@ public: bool brakeOn() const { return isBrakeOn; } double pressure() const { return myBoilerPressure; } double temp() const { return myFireTemp; } - track::Choice consumeChoice(); bool stopped() const { return haveStopped; } // IXMLCallback interface @@ -95,8 +94,6 @@ private: bool reverse; bool haveStopped; - track::Choice nextChoice; - // Boiler pressure lags behind temperature MovingAverage myBoilerDelay; @@ -218,13 +215,6 @@ void Engine::update(int aDelta) // << " (delta=" << aDelta << ")"; } -track::Choice Engine::consumeChoice() -{ - track::Choice c = nextChoice; - nextChoice = track::CHOOSE_STRAIGHT_ON; - return c; -} - // User interface to the engine void Engine::actOn(Action anAction) { @@ -244,15 +234,6 @@ void Engine::actOn(Action anAction) case TOGGLE_REVERSE: reverse = !reverse; break; - case GO_STRAIGHT_ON: - nextChoice = track::CHOOSE_STRAIGHT_ON; - break; - case GO_LEFT: - nextChoice = track::CHOOSE_GO_LEFT; - break; - case GO_RIGHT: - nextChoice = track::CHOOSE_GO_RIGHT; - break; default: break; } diff --git a/src/Game.cpp b/src/Game.cpp index 8982983..fdc20a4 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -304,13 +304,13 @@ void Game::onKeyDown(SDLKey aKey) getGameWindow()->takeScreenShot(); break; case SDLK_LEFT: - train->controller()->actOn(GO_LEFT); + // train->controller()->actOn(GO_LEFT); break; case SDLK_RIGHT: - train->controller()->actOn(GO_RIGHT); + //train->controller()->actOn(GO_RIGHT); break; case SDLK_UP: - train->controller()->actOn(GO_STRAIGHT_ON); + //train->controller()->actOn(GO_STRAIGHT_ON); break; case SDLK_TAB: if (cameraMode == CAMERA_FLOATING) diff --git a/src/IterateTrack.cpp b/src/IterateTrack.cpp index a838bb3..b6d01e7 100644 --- a/src/IterateTrack.cpp +++ b/src/IterateTrack.cpp @@ -62,8 +62,8 @@ TrackIterator iterateTrack(IMapPtr aMap, track::Position aPosition, break; } - if (it.token.choices.size() > 1) - it.status = TRACK_CHOICE; + if (it.track->hasMultipleStates()) + it.status = TRACK_CHOICE; return it; } diff --git a/src/Points.cpp b/src/Points.cpp index ef69805..5fc9945 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -182,13 +182,11 @@ track::TravelToken Points::getTravelToken(track::Position aPosition, track::TravelToken tok = { aDirection, aPosition, - track::CHOOSE_STRAIGHT_ON, bind(&Points::transform, this, _1, _2) }; - tok.choices.insert(track::CHOOSE_STRAIGHT_ON); - - if (aPosition.x == myX && aPosition.y == myY) - tok.choices.insert(track::CHOOSE_GO_RIGHT); + + //if (aPosition.x == myX && aPosition.y == myY) + // tok.choices.insert(track::CHOOSE_GO_RIGHT); return tok; } @@ -200,7 +198,8 @@ void Points::transform(const track::TravelToken& aToken, double aDelta) const assert(aDelta < len); if (myX == aToken.position.x && myY == aToken.position.y - && aToken.activeChoice == track::CHOOSE_STRAIGHT_ON) { + // && aToken.activeChoice == track::CHOOSE_STRAIGHT_ON + ) { if (aToken.direction == myAxis && (myAxis == -axis::X || myAxis == -axis::Y)) @@ -246,7 +245,8 @@ void Points::transform(const track::TravelToken& aToken, double aDelta) const glTranslated(-0.5, 0.0, 0.0); } else if (aToken.position == displacedEndpoint() - || aToken.activeChoice != track::CHOOSE_STRAIGHT_ON) { + // || aToken.activeChoice != track::CHOOSE_STRAIGHT_ON + ) { // Curving onto the straight section float xTrans, yTrans, rotate; @@ -325,7 +325,7 @@ bool Points::isValidDirection(const track::Direction& aDirection) const track::Connection Points::nextPosition(const track::TravelToken& aToken) const { - bool branching = aToken.activeChoice != track::CHOOSE_STRAIGHT_ON; + bool branching = false; //aToken.activeChoice != track::CHOOSE_STRAIGHT_ON; if (myAxis == axis::X) { if (aToken.direction == -axis::X) { diff --git a/src/StraightTrack.cpp b/src/StraightTrack.cpp index 1923864..fd1675a 100644 --- a/src/StraightTrack.cpp +++ b/src/StraightTrack.cpp @@ -86,10 +86,8 @@ StraightTrack::getTravelToken(track::Position aPosition, track::TravelToken tok = { aDirection, aPosition, - track::CHOOSE_STRAIGHT_ON, bind(&StraightTrack::transform, this, _1, _2) }; - tok.choices.insert(track::CHOOSE_STRAIGHT_ON); return tok; } diff --git a/src/Train.cpp b/src/Train.cpp index 2078e68..01d06a6 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -64,9 +64,6 @@ private: // Direction train part is travelling along the track Vector direction; - // Turns to take if this is not the engine - queue followQueue; - // True if this is driving the train bool isLeading; @@ -87,9 +84,7 @@ private: void addPart(IRollingStockPtr aVehicle); Vector partPosition(const Part& aPart) const; void updateSmokePosition(int aDelta); - void makeFollow(track::Choice aChoice); void flipLeader(); - void dumpFollowQueue() const; void eachPart(function callback); void movePart(Part& part, double distance); @@ -158,39 +153,6 @@ const Train::Part& Train::leading() const return *p; } -// Make everything that's not the engine follow its choice -void Train::makeFollow(track::Choice aChoice) -{ - const Part& leader = leading(); - for (list::iterator it = parts.begin(); - it != parts.end(); ++it) { - if (*it != leader) - (*it).followQueue.push(aChoice); - } -} - -void Train::dumpFollowQueue() const -{ - ostringstream ss; - - for (list::const_iterator it = parts.begin(); - it != parts.end(); ++it) { - - if ((*it).isLeading) - ss << ">"; - - if ((*it).followQueue.empty()) - ss << "-"; - else { - ss << (*it).followQueue.front(); - } - - ss << " "; - } - - debug() << ss.str(); -} - Train::Part& Train::engine() { assert(parts.size() > 0); @@ -207,6 +169,7 @@ const Train::Part& Train::engine() const // versa void Train::flipLeader() { + // TODO: Delete? if (leading() == engine()) { // Make the last waggon the leader engine().isLeading = false; @@ -218,11 +181,11 @@ void Train::flipLeader() engine().isLeading = true; } - for (list::iterator it = parts.begin(); - it != parts.end(); ++it) { - while (!(*it).followQueue.empty()) - (*it).followQueue.pop(); - } + // for (list::iterator it = parts.begin(); + // it != parts.end(); ++it) { + // while (!(*it).followQueue.empty()) + // (*it).followQueue.pop(); + // } } // Iterate through the parts in order from the front of the @@ -358,7 +321,7 @@ void Train::enterSegment(Part& aPart, const track::Connection& aConnection) aPart.segment = map->trackAt(pos); aPart.travelToken = aPart.segment->getTravelToken(pos, aPart.direction); - if (aPart.travelToken.choices.size() > 1) { + /*if (aPart.travelToken.choices.size() > 1) { track::Choice choice; if (aPart == leading()) { @@ -375,7 +338,7 @@ void Train::enterSegment(Part& aPart, const track::Connection& aConnection) } aPart.travelToken.activeChoice = choice; - } + }*/ } void Train::transformToPart(const Part& p) -- 2.39.2