1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
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 <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#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<unsigned int, core::Entity *>::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__
|