From 0a2f5f33c64b797636cc377c320a44d7adf3a4a2 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 1 Nov 2009 17:25:55 +0000 Subject: [PATCH] More renaming --- include/{gui2 => }/Colour.hpp | 13 ++-- include/OpenGLHelper.hpp | 22 +++++++ include/gui/IControl.hpp | 2 +- include/gui2/RenderContext.hpp | 2 +- include/gui2/Theme.hpp | 2 +- src/Billboard.cpp | 38 +++++------ src/Config.cpp | 40 ++++++----- src/Engine.cpp | 34 +++++----- src/Frustum.cpp | 8 +-- src/Game.cpp | 4 +- src/Map.cpp | 117 +++++++++++++++++---------------- src/OpenGLHelper.cpp | 3 +- src/Train.cpp | 66 +++++++++---------- src/ft/Font.cpp | 2 +- src/ft/IFont.hpp | 5 +- src/gui/FuelMeter.cpp | 3 +- src/gui2/RenderContext.cpp | 14 ++-- src/gui2/Theme.cpp | 4 +- 18 files changed, 196 insertions(+), 183 deletions(-) rename include/{gui2 => }/Colour.hpp (81%) diff --git a/include/gui2/Colour.hpp b/include/Colour.hpp similarity index 81% rename from include/gui2/Colour.hpp rename to include/Colour.hpp index f0e35f8..19fcd28 100644 --- a/include/gui2/Colour.hpp +++ b/include/Colour.hpp @@ -20,13 +20,14 @@ #include "Platform.hpp" -namespace gui { - typedef tuple Colour; +struct Colour { + float r, g, b, a; +}; - inline Colour make_colour(float r, float g, float b, float a=1.0f) - { - return make_tuple(r, g, b, a); - } +inline Colour makeColour(float r, float g, float b, float a=1.0f) +{ + Colour c = { r, g, b, a }; + return c; } #endif diff --git a/include/OpenGLHelper.hpp b/include/OpenGLHelper.hpp index 314563d..f8ba328 100644 --- a/include/OpenGLHelper.hpp +++ b/include/OpenGLHelper.hpp @@ -22,6 +22,9 @@ #include "IWindow.hpp" #include "IGraphics.hpp" #include "IPickBuffer.hpp" +#include "Colour.hpp" + +#include // Helper functions used by the different IWindow implementations void initGL(); @@ -33,4 +36,23 @@ void printGLVersion(); void beginPick(IWindowPtr aWindow, unsigned* aBuffer, int x, int y); unsigned endPick(unsigned* aBuffer); +// Helper functions for using our Vector and Colour objects +// as OpenGL types +namespace gl { + + inline void colour(const Colour& c) + { + glColor4f(c.r, c.g, c.b, c.a); + } + + template + inline void translate(const Vector& v); + + template <> + inline void translate(const Vector& v) + { + glTranslatef(v.x, v.y, v.z); + } +} + #endif diff --git a/include/gui/IControl.hpp b/include/gui/IControl.hpp index 446884f..471d0ed 100644 --- a/include/gui/IControl.hpp +++ b/include/gui/IControl.hpp @@ -20,7 +20,7 @@ #include "Platform.hpp" #include "IFont.hpp" -#include "gui2/Colour.hpp" +#include "Colour.hpp" #include diff --git a/include/gui2/RenderContext.hpp b/include/gui2/RenderContext.hpp index 4aaff21..cd80dee 100644 --- a/include/gui2/RenderContext.hpp +++ b/include/gui2/RenderContext.hpp @@ -21,7 +21,7 @@ // Internal header: do not include this file directly #include "Platform.hpp" -#include "gui2/Colour.hpp" +#include "Colour.hpp" #include "gui2/Theme.hpp" #include diff --git a/include/gui2/Theme.hpp b/include/gui2/Theme.hpp index 796bc05..f5b0ba8 100644 --- a/include/gui2/Theme.hpp +++ b/include/gui2/Theme.hpp @@ -21,7 +21,7 @@ // Internal header: do not include this file directly #include "Platform.hpp" -#include "gui2/Colour.hpp" +#include "Colour.hpp" #include "ft/IFont.hpp" namespace gui { diff --git a/src/Billboard.cpp b/src/Billboard.cpp index 476d999..04e4fd8 100644 --- a/src/Billboard.cpp +++ b/src/Billboard.cpp @@ -16,13 +16,15 @@ // #include "IBillboard.hpp" +#include "Colour.hpp" +#include "OpenGLHelper.hpp" #include using namespace std; namespace { - Vector theCameraPosition; + Vector cameraPosition; } // Common functions used by billboards @@ -30,8 +32,9 @@ class BillboardCommon : public IBillboard { public: BillboardCommon(ITexturePtr aTexture) : 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) {} + position(makeVector(0.0f, 0.0f, 0.0f)), + scale(1.0f), + colour(makeColour(1.0f, 1.0f, 1.0f)) {} virtual ~BillboardCommon() {} // IBillboard interface @@ -46,24 +49,19 @@ protected: void drawTextureQuad() const; void translate() const; - float x_, y_, z_; + Vector position; float scale; - float r_, g_, b_, a_; + Colour colour; }; void BillboardCommon::setPosition(float x, float y, float z) { - x_ = x; - y_ = y; - z_ = z; + position = makeVector(x, y, z); } void BillboardCommon::setColour(float r, float g, float b, float a) { - r_ = r; - g_ = g; - b_ = b; - a_ = a; + colour = makeColour(r, g, b, a); } void BillboardCommon::setScale(float aScale) @@ -73,7 +71,7 @@ void BillboardCommon::setScale(float aScale) void BillboardCommon::translate() const { - glTranslatef(x_, y_, z_); + gl::translate(position); } // Draw the actual quad containing the texture @@ -85,7 +83,7 @@ void BillboardCommon::drawTextureQuad() const glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); - glColor4f(r_, g_, b_, a_); + gl::colour(colour); texture->bind(); @@ -174,9 +172,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 - x_, + objToCamProj = makeVector(cameraPosition.x - position.x, 0.0f, - theCameraPosition.z - z_); + cameraPosition.z - position.z); // This is the original lookAt vector for the object // in world coordinates @@ -207,9 +205,7 @@ void SphericalBillboard::render() const // objToCam is the vector in world coordinates from // the local origin to the camera - objToCam = makeVector(theCameraPosition.x - x_, - theCameraPosition.y - y_, - theCameraPosition.z - z_); + objToCam = cameraPosition - position; // Normalize to get the cosine afterwards objToCam.normalise(); @@ -249,10 +245,10 @@ IBillboardPtr makeSphericalBillboard(ITexturePtr aTexture) void setBillboardCameraOrigin(Vector aPosition) { - theCameraPosition = aPosition; + cameraPosition = aPosition; } float distanceToCamera(Vector aPosition) { - return (theCameraPosition - aPosition).length(); + return (cameraPosition - aPosition).length(); } diff --git a/src/Config.cpp b/src/Config.cpp index 26930c3..c122f79 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -31,15 +31,13 @@ namespace { typedef tuple Default; - const Default END("", 0); // All valid options - Default theDefaults[] = { + const Default defaults[] = { Default("XRes", 800), Default("YRes", 600), Default("NearClip", 0.1f), Default("FarClip", 70.0f), - END }; } @@ -68,9 +66,9 @@ private: void bindNextOption(const AttributeSet& attrs); typedef map ConfigMap; - ConfigMap myConfigMap; + ConfigMap configMap; - string myConfigFile; + string configFile; bool amDirty; // Used by the XML parser @@ -81,22 +79,22 @@ private: Config::Config() : amDirty(false) { - for (Default* d = theDefaults; *::get<0>(*d) != '\0'; d++) - myConfigMap[::get<0>(*d)] = ::get<1>(*d); + for (size_t i = 0; i < sizeof(::defaults)/sizeof(Default); i++) + configMap[::get<0>(::defaults[i])] = ::get<1>(::defaults[i]); - myConfigFile = configFileName(); + configFile = configFileName(); - if (boost::filesystem::exists(myConfigFile)) { - log() << "Reading config from " << myConfigFile; + if (boost::filesystem::exists(configFile)) { + log() << "Reading config from " << configFile; IXMLParserPtr parser = makeXMLParser("schemas/config.xsd"); - parser->parse(myConfigFile, *this); + parser->parse(configFile, *this); // Ignore all the set() calls made by the XML parser amDirty = false; } else { - warn() << "Config file not present: " << myConfigFile; + warn() << "Config file not present: " << configFile; // Write a default config file when we exit amDirty = true; @@ -162,7 +160,7 @@ void Config::text(const string& localName, const string& aString) template void Config::setFromString(const string& aKey, const string& aString) { - myConfigMap[aKey] = boost::lexical_cast(aString); + configMap[aKey] = boost::lexical_cast(aString); } // Write the config file back to disk @@ -174,17 +172,17 @@ void Config::flush() if (!amDirty) return; - log() << "Saving config to " << myConfigFile; + log() << "Saving config to " << configFile; - create_directories(path(myConfigFile).remove_filename()); + create_directories(path(configFile).remove_filename()); - ofstream ofs(myConfigFile.c_str()); + ofstream ofs(configFile.c_str()); if (!ofs.good()) throw runtime_error("Failed to write to config file"); xml::element root("config"); - for (ConfigMap::const_iterator it = myConfigMap.begin(); - it != myConfigMap.end(); ++it) { + for (ConfigMap::const_iterator it = configMap.begin(); + it != configMap.end(); ++it) { // We can only serialize some types const any& a = (*it).second; @@ -229,8 +227,8 @@ void Config::flush() // Read a single option const IConfig::Option& Config::get(const string& aKey) const { - ConfigMap::const_iterator it = myConfigMap.find(aKey); - if (it != myConfigMap.end()) + ConfigMap::const_iterator it = configMap.find(aKey); + if (it != configMap.end()) return (*it).second; else throw runtime_error("Bad config key " + aKey); @@ -238,7 +236,7 @@ const IConfig::Option& Config::get(const string& aKey) const void Config::set(const string& aKey, const IConfig::Option& aValue) { - myConfigMap[aKey] = aValue; + configMap[aKey] = aValue; amDirty = true; } diff --git a/src/Engine.cpp b/src/Engine.cpp index d31f25b..65488d4 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -68,7 +68,7 @@ public: double speed() const { return mySpeed; } IControllerPtr controller() { return shared_from_this(); } - double length() const { return myModel->dimensions().x; } + double length() const { return model->dimensions().x; } // IController interface void actOn(Action anAction); @@ -85,19 +85,19 @@ private: double resistance() const; double brakeForce() const; - IModelPtr myModel; + IModelPtr model; double mySpeed, myMass, myBoilerPressure, myFireTemp; - double myStatTractiveEffort; + double statTractiveEffort; bool isBrakeOn; int myThrottle; // Ratio measured in tenths - track::Choice myNextChoice; + track::Choice nextChoice; // Boiler pressure lags behind temperature MovingAverage myBoilerDelay; - IResourcePtr myResource; + IResourcePtr resource; static const float MODEL_SCALE; static const double TRACTIVE_EFFORT_KNEE; @@ -114,35 +114,35 @@ Engine::Engine(IResourcePtr aRes) : mySpeed(0.0), myMass(29.0), myBoilerPressure(INIT_PRESSURE), myFireTemp(INIT_TEMP), - myStatTractiveEffort(34.7), + statTractiveEffort(34.7), isBrakeOn(true), myThrottle(0), - myResource(aRes) + resource(aRes) { static IXMLParserPtr parser = makeXMLParser("schemas/engine.xsd"); - parser->parse(myResource->xmlFileName(), *this); + parser->parse(resource->xmlFileName(), *this); } // Callback for loading elements from the XML file void Engine::text(const string& localName, const string& aString) { if (localName == "model") - myModel = loadModel(myResource, aString, MODEL_SCALE); + model = loadModel(resource, aString, MODEL_SCALE); } // Draw the engine model void Engine::render() const { - myModel->render(); + model->render(); } // Calculate the current tractive effort double Engine::tractiveEffort() const { if (mySpeed < TRACTIVE_EFFORT_KNEE) - return myStatTractiveEffort; + return statTractiveEffort; else - return (myStatTractiveEffort * TRACTIVE_EFFORT_KNEE) / mySpeed; + return (statTractiveEffort * TRACTIVE_EFFORT_KNEE) / mySpeed; } // Calculate the magnitude of the resistance on the train @@ -190,8 +190,8 @@ void Engine::update(int aDelta) track::Choice Engine::consumeChoice() { - track::Choice c = myNextChoice; - myNextChoice = track::CHOOSE_STRAIGHT_ON; + track::Choice c = nextChoice; + nextChoice = track::CHOOSE_STRAIGHT_ON; return c; } @@ -212,13 +212,13 @@ void Engine::actOn(Action anAction) myThrottle = max(myThrottle - 1, 0); break; case GO_STRAIGHT_ON: - myNextChoice = track::CHOOSE_STRAIGHT_ON; + nextChoice = track::CHOOSE_STRAIGHT_ON; break; case GO_LEFT: - myNextChoice = track::CHOOSE_GO_LEFT; + nextChoice = track::CHOOSE_GO_LEFT; break; case GO_RIGHT: - myNextChoice = track::CHOOSE_GO_RIGHT; + nextChoice = track::CHOOSE_GO_RIGHT; break; default: break; diff --git a/src/Frustum.cpp b/src/Frustum.cpp index aea0dc4..7d0405f 100644 --- a/src/Frustum.cpp +++ b/src/Frustum.cpp @@ -27,10 +27,10 @@ enum FrustumSide { RIGHT=0, LEFT, BOTTOM, TOP, BACK, FRONT }; /* Coefficients of plane equation */ enum PlaneData { - A = 0, // The X value of the plane's normal - B = 1, // The Y value of the plane's normal - C = 2, // The Z value of the plane's normal - D = 3 // The distance the plane is from the origin + A = 0, // The X value of the plane's normal + B = 1, // The Y value of the plane's normal + C = 2, // The Z value of the plane's normal + D = 3 // The distance the plane is from the origin }; // Normalise a plane's normal vector diff --git a/src/Game.cpp b/src/Game.cpp index 56aed00..7dc755a 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -112,11 +112,11 @@ Game::Game(IMapPtr aMap) myStatsPanel->addChild(myThrottleMeter); myCoalMeter = makeFuelMeter(stdFont, "Coal", - make_colour(0.1f, 0.1f, 0.1f)); + makeColour(0.1f, 0.1f, 0.1f)); //myStatsPanel->addChild(myCoalMeter); myWaterMeter = makeFuelMeter(stdFont, "Water", - make_colour(0.1f, 0.1f, 0.8f)); + makeColour(0.1f, 0.1f, 0.8f)); //myStatsPanel->addChild(myWaterMeter); myTempLabel = makeLabel(stdFont, "Temp"); diff --git a/src/Map.cpp b/src/Map.cpp index e77c71b..528b9c2 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -48,20 +48,21 @@ class TrackNode { public: TrackNode(ITrackSegmentPtr aTrack, int x, int y) - : myTrack(aTrack), amMarked(false), myX(x), myY(y) {} + : track(aTrack), amMarked(false), + origin(makePoint(x, y)) {} inline void setMark() { amMarked = true; } inline void resetMark() { amMarked = false; } inline bool marked() const { return amMarked; } - inline ITrackSegmentPtr get() { return myTrack; } + inline ITrackSegmentPtr get() { return track; } - inline int originX() const { return myX; } - inline int originY() const { return myY; } + inline int originX() const { return origin.x; } + inline int originY() const { return origin.y; } private: - ITrackSegmentPtr myTrack; + ITrackSegmentPtr track; bool amMarked; - int myX, myY; // Position of origin + Point origin; }; typedef shared_ptr TrackNodePtr; @@ -78,7 +79,7 @@ public: int depth() const { return myDepth; } double heightAt() const { return 0.0; } - string name() const { return myResource->name(); } + string name() const { return resource->name(); } void setStart(int x, int y); void setStart(int x, int y, int dirX, int dirY); @@ -123,12 +124,12 @@ private: IStationPtr station; // Station on this tile, if any IBuildingPtr building; // Building on this tile, if any float buildingAngle; // Orientation of building - } *myTiles; + } *tiles; // Vertices on the terrain struct Vertex { Vector pos, normal; - } *myHeightMap; + } *heightMap; static const unsigned TILE_NAME_BASE = 1000; // Base of tile naming static const unsigned NULL_OBJECT = 0; // Non-existant object @@ -150,13 +151,13 @@ private: inline Tile& tileAt(int x, int z) const { - return myTiles[index(x, z)]; + return tiles[index(x, z)]; } inline Vertex& heightAt(int i) const { assert(i >= 0 && i < (myWidth + 1) * (myDepth + 1)); - return myHeightMap[i]; + return heightMap[i]; } bool isValidTileName(unsigned aName) const @@ -197,29 +198,29 @@ private: int myWidth, myDepth; Point myStartLocation; track::Direction myStartDirection; - IQuadTreePtr myQuadTree; - IFogPtr myFog; + IQuadTreePtr quadTree; + IFogPtr fog; bool shouldDrawGridLines, inPickMode; - list > myDirtyTiles; - IResourcePtr myResource; + list > dirtyTiles; + IResourcePtr resource; }; const float Map::TILE_HEIGHT(0.2f); Map::Map(IResourcePtr aRes) - : myTiles(NULL), myHeightMap(NULL), myWidth(0), myDepth(0), + : tiles(NULL), heightMap(NULL), myWidth(0), myDepth(0), myStartLocation(makePoint(1, 1)), myStartDirection(axis::X), shouldDrawGridLines(false), inPickMode(false), - myResource(aRes) + resource(aRes) { - myFog = makeFog(0.005f, // Density + fog = makeFog(0.005f, // Density 50.0f, 70.0f); // Start and end distance } Map::~Map() { - delete myTiles; + delete tiles; } ITrackSegmentPtr Map::trackAt(const Point& aPoint) const @@ -351,18 +352,18 @@ void Map::resetMap(int aWidth, int aDepth) myDepth = aDepth; // Allocate memory - if (myTiles) - delete[] myTiles; - myTiles = new Tile[aWidth * aDepth]; + if (tiles) + delete[] tiles; + tiles = new Tile[aWidth * aDepth]; - if (myHeightMap) - delete[] myHeightMap; - myHeightMap = new Vertex[(aWidth + 1) * (aDepth + 1)]; + if (heightMap) + delete[] heightMap; + heightMap = new Vertex[(aWidth + 1) * (aDepth + 1)]; // Make a flat map for (int x = 0; x <= aWidth; x++) { for (int y = 0; y <= aDepth; y++) { - Vertex& v = myHeightMap[x + y*(aWidth+1)]; + Vertex& v = heightMap[x + y*(aWidth+1)]; const float xf = static_cast(x) - 0.5f; const float yf = static_cast(y) - 0.5f; @@ -373,7 +374,7 @@ void Map::resetMap(int aWidth, int aDepth) } // Create quad tree - myQuadTree = makeQuadTree(shared_from_this(), myWidth); + quadTree = makeQuadTree(shared_from_this(), myWidth); } void Map::resetMarks() const @@ -393,7 +394,7 @@ void Map::render(IGraphicsPtr aContext) const { resetMarks(); - myFog->apply(); + fog->apply(); glPushAttrib(GL_ALL_ATTRIB_BITS); @@ -408,7 +409,7 @@ void Map::render(IGraphicsPtr aContext) const glEnable(GL_CULL_FACE); glPushMatrix(); - myQuadTree->render(aContext); + quadTree->render(aContext); glPopMatrix(); glPopAttrib(); @@ -435,7 +436,7 @@ void Map::highlightTile(IGraphicsPtr aContext, const Point& aPoint, tileVertices(aPoint.x, aPoint.y, indexes); for (int i = 0; i < 4; i++) { - Vertex& v = myHeightMap[indexes[i]]; + Vertex& v = heightMap[indexes[i]]; glNormal3f(v.normal.x, v.normal.y, v.normal.z); glVertex3f(v.pos.x, v.pos.y + 0.1f, v.pos.z); } @@ -462,7 +463,7 @@ void Map::drawStartLocation() const float avgHeight = 0.0f; for (int i = 0; i < 4; i++) - avgHeight += myHeightMap[indexes[i]].pos.y; + avgHeight += heightMap[indexes[i]].pos.y; avgHeight /= 4.0f; glTranslatef(static_cast(myStartLocation.x), @@ -497,16 +498,16 @@ bool Map::haveMesh(int id, Point botLeft, Point topRight) myTerrainMeshes.resize(id + 1); return false; } - else if (myDirtyTiles.empty()) + else if (dirtyTiles.empty()) return myTerrainMeshes[id]; else { bool ok = myTerrainMeshes[id]; - for (list >::iterator it = myDirtyTiles.begin(); - it != myDirtyTiles.end(); ++it) { + for (list >::iterator it = dirtyTiles.begin(); + it != dirtyTiles.end(); ++it) { if ((*it).x >= botLeft.x && (*it).x <= topRight.x && (*it).y >= botLeft.y && (*it).y <= topRight.y) { ok = false; - it = myDirtyTiles.erase(it); + it = dirtyTiles.erase(it); } } return ok; @@ -516,14 +517,14 @@ bool Map::haveMesh(int id, Point botLeft, Point topRight) // Record that the mesh containing a tile needs rebuilding void Map::dirtyTile(int x, int y) { - myDirtyTiles.push_back(makePoint(x, y)); + dirtyTiles.push_back(makePoint(x, y)); // Push its neighbours as well since the vertices of a tile sit // on mesh boundaries - myDirtyTiles.push_back(makePoint(x, y + 1)); - myDirtyTiles.push_back(makePoint(x, y - 1)); - myDirtyTiles.push_back(makePoint(x + 1, y)); - myDirtyTiles.push_back(makePoint(x - 1, y)); + dirtyTiles.push_back(makePoint(x, y + 1)); + dirtyTiles.push_back(makePoint(x, y - 1)); + dirtyTiles.push_back(makePoint(x + 1, y)); + dirtyTiles.push_back(makePoint(x - 1, y)); } // Generate a terrain mesh for a particular sector @@ -554,7 +555,7 @@ void Map::buildMesh(int id, Point botLeft, Point topRight) }; for (int i = 0; i < 6; i++) { - const Vertex& v = myHeightMap[order[i]]; + const Vertex& v = heightMap[order[i]]; const float h = v.pos.y; tuple hcol; @@ -667,7 +668,7 @@ void Map::renderPickSector(Point botLeft, Point topRight) glBegin(GL_QUADS); for (int i = 0; i < 4; i++) { - const Vertex& v = myHeightMap[indexes[i]]; + const Vertex& v = heightMap[indexes[i]]; glNormal3f(v.normal.x, v.normal.y, v.normal.z); glVertex3f(v.pos.x, v.pos.y, v.pos.z); } @@ -696,7 +697,7 @@ void Map::renderSector(IGraphicsPtr aContext, int id, for (int x = topRight.x-1; x >= botLeft.x; x--) { for (int y = botLeft.y; y < topRight.y; y++) { //for (int i = 0; i < 4; i++) { - // const Vertex& v = myHeightMap[indexes[i]]; + // const Vertex& v = heightMap[indexes[i]]; // drawNormal(v.pos, v.normal); //} @@ -708,7 +709,7 @@ void Map::renderSector(IGraphicsPtr aContext, int id, int indexes[4]; tileVertices(x, y, indexes); for (int i = 0; i < 4; i++) { - const Vertex& v = myHeightMap[indexes[i]]; + const Vertex& v = heightMap[indexes[i]]; glVertex3f(v.pos.x, v.pos.y, v.pos.z); } @@ -795,7 +796,7 @@ void Map::fixNormals(int x, int y) for (int n = 0; n < 4; n++) { const int i = indexes[n]; - Vertex& v = myHeightMap[i]; + Vertex& v = heightMap[i]; Vector west, north, east, south; bool haveWest = true, haveNorth = true, @@ -887,7 +888,7 @@ void Map::raiseTile(int x, int y, float deltaHeight) tileVertices(x, y, indexes); for (int i = 0; i < 4; i++) - myHeightMap[indexes[i]].pos.y += deltaHeight; + heightMap[indexes[i]].pos.y += deltaHeight; fixNormals(x, y); dirtyTile(x, y); @@ -903,12 +904,12 @@ void Map::setTileHeight(int x, int y, float h) for (int i = 0; i < 4; i++) { if (trackAffected - && abs(myHeightMap[indexes[i]].pos.y - h) > 0.01f) { + && abs(heightMap[indexes[i]].pos.y - h) > 0.01f) { warn() << "Cannot level terrain under track"; return; } else - myHeightMap[indexes[i]].pos.y = h; + heightMap[indexes[i]].pos.y = h; } fixNormals(x, y); @@ -929,7 +930,7 @@ float Map::heightAt(float x, float y) const float avg = 0.0f; for (int i = 0; i < 4; i++) - avg += myHeightMap[indexes[i]].pos.y; + avg += heightMap[indexes[i]].pos.y; return avg / 4.0f; } @@ -963,7 +964,7 @@ void Map::levelArea(Point aStartPos, Point aFinishPos) float avgHeight = 0.0f; for (int i = 0; i < 4; i++) - avgHeight += myHeightMap[indexes[i]].pos.y; + avgHeight += heightMap[indexes[i]].pos.y; avgHeight /= 4.0f; for (int x = xmin; x <= xmax; x++) { @@ -1079,7 +1080,7 @@ void Map::writeHeightMap() const { using namespace boost; - IResource::Handle h = myResource->writeFile(myResource->name() + ".bin"); + IResource::Handle h = resource->writeFile(resource->name() + ".bin"); log() << "Writing terrain height map to " << h.fileName(); @@ -1091,7 +1092,7 @@ void Map::writeHeightMap() const of.write(reinterpret_cast(&dl), sizeof(int32_t)); for (int i = 0; i < (myWidth + 1) * (myDepth + 1); i++) - of.write(reinterpret_cast(&myHeightMap[i].pos.y), + of.write(reinterpret_cast(&heightMap[i].pos.y), sizeof(float)); } @@ -1117,7 +1118,7 @@ void Map::readHeightMap(IResource::Handle aHandle) } for (int i = 0; i < (myWidth + 1) * (myDepth + 1); i++) - is.read(reinterpret_cast(&myHeightMap[i].pos.y), + is.read(reinterpret_cast(&heightMap[i].pos.y), sizeof(float)); for (int x = 0; x < myWidth; x++) { @@ -1131,7 +1132,7 @@ void Map::save() { using namespace boost::filesystem; - IResource::Handle h = myResource->writeFile(myResource->name() + ".xml"); + IResource::Handle h = resource->writeFile(resource->name() + ".xml"); log() << "Saving map to " << h.fileName(); @@ -1174,7 +1175,7 @@ void Map::save() root.addChild (xml::element("heightmap") - .addText(myResource->name() + ".bin")); + .addText(resource->name() + ".bin")); xml::element tileset("tileset"); @@ -1236,7 +1237,7 @@ class MapLoader : public IXMLCallback { public: MapLoader(shared_ptr aMap, IResourcePtr aRes) : myMap(aMap), myXPtr(0), myYPtr(0), - myResource(aRes) {} + resource(aRes) {} void startElement(const std::string& localName, const AttributeSet& attrs) @@ -1272,7 +1273,7 @@ public: void text(const string& localName, const string& aString) { if (localName == "heightmap") - myMap->readHeightMap(myResource->openFile(aString)); + myMap->readHeightMap(resource->openFile(aString)); else if (myActiveStation) { if (localName == "name") myActiveStation->setName(aString); @@ -1391,7 +1392,7 @@ private: IStationPtr myActiveStation; int myXPtr, myYPtr; - IResourcePtr myResource; + IResourcePtr resource; }; IMapPtr loadMap(const string& aResId) diff --git a/src/OpenGLHelper.cpp b/src/OpenGLHelper.cpp index 7c3ebd5..b575770 100644 --- a/src/OpenGLHelper.cpp +++ b/src/OpenGLHelper.cpp @@ -15,13 +15,14 @@ // along with this program. If not, see . // +#include // Must be included before other GL headers + #include "OpenGLHelper.hpp" #include "ILogger.hpp" #include "IConfig.hpp" #include -#include #include #include diff --git a/src/Train.cpp b/src/Train.cpp index eb1f561..f5e9f39 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -40,8 +40,8 @@ public: track::Direction direction() const; track::Position tile() const { return engine().travelToken.position; } - double speed() const { return myParts.front().vehicle->speed(); } - IControllerPtr controller() { return myParts.front().vehicle->controller(); } + double speed() const { return parts.front().vehicle->speed(); } + IControllerPtr controller() { return parts.front().vehicle->controller(); } private: // The different parts of the train are on different track segments struct Part { @@ -67,7 +67,7 @@ private: // True if this is driving the train bool isDriving; }; - list myParts; + list parts; const Part& engine() const; Part& engine(); @@ -77,10 +77,10 @@ private: void updateSmokePosition(int aDelta); void makeFollow(track::Choice aChoice); - IMapPtr myMap; - ISmokeTrailPtr mySmokeTrail; + IMapPtr map; + ISmokeTrailPtr smokeTrail; - Vector myVelocityVector; + Vector velocityVector; // Move part of the train across a connection void enterSegment(Part& aPart, const track::Connection& aConnection); @@ -92,9 +92,9 @@ private: const double Train::SEPARATION(0.1); Train::Train(IMapPtr aMap) - : myMap(aMap), myVelocityVector(makeVector(0.0f, 0.0f, 0.0f)) + : map(aMap), velocityVector(makeVector(0.0f, 0.0f, 0.0f)) { - myParts.push_front(Part(loadEngine("pclass"), true)); + parts.push_front(Part(loadEngine("pclass"), true)); enterSegment(engine(), aMap->startLocation()); @@ -104,45 +104,45 @@ Train::Train(IMapPtr aMap) for (int i = 1; i <= 5; i++) addPart(loadWaggon("coal_truck")); - mySmokeTrail = makeSmokeTrail(); + smokeTrail = makeSmokeTrail(); } void Train::addPart(IRollingStockPtr aVehicle) { Part part(aVehicle); - enterSegment(part, myMap->startLocation()); + enterSegment(part, map->startLocation()); // Push the rest of the train along some move(part.vehicle->length() + SEPARATION); - myParts.push_back(part); + parts.push_back(part); } // Make everything that's not the engine follow its choice void Train::makeFollow(track::Choice aChoice) { - for (list::iterator it = ++(myParts.begin()); - it != myParts.end(); ++it) + for (list::iterator it = ++(parts.begin()); + it != parts.end(); ++it) (*it).followQueue.push(aChoice); } Train::Part& Train::engine() { - assert(myParts.size() > 0); - return myParts.front(); + assert(parts.size() > 0); + return parts.front(); } const Train::Part& Train::engine() const { - assert(myParts.size() > 0); - return myParts.front(); + assert(parts.size() > 0); + return parts.front(); } // Move the train along the line a bit void Train::move(double aDistance) { - for (list::iterator it = myParts.begin(); - it != myParts.end(); ++it) { + for (list::iterator it = parts.begin(); + it != parts.end(); ++it) { // Never move in units greater than 1.0 double d = aDistance; @@ -181,24 +181,24 @@ void Train::updateSmokePosition(int aDelta) glPopMatrix(); - mySmokeTrail->setPosition(matrix[12], matrix[13], matrix[14]); - mySmokeTrail->setVelocity(myVelocityVector.x, - myVelocityVector.y, - myVelocityVector.z); - mySmokeTrail->update(aDelta); + smokeTrail->setPosition(matrix[12], matrix[13], matrix[14]); + smokeTrail->setVelocity(velocityVector.x, + velocityVector.y, + velocityVector.z); + smokeTrail->update(aDelta); // Make the rate at which new particles are created proportional // to the throttle of the controller const int throttle = e.vehicle->controller()->throttle(); const int baseDelay = 200; - mySmokeTrail->setDelay(baseDelay - (throttle * 15)); + smokeTrail->setDelay(baseDelay - (throttle * 15)); } void Train::update(int aDelta) { - for (list::iterator it = myParts.begin(); - it != myParts.end(); ++it) + for (list::iterator it = parts.begin(); + it != parts.end(); ++it) (*it).vehicle->update(aDelta); updateSmokePosition(aDelta); @@ -211,7 +211,7 @@ void Train::update(int aDelta) const double deltaSeconds = static_cast(aDelta) / 1000.0f; move(engine().vehicle->speed() * deltaSeconds / M_PER_UNIT); - myVelocityVector = partPosition(engine()) - oldPos; + velocityVector = partPosition(engine()) - oldPos; } // Called when the train enters a new segment @@ -224,11 +224,11 @@ void Train::enterSegment(Part& aPart, const track::Connection& aConnection) //debug() << "Train part entered segment at " << pos // << " moving " << aPart.direction; - if (!myMap->isValidTrack(pos)) + if (!map->isValidTrack(pos)) throw runtime_error("Train fell off end of track!"); aPart.segmentDelta = 0.0; - aPart.segment = myMap->trackAt(pos); + aPart.segment = map->trackAt(pos); aPart.travelToken = aPart.segment->getTravelToken(pos, aPart.direction); if (aPart.travelToken.choices.size() > 1) { @@ -253,8 +253,8 @@ void Train::enterSegment(Part& aPart, const track::Connection& aConnection) void Train::render() const { - for (list::const_iterator it = myParts.begin(); - it != myParts.end(); ++it) { + for (list::const_iterator it = parts.begin(); + it != parts.end(); ++it) { glPushMatrix(); (*it).travelToken.transform((*it).segmentDelta); @@ -264,7 +264,7 @@ void Train::render() const glPopMatrix(); } - mySmokeTrail->render(); + smokeTrail->render(); } ITrackSegmentPtr Train::trackSegment() const diff --git a/src/ft/Font.cpp b/src/ft/Font.cpp index 8fe5d4b..a81d9c4 100644 --- a/src/ft/Font.cpp +++ b/src/ft/Font.cpp @@ -256,7 +256,7 @@ void Font::print(int x, int y, Colour c, const string& s) const glPushMatrix(); - glColor4f(get<0>(c), get<1>(c), get<2>(c), get<3>(c)); + glColor4f(c.r, c.g, c.b, c.a); glTranslatef(x, y + (face->size->metrics.ascender>>6), 0.0f); for (string::const_iterator it = s.begin(); diff --git a/src/ft/IFont.hpp b/src/ft/IFont.hpp index b161454..b6a9b84 100644 --- a/src/ft/IFont.hpp +++ b/src/ft/IFont.hpp @@ -19,11 +19,10 @@ #define INC_FT_IFONT_HPP #include "Platform.hpp" -#include "gui2/Colour.hpp" +#include "Colour.hpp" namespace ft { - using namespace gui; - + struct IFont { virtual ~IFont() {} diff --git a/src/gui/FuelMeter.cpp b/src/gui/FuelMeter.cpp index 335c32f..4676902 100644 --- a/src/gui/FuelMeter.cpp +++ b/src/gui/FuelMeter.cpp @@ -17,6 +17,7 @@ #include "gui/IControl.hpp" #include "gui/Internal.hpp" +#include "OpenGLHelper.hpp" #include @@ -107,7 +108,7 @@ void FuelMeter::render(int x, int y) const const float unit = METER_WIDTH / static_cast(myMax + 1); - glColor3f(get<0>(myColour), get<1>(myColour), get<2>(myColour)); + gl::colour(myColour); glBegin(GL_QUADS); glVertex2i(0, 0); glVertex2i(0, METER_HEIGHT); diff --git a/src/gui2/RenderContext.cpp b/src/gui2/RenderContext.cpp index 2207180..71b0a0d 100644 --- a/src/gui2/RenderContext.cpp +++ b/src/gui2/RenderContext.cpp @@ -19,6 +19,7 @@ #include "gui2/Widget.hpp" #include "ILogger.hpp" #include "IWindow.hpp" +#include "OpenGLHelper.hpp" #include @@ -26,13 +27,6 @@ using namespace gui; IWindowPtr getGameWindow(); -namespace { - inline void set_colour(Colour c) - { - glColor4f(get<0>(c), get<1>(c), get<2>(c), get<3>(c)); - } -} - RenderContext::RenderContext() : origin_x(0), origin_y(0) { @@ -68,7 +62,7 @@ void RenderContext::offset(int& x, int& y) const void RenderContext::rectangle(int x, int y, int w, int h, Colour c) { offset(x, y); - set_colour(c); + gl::colour(c); glBegin(GL_QUADS); glVertex2i(x, y); @@ -81,7 +75,7 @@ void RenderContext::rectangle(int x, int y, int w, int h, Colour c) void RenderContext::border(int x, int y, int w, int h, Colour c) { offset(x, y); - set_colour(c); + gl::colour(c); x += 1; y += 1; @@ -108,7 +102,7 @@ void RenderContext::border(int x, int y, int w, int h, Colour c) void RenderContext::print(IFontPtr font, int x, int y, const string& s) { offset(x, y); - font->print(x, y, make_colour(1.0f, 1.0f, 1.0f), s); + font->print(x, y, makeColour(1.0f, 1.0f, 1.0f), s); } void RenderContext::scissor(Widget* w) diff --git a/src/gui2/Theme.cpp b/src/gui2/Theme.cpp index 87fc039..7564c45 100644 --- a/src/gui2/Theme.cpp +++ b/src/gui2/Theme.cpp @@ -29,10 +29,10 @@ Theme::Theme() Colour Theme::background() const { - return make_colour(0.0f, 0.0f, 0.3f, 0.5f); + return makeColour(0.0f, 0.0f, 0.3f, 0.5f); } Colour Theme::border() const { - return make_colour(0.0f, 0.0f, 1.0f, 1.0f); + return makeColour(0.0f, 0.0f, 1.0f, 1.0f); } -- 2.39.2