From ae65ef53fc8b70ebee3b43bb06ecd091aaae2a26 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 17 Jul 2008 14:19:18 +0000 Subject: engine sounds --- src/client/client.cc | 6 ++++++ src/client/client.h | 4 ++++ src/client/view.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) (limited to 'src/client') diff --git a/src/client/client.cc b/src/client/client.cc index a3219e6..2f60fce 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -11,6 +11,7 @@ #include #include "audio/audio.h" +#include "audio/sources.h" #include "client/chat.h" #include "client/client.h" #include "client/video.h" @@ -165,6 +166,11 @@ void Client::notify_sound(const char * name) audio::play(name); } +void Client::notify_remove_sound(size_t source) +{ + audio::Sources::remove(source); +} + void Client::notify_message(std::string const & message) { con_print << message << std::endl; diff --git a/src/client/client.h b/src/client/client.h index 8bd6d45..9b60671 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -33,6 +33,10 @@ public: /// text notifications from the core virtual void notify_message(std::string const & message); + + /// remove sound source notification + virtual void notify_remove_sound(size_t source); + }; diff --git a/src/client/view.cc b/src/client/view.cc index 63718e1..7038a47 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -11,6 +11,8 @@ #include #include +#include "audio/audio.h" +#include "audio/sources.h" #include "client/client.h" #include "client/chat.h" #include "client/console.h" @@ -34,6 +36,7 @@ core::Cvar *draw_stats = 0; core::Cvar *draw_location = 0; core::Cvar *draw_radar = 0; +core::Cvar *snd_engines = 0; core::Cvar *cl_crosshaircolor = 0; namespace view @@ -57,6 +60,9 @@ void init() cl_crosshaircolor = core::Cvar::get("cl_crosshaircolor", "1 1 1", core::Cvar::Archive); cl_crosshaircolor->set_info("[r g b] crosshairs color"); + + snd_engines = core::Cvar::get("snd_engines", "0", core::Cvar::Archive); + snd_engines->set_info("[bool] enable or disable engine sounds"); } void shutdown() @@ -282,6 +288,47 @@ void reset() } +// render ingame sounds +void render_sound() +{ + if (!(snd_engines && snd_engines->value())) + return; + + float speed = 0; + if (core::localcontrol()) { + speed = core::localcontrol()->speed(); + } + + audio::update_listener(render::Camera::eye(), render::Camera::axis(), speed); + + for (std::map::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + core::Entity *entity = (*it).second; + core::ClientState *state = entity->state(); + + if ((entity->type() == core::Entity::Controlable)) { + core::EntityControlable *entitycontrolable = (core::EntityControlable *) entity; + + if (entity->model() && state->detailvisible() && entitycontrolable->thrust() > 0 ) { + + float speed = entitycontrolable->speed(); + float pitch = 0.2f + entitycontrolable->thrust() * 0.8f; + + if (!state->state_enginesound) { + if ((state->state_enginesound = audio::Sources::get()) > 0 ) + audio::loop(state->state_enginesound, "engines/loop01", pitch, 0); + } + + if (state->state_enginesound) { + audio::update_source(state->state_enginesound, + state->location() - state->axis().forward() * entity->model()->maxbbox().y , state->axis().forward() * speed, pitch); + } + } else { + entity->state()->clearsound(); + } + } + } +} + void frame(float seconds) { using namespace render; @@ -300,6 +347,8 @@ void frame(float seconds) if (core::application()->connected() && core::game()->serverframetime()) { render::draw(seconds); // draw the world + + render_sound(); } // switch to ortographic projection to draw the GUI @@ -317,8 +366,14 @@ void frame(float seconds) if (!core::application()->connected()) { // draw the loader bitmap draw_loader(); + + // force console on if not connected + if (!console()->visible()) + console()->toggle(); } + gl::enable(GL_BLEND); + // draw text elements if (draw_ui->value()) { -- cgit v1.2.3