From 56b0856541446cbafee4eed9ef0ee9fb69af565a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 8 Aug 2008 22:17:29 +0000 Subject: improved truster indicator, impulse engine sounds --- src/client/input.cc | 40 ++++++++++++---------- src/client/input.h | 2 ++ src/client/targets.cc | 92 ++++++++++++++++++++++++++++++++++++++------------- src/client/video.cc | 7 +++- src/client/view.cc | 17 ++++++++-- 5 files changed, 115 insertions(+), 43 deletions(-) (limited to 'src/client') diff --git a/src/client/input.cc b/src/client/input.cc index 7812d7e..963dd9f 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -59,8 +59,6 @@ float mouse_pitch = 0; float mouse_direction = 0; - - // true if the mouse has control const float mouse_timeout = 0.200f; // 200 ms select time-out float mouse_control_override_time = 0; @@ -355,8 +353,10 @@ void action_press(Key const *key, std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { - mouse_control_override = true; - mouse_control_override_time = key->pressed(); + if (!mouse_control_override) { + mouse_control_override = true; + mouse_control_override_time = key->pressed(); + } /* -- directional control ------------------------- */ } else if (action.compare("+left") == 0) { @@ -404,17 +404,19 @@ void action_release(Key *key, std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { - mouse_control_override = false; - mouse_control_override_time = 0; - - if (!input_mousecontrol->value() || (joystick_control && mouse_control && - (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) { - local_direction = 0.0f; - local_pitch = 0.0f; - local_roll = 0.0f; - - render::Camera::set_direction(0.0f); - render::Camera::set_pitch(0.0f); + if (mouse_control_override) { + mouse_control_override = false; + mouse_control_override_time = 0; + + if (!input_mousecontrol->value() || (joystick_control && mouse_control && + (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) { + local_direction = 0.0f; + local_pitch = 0.0f; + local_roll = 0.0f; + + render::Camera::set_direction(0.0f); + render::Camera::set_pitch(0.0f); + } } /* -- directional control ------------------------- */ @@ -524,7 +526,7 @@ void key_pressed(Key *key) void key_released(Key *key) { - if (core::application()->connected() && core::localcontrol() && !console()->visible() && !chat::visible()) { + if (core::application()->connected() && core::localcontrol()) { if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= mouse_timeout) ) { // hovering target selected @@ -657,6 +659,10 @@ void frame(float seconds) render::reset(); } + if (core::localcontrol() && (core::localcontrol()->eventstate() != core::Entity::Normal)) { + local_thrust = core::localcontrol()->thrust(); + } + /* -- detect joystick stat changes ---------------- */ Joystick::frame(); joystick_control = Joystick::is_enabled(); @@ -761,7 +767,7 @@ void frame(float seconds) for (Keyboard::iterator it = keyboard->begin(); it != keyboard->end(); it++) { key = (*it).second; - if (key && key->sym() < 512 && key->pressed()) { + if (key && key->pressed()) { while ((key->pressed()+delay < core::application()->time()) && (key->lastpressed()+repeat < core::application()->time())) { if (key->lastpressed() > key->pressed()) key->key_lastpressed += repeat; diff --git a/src/client/input.h b/src/client/input.h index cf4c169..a954040 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -47,6 +47,8 @@ extern bool mouse_deadzone; extern bool mouse_control; extern bool joystick_control; +extern float local_thrust; + } // namespace input } // namespace client 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 #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(entity)); + } // find the current target if (core::localcontrol() && is_legal_target(entity)) { diff --git a/src/client/video.cc b/src/client/video.cc index 5a4e535..2c1fe6b 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -126,6 +126,9 @@ bool init() return false; } con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; + +#ifdef HAVE_DEBUG_MESSAGES + int red, green, blue, alpha, depth; SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &red); @@ -135,7 +138,9 @@ bool init() SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &depth); con_debug << " visual r: " << red << " g: " << green << " blue: " << blue << " alpha: " << alpha << " depth: " << depth << std::endl; - + +#endif // HAVE_DEBUG_MESSAGES + render::Camera::set_aspect(width, height); (*r_width) = width; (*r_height) = height; diff --git a/src/client/view.cc b/src/client/view.cc index e1e0820..1fdbcdc 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -177,7 +177,7 @@ void draw_status() if (state == core::Entity::ImpulseInitiate) { statestr << "^FInitializing kinetic impulse drive " << core::localcontrol()->timer(); } else if (state == core::Entity::Impulse) { - statestr << "^FKinetic impulse"; + //statestr << "^FKinetic impulse"; } else if (state == core::Entity::JumpInitiate) { statestr << "^FInitializing hyperspace jump drive "<< core::localcontrol()->timer(); } else if (state == core::Entity::Jump) { @@ -239,7 +239,17 @@ void draw_status() gl::end(); float u = core::localcontrol()->thrust(); - if ( u > 0) { + if (( u > 0) || (core::localcontrol()->eventstate() == core::Entity::Impulse)) { + + if (core::localcontrol()->eventstate() == core::Entity::Impulse) { + gl::color(0, .8, 0); + } else { + float d = math::absf(input::local_thrust - u); + if (d > 0.1) { + d = 0.1f; + } + gl::color(1, 1, .5f + d * 5.0f); + } Textures::bind("bitmaps/hud/thruster_indicator"); // 316 x 32 bitmap gl::begin(render::gl::Quads); glTexCoord2f(0, 0); @@ -256,7 +266,10 @@ void draw_status() gl::end(); } + Text::setfont("bitmaps/fonts/gui", 14, 24); + Text::setcolor('B'); //set normal color + std::stringstream speedstr; speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f); Text::draw( 316+4+10, video::height - 6 -16 - render::Text::fontwidth() /2, speedstr); -- cgit v1.2.3