From 28ba97bdd8fb6ca352dc49dba01a66bd155ad523 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 15 Nov 2008 19:24:55 +0000 Subject: entity extensions --- src/client/targets.cc | 108 ++++++++++---------------------------------------- 1 file changed, 22 insertions(+), 86 deletions(-) (limited to 'src/client/targets.cc') diff --git a/src/client/targets.cc b/src/client/targets.cc index 8b77644..3ccea8a 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -14,7 +14,9 @@ #include "audio/sources.h" #include "auxiliary/functions.h" #include "audio/sources.h" +#include "client/client.h" #include "client/input.h" +#include "client/soundext.h" #include "client/view.h" #include "client/video.h" #include "core/application.h" @@ -47,13 +49,13 @@ bool is_legal_target(core::Entity *entity) return true; } else if (entity == core::localcontrol()) { return false; - } else if (entity->state()->distance() < 0.001f) { + } else if (ext_render(entity)->distance() < 0.001f) { return false; } else { if (entity->type() != core::Entity::Controlable) { - return entity->state()->visible(); + return ext_render(entity)->visible(); - } else if (entity->state()->distance() < core::range::visible) { + } else if (ext_render(entity)->distance() < core::range::visible) { return true; } } @@ -224,7 +226,7 @@ void func_target_center(std::string const &args) for (core::Zone::Content::iterator it=core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) { core::Entity *entity = (*it); - math::Vector3f v(entity->state()->location() - render::Camera::eye()); + math::Vector3f v(entity->location() - render::Camera::eye()); v.normalize(); if (is_legal_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85 ) { @@ -291,98 +293,31 @@ void render_listener_sound() math::Vector3f velocity(0, 0 ,0); if (core::localcontrol()) { - velocity.assign(core::localcontrol()->state()->axis().forward() * core::localcontrol()->speed()); + velocity.assign(core::localcontrol()->axis().forward() * core::localcontrol()->speed()); } audio::update_listener(render::Camera::eye(), render::Camera::axis(), velocity); } -void render_entity_sound(core::EntityControlable *entity) +void render_entity_sound(core::Entity *entity) { - if (!(entity->type() == core::Entity::Controlable)) - return; - if (!(snd_engines && snd_engines->value())) { - entity->state()->clearsound(); + if (ext_sound(entity)) + delete ext_sound(entity); return; } - core::ClientState *state = entity->state(); - if (!(entity->model() && state->detailvisible())) { - entity->state()->clearsound(); + if (!ext_render(entity) || !ext_render(entity)->visible()) { + if (ext_sound(entity)) + delete ext_sound(entity); return; } - 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"); - } - - - if (!state->state_engineloopsource) { - state->state_engineloopsource = audio::Sources::get(); - state->state_engineeventsource = audio::Sources::get(); - } - - float speed = entity->speed(); - float pitch = 1.0f; - float gain = 0.0; - if (entity->eventstate() == core::Entity::Impulse) { - pitch = 1.0f; - gain = 1.0f; - } else if (entity->thrust() > 0 ) { - pitch = 0.2f + entity->thrust() * 0.8f; - gain = 0.8f; + if (!ext_sound(entity)) { + new SoundExt(entity); } - - - 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) { - - 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 { - - 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); + entity->extension((size_t) core::Extension::Sound)->frame(0.0f); } @@ -428,8 +363,9 @@ void draw() // render entity sound if (entity->type() == core::Entity::Controlable) { - render_entity_sound(static_cast(entity)); + render_entity_sound(entity); } + // find the current target if (!core::localplayer()->view() && core::localcontrol() && is_legal_target(entity)) { @@ -438,7 +374,7 @@ void draw() } // check if the mouse is hovering the entity - Vector3f v(entity->state()->location() - render::Camera::eye()); + Vector3f v(entity->location() - render::Camera::eye()); v.normalize(); if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) { @@ -448,11 +384,11 @@ void draw() float r = entity->radius() * 0.5f; - if (entity->state()->distance() > 512) + if (ext_render(entity)->distance() > 512.0f) math::clamp(r, 8.0f,r); - else if (entity->state()->distance() > 256) + else if (ext_render(entity)->distance() > 256.0f) math::clamp(r, 4.0f,r); - else if (entity->state()->distance() > 128.0f) + else if (ext_render(entity)->distance() > 128.0f) math::clamp(r, 2.0f,r); // if the cursor-beam hits the entity sphere -- cgit v1.2.3