Handle lightning and sound in weather property

This commit is contained in:
Deve 2014-09-01 19:57:32 +02:00
parent 27fb1f6254
commit 7d0dec5c49
5 changed files with 54 additions and 51 deletions

View File

@ -26,10 +26,21 @@
// The rain manager
Rain::Rain()
Rain::Rain(bool lightning, std::string sound)
{
m_thunder_sound = sfx_manager->createSoundSource("thunder");
m_rain_sound = sfx_manager->createSoundSource("rain");
m_lightning = lightning;
m_thunder_sound = NULL;
m_weather_sound = NULL;
if (m_lightning)
{
m_thunder_sound = sfx_manager->createSoundSource("thunder");
}
if (sound != "")
{
m_weather_sound = sfx_manager->createSoundSource(sound);
}
RandomGenerator g;
m_next_lightning = (float)g.get(35);
@ -42,27 +53,35 @@ Rain::~Rain()
if (m_thunder_sound != NULL)
sfx_manager->deleteSFX(m_thunder_sound);
if (m_rain_sound != NULL)
sfx_manager->deleteSFX(m_rain_sound);
if (m_weather_sound != NULL)
sfx_manager->deleteSFX(m_weather_sound);
}
// ----------------------------------------------------------------------------
void Rain::update(float dt)
{
m_next_lightning -= dt;
if (m_next_lightning < 0.0f)
if (m_lightning)
{
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
if (gui_base != NULL)
m_next_lightning -= dt;
if (m_next_lightning < 0.0f)
{
gui_base->doLightning();
if (m_thunder_sound) m_thunder_sound->play();
}
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
RandomGenerator g;
m_next_lightning = 35 + (float)g.get(35);
if (gui_base != NULL)
{
gui_base->doLightning();
if (m_thunder_sound)
{
m_thunder_sound->play();
}
}
RandomGenerator g;
m_next_lightning = 35 + (float)g.get(35);
}
}
} // update
@ -70,9 +89,9 @@ void Rain::update(float dt)
void Rain::playSound()
{
if (m_rain_sound)
if (m_weather_sound)
{
m_rain_sound->setLoop(true);
m_rain_sound->play();
m_weather_sound->setLoop(true);
m_weather_sound->play();
}
}

View File

@ -23,12 +23,14 @@ class SFXBase;
class Rain
{
bool m_lightning;
float m_next_lightning;
SFXBase* m_thunder_sound;
SFXBase* m_rain_sound;
SFXBase* m_weather_sound;
public:
Rain();
Rain(bool lightning, std::string sound);
virtual ~Rain();
void update(float dt);

View File

@ -197,10 +197,10 @@ void World::init()
powerup_manager->updateWeightsForRace(num_karts);
if (UserConfigParams::m_weather_effects &&
m_track->getWeatherType() == WEATHER_RAIN)
if (UserConfigParams::m_weather_effects)
{
m_rain = new Rain();
m_rain = new Rain(m_track->getWeatherLightning(),
m_track->getWeatherSound());
}
} // init

View File

@ -134,7 +134,8 @@ Track::Track(const std::string &filename)
m_sky_dy = 0.0f;
m_godrays_opacity = 1.0f;
m_godrays_color = video::SColor(255, 255, 255, 255);
m_weather_type = WEATHER_NONE;
m_weather_lightning = false;
m_weather_sound = "";
m_cache_track = UserConfigParams::m_cache_overworld &&
m_ident=="overworld";
m_minimap_x_scale = 1.0f;
@ -2101,32 +2102,16 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, ModelDefin
else if (name == "weather")
{
std::string weather_particles;
std::string weather_type;
node->get("particles", &weather_particles);
node->get("type", &weather_type);
node->get("lightning", &m_weather_lightning);
node->get("sound", &m_weather_sound);
if (weather_particles.size() > 0)
{
if (weather_particles == "rain.xml")
{
m_weather_type = WEATHER_RAIN;
}
m_sky_particles =
ParticleKindManager::get()->getParticles(weather_particles);
}
else if (weather_type.size() > 0)
{
if (weather_type == "rain")
{
m_weather_type = WEATHER_RAIN;
}
else
{
Log::error("track", "Unknown weather type : '%s'",
weather_type.c_str());
}
}
else
{
Log::error("track", "Bad weather node found - ignored.\n");

View File

@ -62,12 +62,6 @@ class XMLNode;
const int HEIGHT_MAP_RESOLUTION = 256;
enum WeatherType
{
WEATHER_NONE,
WEATHER_RAIN
};
struct OverworldForceField
{
core::vector3df m_position;
@ -310,7 +304,8 @@ private:
ParticleKind* m_sky_particles;
/** Use a special built-in wheather */
WeatherType m_weather_type;
bool m_weather_lightning;
std::string m_weather_sound;
/** A simple class to keep information about a track mode. */
class TrackMode
@ -566,7 +561,9 @@ public:
unsigned int getNumberOfStartPositions() const
{ return m_start_transforms.size(); }
// ------------------------------------------------------------------------
WeatherType getWeatherType () const { return m_weather_type; }
bool getWeatherLightning() {return m_weather_lightning;}
// ------------------------------------------------------------------------
std::string getWeatherSound() {return m_weather_sound;}
// ------------------------------------------------------------------------
ParticleKind* getSkyParticles () { return m_sky_particles; }
// ------------------------------------------------------------------------