diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/client.cc | 12 | ||||
-rw-r--r-- | src/client/soundext.cc | 52 | ||||
-rw-r--r-- | src/client/soundext.h | 11 | ||||
-rw-r--r-- | src/client/targets.cc | 39 | ||||
-rw-r--r-- | src/client/targets.h | 6 |
5 files changed, 73 insertions, 47 deletions
diff --git a/src/client/client.cc b/src/client/client.cc index 6a50743..5bf783a 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -16,6 +16,7 @@ #include "client/client.h" #include "client/video.h" #include "client/input.h" +#include "client/soundext.h" #include "core/core.h" #include "core/loader.h" #include "core/zone.h" @@ -86,7 +87,16 @@ void Client::init(int count, char **arguments) cvar = core::Cvar::get("rconpassword", "", core::Cvar::Archive | core::Cvar::Info); cvar->set_info("[string] password for remote console access"); - + + snd_volume = core::Cvar::get("snd_volume", "0.8", core::Cvar::Archive); + snd_volume->set_info("[float] master volume from 0 (mute) to 1 (max volume)"); + + snd_engines = core::Cvar::get("snd_engines", "1", core::Cvar::Archive); + snd_engines->set_info("[bool] enable or disable engine sounds"); + + snd_doppler = core::Cvar::get("snd_doppler", "0", core::Cvar::Archive); + snd_doppler->set_info("[bool] enable or disable doppler effect"); + // initialize SDL, but do not initialize any subsystems SDL_Init(0); 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 <sstream> #include <iomanip> @@ -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) { diff --git a/src/client/soundext.h b/src/client/soundext.h index a99cee0..b0fc17a 100644 --- a/src/client/soundext.h +++ b/src/client/soundext.h @@ -8,10 +8,15 @@ #define __INCLUDED_CLIENT_SOUNDEXT_H__ #include "core/extension.h" +#include "core/cvar.h" namespace client { +extern core::Cvar *snd_engines; +extern core::Cvar *snd_doppler; +extern core::Cvar *snd_volume; + /// the sound extension of an entity class SoundExt : public core::Extension { @@ -43,6 +48,12 @@ private: size_t state_engineeventsource; }; +/// render listener sound +void render_listener_sound(); + +/// render sound for a single entity +void render_entity_sound(core::Entity *entity); + } //namespace client // diff --git a/src/client/targets.cc b/src/client/targets.cc index cd3db41..d915f20 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -39,7 +39,6 @@ unsigned int current_target_id = 0; unsigned int current_hover = 0; core::Entity *current_target = 0; -core::Cvar *snd_engines = 0; bool is_valid_hud_target(core::Entity *entity) { @@ -263,9 +262,6 @@ void reset() void init() { - snd_engines = core::Cvar::get("snd_engines", "1", core::Cvar::Archive); - snd_engines->set_info("[bool] enable or disable engine sounds"); - core::Func *func = 0; func = core::Func::add("target_next", func_target_next); @@ -293,41 +289,6 @@ void shutdown() core::Func::remove("target_center"); } -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()); - } - - audio::update_listener(render::Camera::eye(), render::Camera::axis(), velocity); -} - -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); - } -} - - // render targets and sounds (in world coordinates) void frame() { diff --git a/src/client/targets.h b/src/client/targets.h index 9bfa87d..5a3a655 100644 --- a/src/client/targets.h +++ b/src/client/targets.h @@ -33,12 +33,6 @@ bool is_valid_map_target(core::Entity *entity); /// render targets and sounds void frame(); -/// render sound listener properties -void render_listener_sound(); - -/// render the sound for one entity -void render_entity_sound(core::Entity *Entity); - /// currently selected target, 0 if there is none core::Entity *current(); |