From e3d7cddd1bbbd472d4052525e3afccc89c7b4749 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 4 Jul 2010 20:51:52 +0100 Subject: [PATCH] Tidy up function naming --- include/IGraphics.hpp | 14 ++++++------- include/IWindow.hpp | 2 +- src/GenTrack.cpp | 10 ++++++++- src/Main.cpp | 2 +- src/QuadTree.cpp | 8 ++++++-- src/SDLWindow.cpp | 48 +++++++++++++++++++++---------------------- 6 files changed, 48 insertions(+), 36 deletions(-) diff --git a/include/IGraphics.hpp b/include/IGraphics.hpp index 9e3a36a..6ea8e3a 100644 --- a/include/IGraphics.hpp +++ b/include/IGraphics.hpp @@ -26,15 +26,15 @@ struct IGraphics { virtual ~IGraphics() {} // Camera - virtual bool cuboid_in_viewFrustum(float x, float y, float z, - float sizeX, float sizeY, float sizeZ) = 0; - virtual bool cube_in_viewFrustum(float x, float y, float z, - float size) = 0; - virtual bool point_in_viewFrustum(float x, float y, float z) = 0; + virtual bool cuboid_in_view_frustum(float x, float y, float z, float sizeX, + float sizeY, float sizeZ) = 0; + virtual bool cube_in_view_frustum(float x, float y, float z, + float size) = 0; + virtual bool point_in_view_frustum(float x, float y, float z) = 0; virtual void set_camera(const Vector& a_pos, - const Vector& a_rotation) = 0; + const Vector& a_rotation) = 0; virtual void look_at(const Vector an_eye_point, - const Vector a_target_point) = 0; + const Vector a_target_point) = 0; }; typedef std::tr1::shared_ptr IGraphicsPtr; diff --git a/include/IWindow.hpp b/include/IWindow.hpp index 3a8d6ab..a939b34 100644 --- a/include/IWindow.hpp +++ b/include/IWindow.hpp @@ -38,6 +38,6 @@ public: typedef shared_ptr IWindowPtr; // Implementors -IWindowPtr makeSDLWindow(); +IWindowPtr make_sdl_window(); #endif diff --git a/src/GenTrack.cpp b/src/GenTrack.cpp index e9dbbf4..a881007 100644 --- a/src/GenTrack.cpp +++ b/src/GenTrack.cpp @@ -144,7 +144,15 @@ void GenTrack::merge(IMeshBufferPtr buf) const buf->merge(rail_buf, off, 0.0f); // Draw the sleepers - for (float i = 0.2f; i < curve.length; i += 0.25f) { + + const float sleeper_sep = 0.25f; + const float sleepers_per_unit = 1.0f / sleeper_sep; + const int n_sleepers = static_cast(curve.length * sleepers_per_unit); + const float spill = curve.length - (n_sleepers * sleeper_sep); + + debug() << "spill=" << spill; + + for (float i = spill / 2.0f; i < curve.length; i += sleeper_sep) { Vector v = curve(i / curve.length); const Vector deriv = curve.deriv(i / curve.length); diff --git a/src/Main.cpp b/src/Main.cpp index 20fc959..77fcad1 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -102,7 +102,7 @@ int main(int argc, char** argv) IConfigPtr cfg = get_config(); - ::window = makeSDLWindow(); + ::window = make_sdl_window(); IScreenPtr screen; if (::action == "edit") { diff --git a/src/QuadTree.cpp b/src/QuadTree.cpp index e34a9f5..efd6d92 100644 --- a/src/QuadTree.cpp +++ b/src/QuadTree.cpp @@ -163,7 +163,7 @@ int QuadTree::calc_num_sectors(int a_width) // Find all the visible sectors void QuadTree::visible_sectors(IGraphicsPtr a_context, list& a_list, - int a_sector) + int a_sector) { if (a_sector >= num_sectors) { ostringstream ss; @@ -196,7 +196,11 @@ void QuadTree::visible_sectors(IGraphicsPtr a_context, list& a_list, int x = child->bot_left.x + w/2; int y = child->bot_left.y + h/2; - if (a_context->cube_in_viewFrustum((float)x, 0.0f, (float)y, (float)w/2)) + if (a_context->cube_in_view_frustum( + static_cast(x), + 0.0f, + static_cast(y), + static_cast(w) / 2.0f)) visible_sectors(a_context, a_list, childID); else kill_count++; diff --git a/src/SDLWindow.cpp b/src/SDLWindow.cpp index 6c4a54b..93e091b 100644 --- a/src/SDLWindow.cpp +++ b/src/SDLWindow.cpp @@ -53,10 +53,10 @@ public: int get_fps() const; // IGraphics interface - bool cuboid_in_viewFrustum(float x, float y, float z, - float sizeX, float sizeY, float sizeZ); - bool cube_in_viewFrustum(float x, float y, float z, float size); - bool point_in_viewFrustum(float x, float y, float z); + bool cuboid_in_view_frustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ); + bool cube_in_view_frustum(float x, float y, float z, float size); + bool point_in_view_frustum(float x, float y, float z); void set_camera(const Vector& a_pos, const Vector& a_rotation); void look_at(const Vector an_eye_point, @@ -67,14 +67,14 @@ public: unsigned end_pick(); private: void process_input(); - MouseButton fromSDLButton(Uint8 aSDLButton) const; + MouseButton from_sdl_button(Uint8 aSDLButton) const; void capture_frame() const; bool am_running; int width_, height_; IScreenPtr screen; - bool will_skip_nextFrame; - bool will_take_screenShot; + bool will_skip_next_frame; + bool will_take_screen_shot; Frustum view_frustum; // Picking data @@ -123,8 +123,8 @@ namespace { // Create the game window SDLWindow::SDLWindow() - : am_running(false), will_skip_nextFrame(false), - will_take_screenShot(false) + : am_running(false), will_skip_next_frame(false), + will_take_screen_shot(false) { IConfigPtr cfg = get_config(); @@ -171,7 +171,7 @@ SDLWindow::~SDLWindow() // Make a screen capture at the end of this frame void SDLWindow::take_screen_shot() { - will_take_screenShot = true; + will_take_screen_shot = true; } // Change the active screen while the game is running @@ -180,7 +180,7 @@ void SDLWindow::switch_screen(IScreenPtr a_screen) assert(am_running); screen = a_screen; - will_skip_nextFrame = true; + will_skip_next_frame = true; } // Run the game until the user quits @@ -206,21 +206,21 @@ void SDLWindow::run(IScreenPtr a_screen) process_input(); screen->update(shared_from_this(), delta); - if (!will_skip_nextFrame) { + if (!will_skip_next_frame) { drawGLScene(shared_from_this(), shared_from_this(), screen); SDL_GL_SwapBuffers(); } else - will_skip_nextFrame = false; + will_skip_next_frame = false; } catch (runtime_error& e) { error() << "Caught exception: " << e.what(); am_running = false; } - if (will_take_screenShot) { + if (will_take_screen_shot) { capture_frame(); - will_take_screenShot = false; + will_take_screen_shot = false; } frame_complete(); @@ -239,9 +239,9 @@ void SDLWindow::quit() } // Convert an SDL button constant to a MouseButton -MouseButton SDLWindow::fromSDLButton(Uint8 aSDLButton) const +MouseButton SDLWindow::from_sdl_button(Uint8 button) const { - switch (aSDLButton) { + switch (button) { case SDL_BUTTON_LEFT: return MOUSE_LEFT; case SDL_BUTTON_MIDDLE: return MOUSE_MIDDLE; case SDL_BUTTON_RIGHT: return MOUSE_RIGHT; @@ -288,13 +288,13 @@ void SDLWindow::process_input() case SDL_MOUSEBUTTONDOWN: screen->on_mouse_click(shared_from_this(), e.button.x, e.button.y, - fromSDLButton(e.button.button)); + from_sdl_button(e.button.button)); break; case SDL_MOUSEBUTTONUP: screen->on_mouse_release(shared_from_this(), e.button.x, e.button.y, - fromSDLButton(e.button.button)); + from_sdl_button(e.button.button)); break; case SDL_VIDEORESIZE: @@ -346,20 +346,20 @@ void SDLWindow::look_at(const Vector an_eye_point, } // Intersect a cuboid with the current view frustum -bool SDLWindow::cuboid_in_viewFrustum(float x, float y, float z, - float sizeX, float sizeY, float sizeZ) +bool SDLWindow::cuboid_in_view_frustum(float x, float y, float z, + float sizeX, float sizeY, float sizeZ) { return view_frustum.cuboid_in_frustum(x, y, z, sizeX, sizeY, sizeZ); } // Intersect a cube with the current view frustum -bool SDLWindow::cube_in_viewFrustum(float x, float y, float z, float size) +bool SDLWindow::cube_in_view_frustum(float x, float y, float z, float size) { return view_frustum.cube_in_frustum(x, y, z, size); } // True if the point is contained within the view frustum -bool SDLWindow::point_in_viewFrustum(float x, float y, float z) +bool SDLWindow::point_in_view_frustum(float x, float y, float z) { return view_frustum.point_in_frustum(x, y, z); } @@ -404,7 +404,7 @@ int SDLWindow::get_fps() const } // Construct and initialise an OpenGL SDL window -IWindowPtr makeSDLWindow() +IWindowPtr make_sdl_window() { return std::tr1::shared_ptr(new SDLWindow); } -- 2.39.2