Made World::m_weather a singleton to further remove dependencies on World.

This commit is contained in:
hiker 2016-12-13 17:14:29 +11:00
parent 32f2196201
commit 4ee6f6315f
7 changed files with 23 additions and 36 deletions

View File

@ -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();
}

View File

@ -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)

View File

@ -19,13 +19,13 @@
#ifndef HEADER_WEATHER_HPP
#define HEADER_WEATHER_HPP
#include "utils/singleton.hpp"
#include <vector3d.h>
class SFXBase;
class Weather
class Weather : public AbstractSingleton<Weather>
{
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);

View File

@ -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<Weather>(); // 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();

View File

@ -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

View File

@ -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

View File

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