From db77f7025e3347a6f18f65af68cee7bbb1114daa Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 30 Dec 2011 19:14:03 +0000 Subject: [PATCH] Build fixes --- src/Editor.cpp | 84 ++++++------ src/Map.cpp | 269 +++++++++++++++++++------------------- src/Mesh.cpp | 90 ++++++------- src/Resource.cpp | 24 ++-- src/gui/RenderContext.cpp | 18 ++- 5 files changed, 242 insertions(+), 243 deletions(-) diff --git a/src/Editor.cpp b/src/Editor.cpp index d1dd0f6..e89ec48 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -38,7 +38,7 @@ public: Editor(IMapPtr a_map); Editor(const string& a_map_name); ~Editor(); - + void display(IGraphicsPtr a_context) const; void overlay() const; void update(IPickBufferPtr pick_buffer, int a_delta); @@ -50,7 +50,7 @@ public: MouseButton a_button); void on_mouse_release(IPickBufferPtr pick_buffer, int x, int y, MouseButton a_button); - + // Different tools the user can be using enum Tool { TRACK_TOOL, RAISE_TOOL, LOWER_TOOL, DELETE_TOOL, @@ -61,7 +61,7 @@ public: IMapPtr get_map() { return map; } void set_map(IMapPtr a_map); - + private: void build_gui(); void draw_dragged_track(); @@ -85,9 +85,9 @@ private: void plant_trees(); void save(); bool is_diagonal(const track::Direction& dir) const; - + IMapPtr map; - + ILightPtr my_sun; Vector my_position; @@ -104,31 +104,31 @@ private: IRenderStatsPtr render_stats; }; -Editor::Editor(IMapPtr a_map) +Editor::Editor(IMapPtr a_map) : map(a_map), my_position(4.5f, -17.5f, -21.5f), my_tool(TRACK_TOOL), am_scrolling(false), am_dragging(false), is_shift_down(false) { my_sun = make_sun_light(); - + build_gui(); - + map->set_grid(true); - + log() << "Editing " << a_map->name(); } Editor::~Editor() { - + } void Editor::build_gui() { using namespace placeholders; - + layout = gui::make_layout("layouts/editor.xml"); - + layout->get("/tool_wnd/tools/track").connect(gui::Widget::SIG_CLICK, bind(&Editor::set_tool, this, TRACK_TOOL)); layout->get("/tool_wnd/tools/raise").connect(gui::Widget::SIG_CLICK, @@ -149,10 +149,10 @@ void Editor::build_gui() bind(&Editor::set_tool, this, TREE_TOOL)); layout->get("/tool_wnd/tools/smooth").connect(gui::Widget::SIG_CLICK, bind(&Editor::set_tool, this, SMOOTH_TOOL)); - + layout->get("/lower/action_wnd/save").connect(gui::Widget::SIG_CLICK, bind(&Editor::save, this)); - + building_picker = make_building_picker(layout); tree_picker = make_tree_picker(layout); @@ -178,7 +178,7 @@ void Editor::drag_box_bounds(int& x_min, int& x_max, int &y_min, int& y_max) con x_max = max(drag_begin.x, drag_end.x); y_min = min(drag_begin.y, drag_end.y); - y_max = max(drag_begin.y, drag_end.y); + y_max = max(drag_begin.y, drag_end.y); } void Editor::drag_box_size(int& xlen, int& ylen) const @@ -195,22 +195,22 @@ void Editor::display(IGraphicsPtr a_context) const { if (!map) return; - + a_context->set_camera(my_position, make_vector(45.0f, 45.0f, 0.0f)); - + my_sun->apply(); // Draw the highlight if we are dragging track if (am_dragging) { int xmin, xmax, ymin, ymax; drag_box_bounds(xmin, xmax, ymin, ymax); - + for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) map->highlight_tile(make_point(x, y), colour::WHITE); - } + } } - + map->render(a_context); } @@ -235,7 +235,7 @@ bool Editor::can_connect(const Point& a_first_point, return false; ITrackSegmentPtr track = map->track_at(a_first_point); - + Vector dir = make_vector( a_first_point.x - a_second_point.x, 0, @@ -275,7 +275,7 @@ bool Editor::guess_track_dir(const Point& p, track::Direction& d) const } else return false; - + return true; } @@ -288,7 +288,7 @@ bool Editor::draw_track_tile(Point where, track::Direction axis) axis = axis::X; else if (axis == -axis::Y) axis = axis::Y; - + if (map->is_valid_track(where)) { ITrackSegmentPtr merged = map->track_at(where)->merge_exit(where, axis); if (merged) { @@ -307,13 +307,13 @@ bool Editor::draw_track_tile(Point where, track::Direction axis) bool b_valid, a_valid; const VectorF slope_before = map->slope_before(where, axis, b_valid); const VectorF slope_after = map->slope_after(where, axis, a_valid); - + if (level) { const bool flat = abs(slope.y) < 0.001f && (!b_valid || abs(slope_before.y) < 0.001f) && (!a_valid || abs(slope_after.y) < 0.001); - + if (flat) { map->set_track_at(where, make_straight_track(axis)); return true; @@ -379,7 +379,7 @@ bool Editor::can_place_track(ITrackSegmentPtr track) vector > covered; track->get_endpoints(covered); track->get_covers(covered); - + for (vector >::iterator it = covered.begin(); it != covered.end(); ++it) { if (map->is_valid_track(*it)) { @@ -406,7 +406,7 @@ void Editor::draw_initial_track() int xmin, xmax, ymin, ymax, xlen, ylen; drag_box_bounds(xmin, xmax, ymin, ymax); drag_box_size(xlen, ylen); - + if (xlen == 1) draw_dragged_straight(drag_begin.y > drag_end.y ? -axis::Y : axis::Y, ylen); @@ -440,7 +440,7 @@ void Editor::draw_s_bend(const track::Direction& dir) // The direction of the start is known but not the end void Editor::draw_unconstrained_track(const track::Direction& start_dir) -{ +{ debug() << __func__ << ": drag_begin=" << drag_begin << " drag_end=" << drag_end << " start_dir=" << start_dir; @@ -507,11 +507,11 @@ void Editor::draw_unconstrained_track(const track::Direction& start_dir) } ylen--; } - + draw_curve(start_dir, exit_dir); } else if (could_be_45_curve) { - + track::Direction exit_dir; if (start_dir == axis::X || start_dir == -axis::X) { if (drag_end.y < drag_begin.y) @@ -535,7 +535,7 @@ void Editor::draw_unconstrained_track(const track::Direction& start_dir) } else warn() << "cannot infer track"; - + } // The direction of both endpoints is known @@ -591,7 +591,7 @@ void Editor::draw_dragged_track() for (int y = ymin; y <= ymax; y++) map->erase_tile(x, y); } - + map->set_track_at(drag_end, merged); return; } @@ -607,7 +607,7 @@ void Editor::draw_dragged_track() else { swap(drag_begin, drag_end); draw_unconstrained_track(end_dir); - } + } } else { if (end_was_guess) @@ -616,7 +616,7 @@ void Editor::draw_dragged_track() draw_constrained_track(start_dir, end_dir); } - + #if 0 end_dir = -end_dir; @@ -695,9 +695,9 @@ void Editor::draw_dragged_track() } else { Point delta = drag_end - drag_begin; - + VectorI off = make_vector(delta.x, delta.y, 0); - + ITrackSegmentPtr track = make_spline_track(off, start_dir, end_dir); @@ -733,11 +733,11 @@ void Editor::plant_trees() const float threshold = 0.9f; static Uniform tree_rand(0.0f, 1.0f); - + for (int x = xmin; x <= xmax; x++) { for (int y = ymin; y <= ymax; y++) { const Point p = make_point(x, y); - + if ((is_single_tile || tree_rand() > threshold) && map->empty_tile(p)) map->add_scenery(p, tree_picker->get()); } @@ -771,7 +771,7 @@ void Editor::on_mouse_move(IPickBufferPtr pick_buffer, int x, int y, void Editor::on_mouse_click(IPickBufferPtr pick_buffer, int x, int y, MouseButton a_button) -{ +{ if (a_button == MOUSE_RIGHT) { // Start scrolling am_scrolling = true; @@ -786,11 +786,11 @@ void Editor::on_mouse_click(IPickBufferPtr pick_buffer, int x, int y, display(pick_context); int id = pick_buffer->end_pick(); map->set_pick_mode(false); - + if (id > 0) { // Begin dragging a selection rectangle Point where = map->pick_position(id); - + drag_begin = drag_end = where; am_dragging = true; } @@ -841,7 +841,7 @@ void Editor::on_mouse_release(IPickBufferPtr pick_buffer, int x, int y, map->smooth_area(drag_begin, drag_end); break; } - + am_dragging = false; } else if (am_scrolling) { diff --git a/src/Map.cpp b/src/Map.cpp index 5792046..7a9dad8 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; @@ -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,13 @@ 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 +564,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 +576,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,7 +594,7 @@ 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]; list >::iterator it = dirty_tiles.begin(); @@ -605,7 +604,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 +612,7 @@ bool Map::have_mesh(int id, Point bot_left, Point top_right) else ++it; } - + return ok; } @@ -654,12 +653,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 +675,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 +688,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 +719,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 +747,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 +759,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 +772,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 +798,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 +816,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 +825,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 +841,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 +855,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 +879,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 +891,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 +921,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,8 +943,10 @@ 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(); - } + } } + + assert(glGetError() == GL_NO_ERROR); } // Render the semi-transparent overlays such as water @@ -963,7 +964,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 +997,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 +1013,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 +1037,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 +1050,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 +1078,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 +1090,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 +1124,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 +1133,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 +1162,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 +1194,7 @@ Vector Map::slope_at(Point where, << " v1=" << v1 << " v2=" << v2 << " level=" << level; #endif - + return v1; } @@ -1206,13 +1207,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 +1231,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 +1255,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 +1277,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 +1318,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 +1331,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 +1370,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 +1414,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 +1422,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 +1430,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 +1451,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 +1474,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 +1498,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 +1530,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 +1540,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 +1556,7 @@ void Map::save_to(ostream& of) } } } - + // Generate the height map write_height_map(); @@ -1605,7 +1606,7 @@ void Map::save_to(ostream& of) } root.add_child(tileset); - + of << xml::document(root); } @@ -1615,7 +1616,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 +1633,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 +1650,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 +1664,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 +1707,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 +1737,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 +1748,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 +1756,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 +1793,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 +1814,7 @@ void MapLoader::handle_points(const AttributeSet& attrs) { string align; attrs.get("align", align); - + bool reflect; attrs.get("reflect", reflect); @@ -1821,7 +1822,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 +1841,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 +1851,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 +1860,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/Mesh.cpp b/src/Mesh.cpp index cf2fc61..5e18176 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -52,9 +52,9 @@ struct MeshBuffer : IMeshBuffer { }; typedef shared_ptr ChunkPtr; - size_t vertex_count() const; + size_t vertex_count() const; size_t index_count() const; - + void add(const Vertex& vertex, const Normal& normal, const Colour& colour, @@ -65,14 +65,14 @@ struct MeshBuffer : IMeshBuffer { void add_quad(Vertex a, Vertex b, Vertex c, Vertex d, Normal na, Normal nb, Normal nc, Normal nd, Colour colour); - + void bind(ITexturePtr texture); void merge(IMeshBufferPtr other, Vector off, float y_angle); - + void print_stats() const; ChunkPtr find_chunk(ITexturePtr tex) const; - + static MeshBuffer* get(IMeshBufferPtr a_ptr) { return polymorphic_cast(a_ptr.get()); @@ -80,14 +80,14 @@ struct MeshBuffer : IMeshBuffer { vector chunks; ChunkPtr active_chunk; - + int reused; }; MeshBuffer::MeshBuffer() : reused(0) { - + } void MeshBuffer::bind(ITexturePtr tex) @@ -99,7 +99,7 @@ void MeshBuffer::bind(ITexturePtr tex) return; } } - + // Must create new chunk for this texture active_chunk = ChunkPtr(new Chunk); active_chunk->texture = tex; @@ -110,7 +110,7 @@ void MeshBuffer::bind(ITexturePtr tex) size_t MeshBuffer::vertex_count() const { size_t sum = 0; - + for (vector::const_iterator it = chunks.begin(); it != chunks.end(); ++it) sum += (*it)->vertices.size(); @@ -121,7 +121,7 @@ size_t MeshBuffer::vertex_count() const size_t MeshBuffer::index_count() const { size_t sum = 0; - + for (vector::const_iterator it = chunks.begin(); it != chunks.end(); ++it) sum += (*it)->indices.size(); @@ -151,10 +151,10 @@ void MeshBuffer::merge(IMeshBufferPtr other, Vector off, float y_angle) if (!target_chunk) { target_chunk = ChunkPtr(new Chunk); target_chunk->texture = (*it)->texture; - + chunks.push_back(target_chunk); } - + const size_t ibase = target_chunk->vertices.size(); const Matrix translate = @@ -163,11 +163,11 @@ void MeshBuffer::merge(IMeshBufferPtr other, Vector off, float y_angle) Matrix::rotation(y_angle, 0.0f, 1.0f, 0.0f); const Matrix compose = translate * rotate; - + for (size_t i = 0; i < (*it)->vertices.size(); i++) { const Vertex& v = (*it)->vertices[i]; const Normal& n = (*it)->normals[i]; - + target_chunk->vertices.push_back(compose.transform(v)); target_chunk->normals.push_back(rotate.transform(n).normalise()); @@ -181,10 +181,10 @@ void MeshBuffer::merge(IMeshBufferPtr other, Vector off, float y_angle) for (size_t i = 0; i < (*it)->indices.size(); i++) { Index orig = (*it)->indices[i]; Index merged = orig + ibase; - + assert(orig < (*it)->vertices.size()); assert(merged < target_chunk->vertices.size()); - + target_chunk->indices.push_back(merged); } } @@ -208,7 +208,7 @@ void MeshBuffer::add(const Vertex& vertex, // Create an initial chunk for the null texture bind(ITexturePtr()); } - + // See if this vertex has already been added for (vector::iterator it = active_chunk->indices.begin(); it != active_chunk->indices.end(); ++it) { @@ -231,7 +231,7 @@ void MeshBuffer::add(const Vertex& vertex, } } } - + const size_t index = active_chunk->vertices.size(); active_chunk->vertices.push_back(vertex); active_chunk->normals.push_back(normal); @@ -247,7 +247,7 @@ void MeshBuffer::add_quad(Vertex a, Vertex b, Vertex c, Vector n2 = surface_normal(d, a, b); const TexCoord nulltc = make_point(0.0f, 0.0f); - + add(b, n1, colour, nulltc); add(c, n1, colour, nulltc); add(d, n1, colour, nulltc); @@ -262,7 +262,7 @@ void MeshBuffer::add_quad(Vertex a, Vertex b, Vertex c, Vertex d, Colour colour) { const TexCoord nulltc = make_point(0.0f, 0.0f); - + add(b, na, colour, nulltc); add(c, nb, colour, nulltc); add(d, nc, colour, nulltc); @@ -287,26 +287,26 @@ BOOST_STATIC_ASSERT(sizeof(VertexData) == 64); static void copy_vertex_data(const MeshBuffer* buf, VertexData* vertex_data) { size_t offset = 0; - + for (vector::const_iterator it = buf->chunks.begin(); it != buf->chunks.end(); ++it) { - + for (size_t i = 0; i < (*it)->vertices.size(); i++) { VertexData* vd = &vertex_data[offset + i]; - + vd->x = (*it)->vertices[i].x; vd->y = (*it)->vertices[i].y; vd->z = (*it)->vertices[i].z; - + vd->nx = (*it)->normals[i].x; vd->ny = (*it)->normals[i].y; vd->nz = (*it)->normals[i].z; - + if ((*it)->texture) { vd->tx = (*it)->tex_coords[i].x; vd->ty = 1.0f - (*it)->tex_coords[i].y; } - + vd->r = (*it)->colours[i].r; vd->g = (*it)->colours[i].g; vd->b = (*it)->colours[i].b; @@ -331,7 +331,7 @@ static void copy_index_data(const MeshBuffer *buf, GLushort offset = 0; vector::const_iterator chunk_it; - + for (chunk_it = buf->chunks.begin(); chunk_it != buf->chunks.end(); ++chunk_it) { @@ -352,7 +352,7 @@ static void copy_index_data(const MeshBuffer *buf, offset += (*chunk_it)->vertices.size(); delim.max = offset - 1; - + delims.push_back(delim); } } @@ -379,7 +379,7 @@ VertexArrayMesh::VertexArrayMesh(IMeshBufferPtr a_buffer) my_index_count = buf->index_count(); my_indices = new GLushort[my_index_count]; - + my_vertex_count = buf->vertex_count(); my_vertex_data = new VertexData[my_vertex_count]; @@ -407,31 +407,31 @@ void VertexArrayMesh::render() const glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexData), reinterpret_cast(&my_vertex_data->tx)); - + glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, sizeof(VertexData), reinterpret_cast(&my_vertex_data->r)); - + glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(VertexData), reinterpret_cast(my_vertex_data)); glNormalPointer(GL_FLOAT, sizeof(VertexData), reinterpret_cast(&my_vertex_data->nx)); - + glEnable(GL_COLOR_MATERIAL); - + for (vector::const_iterator it = chunks.begin(); it != chunks.end(); ++it) { - + if ((*it).texture) { glEnable(GL_TEXTURE_2D); (*it).texture->bind(); - + } else { glDisable(GL_TEXTURE_2D); - } + } glDrawRangeElements(GL_TRIANGLES, (*it).min, @@ -440,7 +440,7 @@ void VertexArrayMesh::render() const GL_UNSIGNED_SHORT, my_indices + (*it).offset); } - + glPopClientAttrib(); glPopAttrib(); } @@ -468,7 +468,7 @@ VBOMesh::VBOMesh(IMeshBufferPtr a_buffer) copy_vertex_data(buf, p_vertex_data); - // Generate the VBO + // Generate the VBO glGenBuffersARB(1, &vbo_buf); glBindBufferARB(GL_ARRAY_BUFFER, vbo_buf); glBufferDataARB(GL_ARRAY_BUFFER, vertex_count * sizeof(VertexData), @@ -483,7 +483,7 @@ VBOMesh::VBOMesh(IMeshBufferPtr a_buffer) GLushort* p_indices = new GLushort[index_count]; copy_index_data(buf, chunks, p_indices); - + // Build the index buffer glGenBuffersARB(1, &index_buf); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, index_buf); @@ -494,7 +494,7 @@ VBOMesh::VBOMesh(IMeshBufferPtr a_buffer) glBindBufferARB(GL_ARRAY_BUFFER, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0); - + delete[] p_vertex_data; delete[] p_indices; } @@ -521,7 +521,7 @@ void VBOMesh::render() const if (glIsEnabled(GL_BLEND)) glDisable(GL_BLEND); - + glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3, GL_FLOAT, sizeof(VertexData), reinterpret_cast(offsetof(VertexData, r))); @@ -534,14 +534,14 @@ void VBOMesh::render() const reinterpret_cast(offsetof(VertexData, nx))); glVertexPointer(3, GL_FLOAT, sizeof(VertexData), reinterpret_cast(0)); - + glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(VertexData), reinterpret_cast(offsetof(VertexData, tx))); for (vector::const_iterator it = chunks.begin(); it != chunks.end(); ++it) { - + if ((*it).texture) { glEnable(GL_TEXTURE_2D); (*it).texture->bind(); @@ -551,7 +551,7 @@ void VBOMesh::render() const } const size_t offset_ptr = (*it).offset * sizeof(GLushort); - + glDrawRangeElements(GL_TRIANGLES, (*it).min, (*it).max, @@ -569,7 +569,7 @@ void VBOMesh::render() const IMeshPtr make_mesh(IMeshBufferPtr buffer) { //buffer->print_stats(); - + // Prefer VBOs for all meshes if (GLEW_ARB_vertex_buffer_object) return IMeshPtr(new VBOMesh(buffer)); diff --git a/src/Resource.cpp b/src/Resource.cpp index 90e6afd..cdf632f 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -34,9 +34,9 @@ public: { } - + // IResource interface - string name() const { return my_path.filename().string(); } + string name() const { return my_path.filename(); } string xml_file_name() const { return (my_path / (name() + ".xml")).string(); @@ -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,19 +114,19 @@ 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) { - const path xml_file = a_path / (a_path.filename().string() + ".xml"); + const path xml_file = a_path / (a_path.filename() + ".xml"); 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); } diff --git a/src/gui/RenderContext.cpp b/src/gui/RenderContext.cpp index 0a71afb..75c6d6a 100644 --- a/src/gui/RenderContext.cpp +++ b/src/gui/RenderContext.cpp @@ -41,7 +41,7 @@ RenderContext::~RenderContext() glPopAttrib(); assert(origin_stack.empty()); - + IWindowPtr wnd = get_game_window(); glScissor(0, 0, wnd->width(), wnd->height()); } @@ -56,7 +56,7 @@ void RenderContext::push_origin(const Widget* w) void RenderContext::pop_origin() { assert(!origin_stack.empty()); - + const Widget* top = origin_stack.top(); origin_x -= top->x() + top->border(); origin_y -= top->y() + top->border(); @@ -73,22 +73,20 @@ void RenderContext::rectangle(int x, int y, int w, int h, Colour c) { offset(x, y); gl::colour(c); - + glBegin(GL_QUADS); glVertex2i(x, y); glVertex2i(x + w, y); glVertex2i(x + w, y + h); glVertex2i(x, y + h); glEnd(); - - assert(glGetError() == GL_NO_ERROR); } void RenderContext::border(int x, int y, int w, int h, Colour c) { offset(x, y); gl::colour(c); - + glBegin(GL_LINE_LOOP); glVertex2f(x + 0.1f, y + 0.1f); glVertex2f(x + w - 0.1f, y + 0.1f); @@ -104,7 +102,7 @@ void RenderContext::image(int x, int y, int w, int h, ITexturePtr tex) offset(x, y); - tex->bind(); + tex->bind(); glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); @@ -117,7 +115,7 @@ void RenderContext::image(int x, int y, int w, int h, ITexturePtr tex) glTexCoord2i(0, 1); glVertex2i(x, y + h); glEnd(); - + glPopAttrib(); } @@ -140,7 +138,7 @@ void RenderContext::scissor(Widget* w) } else max_w = max_h = 100000; - + int x = w->x() - 1; int y = w->y() - 1; offset(x, y); @@ -149,7 +147,7 @@ void RenderContext::scissor(Widget* w) x = max(x, 0); y = max(y, 0); - + int width = min(w->width() + 1, max_w); int height = min(w->height(), max_h); -- 2.39.2