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>2008-08-08 22:17:29 +0000
committerStijn Buys <ingar@osirion.org>2008-08-08 22:17:29 +0000
commit56b0856541446cbafee4eed9ef0ee9fb69af565a (patch)
tree8cec133fb9b0a02fc2f415c26b69fcd4c6db1ef9 /src/client/targets.cc
parentf540e8dac10de8ff443692e78404b1508dde9d1e (diff)
improved truster indicator, impulse engine sounds
Diffstat (limited to 'src/client/targets.cc')
-rw-r--r--src/client/targets.cc92
1 files changed, 69 insertions, 23 deletions
diff --git a/src/client/targets.cc b/src/client/targets.cc
index f922199..384c793 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -10,6 +10,8 @@
#include <iomanip>
#include "audio/audio.h"
+#include "audio/buffers.h"
+#include "audio/sources.h"
#include "auxiliary/functions.h"
#include "audio/sources.h"
#include "client/input.h"
@@ -292,7 +294,7 @@ void render_listener_sound()
audio::update_listener(render::Camera::eye(), render::Camera::axis(), velocity);
}
-void render_entity_sound(core::Entity *entity)
+void render_entity_sound(core::EntityControlable *entity)
{
if (!(entity->type() == core::Entity::Controlable))
return;
@@ -302,34 +304,77 @@ void render_entity_sound(core::Entity *entity)
return;
}
- core::EntityControlable *entitycontrolable = (core::EntityControlable *) entity;
core::ClientState *state = entity->state();
+ if (!(entity->model() && state->detailvisible())) {
+ entity->state()->clearsound();
+ return;
+ }
- if (entity->model() && state->detailvisible() && entitycontrolable->thrust() > 0 ) {
+ if (!state->state_thusterloopbuffer || ! state->state_impulseloopbuffer) {
+ // load engine sound
+ size_t enginesound = 0;
+ if (entity->model())
+ enginesound = entity->model()->enginesound();
+
+ std::stringstream soundname;
+ soundname << "engines/loop" << std::setfill('0') << std::setw(2) << enginesound;
+ state->state_thusterloopbuffer = audio::Buffers::load(soundname.str());
+
+ // load impulse sound
+ // FIXME read impulse sound set from model
+ state->state_impulseloopbuffer = audio::Buffers::load("engines/impulse_loop00");
+ state->state_impulsestartbuffer = audio::Buffers::load("engines/impulse_start00");
+ state->state_impulsestopbuffer = audio::Buffers::load("engines/impulse_stop00");
+ }
- float speed = entitycontrolable->speed();
- float pitch = 0.2f + entitycontrolable->thrust() * 0.8f;
-
- if (!state->state_enginesound) {
- if ((state->state_enginesound = audio::Sources::get()) > 0 ) {
-
- size_t enginesound = 0;
- if (entity->model())
- enginesound = entity->model()->enginesound();
-
- std::stringstream soundname;
- soundname << "engines/loop" << std::setfill('0') << std::setw(2) << enginesound;
- audio::loop(state->state_enginesound, soundname.str().c_str(), pitch, 0);
- }
+
+ if (!state->state_engineloopsource) {
+ state->state_engineloopsource = audio::Sources::get();
+ state->state_engineeventsource = audio::Sources::get();
+ }
+
+ float speed = entity->speed();
+ float pitch = 0.2f + entity->thrust() * 0.8f;
+ float gain = 0.0;
+ if (entity->thrust() > 0 ) {
+ gain = 1.0f;
+ }
+
+ if (entity->eventstate() == core::Entity::ImpulseInitiate ) {
+
+ if (state->state_engineeventbuffer != state->state_impulsestartbuffer) {
+ audio::update_source(state->state_engineeventsource,
+ state->location() - state->axis().forward() * entity->model()->maxbbox().y , state->axis().forward() * speed);
+ state->state_engineeventbuffer = audio::play(state->state_engineeventsource, state->state_impulsestartbuffer);
}
+ } else if (entity->eventstate() == core::Entity::Impulse) {
- if (state->state_enginesound) {
- audio::update_source(state->state_enginesound,
- state->location() - state->axis().forward() * entity->model()->maxbbox().y , state->axis().forward() * speed, pitch);
+ state->state_engineeventbuffer = state->state_impulseloopbuffer;
+
+ if (state->state_engineloopbuffer != state->state_impulseloopbuffer) {
+ state->state_engineloopbuffer = audio::loop(state->state_engineloopsource, state->state_impulseloopbuffer, pitch, 0);
}
+ pitch = 1.0f;
} else {
- entity->state()->clearsound();
+
+ if (state->state_engineeventbuffer == state->state_impulseloopbuffer) {
+ audio::update_source(state->state_engineeventsource,
+ state->location() - state->axis().forward() * entity->model()->maxbbox().y , state->axis().forward() * speed);
+ state->state_engineeventbuffer = audio::play(state->state_engineeventsource, state->state_impulsestopbuffer);
+ }
+ state->state_engineeventbuffer = 0;
+
+ if (state->state_engineloopbuffer != state->state_thusterloopbuffer) {
+ state->state_engineloopbuffer = audio::loop(state->state_engineloopsource, state->state_thusterloopbuffer, pitch, 0);
+ }
}
+
+
+ audio::update_source(state->state_engineloopsource,
+ state->location() - state->axis().forward() * entity->model()->maxbbox().y , state->axis().forward() * speed, pitch, gain);
+
+ audio::update_source(state->state_engineeventsource,
+ state->location() - state->axis().forward() * entity->model()->maxbbox().y , state->axis().forward() * speed);
}
void draw_entity_offscreen_target(core::Entity *entity, bool is_active_target)
@@ -511,8 +556,9 @@ void draw()
core::Entity *entity = (*it);
// render entity sound
- render_entity_sound(entity);
-
+ if (entity->type() == core::Entity::Controlable) {
+ render_entity_sound(static_cast<core::EntityControlable *>(entity));
+ }
// find the current target
if (core::localcontrol() && is_legal_target(entity)) {