From cd9105b55254567b0bd130f61bb75d73218815b6 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 3 Dec 2011 10:19:46 +0000 Subject: [PATCH] Build as C++11 --- CMakeLists.txt | 2 +- include/IBillboard.hpp | 2 +- include/IFog.hpp | 2 +- include/IGraphics.hpp | 2 +- include/ILight.hpp | 2 +- include/ILogger.hpp | 6 +- include/ITrain.hpp | 4 +- include/Maths.hpp | 24 ++-- include/Platform.hpp | 11 +- src/Map.cpp | 272 ++++++++++++++++++++--------------------- src/Model.cpp | 40 +++--- src/QuadTree.cpp | 32 ++--- src/Resource.cpp | 22 ++-- src/SDLWindow.cpp | 38 +++--- src/Texture.cpp | 15 +-- 15 files changed, 234 insertions(+), 240 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10d9dac..ecf5a08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/" # Make sure optimisation is always enabled if (UNIX) if (CMAKE_COMPILER_IS_GNUCC) - set (CMAKE_CXX_FLAGS "-g -Wall -ffast-math -O2") + set (CMAKE_CXX_FLAGS "-g -Wall -ffast-math -O2 -std=c++0x") # "-Wconversion -Werror" if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -mfpmath=sse") diff --git a/include/IBillboard.hpp b/include/IBillboard.hpp index e6c800a..6af1719 100644 --- a/include/IBillboard.hpp +++ b/include/IBillboard.hpp @@ -33,7 +33,7 @@ struct IBillboard { virtual void set_colour(float r, float g, float b, float a) = 0; }; -typedef std::tr1::shared_ptr IBillboardPtr; +typedef shared_ptr IBillboardPtr; IBillboardPtr make_cylindrical_billboard(ITexturePtr a_texture); IBillboardPtr make_spherical_billboard(ITexturePtr a_texture); diff --git a/include/IFog.hpp b/include/IFog.hpp index 1d2d2f1..0ebf67c 100644 --- a/include/IFog.hpp +++ b/include/IFog.hpp @@ -27,7 +27,7 @@ struct IFog { virtual void apply() const = 0; }; -typedef std::tr1::shared_ptr IFogPtr; +typedef shared_ptr IFogPtr; // Construct a generic fog IFogPtr make_fog(float r, float g, float b, diff --git a/include/IGraphics.hpp b/include/IGraphics.hpp index 6ea8e3a..40547db 100644 --- a/include/IGraphics.hpp +++ b/include/IGraphics.hpp @@ -37,6 +37,6 @@ struct IGraphics { const Vector a_target_point) = 0; }; -typedef std::tr1::shared_ptr IGraphicsPtr; +typedef shared_ptr IGraphicsPtr; #endif diff --git a/include/ILight.hpp b/include/ILight.hpp index e8dbf58..62c7ec4 100644 --- a/include/ILight.hpp +++ b/include/ILight.hpp @@ -28,7 +28,7 @@ struct ILight { virtual void apply() const = 0; }; -typedef std::tr1::shared_ptr ILightPtr; +typedef shared_ptr ILightPtr; // A weak non-directional light ILightPtr make_sun_light(); diff --git a/include/ILogger.hpp b/include/ILogger.hpp index 5c4a9c6..1cd869b 100644 --- a/include/ILogger.hpp +++ b/include/ILogger.hpp @@ -29,7 +29,7 @@ struct PrintLine { std::ostream& stream; }; -typedef std::tr1::shared_ptr PrintLinePtr; +typedef shared_ptr PrintLinePtr; template inline PrintLinePtr operator<<(PrintLinePtr a_print_line, const T& a_thing) @@ -47,11 +47,11 @@ enum LogMsgType { // Interface to logger class struct ILogger { virtual ~ILogger() {} - + virtual PrintLinePtr write_msg(LogMsgType type = LOG_NORMAL) = 0; }; -typedef std::tr1::shared_ptr ILoggerPtr; +typedef shared_ptr ILoggerPtr; ILoggerPtr get_logger(); diff --git a/include/ITrain.hpp b/include/ITrain.hpp index a3bc626..53a8386 100644 --- a/include/ITrain.hpp +++ b/include/ITrain.hpp @@ -26,7 +26,7 @@ // Interface to managing complete trains struct ITrain { virtual ~ITrain() {} - + virtual void render() const = 0; virtual void update(int a_delta) = 0; @@ -50,7 +50,7 @@ struct ITrain { virtual IControllerPtr controller() = 0; }; -typedef std::tr1::shared_ptr ITrainPtr; +typedef shared_ptr ITrainPtr; ITrainPtr make_train(IMapPtr a_map); diff --git a/include/Maths.hpp b/include/Maths.hpp index 0ccbae0..0bbf0c2 100644 --- a/include/Maths.hpp +++ b/include/Maths.hpp @@ -41,7 +41,7 @@ struct Packed { union { Type p; float f[4]; - } u; + } u; u.f[0] = a; u.f[1] = b; u.f[2] = c; @@ -53,7 +53,7 @@ struct Packed { template <> struct Packed { typedef int __attribute__((vector_size (16))) Type; - + static inline Type pack(int a, int b, int c) { union Union { @@ -73,7 +73,7 @@ struct EqTolerance; template <> struct EqTolerance { - static const float Value = 0.01f; + static constexpr float Value = 0.01f; }; template <> @@ -141,18 +141,18 @@ struct Vector { packed /= Packed::pack(m, m, m); return *this; } - + inline Vector operator+(const Vector& v) const { return Vector(packed + v.packed); } - + inline Vector& operator+=(const Vector& v) { packed += v.packed; return *this; } - + inline Vector operator-(const Vector& v) const { return Vector(packed - v.packed); @@ -168,14 +168,14 @@ struct Vector { packed -= v.packed; return *this; } - + inline bool operator==(const Vector& rhs) const { const typename Packed::Type diff = rhs.packed - packed; const T delta2 = EqTolerance::Value * EqTolerance::Value; const Vector squared(diff * diff); - + return (squared.x <= delta2) && (squared.y <= delta2) && (squared.z <= delta2); @@ -284,14 +284,14 @@ struct Point { { return Point(x - rhs.x, y - rhs.y); } - + Point& operator+=(const Point& rhs) { x += rhs.x; y += rhs.y; return *this; } - + Point& operator-=(const Point& rhs) { x -= rhs.x; @@ -309,7 +309,7 @@ struct Point { return x < rhs.x || (x == rhs.x && y < rhs.y); } - + T x, y; }; @@ -338,7 +338,7 @@ struct Frustum { bool cube_in_frustum(float x, float y, float z, float size); // size = 0.5*side_length bool cuboid_in_frustum(float x, float y, float z, float sizeX, float sizeY, float sizeZ); - + float planes[6][4]; }; diff --git a/include/Platform.hpp b/include/Platform.hpp index 6258eea..4a48b40 100644 --- a/include/Platform.hpp +++ b/include/Platform.hpp @@ -28,11 +28,11 @@ // First, make sure we get a decent TR1 implementation #if defined __GNUC__ -#include -#include -#include +#include +#include +#include -#elif (_MSVC_VER >= 1500) +#elif (_MSVC_VER >= 1500) // MSVC9 has TR1 available as an add-on pack @@ -48,6 +48,8 @@ #include #include +using namespace std::tr1; + #endif // Including windows.h is required for OpenGL @@ -64,6 +66,5 @@ #endif using namespace std; -using namespace std::tr1; #endif diff --git a/src/Map.cpp b/src/Map.cpp index 5792046..e734f2e 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -84,7 +84,7 @@ public: void set_start(int x, int y, int dirX, int dirY); void set_grid(bool on_off); void set_pick_mode(bool on_off) { in_pick_mode = on_off; } - + track::Connection start() const; ITrackSegmentPtr track_at(const Point& a_point) const; IStationPtr station_at(Point a_point) const; @@ -103,7 +103,7 @@ public: const Point& a_finish_pos); void level_area(Point a_start_pos, Point a_finish_pos); void smooth_area(Point start, Point finish); - + void save(); IStationPtr extend_station(Point a_start_pos, @@ -117,13 +117,13 @@ public: Vector slope_after(Point where, track::Direction axis, bool &valid) const; void add_scenery(Point where, ISceneryPtr s); - + // ISectorRenderable interface void render_sector(IGraphicsPtr a_context, int id, Point bot_left, Point top_right); void post_render_sector(IGraphicsPtr a_context, int id, Point bot_left, Point top_right); - + private: // Tiles on the map struct Tile { @@ -147,13 +147,13 @@ private: // Meshes for each terrain sector vector terrain_meshes; - + inline int index(int x, int y) const { assert(x < my_width && y < my_depth && x >= 0 && y >= 0); return x + y*my_width; } - + inline int tile_name(int x, int z) const { return TILE_NAME_BASE + index(x, z); @@ -174,7 +174,7 @@ private: assert(i >= 0 && i < (my_width + 1) * (my_depth + 1)); return height_map[i]; } - + bool is_valid_tileName(unsigned a_name) const { return a_name >= TILE_NAME_BASE @@ -182,9 +182,9 @@ private: } Point pick_position(unsigned a_name) const - { + { assert(is_valid_tileName(a_name)); - + int a = a_name - TILE_NAME_BASE; return make_point(a % my_width, a / my_width); } @@ -204,7 +204,7 @@ private: void build_mesh(int id, Point bot_left, Point top_right); bool have_mesh(int id, Point bot_left, Point top_right); void dirty_tile(int x, int y); - + // Terrain modification void change_area_height(const Point& a_start_pos, const Point& a_finish_pos, float a_height_delta); @@ -212,7 +212,7 @@ private: void set_tile_height(int x, int y, float h); void fix_normals(int x, int y); bool raise_will_cover_track(int x, int y) const; - + int my_width, my_depth; Point start_location; track::Direction start_direction; @@ -278,13 +278,13 @@ void Map::erase_tile(int x, int y) // We have to be a bit careful since a piece of track has multiple // endpoints - vector > locked; + vector > locked; tile.track->get()->get_height_locked(locked); for (vector >::iterator it = locked.begin(); it != locked.end(); ++it) unlock_height_at(*it); - + vector > covers; tile.track->get()->get_endpoints(covers); tile.track->get()->get_covers(covers); @@ -301,7 +301,7 @@ void Map::erase_tile(int x, int y) const Point size = tile.scenery->get()->size(); const Point& where = tile.scenery->origin(); - + for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { tile_at(where.x + x, where.y + y).scenery.reset(); @@ -324,17 +324,17 @@ bool Map::empty_tile(Point point) const } void Map::set_track_at(const Point& where, ITrackSegmentPtr track) -{ +{ int indexes[4]; tile_vertices(where.x, where.y, indexes); float lowest_height = 1.0e20f; for (int i = 0; i < 4; i++) lowest_height = min(height_map[indexes[i]].pos.y, lowest_height); - + track->set_origin(where.x, where.y, lowest_height); - - TrackAnchor node(new Anchor(track, where)); + + TrackAnchor node(new Anchor(track, where)); // Attach the track node to every tile it covers vector > covers; @@ -363,7 +363,7 @@ bool Map::is_valid_track(const Point& where) const || where.x >= my_width || where.y >= my_depth) return false; - return tile_at(where.x, where.y).track; + return static_cast(tile_at(where.x, where.y).track); } // Return a location where the train may start @@ -379,7 +379,7 @@ void Map::set_start(int x, int y) axis::X, axis::Y, -axis::X, -axis::Y }; static int next_dir = 0; - + TrackAnchor track_node = tile_at(x, y).track; if (!track_node) { warn() << "Must place start on track"; @@ -420,10 +420,10 @@ void Map::set_grid(bool on_off) } void Map::reset_map(int a_width, int a_depth) -{ +{ my_width = a_width; my_depth = a_depth; - + // Allocate memory if (tiles) delete[] tiles; @@ -432,7 +432,7 @@ void Map::reset_map(int a_width, int a_depth) if (height_map) delete[] height_map; height_map = new HeightMap[(a_width + 1) * (a_depth + 1)]; - + // Make a flat map for (int x = 0; x <= a_width; x++) { for (int y = 0; y <= a_depth; y++) { @@ -446,7 +446,7 @@ void Map::reset_map(int a_width, int a_depth) v.lock_count = 0; } } - + // Create quad tree quad_tree = make_quad_tree(shared_from_this(), my_width, my_depth); } @@ -457,10 +457,10 @@ void Map::highlight_vertex(Point point, Colour colour) const && point.y >= 0 && point.y < my_depth); int index = point.x + (point.y * (my_width + 1)); - + gl::colour(colour); glPointSize(5.0f); - + glBegin(GL_POINTS); glVertex3f(static_cast(point.x) - 0.5f, height_map[index].pos.y + 0.01f, @@ -477,44 +477,44 @@ void Map::render_highlighted_tiles() const { // At the end of the render loop, draw the highlighted tiles over // the top of all others - this is to get the transparency working - + glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT); - + glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glDisable(GL_LIGHTING); - + glDepthMask(GL_FALSE); - + vector, Colour> >::const_iterator it; for (it = highlighted_tiles.begin(); it != highlighted_tiles.end(); ++it) { const Point& point = get<0>(*it); Colour colour = get<1>(*it); - + // User should be able to click on the highlight as well glPushName(tile_name(point.x, point.y)); colour.a = 0.5f; gl::colour(colour); glBegin(GL_POLYGON); - + int indexes[4]; tile_vertices(point.x, point.y, indexes); - + for (int i = 0; i < 4; i++) { HeightMap& v = height_map[indexes[i]]; glNormal3f(v.normal.x, v.normal.y, v.normal.z); glVertex3f(v.pos.x, v.pos.y + 0.1f, v.pos.z); } - + glEnd(); - + glPopName(); } glPopAttrib(); - + highlighted_tiles.clear(); } @@ -523,9 +523,9 @@ void Map::render(IGraphicsPtr a_context) const // The `frame_num' counter is used to ensure we draw each // track segment at most once per frame frame_num++; - + fog->apply(); - + glPushAttrib(GL_ALL_ATTRIB_BITS); // Thick lines for grid @@ -537,14 +537,14 @@ void Map::render(IGraphicsPtr a_context) const glDisable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); - + glPushMatrix(); quad_tree->render(a_context); glPopMatrix(); - + render_highlighted_tiles(); - + glPopAttrib(); } @@ -565,8 +565,8 @@ void Map::draw_start_location() const avg_height += height_map[indexes[i]].pos.y; avg_height /= 4.0f; - glTranslatef(static_cast(start_location.x), - avg_height + 0.1f, + glTranslatef(static_cast(start_location.x), + avg_height + 0.1f, static_cast(start_location.y)); if (start_direction == axis::X) @@ -577,14 +577,14 @@ void Map::draw_start_location() const glRotatef(270.0f, 0.0f, 1.0f, 0.0f); glColor4f(0.0f, 0.9f, 0.0f, 0.8f); - + glBegin(GL_TRIANGLES); glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(0.5f, 0.0f, -0.5f); glVertex3f(-0.5f, 0.0f, -0.5f); glVertex3f(0.0f, 0.0f, 0.5f); glEnd(); - + glPopMatrix(); glPopAttrib(); } @@ -595,8 +595,8 @@ bool Map::have_mesh(int id, Point bot_left, Point top_right) { if (id >= static_cast(terrain_meshes.size())) terrain_meshes.resize(id + 1); - - bool ok = terrain_meshes[id]; + + bool ok = static_cast(terrain_meshes[id]); list >::iterator it = dirty_tiles.begin(); while (it != dirty_tiles.end()) { @@ -605,7 +605,7 @@ bool Map::have_mesh(int id, Point bot_left, Point top_right) && (*it).x <= top_right.x && (*it).y >= bot_left.y && (*it).y <= top_right.y; - + if (covered) { ok = false; it = dirty_tiles.erase(it); @@ -613,7 +613,7 @@ bool Map::have_mesh(int id, Point bot_left, Point top_right) else ++it; } - + return ok; } @@ -654,12 +654,12 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) buf->bind(noise); const float tmul = 1.0f / float(top_right.x - bot_left.x + 1); - + for (int x = top_right.x-1; x >= bot_left.x; x--) { for (int y = bot_left.y; y < top_right.y; y++) { int indexes[4]; tile_vertices(x, y, indexes); - + const int order[6] = { indexes[1], indexes[2], indexes[3], indexes[3], indexes[0], indexes[1] @@ -676,10 +676,10 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) tex_coords[1], tex_coords[2], tex_coords[3], tex_coords[3], tex_coords[0], tex_coords[1] }; - + for (int i = 0; i < 6; i++) { const HeightMap& v = height_map[order[i]]; - + const float h = v.pos.y; tuple hcol; int j = 0; @@ -689,14 +689,14 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) buf->add(v.pos, v.normal, get<1>(hcol), tex_order[i]); } - } + } } // Merge any static scenery for (int x = top_right.x-1; x >= bot_left.x; x--) { for (int y = bot_left.y; y < top_right.y; y++) { Tile& tile = tile_at(x, y); - + if (tile.scenery && tile.scenery->needs_rendering(frame_num)) { tile.scenery->get()->merge(buf); tile.scenery->rendered_on(frame_num); @@ -720,18 +720,18 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) const float depth = -3.0f; buf->bind(ITexturePtr()); // No texture on sides - + int index[4]; - + if (bot_left.x == 0) { for (int y = bot_left.y; y < top_right.y; y++) { const float yf = static_cast(y) - 0.5f; tile_vertices(0, y, index); - + const float h1 = height_at(index[3]).pos.y; const float h2 = height_at(index[0]).pos.y; - + buf->add_quad(make_vector(x1, h1, yf), make_vector(x1, depth, yf), make_vector(x1, depth, yf + 1.0f), @@ -748,7 +748,7 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) const float h1 = height_at(index[2]).pos.y; const float h2 = height_at(index[1]).pos.y; - + buf->add_quad(make_vector(x2, depth, yf), make_vector(x2, h1, yf), make_vector(x2, h2, yf + 1.0f), @@ -760,12 +760,12 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) if (bot_left.y == 0) { for (int x = bot_left.x; x < top_right.x; x++) { const float xf = static_cast(x) - 0.5f; - + tile_vertices(x, 0, index); - + const float h1 = height_at(index[3]).pos.y; const float h2 = height_at(index[2]).pos.y; - + buf->add_quad(make_vector(xf, depth, y1), make_vector(xf, h1, y1), make_vector(xf + 1.0f, h2, y1), @@ -773,16 +773,16 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) brown); } } - + if (top_right.y == my_depth) { for (int x = bot_left.x; x < top_right.x; x++) { const float xf = static_cast(x) - 0.5f; - + tile_vertices(x, my_depth - 1, index); - + const float h1 = height_at(index[0]).pos.y; const float h2 = height_at(index[1]).pos.y; - + buf->add_quad(make_vector(xf, h1, y2), make_vector(xf, depth, y2), make_vector(xf + 1.0f, depth, y2), @@ -799,7 +799,7 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) for (int y = bot_left.y; y < top_right.y; y++) { int index[4]; tile_vertices(x, y, index); - + below_sea_level |= height_at(index[0]).pos.y < 0.0f || height_at(index[1]).pos.y < 0.0f @@ -817,7 +817,7 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) if (sea_sectors.size() < min_size) sea_sectors.resize(min_size); sea_sectors.at(id) = below_sea_level; - + // Make sure we don't rebuild this mesh if any of the tiles are dirty have_mesh(id, bot_left, top_right); } @@ -826,7 +826,7 @@ void Map::build_mesh(int id, Point bot_left, Point top_right) void Map::render_pick_sector(Point bot_left, Point top_right) { glColor3f(1.0f, 1.0f, 1.0f); - + for (int x = top_right.x-1; x >= bot_left.x; x--) { for (int y = bot_left.y; y < top_right.y; y++) { // Name this tile @@ -842,9 +842,9 @@ void Map::render_pick_sector(Point bot_left, Point top_right) glVertex3f(v.pos.x, v.pos.y, v.pos.z); } glEnd(); - + glPopName(); - } + } } } @@ -856,20 +856,20 @@ void Map::render_sector(IGraphicsPtr a_context, int id, render_pick_sector(bot_left, top_right); return; } - + if (!have_mesh(id, bot_left, top_right)) build_mesh(id, bot_left, top_right); { // Parts of track may extend outside the sector so these // are clipped off - + const float x = bot_left.x - 0.5f; const float w = quad_tree->leaf_size(); const float z = bot_left.y - 0.5f; const float d = quad_tree->leaf_size(); ClipVolume clip(x, w, z, d); - + terrain_meshes[id]->render(); } @@ -880,7 +880,7 @@ void Map::render_sector(IGraphicsPtr a_context, int id, // const Vertex& v = height_map[indexes[i]]; // draw_normal(v.pos, v.normal); //} - + if (should_draw_grid_lines) { // Render grid lines glColor3f(0.0f, 0.0f, 0.0f); @@ -892,12 +892,12 @@ void Map::render_sector(IGraphicsPtr a_context, int id, const HeightMap& v = height_map[indexes[i]]; glVertex3f(v.pos.x, v.pos.y, v.pos.z); } - + glEnd(); } Tile& tile = tile_at(x, y); - + if (tile.track && tile.track->needs_rendering(frame_num)) { #if 0 // Draw the endpoints for debugging @@ -922,10 +922,10 @@ void Map::render_sector(IGraphicsPtr a_context, int id, bind(&Map::highlight_vertex, this, placeholders::_1, make_colour(1.0f, 0.0f, 0.0f))); #endif - + // Draw track highlights tile.track->get()->render(); - + tile.track->rendered_on(frame_num); } @@ -944,7 +944,7 @@ void Map::render_sector(IGraphicsPtr a_context, int id, if (start_location.x == x && start_location.y == y && should_draw_grid_lines) draw_start_location(); - } + } } } @@ -963,7 +963,7 @@ void Map::post_render_sector(IGraphicsPtr a_context, int id, const float blY = static_cast(bot_left.y); const float trX = static_cast(top_right.x); const float trY = static_cast(top_right.y); - + static const float sea_level = -0.6f; gl::colour(make_rgb(0, 80, 160, 150)); glNormal3f(0.0f, 1.0f, 0.0f); @@ -996,12 +996,12 @@ void Map::fix_normals(int x, int y) Vector west, north, east, south; bool have_west = true, have_north = true, have_east = true, have_south = true; - + if (i > 0 && i % (my_width + 1) > 0) west = height_at(i-1).pos; else have_west = false; - + if (i < (my_width + 1) * my_depth - 1) north = height_at(i + (my_width + 1)).pos; else @@ -1012,7 +1012,7 @@ void Map::fix_normals(int x, int y) east = height_at(i + 1).pos; else have_east = false; - + if (i > (my_width + 1)) south = height_at(i - (my_width + 1)).pos; else @@ -1036,7 +1036,7 @@ void Map::fix_normals(int x, int y) else count -= 1.0f; - if (have_west && have_south) + if (have_west && have_south) avg += surface_normal(west, v.pos, south); else count -= 1.0f; @@ -1049,7 +1049,7 @@ void Map::fix_normals(int x, int y) void Map::tile_vertices(int x, int y, int* indexes) const { assert(x >= 0 && x < my_width && y >= 0 && y < my_depth); - + indexes[3] = x + (y * (my_width+1)); // (X, Y) indexes[2] = (x+1) + (y * (my_width+1)); // (X+1, Y) indexes[1] = (x+1) + ((y+1) * (my_width+1)); // (X+1, Y+1) @@ -1077,7 +1077,7 @@ bool Map::raise_will_cover_track(int x, int y) const bool ok = true; for (int i = 0; i < 4; i++) ok &= height_map[indexes[i]].lock_count == 0; - + return !ok; #endif } @@ -1089,7 +1089,7 @@ void Map::raise_tile(int x, int y, float delta_height) warn() << "Cannot raise terrain over track"; return; } - + int indexes[4]; tile_vertices(x, y, indexes); @@ -1123,7 +1123,7 @@ void Map::unlock_height_at(Point p) void Map::set_tile_height(int x, int y, float h) { bool track_affected = raise_will_cover_track(x, y); - + int indexes[4]; tile_vertices(x, y, indexes); @@ -1132,11 +1132,11 @@ void Map::set_tile_height(int x, int y, float h) && abs(height_map[indexes[i]].pos.y - h) > 0.01f) { warn() << "Cannot level terrain under track"; return; - } + } else height_map[indexes[i]].pos.y = h; } - + fix_normals(x, y); dirty_tile(x, y); } @@ -1161,7 +1161,7 @@ float Map::height_at(Point where) const float avg = 0.0f; for (int i = 0; i < 4; i++) avg += height_map[indexes[i]].pos.y; - + return avg / 4.0f; } @@ -1193,7 +1193,7 @@ Vector Map::slope_at(Point where, << " v1=" << v1 << " v2=" << v2 << " level=" << level; #endif - + return v1; } @@ -1206,13 +1206,13 @@ Vector Map::slope_before(Point where, before = where + make_point(-1, 0); else before = where + make_point(0, -1); - + const bool off_edge = (axis == axis::X && before.x < 0) || (axis == axis::Y && before.y < 0); valid = !off_edge; - + if (off_edge) return make_vector(0.0f, 0.0f, 0.0f); else { @@ -1230,13 +1230,13 @@ Vector Map::slope_after(Point where, after = where + make_point(1, 0); else after = where + make_point(0, 1); - + const bool off_edge = (axis == axis::X && after.x >= width()) || (axis == axis::Y && after.y >= depth()); valid = !off_edge; - + if (off_edge) return make_vector(0.0f, 0.0f, 0.0f); else { @@ -1254,7 +1254,7 @@ void Map::change_area_height(const Point& a_start_pos, const int ymin = min(a_start_pos.y, a_finish_pos.y); const int ymax = max(a_start_pos.y, a_finish_pos.y); - + for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) raise_tile(x, y, a_height_delta); @@ -1276,7 +1276,7 @@ void Map::level_area(Point a_start_pos, Point a_finish_pos) for (int i = 0; i < 4; i++) avg_height += height_map[indexes[i]].pos.y; avg_height /= 4.0f; - + for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) set_tile_height(x, y, avg_height); @@ -1317,7 +1317,7 @@ void Map::smooth_area(Point start, Point finish) int i = 0; for (Point it = abs_start; it != abs_finish; i++, it += step) { const bool track_affected = raise_will_cover_track(it.x, it.y); - + int indexes[4]; tile_vertices(it.x, it.y, indexes); @@ -1330,23 +1330,23 @@ void Map::smooth_area(Point start, Point finish) targets[0] = 1; targets[1] = 2; } - + for (int j = 0; j < 2; j++) { const float new_height = height_start - (i * drop); - + if (track_affected && abs(height_map[indexes[targets[j]]].pos.y - new_height) > 0.01f) { warn() << "Cannot change terrain under track"; return; - } + } else height_map[indexes[targets[j]]].pos.y = new_height; } - + fix_normals(it.x, it.y); dirty_tile(it.x, it.y); } - + } void Map::raise_area(const Point& a_start_pos, @@ -1369,14 +1369,14 @@ void Map::add_scenery(Point where, ISceneryPtr s) SceneryAnchor indirect(new Anchor(s, where)); const Point size = s->size(); - + for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { tile_at(where.x + x, where.y + y).scenery = indirect; dirty_tile(where.x, where.y); } } - + s->set_position(static_cast(where.x), height_at(where), static_cast(where.y)); @@ -1413,7 +1413,7 @@ IStationPtr Map::extend_station(Point a_start_pos, Point a_finish_pos) // See if any of these track segments are adjacent to a station for (PointList::const_iterator it = track_in_area.begin(); it != track_in_area.end(); ++it) { - + const Point near[] = { make_point(0, 0), make_point(1, 0), @@ -1421,7 +1421,7 @@ IStationPtr Map::extend_station(Point a_start_pos, Point a_finish_pos) make_point(-1, 0), make_point(0, -1) }; - + for (int i = 0; i < 5; i++) { Point neighbour = *it + near[i]; if (neighbour.x >= 0 && neighbour.x < my_width @@ -1429,7 +1429,7 @@ IStationPtr Map::extend_station(Point a_start_pos, Point a_finish_pos) && tile_at(neighbour.x, neighbour.y).station) { IStationPtr candidate = tile_at(neighbour.x, neighbour.y).station; - + // Maybe extend this station if (station && station != candidate) { warn() << "Cannot merge stations"; @@ -1450,11 +1450,11 @@ IStationPtr Map::extend_station(Point a_start_pos, Point a_finish_pos) station = make_station(); } - + for (PointList::iterator it = track_in_area.begin(); it != track_in_area.end(); ++it) tile_at((*it).x, (*it).y).station = station; - + return station; } @@ -1473,12 +1473,12 @@ void Map::write_height_map() const try { ofstream& of = h.wstream(); - + const int32_t wl = static_cast(my_width); const int32_t dl = static_cast(my_depth); of.write(reinterpret_cast(&wl), sizeof(int32_t)); of.write(reinterpret_cast(&dl), sizeof(int32_t)); - + for (int i = 0; i < (my_width + 1) * (my_depth + 1); i++) of.write(reinterpret_cast(&height_map[i].pos.y), sizeof(float)); @@ -1497,7 +1497,7 @@ void Map::read_height_map(IResource::Handle a_handle) log() << "Reading height map from " << a_handle.file_name(); istream& is = a_handle.rstream(); - + // Check the dimensions of the binary file match the XML file int32_t wl, dl; is.read(reinterpret_cast(&wl), sizeof(int32_t)); @@ -1529,7 +1529,7 @@ void Map::save_to(ostream& of) root.add_attribute("height", my_depth); root.add_child(xml::element("name").add_text("No Name")); - + root.add_child (xml::element("start") .add_attribute("x", start_location.x) @@ -1539,7 +1539,7 @@ void Map::save_to(ostream& of) // Write out all the stations set seen_stations; - + for (int x = 0; x < my_width; x++) { for (int y = 0; y < my_depth; y++) { IStationPtr s = tile_at(x, y).station; @@ -1555,7 +1555,7 @@ void Map::save_to(ostream& of) } } } - + // Generate the height map write_height_map(); @@ -1605,7 +1605,7 @@ void Map::save_to(ostream& of) } root.add_child(tileset); - + of << xml::document(root); } @@ -1615,7 +1615,7 @@ void Map::save() using namespace boost::filesystem; IResource::Handle h = resource->write_file(resource->name() + ".xml"); - + log() << "Saving map to " << h.file_name(); ofstream& of = h.wstream(); @@ -1632,7 +1632,7 @@ void Map::save() IMapPtr make_empty_map(const string& a_res_id, int a_width, int a_depth) { IResourcePtr res = make_new_resource(a_res_id, "maps"); - + shared_ptr ptr(new Map(res)); ptr->reset_map(a_width, a_depth); ptr->save(); @@ -1649,7 +1649,7 @@ public: void start_element(const string& local_name, const AttributeSet& attrs); void end_element(const string& local_name); void text(const string& local_name, const string& a_string); - + private: void handle_map(const AttributeSet& attrs); void handle_building(const AttributeSet& attrs); @@ -1663,7 +1663,7 @@ private: void handle_points(const AttributeSet& attrs); void handle_crossover_track(const AttributeSet& attrs); void handle_spline_track(const AttributeSet& attrs); - + shared_ptr my_map; map my_stations; IStationPtr my_active_station; @@ -1706,8 +1706,8 @@ void MapLoader::end_element(const string& local_name) { if (local_name == "station") my_active_station.reset(); -} - +} + void MapLoader::text(const string& local_name, const string& a_string) { if (local_name == "heightmap") @@ -1736,7 +1736,7 @@ void MapLoader::handle_tree(const AttributeSet& attrs) { my_map->add_scenery(tile, load_tree(attrs)); } - + void MapLoader::handle_station(const AttributeSet& attrs) { my_active_station = make_station(); @@ -1747,7 +1747,7 @@ void MapLoader::handle_station(const AttributeSet& attrs) my_stations[id] = my_active_station; } - + void MapLoader::handle_start(const AttributeSet& attrs) { int x, y, dirX, dirY; @@ -1755,7 +1755,7 @@ void MapLoader::handle_start(const AttributeSet& attrs) attrs.get("y", y); attrs.get("dirX", dirX); attrs.get("dirY", dirY); - + my_map->set_start(x, y, dirX, dirY); } @@ -1792,12 +1792,12 @@ void MapLoader::handle_slope_track(const AttributeSet& attrs) { string align; attrs.get("align", align); - + track::Direction axis = align == "x" ? axis::X : axis::Y; bool level; Vector slope = my_map->slope_at(tile, axis, level); - + bool a_valid, b_valid; Vector slope_before = my_map->slope_before(tile, axis, b_valid); Vector slope_after = my_map->slope_after(tile, axis, a_valid); @@ -1813,7 +1813,7 @@ void MapLoader::handle_points(const AttributeSet& attrs) { string align; attrs.get("align", align); - + bool reflect; attrs.get("reflect", reflect); @@ -1821,7 +1821,7 @@ void MapLoader::handle_points(const AttributeSet& attrs) align == "x" ? axis::X : (align == "-x" ? -axis::X : (align == "y" ? axis::Y : -axis::Y)); - + my_map->set_track_at(tile, make_points(dir, reflect)); } @@ -1840,7 +1840,7 @@ void MapLoader::handle_spline_track(const AttributeSet& attrs) attrs.get("entry-dir-x", entry_dir.x); attrs.get("entry-dir-y", entry_dir.z); - + attrs.get("exit-dir-x", exit_dir.x); attrs.get("exit-dir-y", exit_dir.z); @@ -1850,7 +1850,7 @@ void MapLoader::handle_spline_track(const AttributeSet& attrs) IMapPtr load_map(const string& a_res_id) { IResourcePtr res = find_resource(a_res_id, "maps"); - + shared_ptr map(new Map(res)); log() << "Loading map from file " << res->xml_file_name(); @@ -1859,6 +1859,6 @@ IMapPtr load_map(const string& a_res_id) MapLoader loader(map, res); xml_parser->parse(res->xml_file_name(), loader); - + return IMapPtr(map); } diff --git a/src/Model.cpp b/src/Model.cpp index 9a725a9..e079dd3 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -34,8 +34,6 @@ #include -using namespace boost; - // Cache of already loaded models namespace { typedef map ModelCache; @@ -48,7 +46,7 @@ struct Material { ambientR(1.0f), ambientG(1.0f), ambientB(1.0f), specularR(0.0f), specularG(0.0f), specularB(0.0f) {} - + float diffuseR, diffuseG, diffuseB; float ambientR, ambientG, ambientB; float specularR, specularG, specularB; @@ -67,16 +65,16 @@ private: MaterialSet my_materials; }; -typedef std::tr1::shared_ptr MaterialFilePtr; +typedef shared_ptr MaterialFilePtr; MaterialFile::MaterialFile(const string& a_file_name, IResourcePtr a_res) { IResource::Handle h = a_res->open_file(a_file_name); - + log() << "Loading materials from " << h.file_name(); istream& is = h.rstream(); - + string active_material; while (!is.eof()) { string word; @@ -139,10 +137,10 @@ public: void cache(); void merge(IMeshBufferPtr into, Vector off, float y_angle) const; Vector dimensions() const { return dimensions_; } - + private: void compile_mesh() const; - + Vector dimensions_; mutable IMeshPtr mesh; const IMeshBufferPtr buffer; @@ -150,7 +148,7 @@ private: Model::~Model() { - + } void Model::cache() @@ -163,14 +161,14 @@ void Model::render() const { if (!mesh) compile_mesh(); - + mesh->render(); } void Model::merge(IMeshBufferPtr into, Vector off, float y_angle) const { into->merge(buffer, off, y_angle); -} +} void Model::compile_mesh() const { @@ -211,7 +209,7 @@ IModelPtr load_model(IResourcePtr a_res, Material active_mtl; ifstream& f = h.rstream(); - + while (!f.eof()) { string first; f >> first; @@ -228,7 +226,7 @@ IModelPtr load_model(IResourcePtr a_res, // Material file string file_name; f >> file_name; - + material_file = MaterialFilePtr(new MaterialFile(file_name, a_res)); } @@ -269,7 +267,7 @@ IModelPtr load_model(IResourcePtr a_res, // Normal float x, y, z; f >> x >> y >> z; - + normals.push_back(make_vector(x, y, z)); } else if (first == "vt") { @@ -287,7 +285,7 @@ IModelPtr load_model(IResourcePtr a_res, // Set the material for this group string material_name; f >> material_name; - + if (material_file) { assert(buffer); active_mtl = material_file->get(material_name); @@ -300,7 +298,7 @@ IModelPtr load_model(IResourcePtr a_res, istringstream ss(line); int v_in_thisFace = 0; - + while (!ss.eof()) { char delim1, delim2; unsigned vi, vti, vni; @@ -326,11 +324,11 @@ IModelPtr load_model(IResourcePtr a_res, Vector& vn = normals[vni - 1]; assert(buffer); - + const Colour col = make_colour(active_mtl.diffuseR, active_mtl.diffuseG, active_mtl.diffuseB); - + if (vti - 1 < texture_offs.size()) { Point& vt = texture_offs[vti - 1]; buffer->add(v, vn, col, vt); @@ -340,7 +338,7 @@ IModelPtr load_model(IResourcePtr a_res, } face_count++; - + // Don't discard the next line continue; } @@ -350,10 +348,10 @@ IModelPtr load_model(IResourcePtr a_res, } Vector dim = make_vector(xmax - xmin, ymax - ymin, zmax - zmin); - + log() << "Model loaded: " << vertices.size() << " vertices, " << face_count << " faces"; - + IModelPtr ptr(new Model(dim, buffer)); the_cache[cache_name] = ptr; diff --git a/src/QuadTree.cpp b/src/QuadTree.cpp index c92bec1..68a0968 100644 --- a/src/QuadTree.cpp +++ b/src/QuadTree.cpp @@ -31,7 +31,7 @@ public: ~QuadTree(); void build_tree(int width, int height); - + void render(IGraphicsPtr a_context); int leaf_size() const { return QT_LEAF_SIZE; } @@ -48,7 +48,7 @@ private: int calc_num_sectors(int a_width); int build_node(int an_id, int a_parent, int x1, int y1, int x2, int y2); void visible_sectors(IGraphicsPtr a_context, list& a_list, int a_sector); - + int size, num_sectors, used_sectors; ISectorRenderablePtr renderer; @@ -68,7 +68,7 @@ QuadTree::QuadTree(ISectorRenderablePtr a_renderable) real_width(0), real_height(0), kill_count(0) { - + } QuadTree::~QuadTree() @@ -84,7 +84,7 @@ void QuadTree::render(IGraphicsPtr a_context) visible_sectors(a_context, visible, 0); list::const_iterator it; - + for (it = visible.begin(); it != visible.end(); ++it) renderer->render_sector(a_context, (*it)->id, (*it)->bot_left, (*it)->top_right); @@ -105,21 +105,21 @@ void QuadTree::build_tree(int width, int height) // Error checking if (size % QT_LEAF_SIZE != 0) throw runtime_error("Invalid QuadTree dimensions!"); - + // Allocate memory num_sectors = calc_num_sectors(size); used_sectors = 0; if (sectors) delete[] sectors; sectors = new Sector[num_sectors]; - + // Build the tree build_node(0, 0, 0, 0, size, size); } // Builds a node in the tree int QuadTree::build_node(int an_id, int a_parent, int x1, int y1, int x2, int y2) -{ +{ // Store this sector's data sectors[an_id].id = an_id; sectors[an_id].bot_left.x = x1; @@ -132,10 +132,10 @@ int QuadTree::build_node(int an_id, int a_parent, int x1, int y1, int x2, int y2 sectors[an_id].type = QT_LEAF; else { sectors[an_id].type = QT_BRANCH; - + int w = x2 - x1; int h = y2 - y1; - + // Build children unsigned int* c = sectors[an_id].children; c[0] = build_node(++used_sectors, an_id, x1, y1, x1+w/2, y1+h/2); @@ -151,14 +151,14 @@ int QuadTree::build_node(int an_id, int a_parent, int x1, int y1, int x2, int y2 int QuadTree::calc_num_sectors(int a_width) { int count = 0; - + if (a_width > QT_LEAF_SIZE) { for (int i = 0; i < 4; i++) count += calc_num_sectors(a_width/2); return count + 1; } else - return 1; + return 1; } // Find all the visible sectors @@ -179,8 +179,8 @@ void QuadTree::visible_sectors(IGraphicsPtr a_context, list& a_list, if (bot_left_outside) { // A non-square map return; - } - + } + // See if it's a leaf if (s.type == QT_LEAF) a_list.push_back(&s); @@ -189,10 +189,10 @@ void QuadTree::visible_sectors(IGraphicsPtr a_context, list& a_list, for (int i = 3; i >= 0; i--) { int childID = s.children[i]; Sector* child = §ors[childID]; - + int w = child->top_right.x - child->bot_left.x; int h = child->top_right.y - child->bot_left.y; - + int x = child->bot_left.x + w/2; int y = child->bot_left.y + h/2; @@ -211,7 +211,7 @@ void QuadTree::visible_sectors(IGraphicsPtr a_context, list& a_list, IQuadTreePtr make_quad_tree(ISectorRenderablePtr a_renderer, int width, int height) { - auto_ptr ptr(new QuadTree(a_renderer)); + QuadTree *ptr = new QuadTree(a_renderer); ptr->build_tree(width, height); return IQuadTreePtr(ptr); } diff --git a/src/Resource.cpp b/src/Resource.cpp index 90e6afd..791cc2b 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -34,7 +34,7 @@ public: { } - + // IResource interface string name() const { return my_path.filename().string(); } string xml_file_name() const @@ -60,14 +60,14 @@ IResource::Handle::Handle(const string& file_name, Mode mode) { if (mode == READ) { read_stream = shared_ptr(new ifstream(file_name.c_str())); - + if (!read_stream->good()) throw runtime_error("Failed to open resource file " + file_name); } else if (mode == WRITE) { - const string tmp = tmp_file_name(); + const string tmp = tmp_file_name(); write_stream = shared_ptr(new ofstream(tmp.c_str())); - + if (!write_stream->good()) throw runtime_error("Failed to open resource file " + file_name); } @@ -114,7 +114,7 @@ static ResourceList& res_class_list(const string& a_class) static void add_resource(const string& a_class, IResourcePtr a_res) { - res_class_list(a_class).push_back(a_res); + res_class_list(a_class).push_back(a_res); } static void add_resource_dir(const char* a_class, const path& a_path) @@ -123,10 +123,10 @@ static void add_resource_dir(const char* a_class, const path& a_path) if (!exists(xml_file)) warn() << "Missing resource XML file: " << xml_file; - else + else add_resource(a_class, IResourcePtr(new FilesystemResource(a_path))); } - + static void look_in_dir(const path& a_path) { log() << "Looking for resources in " << a_path; @@ -148,7 +148,7 @@ void init_resources() ostringstream ss; ss << "Found "; - + for (const char **it = classes; *it; ++it) { const ResourceList& lst = res_class_list(*it); @@ -177,7 +177,7 @@ static IResourcePtr maybe_find_resource(const string& a_res_id, if ((*it)->name() == a_res_id) return *it; } - + return IResourcePtr(); } @@ -187,7 +187,7 @@ IResourcePtr find_resource(const string& a_res_id, const string& a_class) IResourcePtr r = maybe_find_resource(a_res_id, a_class); if (r) return r; - else + else throw runtime_error("Failed to find resource " + a_res_id + " in class " + a_class); } @@ -195,7 +195,7 @@ IResourcePtr find_resource(const string& a_res_id, const string& a_class) // True if the given resource exists bool resource_exists(const string& a_res_id, const string& a_class) { - return maybe_find_resource(a_res_id, a_class); + return static_cast(maybe_find_resource(a_res_id, a_class)); } // Create an empty resource directory diff --git a/src/SDLWindow.cpp b/src/SDLWindow.cpp index aa4ed93..58146a4 100644 --- a/src/SDLWindow.cpp +++ b/src/SDLWindow.cpp @@ -33,8 +33,6 @@ #include #include -using namespace boost; - // Concrete implementation of SDL window class SDLWindow : public IWindow, public IGraphics, public IPickBuffer, public enable_shared_from_this { @@ -69,7 +67,7 @@ private: void process_input(); MouseButton from_sdl_button(Uint8 aSDLButton) const; void capture_frame() const; - + bool am_running; int width_, height_; IScreenPtr screen; @@ -92,14 +90,14 @@ static Uint32 updateFPS(Uint32 an_interval, void* thread) { the_last_fps = the_frame_counter; the_frame_counter = 0; - + return an_interval; } static void frame_complete() { the_frame_counter++; - + update_render_stats(); } @@ -109,13 +107,13 @@ struct FrameTimerThread { { my_timer = SDL_AddTimer(1000, updateFPS, this); } - + ~FrameTimerThread() { // Finalise properly when an exception is thrown SDL_RemoveTimer(my_timer); } - + SDL_TimerID my_timer; }; @@ -125,7 +123,7 @@ SDLWindow::SDLWindow() will_take_screen_shot(false) { IConfigPtr cfg = get_config(); - + // Start SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { ostringstream ss; @@ -152,7 +150,7 @@ SDLWindow::SDLWindow() // Hide the window manager cursor //SDL_ShowCursor(SDL_DISABLE); - + // Start OpenGL printGLVersion(); initGL(); @@ -163,7 +161,7 @@ SDLWindow::SDLWindow() // Destroy the game window SDLWindow::~SDLWindow() { - + } // Make a screen capture at the end of this frame @@ -185,7 +183,7 @@ void SDLWindow::switch_screen(IScreenPtr a_screen) void SDLWindow::run(IScreenPtr a_screen, int frames) { assert(!am_running); - + screen = a_screen; FrameTimerThread fps_timer; @@ -194,7 +192,7 @@ void SDLWindow::run(IScreenPtr a_screen, int frames) // Wait a few milliseconds to get a reasonable tick delta SDL_Delay(1); - + am_running = true; do { unsigned tick_start = SDL_GetTicks(); @@ -203,7 +201,7 @@ void SDLWindow::run(IScreenPtr a_screen, int frames) try { process_input(); screen->update(shared_from_this(), delta); - + if (!will_skip_next_frame) { drawGLScene(shared_from_this(), shared_from_this(), screen); SDL_GL_SwapBuffers(); @@ -230,7 +228,7 @@ void SDLWindow::run(IScreenPtr a_screen, int frames) last_tick = tick_start; update_render_stats(); } while (am_running); - + screen.reset(); } @@ -269,7 +267,7 @@ void SDLWindow::process_input() quit(); log() << "Window closed"; break; - + case SDL_KEYDOWN: screen->on_key_down(e.key.keysym.sym); break; @@ -286,7 +284,7 @@ void SDLWindow::process_input() have_sent_mouseMotion = true; } break; - + case SDL_MOUSEBUTTONDOWN: screen->on_mouse_click(shared_from_this(), e.button.x, e.button.y, @@ -302,7 +300,7 @@ void SDLWindow::process_input() case SDL_VIDEORESIZE: width_ = e.resize.w; height_ = e.resize.h; - + resizeGLScene(shared_from_this()); break; } @@ -370,9 +368,9 @@ bool SDLWindow::point_in_view_frustum(float x, float y, float z) void SDLWindow::capture_frame() const { static int file_number = 1; - + const string file_name - ("screenshot" + lexical_cast(file_number++) + ".bmp"); + ("screenshot" + boost::lexical_cast(file_number++) + ".bmp"); SDL_Surface* temp = SDL_CreateRGBSurface (SDL_SWSURFACE, width_, height_, 24, @@ -408,5 +406,5 @@ int SDLWindow::get_fps() const // Construct and initialise an OpenGL SDL window IWindowPtr make_sdl_window() { - return std::tr1::shared_ptr(new SDLWindow); + return shared_ptr(new SDLWindow); } diff --git a/src/Texture.cpp b/src/Texture.cpp index c13b59d..082985f 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -27,9 +27,6 @@ #include #include -using namespace std; -using namespace std::tr1; - class Texture : public ITexture { public: Texture(const string &file); @@ -37,14 +34,14 @@ public: GLuint texture() const { return my_texture; } void bind(); - + int width() const { return my_width; } int height() const { return my_height; } - + private: GLuint my_texture; int my_width, my_height; - + static bool is_power_ofTwo(int n); static bool is_texture_sizeSupported(int width, int height, int ncols = 4, GLenum format = GL_RGBA); @@ -54,7 +51,7 @@ private: namespace { map the_texture_cache; } - + ITexturePtr load_texture(const string& a_file_name) { map::iterator it = @@ -66,7 +63,7 @@ ITexturePtr load_texture(const string& a_file_name) ITexturePtr ptr(new Texture(a_file_name)); the_texture_cache[a_file_name] = ptr; return ptr; - } + } } ITexturePtr load_texture(IResourcePtr a_res, const string& a_file_name) @@ -123,7 +120,7 @@ Texture::Texture(const string &file) my_width = surface->w; my_height = surface->h; - + glGenTextures(1, &my_texture); glBindTexture(GL_TEXTURE_2D, my_texture); -- 2.39.2