/* client/targets.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_TARGET_H__ #define __INCLUDED_CLIENT_TARGET_H__ #include #include #include #include #include "audio/audio.h" #include "audio/sources.h" #include "client/view.h" #include "core/gameinterface.h" #include "core/entity.h" #include "render/render.h" #include "render/gl.h" #include "render/text.h" namespace client { core::Cvar *draw_target = 0; core::Cvar *snd_engines = 0; namespace targets { void init() { snd_engines = core::Cvar::get("snd_engines", "1", core::Cvar::Archive); snd_engines->set_info("[bool] enable or disable engine sounds"); draw_target = core::Cvar::get("draw_target", "1", core::Cvar::Archive); draw_target->set_info("[bool] draw target information"); } void shutdown() { } void render_listener_sound() { if (!(snd_engines && snd_engines->value())) return; math::Vector3f velocity(0, 0 ,0); if (core::localcontrol()) { velocity.assign(core::localcontrol()->state()->axis().forward() * core::localcontrol()->speed()); } audio::update_listener(render::Camera::eye(), render::Camera::axis(), velocity); } void render_entity_sound(core::Entity *entity) { if (!(entity->type() == core::Entity::Controlable)) return; if (!(snd_engines && snd_engines->value())) { entity->state()->clearsound(); return; } core::EntityControlable *entitycontrolable = (core::EntityControlable *) entity; core::ClientState *state = entity->state(); 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 ) { 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_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(); } } // render ingame sounds void draw() { render_listener_sound(); for (std::map::iterator it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { core::Entity *entity = (*it).second; render_entity_sound(entity); } } } } #endif // __INCLUDED_CLIENT_RADAR_H__