From ffdfeab21bf46054abf48cb1a748b8687f847b1e Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 28 Feb 2010 18:00:36 +0000 Subject: [PATCH] Add stub SlopeTrack class --- include/ITrackSegment.hpp | 8 +-- src/CrossoverTrack.cpp | 11 ++-- src/CurvedTrack.cpp | 10 ++-- src/Points.cpp | 6 +-- src/SlopeTrack.cpp | 104 ++++++++++++++++++++++++++++++++++++++ src/StraightTrack.cpp | 35 ++++++------- 6 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 src/SlopeTrack.cpp diff --git a/include/ITrackSegment.hpp b/include/ITrackSegment.hpp index 58302a2..dd26a5e 100644 --- a/include/ITrackSegment.hpp +++ b/include/ITrackSegment.hpp @@ -76,7 +76,7 @@ namespace axis { } struct ITrackSegment; -typedef std::tr1::shared_ptr ITrackSegmentPtr; +typedef shared_ptr ITrackSegmentPtr; // A segment of track which fits over a number of tiles // Each track segment has an origin and one or more exits @@ -127,8 +127,8 @@ struct ITrackSegment : IXMLSerialisable { // may be bigger than the origin segment // The track may already have an exit here in which case // a pointer to itself will be returned - virtual ITrackSegmentPtr mergeExit(const Point& aPoint, - const track::Direction& aDirection) = 0; + virtual ITrackSegmentPtr mergeExit(Point where, + track::Direction dir) = 0; // Some track segments may have several states - e.g. points // These functions change the track state @@ -146,5 +146,7 @@ ITrackSegmentPtr makeCurvedTrack(track::Angle aStartAngle, track::Angle aFinishAngle, int aRadius); ITrackSegmentPtr makeCrossoverTrack(); ITrackSegmentPtr makePoints(track::Direction aDirection, bool reflect); +ITrackSegmentPtr makeSlope(track::Direction axis, + Vector slopeBefore, Vector slopeAfter); #endif diff --git a/src/CrossoverTrack.cpp b/src/CrossoverTrack.cpp index 14dd454..1e2cf9b 100644 --- a/src/CrossoverTrack.cpp +++ b/src/CrossoverTrack.cpp @@ -46,8 +46,7 @@ public: track::Connection nextPosition(const track::TravelToken& aToken) const; void getEndpoints(vector >& aList) const; void getCovers(vector >& output) const { } - ITrackSegmentPtr mergeExit(const Point& aPoint, - const track::Direction& aDirection); + ITrackSegmentPtr mergeExit(Point where, track::Direction dir); track::TravelToken getTravelToken(track::Position aPosition, track::Direction aDirection) const; void nextState() {} @@ -177,11 +176,11 @@ void CrossoverTrack::getEndpoints(vector >& aList) const aList.push_back(makePoint(myX, myY)); } -ITrackSegmentPtr CrossoverTrack::mergeExit(const Point& aPoint, - const track::Direction& aDirection) +ITrackSegmentPtr CrossoverTrack::mergeExit(Point where, + track::Direction dir) { - if (aPoint == makePoint(myX, myY) - && isValidDirection(aDirection)) + if (where == makePoint(myX, myY) + && isValidDirection(dir)) return shared_from_this(); // No way to extend a crossover diff --git a/src/CurvedTrack.cpp b/src/CurvedTrack.cpp index 452accf..998a3eb 100644 --- a/src/CurvedTrack.cpp +++ b/src/CurvedTrack.cpp @@ -50,8 +50,7 @@ public: void getEndpoints(vector >& aList) const; void getCovers(vector >& output) const; - ITrackSegmentPtr mergeExit(const Point& aPoint, - const track::Direction& aDirection); + ITrackSegmentPtr mergeExit(Point where, track::Direction dir); xml::element toXml() const; track::TravelToken getTravelToken(track::Position aPosition, @@ -273,17 +272,16 @@ void CurvedTrack::getCovers(vector >& output) const copy(tmp.begin(), tmp.end(), back_inserter(output)); } -ITrackSegmentPtr CurvedTrack::mergeExit(const Point& aPoint, - const track::Direction& aDirection) +ITrackSegmentPtr CurvedTrack::mergeExit(Point where, track::Direction dir) { // See if this is already an exit - if (isValidDirection(aDirection)) { + if (isValidDirection(dir)) { vector > exits; getEndpoints(exits); for (vector >::iterator it = exits.begin(); it != exits.end(); ++it) - if (*it == aPoint) + if (*it == where) return shared_from_this(); } diff --git a/src/Points.cpp b/src/Points.cpp index 24ec621..39b948e 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -39,8 +39,7 @@ public: track::Connection nextPosition(const track::TravelToken& aToken) const; void getEndpoints(vector >& aList) const; void getCovers(vector >& output) const; - ITrackSegmentPtr mergeExit(const Point& aPoint, - const track::Direction& aDirection); + ITrackSegmentPtr mergeExit(Point where, track::Direction dir); track::TravelToken getTravelToken(track::Position aPosition, track::Direction aDirection) const; void nextState(); @@ -531,8 +530,7 @@ void Points::getCovers(vector >& output) const assert(false); } -ITrackSegmentPtr Points::mergeExit(const Point& aPoint, - const track::Direction& aDirection) +ITrackSegmentPtr Points::mergeExit(Point where, track::Direction dir) { // Cant merge with anything return ITrackSegmentPtr(); diff --git a/src/SlopeTrack.cpp b/src/SlopeTrack.cpp new file mode 100644 index 0000000..78e39c6 --- /dev/null +++ b/src/SlopeTrack.cpp @@ -0,0 +1,104 @@ +// +// Copyright (C) 2010 Nick Gasson +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include "ITrackSegment.hpp" +#include "IXMLSerialisable.hpp" +#include "XMLBuilder.hpp" + +// Like StraightTrack but with a change of height +class SlopeTrack : public ITrackSegment { +public: + SlopeTrack(track::Direction axis, + Vector slopeBefore, Vector slopeAfter); + + // ITrackSegment interface + void render() const; + void setOrigin(int x, int y) { origin = makePoint(x, y); } + double segmentLength(const track::TravelToken& token) const; + track::TravelToken getTravelToken(track::Position pos, + track::Direction dir) const; + bool isValidDirection(const track::Direction& dir) const; + track::Connection nextPosition(const track::TravelToken& token) const; + void getEndpoints(vector >& output) const; + void getCovers(vector >& output) const {}; + ITrackSegmentPtr mergeExit(Point where, track::Direction dir); + + bool hasMultipleStates() const { return false; } + void nextState() {} + void prevState() {} + void setStateRenderHint() {} + + // IXMLSerialisable inteface + xml::element toXml() const; + +private: + Point origin; +}; + +SlopeTrack::SlopeTrack(track::Direction axis, + Vector slopeBefore, Vector slopeAfter) +{ + +} + +void SlopeTrack::render() const +{ + +} + +double SlopeTrack::segmentLength(const track::TravelToken& token) const +{ + return 1.0; // TODO: use Pythagoras! +} + +bool SlopeTrack::isValidDirection(const track::Direction& dir) const +{ + return false; // TODO +} + +track::Connection SlopeTrack::nextPosition( + const track::TravelToken& token) const +{ + // TODO +} + +track::TravelToken SlopeTrack::getTravelToken(track::Position pos, + track::Direction dir) const +{ + // TODO +} + +void SlopeTrack::getEndpoints(vector >& output) const +{ + +} + +ITrackSegmentPtr SlopeTrack::mergeExit(Point where, track::Direction dir) +{ + return ITrackSegmentPtr(); +} + +xml::element SlopeTrack::toXml() const +{ + return xml::element("slopeTrack"); +} + +ITrackSegmentPtr makeSlope(track::Direction axis, + Vector slopeBefore, Vector slopeAfter) +{ + return ITrackSegmentPtr(new SlopeTrack(axis, slopeBefore, slopeAfter)); +} diff --git a/src/StraightTrack.cpp b/src/StraightTrack.cpp index 6fe7663..1afb64a 100644 --- a/src/StraightTrack.cpp +++ b/src/StraightTrack.cpp @@ -49,8 +49,7 @@ public: void getEndpoints(vector >& aList) const; void getCovers(vector >& output) const { } - ITrackSegmentPtr mergeExit(const Point& aPoint, - const track::Direction& aDirection); + ITrackSegmentPtr mergeExit(Point where, track::Direction dir); track::TravelToken getTravelToken(track::Position aPosition, track::Direction aDirection) const; @@ -120,41 +119,43 @@ void StraightTrack::transform(const track::TravelToken& aToken, glRotated(-180.0, 0.0, 1.0, 0.0); } -ITrackSegmentPtr StraightTrack::mergeExit(const Point& aPoint, - const track::Direction& aDirection) +ITrackSegmentPtr StraightTrack::mergeExit(Point where, + track::Direction dir) { - debug() << "mergeExit aPoint=" << aPoint - << " aDirection=" << aDirection +#if 0 + debug() << "mergeExit where=" << where + << " dir=" << dir << " me=" << origin; +#endif // See if this is already a valid exit - if (isValidDirection(aDirection) && aPoint == origin) + if (isValidDirection(dir) && where == origin) return shared_from_this(); // See if we can make this a crossover track - if (direction != aDirection && aPoint == origin) + if (direction != dir && where == origin) return makeCrossoverTrack(); // See if we can make some points - if (isValidDirection(aDirection)) { + if (isValidDirection(dir)) { // X-aligned points - if (aPoint == origin + makePoint(-2, 1)) + if (where == origin + makePoint(-2, 1)) return makePoints(-axis::X, true); - else if (aPoint == origin + makePoint(-2, -1)) + else if (where == origin + makePoint(-2, -1)) return makePoints(-axis::X, false); - else if (aPoint == origin + makePoint(2, 1)) + else if (where == origin + makePoint(2, 1)) return makePoints(axis::X, false); - else if (aPoint == origin + makePoint(2, -1)) + else if (where == origin + makePoint(2, -1)) return makePoints(axis::X, true); // Y-aligned points - if (aPoint == origin + makePoint(1, -2)) + if (where == origin + makePoint(1, -2)) return makePoints(-axis::Y, false); - else if (aPoint == origin + makePoint(-1, -2)) + else if (where == origin + makePoint(-1, -2)) return makePoints(-axis::Y, true); - else if (aPoint == origin + makePoint(1, 2)) + else if (where == origin + makePoint(1, 2)) return makePoints(axis::Y, true); - else if (aPoint == origin + makePoint(-1, 2)) + else if (where == origin + makePoint(-1, 2)) return makePoints(axis::Y, false); } -- 2.39.2