Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio/audio.cc15
-rw-r--r--src/audio/audio.h3
-rw-r--r--src/client/soundext.cc67
-rw-r--r--src/client/soundext.h2
4 files changed, 67 insertions, 20 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 304174c..3f505c0 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -193,6 +193,21 @@ size_t loop(size_t source_index, size_t buffer_index, float pitch, float gain)
return buffer_index;
}
+size_t stop(size_t source_index)
+{
+ if (!audio_initialized)
+ return 0;
+
+ ALuint source = Sources::source(source_index);
+ ALint srcstate = 0;
+ alGetSourcei(source , AL_SOURCE_STATE , &srcstate);
+ if (srcstate == AL_PLAYING) {
+ alSourceStop(source);
+ }
+
+ return source_index;
+}
+
size_t loop(size_t source_index, const char *name, float pitch, float gain)
{
if (!audio_initialized)
diff --git a/src/audio/audio.h b/src/audio/audio.h
index bab3402..f95e872 100644
--- a/src/audio/audio.h
+++ b/src/audio/audio.h
@@ -54,6 +54,9 @@ size_t loop(size_t source_index, const char *name, float pitch = 1.0f, float gai
/// play a looping sound from a specified buffer on a specified source
size_t loop(size_t source_index, size_t buffer_index, float pitch, float gain);
+/// stop playback of a specific source
+size_t stop(size_t source_index);
+
/// update source parameters
void update_source(size_t source_index, math::Vector3f const & location, math::Vector3f const & velocity, float pitch = 1.0f, float gain = 1.0f);
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;