From 36d02733a880b7403209cb9577da1ee30fe57d71 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 7 Feb 2010 12:57:19 +0000 Subject: [PATCH] Only draw points arrow when we are near it --- include/ITrackSegment.hpp | 4 ++++ src/CrossoverTrack.cpp | 1 + src/CurvedTrack.cpp | 1 + src/Game.cpp | 1 + src/Points.cpp | 19 ++++++++++++++++--- src/StraightTrack.cpp | 1 + 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/ITrackSegment.hpp b/include/ITrackSegment.hpp index 58fb864..b17d26e 100644 --- a/include/ITrackSegment.hpp +++ b/include/ITrackSegment.hpp @@ -138,6 +138,10 @@ struct ITrackSegment { virtual bool hasMultipleStates() const = 0; virtual void prevState() = 0; virtual void nextState() = 0; + + // Set a hint to display something about the track state on the next render + // call - e.g display an arrow over points + virtual void setStateRenderHint() = 0; }; ITrackSegmentPtr makeStraightTrack(const track::Direction& aDirection); diff --git a/src/CrossoverTrack.cpp b/src/CrossoverTrack.cpp index c91c325..e370d2e 100644 --- a/src/CrossoverTrack.cpp +++ b/src/CrossoverTrack.cpp @@ -53,6 +53,7 @@ public: void nextState() {} void prevState() {} bool hasMultipleStates() const { return false; } + void setStateRenderHint() {} private: void transform(const track::TravelToken& aToken, double aDelta) const; diff --git a/src/CurvedTrack.cpp b/src/CurvedTrack.cpp index 0cf8030..086959d 100644 --- a/src/CurvedTrack.cpp +++ b/src/CurvedTrack.cpp @@ -58,6 +58,7 @@ public: bool hasMultipleStates() const { return false; } void nextState() {} void prevState() {} + void setStateRenderHint() {} private: void transform(const track::TravelToken& aToken, double aDelta) const; diff --git a/src/Game.cpp b/src/Game.cpp index 2d9f33b..8fbd241 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -261,6 +261,7 @@ void Game::lookAhead() break; case TRACK_CHOICE: setStatus("Oh no! You have to make a decision!"); + it.track->setStateRenderHint(); break; default: break; diff --git a/src/Points.cpp b/src/Points.cpp index c2837c5..a0b4390 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -46,6 +46,7 @@ public: void nextState(); void prevState(); bool hasMultipleStates() const { return true; } + void setStateRenderHint(); private: void transform(const track::TravelToken& aToken, double aDelta) const; @@ -62,6 +63,9 @@ private: bool reflected; State state; + // Draw the arrow over the points if true + mutable bool stateRenderHint; + static const BezierCurve myCurve, myReflectedCurve; }; @@ -80,11 +84,17 @@ const BezierCurve Points::myReflectedCurve = makeBezierCurve Points::Points(track::Direction aDirection, bool reflect) : myX(0), myY(0), myAxis(aDirection), reflected(reflect), - state(NOT_TAKEN) + state(NOT_TAKEN), + stateRenderHint(false) { } +void Points::setStateRenderHint() +{ + stateRenderHint = true; +} + void Points::renderArrow() const { glPushMatrix(); @@ -215,8 +225,11 @@ void Points::render() const glTranslatef(0.25f, 0.0f, 0.0f); } glPopMatrix(); - - renderArrow(); + + if (stateRenderHint) { + renderArrow(); + stateRenderHint = false; + } glPopMatrix(); } diff --git a/src/StraightTrack.cpp b/src/StraightTrack.cpp index ac17dbd..f554f84 100644 --- a/src/StraightTrack.cpp +++ b/src/StraightTrack.cpp @@ -57,6 +57,7 @@ public: bool hasMultipleStates() const { return false; } void nextState() {} void prevState() {} + void setStateRenderHint() {} private: void transform(const track::TravelToken& aToken, double aDelta) const; -- 2.39.2