From c013fcea61d37591e6d329dc008570fa318c8d5c Mon Sep 17 00:00:00 2001 From: Deve Date: Tue, 6 Dec 2016 23:13:10 +0100 Subject: [PATCH 01/17] Allow to log messages to file on android --- src/utils/log.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/utils/log.cpp b/src/utils/log.cpp index f77f0bcfc..e5d39167e 100644 --- a/src/utils/log.cpp +++ b/src/utils/log.cpp @@ -140,11 +140,11 @@ void Log::printMessage(int level, const char *component, const char *format, android_LogPriority alp; switch (level) { - // STK is using the levels slightly different from android - // (debug lowest, verbose above it; while android reverses - // this order. So to get the same behaviour (e.g. filter - // out debug message, but still get verbose, we swap - // the order here. + // STK is using the levels slightly different from android + // (debug lowest, verbose above it; while android reverses + // this order. So to get the same behaviour (e.g. filter + // out debug message, but still get verbose, we swap + // the order here. case LL_VERBOSE: alp = ANDROID_LOG_DEBUG; break; case LL_DEBUG: alp = ANDROID_LOG_VERBOSE; break; case LL_INFO: alp = ANDROID_LOG_INFO; break; @@ -153,8 +153,8 @@ void Log::printMessage(int level, const char *component, const char *format, case LL_FATAL: alp = ANDROID_LOG_FATAL; break; default: alp = ANDROID_LOG_FATAL; } - __android_log_vprint(alp, "SuperTuxKart", format, args); -#else +#endif + static const char *names[] = {"debug", "verbose ", "info ", "warn ", "error ", "fatal "}; @@ -178,8 +178,12 @@ void Log::printMessage(int level, const char *component, const char *format, va_copy(out, args); setTerminalColor((LogLevel)level); + #ifdef ANDROID + __android_log_vprint(alp, "SuperTuxKart", format, out); + #else printf("[%s] %s: ", names[level], component); vprintf(format, out); + #endif resetTerminalColor(); // this prints a \n va_end(out); @@ -225,8 +229,6 @@ void Log::printMessage(int level, const char *component, const char *format, MessageBoxA(NULL, message.c_str(), "SuperTuxKart - Fatal error", MB_OK); } #endif - -#endif } // printMessage From 5fad8a135edf8d8b85b56940d4558f10c67ef10a Mon Sep 17 00:00:00 2001 From: Deve Date: Tue, 6 Dec 2016 23:23:12 +0100 Subject: [PATCH 02/17] Destroy egl context on exit --- .../source/Irrlicht/COGLES2Driver.cpp | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp index 58f98b85e..d57f564f8 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp @@ -341,11 +341,25 @@ namespace video delete BridgeCalls; #if defined(EGL_VERSION_1_0) - // HACK : the following is commented because destroying the context crashes under Linux (Thibault 04-feb-10) - /*eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglDestroyContext(EglDisplay, EglContext); - eglDestroySurface(EglDisplay, EglSurface);*/ - eglTerminate(EglDisplay); + eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + if (EglContext != EGL_NO_CONTEXT) + { + eglDestroyContext(EglDisplay, EglContext); + EglContext = EGL_NO_CONTEXT; + } + + if (EglSurface != EGL_NO_SURFACE) + { + eglDestroySurface(EglDisplay, EglSurface); + EglSurface = EGL_NO_SURFACE; + } + + if (EglDisplay != EGL_NO_DISPLAY) + { + eglTerminate(EglDisplay); + EglDisplay = EGL_NO_DISPLAY; + } #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) if (HDc) From 66f57ada613177ef05e467f40d9b6e8f032a9665 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 7 Dec 2016 00:07:22 +0100 Subject: [PATCH 03/17] Fixed a crash when GLES device is re-created --- lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp index d57f564f8..501152864 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp @@ -341,7 +341,7 @@ namespace video delete BridgeCalls; #if defined(EGL_VERSION_1_0) - eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (EglContext != EGL_NO_CONTEXT) { From fed12f774c646a949df1dc84fed9962d1f5bcce2 Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 8 Dec 2016 09:46:44 +1100 Subject: [PATCH 04/17] Fixed potential deadlock, made debug output more useful. --- src/network/protocols/server_lobby.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 103adc26a..144ba5e5b 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -217,8 +217,8 @@ void ServerLobby::update(float dt) signalRaceStartToClients(); m_server_delay = 0.02f; m_client_ready_count.getData() = 0; - m_client_ready_count.unlock(); } + m_client_ready_count.unlock(); // Initialise counter again, to wait for all clients to indicate that // they have started the race/ break; @@ -887,11 +887,11 @@ void ServerLobby::finishedLoadingWorldClient(Event *event) m_client_ready_count.unlock(); return; } - Log::info("ServerLobbyeProtocol", "Player %d is ready (%d/%d).", - player_id, m_client_ready_count.getData(), - m_game_setup->getPlayerCount() ); m_player_states[player_id] = true; m_client_ready_count.getData()++; + Log::info("ServerLobbyeProtocol", "Player %d is ready (%d/%d).", + player_id, m_client_ready_count.getData(), + m_game_setup->getPlayerCount()); } m_client_ready_count.unlock(); From 22092e645951b914681a1e5a3f6af0b45411b923 Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 9 Dec 2016 17:14:04 +1100 Subject: [PATCH 05/17] Moved background/clear color from world to irr_driver. --- src/graphics/fixed_pipeline_renderer.cpp | 2 +- src/graphics/irr_driver.cpp | 3 ++- src/graphics/irr_driver.hpp | 13 +++++++++++++ src/graphics/shader_based_renderer.cpp | 4 ++-- src/modes/world.cpp | 2 +- src/modes/world.hpp | 10 ---------- src/tracks/graph.cpp | 7 +++---- src/tracks/track.cpp | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/graphics/fixed_pipeline_renderer.cpp b/src/graphics/fixed_pipeline_renderer.cpp index 1910db80f..99d68787c 100644 --- a/src/graphics/fixed_pipeline_renderer.cpp +++ b/src/graphics/fixed_pipeline_renderer.cpp @@ -43,7 +43,7 @@ void FixedPipelineRenderer::render(float dt) irr_driver->getVideoDriver()->beginScene(/*backBuffer clear*/ true, /*zBuffer*/ true, - world->getClearColor()); + irr_driver->getClearColor()); irr_driver->getVideoDriver()->enableMaterial2D(); diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 831f7c898..63c0aa900 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -140,8 +140,9 @@ IrrDriver::IrrDriver() m_mipviz = m_wireframe = m_normals = m_ssaoviz = false; m_lightviz = m_shadowviz = m_distortviz = m_rsm = m_rh = m_gi = false; - m_boundingboxesviz = false; + m_boundingboxesviz = false; m_last_light_bucket_distance = 0; + m_clear_color = video::SColor(255, 100, 101, 140); } // IrrDriver // ---------------------------------------------------------------------------- diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 11bb3a6dd..56cf70c97 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -172,6 +172,10 @@ private: bool m_distortviz; bool m_boundingboxesviz; + /** Background colour to reset a buffer. Can be changed by each track. */ + irr::video::SColor m_clear_color; + + unsigned m_last_light_bucket_distance; u32 m_renderpass; class STKMeshSceneNode *m_sun_interposer; @@ -307,6 +311,15 @@ public: std::unique_ptr createRenderTarget(const irr::core::dimension2du &dimension, const std::string &name); #endif + // ------------------------------------------------------------------------ + /** Returns the color to clear the back buffer. */ + const irr::video::SColor& getClearColor() const { return m_clear_color; } + // ------------------------------------------------------------------------ + /** Sets the color to use when clearing the back buffer. */ + void setClearbackBufferColor(irr::video::SColor color) + { + m_clear_color = color; + } // setClearbackBufferColor // ------------------------------------------------------------------------ /** Convenience function that loads a texture with default parameters diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index be5ccf605..742b4df14 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -168,7 +168,7 @@ void ShaderBasedRenderer::prepareForwardRenderer() { irr::video::SColor clearColor(0, 150, 150, 150); if (World::getWorld() != NULL) - clearColor = World::getWorld()->getClearColor(); + clearColor = irr_driver->getClearColor(); glClear(GL_COLOR_BUFFER_BIT); glDepthMask(GL_TRUE); @@ -408,7 +408,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, m_rtts->getFBO(FBO_COLORS).bind(); video::SColor clearColor(0, 150, 150, 150); if (World::getWorld() != NULL) - clearColor = World::getWorld()->getClearColor(); + clearColor = irr_driver->getClearColor(); glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f, clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f); diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 293a060f2..6b5f2cf29 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -114,7 +114,7 @@ World* World::m_world = NULL; * after the constructor. Those functions must be called in the init() * function, which is called immediately after the constructor. */ -World::World() : WorldStatus(), m_clear_color(255,100,101,140) +World::World() : WorldStatus() { #ifdef DEBUG diff --git a/src/modes/world.hpp b/src/modes/world.hpp index fedeb4e79..313cb8ad2 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -141,8 +141,6 @@ protected: there are scene nodes). */ RaceGUIBase *m_saved_race_gui; - irr::video::SColor m_clear_color; - /** Pausing/unpausing are not done immediately, but at next udpdate. The * use of this is when switching between screens : if we leave a screen * that paused the game, only to go to another screen that pauses back @@ -339,14 +337,6 @@ public: /** \return whether this world can generate/have highscores */ bool useHighScores() const { return m_use_highscores; } // ------------------------------------------------------------------------ - /** Returns the color to clear the back buffer. */ - const irr::video::SColor& getClearColor() const { return m_clear_color; } - // ------------------------------------------------------------------------ - /** Sets the color to use when clearing the back buffer. */ - void setClearbackBufferColor(irr::video::SColor color) - { - m_clear_color = color; - } /** Override track fog value to force disabled */ void forceFogDisabled(bool v) { m_force_disable_fog = v; } // ------------------------------------------------------------------------ diff --git a/src/tracks/graph.cpp b/src/tracks/graph.cpp index 5e4c36af2..2fec46183 100644 --- a/src/tracks/graph.cpp +++ b/src/tracks/graph.cpp @@ -243,9 +243,8 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, // Skip minimap when profiling if (ProfileWorld::isNoGraphics()) return NULL; - const video::SColor oldClearColor = World::getWorld()->getClearColor(); - World::getWorld() - ->setClearbackBufferColor(video::SColor(0, 255, 255, 255)); + const video::SColor oldClearColor = irr_driver->getClearColor(); + irr_driver->setClearbackBufferColor(video::SColor(0, 255, 255, 255)); World::getWorld()->forceFogDisabled(true); #ifndef SERVER_ONLY m_render_target = irr_driver->createRenderTarget(dimension, name); @@ -330,7 +329,7 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, cleanupDebugMesh(); irr_driver->removeCameraSceneNode(camera); - World::getWorld()->setClearbackBufferColor(oldClearColor); + irr_driver->setClearbackBufferColor(oldClearColor); World::getWorld()->forceFogDisabled(false); irr_driver->getSceneManager()->clear(); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index ef0bed24f..76d1f65ab 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1823,7 +1823,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) } else if(m_sky_type==SKY_COLOR) { - World::getWorld()->setClearbackBufferColor(m_sky_color); + irr_driver->setClearbackBufferColor(m_sky_color); } #ifdef USE_RESIZE_CACHE From ae0b1136f533ce63cdb2835da2bc0d16768a95ed Mon Sep 17 00:00:00 2001 From: samuncle Date: Fri, 9 Dec 2016 11:38:56 -0500 Subject: [PATCH 06/17] better shader for underwater vegetation --- data/shaders/grass_pass2.frag | 3 ++- data/shaders/instanced_grass_pass2.frag | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data/shaders/grass_pass2.frag b/data/shaders/grass_pass2.frag index 76776c200..b5ebadbd9 100644 --- a/data/shaders/grass_pass2.frag +++ b/data/shaders/grass_pass2.frag @@ -54,6 +54,7 @@ void main(void) float scattering = mix(fPowEdotL, fLdotNBack, .5); float specmap = texture(SpecMap, uv).g; - vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, 0.); + float emitmap = texture(SpecMap, uv).b; + vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, emitmap); FragColor = vec4(LightFactor, 1.); } diff --git a/data/shaders/instanced_grass_pass2.frag b/data/shaders/instanced_grass_pass2.frag index bcce07ad3..4d69593f0 100644 --- a/data/shaders/instanced_grass_pass2.frag +++ b/data/shaders/instanced_grass_pass2.frag @@ -25,6 +25,7 @@ void main(void) #ifdef Use_Bindless_Texture vec4 color = texture(handle, uv); float specmap = texture(secondhandle, uv).g; + float emitmap = texture(secondhandle, uv).b; float mask = texture(thirdhandle, uv).a; #ifdef SRGBBindlessFix color.xyz = pow(color.xyz, vec3(2.2)); @@ -32,6 +33,7 @@ void main(void) #else vec4 color = texture(Albedo, uv); float specmap = texture(SpecMap, uv).g; + float emitmap = texture(SpecMap, uv).b; float mask = texture(colorization_mask, uv).a; #endif if (color.a < 0.5) discard; @@ -59,7 +61,8 @@ void main(void) float fLdotNBack = max(0., - dot(nor, L) * 0.6 + 0.4); float scattering = mix(fPowEdotL, fLdotNBack, .5); + + vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, emitmap); - vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, 0.); FragColor = vec4(LightFactor, 1.); } From 8785ddf1484f09a86d5dfda309e77ab4cb930294 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 12 Dec 2016 08:05:07 +1100 Subject: [PATCH 07/17] Moved force-fog settings into track. --- src/graphics/draw_calls.cpp | 3 ++- src/graphics/geometry_passes.cpp | 4 +++- src/graphics/shader_based_renderer.cpp | 7 +++---- src/graphics/stk_mesh_scene_node.cpp | 3 ++- src/modes/world.cpp | 7 ------- src/modes/world.hpp | 6 ------ src/tracks/graph.cpp | 5 +++-- src/tracks/track.cpp | 5 +++-- src/tracks/track.hpp | 16 +++++++++++++++- 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index de7411572..36b1cb8c9 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -196,7 +196,8 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, } // Transparent - if (World::getWorld() && World::getWorld()->isFogEnabled()) + const World *world = World::getWorld(); + if (world && world->getTrack()->isFogEnabled()) { const Track * const track = World::getWorld()->getTrack(); diff --git a/src/graphics/geometry_passes.cpp b/src/graphics/geometry_passes.cpp index f9fb65400..a30bbac03 100644 --- a/src/graphics/geometry_passes.cpp +++ b/src/graphics/geometry_passes.cpp @@ -25,6 +25,7 @@ #include "graphics/rtts.hpp" #include "graphics/shaders.hpp" #include "modes/world.hpp" +#include "tracks/track.hpp" #include "utils/tuple.hpp" #include #include @@ -260,7 +261,8 @@ void AbstractGeometryPasses::renderTransparent(const DrawCalls& draw_calls, if (CVS->isARBBaseInstanceUsable()) glBindVertexArray(VAOManager::getInstance()->getVAO(video::EVT_STANDARD)); - if (World::getWorld() && World::getWorld()->isFogEnabled()) + const World *world = World::getWorld(); + if (world && world->getTrack()->isFogEnabled()) { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); renderTransparenPassisDefferedEnabled() && World::getWorld() != NULL && - World::getWorld()->isFogEnabled()) + const World *world = World::getWorld(); + if (CVS->isDefferedEnabled() && world && world->getTrack()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- Ambient scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_FOG)); @@ -446,8 +446,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, } // Render discrete lights scattering - if (CVS->isDefferedEnabled() && World::getWorld() != NULL && - World::getWorld()->isFogEnabled()) + if (CVS->isDefferedEnabled() && world && world->getTrack()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- PointLight Scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_FOG)); diff --git a/src/graphics/stk_mesh_scene_node.cpp b/src/graphics/stk_mesh_scene_node.cpp index 92a0a6cc8..028ffe18d 100644 --- a/src/graphics/stk_mesh_scene_node.cpp +++ b/src/graphics/stk_mesh_scene_node.cpp @@ -512,7 +512,8 @@ void STKMeshSceneNode::render() else glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - if (World::getWorld() && World::getWorld()->isFogEnabled()) + const World* world = World::getWorld(); + if (world && world->getTrack()->isFogEnabled()) { Shaders::TransparentFogShader::getInstance()->use(); for (unsigned i = 0; i < GLmeshes.size(); i++) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 6b5f2cf29..e68a9f394 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -133,7 +133,6 @@ World::World() : WorldStatus() m_schedule_tutorial = false; m_is_network_world = false; m_weather = NULL; - m_force_disable_fog = false; m_stop_music_when_dialog_open = true; @@ -1291,12 +1290,6 @@ void World::escapePressed() new RacePausedDialog(0.8f, 0.6f); } // escapePressed -//----------------------------------------------------------------------------- -bool World::isFogEnabled() const -{ - return !m_force_disable_fog && (m_track != NULL && m_track->isFogEnabled()); -} // isFogEnabled - // ---------------------------------------------------------------------------- /** Returns the start transform with the give index. * \param rescue_pos Index of the start position to be returned. diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 313cb8ad2..d10a43113 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -97,7 +97,6 @@ protected: RandomGenerator m_random; Physics* m_physics; - bool m_force_disable_fog; AbstractKart* m_fastest_kart; /** Number of eliminated karts. */ int m_eliminated_karts; @@ -324,8 +323,6 @@ public: /** Returns a pointer to the Scripting Engine. */ Scripting::ScriptEngine *getScriptEngine() const { return m_script_engine; } - //------------------------------------------------------------------------- - bool isFogEnabled() const; // ------------------------------------------------------------------------ void moveKartTo(AbstractKart* kart, const btTransform &t); // ------------------------------------------------------------------------ @@ -337,9 +334,6 @@ public: /** \return whether this world can generate/have highscores */ bool useHighScores() const { return m_use_highscores; } // ------------------------------------------------------------------------ - /** Override track fog value to force disabled */ - void forceFogDisabled(bool v) { m_force_disable_fog = v; } - // ------------------------------------------------------------------------ /** Override if you want to know when a kart presses fire */ virtual void onFirePressed(Controller* who) {} // ------------------------------------------------------------------------ diff --git a/src/tracks/graph.cpp b/src/tracks/graph.cpp index 2fec46183..d4953e60f 100644 --- a/src/tracks/graph.cpp +++ b/src/tracks/graph.cpp @@ -28,6 +28,7 @@ #include "tracks/arena_node_3d.hpp" #include "tracks/drive_node_2d.hpp" #include "tracks/drive_node_3d.hpp" +#include "tracks/track.hpp" #include "utils/log.hpp" const int Graph::UNKNOWN_SECTOR = -1; @@ -245,7 +246,7 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, const video::SColor oldClearColor = irr_driver->getClearColor(); irr_driver->setClearbackBufferColor(video::SColor(0, 255, 255, 255)); - World::getWorld()->forceFogDisabled(true); + World::getWorld()->getTrack()->forceFogDisabled(true); #ifndef SERVER_ONLY m_render_target = irr_driver->createRenderTarget(dimension, name); #endif @@ -330,7 +331,7 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, irr_driver->removeCameraSceneNode(camera); irr_driver->setClearbackBufferColor(oldClearColor); - World::getWorld()->forceFogDisabled(false); + World::getWorld()->getTrack()->forceFogDisabled(false); irr_driver->getSceneManager()->clear(); VAOManager::kill(); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 76d1f65ab..8956c56a2 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -145,8 +145,9 @@ Track::Track(const std::string &filename) m_render_target = NULL; m_minimap_x_scale = 1.0f; m_minimap_y_scale = 1.0f; - m_startup_run = false; - m_default_number_of_laps= 3; + m_force_disable_fog = false; + m_startup_run = false; + m_default_number_of_laps = 3; m_all_nodes.clear(); m_static_physics_only_nodes.clear(); m_all_cached_meshes.clear(); diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index ddc04e691..21bd667e5 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -313,7 +313,12 @@ private: /** The name used in sorting the track. */ core::stringw m_sort_name; + /** True if the track uses fog. */ bool m_use_fog; + + /** Can be set to force fog off (e.g. for rendering minimap). */ + bool m_force_disable_fog; + /** True if this track supports using smoothed normals. */ bool m_smooth_normals; @@ -546,7 +551,16 @@ public: // ------------------------------------------------------------------------ ParticleKind* getSkyParticles () { return m_sky_particles; } // ------------------------------------------------------------------------ - bool isFogEnabled() const { return m_use_fog; } + /** Override track fog value to force disabled */ + void forceFogDisabled(bool v) { m_force_disable_fog = v; } + //------------------------------------------------------------------------- + /** Returns if fog is currently enabled. It can be disabled per track, or + * temporary be disabled (e.g. for rendering mini map). */ + bool isFogEnabled() const + { + return !m_force_disable_fog && m_use_fog; + } // isFogEnabled + // ------------------------------------------------------------------------ float getFogStart() const { return m_fog_start; } // ------------------------------------------------------------------------ From 244c812cf3b2d2b133a48cb6e8eaf45aedcc896e Mon Sep 17 00:00:00 2001 From: Daniel Butum Date: Mon, 12 Dec 2016 02:15:37 +0200 Subject: [PATCH 08/17] Add travis server only matrix configuration (#2682) Also increase number of threads for the gcc builds --- .travis.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b52e85b3..e5a58839d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# Travis-CI configuration file for SuperTuxKart +# Travis-CI configuration file for SuperTuxKart # # Configuration manual: # http://docs.travis-ci.com/user/build-configuration/ @@ -14,8 +14,10 @@ matrix: env: matrix: - - BUILD_TYPE="Debug" - - BUILD_TYPE="Release" + - BUILD_TYPE="Debug" SERVER_ONLY="OFF" + - BUILD_TYPE="Debug" SERVER_ONLY="ON" + - BUILD_TYPE="Release" SERVER_ONLY="OFF" + - BUILD_TYPE="Release" SERVER_ONLY="ON" addons: apt: @@ -39,8 +41,9 @@ addons: before_script: # Unfortunately using all threads crashes g++: "g++: internal compiler error: Killed (program cc1plus)" + # Use half of the available threads, gcc is memory hungry - 'if [ ${CC} = "gcc" ]; then - export THREADS=4; + export THREADS=$((`nproc` / 2)); else export THREADS=$((`nproc` + 1)); fi' @@ -50,7 +53,7 @@ before_script: script: - mkdir "build" - cd "build" - - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCHECK_ASSETS=off + - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSERVER_ONLY=$SERVER_ONLY -DCHECK_ASSETS=off - make VERBOSE=1 -j $THREADS notifications: From 62e1a2ddccd8ab3201dfe849018084e639cbdb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96lschlegel?= Date: Mon, 12 Dec 2016 01:16:47 +0100 Subject: [PATCH 09/17] Add a little more BSD detection (#2685) Tested for NetBSD, the same signature has DragonFly(http://fxr.watson.org/fxr/source/sys/endian.h?v=DFBSD#L42) --- lib/irrlicht/source/Irrlicht/os.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/irrlicht/source/Irrlicht/os.cpp b/lib/irrlicht/source/Irrlicht/os.cpp index 5096bf9d0..fd14dda61 100644 --- a/lib/irrlicht/source/Irrlicht/os.cpp +++ b/lib/irrlicht/source/Irrlicht/os.cpp @@ -22,7 +22,7 @@ #include #define bswap_16(X) OSReadSwapInt16(&X,0) #define bswap_32(X) OSReadSwapInt32(&X,0) -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) #include #define bswap_16(X) bswap16(X) #define bswap_32(X) bswap32(X) From aaecd58fc0d1c4c9fb6f241aa342f9adb14025b8 Mon Sep 17 00:00:00 2001 From: Corentin Pazdera Date: Mon, 12 Dec 2016 01:52:15 +0100 Subject: [PATCH 10/17] Adding appveyor config file (#2652) I am unfamiliar with appveyor myself but I can merge the file. Next step would be for someone to take a look at settuping an account --- .appveyor.yml | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 000000000..ac3e4f287 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,57 @@ +environment: + DEPS_DIR: c:\\projects\dependencies + ASSETS_DIR: c:\\projects\stk-assets + APPVEYOR_CACHE_ENTRY_ZIP_ARGS: -t7z -m0=lzma2 -mx=9 + +os: Visual Studio 2015 +clone_depth: 1 +shallow_clone: true + +platform: + - x86 + #- x64 + +configuration: + - Debug + - Release + +matrix: + fast_finish: true + +cache: + - '%DEPS_DIR%' + #- '%ASSETS_DIR%' + +install: + - ps: >- + If(!(Test-Path "$env:DEPS_DIR")) { + Write-Host "Downloading dependencies"; + Start-Process -FilePath "git" -ArgumentList "clone --branch master --single-branch --depth 1 https://github.com/supertuxkart/dependencies.git $env:DEPS_DIR" -Wait; + } + Else { + Write-Host "Updating dependencies"; + Start-Process -FilePath "git" -ArgumentList "fetch --depth 1" -WorkingDirectory "$env:DEPS_DIR" -Wait; + } + Get-ChildItem $env:DEPS_DIR | Measure-Object -property length -sum + #- ps: >- + #If(!(Test-Path "$env:ASSETS_DIR")) { + # Write-Host "Downloading assets"; + # Start-Process -FilePath "svn" -ArgumentList "checkout https://svn.code.sf.net/p/supertuxkart/code/stk-assets $env:ASSETS_DIR" -Wait; + #} + #Else { + # Write-Host "Updating assets"; + # Start-Process -FilePath "svn" -ArgumentList "update" -WorkingDirectory "$env:ASSETS_DIR" -Wait; + #} + #Get-ChildItem $env:ASSETS_DIR | Measure-Object -property length -sum + +before_build: + - ps: Copy-Item "${env:DEPS_DIR}\windows\dependencies" c:\projects\stk-code\dependencies –Recurse + - cmd: | + md build + cd build + if "%platform%"=="x86" set CMAKE_GENERATOR_NAME="Visual Studio 14 2015" + cmake -G %CMAKE_GENERATOR_NAME% -DCMAKE_BUILD_TYPE="%configuration%" .. -DCHECK_ASSETS=OFF + +build: + parallel: true + project: build\ALL_BUILD.vcxproj From ab7ded308a84be73e538271ebed1d6b273e4b9b7 Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Sun, 11 Dec 2016 20:16:44 -0500 Subject: [PATCH 11/17] Make presentation of kart characteristics uniform and indepdendent of difficulty. Fixes #2684, fixes #2539 --- src/guiengine/widgets/kart_stats_widget.cpp | 54 ++++++++++++++------- src/guiengine/widgets/kart_stats_widget.hpp | 3 ++ src/karts/kart_properties.hpp | 4 +- src/states_screens/kart_selection.cpp | 9 +--- 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index de33d5a21..84f347ef8 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -80,23 +80,7 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, m_children.push_back(skill_bar); } - // Scale the values so they look better - // The scaling factor and offset were found by trial and error. - // It should look nice and you should be able to see the difference between - // different masses or velocities. - m_skills[SKILL_MASS]->setValue((int) - ((props->getCombinedCharacteristic()->getMass() - 20) / 4)); - m_skills[SKILL_MASS]->setLabel(_("WEIGHT")); - m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); - - m_skills[SKILL_SPEED]->setValue((int) - ((props->getCombinedCharacteristic()->getEngineMaxSpeed() - 15) * 6)); - m_skills[SKILL_SPEED]->setLabel(_("SPEED")); - m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); - - m_skills[SKILL_POWER]->setValue((int) ((props->getAvgPower() - 30) / 20)); - m_skills[SKILL_POWER]->setLabel(_("POWER")); - m_skills[SKILL_POWER]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_power", m_player_id); + setValues(props); move(area.UpperLeftCorner.X, area.UpperLeftCorner.Y, area.getWidth(), area.getHeight()); @@ -104,6 +88,42 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, // ----------------------------------------------------------------------------- +void KartStatsWidget::setValues(const KartProperties* props) +{ + // Use kart properties computed for "hard" difficulty to show the user, so + // that properties don't change according to the the last used difficulty + // (And because this code uses arbitrary scaling factors to make them look + // nice and the arbitrary factors were optimised for hard difficulty) + RaceManager::Difficulty previous_difficulty = race_manager->getDifficulty(); + race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD); + //KartProperties* kp_computed = new KartProperties(); + KartProperties kp_computed; + kp_computed.copyForPlayer(props); + + // Scale the values so they look better + // The scaling factor and offset were found by trial and error. + // It should look nice and you should be able to see the difference between + // different masses or velocities. + m_skills[SKILL_MASS]->setValue((int) + ((kp_computed.getCombinedCharacteristic()->getMass() - 20) / 4)); + m_skills[SKILL_MASS]->setLabel(_("WEIGHT")); + m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + + m_skills[SKILL_SPEED]->setValue((int) + ((kp_computed.getCombinedCharacteristic()->getEngineMaxSpeed() - 15) * 6)); + m_skills[SKILL_SPEED]->setLabel(_("SPEED")); + m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); + + m_skills[SKILL_POWER]->setValue((int)((kp_computed.getAvgPower() - 30) / 20)); + m_skills[SKILL_POWER]->setLabel(_("POWER")); + m_skills[SKILL_POWER]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_power", m_player_id); + + race_manager->setDifficulty(previous_difficulty); + +} + +// ----------------------------------------------------------------------------- + void KartStatsWidget::add() { for (int i = 0; i < SKILL_COUNT; ++i) { diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp index e78aa4555..ccdc13e57 100644 --- a/src/guiengine/widgets/kart_stats_widget.hpp +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -30,6 +30,7 @@ #include "guiengine/widgets/progress_bar_widget.hpp" #include "guiengine/widgets/skill_level_widget.hpp" +class KartProperties; namespace GUIEngine { @@ -91,6 +92,8 @@ namespace GUIEngine * inside itself */ void setSize(const int x, const int y, const int w, const int h); + void setValues(const KartProperties* props); + /** Change the value of the widget, it must be a percent. */ void setValue(Stats type, int value); diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index 89f916433..c5ca77816 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -544,7 +544,9 @@ public: float getSkidReduceTurnMax() const; bool getSkidEnabled() const; - /* */ + /* */ + + LEAK_CHECK() }; // KartProperties #endif diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index cf53a07be..66e07d977 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -809,15 +809,10 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id, const KartProperties *kp = kart_properties_manager->getKart(selection); + if (kp != NULL) { - // Scale the values so they look better - w->setValue(KartStatsWidget::SKILL_MASS, (int) - ((kp->getCombinedCharacteristic()->getMass() - 20) / 4)); - w->setValue(KartStatsWidget::SKILL_SPEED, (int) - ((kp->getCombinedCharacteristic()->getEngineMaxSpeed() - 15) * 6)); - w->setValue(KartStatsWidget::SKILL_POWER, (int) - ((kp->getAvgPower() - 30) / 20)); + w->setValues(kp); w->update(0); } } From 044e8c52e142a351456d63667c785f43734d5504 Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Sun, 11 Dec 2016 20:19:58 -0500 Subject: [PATCH 12/17] Fix tabs added in previous commit, used spaces instead... --- src/guiengine/widgets/kart_stats_widget.cpp | 58 ++++++++++----------- src/guiengine/widgets/kart_stats_widget.hpp | 2 +- src/karts/kart_properties.hpp | 6 +-- src/states_screens/kart_selection.cpp | 2 +- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/guiengine/widgets/kart_stats_widget.cpp b/src/guiengine/widgets/kart_stats_widget.cpp index 84f347ef8..9860b1fce 100644 --- a/src/guiengine/widgets/kart_stats_widget.cpp +++ b/src/guiengine/widgets/kart_stats_widget.cpp @@ -90,36 +90,34 @@ KartStatsWidget::KartStatsWidget(core::recti area, const int player_id, void KartStatsWidget::setValues(const KartProperties* props) { - // Use kart properties computed for "hard" difficulty to show the user, so - // that properties don't change according to the the last used difficulty - // (And because this code uses arbitrary scaling factors to make them look - // nice and the arbitrary factors were optimised for hard difficulty) - RaceManager::Difficulty previous_difficulty = race_manager->getDifficulty(); - race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD); - //KartProperties* kp_computed = new KartProperties(); - KartProperties kp_computed; - kp_computed.copyForPlayer(props); - - // Scale the values so they look better - // The scaling factor and offset were found by trial and error. - // It should look nice and you should be able to see the difference between - // different masses or velocities. - m_skills[SKILL_MASS]->setValue((int) - ((kp_computed.getCombinedCharacteristic()->getMass() - 20) / 4)); - m_skills[SKILL_MASS]->setLabel(_("WEIGHT")); - m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); - - m_skills[SKILL_SPEED]->setValue((int) - ((kp_computed.getCombinedCharacteristic()->getEngineMaxSpeed() - 15) * 6)); - m_skills[SKILL_SPEED]->setLabel(_("SPEED")); - m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); - - m_skills[SKILL_POWER]->setValue((int)((kp_computed.getAvgPower() - 30) / 20)); - m_skills[SKILL_POWER]->setLabel(_("POWER")); - m_skills[SKILL_POWER]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_power", m_player_id); - - race_manager->setDifficulty(previous_difficulty); - + // Use kart properties computed for "hard" difficulty to show the user, so + // that properties don't change according to the the last used difficulty + // (And because this code uses arbitrary scaling factors to make them look + // nice and the arbitrary factors were optimised for hard difficulty) + RaceManager::Difficulty previous_difficulty = race_manager->getDifficulty(); + race_manager->setDifficulty(RaceManager::DIFFICULTY_HARD); + KartProperties kp_computed; + kp_computed.copyForPlayer(props); + + // Scale the values so they look better + // The scaling factor and offset were found by trial and error. + // It should look nice and you should be able to see the difference between + // different masses or velocities. + m_skills[SKILL_MASS]->setValue((int) + ((kp_computed.getCombinedCharacteristic()->getMass() - 20) / 4)); + m_skills[SKILL_MASS]->setLabel(_("WEIGHT")); + m_skills[SKILL_MASS]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_mass", m_player_id); + + m_skills[SKILL_SPEED]->setValue((int) + ((kp_computed.getCombinedCharacteristic()->getEngineMaxSpeed() - 15) * 6)); + m_skills[SKILL_SPEED]->setLabel(_("SPEED")); + m_skills[SKILL_SPEED]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_speed", m_player_id); + + m_skills[SKILL_POWER]->setValue((int)((kp_computed.getAvgPower() - 30) / 20)); + m_skills[SKILL_POWER]->setLabel(_("POWER")); + m_skills[SKILL_POWER]->m_properties[PROP_ID] = StringUtils::insertValues("@p%i_power", m_player_id); + + race_manager->setDifficulty(previous_difficulty); } // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widgets/kart_stats_widget.hpp b/src/guiengine/widgets/kart_stats_widget.hpp index ccdc13e57..d24ec1134 100644 --- a/src/guiengine/widgets/kart_stats_widget.hpp +++ b/src/guiengine/widgets/kart_stats_widget.hpp @@ -92,7 +92,7 @@ namespace GUIEngine * inside itself */ void setSize(const int x, const int y, const int w, const int h); - void setValues(const KartProperties* props); + void setValues(const KartProperties* props); /** Change the value of the widget, it must be a percent. */ void setValue(Stats type, int value); diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index c5ca77816..8a6ef3e8a 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -544,9 +544,9 @@ public: float getSkidReduceTurnMax() const; bool getSkidEnabled() const; - /* */ - - LEAK_CHECK() + /* */ + + LEAK_CHECK() }; // KartProperties #endif diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 66e07d977..510022e23 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -812,7 +812,7 @@ void KartSelectionScreen::updateKartStats(uint8_t widget_id, if (kp != NULL) { - w->setValues(kp); + w->setValues(kp); w->update(0); } } From cd149ab5d7a05ff4ff310265d99861ee392fefec Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 13 Dec 2016 07:53:33 +1100 Subject: [PATCH 13/17] Moved m_track out of World into a static m_track in Track. Makes world smaller and removes a few dependencies on World. --- src/challenges/challenge_data.cpp | 2 +- src/graphics/callbacks.cpp | 4 +- src/graphics/camera.cpp | 10 ++-- src/graphics/camera_normal.cpp | 4 +- src/graphics/draw_calls.cpp | 11 ++-- src/graphics/geometry_passes.cpp | 4 +- src/graphics/lighting_passes.cpp | 7 +-- src/graphics/mesh_tools.cpp | 5 +- src/graphics/post_processing.cpp | 7 +-- src/graphics/shader_based_renderer.cpp | 8 +-- src/graphics/shadow_matrices.cpp | 10 ++-- src/graphics/stk_mesh_scene_node.cpp | 16 +++--- src/items/attachment.cpp | 8 +-- src/items/flyable.cpp | 6 +-- src/items/item.cpp | 7 ++- src/items/item_manager.cpp | 4 +- src/items/powerup.cpp | 6 ++- src/items/rubber_ball.cpp | 11 ++-- .../controller/ai_base_lap_controller.cpp | 3 +- src/karts/controller/battle_ai.cpp | 3 +- .../controller/local_player_controller.cpp | 2 +- src/karts/controller/skidding_ai.cpp | 2 +- src/karts/controller/soccer_ai.cpp | 3 +- src/karts/controller/test_ai.cpp | 2 +- src/karts/explosion_animation.cpp | 5 +- src/karts/kart.cpp | 14 ++--- src/karts/moveable.cpp | 3 +- src/karts/skidding.cpp | 6 +-- src/modes/cutscene_world.cpp | 17 +++--- src/modes/easter_egg_hunt.cpp | 2 +- src/modes/follow_the_leader.cpp | 4 +- src/modes/linear_world.cpp | 19 +++---- src/modes/overworld.cpp | 4 +- src/modes/profile_world.cpp | 4 +- src/modes/soccer_world.cpp | 11 ++-- src/modes/three_strikes_battle.cpp | 8 +-- src/modes/tutorial_world.cpp | 3 +- src/modes/world.cpp | 43 +++++++-------- src/modes/world.hpp | 6 --- src/modes/world_status.cpp | 2 +- src/modes/world_with_rank.cpp | 6 ++- src/physics/btKart.cpp | 3 +- src/physics/btKartRaycast.cpp | 2 +- src/physics/physics.cpp | 2 +- src/race/history.cpp | 2 +- src/replay/replay_recorder.cpp | 4 +- src/scriptengine/script_challenges.cpp | 53 ++++++++++++------- src/scriptengine/script_track.cpp | 11 ++-- src/states_screens/grand_prix_lose.cpp | 2 +- src/states_screens/grand_prix_win.cpp | 5 +- src/states_screens/race_gui.cpp | 14 ++--- src/states_screens/race_gui_base.cpp | 2 +- src/states_screens/race_gui_overworld.cpp | 6 +-- src/tracks/ambient_light_sphere.cpp | 4 +- src/tracks/check_lap.cpp | 2 +- src/tracks/graph.cpp | 4 +- src/tracks/terrain_info.cpp | 17 +++--- src/tracks/track.cpp | 12 ++++- src/tracks/track.hpp | 17 +++--- src/tracks/track_object_presentation.cpp | 31 ++++++----- 60 files changed, 264 insertions(+), 231 deletions(-) diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index e6b880fd8..6a0e6c52c 100644 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -436,7 +436,7 @@ bool ChallengeData::isChallengeFulfilled() const // Single races // ------------ World *world = World::getWorld(); - std::string track_name = world->getTrack()->getIdent(); + std::string track_name = Track::getCurrentTrack()->getIdent(); int d = race_manager->getDifficulty(); diff --git a/src/graphics/callbacks.cpp b/src/graphics/callbacks.cpp index e85e246c5..45d760fe5 100644 --- a/src/graphics/callbacks.cpp +++ b/src/graphics/callbacks.cpp @@ -158,10 +158,10 @@ void DisplaceProvider::OnSetConstants(IMaterialRendererServices *srv, int) void DisplaceProvider::update() { - if (World::getWorld() == NULL) return; + if (!Track::getCurrentTrack()) return; const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f; - const float speed = World::getWorld()->getTrack()->getDisplacementSpeed(); + const float speed = Track::getCurrentTrack()->getDisplacementSpeed(); float strength = time; strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.002f; diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 6cb61b53f..f84f8f8bd 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -19,9 +19,8 @@ #include "graphics/camera.hpp" -#include - #include "audio/sfx_manager.hpp" +#include "config/stk_config.hpp" #include "config/user_config.hpp" #include "graphics/camera_debug.hpp" #include "graphics/camera_end.hpp" @@ -34,7 +33,6 @@ #include "karts/kart.hpp" #include "karts/kart_properties.hpp" #include "karts/skidding.hpp" -#include "modes/world.hpp" #include "physics/btKart.hpp" #include "race/race_manager.hpp" #include "tracks/track.hpp" @@ -44,6 +42,8 @@ #include "ISceneManager.h" +#include + std::vector Camera::m_all_cameras; Camera* Camera::s_active_camera = NULL; Camera::CameraType Camera::m_default_type = Camera::CM_TYPE_NORMAL; @@ -125,7 +125,7 @@ Camera::Camera(CameraType type, int camera_index, AbstractKart* kart) setupCamera(); setKart(kart); - m_ambient_light = World::getWorld()->getTrack()->getDefaultAmbientColor(); + m_ambient_light = Track::getCurrentTrack()->getDefaultAmbientColor(); reset(); } // Camera @@ -229,7 +229,7 @@ void Camera::setupCamera() } // switch m_camera->setFOV(m_fov); m_camera->setAspectRatio(m_aspect); - m_camera->setFarValue(World::getWorld()->getTrack()->getCameraFar()); + m_camera->setFarValue(Track::getCurrentTrack()->getCameraFar()); } // setupCamera // ---------------------------------------------------------------------------- diff --git a/src/graphics/camera_normal.cpp b/src/graphics/camera_normal.cpp index 45ade8858..93d818c58 100644 --- a/src/graphics/camera_normal.cpp +++ b/src/graphics/camera_normal.cpp @@ -19,12 +19,12 @@ #include "graphics/camera_normal.hpp" +#include "config/stk_config.hpp" #include "karts/abstract_kart.hpp" #include "karts/explosion_animation.hpp" #include "karts/kart.hpp" #include "karts/kart_properties.hpp" #include "karts/skidding.hpp" -#include "modes/world.hpp" #include "tracks/track.hpp" // ============================================================================ @@ -41,7 +41,7 @@ CameraNormal::CameraNormal(Camera::CameraType type, int camera_index, : Camera(type, camera_index, kart) { m_distance = kart ? kart->getKartProperties()->getCameraDistance() : 1000.0f; - m_ambient_light = World::getWorld()->getTrack()->getDefaultAmbientColor(); + m_ambient_light = Track::getCurrentTrack()->getDefaultAmbientColor(); m_smooth_dt = 0.0f; // TODO: Put these values into a config file diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index 36b1cb8c9..7701c605b 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -28,7 +28,6 @@ #include "graphics/stk_mesh.hpp" #include "graphics/stk_mesh_scene_node.hpp" #include "graphics/vao_manager.hpp" -#include "modes/world.hpp" #include "tracks/track.hpp" #include "utils/profiler.hpp" @@ -196,11 +195,9 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, } // Transparent - const World *world = World::getWorld(); - if (world && world->getTrack()->isFogEnabled()) + const Track* const track = Track::getCurrentTrack(); + if (track&& track->isFogEnabled()) { - const Track * const track = World::getWorld()->getTrack(); - // Todo : put everything in a ubo const float fogmax = track->getFogMax(); const float startH = track->getFogStartHeight(); @@ -230,9 +227,9 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, // Use sun color to determine custom alpha for ghost karts float custom_alpha = 1.0f; - if (World::getWorld()) + if (track) { - const video::SColor& c = World::getWorld()->getTrack()->getSunColor(); + const video::SColor& c = track->getSunColor(); float y = 0.2126f * c.getRed() + 0.7152f * c.getGreen() + 0.0722f * c.getBlue(); custom_alpha = y > 128.0f ? 0.5f : 0.35f; } diff --git a/src/graphics/geometry_passes.cpp b/src/graphics/geometry_passes.cpp index a30bbac03..b003ab6d5 100644 --- a/src/graphics/geometry_passes.cpp +++ b/src/graphics/geometry_passes.cpp @@ -261,8 +261,8 @@ void AbstractGeometryPasses::renderTransparent(const DrawCalls& draw_calls, if (CVS->isARBBaseInstanceUsable()) glBindVertexArray(VAOManager::getInstance()->getVAO(video::EVT_STANDARD)); - const World *world = World::getWorld(); - if (world && world->getTrack()->isFogEnabled()) + const Track* const track = Track::getCurrentTrack(); + if (track && track->isFogEnabled()) { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); renderTransparenPassgetTrack()->hasShadows()) + const Track* const track = Track::getCurrentTrack(); + if (!track|| track->hasShadows()) { ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_SUN)); if (World::getWorld() && CVS->isShadowEnabled() && has_shadow) @@ -664,7 +665,7 @@ void LightingPasses::renderLights( bool has_shadow, // ---------------------------------------------------------------------------- void LightingPasses::renderAmbientScatter(GLuint depth_stencil_texture) { - const Track * const track = World::getWorld()->getTrack(); + const Track * const track = Track::getCurrentTrack(); // This function is only called once per frame - thus no need for setters. float start = track->getFogStart() + .001f; @@ -694,7 +695,7 @@ void LightingPasses::renderLightsScatter(GLuint depth_stencil_texture, glClearColor(0., 0., 0., 0.); glClear(GL_COLOR_BUFFER_BIT); - const Track * const track = World::getWorld()->getTrack(); + const Track * const track = Track::getCurrentTrack(); // This function is only called once per frame - thus no need for setters. float start = track->getFogStart() + .001f; diff --git a/src/graphics/mesh_tools.cpp b/src/graphics/mesh_tools.cpp index cbc1f83a7..f2478da4d 100644 --- a/src/graphics/mesh_tools.cpp +++ b/src/graphics/mesh_tools.cpp @@ -464,10 +464,11 @@ scene::IMesh* MeshTools::createMeshWithTangents(scene::IMesh* mesh, scene::SAnimatedMesh* amesh = new scene::SAnimatedMesh(clone); clone->drop(); meshCache->addMesh(path, amesh); - if (World::getWorld()) + Track* track = Track::getCurrentTrack(); + if (track) { irr_driver->grabAllTextures(amesh); - World::getWorld()->getTrack()->addCachedMesh(amesh); + track->addCachedMesh(amesh); return amesh; } amesh->drop(); diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index fbdbceb33..784751940 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -1300,7 +1300,7 @@ void PostProcessing::renderGodRays(scene::ICameraSceneNode * const camnode, const FrameBuffer &quarter1_fbo, const FrameBuffer &quarter2_fbo) { - Track* track = World::getWorld()->getTrack(); + Track* track = Track::getCurrentTrack(); glEnable(GL_DEPTH_TEST); // Grab the sky @@ -1448,8 +1448,9 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, } bool hasgodrays = false; - if (World::getWorld() != NULL) - hasgodrays = World::getWorld()->getTrack()->hasGodRays(); + const Track * const track = Track::getCurrentTrack(); + if (track) + hasgodrays = track->hasGodRays(); if (isRace && UserConfigParams::m_light_shaft && hasgodrays) { diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index 5a20c06d0..a383a7706 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -429,8 +429,8 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, } // Render ambient scattering - const World *world = World::getWorld(); - if (CVS->isDefferedEnabled() && world && world->getTrack()->isFogEnabled()) + const Track * const track = Track::getCurrentTrack(); + if (CVS->isDefferedEnabled() && track && track->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- Ambient scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_FOG)); @@ -446,7 +446,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, } // Render discrete lights scattering - if (CVS->isDefferedEnabled() && world && world->getTrack()->isFogEnabled()) + if (CVS->isDefferedEnabled() && track && track->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- PointLight Scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_FOG)); @@ -801,7 +801,7 @@ void ShaderBasedRenderer::render(float dt) m_post_processing->begin(); World *world = World::getWorld(); // Never NULL. - Track *track = world->getTrack(); + Track *track = Track::getCurrentTrack(); RaceGUIBase *rg = world->getRaceGUI(); if (rg) rg->update(dt); diff --git a/src/graphics/shadow_matrices.cpp b/src/graphics/shadow_matrices.cpp index ceff5a5f4..9ba9f0b6a 100644 --- a/src/graphics/shadow_matrices.cpp +++ b/src/graphics/shadow_matrices.cpp @@ -355,7 +355,8 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca m_sun_ortho_matrices.clear(); const core::matrix4 &sun_cam_view_matrix = m_sun_cam->getViewMatrix(); - if (World::getWorld() && World::getWorld()->getTrack()) + const Track* const track = Track::getCurrentTrack(); + if (track) { float FarValues[] = { @@ -423,13 +424,12 @@ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const ca } // Rsm Matrix and camera - if (!m_rsm_matrix_initialized && - World::getWorld()->getTrack()->getPtrTriangleMesh()) + if (!m_rsm_matrix_initialized && track->getPtrTriangleMesh()) { // Compute track extent Vec3 vmin, vmax; - World::getWorld()->getTrack()->getTriangleMesh().getCollisionShape() - .getAabb(btTransform::getIdentity(), vmin, vmax); + track->getTriangleMesh().getCollisionShape() + .getAabb(btTransform::getIdentity(), vmin, vmax); core::aabbox3df trackbox(vmin.toIrrVector(), vmax.toIrrVector() - core::vector3df(0, 30, 0)); diff --git a/src/graphics/stk_mesh_scene_node.cpp b/src/graphics/stk_mesh_scene_node.cpp index 028ffe18d..cf7473a58 100644 --- a/src/graphics/stk_mesh_scene_node.cpp +++ b/src/graphics/stk_mesh_scene_node.cpp @@ -512,8 +512,8 @@ void STKMeshSceneNode::render() else glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - const World* world = World::getWorld(); - if (world && world->getTrack()->isFogEnabled()) + const Track * const track = Track::getCurrentTrack(); + if (track && track->isFogEnabled()) { Shaders::TransparentFogShader::getInstance()->use(); for (unsigned i = 0; i < GLmeshes.size(); i++) @@ -524,19 +524,17 @@ void STKMeshSceneNode::render() GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - const Track * const track = World::getWorld()->getTrack(); - // This function is only called once per frame - thus no need for setters. const float fogmax = track->getFogMax(); const float startH = track->getFogStartHeight(); - const float endH = track->getFogEndHeight(); - const float start = track->getFogStart(); - const float end = track->getFogEnd(); + const float endH = track->getFogEndHeight(); + const float start = track->getFogStart(); + const float end = track->getFogEnd(); const video::SColor tmpcol = track->getFogColor(); video::SColorf col(tmpcol.getRed() / 255.0f, - tmpcol.getGreen() / 255.0f, - tmpcol.getBlue() / 255.0f); + tmpcol.getGreen() / 255.0f, + tmpcol.getBlue() / 255.0f); compressTexture(mesh.textures[0], true); #if !defined(USE_GLES2) diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index 5b72cf7c3..a6a32d44b 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -573,10 +573,10 @@ void Attachment::update(float dt) Vec3 hit_point; Vec3 normal; const Material* material_hit; - World* world = World::getWorld(); - world->getTrack()->getTriangleMesh().castRay(m_kart->getXYZ(), - m_kart->getTrans().getBasis() * Vec3(0, -10000, 0), &hit_point, - &material_hit, &normal); + + Track::getCurrentTrack()->getTriangleMesh().castRay(m_kart->getXYZ(), + m_kart->getTrans().getBasis() * Vec3(0, -10000, 0), + &hit_point,&material_hit, &normal ); // This can happen if the kart is 'over nothing' when dropping // the bubble gum if(material_hit) diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index 5683b4100..d0195ff17 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -371,7 +371,7 @@ bool Flyable::updateAndDelete(float dt) const Vec3 &xyz=getXYZ(); // Check if the flyable is outside of the track. If so, explode it. const Vec3 *min, *max; - World::getWorld()->getTrack()->getAABB(&min, &max); + Track::getCurrentTrack()->getAABB(&min, &max); // I have seen that the bullet AABB can be slightly different from the // one computed here - I assume due to minor floating point errors @@ -515,13 +515,13 @@ void Flyable::explode(AbstractKart *kart_hit, PhysicalObject *object, // The explosion animation will register itself with the kart // and will free it later. ExplosionAnimation::create(kart, getXYZ(), kart==kart_hit); - if(kart==kart_hit && world->getTrack()->isArena()) + if(kart==kart_hit && Track::getCurrentTrack()->isArena()) { world->kartHit(kart->getWorldKartId()); } } } - world->getTrack()->handleExplosion(getXYZ(), object, secondary_hits); + Track::getCurrentTrack()->handleExplosion(getXYZ(), object,secondary_hits); } // explode // ---------------------------------------------------------------------------- diff --git a/src/items/item.cpp b/src/items/item.cpp index 2ab9d969e..3ab2a9d8a 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -76,8 +76,7 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal, debug_name += m_type; m_node->setName(debug_name.c_str()); #endif - - World::getWorld()->getTrack()->adjustForFog(m_node); + Track::getCurrentTrack()->adjustForFog(m_node); m_node->setAutomaticCulling(scene::EAC_FRUSTUM_BOX); m_node->setPosition(xyz.toIrrVector()); Vec3 hpr; @@ -195,7 +194,7 @@ void Item::switchTo(ItemType type, scene::IMesh *mesh, scene::IMesh *lowmesh) irr_driver->applyObjectPassShader(m_node->getAllNodes()[0]); - World::getWorld()->getTrack()->adjustForFog(m_node); + Track::getCurrentTrack()->adjustForFog(m_node); #endif } // switchTo @@ -224,7 +223,7 @@ void Item::switchBack() ((scene::IMeshSceneNode*)node)->setMesh(m_original_lowmesh); } - World::getWorld()->getTrack()->adjustForFog(m_node); + Track::getCurrentTrack()->adjustForFog(m_node); Vec3 hpr; hpr.setHPR(m_original_rotation); m_node->setRotation(hpr.toIrrHPR()); diff --git a/src/items/item_manager.cpp b/src/items/item_manager.cpp index 6afb9733d..24bf8f4dc 100644 --- a/src/items/item_manager.cpp +++ b/src/items/item_manager.cpp @@ -30,7 +30,6 @@ #include "io/file_manager.hpp" #include "karts/abstract_kart.hpp" #include "karts/controller/spare_tire_ai.hpp" -#include "modes/linear_world.hpp" #include "network/network_config.hpp" #include "network/race_event_manager.hpp" #include "physics/triangle_mesh.hpp" @@ -577,8 +576,7 @@ bool ItemManager::randomItemsForArena(const AlignedArray& pos) const Material* m; Vec3 normal; Vec3 hit_point; - const TriangleMesh& tm = - World::getWorld()->getTrack()->getTriangleMesh(); + const TriangleMesh& tm = Track::getCurrentTrack()->getTriangleMesh(); bool success = tm.castRay(loc, an->getCenter() + (-10000*quad_normal), &hit_point, &m, &normal); diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index ae9d1e7f8..08484efe6 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -279,8 +279,10 @@ void Powerup::use() const Material* material_hit; Vec3 pos = m_kart->getXYZ(); Vec3 to = pos+ m_kart->getTrans().getBasis() * Vec3(0, -10000, 0); - world->getTrack()->getTriangleMesh().castRay(pos, to, &hit_point, - &material_hit, &normal); + Track::getCurrentTrack()->getTriangleMesh().castRay(pos, to, + &hit_point, + &material_hit, + &normal); // This can happen if the kart is 'over nothing' when dropping // the bubble gum if(!material_hit) diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index 04c9e5ad5..2f69e3c43 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -492,7 +492,7 @@ void RubberBall::interpolate(Vec3 *next_xyz, float dt) */ bool RubberBall::checkTunneling() { - const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh(); + const TriangleMesh &tm = Track::getCurrentTrack()->getTriangleMesh(); Vec3 hit_point; const Material *material; @@ -595,9 +595,10 @@ float RubberBall::updateHeight() * \returns The distance to the terrain element found by raycast in the up direction. If no terrain found, it returns 99990 */ -float RubberBall::getTunnelHeight(const Vec3 &next_xyz, const float vertical_offset) const +float RubberBall::getTunnelHeight(const Vec3 &next_xyz, + const float vertical_offset) const { - const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh(); + const TriangleMesh &tm = Track::getCurrentTrack()->getTriangleMesh(); Vec3 from(next_xyz + vertical_offset*getNormal()); Vec3 to(next_xyz + 10000.0f*getNormal()); Vec3 hit_point; @@ -623,7 +624,7 @@ void RubberBall::updateDistanceToTarget() m_distance_to_target = target_distance - ball_distance; if(m_distance_to_target < 0) { - m_distance_to_target += world->getTrack()->getTrackLength(); + m_distance_to_target += Track::getCurrentTrack()->getTrackLength(); } if(UserConfigParams::logFlyable()) Log::debug("[RubberBall]", "ball %d: target %f %f %f distance_2_target %f", @@ -652,7 +653,7 @@ void RubberBall::updateDistanceToTarget() // new target. If the new distance is nearly the full track // length, assume that the rubber ball has overtaken the // original target, and start deleting it. - if(m_distance_to_target > 0.9f * world->getTrack()->getTrackLength()) + if(m_distance_to_target > 0.9f * Track::getCurrentTrack()->getTrackLength()) { m_delete_timer = m_st_delete_time; #ifdef PRINT_BALL_REMOVE_INFO diff --git a/src/karts/controller/ai_base_lap_controller.cpp b/src/karts/controller/ai_base_lap_controller.cpp index 059ca0fd6..cfda6ad87 100644 --- a/src/karts/controller/ai_base_lap_controller.cpp +++ b/src/karts/controller/ai_base_lap_controller.cpp @@ -26,6 +26,7 @@ #include "karts/controller/ai_properties.hpp" #include "modes/linear_world.hpp" #include "tracks/drive_graph.hpp" +#include "tracks/track.hpp" #include "utils/constants.hpp" @@ -90,7 +91,7 @@ AIBaseLapController::AIBaseLapController(AbstractKart *kart) race_manager->getMinorMode()!=RaceManager::MINOR_MODE_SOCCER) { m_world = dynamic_cast(World::getWorld()); - m_track = m_world->getTrack(); + m_track = Track::getCurrentTrack(); computePath(); } else diff --git a/src/karts/controller/battle_ai.cpp b/src/karts/controller/battle_ai.cpp index 6349bcffa..7f3065712 100644 --- a/src/karts/controller/battle_ai.cpp +++ b/src/karts/controller/battle_ai.cpp @@ -27,6 +27,7 @@ #include "karts/controller/spare_tire_ai.hpp" #include "modes/three_strikes_battle.hpp" #include "tracks/arena_graph.hpp" +#include "tracks/track.hpp" #ifdef AI_DEBUG #include "irrlicht.h" @@ -47,7 +48,7 @@ BattleAI::BattleAI(AbstractKart *kart) m_debug_sphere_next->setVisible(true); #endif m_world = dynamic_cast(World::getWorld()); - m_track = m_world->getTrack(); + m_track = Track::getCurrentTrack(); // Don't call our own setControllerName, since this will add a // billboard showing 'AIBaseController' to the kart. diff --git a/src/karts/controller/local_player_controller.cpp b/src/karts/controller/local_player_controller.cpp index 9aea483c4..01eb0879f 100644 --- a/src/karts/controller/local_player_controller.cpp +++ b/src/karts/controller/local_player_controller.cpp @@ -72,7 +72,7 @@ LocalPlayerController::LocalPlayerController(AbstractKart *kart, m_full_sound = SFXManager::get()->createSoundSource("energy_bar_full"); // Attach Particle System - Track *track = World::getWorld()->getTrack(); + Track *track = Track::getCurrentTrack(); #ifndef SERVER_ONLY if (UserConfigParams::m_weather_effects && track->getSkyParticles() != NULL) diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index affd0c1d7..e042cb8f1 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -1694,7 +1694,7 @@ void SkiddingAI::handleNitroAndZipper() { float diff = DriveGraph::get()->getDistanceFromStart(last) - DriveGraph::get()->getDistanceFromStart(m_track_node); - if(diff<0) diff+=World::getWorld()->getTrack()->getTrackLength(); + if(diff<0) diff += Track::getCurrentTrack()->getTrackLength(); if(diff>m_ai_properties->m_straight_length_for_zipper) m_controls->setFire(true); } diff --git a/src/karts/controller/soccer_ai.cpp b/src/karts/controller/soccer_ai.cpp index 12e2e03d1..0b1517219 100644 --- a/src/karts/controller/soccer_ai.cpp +++ b/src/karts/controller/soccer_ai.cpp @@ -25,6 +25,7 @@ #include "karts/kart_properties.hpp" #include "modes/soccer_world.hpp" #include "tracks/arena_graph.hpp" +#include "tracks/track.hpp" #ifdef AI_DEBUG #include "irrlicht.h" @@ -59,7 +60,7 @@ SoccerAI::SoccerAI(AbstractKart *kart) #endif m_world = dynamic_cast(World::getWorld()); - m_track = m_world->getTrack(); + m_track = Track::getCurrentTrack(); m_cur_team = m_world->getKartTeam(m_kart->getWorldKartId()); m_opp_team = (m_cur_team == SOCCER_TEAM_BLUE ? SOCCER_TEAM_RED : SOCCER_TEAM_BLUE); diff --git a/src/karts/controller/test_ai.cpp b/src/karts/controller/test_ai.cpp index d36e2c171..151875926 100644 --- a/src/karts/controller/test_ai.cpp +++ b/src/karts/controller/test_ai.cpp @@ -1743,7 +1743,7 @@ void SkiddingAI::handleNitroAndZipper() { float diff = DriveGraph::get()->getDistanceFromStart(last) - DriveGraph::get()->getDistanceFromStart(m_track_node); - if(diff<0) diff+=World::getWorld()->getTrack()->getTrackLength(); + if (diff < 0) diff += Track::getCurrentTrack()->getTrackLength(); if(diff>m_ai_properties->m_straight_length_for_zipper) m_controls->setFire(true); } diff --git a/src/karts/explosion_animation.cpp b/src/karts/explosion_animation.cpp index 4980fab57..2a81d1bc1 100644 --- a/src/karts/explosion_animation.cpp +++ b/src/karts/explosion_animation.cpp @@ -24,7 +24,6 @@ #include "items/attachment.hpp" #include "karts/abstract_kart.hpp" #include "karts/kart_properties.hpp" -#include "modes/world.hpp" #include "tracks/track.hpp" /** A static create function that does only create an explosion if @@ -91,7 +90,7 @@ ExplosionAnimation::ExplosionAnimation(AbstractKart *kart, // Since v(explosion_time*0.5) = 0, the following forumla computes // the right initial velocity for a kart to land back after // the specified time. - m_velocity = 0.5f * m_timer * World::getWorld()->getTrack()->getGravity(); + m_velocity = 0.5f * m_timer * Track::getCurrentTrack()->getGravity(); m_curr_rotation.setHeading(m_kart->getHeading()); m_curr_rotation.setPitch(m_kart->getPitch()); @@ -141,7 +140,7 @@ ExplosionAnimation::~ExplosionAnimation() */ void ExplosionAnimation::update(float dt) { - m_velocity -= dt*World::getWorld()->getTrack()->getGravity(); + m_velocity -= dt*Track::getCurrentTrack()->getGravity(); m_xyz = m_xyz + dt*m_velocity*m_normal; // Make sure the kart does not end up under the track diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index ce1123080..371ebd66c 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -673,7 +673,7 @@ void Kart::createPhysics() m_vehicle_raycaster = new btKartRaycaster(World::getWorld()->getPhysics()->getPhysicsWorld(), stk_config->m_smooth_normals && - World::getWorld()->getTrack()->smoothNormals()); + Track::getCurrentTrack()->smoothNormals()); m_vehicle = new btKart(m_body, m_vehicle_raycaster, this); // never deactivate the vehicle @@ -1360,7 +1360,7 @@ void Kart::update(float dt) const float roll = quad_normal.angle ((Vec3(0, 1, 0).rotate(q.getAxis(), q.getAngle()))); - if (World::getWorld()->getTrack()->isAutoRescueEnabled() && + if (Track::getCurrentTrack()->isAutoRescueEnabled() && (!m_terrain_info->getMaterial() || !m_terrain_info->getMaterial()->hasGravity()) && !has_animation_before && fabs(roll) > 60 * DEGREE_TO_RAD && @@ -1420,14 +1420,14 @@ void Kart::update(float dt) { if (!m_flying) { - float g = World::getWorld()->getTrack()->getGravity(); + float g = Track::getCurrentTrack()->getGravity(); Vec3 gravity(0, -g, 0); btRigidBody *body = getVehicle()->getRigidBody(); body->setGravity(gravity); } // let kart fall a bit before rescuing const Vec3 *min, *max; - World::getWorld()->getTrack()->getAABB(&min, &max); + Track::getCurrentTrack()->getAABB(&min, &max); if((min->getY() - getXYZ().getY() > 17 || dist_to_sector > 25) && !m_flying && !getKartAnimation()) @@ -1437,7 +1437,7 @@ void Kart::update(float dt) { if (!m_flying) { - float g = World::getWorld()->getTrack()->getGravity(); + float g = Track::getCurrentTrack()->getGravity(); Vec3 gravity(0.0f, -g, 0.0f); btRigidBody *body = getVehicle()->getRigidBody(); // If the material should overwrite the gravity, @@ -1519,7 +1519,7 @@ void Kart::update(float dt) m_kart_model->getAnimation() == KartModel::AF_DEFAULT) { float v = getVelocity().getY(); - float force = World::getWorld()->getTrack()->getGravity(); + float force = Track::getCurrentTrack()->getGravity(); // Velocity / force is the time it takes to reach the peak // of the jump (i.e. when vertical speed becomes 0). Assuming // that jump start height and end height are the same, it will @@ -2027,7 +2027,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal) else if(m_kart_properties->getTerrainImpulseType() ==KartProperties::IMPULSE_TO_DRIVELINE && lw && m_vehicle->getCentralImpulseTime()<=0 && - World::getWorld()->getTrack()->isPushBackEnabled()) + Track::getCurrentTrack()->isPushBackEnabled()) { int sector = lw->getSectorForKart(this); if(sector!=Graph::UNKNOWN_SECTOR) diff --git a/src/karts/moveable.cpp b/src/karts/moveable.cpp index 55aa85953..c5b918ffa 100644 --- a/src/karts/moveable.cpp +++ b/src/karts/moveable.cpp @@ -23,7 +23,6 @@ #include "graphics/irr_driver.hpp" #include "graphics/material.hpp" #include "graphics/material_manager.hpp" -#include "modes/world.hpp" #include "tracks/track.hpp" #include "ISceneNode.h" @@ -118,7 +117,7 @@ void Moveable::flyDown() // ---------------------------------------------------------------------------- void Moveable::stopFlying() { - m_body->setGravity(btVector3(0.0, -World::getWorld()->getTrack()->getGravity(), 0.0)); + m_body->setGravity(btVector3(0.0, -Track::getCurrentTrack()->getGravity(), 0.0)); } // stopFlying //----------------------------------------------------------------------------- diff --git a/src/karts/skidding.cpp b/src/karts/skidding.cpp index a4b82d83e..708d072f7 100644 --- a/src/karts/skidding.cpp +++ b/src/karts/skidding.cpp @@ -287,7 +287,7 @@ void Skidding::update(float dt, bool is_on_ground, // be displayed, update the data if(m_remaining_jump_time>0) { - m_jump_speed -= World::getWorld()->getTrack()->getGravity()*dt; + m_jump_speed -= Track::getCurrentTrack()->getGravity()*dt; m_gfx_jump_offset += m_jump_speed * dt; m_remaining_jump_time -= dt; if(m_remaining_jump_time<0) @@ -339,13 +339,13 @@ void Skidding::update(float dt, bool is_on_ground, // the same time to come down again), based on v = gravity * t. // Then use this speed to determine the impulse necessary to // reach this speed. - float v = World::getWorld()->getTrack()->getGravity() + float v = Track::getCurrentTrack()->getGravity() * 0.5f * kp->getSkidPhysicalJumpTime(); btVector3 imp(0, v / m_kart->getBody()->getInvMass(),0); m_kart->getVehicle()->getRigidBody()->applyCentralImpulse(imp); // Some karts might use a graphical-only jump. Set it up: - m_jump_speed = World::getWorld()->getTrack()->getGravity() + m_jump_speed = Track::getCurrentTrack()->getGravity() * 0.5f * kp->getSkidGraphicalJumpTime(); m_remaining_jump_time = kp->getSkidGraphicalJumpTime(); diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index a4861cb37..514bf8629 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -75,7 +75,7 @@ void CutsceneWorld::init() dynamic_cast(m_race_gui)->setFadeLevel(1.0f); - getTrack()->startMusic(); + Track::getCurrentTrack()->startMusic(); m_duration = -1.0f; @@ -85,7 +85,8 @@ void CutsceneWorld::init() m_camera->bindTargetAndRotation(true); // no "look-at" // --- Build list of sounds to play at certain frames - PtrVector& objects = m_track->getTrackObjectManager()->getObjects(); + PtrVector& objects = Track::getCurrentTrack() + ->getTrackObjectManager()->getObjects(); for (TrackObject* curr : objects) { if (curr->getType() == "particle-emitter" && @@ -199,7 +200,8 @@ void CutsceneWorld::update(float dt) { //printf("INITIAL TIME for CutsceneWorld\n"); - PtrVector& objects = m_track->getTrackObjectManager()->getObjects(); + PtrVector& objects = Track::getCurrentTrack() + ->getTrackObjectManager()->getObjects(); TrackObject* curr; for_in(curr, objects) { @@ -213,7 +215,8 @@ void CutsceneWorld::update(float dt) { m_second_reset = false; - PtrVector& objects = m_track->getTrackObjectManager()->getObjects(); + PtrVector& objects = Track::getCurrentTrack() + ->getTrackObjectManager()->getObjects(); TrackObject* curr; for_in(curr, objects) { @@ -265,7 +268,8 @@ void CutsceneWorld::update(float dt) //printf("Estimated current frame : %f\n", curr_frame); - const std::vector& subtitles = m_track->getSubtitles(); + const std::vector& subtitles = Track::getCurrentTrack() + ->getSubtitles(); bool foundSubtitle = false; for (unsigned int n = 0; n < subtitles.size(); n++) { @@ -287,7 +291,8 @@ void CutsceneWorld::update(float dt) World::update((float)dt); World::updateTrack((float)dt); - PtrVector& objects = m_track->getTrackObjectManager()->getObjects(); + PtrVector& objects = Track::getCurrentTrack() + ->getTrackObjectManager()->getObjects(); TrackObject* curr; for_in(curr, objects) { diff --git a/src/modes/easter_egg_hunt.cpp b/src/modes/easter_egg_hunt.cpp index ea848b1b7..b449ba936 100644 --- a/src/modes/easter_egg_hunt.cpp +++ b/src/modes/easter_egg_hunt.cpp @@ -126,7 +126,7 @@ void EasterEggHunt::readData(const std::string &filename) race_manager->getDifficultyAsString(act_difficulty).c_str()); continue; } - World::getTrack()->itemCommand(egg); + Track::getCurrentTrack()->itemCommand(egg); m_number_of_eggs++; } // for i getStartTransform(index); + return Track::getCurrentTrack()->getStartTransform(index); // Otherwise the karts will start at the rear starting positions int start_index = stk_config->m_max_karts - race_manager->getNumberOfKarts() + index; - return m_track->getStartTransform(start_index); + return Track::getCurrentTrack()->getStartTransform(start_index); } // getStartTransform //----------------------------------------------------------------------------- diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 4b13ce270..ef70921c3 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -61,8 +61,8 @@ void LinearWorld::init() { WorldWithRank::init(); - assert(!m_track->isArena()); - assert(!m_track->isSoccer()); + assert(!Track::getCurrentTrack()->isArena()); + assert(!Track::getCurrentTrack()->isSoccer()); m_last_lap_sfx_played = false; m_last_lap_sfx_playing = false; @@ -102,7 +102,7 @@ void LinearWorld::reset() // the track length must be extended (to avoid negative numbers in // estimateFinishTimeForKart()). On the other hand future game modes // might not follow this rule, so check the distance for all karts here: - m_distance_increase = m_track->getTrackLength(); + m_distance_increase = Track::getCurrentTrack()->getTrackLength(); for(unsigned int i=0; igetTrackLength() - m_distance_increase - + 5.0f; + m_distance_increase = Track::getCurrentTrack()->getTrackLength() + - m_distance_increase + 5.0f; if(m_distance_increase<0) m_distance_increase = 1.0f; // shouldn't happen @@ -187,7 +187,7 @@ void LinearWorld::update(float dt) continue; getTrackSector(n)->update(kart->getFrontXYZ()); kart_info.m_overall_distance = kart_info.m_race_lap - * m_track->getTrackLength() + * Track::getCurrentTrack()->getTrackLength() + getDistanceDownTrackForKart(kart->getWorldKartId()); } // for n @@ -277,7 +277,8 @@ void LinearWorld::newLap(unsigned int kart_index) kart_info.m_time_at_last_lap=getTime(); kart_info.m_race_lap++; m_kart_info[kart_index].m_overall_distance = - m_kart_info[kart_index].m_race_lap * m_track->getTrackLength() + m_kart_info[kart_index].m_race_lap + * Track::getCurrentTrack()->getTrackLength() + getDistanceDownTrackForKart(kart->getWorldKartId()); } // Last lap message (kart_index's assert in previous block already) @@ -549,7 +550,7 @@ float LinearWorld::estimateFinishTimeForKart(AbstractKart* kart) const KartInfo &kart_info = m_kart_info[kart->getWorldKartId()]; float full_distance = race_manager->getNumLaps() - * m_track->getTrackLength(); + * Track::getCurrentTrack()->getTrackLength(); if(full_distance == 0) full_distance = 1.0f; // For 0 lap races avoid warning below @@ -651,7 +652,7 @@ btTransform LinearWorld::getRescueTransform(unsigned int index) const else q1 = btQuaternion(Vec3(0,1,0),0); // First apply the heading change, than the 'parallelisation' to the plane - btQuaternion q2(btVector3(0,1,0), m_track->getAngle(index)); + btQuaternion q2(btVector3(0,1,0), Track::getCurrentTrack()->getAngle(index)); pos.setRotation(q1*q2); return pos; } // getRescueTransform diff --git a/src/modes/overworld.cpp b/src/modes/overworld.cpp index 7bc034b0a..47a8c5046 100644 --- a/src/modes/overworld.cpp +++ b/src/modes/overworld.cpp @@ -112,7 +112,7 @@ void OverWorld::update(float dt) setPhase(RACE_PHASE); // Normally done in WorldStatus::update(), during phase SET_PHASE, // so we have to start music 'manually', since we skip all phases. - World::getWorld()->getTrack()->startMusic(); + Track::getCurrentTrack()->startMusic(); if (UserConfigParams::m_music) music_manager->startMusic(); @@ -212,7 +212,7 @@ void OverWorld::createRaceGUI() void OverWorld::onFirePressed(Controller* who) { const std::vector& challenges = - m_track->getChallengeList(); + Track::getCurrentTrack()->getChallengeList(); AbstractKart* k = getKart(0); Vec3 kart_xyz = k->getXYZ(); diff --git a/src/modes/profile_world.cpp b/src/modes/profile_world.cpp index 688f18c3e..25b1e1be8 100644 --- a/src/modes/profile_world.cpp +++ b/src/modes/profile_world.cpp @@ -244,7 +244,7 @@ void ProfileWorld::enterRaceOverState() all_groups.insert(kart->getController()->getControllerName()); float distance = (float)(m_profile_mode==PROFILE_LAPS ? race_manager->getNumLaps() : 1); - distance *= m_track->getTrackLength(); + distance *= Track::getCurrentTrack()->getTrackLength(); ss << distance/kart->getFinishTime() << " " << kart->getTopSpeed() << " "; ss << kart->getSkiddingTime() << " " << kart->getRescueTime() << " "; ss << kart->getRescueCount() << " " << kart->getBrakeCount() << " "; @@ -300,7 +300,7 @@ void ProfileWorld::enterRaceOverState() float distance = (float)(m_profile_mode==PROFILE_LAPS ? race_manager->getNumLaps() : 1); - distance *= m_track->getTrackLength(); + distance *= Track::getCurrentTrack()->getTrackLength(); Log::verbose("profile", "%s %4.2f %3.2f %6.2f %4.2f %3d %5d %4.2f %3d %3d %3d %3d %3d %3d %5d %4.2f", diff --git a/src/modes/soccer_world.cpp b/src/modes/soccer_world.cpp index 34e1d2eec..101beea45 100644 --- a/src/modes/soccer_world.cpp +++ b/src/modes/soccer_world.cpp @@ -91,13 +91,14 @@ void SoccerWorld::init() m_goal_target = race_manager->getMaxGoal(); m_goal_sound = SFXManager::get()->createSoundSource("goal_scored"); - if (m_track->hasNavMesh()) + Track *track = Track::getCurrentTrack(); + if (track->hasNavMesh()) { // Init track sector for ball if navmesh is found m_ball_track_sector = new TrackSector(); } - TrackObjectManager* tom = getTrack()->getTrackObjectManager(); + TrackObjectManager* tom = track->getTrackObjectManager(); assert(tom); PtrVector& objects = tom->getObjects(); for (unsigned int i = 0; i < objects.size(); i++) @@ -150,7 +151,7 @@ void SoccerWorld::reset() m_goal_sound->stop(); } - if (m_track->hasNavMesh()) + if (Track::getCurrentTrack()->hasNavMesh()) { m_ball_track_sector->reset(); } @@ -181,7 +182,7 @@ const std::string& SoccerWorld::getIdent() const void SoccerWorld::update(float dt) { updateBallPosition(dt); - if (m_track->hasNavMesh()) + if (Track::getCurrentTrack()->hasNavMesh()) { updateSectorForKarts(); updateAIData(); @@ -457,7 +458,7 @@ void SoccerWorld::updateBallPosition(float dt) m_ball_body->getLinearVelocity().getZ()); } - if (m_track->hasNavMesh()) + if (Track::getCurrentTrack()->hasNavMesh()) { m_ball_track_sector ->update(getBallPosition(), true/*ignore_vertical*/); diff --git a/src/modes/three_strikes_battle.cpp b/src/modes/three_strikes_battle.cpp index 27f100ce0..2e5c1d9e1 100644 --- a/src/modes/three_strikes_battle.cpp +++ b/src/modes/three_strikes_battle.cpp @@ -149,7 +149,7 @@ void ThreeStrikesBattle::reset() TrackObject *obj; for_in(obj, m_tires) { - m_track->getTrackObjectManager()->removeObject(obj); + Track::getCurrentTrack()->getTrackObjectManager()->removeObject(obj); } m_tires.clearWithoutDeleting(); @@ -357,7 +357,7 @@ void ThreeStrikesBattle::update(float dt) WorldWithRank::updateTrack(dt); spawnSpareTireKarts(); - if (m_track->hasNavMesh()) + if (Track::getCurrentTrack()->hasNavMesh()) updateSectorForKarts(); // insert blown away tire(s) now if was requested @@ -419,7 +419,7 @@ void ThreeStrikesBattle::update(float dt) "movable", tire_presentation, true /* is_dynamic */, &physics_settings); - getTrack()->getTrackObjectManager()->insertObject(tire_obj); + Track::getCurrentTrack()->getTrackObjectManager()->insertObject(tire_obj); // FIXME: orient the force relative to kart orientation tire_obj->getPhysicalObject()->getBody() @@ -730,7 +730,7 @@ void ThreeStrikesBattle::loadCustomModels() m_karts.push_back(sta); race_manager->addSpareTireKart(sta_list[i]); - m_track->adjustForFog(sta->getNode()); + Track::getCurrentTrack()->adjustForFog(sta->getNode()); // Copy STA pointer to m_spare_tire_karts array, allowing them // to respawn easily diff --git a/src/modes/tutorial_world.cpp b/src/modes/tutorial_world.cpp index 27def25a0..5104ec551 100644 --- a/src/modes/tutorial_world.cpp +++ b/src/modes/tutorial_world.cpp @@ -29,7 +29,8 @@ TutorialWorld::TutorialWorld() unsigned int TutorialWorld::getRescuePositionIndex(AbstractKart *kart) { - const int start_spots_amount = getTrack()->getNumberOfStartPositions(); + const int start_spots_amount = + Track::getCurrentTrack()->getNumberOfStartPositions(); assert(start_spots_amount > 0); float closest_distance = 999999.0f; diff --git a/src/modes/world.cpp b/src/modes/world.cpp index e68a9f394..7bf11f867 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -125,7 +125,6 @@ World::World() : WorldStatus() m_race_gui = NULL; m_saved_race_gui = NULL; m_use_highscores = true; - m_track = NULL; m_schedule_pause = false; m_schedule_unpause = false; m_schedule_exit_race = false; @@ -168,9 +167,9 @@ void World::init() RewindManager::create(); // Grab the track file - m_track = track_manager->getTrack(race_manager->getTrackName()); + Track *track = track_manager->getTrack(race_manager->getTrackName()); m_script_engine = new Scripting::ScriptEngine(); - if(!m_track) + if(!track) { std::ostringstream msg; msg << "Track '" << race_manager->getTrackName() @@ -178,7 +177,7 @@ void World::init() throw std::runtime_error(msg.str()); } - std::string script_path = World::getWorld()->getTrack()->getTrackFile("scripting.as"); + std::string script_path = track->getTrackFile("scripting.as"); m_script_engine->loadScript(script_path, true); // Create the physics @@ -189,7 +188,8 @@ void World::init() // Load the track models - this must be done before the karts so that the // karts can be positioned properly on (and not in) the tracks. - m_track->loadTrackModel(race_manager->getReverseTrack()); + // This also defines the static Track::getCurrentTrack function. + track->loadTrackModel(race_manager->getReverseTrack()); if (gk > 0) { @@ -216,7 +216,7 @@ void World::init() race_manager->getKartType(i), race_manager->getPlayerDifficulty(i)); m_karts.push_back(newkart); - m_track->adjustForFog(newkart->getNode()); + track->adjustForFog(newkart->getNode()); } // for i @@ -235,8 +235,8 @@ void World::init() if (UserConfigParams::m_weather_effects) { - m_weather = new Weather(m_track->getWeatherLightning(), - m_track->getWeatherSound()); + m_weather = new Weather(track->getWeatherLightning(), + track->getWeatherSound()); } } // init @@ -282,7 +282,7 @@ void World::reset() // Note: track reset must be called after all karts exist, since check // objects need to allocate data structures depending on the number // of karts. - m_track->reset(); + Track::getCurrentTrack()->reset(); // Reset the race gui. m_race_gui->reset(); @@ -387,7 +387,7 @@ AbstractKart *World::createKart(const std::string &kart_ident, int index, * \param index Index of kart ranging from 0 to kart_num-1. */ const btTransform &World::getStartTransform(int index) { - return m_track->getStartTransform(index); + return Track::getCurrentTrack()->getStartTransform(index); } // getStartTransform //----------------------------------------------------------------------------- @@ -437,9 +437,9 @@ World::~World() irr_driver->onUnloadWorld(); - // In case that a race is aborted (e.g. track not found) m_track is 0. - if(m_track) - m_track->cleanup(); + // In case that a race is aborted (e.g. track not found) track is 0. + if(Track::getCurrentTrack()) + Track::getCurrentTrack()->cleanup(); // Delete the in-race-gui: if(m_saved_race_gui) @@ -555,7 +555,7 @@ void World::terminateRace() // Check achievements PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_COLUMBUS, - getTrack()->getIdent(), 1); + Track::getCurrentTrack()->getIdent(), 1); if (raceHasLaps()) { PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_MARATHONER, @@ -697,13 +697,14 @@ void World::resetAllKarts() Vec3 up_offset = (*i)->getNormal() * (0.5f * ((*i)->getKartHeight())); (*i)->setXYZ(xyz+up_offset); - bool kart_over_ground = m_track->findGround(*i); + bool kart_over_ground = Track::getCurrentTrack()->findGround(*i); if (!kart_over_ground) { Log::error("World", "No valid starting position for kart %d on track %s.", - (int)(i-m_karts.begin()), m_track->getIdent().c_str()); + (int)(i - m_karts.begin()), + Track::getCurrentTrack()->getIdent().c_str()); if (UserConfigParams::m_artist_debug_mode) { Log::warn("World", "Activating fly mode."); @@ -719,7 +720,7 @@ void World::resetAllKarts() // Do a longer initial simulation, which should be long enough for all // karts to be firmly on ground. - float g = World::getWorld()->getTrack()->getGravity(); + float g = Track::getCurrentTrack()->getGravity(); for (KartList::iterator i = m_karts.begin(); i != m_karts.end(); i++) { if ((*i)->isGhostKart()) continue; @@ -780,7 +781,7 @@ void World::moveKartTo(AbstractKart* kart, const btTransform &transform) // Project kart to surface of track // This will set the physics transform - m_track->findGround(kart); + Track::getCurrentTrack()->findGround(kart); } // moveKartTo @@ -1052,7 +1053,7 @@ void World::updateTime(const float dt) */ void World::updateTrack(float dt) { - m_track->update(dt); + Track::getCurrentTrack()->update(dt); } // update Track // ---------------------------------------------------------------------------- @@ -1297,7 +1298,7 @@ void World::escapePressed() */ btTransform World::getRescueTransform(unsigned int rescue_pos) const { - return m_track->getStartTransform(rescue_pos); + return Track::getCurrentTrack()->getStartTransform(rescue_pos); } // getRescueTransform //----------------------------------------------------------------------------- @@ -1305,7 +1306,7 @@ btTransform World::getRescueTransform(unsigned int rescue_pos) const */ unsigned int World::getNumberOfRescuePositions() const { - return m_track->getNumberOfStartPositions(); + return Track::getCurrentTrack()->getNumberOfStartPositions(); } // getNumberOfRescuePositions /* EOF */ diff --git a/src/modes/world.hpp b/src/modes/world.hpp index d10a43113..c3204c5f5 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -42,7 +42,6 @@ class btRigidBody; class Controller; class PhysicalObject; class Physics; -class Track; namespace Scripting { @@ -124,8 +123,6 @@ protected: int local_player_id, int global_player_id, RaceManager::KartType type, PerPlayerDifficulty difficulty); - /** Pointer to the track. The track is managed by world. */ - Track* m_track; /**Pointer to scripting engine */ Scripting::ScriptEngine* m_script_engine; @@ -317,9 +314,6 @@ public: /** Returns a pointer to the physics. */ Physics *getPhysics() const { return m_physics; } // ------------------------------------------------------------------------ - /** Returns a pointer to the track. */ - Track *getTrack() const { return m_track; } - // ------------------------------------------------------------------------ /** Returns a pointer to the Scripting Engine. */ Scripting::ScriptEngine *getScriptEngine() const { return m_script_engine; } diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index c60a1c7c4..8bf2551be 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -92,7 +92,7 @@ void WorldStatus::reset() device->getTimer()->start(); // Set the right music - World::getWorld()->getTrack()->startMusic(); + Track::getCurrentTrack()->startMusic(); // In case of a networked race the race can only start once // all protocols are up. This flag is used to wait for // a confirmation before starting the actual race. diff --git a/src/modes/world_with_rank.cpp b/src/modes/world_with_rank.cpp index 60f4ffe27..6d23e20f2 100644 --- a/src/modes/world_with_rank.cpp +++ b/src/modes/world_with_rank.cpp @@ -52,8 +52,9 @@ void WorldWithRank::init() #endif stk_config->getAllScores(&m_score_for_position, getNumKarts()); + Track *track = Track::getCurrentTrack(); // Don't init track sector if navmesh is not found in arena - if ((m_track->isArena() || m_track->isSoccer()) && !m_track->hasNavMesh()) + if ((track->isArena() || track->isSoccer()) && !track->hasNavMesh()) return; for (unsigned int i = 0; i < m_karts.size(); i++) @@ -167,7 +168,8 @@ void WorldWithRank::endSetKartPositions() unsigned int WorldWithRank::getRescuePositionIndex(AbstractKart *kart) { - const int start_spots_amount = getTrack()->getNumberOfStartPositions(); + const int start_spots_amount = + Track::getCurrentTrack()->getNumberOfStartPositions(); assert(start_spots_amount > 0); float largest_accumulated_distance_found = -1; diff --git a/src/physics/btKart.cpp b/src/physics/btKart.cpp index 4599fef9d..d9b3d68b1 100644 --- a/src/physics/btKart.cpp +++ b/src/physics/btKart.cpp @@ -24,7 +24,6 @@ #include "graphics/material.hpp" #include "karts/kart.hpp" -#include "modes/world.hpp" #include "physics/triangle_mesh.hpp" #include "tracks/terrain_info.hpp" #include "tracks/track.hpp" @@ -1026,7 +1025,7 @@ void btKart::debugDraw(btIDebugDraw* debugDrawer) int n = w.m_raycastInfo.m_triangle_index; if (n > -1) { - const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh(); + const TriangleMesh &tm = Track::getCurrentTrack()->getTriangleMesh(); btVector3 *p1, *p2, *p3; tm.getTriangle(n, &p1, &p2, &p3); const btVector3 *n1, *n2, *n3; diff --git a/src/physics/btKartRaycast.cpp b/src/physics/btKartRaycast.cpp index 71ec999a8..8a6d0a46a 100644 --- a/src/physics/btKartRaycast.cpp +++ b/src/physics/btKartRaycast.cpp @@ -72,7 +72,7 @@ void* btKartRaycaster::castRay(const btVector3& from, const btVector3& to, result.m_distFraction = rayCallback.m_closestHitFraction; result.m_triangle_index = -1; const TriangleMesh &tm = - World::getWorld()->getTrack()->getTriangleMesh(); + Track::getCurrentTrack()->getTriangleMesh(); if(m_smooth_normals && rayCallback.getTriangleIndex()>-1) { diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 353c966e4..56597a16a 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -69,7 +69,7 @@ void Physics::init(const Vec3 &world_min, const Vec3 &world_max) m_karts_to_delete.clear(); m_dynamics_world->setGravity( btVector3(0.0f, - -World::getWorld()->getTrack()->getGravity(), + -Track::getCurrentTrack()->getGravity(), 0.0f)); m_debug_drawer = new IrrDebugDrawer(); m_dynamics_world->setDebugDrawer(m_debug_drawer); diff --git a/src/race/history.cpp b/src/race/history.cpp index 85ce6492a..b53d762f1 100644 --- a/src/race/history.cpp +++ b/src/race/history.cpp @@ -181,7 +181,7 @@ void History::Save() fprintf(fd, "difficulty: %d\n", race_manager->getDifficulty()); fprintf(fd, "reverse: %c\n", race_manager->getReverseTrack() ? 'y' : 'n'); - fprintf(fd, "track: %s\n", world->getTrack()->getIdent().c_str()); + fprintf(fd, "track: %s\n", Track::getCurrentTrack()->getIdent().c_str()); assert(num_karts > 0); diff --git a/src/replay/replay_recorder.cpp b/src/replay/replay_recorder.cpp index 255508845..3557ea97a 100644 --- a/src/replay/replay_recorder.cpp +++ b/src/replay/replay_recorder.cpp @@ -203,7 +203,7 @@ void ReplayRecorder::save() std::string time = StringUtils::toString(min_time); std::replace(time.begin(), time.end(), '.', '_'); std::ostringstream oss; - oss << world->getTrack()->getIdent() << "_" << year << month << day + oss << Track::getCurrentTrack()->getIdent() << "_" << year << month << day << "_" << num_karts << "_" << time << ".replay"; m_filename = oss.str(); @@ -230,7 +230,7 @@ void ReplayRecorder::save() fprintf(fd, "kart_list_end\n"); fprintf(fd, "reverse: %d\n", (int)race_manager->getReverseTrack()); fprintf(fd, "difficulty: %d\n", race_manager->getDifficulty()); - fprintf(fd, "track: %s\n", world->getTrack()->getIdent().c_str()); + fprintf(fd, "track: %s\n", Track::getCurrentTrack()->getIdent().c_str()); fprintf(fd, "laps: %d\n", race_manager->getNumLaps()); fprintf(fd, "min_time: %f\n", min_time); diff --git a/src/scriptengine/script_challenges.cpp b/src/scriptengine/script_challenges.cpp index 2dd100f12..5c391cd15 100644 --- a/src/scriptengine/script_challenges.cpp +++ b/src/scriptengine/script_challenges.cpp @@ -48,37 +48,41 @@ namespace Scripting * @{ */ + // -------------------------------------------------------------------- /** Get number of challenges that were completed at any difficulty */ int getCompletedChallengesCount() { - ::Track* track = World::getWorld()->getTrack(); - return track->getNumOfCompletedChallenges(); - } + return ::Track::getCurrentTrack()->getNumOfCompletedChallenges(); + } // getCompletedChallengesCount + // -------------------------------------------------------------------- /** Get total number of challenges */ int getChallengeCount() { - ::Track* track = World::getWorld()->getTrack(); - return track->getChallengeList().size(); - } + return ::Track::getCurrentTrack()->getChallengeList().size(); + } // getChallengeCount + // -------------------------------------------------------------------- int getChallengeRequiredPoints(std::string* challenge_name) { - const ChallengeData* challenge = unlock_manager->getChallengeData(*challenge_name); + const ChallengeData* challenge = + unlock_manager->getChallengeData(*challenge_name); if (challenge == NULL) { if (*challenge_name != "tutorial") Log::error("track", "Cannot find challenge named '%s'\n", - challenge_name->c_str()); + challenge_name->c_str()); return false; } return challenge->getNumTrophies(); - } + } // getChallengeRequiredPoints + // -------------------------------------------------------------------- bool isChallengeUnlocked(std::string* challenge_name) { - const ChallengeData* challenge = unlock_manager->getChallengeData(*challenge_name); + const ChallengeData* challenge = + unlock_manager->getChallengeData(*challenge_name); if (challenge == NULL) { if (*challenge_name != "tutorial") @@ -90,8 +94,9 @@ namespace Scripting const unsigned int val = challenge->getNumTrophies(); bool shown = (PlayerManager::getCurrentPlayer()->getPoints() >= val); return shown; - } + } // isChallengeUnlocked + // -------------------------------------------------------------------- /** @}*/ /** @}*/ @@ -101,15 +106,27 @@ namespace Scripting engine->SetDefaultNamespace("Challenges"); - r = engine->RegisterGlobalFunction("int getCompletedChallengesCount()", asFUNCTION(getCompletedChallengesCount), asCALL_CDECL); assert(r >= 0); - r = engine->RegisterGlobalFunction("int getChallengeCount()", asFUNCTION(getChallengeCount), asCALL_CDECL); assert(r >= 0); - r = engine->RegisterGlobalFunction("bool isChallengeUnlocked(string &in)", asFUNCTION(isChallengeUnlocked), asCALL_CDECL); assert(r >= 0); - r = engine->RegisterGlobalFunction("int getChallengeRequiredPoints(string &in)", asFUNCTION(getChallengeRequiredPoints), asCALL_CDECL); assert(r >= 0); - } + r = engine->RegisterGlobalFunction("int getCompletedChallengesCount()", + asFUNCTION(getCompletedChallengesCount), + asCALL_CDECL); + assert(r >= 0); + r = engine->RegisterGlobalFunction("int getChallengeCount()", + asFUNCTION(getChallengeCount), + asCALL_CDECL); + assert(r >= 0); + r = engine->RegisterGlobalFunction("bool isChallengeUnlocked(string &in)", + asFUNCTION(isChallengeUnlocked), + asCALL_CDECL); + assert(r >= 0); + r = engine->RegisterGlobalFunction("int getChallengeRequiredPoints(string &in)", + asFUNCTION(getChallengeRequiredPoints), + asCALL_CDECL); + assert(r >= 0); + } // registerScriptFunctions - } + } // namespace Challenges /** \cond DOXYGEN_IGNORE */ -} +} // namespace Scripting /** \endcond */ diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index a4abe595d..59d957064 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -67,7 +67,8 @@ namespace Scripting */ ::TrackObject* getTrackObject(std::string* libraryInstance, std::string* objID) { - return World::getWorld()->getTrack()->getTrackObjectManager()->getTrackObject(*libraryInstance, *objID); + return ::Track::getCurrentTrack()->getTrackObjectManager() + ->getTrackObject(*libraryInstance, *objID); } /** Creates a trigger at the specified location */ @@ -84,7 +85,7 @@ namespace Scripting ::TrackObject* tobj = new ::TrackObject(posi, hpr, scale, "none", newtrigger, false /* isDynamic */, NULL /* physics settings */); tobj->setID(*triggerID); - World::getWorld()->getTrack()->getTrackObjectManager()->insertObject(tobj); + ::Track::getCurrentTrack()->getTrackObjectManager()->insertObject(tobj); } void createTextBillboard(std::string* text, SimpleVec3* location) @@ -104,7 +105,7 @@ namespace Scripting irr_driver->getSceneManager(), -1, xyz, core::vector3df(1.5f, 1.5f, 1.5f)); - World::getWorld()->getTrack()->addNode(tb); + ::Track::getCurrentTrack()->addNode(tb); tb->drop(); } else @@ -121,7 +122,7 @@ namespace Scripting -1, // id GUIEngine::getSkin()->getColor("font::bottom"), GUIEngine::getSkin()->getColor("font::top")); - World::getWorld()->getTrack()->addNode(sn); + ::Track::getCurrentTrack()->addNode(sn); } #endif } @@ -155,7 +156,7 @@ namespace Scripting void setFog(float maxDensity, float start, float end, int r, int g, int b, float duration) { PropertyAnimator* animator = PropertyAnimator::get(); - ::Track* track = World::getWorld()->getTrack(); + ::Track* track = ::Track::getCurrentTrack(); animator->add( new AnimatedProperty(FOG_MAX, 1, new double[1] { track->getFogMax() }, diff --git a/src/states_screens/grand_prix_lose.cpp b/src/states_screens/grand_prix_lose.cpp index 6a86893dd..25ea129f5 100644 --- a/src/states_screens/grand_prix_lose.cpp +++ b/src/states_screens/grand_prix_lose.cpp @@ -161,7 +161,7 @@ void GrandPrixLose::onUpdate(float dt) void GrandPrixLose::setKarts(std::vector ident_arg) { - TrackObjectManager* tobjman = World::getWorld()->getTrack()->getTrackObjectManager(); + TrackObjectManager* tobjman = Track::getCurrentTrack()->getTrackObjectManager(); assert(ident_arg.size() > 0); if ((int)ident_arg.size() > MAX_KART_COUNT) diff --git a/src/states_screens/grand_prix_win.cpp b/src/states_screens/grand_prix_win.cpp index d124a9584..ba6ed064f 100644 --- a/src/states_screens/grand_prix_win.cpp +++ b/src/states_screens/grand_prix_win.cpp @@ -292,9 +292,10 @@ void GrandPrixWin::onUpdate(float dt) void GrandPrixWin::setKarts(const std::string idents_arg[3]) { - TrackObjectManager* tobjman = World::getWorld()->getTrack()->getTrackObjectManager(); + TrackObjectManager* tobjman = Track::getCurrentTrack()->getTrackObjectManager(); - // reorder in "podium order" (i.e. second player to the left, first player in the middle, last at the right) + // reorder in "podium order" (i.e. second player to the left, first player + // in the middle, last at the right) std::string idents[3]; idents[0] = idents_arg[1]; idents[1] = idents_arg[0]; diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index fdcc68d25..a041dd930 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -216,7 +216,7 @@ void RaceGUI::renderGlobal(float dt) drawGlobalMiniMap(); if (!m_is_tutorial) drawGlobalPlayerIcons(m_map_height); - if(world->getTrack()->isSoccer()) drawScores(); + if(Track::getCurrentTrack()->isSoccer()) drawScores(); #endif } // renderGlobal @@ -378,10 +378,9 @@ void RaceGUI::drawGlobalTimer() void RaceGUI::drawGlobalMiniMap() { #ifndef SERVER_ONLY - World *world = World::getWorld(); // draw a map when arena has a navigation mesh. - if ((world->getTrack()->isArena() || world->getTrack()->isSoccer()) && - !(world->getTrack()->hasNavMesh())) + Track *track = Track::getCurrentTrack(); + if ( (track->isArena() || track->isSoccer()) && !(track->hasNavMesh()) ) return; int upper_y = irr_driver->getActualScreenSize().Height - m_map_bottom - m_map_height; @@ -390,8 +389,9 @@ void RaceGUI::drawGlobalMiniMap() core::rect dest(m_map_left, upper_y, m_map_left + m_map_width, lower_y); - world->getTrack()->drawMiniMap(dest); + track->drawMiniMap(dest); + World *world = World::getWorld(); for(unsigned int i=0; igetNumKarts(); i++) { const AbstractKart *kart = world->getKart(i); @@ -401,7 +401,7 @@ void RaceGUI::drawGlobalMiniMap() if(kart->isEliminated() && !(sta && sta->isMoving())) continue; const Vec3& xyz = kart->getXYZ(); Vec3 draw_at; - world->getTrack()->mapPoint2MiniMap(xyz, &draw_at); + track->mapPoint2MiniMap(xyz, &draw_at); draw_at *= UserConfigParams::m_scale_rtts_factor; video::ITexture* icon = sta ? @@ -424,7 +424,7 @@ void RaceGUI::drawGlobalMiniMap() if (sw) { Vec3 draw_at; - world->getTrack()->mapPoint2MiniMap(sw->getBallPosition(), &draw_at); + track->mapPoint2MiniMap(sw->getBallPosition(), &draw_at); draw_at *= UserConfigParams::m_scale_rtts_factor; video::ITexture* icon = irr_driver->getTexture(FileManager::GUI, "soccer_ball_normal.png"); diff --git a/src/states_screens/race_gui_base.cpp b/src/states_screens/race_gui_base.cpp index 3b28e7af1..800d68290 100644 --- a/src/states_screens/race_gui_base.cpp +++ b/src/states_screens/race_gui_base.cpp @@ -740,7 +740,7 @@ void RaceGUIBase::drawGlobalPlayerIcons(int bottom_margin) LinearWorld *linear_world = (LinearWorld*)(World::getWorld()); float distance = linear_world->getDistanceDownTrackForKart(kart_id) - + linear_world->getTrack()->getTrackLength()*lap; + + Track::getCurrentTrack()->getTrackLength()*lap; if ((position>1) && (previous_distance-distancehasFinishedRace()) ) diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index bc5bcb4a1..5ed8ac3bd 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -303,9 +303,9 @@ void RaceGUIOverworld::drawGlobalMiniMap() #ifndef SERVER_ONLY World *world = World::getWorld(); // arenas currently don't have a map. - if(world->getTrack()->isArena() || world->getTrack()->isSoccer()) return; + Track* track = Track::getCurrentTrack(); + if(track->isArena() || track->isSoccer()) return; - Track* track = world->getTrack(); const std::vector& challenges = track->getChallengeList(); @@ -332,7 +332,7 @@ void RaceGUIOverworld::drawGlobalMiniMap() core::rect dest(m_map_left, upper_y, m_map_left + m_map_width, lower_y); - world->getTrack()->drawMiniMap(dest); + track->drawMiniMap(dest); Vec3 kart_xyz; diff --git a/src/tracks/ambient_light_sphere.cpp b/src/tracks/ambient_light_sphere.cpp index 806bd6f48..bf31836c3 100644 --- a/src/tracks/ambient_light_sphere.cpp +++ b/src/tracks/ambient_light_sphere.cpp @@ -24,7 +24,6 @@ #include "graphics/camera.hpp" #include "io/xml_node.hpp" #include "karts/abstract_kart.hpp" -#include "modes/world.hpp" #include "race/race_manager.hpp" #include "tracks/track.hpp" @@ -47,7 +46,6 @@ void AmbientLightSphere::update(float dt) { CheckStructure::update(dt); - World *world = World::getWorld(); for(unsigned int i=0; igetTrack(); + Track *track=Track::getCurrentTrack(); if(d2 use new ambient color color = m_ambient_color; diff --git a/src/tracks/check_lap.cpp b/src/tracks/check_lap.cpp index b6f9ed460..ab2d4bb1c 100644 --- a/src/tracks/check_lap.cpp +++ b/src/tracks/check_lap.cpp @@ -64,7 +64,7 @@ bool CheckLap::isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, World* w = World::getWorld(); LinearWorld* lin_world = dynamic_cast(w); - float track_length = w->getTrack()->getTrackLength(); + float track_length = Track::getCurrentTrack()->getTrackLength(); // Can happen if a non-lap based race mode is used with a scene file that // has check defined. if(!lin_world) diff --git a/src/tracks/graph.cpp b/src/tracks/graph.cpp index d4953e60f..cc862cade 100644 --- a/src/tracks/graph.cpp +++ b/src/tracks/graph.cpp @@ -246,7 +246,7 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, const video::SColor oldClearColor = irr_driver->getClearColor(); irr_driver->setClearbackBufferColor(video::SColor(0, 255, 255, 255)); - World::getWorld()->getTrack()->forceFogDisabled(true); + Track::getCurrentTrack()->forceFogDisabled(true); #ifndef SERVER_ONLY m_render_target = irr_driver->createRenderTarget(dimension, name); #endif @@ -331,7 +331,7 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, irr_driver->removeCameraSceneNode(camera); irr_driver->setClearbackBufferColor(oldClearColor); - World::getWorld()->getTrack()->forceFogDisabled(false); + Track::getCurrentTrack()->forceFogDisabled(false); irr_driver->getSceneManager()->clear(); VAOManager::kill(); diff --git a/src/tracks/terrain_info.cpp b/src/tracks/terrain_info.cpp index e90527a51..e37bb712a 100644 --- a/src/tracks/terrain_info.cpp +++ b/src/tracks/terrain_info.cpp @@ -18,7 +18,6 @@ #include "tracks/terrain_info.hpp" -#include "modes/world.hpp" #include "physics/triangle_mesh.hpp" #include "race/race_manager.hpp" #include "tracks/track.hpp" @@ -58,11 +57,11 @@ void TerrainInfo::update(const Vec3 &from) btVector3 to(from); to.setY(-10000.0f); - const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh(); + const TriangleMesh &tm = Track::getCurrentTrack()->getTriangleMesh(); tm.castRay(from, to, &m_hit_point, &m_material, &m_normal, /*interpolate*/false); // Now also raycast against all track objects (that are driveable). - World::getWorld()->getTrack()->getTrackObjectManager() + Track::getCurrentTrack()->getTrackObjectManager() ->castRay(from, to, &m_hit_point, &m_material, &m_normal, /*interpolate*/false); } // update @@ -83,15 +82,15 @@ void TerrainInfo::update(const btMatrix3x3 &rotation, const Vec3 &from) btVector3 to(0, -10000.0f, 0); to = from + rotation*to; - const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh(); + const TriangleMesh &tm = Track::getCurrentTrack()->getTriangleMesh(); tm.castRay(from, to, &m_hit_point, &m_material, &m_normal, /*interpolate*/true); // Now also raycast against all track objects (that are driveable). If // there should be a closer result (than the one against the main track // mesh), its data will be returned. - World::getWorld()->getTrack()->getTrackObjectManager() - ->castRay(from, to, &m_hit_point, &m_material, - &m_normal, /*interpolate*/true); + Track::getCurrentTrack()->getTrackObjectManager() + ->castRay(from, to, &m_hit_point, &m_material, + &m_normal, /*interpolate*/true); } // update //----------------------------------------------------------------------------- /** Update the terrain information based on the latest position. @@ -103,7 +102,7 @@ void TerrainInfo::update(const Vec3 &from, const Vec3 &towards) Vec3 direction = towards.normalized(); btVector3 to = from + 10000.0f*direction; - const TriangleMesh &tm = World::getWorld()->getTrack()->getTriangleMesh(); + const TriangleMesh &tm = Track::getCurrentTrack()->getTriangleMesh(); tm.castRay(from, to, &m_hit_point, &m_material, &m_normal); } // update @@ -120,7 +119,7 @@ bool TerrainInfo::getSurfaceInfo(const Vec3 &from, Vec3 *position, const Material **material) { Vec3 to=from+Vec3(0, 10000, 0); - const TriangleMesh &tm = World::getWorld()->getTrack()->getGFXEffectMesh(); + const TriangleMesh &tm = Track::getCurrentTrack()->getGFXEffectMesh(); return tm.castRay(from, to, position, material); } // getSurfaceInfo diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 8956c56a2..e606d6522 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -86,6 +86,7 @@ using namespace irr; const float Track::NOHIT = -99999.9f; bool Track::m_dont_load_navmesh = false; +Track *Track::m_current_track = NULL; // ---------------------------------------------------------------------------- Track::Track(const std::string &filename) @@ -460,6 +461,8 @@ void Track::cleanup() Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); script_engine->cleanupCache(); + + m_current_track = NULL; } // cleanup //----------------------------------------------------------------------------- @@ -1578,6 +1581,8 @@ void Track::createWater(const XMLNode &node) */ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) { + assert(!m_current_track); + // Use m_filename to also get the path, not only the identifier irr_driver->setTextureErrorMessage("While loading track '%s'", m_filename ); @@ -1670,11 +1675,14 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) throw std::runtime_error(msg.str()); } + m_current_track = this; + // Load the graph only now: this function is called from world, after // the race gui was created. The race gui is needed since it stores // the information about the size of the texture to render the mini // map to. - if (!m_is_arena && !m_is_soccer && !m_is_cutscene) loadDriveGraph(mode_id, reverse_track); + if (!m_is_arena && !m_is_soccer && !m_is_cutscene) + loadDriveGraph(mode_id, reverse_track); else if ((m_is_arena || m_is_soccer) && !m_is_cutscene && m_has_navmesh) loadArenaGraph(*root); @@ -1738,6 +1746,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) } loadMainTrack(*root); + unsigned int main_track_count = (unsigned int)m_all_nodes.size(); ModelDefinitionLoader model_def_loader(this); @@ -1933,6 +1942,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) } irr_driver->unsetTextureErrorMessage(); + } // loadTrackModel //----------------------------------------------------------------------------- diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 21bd667e5..a137f9e02 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -54,7 +54,6 @@ class RenderTarget; class TrackObject; class TrackObjectManager; class TriangleMesh; -class World; class XMLNode; const int HEIGHT_MAP_RESOLUTION = 256; @@ -97,6 +96,10 @@ class Track { private: + /** If a race is in progress, this stores the active track object. + * NULL otherwise. */ + static Track *m_current_track; + #ifdef DEBUG unsigned int m_magic_number; #endif @@ -387,7 +390,10 @@ private: public: - bool reverseAvailable() const { return m_reverse_available; } + /** Static function to get the current track. NULL if no current + * track is defined (i.e. no race is active atm) */ + static Track* getCurrentTrack() { return m_current_track; } + // ------------------------------------------------------------------------ void handleAnimatedTextures(scene::ISceneNode *node, const XMLNode &xml); /** Flag to avoid loading navmeshes (useful to speedup debugging: e.g. @@ -440,6 +446,9 @@ public: /** Returns true if this track has easter eggs. */ bool hasEasterEggs() const { return m_has_easter_eggs; } // ------------------------------------------------------------------------ + /** Returns true if this race can be driven in reverse. */ + bool reverseAvailable() const { return m_reverse_available; } + // ------------------------------------------------------------------------ /** Returns true if this track navmesh. */ bool hasNavMesh() const { return m_has_navmesh; } // ------------------------------------------------------------------------ @@ -449,10 +458,6 @@ public: // ------------------------------------------------------------------------ bool isSoccer () const { return m_is_soccer; } // ------------------------------------------------------------------------ - void loadTrackModel (World* parent, - bool reverse_track = false, - unsigned int mode_id=0); - // ------------------------------------------------------------------------ void addMusic (MusicInformation* mi) {m_music.push_back(mi); } // ------------------------------------------------------------------------ diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index fa70762ad..2e1630b05 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -193,10 +193,7 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode( if (!model_def_loader.containsLibraryNode(name)) { - World* world = World::getWorld(); - Track* track = NULL; - if (world != NULL) - track = world->getTrack(); + Track* track = Track::getCurrentTrack(); std::string local_lib_node_path; std::string local_script_file_path; if (track != NULL) @@ -206,6 +203,7 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode( } std::string lib_node_path = lib_path + "node.xml"; std::string lib_script_file_path = lib_path + "scripting.as"; + World* world = World::getWorld(); if (local_lib_node_path.size() > 0 && file_manager->fileExists(local_lib_node_path)) { @@ -267,8 +265,9 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode( m_node->updateAbsolutePosition(); assert(libroot != NULL); - World::getWorld()->getTrack()->loadObjects(libroot, lib_path, model_def_loader, - create_lod_definitions, m_node, parent); + Track::getCurrentTrack()->loadObjects(libroot, lib_path, model_def_loader, + create_lod_definitions, m_node, + parent); m_parent = parent; } // TrackObjectPresentationLibraryNode @@ -494,9 +493,9 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node, m_force_always_hidden = true; m_frame_start = 0; m_frame_end = 0; - - if (World::getWorld() && World::getWorld()->getTrack() && xml_node) - World::getWorld()->getTrack()->addPhysicsOnlyNode(m_node); + Track *track = Track::getCurrentTrack(); + if (track && track && xml_node) + track->addPhysicsOnlyNode(m_node); } } else if (m_is_in_skybox) @@ -526,9 +525,9 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node, if (xml_node) xml_node->get("frame-end", &m_frame_end); - if (World::getWorld() && World::getWorld()->getTrack() && xml_node) - World::getWorld()->getTrack() - ->handleAnimatedTextures(m_node, *xml_node); + Track *track = Track::getCurrentTrack(); + if (track && track && xml_node) + track->handleAnimatedTextures(m_node, *xml_node); } else { @@ -547,9 +546,9 @@ void TrackObjectPresentationMesh::init(const XMLNode* xml_node, m_frame_start = 0; m_frame_end = 0; - if (World::getWorld() && World::getWorld()->getTrack() && xml_node) - World::getWorld()->getTrack() - ->handleAnimatedTextures(m_node, *xml_node); + Track *track = Track::getCurrentTrack(); + if (track && xml_node) + track->handleAnimatedTextures(m_node, *xml_node); } if(!enabled) @@ -674,7 +673,7 @@ TrackObjectPresentationSound::TrackObjectPresentationSound( xml_node.get("max_dist", &max_dist ); // first try track dir, then global dir - std::string soundfile = World::getWorld()->getTrack()->getTrackFile(sound); + std::string soundfile = Track::getCurrentTrack()->getTrackFile(sound); //std::string soundfile = file_manager->getAsset(FileManager::MODEL,sound); if (!file_manager->fileExists(soundfile)) { From b12453e9ca1612ad41c46ab675d87cdb84f082d4 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 13 Dec 2016 08:31:08 +1100 Subject: [PATCH 14/17] Made Physics a singleton, removing the accessor functions from World. Removes dependency on World for a few files. --- src/graphics/fixed_pipeline_renderer.cpp | 2 +- src/graphics/irr_driver.cpp | 4 ++-- src/graphics/post_processing.cpp | 2 +- src/graphics/shader_based_renderer.cpp | 13 +++++++------ src/items/flyable.cpp | 4 ++-- src/items/plunger.cpp | 5 ++--- src/items/rubber_band.cpp | 4 +--- src/karts/abstract_kart_animation.cpp | 5 ++--- src/karts/controller/spare_tire_ai.cpp | 2 +- src/karts/kart.cpp | 10 +++++----- src/karts/rescue_animation.cpp | 2 +- src/modes/world.cpp | 16 ++++++++-------- src/modes/world.hpp | 5 ----- src/network/rewind_info.cpp | 5 ++--- src/network/rewind_manager.cpp | 2 +- src/physics/physical_object.cpp | 21 ++++++++++----------- src/physics/physics.hpp | 14 +++++++++++--- src/physics/stk_dynamics_world.hpp | 4 ++++ src/physics/triangle_mesh.cpp | 10 +++++----- src/tracks/track.cpp | 2 +- src/utils/debug.cpp | 6 +++--- 21 files changed, 70 insertions(+), 68 deletions(-) diff --git a/src/graphics/fixed_pipeline_renderer.cpp b/src/graphics/fixed_pipeline_renderer.cpp index 99d68787c..8aab91030 100644 --- a/src/graphics/fixed_pipeline_renderer.cpp +++ b/src/graphics/fixed_pipeline_renderer.cpp @@ -71,7 +71,7 @@ void FixedPipelineRenderer::render(float dt) // is not set up properly. This is only used for // the bullet debug view. if (UserConfigParams::m_artist_debug_mode) - World::getWorld()->getPhysics()->draw(); + Physics::getInstance()->draw(); } // for igetNumKarts() // Set the viewport back to the full screen for race gui diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 63c0aa900..2396f28d0 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -2078,9 +2078,9 @@ void IrrDriver::update(float dt) GUIEngine::render(dt); } - if (world->getPhysics() != NULL) + if (Physics::getInstance()) { - IrrDebugDrawer* debug_drawer = world->getPhysics()->getDebugDrawer(); + IrrDebugDrawer* debug_drawer = Physics::getInstance()->getDebugDrawer(); if (debug_drawer != NULL && debug_drawer->debugEnabled()) { debug_drawer->beginNextFrame(); diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 784751940..0623a0619 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -1436,7 +1436,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, glDisable(GL_BLEND); World *world = World::getWorld(); - Physics *physics = world ? world->getPhysics() : NULL; + Physics *physics = Physics::getInstance(); if (isRace && UserConfigParams::m_dof && (physics == NULL || !physics->isDebug())) { diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index a383a7706..f174961ce 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -547,15 +547,16 @@ void ShaderBasedRenderer::debugPhysics() // the bullet debug view, since otherwise the camera // is not set up properly. This is only used for // the bullet debug view. - World *world = World::getWorld(); - if (UserConfigParams::m_artist_debug_mode) - world->getPhysics()->draw(); - if (world != NULL && world->getPhysics() != NULL) + if(Physics::getInstance()) { - IrrDebugDrawer* debug_drawer = world->getPhysics()->getDebugDrawer(); + if (UserConfigParams::m_artist_debug_mode) + Physics::getInstance()->draw(); + + IrrDebugDrawer* debug_drawer = Physics::getInstance()->getDebugDrawer(); if (debug_drawer != NULL && debug_drawer->debugEnabled()) { - const std::map >& lines = debug_drawer->getLines(); + const std::map >& lines = + debug_drawer->getLines(); std::map >::const_iterator it; Shaders::ColoredLine *line = Shaders::ColoredLine::getInstance(); diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index d0195ff17..e0b122844 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -133,7 +133,7 @@ void Flyable::createPhysics(float forw_offset, const Vec3 &velocity, m_shape = shape; createBody(m_mass, trans, m_shape, restitution); m_user_pointer.set(this); - World::getWorld()->getPhysics()->addBody(getBody()); + Physics::getInstance()->addBody(getBody()); m_body->setGravity(gravity); @@ -199,7 +199,7 @@ void Flyable::init(const XMLNode &node, scene::IMesh *model, Flyable::~Flyable() { if(m_shape) delete m_shape; - World::getWorld()->getPhysics()->removeBody(getBody()); + Physics::getInstance()->removeBody(getBody()); } // ~Flyable //----------------------------------------------------------------------------- diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 309be7b18..be863f551 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -28,7 +28,6 @@ #include "karts/abstract_kart.hpp" #include "karts/controller/controller.hpp" #include "karts/kart_properties.hpp" -#include "modes/world.hpp" #include "physics/physical_object.hpp" #include "physics/physics.hpp" #include "tracks/track.hpp" @@ -174,7 +173,7 @@ bool Plunger::hit(AbstractKart *kart, PhysicalObject *obj) m_keep_alive = 0; // Make this object invisible. getNode()->setVisible(false); - World::getWorld()->getPhysics()->removeBody(getBody()); + Physics::getInstance()->removeBody(getBody()); } else { @@ -188,7 +187,7 @@ bool Plunger::hit(AbstractKart *kart, PhysicalObject *obj) { node->setVisible(false); } - World::getWorld()->getPhysics()->removeBody(getBody()); + Physics::getInstance()->removeBody(getBody()); if(kart) { diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index e9245584b..6fad556cf 100644 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -29,7 +29,6 @@ #include "karts/abstract_kart.hpp" #include "karts/kart_properties.hpp" #include "karts/max_speed.hpp" -#include "modes/world.hpp" #include "physics/physics.hpp" #include "race/race_manager.hpp" #include "utils/string_utils.hpp" @@ -215,8 +214,7 @@ void RubberBand::checkForHit(const Vec3 &k, const Vec3 &p) m_owner->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = 0; // Do the raycast - World::getWorld()->getPhysics()->getPhysicsWorld()->rayTest(k, p, - ray_callback); + Physics::getInstance()->getPhysicsWorld()->rayTest(k, p, ray_callback); // Reset collision groups m_plunger->getBody()->getBroadphaseHandle()->m_collisionFilterGroup = old_plunger_group; if(m_owner->getBody()->getBroadphaseHandle()) diff --git a/src/karts/abstract_kart_animation.cpp b/src/karts/abstract_kart_animation.cpp index 5a10b9374..54cc9b09c 100644 --- a/src/karts/abstract_kart_animation.cpp +++ b/src/karts/abstract_kart_animation.cpp @@ -22,7 +22,6 @@ #include "karts/abstract_kart.hpp" #include "karts/kart_model.hpp" #include "karts/skidding.hpp" -#include "modes/world.hpp" #include "physics/physics.hpp" AbstractKartAnimation::AbstractKartAnimation(AbstractKart *kart, @@ -48,7 +47,7 @@ AbstractKartAnimation::AbstractKartAnimation(AbstractKart *kart, // Register this animation with the kart (which will free it // later). kart->setKartAnimation(this); - World::getWorld()->getPhysics()->removeKart(m_kart); + Physics::getInstance()->removeKart(m_kart); kart->getSkidding()->reset(); kart->getSlipstream()->reset(); if(kart->isSquashed()) @@ -74,7 +73,7 @@ AbstractKartAnimation::~AbstractKartAnimation() if(m_timer < 0) { m_kart->getBody()->setAngularVelocity(btVector3(0,0,0)); - World::getWorld()->getPhysics()->addKart(m_kart); + Physics::getInstance()->addKart(m_kart); } } // ~AbstractKartAnimation diff --git a/src/karts/controller/spare_tire_ai.cpp b/src/karts/controller/spare_tire_ai.cpp index b68faa386..2f4eb2f9d 100644 --- a/src/karts/controller/spare_tire_ai.cpp +++ b/src/karts/controller/spare_tire_ai.cpp @@ -113,7 +113,7 @@ void SpareTireAI::spawn(float time_to_last) findDefaultPath(); m_timer = time_to_last; - World::getWorld()->getPhysics()->addKart(m_kart); + Physics::getInstance()->addKart(m_kart); m_kart->startEngineSFX(); m_kart->getKartGFX()->reset(); m_kart->getNode()->setVisible(true); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 371ebd66c..b4d250c22 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -273,7 +273,7 @@ Kart::~Kart() // Ghost karts don't have a body if(m_body) { - World::getWorld()->getPhysics()->removeKart(this); + Physics::getInstance()->removeKart(this); delete m_vehicle; delete m_vehicle_raycaster; } @@ -310,8 +310,8 @@ void Kart::reset() // don't have one). if(m_body) { - World::getWorld()->getPhysics()->removeKart(this); - World::getWorld()->getPhysics()->addKart(this); + Physics::getInstance()->removeKart(this); + Physics::getInstance()->addKart(this); } m_min_nitro_time = 0.0f; @@ -671,7 +671,7 @@ void Kart::createPhysics() // Create the actual vehicle // ------------------------- m_vehicle_raycaster = - new btKartRaycaster(World::getWorld()->getPhysics()->getPhysicsWorld(), + new btKartRaycaster(Physics::getInstance()->getPhysicsWorld(), stk_config->m_smooth_normals && Track::getCurrentTrack()->smoothNormals()); m_vehicle = new btKart(m_body, m_vehicle_raycaster, this); @@ -1158,7 +1158,7 @@ void Kart::eliminate() { if (!getKartAnimation()) { - World::getWorld()->getPhysics()->removeKart(this); + Physics::getInstance()->removeKart(this); } if (m_stars_effect) { diff --git a/src/karts/rescue_animation.cpp b/src/karts/rescue_animation.cpp index dbec7ff01..06c7d2002 100644 --- a/src/karts/rescue_animation.cpp +++ b/src/karts/rescue_animation.cpp @@ -89,7 +89,7 @@ RescueAnimation::~RescueAnimation() { m_kart->getBody()->setLinearVelocity(btVector3(0,0,0)); m_kart->getBody()->setAngularVelocity(btVector3(0,0,0)); - World::getWorld()->getPhysics()->addKart(m_kart); + Physics::getInstance()->addKart(m_kart); for(unsigned int i=0; iloadScript(script_path, true); // Create the physics - m_physics = new Physics(); + Physics::getInstance(); unsigned int num_karts = race_manager->getNumberOfKarts(); //assert(num_karts > 0); @@ -489,9 +488,10 @@ World::~World() Camera::removeAllCameras(); projectile_manager->cleanup(); - // In case that the track is not found, m_physics is still undefined. - if(m_physics) - delete m_physics; + + // In case that the track is not found, Physics was not instantiated, + // but kill handles this correctly. + Physics::kill(); delete m_script_engine; @@ -654,7 +654,7 @@ void World::resetAllKarts() { // Reset the physics 'remaining' time to 0 so that the number // of timesteps is reproducible if doing a physics-based history run - getPhysics()->getPhysicsWorld()->resetLocalTime(); + Physics::getInstance()->getPhysicsWorld()->resetLocalTime(); // If track checking is requested, check all rescue positions if // they are high enough. @@ -727,7 +727,7 @@ void World::resetAllKarts() (*i)->getBody()->setGravity((*i)->getMaterial()->hasGravity() ? (*i)->getNormal() * -g : Vec3(0, -g, 0)); } - for(int i=0; i<60; i++) m_physics->update(1.f/60.f); + for(int i=0; i<60; i++) Physics::getInstance()->update(1.f/60.f); for ( KartList::iterator i=m_karts.begin(); i!=m_karts.end(); i++) { @@ -1002,7 +1002,7 @@ void World::update(float dt) if (!history->dontDoPhysics()) { - m_physics->update(dt); + Physics::getInstance()->update(dt); } PROFILER_PUSH_CPU_MARKER("World::update (weather)", 0x80, 0x7F, 0x00); diff --git a/src/modes/world.hpp b/src/modes/world.hpp index c3204c5f5..fbdca0382 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -41,7 +41,6 @@ class AbstractKart; class btRigidBody; class Controller; class PhysicalObject; -class Physics; namespace Scripting { @@ -95,7 +94,6 @@ protected: KartList m_karts; RandomGenerator m_random; - Physics* m_physics; AbstractKart* m_fastest_kart; /** Number of eliminated karts. */ int m_eliminated_karts; @@ -311,9 +309,6 @@ public: unsigned int getCurrentNumPlayers() const { return m_num_players - m_eliminated_players;} // ------------------------------------------------------------------------ - /** Returns a pointer to the physics. */ - Physics *getPhysics() const { return m_physics; } - // ------------------------------------------------------------------------ /** Returns a pointer to the Scripting Engine. */ Scripting::ScriptEngine *getScriptEngine() const { return m_script_engine; } diff --git a/src/network/rewind_info.cpp b/src/network/rewind_info.cpp index 4340f2457..ec9989afb 100644 --- a/src/network/rewind_info.cpp +++ b/src/network/rewind_info.cpp @@ -18,7 +18,6 @@ #include "network/rewind_info.hpp" -#include "modes/world.hpp" #include "physics/physics.hpp" /** Constructor for a state: it only takes the size, and allocates a buffer @@ -42,8 +41,8 @@ RewindInfoState::RewindInfoState(float time, Rewinder *rewinder, BareNetworkString *buffer, bool is_confirmed) : RewindInfoRewinder(time, rewinder, buffer, is_confirmed) { - m_local_physics_time = World::getWorld()->getPhysics()->getPhysicsWorld() - ->getLocalTime(); + m_local_physics_time = Physics::getInstance()->getPhysicsWorld() + ->getLocalTime(); } // RewindInfoState // ============================================================================ diff --git a/src/network/rewind_manager.cpp b/src/network/rewind_manager.cpp index 5e8504770..7d33a764a 100644 --- a/src/network/rewind_manager.cpp +++ b/src/network/rewind_manager.cpp @@ -322,7 +322,7 @@ void RewindManager::rewindTo(float rewind_time) // Now start the rewind with the full state: world->setTime(exact_rewind_time); float local_physics_time = state->getLocalPhysicsTime(); - world->getPhysics()->getPhysicsWorld()->setLocalTime(local_physics_time); + Physics::getInstance()->getPhysicsWorld()->setLocalTime(local_physics_time); // Restore all states from the current time - the full state of a race // will be potentially stored in several state objects. State can be NULL diff --git a/src/physics/physical_object.cpp b/src/physics/physical_object.cpp index 7480563eb..275d063bd 100644 --- a/src/physics/physical_object.cpp +++ b/src/physics/physical_object.cpp @@ -18,18 +18,12 @@ #include "physics/physical_object.hpp" -#include -#include -#include - -using namespace irr; - +#include "config/stk_config.hpp" #include "graphics/material.hpp" #include "graphics/material_manager.hpp" #include "graphics/mesh_tools.hpp" #include "io/file_manager.hpp" #include "io/xml_node.hpp" -#include "modes/world.hpp" #include "physics/physics.hpp" #include "physics/triangle_mesh.hpp" #include "tracks/track.hpp" @@ -40,6 +34,11 @@ using namespace irr; #include #include #include +using namespace irr; + +#include +#include +#include /** Creates a physical Settings object with the given type, radius and mass. */ @@ -180,7 +179,7 @@ PhysicalObject::PhysicalObject(bool is_dynamic, // ---------------------------------------------------------------------------- PhysicalObject::~PhysicalObject() { - World::getWorld()->getPhysics()->removeBody(m_body); + Physics::getInstance()->removeBody(m_body); delete m_body; delete m_motion_state; @@ -540,7 +539,7 @@ void PhysicalObject::init(const PhysicalObject::Settings& settings) m_body->setActivationState(DISABLE_DEACTIVATION); } - World::getWorld()->getPhysics()->addBody(m_body); + Physics::getInstance()->addBody(m_body); m_body_added = true; if(m_triangle_mesh) m_triangle_mesh->setBody(m_body); @@ -672,7 +671,7 @@ void PhysicalObject::removeBody() { if (m_body_added) { - World::getWorld()->getPhysics()->removeBody(m_body); + Physics::getInstance()->removeBody(m_body); m_body_added = false; } } // Remove body @@ -684,7 +683,7 @@ void PhysicalObject::addBody() if (!m_body_added) { m_body_added = true; - World::getWorld()->getPhysics()->addBody(m_body); + Physics::getInstance()->addBody(m_body); } } // Add body diff --git a/src/physics/physics.hpp b/src/physics/physics.hpp index ac0cf77f7..a5d1209b7 100644 --- a/src/physics/physics.hpp +++ b/src/physics/physics.hpp @@ -32,6 +32,7 @@ #include "physics/irr_debug_drawer.hpp" #include "physics/stk_dynamics_world.hpp" #include "physics/user_pointer.hpp" +#include "utils/singleton.hpp" class AbstractKart; class STKDynamicsWorld; @@ -41,6 +42,7 @@ class Vec3; * \ingroup physics */ class Physics : public btSequentialImpulseConstraintSolver + , public AbstractSingleton { private: /** Bullet can report the same collision more than once (up to 4 @@ -53,7 +55,8 @@ private: * overhead (since it will likely use a tree to sort the entries). * Considering that the number of collisions is usually rather small * a simple list and linear search is faster is is being used here. */ - class CollisionPair { + class CollisionPair + { private: /** The user pointer of the objects involved in this collision. */ const UserPointer *m_up[2]; @@ -140,14 +143,19 @@ private: /** Used in physics debugging to draw the physics world. */ IrrDebugDrawer *m_debug_drawer; + btCollisionDispatcher *m_dispatcher; btBroadphaseInterface *m_axis_sweep; btDefaultCollisionConfiguration *m_collision_conf; CollisionList m_all_collisions; + /** Singleton. */ + static Physics *m_physics; + + Physics(); + virtual ~Physics(); + friend class AbstractSingleton; public: - Physics (); - ~Physics (); void init (const Vec3 &min_world, const Vec3 &max_world); void addKart (const AbstractKart *k); void addBody (btRigidBody* b) {m_dynamics_world->addRigidBody(b);} diff --git a/src/physics/stk_dynamics_world.hpp b/src/physics/stk_dynamics_world.hpp index 3e2c4f11a..ada89138a 100644 --- a/src/physics/stk_dynamics_world.hpp +++ b/src/physics/stk_dynamics_world.hpp @@ -21,6 +21,10 @@ #include "btBulletDynamicsCommon.h" +/** A thin wrapper around bullet's btDiscreteDynamicsWorld. Used to + * be able to query and set the 'left over' time from a previous + * time step, which is needed for more precise rewind/replays. + */ class STKDynamicsWorld : public btDiscreteDynamicsWorld { public: diff --git a/src/physics/triangle_mesh.cpp b/src/physics/triangle_mesh.cpp index 36b403d8f..7533c31fa 100644 --- a/src/physics/triangle_mesh.cpp +++ b/src/physics/triangle_mesh.cpp @@ -18,13 +18,13 @@ #include "physics/triangle_mesh.hpp" -#include "btBulletDynamicsCommon.h" - -#include "modes/world.hpp" +#include "config/stk_config.hpp" #include "physics/physics.hpp" #include "utils/constants.hpp" #include "utils/time.hpp" +#include "btBulletDynamicsCommon.h" + #include // ----------------------------------------------------------------------------- @@ -190,7 +190,7 @@ void TriangleMesh::createPhysicalBody(btCollisionObject::CollisionFlags flags, m_collision_shape); info.m_restitution = 0.8f; m_body=new btRigidBody(info); - World::getWorld()->getPhysics()->addBody(m_body); + Physics::getInstance()->addBody(m_body); m_body->setUserPointer(&m_user_pointer); m_body->setCollisionFlags(m_body->getCollisionFlags() | @@ -210,7 +210,7 @@ void TriangleMesh::removeAll() // Don't free the physical body if it was created outside this object. if(m_body && m_free_body) { - World::getWorld()->getPhysics()->removeBody(m_body); + Physics::getInstance()->removeBody(m_body); delete m_body; delete m_motion_state; m_body = NULL; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index e606d6522..8b866fecd 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1183,7 +1183,7 @@ bool Track::loadMainTrack(const XMLNode &root) // could be relaxed to fix this, it is not certain how the physics // will handle items that are out of the AABB m_aabb_max.setY(m_aabb_max.getY()+30.0f); - World::getWorld()->getPhysics()->init(m_aabb_min, m_aabb_max); + Physics::getInstance()->init(m_aabb_min, m_aabb_max); ModelDefinitionLoader lodLoader(this); diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index f9d82f23d..0d7e351d1 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -230,7 +230,7 @@ bool handleContextMenuAction(s32 cmd_id) { World *world = World::getWorld(); - Physics *physics = world ? world->getPhysics() : NULL; + Physics *physics = Physics::getInstance(); switch(cmd_id) { case DEBUG_GRAPHICS_RELOAD_SHADERS: @@ -325,8 +325,8 @@ bool handleContextMenuAction(s32 cmd_id) { irr_driver->resetDebugModes(); - if (!world) return false; - Physics *physics = world->getPhysics(); + Physics *physics = Physics::getInstance(); + if (!physics) return false; physics->setDebugMode(IrrDebugDrawer::DM_NO_KARTS_GRAPHICS); break; } From 4d406490e1276ee887586ecbdfecd37cac4062e3 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 13 Dec 2016 09:18:59 +1100 Subject: [PATCH 15/17] Made ScriptingEngine a singleton and removed it from World, which reduces more dependencies on world. --- src/modes/world.cpp | 9 ++++---- src/modes/world.hpp | 10 +-------- src/physics/physics.cpp | 7 ++++--- src/physics/physics.hpp | 3 +++ src/scriptengine/script_engine.hpp | 21 ++++++++++++------- src/scriptengine/script_utils.cpp | 8 +++---- .../dialogs/scripting_console.cpp | 4 ++-- src/tracks/track.cpp | 9 +++----- src/tracks/track_object.cpp | 4 ++-- src/tracks/track_object_presentation.cpp | 10 ++++----- 10 files changed, 40 insertions(+), 45 deletions(-) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index ef607f0e9..0815022b2 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -167,7 +167,7 @@ void World::init() // Grab the track file Track *track = track_manager->getTrack(race_manager->getTrackName()); - m_script_engine = new Scripting::ScriptEngine(); + Scripting::ScriptEngine::getInstance(); if(!track) { std::ostringstream msg; @@ -177,7 +177,7 @@ void World::init() } std::string script_path = track->getTrackFile("scripting.as"); - m_script_engine->loadScript(script_path, true); + Scripting::ScriptEngine::getInstance()->loadScript(script_path, true); // Create the physics Physics::getInstance(); @@ -493,7 +493,7 @@ World::~World() // but kill handles this correctly. Physics::kill(); - delete m_script_engine; + Scripting::ScriptEngine::kill(); m_world = NULL; @@ -998,7 +998,8 @@ void World::update(float dt) PROFILER_POP_CPU_MARKER(); if(race_manager->isRecordingRace()) ReplayRecorder::get()->update(dt); - if (m_script_engine) m_script_engine->update(dt); + Scripting::ScriptEngine *script_engine = Scripting::ScriptEngine::getInstance(); + if (script_engine) script_engine->update(dt); if (!history->dontDoPhysics()) { diff --git a/src/modes/world.hpp b/src/modes/world.hpp index fbdca0382..ce149d099 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -122,9 +122,6 @@ protected: RaceManager::KartType type, PerPlayerDifficulty difficulty); - /**Pointer to scripting engine */ - Scripting::ScriptEngine* m_script_engine; - /** Pointer to the race GUI. The race GUI is handled by world. */ RaceGUIBase *m_race_gui; @@ -286,6 +283,7 @@ public: AbstractKart* getPlayerKart(unsigned int player) const; AbstractKart* getLocalPlayerKart(unsigned int n) const; virtual const btTransform &getStartTransform(int index); + void moveKartTo(AbstractKart* kart, const btTransform &t); // ------------------------------------------------------------------------ /** Returns a pointer to the race gui. */ RaceGUIBase *getRaceGUI() const { return m_race_gui;} @@ -309,12 +307,6 @@ public: unsigned int getCurrentNumPlayers() const { return m_num_players - m_eliminated_players;} // ------------------------------------------------------------------------ - /** Returns a pointer to the Scripting Engine. */ - Scripting::ScriptEngine *getScriptEngine() - const { return m_script_engine; } - // ------------------------------------------------------------------------ - void moveKartTo(AbstractKart* kart, const btTransform &t); - // ------------------------------------------------------------------------ /** The code that draws the timer should call this first to know * whether the game mode wants a timer drawn. */ virtual bool shouldDrawTimer() const diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index 56597a16a..bd3e92f55 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -169,7 +169,8 @@ void Physics::update(float dt) p->getContactPointCS(0), p->getUserPointer(1)->getPointerKart(), p->getContactPointCS(1) ); - Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); + Scripting::ScriptEngine* script_engine = + Scripting::ScriptEngine::getInstance(); int kartid1 = p->getUserPointer(0)->getPointerKart()->getWorldKartId(); int kartid2 = p->getUserPointer(1)->getPointerKart()->getWorldKartId(); script_engine->runFunction(false, "void onKartKartCollision(int, int)", @@ -184,7 +185,7 @@ void Physics::update(float dt) { // Kart hits physical object // ------------------------- - Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); + Scripting::ScriptEngine* script_engine = Scripting::ScriptEngine::getInstance(); AbstractKart *kart = p->getUserPointer(1)->getPointerKart(); int kartId = kart->getWorldKartId(); PhysicalObject* obj = p->getUserPointer(0)->getPointerPhysicalObject(); @@ -267,7 +268,7 @@ void Physics::update(float dt) { // Projectile hits physical object // ------------------------------- - Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); + Scripting::ScriptEngine* script_engine = Scripting::ScriptEngine::getInstance(); Flyable* flyable = p->getUserPointer(0)->getPointerFlyable(); PhysicalObject* obj = p->getUserPointer(1)->getPointerPhysicalObject(); std::string obj_id = obj->getID(); diff --git a/src/physics/physics.hpp b/src/physics/physics.hpp index a5d1209b7..9f6702a3b 100644 --- a/src/physics/physics.hpp +++ b/src/physics/physics.hpp @@ -154,7 +154,10 @@ private: Physics(); virtual ~Physics(); + + // Give the singleton access to the constructor friend class AbstractSingleton; + public: void init (const Vec3 &min_world, const Vec3 &max_world); void addKart (const AbstractKart *k); diff --git a/src/scriptengine/script_engine.hpp b/src/scriptengine/script_engine.hpp index 7ea19f96c..f542c8220 100644 --- a/src/scriptengine/script_engine.hpp +++ b/src/scriptengine/script_engine.hpp @@ -19,14 +19,15 @@ #ifndef HEADER_SCRIPT_ENGINE_HPP #define HEADER_SCRIPT_ENGINE_HPP -#include -#include -#include -#include - #include "scriptengine/script_utils.hpp" #include "utils/no_copy.hpp" #include "utils/ptr_vector.hpp" +#include "utils/singleton.hpp" + +#include +#include +#include +#include class TrackObjectPresentation; @@ -55,12 +56,16 @@ namespace Scripting ~PendingTimeout(); }; - class ScriptEngine + class ScriptEngine : public AbstractSingleton { + ScriptEngine(); + ~ScriptEngine(); + + // Give the singleton access to the constructor. + friend class AbstractSingleton; + public: - ScriptEngine(); - ~ScriptEngine(); void runFunction(bool warn_if_not_found, std::string function_name); void runFunction(bool warn_if_not_found, std::string function_name, diff --git a/src/scriptengine/script_utils.cpp b/src/scriptengine/script_utils.cpp index 18b3b3496..03f698569 100644 --- a/src/scriptengine/script_utils.cpp +++ b/src/scriptengine/script_utils.cpp @@ -22,7 +22,6 @@ #include "input/device_manager.hpp" #include "input/input_device.hpp" #include "input/input_manager.hpp" -#include "modes/world.hpp" #include "scriptengine/script_engine.hpp" #include "states_screens/dialogs/tutorial_message_dialog.hpp" #include "tracks/track.hpp" @@ -109,8 +108,7 @@ namespace Scripting /** Runs the script function specified by the given string */ void runScript(const std::string* str) { - ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); - script_engine->runFunction(true, *str); + ScriptEngine::getInstance()->runFunction(true, *str); } /** Generate a random integer value */ @@ -129,13 +127,13 @@ namespace Scripting /** Call a function after the specified delay */ void setTimeout(const std::string* callback_name, float delay) { - World::getWorld()->getScriptEngine()->addPendingTimeout(delay, *callback_name); + ScriptEngine::getInstance()->addPendingTimeout(delay, *callback_name); } /** Call a method from the given object after the specified delay */ void setTimeoutDelegate(asIScriptFunction* obj, float delay) { - World::getWorld()->getScriptEngine()->addPendingTimeout(delay, obj); + ScriptEngine::getInstance()->addPendingTimeout(delay, obj); } /** Log to the console */ diff --git a/src/states_screens/dialogs/scripting_console.cpp b/src/states_screens/dialogs/scripting_console.cpp index f7b7228f6..3e0770e58 100644 --- a/src/states_screens/dialogs/scripting_console.cpp +++ b/src/states_screens/dialogs/scripting_console.cpp @@ -21,7 +21,6 @@ #include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/text_box_widget.hpp" -#include "modes/world.hpp" #include "scriptengine/script_engine.hpp" #include "states_screens/state_manager.hpp" #include "utils/translation.hpp" @@ -80,7 +79,8 @@ void ScriptingConsole::runScript() core::stringw script = textCtrl->getText(); textCtrl->setText(L""); - World::getWorld()->getScriptEngine()->evalScript(core::stringc(script.c_str()).c_str()); + Scripting::ScriptEngine::getInstance() + ->evalScript(core::stringc(script.c_str()).c_str()); } // ----------------------------------------------------------------------------- diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 8b866fecd..6218111b8 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -458,9 +458,7 @@ void Track::cleanup() } #endif - Scripting::ScriptEngine* script_engine = - World::getWorld()->getScriptEngine(); - script_engine->cleanupCache(); + Scripting::ScriptEngine::getInstance()->cleanupCache(); m_current_track = NULL; } // cleanup @@ -1449,8 +1447,7 @@ void Track::update(float dt) { if (!m_startup_run) // first time running update = good point to run startup script { - Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); - script_engine->runFunction(false, "void onStart()"); + Scripting::ScriptEngine::getInstance()->runFunction(false, "void onStart()"); m_startup_run = true; } m_track_object_manager->update(dt); @@ -1769,7 +1766,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) model_def_loader.cleanLibraryNodesAfterLoad(); - World::getWorld()->getScriptEngine()->compileLoadedScripts(); + Scripting::ScriptEngine::getInstance()->compileLoadedScripts(); // Init all track objects m_track_object_manager->init(); diff --git a/src/tracks/track_object.cpp b/src/tracks/track_object.cpp index ebf01ff84..2869dedeb 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -27,7 +27,6 @@ #include "io/xml_node.hpp" #include "input/device_manager.hpp" #include "items/item_manager.hpp" -#include "modes/world.hpp" #include "physics/physical_object.hpp" #include "race/race_manager.hpp" #include "scriptengine/script_engine.hpp" @@ -364,7 +363,8 @@ void TrackObject::onWorldReady() else if (m_visibility_condition.size() > 0) { unsigned char result = -1; - Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine(); + Scripting::ScriptEngine* script_engine = + Scripting::ScriptEngine::getInstance(); std::ostringstream fn_signature; std::vector arguments; diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index 2e1630b05..c20ad6179 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -210,13 +210,13 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode( lib_path = track->getTrackFile("library/" + name); libroot = file_manager->createXMLTree(local_lib_node_path); if (track != NULL) - World::getWorld()->getScriptEngine()->loadScript(local_script_file_path, false); + Scripting::ScriptEngine::getInstance()->loadScript(local_script_file_path, false); } else if (file_manager->fileExists(lib_node_path)) { libroot = file_manager->createXMLTree(lib_node_path); if (track != NULL) - World::getWorld()->getScriptEngine()->loadScript(lib_script_file_path, false); + Scripting::ScriptEngine::getInstance()->loadScript(lib_script_file_path, false); } else { @@ -1098,13 +1098,11 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached() { if (!m_action_active) return; - Scripting::ScriptEngine* script_engine = - World::getWorld()->getScriptEngine(); m_action_active = false; // TODO: allow auto re-activating? int idKart = 0; Camera* camera = Camera::getActiveCamera(); if (camera != NULL && camera->getKart() != NULL) idKart = camera->getKart()->getWorldKartId(); - script_engine->runFunction(true, "void " + m_action + "(int)", - [=](asIScriptContext* ctx) { ctx->SetArgDWord(0, idKart); }); + Scripting::ScriptEngine::getInstance()->runFunction(true, "void " + m_action + "(int)", + [=](asIScriptContext* ctx) { ctx->SetArgDWord(0, idKart); }); } // onTriggerItemApproached From 32f2196201a8fdeb396884cf0cad052dfd0d6db3 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 13 Dec 2016 17:13:54 +1100 Subject: [PATCH 16/17] Removed unnecessary #include world.hpp. --- src/graphics/material.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index 653a8a43d..0d06343b4 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -35,9 +35,9 @@ #include "graphics/shaders.hpp" #include "graphics/texture_manager.hpp" #include "io/file_manager.hpp" +#include "race/race_manager.hpp" #include "io/xml_node.hpp" #include "utils/string_utils.hpp" -#include "modes/world.hpp" #include "tracks/track.hpp" #include "utils/log.hpp" #include "utils/vs.hpp" From 4ee6f6315f387caf8b3e5a0e756f08047c6389b6 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 13 Dec 2016 17:14:29 +1100 Subject: [PATCH 17/17] Made World::m_weather a singleton to further remove dependencies on World. --- src/graphics/post_processing.cpp | 11 +++-------- src/graphics/weather.cpp | 15 ++++++++------- src/graphics/weather.hpp | 6 +++--- src/modes/world.cpp | 11 ++++------- src/modes/world.hpp | 6 ------ src/modes/world_status.cpp | 8 ++++---- src/tracks/track.hpp | 2 +- 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 0623a0619..3ba0be240 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -1435,7 +1435,6 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); - World *world = World::getWorld(); Physics *physics = Physics::getInstance(); if (isRace && UserConfigParams::m_dof && (physics == NULL || !physics->isDebug())) @@ -1564,14 +1563,10 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, { PROFILER_PUSH_CPU_MARKER("- Lightning", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_LIGHTNING)); - if (World::getWorld() != NULL) + Weather* weather = Weather::getInstance(); + if ( weather && weather->shouldLightning() ) { - Weather* m_weather = World::getWorld()->getWeather(); - - if (m_weather != NULL && m_weather->shouldLightning()) - { - renderLightning(m_weather->getIntensity()); - } + renderLightning(weather->getIntensity()); } PROFILER_POP_CPU_MARKER(); } diff --git a/src/graphics/weather.cpp b/src/graphics/weather.cpp index 6941af4fb..f462bb591 100644 --- a/src/graphics/weather.cpp +++ b/src/graphics/weather.cpp @@ -20,24 +20,25 @@ #include "audio/sfx_manager.hpp" #include "graphics/weather.hpp" #include "modes/world.hpp" +#include "tracks/track.hpp" #include "utils/random_generator.hpp" -// The weather manager - -Weather::Weather(bool lightning, std::string sound) +/** The weather manager stores information about the weather. + */ +Weather::Weather() { - m_lightning_enabled = lightning; m_thunder_sound = NULL; m_weather_sound = NULL; m_lightning = 0.0f; - if (m_lightning_enabled) + if (Track::getCurrentTrack()->getWeatherLightning()) { m_thunder_sound = SFXManager::get()->createSoundSource("thunder"); } - if (sound != "") + const std::string &sound = Track::getCurrentTrack()->getWeatherSound(); + if (!sound.empty()) { m_weather_sound = SFXManager::get()->createSoundSource(sound); } @@ -61,7 +62,7 @@ Weather::~Weather() void Weather::update(float dt) { - if (!m_lightning_enabled) + if (!Track::getCurrentTrack()->getWeatherLightning()) return; if (World::getWorld()->getRaceGUI() == NULL) diff --git a/src/graphics/weather.hpp b/src/graphics/weather.hpp index eb5a64fde..aaaf26b56 100644 --- a/src/graphics/weather.hpp +++ b/src/graphics/weather.hpp @@ -19,13 +19,13 @@ #ifndef HEADER_WEATHER_HPP #define HEADER_WEATHER_HPP +#include "utils/singleton.hpp" #include class SFXBase; -class Weather +class Weather : public AbstractSingleton { - bool m_lightning_enabled; float m_next_lightning; float m_lightning; @@ -33,7 +33,7 @@ class Weather SFXBase* m_weather_sound; public: - Weather(bool lightning, std::string sound); + Weather(); virtual ~Weather(); void update(float dt); diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 0815022b2..2522369dd 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -130,7 +130,6 @@ World::World() : WorldStatus() m_self_destruct = false; m_schedule_tutorial = false; m_is_network_world = false; - m_weather = NULL; m_stop_music_when_dialog_open = true; @@ -234,8 +233,7 @@ void World::init() if (UserConfigParams::m_weather_effects) { - m_weather = new Weather(track->getWeatherLightning(), - track->getWeatherSound()); + Weather::getInstance(); // create Weather instance } } // init @@ -456,8 +454,7 @@ World::~World() delete m_race_gui; } - if (m_weather != NULL) - delete m_weather; + Weather::kill(); for ( unsigned int i = 0 ; i < m_karts.size() ; i++ ) { @@ -1007,9 +1004,9 @@ void World::update(float dt) } PROFILER_PUSH_CPU_MARKER("World::update (weather)", 0x80, 0x7F, 0x00); - if (UserConfigParams::m_graphical_effects && m_weather) + if (UserConfigParams::m_graphical_effects && Weather::getInstance()) { - m_weather->update(dt); + Weather::getInstance()->update(dt); } PROFILER_POP_CPU_MARKER(); diff --git a/src/modes/world.hpp b/src/modes/world.hpp index ce149d099..5626baa17 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -160,10 +160,6 @@ protected: /** Set when the world is online and counts network players. */ bool m_is_network_world; - /** Used to show weather graphical effects. */ - Weather* m_weather; - - virtual void onGo() OVERRIDE; /** Returns true if the race is over. Must be defined by all modes. */ virtual bool isRaceOver() = 0; @@ -333,8 +329,6 @@ public: bool isNetworkWorld() const { return m_is_network_world; } - /** Returns a pointer to the weather. */ - Weather* getWeather() {return m_weather;} }; // World #endif diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index 8bf2551be..4c0100d70 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -74,8 +74,8 @@ void WorldStatus::reset() if (UserConfigParams::m_race_now) { // Setup music and sound - if (World::getWorld()->getWeather() != NULL) - World::getWorld()->getWeather()->playSound(); + if (Weather::getInstance()) + Weather::getInstance()->playSound(); // Start engines for (unsigned int i = 0; i < World::getWorld()->getNumKarts(); i++) @@ -196,9 +196,9 @@ void WorldStatus::updateTime(const float dt) m_track_intro_sound->play(); } - if (World::getWorld()->getWeather() != NULL) + if (Weather::getInstance()) { - World::getWorld()->getWeather()->playSound(); + Weather::getInstance()->playSound(); } return; // Do not increase time diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index a137f9e02..db55fe6a0 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -552,7 +552,7 @@ public: // ------------------------------------------------------------------------ bool getWeatherLightning() {return m_weather_lightning;} // ------------------------------------------------------------------------ - std::string getWeatherSound() {return m_weather_sound;} + const std::string& getWeatherSound() {return m_weather_sound;} // ------------------------------------------------------------------------ ParticleKind* getSkyParticles () { return m_sky_particles; } // ------------------------------------------------------------------------