From ea69a6b12b380780290cda938952e1b583c5d2cc Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 25 Jul 2010 09:51:06 +0100 Subject: [PATCH] Cache bounding polygon in GenTrack --- src/GenTrack.cpp | 16 +++++++--------- src/Map.cpp | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/GenTrack.cpp b/src/GenTrack.cpp index cb9fe43..2193837 100644 --- a/src/GenTrack.cpp +++ b/src/GenTrack.cpp @@ -71,6 +71,7 @@ private: float height; Vector delta; track::Direction entry_dir, exit_dir; + Polygon bounds; typedef tuple, track::Direction, @@ -123,6 +124,8 @@ GenTrack::GenTrack(Vector delta, } else rail_buf = (*it).second; + + bounding_polygon(bounds); } float GenTrack::extend_from_center(track::Direction dir) const @@ -174,18 +177,16 @@ void GenTrack::merge(IMeshBufferPtr buf) const void GenTrack::render() const { - Polygon p; - bounding_polygon(p); - glPushMatrix(); glTranslatef(origin.x, 0.0f, origin.y); glColor3f(0.1f, 0.1f, 0.8f); glBegin(GL_LINE_LOOP); - for (Polygon::const_iterator it = p.begin(); it != p.end(); ++it) { + for (Polygon::const_iterator it = bounds.begin(); + it != bounds.end(); + ++it) glVertex3f((*it).x, 0.1f, (*it).y); - } glEnd(); glPopMatrix(); @@ -287,14 +288,11 @@ void GenTrack::bounding_polygon(Polygon& poly) const void GenTrack::get_covers2(vector >& output) const { - Polygon poly; - bounding_polygon(poly); - for (int x = min(0, delta.x); x <= max(0, delta.x) + 1; x++) { for (int y = min(0, delta.y); y <= max(0, delta.y) + 1; y++) { Point p = make_point(x, y); - if (point_in_polygon(poly, point_cast(p))) + if (point_in_polygon(bounds, point_cast(p))) output.push_back(p + origin); } } diff --git a/src/Map.cpp b/src/Map.cpp index c1edd32..9776804 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -1757,7 +1757,6 @@ void MapLoader::handle_curved_track(const AttributeSet& attrs) #if 1 ITrackSegmentPtr track; const int off = radius - 1; - Vector delta = make_vector(radius - 1, radius - 1, 0); switch (start_angle) { case 0: -- 2.39.2