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.cc4
-rw-r--r--src/client/soundext.cc77
-rw-r--r--src/client/soundext.h48
-rw-r--r--src/client/targets.cc2
-rw-r--r--src/model/mapfile.cc34
5 files changed, 151 insertions, 14 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 2c8a7c1..b7a79d7 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -196,7 +196,7 @@ void update_listener(math::Vector3f const &location, math::Axis const &axis, mat
}
alListenerfv(AL_ORIENTATION, orientation);
alListenerf(AL_GAIN, gain);
- //alListenerfv(AL_VELOCITY, velocity.ptr());
+ alListenerfv(AL_VELOCITY, velocity.ptr());
}
@@ -207,7 +207,7 @@ void update_source(size_t source_index, math::Vector3f const & location, math::V
ALuint source = Sources::source(source_index);
alSourcefv(source, AL_POSITION, location.ptr());
- //alSourcefv(source, AL_VELOCITY, velocity.ptr());
+ alSourcefv(source, AL_VELOCITY, velocity.ptr());
alSourcef(source, AL_PITCH, pitch);
alSourcef(source, AL_GAIN, gain);
}
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);
}
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index aa0cb37..6bac44e 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -1274,12 +1274,37 @@ Model * MapFile::load(std::string const &name)
// sound attributes
if (mapfile.got_key_vector3f("origin", location)) {
- tag_sound->get_location().assign(location * SCALE);
+ tag_sound->get_location().assign(location * SCALE);
continue;
- } else {
+
+ } else if (mapfile.got_key_string("name", str)) {
+ // remove sounds/ prefix
+ if (str.substr(0, 7).compare("sounds/") == 0)
+ str.erase(0, 7);
+ // remove extension
+ if (str[str.size()-4] == '.') {
+ str.erase(str.size() - 4);
+ }
+ tag_sound->set_name(str);
+ continue;
+
+ } else if (mapfile.got_key_string("noise", str)) {
+ // remove sounds/ prefix
+ if (str.substr(0, 7).compare("sounds/") == 0)
+ str.erase(0, 7);
+ // remove extension
+ if (str[str.size()-4] == '.') {
+ str.erase(str.size() - 4);
+ }
+ tag_sound->set_name(str);
+ continue;
+
+ } else if (mapfile.got_key()) {
mapfile.unknown_key();
+
}
+
} else if (mapfile.got_classname("misc_model")) {
// new submodel tag
@@ -1316,8 +1341,13 @@ Model * MapFile::load(std::string const &name)
} else {
tag_submodel->set_scale(1.0f);
}
+
+ } else if (mapfile.got_key()) {
+ mapfile.unknown_key();
+
}
+
} else if (mapfile.got_classname("location_dock")) {
// new docking location