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; } // ------------------------------------------------------------------------