Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/soundext.cc77
-rw-r--r--src/client/soundext.h48
-rw-r--r--src/client/targets.cc2
3 files changed, 117 insertions, 10 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);
+ }
}
}
diff --git a/src/client/soundext.h b/src/client/soundext.h
index b0fc17a..9991b69 100644
--- a/src/client/soundext.h
+++ b/src/client/soundext.h
@@ -10,6 +10,9 @@
#include "core/extension.h"
#include "core/cvar.h"
+#include <list>
+#include <string>
+
namespace client
{
@@ -17,6 +20,47 @@ extern core::Cvar *snd_engines;
extern core::Cvar *snd_doppler;
extern core::Cvar *snd_volume;
+/// a sound playing
+class Sound {
+public:
+ Sound();
+ Sound(const std::string & name);
+
+ inline size_t buffer() const {
+ return sound_buffer;
+ }
+
+ inline size_t source() const {
+ return sound_source;
+ }
+
+ inline math::Vector3f const & location() {
+ return sound_location;
+ }
+
+ inline math::Vector3f & get_location() {
+ return sound_location;
+ }
+
+ inline void set_location(const math::Vector3f & location) {
+ sound_location.assign(location);
+ }
+
+ inline void set_source(size_t source) {
+ sound_source = source;
+ }
+
+ inline void set_buffer(size_t buffer) {
+ sound_buffer = buffer;
+ }
+
+private:
+ size_t sound_buffer;
+ size_t sound_source;
+
+ math::Vector3f sound_location;
+};
+
/// the sound extension of an entity
class SoundExt : public core::Extension
{
@@ -26,7 +70,9 @@ public:
virtual void frame(float elapsed);
+ typedef std::list<client::Sound *> Sounds;
private:
+
void clear();
/// index of the audio buffer containing the thruster sound loop
@@ -46,6 +92,8 @@ private:
size_t state_engineeventbuffer;
/// index of the audio source used to play engine sound events
size_t state_engineeventsource;
+
+ Sounds state_soundlist;
};
/// render listener sound
diff --git a/src/client/targets.cc b/src/client/targets.cc
index d915f20..cc7f29f 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -330,7 +330,7 @@ void frame()
core::Entity *entity = (*it);
// render entity sound
- if (entity->type() == core::Entity::Controlable) {
+ if ((entity->type() == core::Entity::Controlable) || (entity->model() && entity->model()->sounds().size())) {
render_entity_sound(entity);
}