diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/soundext.cc | 67 | ||||
-rw-r--r-- | src/client/soundext.h | 2 |
2 files changed, 49 insertions, 20 deletions
diff --git a/src/client/soundext.cc b/src/client/soundext.cc index ed22612..397a420 100644 --- a/src/client/soundext.cc +++ b/src/client/soundext.cc @@ -56,7 +56,7 @@ void render_entity_sound(core::Entity *entity) return; } - if (!ext_render(entity) || (ext_render(entity)->distance() > core::range::fxdistance) || (!ext_render(entity)->power())) { + if (!ext_render(entity) || (ext_render(entity)->distance() > core::range::fxdistance)) { if (ext_sound(entity)) delete ext_sound(entity); return; @@ -97,6 +97,7 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun state_impulsestopbuffer = 0; state_jumpstartbuffer = 0; state_jumpstopbuffer = 0; + state_explosionbuffer = 0; state_engineloopbuffer = 0; state_engineloopsource = 0; @@ -126,6 +127,8 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun state_impulsestopbuffer = audio::Buffers::load("engines/impulse_stop00"); state_jumpstartbuffer = audio::Buffers::load("engines/jump_start00"); state_jumpstopbuffer = audio::Buffers::load("engines/jump_stop00"); + + state_explosionbuffer = audio::Buffers::load("fx/explosion01"); state_engineloopsource = audio::Sources::get(); state_engineeventsource = audio::Sources::get(); @@ -192,6 +195,7 @@ SoundExt::~SoundExt() state_impulsestopbuffer = 0; state_jumpstartbuffer = 0; state_jumpstopbuffer = 0; + state_explosionbuffer = 0; state_engineloopbuffer = 0; state_engineloopsource = 0; @@ -211,52 +215,52 @@ void SoundExt::frame(float elapsed) if (entity()->type() == core::Entity::Controlable) { // update engine sounds - core::EntityControlable *entity = static_cast<core::EntityControlable *>(this->entity()); + core::EntityControlable *controlable = static_cast<core::EntityControlable *>(this->entity()); - speed = entity->speed(); + speed = controlable->speed(); if (snd_doppler->value()) - velocity.assign(entity->axis().forward() * speed); + velocity.assign(controlable->axis().forward() * speed); - if (entity->state() == core::Entity::Impulse) { + if (controlable->state() == core::Entity::Impulse) { pitch = 1.0f; gain = 1.0f; } else { - pitch = 0.2f + entity->thrust() * 0.8f; + pitch = 0.2f + controlable->thrust() * 0.8f; gain = 1.0f; } - if (entity->state() == core::Entity::ImpulseInitiate) { + if (controlable->state() == core::Entity::ImpulseInitiate) { if (state_engineeventbuffer != state_impulsestartbuffer) { audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , - entity->axis().forward() * speed); + controlable->location() - controlable->axis().forward() * r , + controlable->axis().forward() * speed); state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestartbuffer); } - } else if (entity->state() == core::Entity::JumpInitiate) { + } else if (controlable->state() == core::Entity::JumpInitiate) { if (state_engineeventbuffer != state_jumpstartbuffer) { audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , - entity->axis().forward() * speed); + controlable->location() - controlable->axis().forward() * r , + controlable->axis().forward() * speed); state_engineeventbuffer = audio::play(state_engineeventsource, state_jumpstartbuffer); } - } else if (entity->state() == core::Entity::Jump) { + } else if (controlable->state() == core::Entity::Jump) { if (state_engineeventbuffer != state_jumpstopbuffer) { audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , - entity->axis().forward() * speed); + controlable->location() - controlable->axis().forward() * r , + controlable->axis().forward() * speed); state_engineeventbuffer = audio::play(state_engineeventsource, state_jumpstopbuffer); } - } else if (entity->state() == core::Entity::Impulse) { + } else if (controlable->state() == core::Entity::Impulse) { state_engineeventbuffer = state_impulseloopbuffer; @@ -264,12 +268,35 @@ void SoundExt::frame(float elapsed) state_engineloopbuffer = audio::loop(state_engineloopsource, state_impulseloopbuffer, pitch, 0); } pitch = 1.0f; + + } else if (controlable->state() == core::Entity::Destroyed) { + + if (state_engineloopbuffer) { + audio::stop(state_engineloopbuffer); + state_engineloopbuffer = 0; + } + if (state_engineeventbuffer != state_explosionbuffer) { + audio::update_source(state_engineeventsource, + controlable->location() - controlable->axis().forward() * r , + controlable->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); + } + pitch = 1.0f; + gain = 0.0f; // loop buffer gain + } else { if ((state_engineeventbuffer == state_impulsestartbuffer) || (state_engineeventbuffer == state_impulseloopbuffer)) { audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , - entity->axis().forward() * speed); + controlable->location() - controlable->axis().forward() * r , + controlable->axis().forward() * speed); state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestopbuffer); } state_engineeventbuffer = 0; @@ -280,10 +307,10 @@ void SoundExt::frame(float elapsed) } audio::update_source(state_engineloopsource, - entity->location() - entity->axis().forward() * r ,velocity, pitch, gain); + controlable->location() - controlable->axis().forward() * r ,velocity, pitch, gain); audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , velocity); + controlable->location() - controlable->axis().forward() * r , velocity); } else if (entity()->type() == core::Entity::Projectile) { diff --git a/src/client/soundext.h b/src/client/soundext.h index 2750afd..1cadae6 100644 --- a/src/client/soundext.h +++ b/src/client/soundext.h @@ -85,6 +85,8 @@ private: size_t state_jumpstartbuffer; /// index of the audio buffer containing the jump engine stop sound size_t state_jumpstopbuffer; + /// index of the audio buffer containing the explosion sound + size_t state_explosionbuffer; /// index of the audio buffer currently looping in enginesource size_t state_engineloopbuffer; |