From 28d9d1b782734987fffd4cd6cffb8f1a53fb2ad7 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 1 Nov 2009 16:48:44 +0000 Subject: [PATCH] Renaming variables and refactoring code --- include/GameScreens.hpp | 2 +- src/Billboard.cpp | 48 +++++------ src/CurvedTrack.cpp | 83 ++++++++++--------- src/Editor.cpp | 154 ++++++++++++++++++------------------ src/Fog.cpp | 16 ++-- src/Game.cpp | 171 ++++++++++++++++++++-------------------- src/Main.cpp | 16 ++-- src/Mesh.cpp | 34 ++++---- src/QuadTree.cpp | 41 +++++----- src/SDLWindow.cpp | 58 +++++++------- src/SkyBox.cpp | 22 +++--- src/StraightTrack.cpp | 66 ++++++++-------- 12 files changed, 354 insertions(+), 357 deletions(-) diff --git a/include/GameScreens.hpp b/include/GameScreens.hpp index 0165010..76324bc 100644 --- a/include/GameScreens.hpp +++ b/include/GameScreens.hpp @@ -27,7 +27,7 @@ IScreenPtr makeEditorScreen(IMapPtr aMap); IScreenPtr makeEditorScreen(const string& aMapName); IScreenPtr makeGameScreen(IMapPtr aMap); -IScreenPtr make_ui_demo(); +IScreenPtr makeUIDemo(); // Access to the window the game is running in IWindowPtr getGameWindow(); diff --git a/src/Billboard.cpp b/src/Billboard.cpp index 24a880e..476d999 100644 --- a/src/Billboard.cpp +++ b/src/Billboard.cpp @@ -29,9 +29,9 @@ namespace { class BillboardCommon : public IBillboard { public: BillboardCommon(ITexturePtr aTexture) - : myTexture(aTexture), - myX(0.0f), myY(0.0f), myZ(0.0f), myScale(1.0f), - myR(1.0f), myG(1.0f), myB(1.0f), myA(1.0f) {} + : texture(aTexture), + x_(0.0f), y_(0.0f), z_(0.0f), scale(1.0f), + r_(1.0f), g_(1.0f), b_(1.0f), a_(1.0f) {} virtual ~BillboardCommon() {} // IBillboard interface @@ -40,40 +40,40 @@ public: void setColour(float r, float g, float b, float a); private: - const ITexturePtr myTexture; + const ITexturePtr texture; protected: void drawTextureQuad() const; void translate() const; - float myX, myY, myZ; - float myScale; - float myR, myG, myB, myA; + float x_, y_, z_; + float scale; + float r_, g_, b_, a_; }; void BillboardCommon::setPosition(float x, float y, float z) { - myX = x; - myY = y; - myZ = z; + x_ = x; + y_ = y; + z_ = z; } void BillboardCommon::setColour(float r, float g, float b, float a) { - myR = r; - myG = g; - myB = b; - myA = a; + r_ = r; + g_ = g; + b_ = b; + a_ = a; } void BillboardCommon::setScale(float aScale) { - myScale = aScale; + scale = aScale; } void BillboardCommon::translate() const { - glTranslatef(myX, myY, myZ); + glTranslatef(x_, y_, z_); } // Draw the actual quad containing the texture @@ -85,11 +85,11 @@ void BillboardCommon::drawTextureQuad() const glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); - glColor4f(myR, myG, myB, myA); + glColor4f(r_, g_, b_, a_); - myTexture->bind(); + texture->bind(); - const float w = myScale / 2.0f; + const float w = scale / 2.0f; glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); @@ -174,9 +174,9 @@ void SphericalBillboard::render() const // objToCamProj is the vector in world coordinates from the // local origin to the camera projected in the XZ plane - objToCamProj = makeVector(theCameraPosition.x - myX, + objToCamProj = makeVector(theCameraPosition.x - x_, 0.0f, - theCameraPosition.z - myZ); + theCameraPosition.z - z_); // This is the original lookAt vector for the object // in world coordinates @@ -207,9 +207,9 @@ void SphericalBillboard::render() const // objToCam is the vector in world coordinates from // the local origin to the camera - objToCam = makeVector(theCameraPosition.x - myX, - theCameraPosition.y - myY, - theCameraPosition.z - myZ); + objToCam = makeVector(theCameraPosition.x - x_, + theCameraPosition.y - y_, + theCameraPosition.z - z_); // Normalize to get the cosine afterwards objToCam.normalise(); diff --git a/src/CurvedTrack.cpp b/src/CurvedTrack.cpp index b9a008f..33392bc 100644 --- a/src/CurvedTrack.cpp +++ b/src/CurvedTrack.cpp @@ -26,10 +26,8 @@ #include #include - -using namespace std; -using namespace std::tr1; -using namespace std::tr1::placeholders; + +using namespace placeholders; using namespace track; using namespace boost; @@ -43,7 +41,7 @@ public: void render() const; - void setOrigin(int x, int y) { myX = x; myY = y; } + void setOrigin(int x, int y) { origin.x = x; origin.y = y; } double segmentLength(const track::TravelToken& aToken) const; Connection nextPosition(const track::TravelToken& aToken) const; @@ -62,16 +60,17 @@ private: Vector cwEntryVector() const; Vector ccwEntryVector() const; void ensureValidDirection(const Direction& aDirection) const; - - int myX, myY, myBaseRadius; - track::Angle myStartAngle, myFinishAngle; + + Point origin; + int baseRadius; + track::Angle startAngle, finishAngle; }; CurvedTrack::CurvedTrack(track::Angle aStartAngle, track::Angle aFinishAngle, int aRadius) - : myX(0), myY(0), myBaseRadius(aRadius), - myStartAngle(aStartAngle), myFinishAngle(aFinishAngle) + : origin(makePoint(0, 0)), baseRadius(aRadius), + startAngle(aStartAngle), finishAngle(aFinishAngle) { } @@ -101,11 +100,11 @@ void CurvedTrack::transform(const track::TravelToken& aToken, double aDelta) con { assert(aDelta < segmentLength(aToken)); - glTranslated(static_cast(myX), + glTranslated(static_cast(origin.x), 0.0, - static_cast(myY)); + static_cast(origin.y)); - transformToOrigin(myBaseRadius, myStartAngle); + transformToOrigin(baseRadius, startAngle); bool backwards = aToken.direction == cwEntryVector(); @@ -113,10 +112,10 @@ void CurvedTrack::transform(const track::TravelToken& aToken, double aDelta) con if (backwards) ratio = 1.0 - ratio; - double angle = myStartAngle + (90.0 * ratio); + double angle = startAngle + (90.0 * ratio); glRotated(angle, 0.0, 1.0, 0.0); - glTranslated(0.0, 0.0, static_cast(myBaseRadius - 0.5)); + glTranslated(0.0, 0.0, static_cast(baseRadius - 0.5)); if (backwards) glRotatef(180.0, 0, 1, 0); @@ -125,7 +124,7 @@ void CurvedTrack::transform(const track::TravelToken& aToken, double aDelta) con double CurvedTrack::segmentLength(const track::TravelToken& aToken) const { // Assume curve is only through 90 degrees - return M_PI * (static_cast(myBaseRadius) - 0.5) / 2.0; + return M_PI * (static_cast(baseRadius) - 0.5) / 2.0; } // @@ -150,15 +149,15 @@ double CurvedTrack::segmentLength(const track::TravelToken& aToken) const // The vector the train is moving on if it enters clockwise Vector CurvedTrack::cwEntryVector() const { - return makeVector(-cos(degToRad(myFinishAngle)), 0, - sin(degToRad(myFinishAngle))); + return makeVector(-cos(degToRad(finishAngle)), 0, + sin(degToRad(finishAngle))); } // The vector the train is moving on if it enters counter-clockwise Vector CurvedTrack::ccwEntryVector() const { - return makeVector(cos(degToRad(myStartAngle)), 0.0, - -sin(degToRad(myStartAngle))); + return makeVector(cos(degToRad(startAngle)), 0.0, + -sin(degToRad(startAngle))); } void CurvedTrack::ensureValidDirection(const Direction& aDirection) const @@ -166,8 +165,8 @@ void CurvedTrack::ensureValidDirection(const Direction& aDirection) const if (!isValidDirection(aDirection)) throw runtime_error ("Invalid direction on curved track from " - + lexical_cast(myStartAngle) + " to " - + lexical_cast(myFinishAngle) + " degrees: " + + lexical_cast(startAngle) + " to " + + lexical_cast(finishAngle) + " degrees: " + lexical_cast(aDirection) + " (should be " + lexical_cast(cwEntryVector()) + " or " @@ -195,39 +194,39 @@ Connection CurvedTrack::nextPosition(const track::TravelToken& aToken) const assert(false); // Assuming 90 degree curves again - const int cosEnd = static_cast(cos(degToRad(myFinishAngle))); - const int cosStart = static_cast(cos(degToRad(myStartAngle))); - const int sinEnd = static_cast(sin(degToRad(myFinishAngle))); - const int sinStart = static_cast(sin(degToRad(myStartAngle))); + const int cosEnd = static_cast(cos(degToRad(finishAngle))); + const int cosStart = static_cast(cos(degToRad(startAngle))); + const int sinEnd = static_cast(sin(degToRad(finishAngle))); + const int sinStart = static_cast(sin(degToRad(startAngle))); int xDelta, yDelta; if (backwards) xDelta = yDelta = 0; else { - xDelta = (myBaseRadius - 1) * (sinEnd - sinStart); - yDelta = (myBaseRadius - 1) * (cosEnd - cosStart); + xDelta = (baseRadius - 1) * (sinEnd - sinStart); + yDelta = (baseRadius - 1) * (cosEnd - cosStart); } - return make_pair(makePoint(myX + xDelta + nextDir.x, - myY + yDelta + nextDir.z), + return make_pair(makePoint(origin.x + xDelta + nextDir.x, + origin.y + yDelta + nextDir.z), nextDir); } void CurvedTrack::getEndpoints(list >& aList) const { - aList.push_back(makePoint(myX, myY)); + aList.push_back(origin); // Assuming 90 degree curves again - const int cosEnd = static_cast(cos(degToRad(myFinishAngle))); - const int cosStart = static_cast(cos(degToRad(myStartAngle))); - const int sinEnd = static_cast(sin(degToRad(myFinishAngle))); - const int sinStart = static_cast(sin(degToRad(myStartAngle))); + const int cosEnd = static_cast(cos(degToRad(finishAngle))); + const int cosStart = static_cast(cos(degToRad(startAngle))); + const int sinEnd = static_cast(sin(degToRad(finishAngle))); + const int sinStart = static_cast(sin(degToRad(startAngle))); - const int xDelta = (myBaseRadius - 1) * (sinEnd - sinStart); - const int yDelta = (myBaseRadius - 1) * (cosEnd - cosStart); + const int xDelta = (baseRadius - 1) * (sinEnd - sinStart); + const int yDelta = (baseRadius - 1) * (cosEnd - cosStart); - aList.push_back(makePoint(myX + xDelta, myY + yDelta)); + aList.push_back(makePoint(origin.x + xDelta, origin.y + yDelta)); } ITrackSegmentPtr CurvedTrack::mergeExit(const Point& aPoint, @@ -250,15 +249,15 @@ ITrackSegmentPtr CurvedTrack::mergeExit(const Point& aPoint, void CurvedTrack::render() const { - renderCurvedTrack(myBaseRadius, myStartAngle, myFinishAngle); + renderCurvedTrack(baseRadius, startAngle, finishAngle); } xml::element CurvedTrack::toXml() const { return xml::element("curvedTrack") - .addAttribute("startAngle", myStartAngle) - .addAttribute("finishAngle", myFinishAngle) - .addAttribute("radius", myBaseRadius); + .addAttribute("startAngle", startAngle) + .addAttribute("finishAngle", finishAngle) + .addAttribute("radius", baseRadius); } ITrackSegmentPtr makeCurvedTrack(track::Angle aStartAngle, diff --git a/src/Editor.cpp b/src/Editor.cpp index 176e701..7de7584 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -62,7 +62,7 @@ public: }; void setTool(Tool aTool) { myTool = aTool; } - IMapPtr map() { return myMap; } + IMapPtr getMap() { return map; } void setMap(IMapPtr aMap); private: @@ -76,7 +76,7 @@ private: void dragBoxBounds(int& xMin, int& xMax, int &yMin, int& yMax) const; void deleteObjects(); - IMapPtr myMap; + IMapPtr map; ILightPtr mySun; Vector myPosition; @@ -85,7 +85,7 @@ private: bool amScrolling; // Variables for dragging track segments - Point myDragBegin, myDragEnd; + Point dragBegin, dragEnd; bool amDragging; }; @@ -170,7 +170,7 @@ namespace { { if (aResult == OK) anEditor->setMap(aMap); - else if (!anEditor->map()) + else if (!anEditor->getMap()) throw runtime_error("No map to edit!"); } @@ -185,7 +185,7 @@ namespace { void onSaveClick(Fl_Widget* aWidget) { - theEditor->map()->save(); + theEditor->getMap()->save(); } void onNewClick(Fl_Widget* aWidget) @@ -241,15 +241,15 @@ void addEditorGUI() } Editor::Editor(IMapPtr aMap) - : myMap(aMap), myPosition(4.5, -17.5, -21.5), + : map(aMap), myPosition(4.5, -17.5, -21.5), myTool(TRACK_TOOL), amScrolling(false), amDragging(false) { mySun = makeSunLight(); theEditor = this; - if (myMap) { - myMap->setGrid(true); + if (map) { + map->setGrid(true); log() << "Editing " << aMap->name(); } @@ -262,32 +262,32 @@ Editor::~Editor() void Editor::setMap(IMapPtr aMap) { - myMap = aMap; - myMap->setGrid(true); + map = aMap; + map->setGrid(true); } // Calculate the bounds of the drag box accounting for the different // possible directions of dragging void Editor::dragBoxBounds(int& xMin, int& xMax, int &yMin, int& yMax) const { - xMin = min(myDragBegin.x, myDragEnd.x); - xMax = max(myDragBegin.x, myDragEnd.x); + xMin = min(dragBegin.x, dragEnd.x); + xMax = max(dragBegin.x, dragEnd.x); - yMin = min(myDragBegin.y, myDragEnd.y); - yMax = max(myDragBegin.y, myDragEnd.y); + yMin = min(dragBegin.y, dragEnd.y); + yMax = max(dragBegin.y, dragEnd.y); } // Render the next frame void Editor::display(IGraphicsPtr aContext) const { - if (!myMap) + if (!map) return; aContext->setCamera(myPosition, makeVector(45.0f, 45.0f, 0.0f)); mySun->apply(); - myMap->render(aContext); + map->render(aContext); // Draw the highlight if we are dragging track if (amDragging) { @@ -296,7 +296,7 @@ void Editor::display(IGraphicsPtr aContext) const for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) - myMap->highlightTile(aContext, makePoint(x, y), + map->highlightTile(aContext, makePoint(x, y), make_tuple(1.0f, 1.0f, 1.0f)); } } @@ -319,10 +319,10 @@ void Editor::update(IPickBufferPtr aPickBuffer, int aDelta) bool Editor::canConnect(const Point& aFirstPoint, const Point& aSecondPoint) const { - if (!myMap->isValidTrack(aFirstPoint)) + if (!map->isValidTrack(aFirstPoint)) return false; - ITrackSegmentPtr track = myMap->trackAt(aFirstPoint); + ITrackSegmentPtr track = map->trackAt(aFirstPoint); Vector dir = makeVector (aFirstPoint.x - aSecondPoint.x, 0, @@ -336,10 +336,10 @@ bool Editor::canConnect(const Point& aFirstPoint, // Returns `false' if track cannot be placed here bool Editor::drawTrackTile(const Point& aPoint, const track::Direction& anAxis) { - if (myMap->isValidTrack(aPoint)) { - ITrackSegmentPtr merged = myMap->trackAt(aPoint)->mergeExit(aPoint, anAxis); + if (map->isValidTrack(aPoint)) { + ITrackSegmentPtr merged = map->trackAt(aPoint)->mergeExit(aPoint, anAxis); if (merged) { - myMap->setTrackAt(aPoint, merged); + map->setTrackAt(aPoint, merged); return true; } else { @@ -348,7 +348,7 @@ bool Editor::drawTrackTile(const Point& aPoint, const track::Direction& anA } } else { - myMap->setTrackAt(aPoint, makeStraightTrack(anAxis)); + map->setTrackAt(aPoint, makeStraightTrack(anAxis)); return true; } } @@ -357,7 +357,7 @@ bool Editor::drawTrackTile(const Point& aPoint, const track::Direction& anA // This just draws straight track along the rectangle void Editor::drawDraggedStraight(const track::Direction& anAxis, int aLength) { - Point where = myDragBegin; + Point where = dragBegin; for (int i = 0; i < aLength; i++) { drawTrackTile(where, anAxis); @@ -381,52 +381,52 @@ void Editor::drawDraggedTrack() // Try to merge the start and end directly const track::Direction mergeAxis = - xlen > ylen ? (myDragBegin.x < myDragEnd.x ? -axis::X : axis::X) - : (myDragBegin.y < myDragEnd.y ? -axis::Y : axis::Y); - if (myMap->isValidTrack(myDragEnd)) { + xlen > ylen ? (dragBegin.x < dragEnd.x ? -axis::X : axis::X) + : (dragBegin.y < dragEnd.y ? -axis::Y : axis::Y); + if (map->isValidTrack(dragEnd)) { ITrackSegmentPtr merged = - myMap->trackAt(myDragEnd)->mergeExit(myDragBegin, mergeAxis); + map->trackAt(dragEnd)->mergeExit(dragBegin, mergeAxis); if (merged) { // Erase all the tiles covered for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) - myMap->eraseTile(x, y); + map->eraseTile(x, y); } - myMap->setTrackAt(myDragEnd, merged); + map->setTrackAt(dragEnd, merged); return; } } // Normalise the coordinates so the start is always the one with // the smallest x-coordinate - if (myDragBegin.x > myDragEnd.x) - swap(myDragBegin, myDragEnd); + if (dragBegin.x > dragEnd.x) + swap(dragBegin, dragEnd); track::Direction startDir, endDir; bool startWasGuess = false; bool endWasGuess = false; // Try to work out the direction of the track start - if (canConnect(myDragBegin.left(), myDragBegin) - || canConnect(myDragBegin.right(), myDragBegin)) { + if (canConnect(dragBegin.left(), dragBegin) + || canConnect(dragBegin.right(), dragBegin)) { startDir = axis::X; } - else if (canConnect(myDragBegin.up(), myDragBegin) - || canConnect(myDragBegin.down(), myDragBegin)) { + else if (canConnect(dragBegin.up(), dragBegin) + || canConnect(dragBegin.down(), dragBegin)) { startDir = axis::Y; } else startWasGuess = true; // Try to work out the direction of the track end - if (canConnect(myDragEnd.left(), myDragEnd) - || canConnect(myDragEnd.right(), myDragEnd)) { + if (canConnect(dragEnd.left(), dragEnd) + || canConnect(dragEnd.right(), dragEnd)) { endDir = axis::X; } - else if (canConnect(myDragEnd.up(), myDragEnd) - || canConnect(myDragEnd.down(), myDragEnd)) { + else if (canConnect(dragEnd.up(), dragEnd) + || canConnect(dragEnd.down(), dragEnd)) { endDir = axis::Y; } else @@ -454,10 +454,10 @@ void Editor::drawDraggedTrack() if (xlen == 1 && ylen == 1) { // A single tile - drawTrackTile(myDragBegin, startDir); + drawTrackTile(dragBegin, startDir); } else if (xlen == 1) - drawDraggedStraight(myDragBegin.y < myDragEnd.y ? axis::Y : -axis::Y, ylen); + drawDraggedStraight(dragBegin.y < dragEnd.y ? axis::Y : -axis::Y, ylen); else if (ylen == 1) drawDraggedStraight(axis::X, xlen); else if (startDir == endDir) { @@ -472,34 +472,34 @@ void Editor::drawDraggedTrack() // One of the ends must lie along the x-axis since all // curves are through 90 degrees so extend that one if (startDir == axis::X) { - drawTrackTile(myDragBegin, axis::X); - myDragBegin.x++; + drawTrackTile(dragBegin, axis::X); + dragBegin.x++; } else { - drawTrackTile(myDragEnd, axis::X); - myDragEnd.x--; + drawTrackTile(dragEnd, axis::X); + dragEnd.x--; } xlen--; } else { // Need to draw track along y-axis if (startDir == axis::Y) { - drawTrackTile(myDragBegin, axis::Y); + drawTrackTile(dragBegin, axis::Y); // The y-coordinate for the drag points is not guaranteed // to be sorted - if (myDragBegin.y > myDragEnd.y) - myDragBegin.y--; + if (dragBegin.y > dragEnd.y) + dragBegin.y--; else - myDragBegin.y++; + dragBegin.y++; } else { - drawTrackTile(myDragEnd, axis::Y); + drawTrackTile(dragEnd, axis::Y); - if (myDragBegin.y > myDragEnd.y) - myDragEnd.y++; + if (dragBegin.y > dragEnd.y) + dragEnd.y++; else - myDragEnd.y--; + dragEnd.y--; } ylen--; } @@ -509,27 +509,27 @@ void Editor::drawDraggedTrack() Point where; if (startDir == axis::X && endDir == axis::Y) { - if (myDragBegin.y < myDragEnd.y) { + if (dragBegin.y < dragEnd.y) { startAngle = 90; endAngle = 180; - where = myDragEnd; + where = dragEnd; } else { startAngle = 0; endAngle = 90; - where = myDragBegin; + where = dragBegin; } } else { - if (myDragBegin.y < myDragEnd.y) { + if (dragBegin.y < dragEnd.y) { startAngle = 270; endAngle = 360; - where = myDragBegin; + where = dragBegin; } else { startAngle = 180; endAngle = 270; - where = myDragEnd; + where = dragEnd; } } @@ -542,7 +542,7 @@ void Editor::drawDraggedTrack() bool ok = true; for (list >::iterator it = exits.begin(); it != exits.end(); ++it) { - if (myMap->isValidTrack(*it)) { + if (map->isValidTrack(*it)) { warn() << "Cannot place curve here"; ok = false; break; @@ -550,7 +550,7 @@ void Editor::drawDraggedTrack() } if (ok) - myMap->setTrackAt(where, track); + map->setTrackAt(where, track); } } @@ -562,7 +562,7 @@ void Editor::deleteObjects() for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) - myMap->eraseTile(x, y); + map->eraseTile(x, y); } } @@ -571,14 +571,14 @@ void Editor::onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, { if (amDragging) { // Extend the selection rectangle - myMap->setPickMode(true); + map->setPickMode(true); IGraphicsPtr pickContext = aPickBuffer->beginPick(x, y); display(pickContext); int id = aPickBuffer->endPick(); - myMap->setPickMode(false); + map->setPickMode(false); if (id > 0) - myDragEnd = myMap->pickPosition(id); + dragEnd = map->pickPosition(id); } else if (amScrolling) { const float speed = 0.05f; @@ -602,17 +602,17 @@ void Editor::onMouseClick(IPickBufferPtr aPickBuffer, int x, int y, } else if (aButton == MOUSE_LEFT) { // See if the user clicked on something in the map - myMap->setPickMode(true); + map->setPickMode(true); IGraphicsPtr pickContext = aPickBuffer->beginPick(x, y); display(pickContext); int id = aPickBuffer->endPick(); - myMap->setPickMode(false); + map->setPickMode(false); if (id > 0) { // Begin dragging a selection rectangle - Point where = myMap->pickPosition(id); + Point where = map->pickPosition(id); - myDragBegin = myDragEnd = where; + dragBegin = dragEnd = where; amDragging = true; } } @@ -636,25 +636,25 @@ void Editor::onMouseRelease(IPickBufferPtr aPickBuffer, int x, int y, drawDraggedTrack(); break; case RAISE_TOOL: - myMap->raiseArea(myDragBegin, myDragEnd); + map->raiseArea(dragBegin, dragEnd); break; case LOWER_TOOL: - myMap->lowerArea(myDragBegin, myDragEnd); + map->lowerArea(dragBegin, dragEnd); break; case LEVEL_TOOL: - myMap->levelArea(myDragBegin, myDragEnd); + map->levelArea(dragBegin, dragEnd); break; case DELETE_TOOL: deleteObjects(); break; case START_TOOL: - myMap->setStart(myDragBegin.x, myDragBegin.y); + map->setStart(dragBegin.x, dragBegin.y); break; case STATION_TOOL: - myMap->extendStation(myDragBegin, myDragEnd); + map->extendStation(dragBegin, dragEnd); break; case BUILDING_TOOL: - myMap->placeBuilding(myDragBegin, theBuildingPicker->active(), + map->placeBuilding(dragBegin, theBuildingPicker->active(), theModelViewer->angle()); break; } @@ -678,7 +678,7 @@ void Editor::onKeyDown(SDLKey aKey) switch (aKey) { case SDLK_g: // Toggle grid - myMap->setGrid(true); + map->setGrid(true); break; default: break; diff --git a/src/Fog.cpp b/src/Fog.cpp index e80a11b..bfed6b8 100644 --- a/src/Fog.cpp +++ b/src/Fog.cpp @@ -27,25 +27,25 @@ class Fog : public IFog { public: Fog(float r, float g, float b, float density, float start, float end) - : myR(r), myG(g), myB(b), - myDensity(density), myStart(start), myEnd(end) {} + : r(r), g(g), b(b), + density(density), start(start), end(end) {} void apply() const; private: - float myR, myG, myB; - float myDensity, myStart, myEnd; + float r, g, b; + float density, start, end; }; void Fog::apply() const { - GLfloat fogColor[4] = { myR, myG, myB, 1.0f }; + GLfloat fogColor[4] = { r, g, b, 1.0f }; glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fogColor); - glFogf(GL_FOG_DENSITY, myDensity); + glFogf(GL_FOG_DENSITY, density); glHint(GL_FOG_HINT, GL_DONT_CARE); - glFogf(GL_FOG_START, myStart); - glFogf(GL_FOG_END, myEnd); + glFogf(GL_FOG_START, start); + glFogf(GL_FOG_END, end); glEnable(GL_FOG); } diff --git a/src/Game.cpp b/src/Game.cpp index 086a218..56aed00 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -46,34 +46,35 @@ public: void update(IPickBufferPtr aPickBuffer, int aDelta); void onKeyDown(SDLKey aKey); void onKeyUp(SDLKey aKey); - void onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, int xrel, int yrel); + void onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, int xrel, + int yrel); void onMouseClick(IPickBufferPtr aPickBuffer, int x, int y, MouseButton aButton); void onMouseRelease(IPickBufferPtr aPickBuffer, int x, int y, MouseButton aButton) {} private: void lookAhead(); - void setStatus(const string& aString) { myStatusMsg = aString; } - void nearStation(IStationPtr aStation); + void setStatus(const string& s) { statusMsg = s; } + void nearStation(IStationPtr s); void leftStation(); Vector cameraPosition(float aRadius) const; - IMapPtr myMap; - ITrainPtr myTrain; - ILightPtr mySun; + IMapPtr map; + ITrainPtr train; + ILightPtr sun; // Station the train is either approaching or stopped at - IStationPtr myActiveStation; + IStationPtr activeStation; // Camera position - float myHorizAngle, myVertAngle, myViewRadius; + float horizAngle, vertAngle, viewRadius; // Camera adjustment - float myCameraHTarget, myCameraVTarget; - float myCameraSpeed; + float cameraHTarget, cameraVTarget; + float cameraSpeed; enum CameraMode { CAMERA_FLOATING, CAMERA_FIXED, CAMERA_BIRD }; - CameraMode myCameraMode; + CameraMode cameraMode; // GUI elements IContainerPtr myStatsPanel; @@ -83,26 +84,26 @@ private: IMeterControlPtr myCoalMeter, myWaterMeter; ILayoutPtr layout; - string myStatusMsg; - gui::IFontPtr myStatusFont; + string statusMsg; + gui::IFontPtr statusFont; }; Game::Game(IMapPtr aMap) - : myMap(aMap), - myHorizAngle(2.5f), myVertAngle(1.0f), myViewRadius(10.0f), - myCameraHTarget(2.5f), myCameraVTarget(1.0f), - myCameraSpeed(1.0f), myCameraMode(CAMERA_FLOATING) + : map(aMap), + horizAngle(2.5f), vertAngle(1.0f), viewRadius(10.0f), + cameraHTarget(2.5f), cameraVTarget(1.0f), + cameraSpeed(1.0f), cameraMode(CAMERA_FLOATING) { - myTrain = makeTrain(myMap); - mySun = makeSunLight(); + train = makeTrain(map); + sun = makeSunLight(); - myMap->setGrid(false); + map->setGrid(false); // Build the GUI myStatsPanel = makeFlowBox(FLOW_BOX_VERT); gui::IFontPtr stdFont = gui::load_font("data/fonts/Vera.ttf", 14); - myStatusFont = gui::load_font("data/fonts/Vera.ttf", 18); + statusFont = gui::load_font("data/fonts/Vera.ttf", 18); mySpeedLabel = makeLabel(stdFont); myStatsPanel->addChild(mySpeedLabel); @@ -130,7 +131,7 @@ Game::Game(IMapPtr aMap) myStatsPanel->setOrigin(5, 10); - layout = gui::make_layout("layouts/game.xml"); + //layout = gui::makeLayout("layouts/game.xml"); } Game::~Game() @@ -143,59 +144,59 @@ Vector Game::cameraPosition(float aRadius) const // Two angles give unique position on surface of a sphere // Look up ``spherical coordinates'' const float yCentre = 0.9f; - Vector position = myTrain->front(); - position.x += aRadius * cosf(myHorizAngle) * sinf(myVertAngle); - position.z += aRadius * sinf(myHorizAngle) * sinf(myVertAngle); - position.y = aRadius * cosf(myVertAngle) + yCentre; + Vector position = train->front(); + position.x += aRadius * cosf(horizAngle) * sinf(vertAngle); + position.z += aRadius * sinf(horizAngle) * sinf(vertAngle); + position.y = aRadius * cosf(vertAngle) + yCentre; return position; } void Game::display(IGraphicsPtr aContext) const { - Vector trainPos = myTrain->front(); + Vector trainPos = train->front(); - Vector position = cameraPosition(myViewRadius); + Vector position = cameraPosition(viewRadius); aContext->lookAt(position, trainPos); setBillboardCameraOrigin(position); - mySun->apply(); + sun->apply(); - myMap->render(aContext); - myTrain->render(); + map->render(aContext); + train->render(); } void Game::overlay() const { //myStatsPanel->render(); - layout->render(); + //layout->render(); const int screenH = getGameWindow()->height(); const int screenW = getGameWindow()->width(); - const int len = myStatusFont->string_width("%s", myStatusMsg.c_str()); - myStatusFont->print((screenW - len)/2, screenH - 50, - "%s", myStatusMsg.c_str()); + const int len = statusFont->string_width("%s", statusMsg.c_str()); + statusFont->print((screenW - len)/2, screenH - 50, + "%s", statusMsg.c_str()); } void Game::update(IPickBufferPtr aPickBuffer, int aDelta) { - myTrain->update(aDelta); + train->update(aDelta); // Update the GUI elements const double msToMPH = 2.237; - mySpeedLabel->setText("Speed: %.1lfmph\n", myTrain->speed() * msToMPH); - myThrottleMeter->setValue(myTrain->controller()->throttle()); - myBrakeLabel->setVisible(myTrain->controller()->brakeOn()); + mySpeedLabel->setText("Speed: %.1lfmph\n", train->speed() * msToMPH); + myThrottleMeter->setValue(train->controller()->throttle()); + myBrakeLabel->setVisible(train->controller()->brakeOn()); - layout->get_cast("/status_wnd/speed_label").format( - "Speed: %.1lfmph", myTrain->speed() * msToMPH); + //layout->cast("/status_wnd/speed_label").format( + // "Speed: %.1lfmph", train->speed() * msToMPH); - const double pressure = myTrain->controller()->pressure(); + const double pressure = train->controller()->pressure(); myPressureLabel->setText("Pressure: %.lfpsi", pressure); - const double temp = myTrain->controller()->temp(); + const double temp = train->controller()->temp(); myTempLabel->setText("Temp: %.lfdeg", temp); myWaterMeter->setValue(8); @@ -206,39 +207,39 @@ void Game::update(IPickBufferPtr aPickBuffer, int aDelta) // Calculate the location of the near clip plane const float nearClip = getConfig()->get("NearClip"); - Vector clipPosition = cameraPosition(myViewRadius - nearClip); + Vector clipPosition = cameraPosition(viewRadius - nearClip); // A hack because we don't calculate the height properly const float MIN_HEIGHT = 0.25f; - float h = myMap->heightAt(clipPosition.x, clipPosition.z); + float h = map->heightAt(clipPosition.x, clipPosition.z); if (h + MIN_HEIGHT > clipPosition.y) { - myCameraVTarget -= 0.001f * static_cast(aDelta); - myCameraSpeed = 200.0f; + cameraVTarget -= 0.001f * static_cast(aDelta); + cameraSpeed = 200.0f; } // Bounce the camera if we need to - myVertAngle -= (myVertAngle - myCameraVTarget) / myCameraSpeed; - myHorizAngle -= (myHorizAngle - myCameraHTarget) / myCameraSpeed; + vertAngle -= (vertAngle - cameraVTarget) / cameraSpeed; + horizAngle -= (horizAngle - cameraHTarget) / cameraSpeed; } // Signal that we are approaching a station -void Game::nearStation(IStationPtr aStation) +void Game::nearStation(IStationPtr s) { leftStation(); // Clear any previous station - if (aStation != myActiveStation) { - myActiveStation = aStation; - aStation->setHighlightVisible(true); + if (s != activeStation) { + activeStation = s; + s->setHighlightVisible(true); } } // Signal that we are no longer at or approaching a station void Game::leftStation() { - if (myActiveStation) { - myActiveStation->setHighlightVisible(false); - myActiveStation.reset(); + if (activeStation) { + activeStation->setHighlightVisible(false); + activeStation.reset(); } } @@ -246,8 +247,8 @@ void Game::leftStation() // that they are approaching void Game::lookAhead() { - TrackIterator it = iterateTrack(myMap, myTrain->tile(), - myTrain->direction()); + TrackIterator it = iterateTrack(map, train->tile(), + train->direction()); // Are we sitting on a station? if (it.status == TRACK_STATION) { @@ -296,48 +297,48 @@ void Game::onKeyDown(SDLKey aKey) { switch (aKey) { case SDLK_PAGEUP: - myViewRadius = max(myViewRadius - 0.2f, 0.1f); + viewRadius = max(viewRadius - 0.2f, 0.1f); break; case SDLK_PAGEDOWN: - myViewRadius += 0.2f; + viewRadius += 0.2f; break; case SDLK_b: - myTrain->controller()->actOn(BRAKE_TOGGLE); + train->controller()->actOn(BRAKE_TOGGLE); break; case SDLK_LCTRL: - myTrain->controller()->actOn(SHOVEL_COAL); + train->controller()->actOn(SHOVEL_COAL); break; case SDLK_a: - myTrain->controller()->actOn(THROTTLE_DOWN); + train->controller()->actOn(THROTTLE_DOWN); break; case SDLK_s: - myTrain->controller()->actOn(THROTTLE_UP); + train->controller()->actOn(THROTTLE_UP); break; case SDLK_PRINT: getGameWindow()->takeScreenShot(); break; case SDLK_LEFT: - myTrain->controller()->actOn(GO_LEFT); + train->controller()->actOn(GO_LEFT); break; case SDLK_RIGHT: - myTrain->controller()->actOn(GO_RIGHT); + train->controller()->actOn(GO_RIGHT); break; case SDLK_UP: - myTrain->controller()->actOn(GO_STRAIGHT_ON); + train->controller()->actOn(GO_STRAIGHT_ON); break; case SDLK_TAB: - if (myCameraMode == CAMERA_FLOATING) - myCameraMode = CAMERA_FIXED; - else if (myCameraMode == CAMERA_FIXED) { - myCameraMode = CAMERA_BIRD; + if (cameraMode == CAMERA_FLOATING) + cameraMode = CAMERA_FIXED; + else if (cameraMode == CAMERA_FIXED) { + cameraMode = CAMERA_BIRD; - myCameraHTarget = M_PI/4.0f; - myCameraVTarget = M_PI/4.0f; + cameraHTarget = M_PI/4.0f; + cameraVTarget = M_PI/4.0f; - myCameraSpeed = 100.0f; + cameraSpeed = 100.0f; } else - myCameraMode = CAMERA_FLOATING; + cameraMode = CAMERA_FLOATING; break; default: break; @@ -354,10 +355,10 @@ void Game::onMouseClick(IPickBufferPtr aPickBuffer, int x, int y, { switch (aButton) { case MOUSE_WHEEL_UP: - myViewRadius = max(myViewRadius - 1.0f, 0.1f); + viewRadius = max(viewRadius - 1.0f, 0.1f); break; case MOUSE_WHEEL_DOWN: - myViewRadius += 1.0f; + viewRadius += 1.0f; break; default: break; @@ -367,21 +368,21 @@ void Game::onMouseClick(IPickBufferPtr aPickBuffer, int x, int y, void Game::onMouseMove(IPickBufferPtr aPickBuffer, int x, int y, int xrel, int yrel) { - if (myCameraMode == CAMERA_FLOATING) { - myCameraHTarget -= xrel / 100.0f; - myCameraVTarget += yrel / 100.0f; + if (cameraMode == CAMERA_FLOATING) { + cameraHTarget -= xrel / 100.0f; + cameraVTarget += yrel / 100.0f; // Don't allow the camera to go under the ground const float ground = (M_PI / 2.0f) - 0.01f; - if (myCameraVTarget > ground) - myCameraVTarget = ground; + if (cameraVTarget > ground) + cameraVTarget = ground; // Don't let the camera flip over the top const float top = 0.01f; - if (myCameraVTarget < top) - myCameraVTarget = top; + if (cameraVTarget < top) + cameraVTarget = top; - myCameraSpeed = 2.0f; + cameraSpeed = 2.0f; } } diff --git a/src/Main.cpp b/src/Main.cpp index c76d2c1..da1071f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -29,12 +29,12 @@ using namespace boost::filesystem; namespace { - IWindowPtr theWindow; + IWindowPtr window; } IWindowPtr getGameWindow() { - return theWindow; + return ::window; } int main(int argc, char** argv) @@ -68,25 +68,25 @@ int main(int argc, char** argv) IScreenPtr screen; if (cmd == "edit") { - theWindow = makeFLTKWindow("Train Game Editor", addEditorGUI); + ::window = makeFLTKWindow("Train Game Editor", addEditorGUI); if (resourceExists(mapFile, "maps")) screen = makeEditorScreen(loadMap(mapFile)); else { - screen = makeEditorScreen(mapFile); + screen = makeEditorScreen(mapFile); } } else if (cmd == "play") { - theWindow = makeSDLWindow(); + ::window = makeSDLWindow(); screen = makeGameScreen(loadMap(mapFile)); } else if (cmd == "uidemo") { - theWindow = makeSDLWindow(); - screen = make_ui_demo(); + ::window = makeSDLWindow(); + screen = makeUIDemo(); } else throw runtime_error("Unrecognised command: " + cmd); - theWindow->run(screen); + ::window->run(screen); cfg->flush(); } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index c5877a5..c1add4c 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -27,8 +27,6 @@ #include #include -using namespace std; -using namespace std::tr1; using namespace boost; // Concrete implementation of mesh buffers @@ -374,7 +372,7 @@ public: void render() const; private: - Material myMaterial; + Material material; bool hasMaterial, hasTexture; int myVertexCount; VertexData* myVertexData; @@ -386,7 +384,7 @@ VertexArrayMesh::VertexArrayMesh(IMeshBufferPtr aBuffer) { const MeshBuffer* buf = MeshBuffer::get(aBuffer); - myMaterial = buf->material; + material = buf->material; hasMaterial = buf->hasMaterial; hasTexture = buf->hasTexture; @@ -415,7 +413,7 @@ void VertexArrayMesh::render() const glDisable(GL_BLEND); if (hasMaterial) - myMaterial.apply(); + material.apply(); else { glEnable(GL_COLOR_MATERIAL); @@ -451,8 +449,8 @@ public: void render() const; private: - GLuint myVBOBuf, myIndexBuf; - Material myMaterial; + GLuint vboBuf, indexBuf; + Material material; bool hasTexture, hasMaterial; size_t myIndexCount; }; @@ -462,7 +460,7 @@ VBOMesh::VBOMesh(IMeshBufferPtr aBuffer) // Get the data out of the buffer; const MeshBuffer* buf = MeshBuffer::get(aBuffer); - myMaterial = buf->material; + material = buf->material; hasMaterial = buf->hasMaterial; hasTexture = buf->hasTexture; @@ -472,8 +470,8 @@ VBOMesh::VBOMesh(IMeshBufferPtr aBuffer) copyVertexData(buf, pVertexData); // Generate the VBO - glGenBuffersARB(1, &myVBOBuf); - glBindBufferARB(GL_ARRAY_BUFFER, myVBOBuf); + glGenBuffersARB(1, &vboBuf); + glBindBufferARB(GL_ARRAY_BUFFER, vboBuf); glBufferDataARB(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexData), NULL, GL_STATIC_DRAW); @@ -488,8 +486,8 @@ VBOMesh::VBOMesh(IMeshBufferPtr aBuffer) copy(buf->indices.begin(), buf->indices.end(), pIndices); // Build the index buffer - glGenBuffersARB(1, &myIndexBuf); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, myIndexBuf); + glGenBuffersARB(1, &indexBuf); + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, indexBuf); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, myIndexCount * sizeof(GLushort), NULL, GL_STATIC_DRAW); glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER, 0, @@ -504,8 +502,8 @@ VBOMesh::VBOMesh(IMeshBufferPtr aBuffer) VBOMesh::~VBOMesh() { - glDeleteBuffersARB(1, &myVBOBuf); - glDeleteBuffersARB(1, &myIndexBuf); + glDeleteBuffersARB(1, &vboBuf); + glDeleteBuffersARB(1, &indexBuf); } void VBOMesh::render() const @@ -513,8 +511,8 @@ void VBOMesh::render() const glPushAttrib(GL_ENABLE_BIT); glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); - glBindBufferARB(GL_ARRAY_BUFFER, myVBOBuf); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, myIndexBuf); + glBindBufferARB(GL_ARRAY_BUFFER, vboBuf); + glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, indexBuf); glDisable(GL_BLEND); @@ -524,13 +522,13 @@ void VBOMesh::render() const glDisable(GL_TEXTURE_2D); if (hasMaterial) - myMaterial.apply(); + material.apply(); else { glEnable(GL_COLOR_MATERIAL); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, sizeof(VertexData), - reinterpret_cast(offsetof(VertexData, r))); + reinterpret_cast(offsetof(VertexData, r))); } glEnableClientState(GL_VERTEX_ARRAY); diff --git a/src/QuadTree.cpp b/src/QuadTree.cpp index fdcb107..413320f 100644 --- a/src/QuadTree.cpp +++ b/src/QuadTree.cpp @@ -48,17 +48,17 @@ private: int buildNode(int anId, int aParent, int x1, int y1, int x2, int y2); void visibleSectors(IGraphicsPtr aContext, list& aList, int aSector); - int mySize, myNumSectors, myUsedSectors; - ISectorRenderablePtr myRenderer; + int size, numSectors, usedSectors; + ISectorRenderablePtr renderer; - int myKillCount; + int killCount; static const int QT_LEAF_SIZE = 8; // Number of tiles in a QuadTree leaf }; QuadTree::QuadTree(ISectorRenderablePtr aRenderable) - : mySectors(NULL), mySize(0), myNumSectors(0), myUsedSectors(0), - myRenderer(aRenderable), myKillCount(0) + : mySectors(NULL), size(0), numSectors(0), usedSectors(0), + renderer(aRenderable), killCount(0) { } @@ -72,37 +72,38 @@ QuadTree::~QuadTree() void QuadTree::render(IGraphicsPtr aContext) { list visible; - myKillCount = 0; + killCount = 0; visibleSectors(aContext, visible, 0); list::const_iterator it; for (it = visible.begin(); it != visible.end(); ++it) - myRenderer->renderSector(aContext, (*it)->id, (*it)->botLeft, (*it)->topRight); + renderer->renderSector(aContext, (*it)->id, + (*it)->botLeft, (*it)->topRight); for (it = visible.begin(); it != visible.end(); ++it) - myRenderer->postRenderSector(aContext, (*it)->id, - (*it)->botLeft, (*it)->topRight); + renderer->postRenderSector(aContext, (*it)->id, + (*it)->botLeft, (*it)->topRight); } // Creates a blank QuadTree void QuadTree::buildTree(int aDim) { - mySize = aDim; + size = aDim; // Error checking if (aDim % QT_LEAF_SIZE != 0) throw runtime_error("Invalid QuadTree dimensions!"); // Allocate memory - myNumSectors = calcNumSectors(aDim); - myUsedSectors = 0; + numSectors = calcNumSectors(aDim); + usedSectors = 0; if (mySectors) delete[] mySectors; - mySectors = new Sector[myNumSectors]; + mySectors = new Sector[numSectors]; // Build the tree - buildNode(0, 0, 0, 0, mySize, mySize); + buildNode(0, 0, 0, 0, size, size); } // Builds a node in the tree @@ -126,10 +127,10 @@ int QuadTree::buildNode(int anId, int aParent, int x1, int y1, int x2, int y2) // Build children unsigned int* c = mySectors[anId].children; - c[0] = buildNode(++myUsedSectors, anId, x1, y1, x1+w/2, y1+h/2); - c[1] = buildNode(++myUsedSectors, anId, x1, y1+h/2, x1+w/2, y2 ); - c[3] = buildNode(++myUsedSectors, anId, x1+w/2, y1+h/2, x2, y2 ); - c[2] = buildNode(++myUsedSectors, anId, x1+w/2, y1, x2, y1+h/2); + c[0] = buildNode(++usedSectors, anId, x1, y1, x1+w/2, y1+h/2); + c[1] = buildNode(++usedSectors, anId, x1, y1+h/2, x1+w/2, y2 ); + c[3] = buildNode(++usedSectors, anId, x1+w/2, y1+h/2, x2, y2 ); + c[2] = buildNode(++usedSectors, anId, x1+w/2, y1, x2, y1+h/2); } return anId; @@ -153,7 +154,7 @@ int QuadTree::calcNumSectors(int aWidth) void QuadTree::visibleSectors(IGraphicsPtr aContext, list& aList, int aSector) { - if (aSector >= myNumSectors) { + if (aSector >= numSectors) { ostringstream ss; ss << "displaySector(" << aSector << ") out of range"; throw runtime_error(ss.str()); @@ -177,7 +178,7 @@ void QuadTree::visibleSectors(IGraphicsPtr aContext, list& aList, if (aContext->cubeInViewFrustum((float)x, 0.0f, (float)y, (float)w/2)) visibleSectors(aContext, aList, childID); else - myKillCount++; + killCount++; } } } diff --git a/src/SDLWindow.cpp b/src/SDLWindow.cpp index 176a3e2..3498264 100644 --- a/src/SDLWindow.cpp +++ b/src/SDLWindow.cpp @@ -46,8 +46,8 @@ public: void switchScreen(IScreenPtr aScreen); void quit(); void takeScreenShot(); - int width() const { return myWidth; } - int height() const { return myHeight; } + int width() const { return width_; } + int height() const { return height_; } void redrawHint() {} // IGraphics interface @@ -69,11 +69,11 @@ private: void captureFrame() const; bool amRunning; - int myWidth, myHeight; - IScreenPtr myScreen; + int width_, height_; + IScreenPtr screen; bool willSkipNextFrame; bool willTakeScreenShot; - Frustum myViewFrustum; + Frustum viewFrustum; // Picking data static const int SELECT_BUFFER_SZ = 128; @@ -146,11 +146,11 @@ SDLWindow::SDLWindow() atexit(SDL_Quit); // Set the video mode - cfg->get("XRes", myWidth); - cfg->get("YRes", myHeight); + cfg->get("XRes", width_); + cfg->get("YRes", height_); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (SDL_SetVideoMode(myWidth, myHeight, 0, SDL_OPENGL) == NULL) { + if (SDL_SetVideoMode(width_, height_, 0, SDL_OPENGL) == NULL) { ostringstream ss; ss << "Unable to create OpenGL screen: " << SDL_GetError(); throw runtime_error(ss.str()); @@ -166,7 +166,7 @@ SDLWindow::SDLWindow() printGLVersion(); initGL(); - log() << "Created " << myWidth << "x" << myHeight << " window"; + log() << "Created " << width_ << "x" << height_ << " window"; } // Destroy the game window @@ -186,7 +186,7 @@ void SDLWindow::switchScreen(IScreenPtr aScreen) { assert(amRunning); - myScreen = aScreen; + screen = aScreen; willSkipNextFrame = true; } @@ -195,7 +195,7 @@ void SDLWindow::run(IScreenPtr aScreen) { assert(!amRunning); - myScreen = aScreen; + screen = aScreen; FrameTimerThread fpsTimer; @@ -211,10 +211,10 @@ void SDLWindow::run(IScreenPtr aScreen) try { processInput(); - myScreen->update(shared_from_this(), delta); + screen->update(shared_from_this(), delta); if (!willSkipNextFrame) { - drawGLScene(shared_from_this(), shared_from_this(), myScreen); + drawGLScene(shared_from_this(), shared_from_this(), screen); SDL_GL_SwapBuffers(); } else @@ -238,7 +238,7 @@ void SDLWindow::run(IScreenPtr aScreen) lastTick = tickStart; } while (amRunning); - myScreen.reset(); + screen.reset(); } // Stop the game cleanly @@ -278,16 +278,16 @@ void SDLWindow::processInput() break; case SDL_KEYDOWN: - myScreen->onKeyDown(e.key.keysym.sym); + screen->onKeyDown(e.key.keysym.sym); break; case SDL_KEYUP: - myScreen->onKeyUp(e.key.keysym.sym); + screen->onKeyUp(e.key.keysym.sym); break; case SDL_MOUSEMOTION: if (!haveSentMouseMotion) { - myScreen->onMouseMove(shared_from_this(), + screen->onMouseMove(shared_from_this(), e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel); haveSentMouseMotion = true; @@ -295,20 +295,20 @@ void SDLWindow::processInput() break; case SDL_MOUSEBUTTONDOWN: - myScreen->onMouseClick(shared_from_this(), + screen->onMouseClick(shared_from_this(), e.button.x, e.button.y, fromSDLButton(e.button.button)); break; case SDL_MOUSEBUTTONUP: - myScreen->onMouseRelease(shared_from_this(), + screen->onMouseRelease(shared_from_this(), e.button.x, e.button.y, fromSDLButton(e.button.button)); break; case SDL_VIDEORESIZE: - myWidth = e.resize.w; - myHeight = e.resize.h; + width_ = e.resize.w; + height_ = e.resize.h; resizeGLScene(shared_from_this()); break; @@ -340,7 +340,7 @@ void SDLWindow::setCamera(const Vector& aPos, glRotatef(aRotation.z, 0.0f, 0.0f, 1.0f); glTranslatef(aPos.x, aPos.y, aPos.z); - myViewFrustum = getViewFrustum(); + viewFrustum = getViewFrustum(); } // A wrapper around gluLookAt @@ -351,26 +351,26 @@ void SDLWindow::lookAt(const Vector anEyePoint, aTargetPoint.x, aTargetPoint.y, aTargetPoint.z, 0, 1, 0); - myViewFrustum = getViewFrustum(); + viewFrustum = getViewFrustum(); } // Intersect a cuboid with the current view frustum bool SDLWindow::cuboidInViewFrustum(float x, float y, float z, float sizeX, float sizeY, float sizeZ) { - return myViewFrustum.cuboidInFrustum(x, y, z, sizeX, sizeY, sizeZ); + return viewFrustum.cuboidInFrustum(x, y, z, sizeX, sizeY, sizeZ); } // Intersect a cube with the current view frustum bool SDLWindow::cubeInViewFrustum(float x, float y, float z, float size) { - return myViewFrustum.cubeInFrustum(x, y, z, size); + return viewFrustum.cubeInFrustum(x, y, z, size); } // True if the point is contained within the view frustum bool SDLWindow::pointInViewFrustum(float x, float y, float z) { - return myViewFrustum.pointInFrustum(x, y, z); + return viewFrustum.pointInFrustum(x, y, z); } // Capture the OpenGL pixels and save them to a file @@ -382,7 +382,7 @@ void SDLWindow::captureFrame() const ("screenshot" + lexical_cast(fileNumber++) + ".bmp"); SDL_Surface* temp = SDL_CreateRGBSurface - (SDL_SWSURFACE, myWidth, myHeight, 24, + (SDL_SWSURFACE, width_, height_, 24, #if SDL_BYTEORDER == SDL_LIL_ENDIAN 0x000000FF, 0x0000FF00, 0x00FF0000, 0 #else @@ -391,8 +391,8 @@ void SDLWindow::captureFrame() const ); assert(temp); - const int w = myWidth; - const int h = myHeight; + const int w = width_; + const int h = height_; unsigned char* pixels = new unsigned char[3 * w * h]; glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels); diff --git a/src/SkyBox.cpp b/src/SkyBox.cpp index c3cc38c..41c0753 100644 --- a/src/SkyBox.cpp +++ b/src/SkyBox.cpp @@ -32,14 +32,14 @@ public: private: void loadSkyTexture(int anIndex, const string& aSuffix); - ITexturePtr myTextures[6]; - const string myBaseName; + ITexturePtr textures[6]; + const string baseName; }; // The base name is used to generate the file names of all six // textures SkyBox::SkyBox(const string& aBaseName) - : myBaseName(aBaseName) + : baseName(aBaseName) { loadSkyTexture(0, "bottom"); loadSkyTexture(1, "top"); @@ -51,8 +51,8 @@ SkyBox::SkyBox(const string& aBaseName) void SkyBox::loadSkyTexture(int anIndex, const string& aSuffix) { - myTextures[anIndex] = - loadTexture("data/images/" + myBaseName + "_" + aSuffix + ".png"); + textures[anIndex] = + loadTexture("data/images/" + baseName + "_" + aSuffix + ".png"); } void SkyBox::apply(float anAngle) const @@ -73,7 +73,7 @@ void SkyBox::apply(float anAngle) const glRotatef(radToDeg(anAngle), 0.0f, 1.0f, 0.0f); // Bottom - myTextures[0]->bind(); + textures[0]->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-r, -r, -r); glTexCoord2f(0.0f, 0.0f); glVertex3f(-r, -r, r); @@ -82,7 +82,7 @@ void SkyBox::apply(float anAngle) const glEnd(); // Top - myTextures[1]->bind(); + textures[1]->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-r, r, -r); glTexCoord2f(0.0f, 0.0f); glVertex3f(-r, r, r); @@ -91,7 +91,7 @@ void SkyBox::apply(float anAngle) const glEnd(); // Front - myTextures[2]->bind(); + textures[2]->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-r, -r, -r); glTexCoord2f(0.0f, 0.0f); glVertex3f(-r, r, -r); @@ -100,7 +100,7 @@ void SkyBox::apply(float anAngle) const glEnd(); // Back - myTextures[3]->bind(); + textures[3]->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-r, -r, r); glTexCoord2f(0.0f, 0.0f); glVertex3f(-r, r, r); @@ -109,7 +109,7 @@ void SkyBox::apply(float anAngle) const glEnd(); // Left - myTextures[4]->bind(); + textures[4]->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-r, -r, -r); glTexCoord2f(0.0f, 0.0f); glVertex3f(-r, r, -r); @@ -118,7 +118,7 @@ void SkyBox::apply(float anAngle) const glEnd(); // Right - myTextures[5]->bind(); + textures[5]->bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(r, -r, -r); glTexCoord2f(0.0f, 0.0f); glVertex3f(r, r, -r); diff --git a/src/StraightTrack.cpp b/src/StraightTrack.cpp index e451379..35501ee 100644 --- a/src/StraightTrack.cpp +++ b/src/StraightTrack.cpp @@ -40,7 +40,7 @@ public: void render() const; - void setOrigin(int x, int y) { myX = x; myY = y; } + void setOrigin(int x, int y) { origin.x = x; origin.y = y; } double segmentLength(const track::TravelToken& aToken) const { return 1.0; } Vector offsetForDelta(double aDelta) const; @@ -57,12 +57,12 @@ private: void transform(const track::TravelToken& aToken, double aDelta) const; void ensureValidDirection(const track::Direction& aDirection) const; - int myX, myY; // Absolute position - Direction myDirection; + Point origin; // Absolute position + Direction direction; }; StraightTrack::StraightTrack(const Direction& aDirection) - : myDirection(aDirection) + : direction(aDirection) { } @@ -93,22 +93,22 @@ void StraightTrack::transform(const track::TravelToken& aToken, { assert(aDelta < 1.0); - if (aToken.direction == -myDirection) + if (aToken.direction == -direction) aDelta = 1.0 - aDelta; - const double xTrans = myDirection == axis::X ? aDelta : 0; - const double yTrans = myDirection == axis::Y ? aDelta : 0; + const double xTrans = direction == axis::X ? aDelta : 0; + const double yTrans = direction == axis::Y ? aDelta : 0; - glTranslated(static_cast(myX) + xTrans, - 0.0, - static_cast(myY) + yTrans); + glTranslated(static_cast(origin.x) + xTrans, + 0.0, + static_cast(origin.y) + yTrans); - if (myDirection == axis::Y) + if (direction == axis::Y) glRotated(-90.0, 0.0, 1.0, 0.0); glTranslated(-0.5, 0.0, 0.0); - if (aToken.direction == -myDirection) + if (aToken.direction == -direction) glRotated(-180.0, 0.0, 1.0, 0.0); } @@ -117,38 +117,36 @@ ITrackSegmentPtr StraightTrack::mergeExit(const Point& aPoint, { debug() << "mergeExit aPoint=" << aPoint << " aDirection=" << aDirection - << " me=" << makePoint(myX, myY); + << " me=" << origin; - const Point me = makePoint(myX, myY); - // See if this is already a valid exit - if (isValidDirection(aDirection) && aPoint == me) + if (isValidDirection(aDirection) && aPoint == origin) return shared_from_this(); // See if we can make this a crossover track - if (myDirection != aDirection && aPoint == me) + if (direction != aDirection && aPoint == origin) return makeCrossoverTrack(); // See if we can make some points if (isValidDirection(aDirection)) { // X-aligned points - if (aPoint == me + makePoint(-2, 1)) + if (aPoint == origin + makePoint(-2, 1)) return makePoints(-axis::X, true); - else if (aPoint == me + makePoint(-2, -1)) + else if (aPoint == origin + makePoint(-2, -1)) return makePoints(-axis::X, false); - else if (aPoint == me + makePoint(2, 1)) + else if (aPoint == origin + makePoint(2, 1)) return makePoints(axis::X, false); - else if (aPoint == me + makePoint(2, -1)) + else if (aPoint == origin + makePoint(2, -1)) return makePoints(axis::X, true); // Y-aligned points - if (aPoint == me + makePoint(1, -2)) + if (aPoint == origin + makePoint(1, -2)) return makePoints(-axis::Y, false); - else if (aPoint == me + makePoint(-1, -2)) + else if (aPoint == origin + makePoint(-1, -2)) return makePoints(-axis::Y, true); - else if (aPoint == me + makePoint(1, 2)) + else if (aPoint == origin + makePoint(1, 2)) return makePoints(axis::Y, true); - else if (aPoint == me + makePoint(-1, 2)) + else if (aPoint == origin + makePoint(-1, 2)) return makePoints(axis::Y, false); } @@ -158,7 +156,7 @@ ITrackSegmentPtr StraightTrack::mergeExit(const Point& aPoint, bool StraightTrack::isValidDirection(const Direction& aDirection) const { - if (myDirection == axis::X) + if (direction == axis::X) return aDirection == axis::X || -aDirection == axis::X; else return aDirection == axis::Y || -aDirection == axis::Y; @@ -166,7 +164,7 @@ bool StraightTrack::isValidDirection(const Direction& aDirection) const void StraightTrack::getEndpoints(list >& aList) const { - aList.push_back(makePoint(myX, myY)); + aList.push_back(origin); } void StraightTrack::ensureValidDirection(const Direction& aDirection) const @@ -176,7 +174,7 @@ void StraightTrack::ensureValidDirection(const Direction& aDirection) const ("Invalid direction on straight track: " + lexical_cast(aDirection) + " (should be parallel to " - + lexical_cast(myDirection) + ")"); + + lexical_cast(direction) + ")"); } Connection StraightTrack::nextPosition(const track::TravelToken& aToken) const @@ -184,13 +182,13 @@ Connection StraightTrack::nextPosition(const track::TravelToken& aToken) const ensureValidDirection(aToken.direction); if (aToken.direction == axis::X) - return make_pair(makePoint(myX + 1, myY), axis::X); + return make_pair(makePoint(origin.x + 1, origin.y), axis::X); else if (aToken.direction == -axis::X) - return make_pair(makePoint(myX - 1, myY), -axis::X); + return make_pair(makePoint(origin.x - 1, origin.y), -axis::X); else if (aToken.direction == axis::Y) - return make_pair(makePoint(myX, myY + 1), axis::Y); + return make_pair(makePoint(origin.x, origin.y + 1), axis::Y); else if (aToken.direction == -axis::Y) - return make_pair(makePoint(myX, myY - 1), -axis::Y); + return make_pair(makePoint(origin.x, origin.y - 1), -axis::Y); else assert(false); } @@ -199,7 +197,7 @@ void StraightTrack::render() const { glPushMatrix(); - if (myDirection == axis::X) + if (direction == axis::X) glRotated(90.0, 0.0, 1.0, 0.0); renderStraightRail(); @@ -219,7 +217,7 @@ void StraightTrack::render() const xml::element StraightTrack::toXml() const { return xml::element("straightTrack") - .addAttribute("align", myDirection == axis::X ? "x" : "y"); + .addAttribute("align", direction == axis::X ? "x" : "y"); } ITrackSegmentPtr makeStraightTrack(const Direction& aDirection) -- 2.39.2