Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-11-15 19:24:55 +0000
committerStijn Buys <ingar@osirion.org>2008-11-15 19:24:55 +0000
commit28ba97bdd8fb6ca352dc49dba01a66bd155ad523 (patch)
treeeb4abd0505eb842e15201783529814bda1ae6e76 /src/client/targets.cc
parent1f0dbeeabdffff096908473168898c5fa63bcff0 (diff)
entity extensions
Diffstat (limited to 'src/client/targets.cc')
-rw-r--r--src/client/targets.cc108
1 files changed, 22 insertions, 86 deletions
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<core::EntityControlable *>(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