From 93bb759aeb71537a98386693918b28b37961a103 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 23 Nov 2013 14:02:14 +0000 Subject: Support for EntityDynamic explosion sounds, minor SoundExt cleanups. --- src/client/soundext.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++----- src/client/soundext.h | 2 ++ src/client/targets.cc | 2 +- 3 files changed, 56 insertions(+), 7 deletions(-) (limited to 'src/client') diff --git a/src/client/soundext.cc b/src/client/soundext.cc index 397a420..09c83d8 100644 --- a/src/client/soundext.cc +++ b/src/client/soundext.cc @@ -98,6 +98,7 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun state_jumpstartbuffer = 0; state_jumpstopbuffer = 0; state_explosionbuffer = 0; + state_projectilebuffer = 0; state_engineloopbuffer = 0; state_engineloopsource = 0; @@ -132,20 +133,23 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun state_engineloopsource = audio::Sources::get(); state_engineeventsource = audio::Sources::get(); - + + } else if (entity->type() == core::Entity::Dynamic) { + + state_explosionbuffer = audio::Buffers::load("fx/explosion01"); } else if (entity->type() == core::Entity::Projectile) { core::EntityProjectile *projectile = static_cast(entity); // if the sound name is set if (projectile->projectile_soundname().size()) { - state_impulsestartbuffer = audio::Buffers::load("projectiles/" + projectile->projectile_soundname()); + state_projectilebuffer = audio::Buffers::load("projectiles/" + projectile->projectile_soundname()); // if the sound file was loaded - if (state_impulsestartbuffer) { + if (state_projectilebuffer) { state_engineeventsource = audio::Sources::get(); // of the OpenAL source is available if (state_engineeventsource) { - audio::update_source(state_engineeventsource, entity->location(), math::Vector3f()); - audio::play(state_engineeventsource, state_impulsestartbuffer); + audio::update_source(state_engineeventsource, entity->location(), math::Vector3f(), 1.0f, 1.0f); + audio::play(state_engineeventsource, state_projectilebuffer); } } } @@ -272,7 +276,7 @@ void SoundExt::frame(float elapsed) } else if (controlable->state() == core::Entity::Destroyed) { if (state_engineloopbuffer) { - audio::stop(state_engineloopbuffer); + audio::stop(state_engineloopsource); state_engineloopbuffer = 0; } if (state_engineeventbuffer != state_explosionbuffer) { @@ -311,6 +315,49 @@ void SoundExt::frame(float elapsed) audio::update_source(state_engineeventsource, controlable->location() - controlable->axis().forward() * r , velocity); + + } else if (entity()->type() == core::Entity::Dynamic) { + + core::EntityDynamic *dynamic = static_cast(this->entity()); + + speed = dynamic->speed(); + + if (snd_doppler->value()) { + velocity.assign(dynamic->axis().forward() * speed); + } + + if (dynamic->state() == core::Entity::Destroyed) { + if (!state_engineeventsource) { + state_engineeventsource = audio::Sources::get(); + } + + if (state_engineeventbuffer != state_explosionbuffer) { + audio::update_source(state_engineeventsource, + dynamic->location() - dynamic->axis().forward() * r , + dynamic->axis().forward() * speed); + // pack random explosion sound + if (math::randomf(100.0f) < 50.0f) { + state_explosionbuffer = audio::Buffers::load("fx/explosion01"); + } else { + state_explosionbuffer = audio::Buffers::load("fx/explosion02"); + } + state_engineeventbuffer = audio::play(state_engineeventsource, state_explosionbuffer); + } + } else { + if (state_engineeventbuffer) { + audio::stop(state_engineeventsource); + state_engineloopbuffer = 0; + } + if (state_engineeventsource) { + audio::Sources::remove(state_engineeventsource); + state_engineeventsource = 0; + } + } + + if (state_engineeventbuffer) { + audio::update_source(state_engineeventsource, + dynamic->location() - dynamic->axis().forward() * r , velocity, 1.0f, 1.0f); + } } else if (entity()->type() == core::Entity::Projectile) { diff --git a/src/client/soundext.h b/src/client/soundext.h index 1cadae6..6616b89 100644 --- a/src/client/soundext.h +++ b/src/client/soundext.h @@ -87,6 +87,8 @@ private: size_t state_jumpstopbuffer; /// index of the audio buffer containing the explosion sound size_t state_explosionbuffer; + /// index of the audio buffer containing the projetile sound + size_t state_projectilebuffer; /// index of the audio buffer currently looping in enginesource size_t state_engineloopbuffer; diff --git a/src/client/targets.cc b/src/client/targets.cc index 466b4a9..a35ebe7 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -515,7 +515,7 @@ void frame() core::Entity *entity = (*it); // render entity sound - if ((entity->type() == core::Entity::Controlable) || (entity->type() == core::Entity::Projectile) || (entity->model() && entity->model()->sounds().size())) { + if ((entity->type() == core::Entity::Dynamic) || (entity->type() == core::Entity::Controlable) || (entity->type() == core::Entity::Projectile) || (entity->model() && entity->model()->sounds().size())) { render_entity_sound(entity); } -- cgit v1.2.3