Move creating rain to world class because now it doesn't depend on cameras.

This commit is contained in:
Deve 2014-08-30 18:08:23 +02:00
parent 52384f151c
commit d8f61e336e
6 changed files with 34 additions and 101 deletions

View File

@ -24,7 +24,6 @@
#include "audio/music_manager.hpp"
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/rain.hpp"
#include "io/xml_node.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/explosion_animation.hpp"
@ -52,7 +51,6 @@ Camera::Camera(int camera_index, AbstractKart* kart) : m_kart(NULL)
{
m_mode = CM_NORMAL;
m_index = camera_index;
m_rain = NULL;
m_original_kart = kart;
m_camera = irr_driver->addCameraSceneNode();
@ -92,7 +90,6 @@ Camera::Camera(int camera_index, AbstractKart* kart) : m_kart(NULL)
*/
Camera::~Camera()
{
if(m_rain) delete m_rain;
irr_driver->removeCameraSceneNode(m_camera);
if (s_active_camera == this)
@ -222,13 +219,6 @@ void Camera::setupCamera()
m_camera->setFOV(m_fov);
m_camera->setAspectRatio(m_aspect);
m_camera->setFarValue(World::getWorld()->getTrack()->getCameraFar());
if (UserConfigParams::m_weather_effects &&
World::getWorld()->getTrack()->getWeatherType() == WEATHER_RAIN)
{
m_rain = new Rain(this, NULL);
}
} // setupCamera
// ----------------------------------------------------------------------------
@ -530,12 +520,6 @@ void Camera::update(float dt)
getCameraSettings(&above_kart, &cam_angle, &side_way, &distance, &smoothing);
positionCamera(dt, above_kart, cam_angle, side_way, distance, smoothing);
}
if (UserConfigParams::m_graphical_effects && m_rain)
{
m_rain->setPosition( getCameraSceneNode()->getPosition() );
m_rain->update(dt);
} // UserConfigParams::m_graphical_effects
} // update
// ----------------------------------------------------------------------------

View File

@ -41,7 +41,6 @@ namespace irr
using namespace irr;
class AbstractKart;
class Rain;
/**
* \brief Handles the game camera
@ -120,10 +119,6 @@ private:
/** List of all cameras. */
static std::vector<Camera*> m_all_cameras;
/** Used to show rain graphical effects. */
Rain *m_rain;
/** A class that stores information about the different end cameras
* which can be specified in the scene.xml file. */
class EndCameraInformation

View File

@ -18,37 +18,17 @@
#include "audio/sfx_base.hpp"
#include "audio/sfx_manager.hpp"
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/gpuparticles.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/material.hpp"
#include "graphics/per_camera_node.hpp"
#include "graphics/rain.hpp"
#include "graphics/shaders.hpp"
#include "modes/world.hpp"
#include "states_screens/race_gui.hpp"
#include "utils/constants.hpp"
#include "utils/random_generator.hpp"
#include <ISceneManager.h>
#include <SMeshBuffer.h>
using namespace video;
using namespace scene;
using namespace core;
// The rain manager
Rain::Rain(Camera *camera, irr::scene::ISceneNode* parent) : m_thunder_sound(0)
Rain::Rain()
{
m_lightning = camera->getIndex()==0;
if (m_lightning)
m_thunder_sound = sfx_manager->createSoundSource("thunder");
m_thunder_sound = sfx_manager->createSoundSource("thunder");
m_rain_sound = sfx_manager->createSoundSource("rain");
if (m_rain_sound)
@ -57,25 +37,15 @@ Rain::Rain(Camera *camera, irr::scene::ISceneNode* parent) : m_thunder_sound(0)
m_rain_sound->play();
}
Material* m = material_manager->getMaterial("rain.png");
assert(m != NULL);
RandomGenerator g;
m_next_lightning = (float)g.get(35);
// RainNode *node = new RainNode(irr_driver->getSceneManager(), m->getTexture());
// m_node = irr_driver->addPerCameraNode(node, camera->getCameraSceneNode(), parent);
// m_node->setAutomaticCulling(0);
} // Rain
// ----------------------------------------------------------------------------
Rain::~Rain()
{
// m_node->drop(); // drop STK's reference
// m_node->remove(); // Then remove it from the scene graph.
if (m_lightning && m_thunder_sound != NULL)
if (m_thunder_sound != NULL)
sfx_manager->deleteSFX(m_thunder_sound);
if (m_rain_sound != NULL)
@ -86,36 +56,18 @@ Rain::~Rain()
void Rain::update(float dt)
{
if (m_lightning)
m_next_lightning -= dt;
if (m_next_lightning < 0.0f)
{
m_next_lightning -= dt;
if (m_next_lightning < 0.0f)
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
if (gui_base != NULL)
{
RaceGUIBase* gui_base = World::getWorld()->getRaceGUI();
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);
gui_base->doLightning();
if (m_thunder_sound) m_thunder_sound->play();
}
RandomGenerator g;
m_next_lightning = 35 + (float)g.get(35);
}
} // update
// ----------------------------------------------------------------------------
void Rain::setPosition(const core::vector3df& position)
{
// m_node->getChild()->setPosition(position);
} // setPosition
// ----------------------------------------------------------------------------
void Rain::setCamera(scene::ICameraSceneNode* camera)
{
// m_node->setCamera(camera);
}

View File

@ -19,36 +19,19 @@
#ifndef HEADER_RAIN_HPP
#define HEADER_RAIN_HPP
class Camera;
class PerCameraNode;
#include <vector3d.h>
namespace irr
{
namespace video { class SMaterial; class ITexture; }
namespace scene { class ICameraSceneNode; class ISceneNode; }
}
using namespace irr;
class SFXBase;
class Rain
{
PerCameraNode* m_node;
float m_next_lightning;
bool m_lightning;
SFXBase* m_thunder_sound;
SFXBase* m_rain_sound;
public:
Rain(Camera* camera, irr::scene::ISceneNode* parent);
Rain();
virtual ~Rain();
void update(float dt);
void setPosition(const irr::core::vector3df& position);
void setCamera(scene::ICameraSceneNode* camera);
};
#endif

View File

@ -121,6 +121,7 @@ World::World() : WorldStatus(), m_clear_color(255,100,101,140)
m_self_destruct = false;
m_schedule_tutorial = false;
m_is_network_world = false;
m_rain = NULL;
m_stop_music_when_dialog_open = true;
@ -195,6 +196,12 @@ void World::init()
ReplayPlay::get()->Load();
powerup_manager->updateWeightsForRace(num_karts);
if (UserConfigParams::m_weather_effects &&
m_track->getWeatherType() == WEATHER_RAIN)
{
m_rain = new Rain();
}
} // init
//-----------------------------------------------------------------------------
@ -262,7 +269,6 @@ void World::reset()
//Reset the Rubber Ball Collect Time to some negative value.
powerup_manager->setBallCollectTime(-100);
} // reset
//-----------------------------------------------------------------------------
@ -376,6 +382,9 @@ World::~World()
// gui and this must be deleted.
delete m_race_gui;
}
if (m_rain != NULL)
delete m_rain;
for ( unsigned int i = 0 ; i < m_karts.size() ; i++ )
delete m_karts[i];
@ -925,6 +934,11 @@ void World::update(float dt)
{
Camera::getCamera(i)->update(dt);
}
if (UserConfigParams::m_graphical_effects && m_rain)
{
m_rain->update(dt);
}
projectile_manager->update(dt);

View File

@ -28,6 +28,7 @@
#include <vector>
#include <stdexcept>
#include "graphics/rain.hpp"
#include "modes/world_status.hpp"
#include "race/highscores.hpp"
#include "states_screens/race_gui_base.hpp"
@ -161,6 +162,10 @@ protected:
/** Set when the world is online and counts network players. */
bool m_is_network_world;
/** Used to show rain graphical effects. */
Rain* m_rain;
virtual void onGo();
/** Returns true if the race is over. Must be defined by all modes. */