From 90fbc4c5caf5afd54920894319448b74967399ba Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 25 Feb 2010 19:28:14 +0000 Subject: added initial support for model sound tags, moved sound code from client/targets.cc to client/soundext.cc, added master volume cvar snd_volume --- src/client/soundext.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'src/client/soundext.cc') diff --git a/src/client/soundext.cc b/src/client/soundext.cc index 1ea0c94..04c37f9 100644 --- a/src/client/soundext.cc +++ b/src/client/soundext.cc @@ -13,6 +13,7 @@ #include "core/entity.h" #include "client/soundext.h" #include "client/client.h" +#include "render/camera.h" #include #include @@ -20,6 +21,52 @@ namespace client { +// cvars are initialized in client.cc +core::Cvar *snd_doppler = 0; +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()) { + velocity.assign(core::localcontrol()->axis().forward() * core::localcontrol()->speed()); + } + + if (master_volume != snd_volume->value()) { + master_volume = snd_volume->value(); + math::clamp(master_volume, 0, 1); + (*snd_volume) = master_volume; + } + + audio::update_listener(render::Camera::eye(), render::Camera::axis(), velocity, master_volume); +} + +void render_entity_sound(core::Entity *entity) +{ + if (!(snd_engines && snd_engines->value())) { + if (ext_sound(entity)) + delete ext_sound(entity); + return; + } + + if (!ext_render(entity) || (ext_render(entity) && !ext_render(entity)->visible())) { + if (ext_sound(entity)) + delete ext_sound(entity); + return; + } else { + if (!ext_sound(entity)) { + new SoundExt(entity); + } + + ext_sound(entity)->frame(0.0f); + } +} + SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Sound, entity) { state_thusterloopbuffer = 0; @@ -103,7 +150,10 @@ void SoundExt::frame(float elapsed) gain = 1.0f; } else if (entity->thrust() > 0) { pitch = 0.2f + entity->thrust() * 0.8f; - gain = 0.8f; + gain = 1.0f; + if (entity->thrust() < 0.2f) { + gain *= entity->thrust() * 5.0f; + } } if (entity->state() == core::Entity::ImpulseInitiate) { -- cgit v1.2.3