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-11-15 19:24:55 +0000
committerStijn Buys <ingar@osirion.org>2008-11-15 19:24:55 +0000
commit28ba97bdd8fb6ca352dc49dba01a66bd155ad523 (patch)
treeeb4abd0505eb842e15201783529814bda1ae6e76 /src/client/soundext.cc
parent1f0dbeeabdffff096908473168898c5fa63bcff0 (diff)
entity extensions
Diffstat (limited to 'src/client/soundext.cc')
-rw-r--r--src/client/soundext.cc147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/client/soundext.cc b/src/client/soundext.cc
new file mode 100644
index 0000000..421575d
--- /dev/null
+++ b/src/client/soundext.cc
@@ -0,0 +1,147 @@
+/*
+ client/soundext.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+
+#include "audio/audio.h"
+#include "audio/buffers.h"
+#include "audio/sources.h"
+#include "auxiliary/functions.h"
+#include "core/gameinterface.h"
+#include "core/entity.h"
+#include "client/soundext.h"
+#include "client/client.h"
+
+#include <sstream>
+#include <iomanip>
+
+namespace client
+{
+
+SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Sound, entity)
+{
+ state_thusterloopbuffer = 0;
+
+ state_impulseloopbuffer = 0;
+ state_impulsestartbuffer = 0;
+ state_impulsestopbuffer = 0;
+
+ state_engineloopbuffer = 0;
+ state_engineloopsource = 0;
+
+ state_engineeventbuffer = 0;
+ state_engineeventsource = 0;
+
+ // load engine sound
+ if (entity->type() == core::Entity::Controlable)
+ {
+ core::EntityControlable *entityco = static_cast<core::EntityControlable *>(entity);
+ unsigned int enginesoundset = 0;
+ unsigned int impulsesoundset = 0;
+
+ if (entityco->model()) {
+ enginesoundset = entityco->model()->enginesound();
+ impulsesoundset = entityco->model()->impulsesound();
+ }
+
+
+ std::stringstream soundname;
+ soundname << "engines/loop" << std::setfill('0') << std::setw(2) << enginesoundset;
+ state_thusterloopbuffer = audio::Buffers::load(soundname.str());
+
+ // load impulse sound
+ // FIXME load impulse sound set
+ state_impulseloopbuffer = audio::Buffers::load("engines/impulse_loop00");
+ state_impulsestartbuffer = audio::Buffers::load("engines/impulse_start00");
+ state_impulsestopbuffer = audio::Buffers::load("engines/impulse_stop00");
+ }
+
+ state_engineloopsource = audio::Sources::get();
+ state_engineeventsource = audio::Sources::get();
+}
+
+SoundExt::~SoundExt()
+{
+ clear();
+}
+
+void SoundExt::clear()
+{
+ if (state_engineloopsource) {
+ audio::Sources::remove(state_engineloopsource);
+ }
+
+ if (state_engineeventsource) {
+ audio::Sources::remove(state_engineeventsource);
+ }
+
+ state_thusterloopbuffer = 0;
+ state_impulseloopbuffer = 0;
+ state_impulsestartbuffer = 0;
+ state_impulsestopbuffer = 0;
+
+ state_engineloopbuffer = 0;
+ state_engineloopsource = 0;
+
+ state_engineeventbuffer = 0;
+ state_engineeventsource = 0;
+}
+
+void SoundExt::frame(float elapsed)
+{
+ core::EntityControlable *entity = static_cast<core::EntityControlable *>(this->entity());
+
+ float speed = entity->speed();
+ float pitch = 1.0f;
+ float gain = 0.0;
+ if (entity->eventstate() == core::Entity::Impulse) {
+ pitch = 1.0f;
+ gain = 1.0f;
+ } else if (entity->thrust() > 0 ) {
+ pitch = 0.2f + entity->thrust() * 0.8f;
+ gain = 0.8f;
+ }
+
+ if (entity->eventstate() == core::Entity::ImpulseInitiate ) {
+
+ if (state_engineeventbuffer != state_impulsestartbuffer) {
+ audio::update_source(state_engineeventsource,
+ entity->location() - entity->axis().forward() * entity->model()->maxbbox().y , entity->axis().forward() * speed);
+ state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestartbuffer);
+ }
+ } else if (entity->eventstate() == core::Entity::Impulse) {
+
+ state_engineeventbuffer = state_impulseloopbuffer;
+
+ if (state_engineloopbuffer != state_impulseloopbuffer) {
+ state_engineloopbuffer = audio::loop(state_engineloopsource, state_impulseloopbuffer, pitch, 0);
+ }
+ pitch = 1.0f;
+ } else {
+
+ if (state_engineeventbuffer == state_impulseloopbuffer) {
+ audio::update_source(state_engineeventsource,
+ entity->location() - entity->axis().forward() * entity->model()->maxbbox().y , entity->axis().forward() * speed);
+ state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestopbuffer);
+ }
+ state_engineeventbuffer = 0;
+
+ if (state_engineloopbuffer != state_thusterloopbuffer) {
+ state_engineloopbuffer = audio::loop(state_engineloopsource, state_thusterloopbuffer, pitch, 0);
+ }
+ }
+
+
+ audio::update_source(state_engineloopsource,
+ entity->location() - entity->axis().forward() * entity->model()->maxbbox().x , entity->axis().forward() * speed, pitch, gain);
+
+ audio::update_source(state_engineeventsource,
+ entity->location() - entity->axis().forward() * entity->model()->maxbbox().x , entity->axis().forward() * speed);
+
+}
+
+} // namespace client
+
+