Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-02-25 22:24:25 +0000
committerStijn Buys <ingar@osirion.org>2010-02-25 22:24:25 +0000
commit11a5ebe38a83383970425baf53d4595ae56efe70 (patch)
tree99c59f3cd07c829122c2673563a8e32388aefdd5 /src/client/soundext.cc
parent90fbc4c5caf5afd54920894319448b74967399ba (diff)
looped sound support for fx_sound model tags
Diffstat (limited to 'src/client/soundext.cc')
-rw-r--r--src/client/soundext.cc77
1 files changed, 68 insertions, 9 deletions
diff --git a/src/client/soundext.cc b/src/client/soundext.cc
index 04c37f9..d05d20e 100644
--- a/src/client/soundext.cc
+++ b/src/client/soundext.cc
@@ -27,13 +27,14 @@ core::Cvar *snd_engines = 0;
core::Cvar *snd_volume = 0;
float master_volume = 0;
+
void render_listener_sound()
{
if (!(snd_engines && snd_engines->value()))
return;
math::Vector3f velocity(0, 0 , 0);
- if (core::localcontrol()) {
+ if (snd_doppler->value() && core::localcontrol()) {
velocity.assign(core::localcontrol()->axis().forward() * core::localcontrol()->speed());
}
@@ -67,6 +68,24 @@ void render_entity_sound(core::Entity *entity)
}
}
+Sound::Sound()
+{
+ sound_source = 0;
+ sound_buffer = 0;
+
+}
+
+Sound::Sound(const std::string & name)
+{
+ sound_source = 0;
+ sound_buffer = 0;
+
+ if (name.size()) {
+ sound_source = audio::Sources::get();
+ sound_buffer = audio::Buffers::load(name.c_str());
+ }
+}
+
SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Sound, entity)
{
state_thusterloopbuffer = 0;
@@ -92,7 +111,6 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun
impulsesoundset = entityco->model()->impulsesound();
}
-
std::stringstream soundname;
soundname << "engines/loop" << std::setfill('0') << std::setw(2) << enginesoundset;
state_thusterloopbuffer = audio::Buffers::load(soundname.str());
@@ -106,6 +124,25 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun
state_engineloopsource = audio::Sources::get();
state_engineeventsource = audio::Sources::get();
}
+
+ // load model sounds
+ // TODO only sound loops for now
+ if (entity->model() && entity->model()->sounds().size()) {
+
+ for (model::Model::Sounds::iterator it = entity->model()->sounds().begin();
+ it != entity->model()->sounds().end(); it++) {
+
+ model::Sound *tag = (*it);
+ client::Sound *sound = new client::Sound(tag->name());
+ sound->set_location(tag->location());
+ state_soundlist.push_back(sound);
+
+ if (sound->source()) {
+ audio::loop(sound->source(), sound->buffer(), 1.0f, 0.0f);
+ }
+ }
+
+ }
}
SoundExt::~SoundExt()
@@ -115,6 +152,14 @@ SoundExt::~SoundExt()
void SoundExt::clear()
{
+ for (Sounds::iterator it = state_soundlist.begin(); it != state_soundlist.end(); it++) {
+ client::Sound *sound = *it;
+ if (sound->source()) {
+ audio::Sources::remove(sound->source());
+ }
+ }
+ state_soundlist.clear();
+
if (state_engineloopsource) {
audio::Sources::remove(state_engineloopsource);
}
@@ -137,14 +182,21 @@ void SoundExt::clear()
void SoundExt::frame(float elapsed)
{
+ float speed = 0;
+ float pitch = 1.0f;
+ float gain = 0.0;
+ float r = (entity()->model() ? entity()->model()->maxbbox().x() : entity()->radius());
+
+ math::Vector3f velocity;
+
if (entity()->type() == core::Entity::Controlable) {
core::EntityControlable *entity = static_cast<core::EntityControlable *>(this->entity());
- float speed = entity->speed();
- float pitch = 1.0f;
- float gain = 0.0;
- float r = (entity->model() ? entity->model()->maxbbox().x() : entity->radius());
-
+ speed = entity->speed();
+
+ if (snd_doppler->value())
+ velocity.assign(entity->axis().forward() * speed);
+
if (entity->state() == core::Entity::Impulse) {
pitch = 1.0f;
gain = 1.0f;
@@ -189,10 +241,17 @@ void SoundExt::frame(float elapsed)
}
audio::update_source(state_engineloopsource,
- entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed, pitch, gain);
+ entity->location() - entity->axis().forward() * r ,velocity, pitch, gain);
audio::update_source(state_engineeventsource,
- entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed);
+ entity->location() - entity->axis().forward() * r , velocity);
+ }
+
+ for (Sounds::iterator it = state_soundlist.begin(); it != state_soundlist.end(); it++) {
+ client::Sound *sound = *it;
+ if (sound->source()) {
+ audio::update_source(sound->source(), sound->location() + entity()->location(), velocity, 1.0f, 1.0f);
+ }
}
}