1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "objs/vehic_sounds.hh"
|
---|
10 | #include "sound/sfx_id.hh"
|
---|
11 |
|
---|
12 | class g1_average_sound : public s1_sound_handle
|
---|
13 | {
|
---|
14 | public:
|
---|
15 | int t_contributors;
|
---|
16 |
|
---|
17 | void add_to_average(const i4_3d_vector& p)
|
---|
18 | {
|
---|
19 | x+=p.x; y+=p.y; z+=p.z;
|
---|
20 | t_contributors++;
|
---|
21 | }
|
---|
22 | void reset();
|
---|
23 | };
|
---|
24 |
|
---|
25 | g1_average_sound g1_average_rumbles[G1_T_RUMBLES];
|
---|
26 |
|
---|
27 | S1_SFX(heli, "rumble/helicopter_lp.wav", S1_3D, 40);
|
---|
28 | S1_SFX(jet , "rumble/jet_lp.wav", S1_3D, 40);
|
---|
29 | S1_SFX(ground, "rumble/peon_tank_lp.wav", S1_3D, 40);
|
---|
30 | S1_SFX(missile, "misc/missile_in_flight_22khz.wav", S1_3D, 40);
|
---|
31 | S1_SFX(s_stank, "rumble/supertank_lp.wav", S1_3D, 50);
|
---|
32 |
|
---|
33 |
|
---|
34 | void g1_add_to_sound_average(g1_rumble_type type, const i4_3d_vector& v)
|
---|
35 | {
|
---|
36 | i4_3d_vector pos;
|
---|
37 | s1_get_camera_pos(pos);
|
---|
38 | float r=20;
|
---|
39 | pos -= v;
|
---|
40 | if (pos.dot(pos)<r*r)
|
---|
41 | g1_average_rumbles[type].add_to_average(v);
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | void g1_add_to_sound_average(g1_rumble_type type, const i4_3d_vector& v, const i4_3d_vector& vel)
|
---|
46 | {
|
---|
47 | i4_3d_vector pos;
|
---|
48 | s1_get_camera_pos(pos);
|
---|
49 | float r=20;
|
---|
50 | pos -= v;
|
---|
51 | if (pos.dot(pos)<r*r)
|
---|
52 | {
|
---|
53 | g1_average_sound *s=g1_average_rumbles+type;
|
---|
54 | s->add_to_average(v);
|
---|
55 | s->xv=vel.x;
|
---|
56 | s->yv=vel.y;
|
---|
57 | s->zv=vel.z;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 | void g1_average_sound::reset()
|
---|
64 | {
|
---|
65 | t_contributors=0;
|
---|
66 | x=0;
|
---|
67 | y=0;
|
---|
68 | z=0;
|
---|
69 | frequency_scale=1.0;
|
---|
70 | }
|
---|
71 |
|
---|
72 | void g1_reset_sound_averages()
|
---|
73 | {
|
---|
74 | for (int i=0; i<G1_T_RUMBLES; i++)
|
---|
75 | g1_average_rumbles[i].reset();
|
---|
76 |
|
---|
77 | }
|
---|
78 |
|
---|
79 | void g1_recalc_sound_averages()
|
---|
80 | {
|
---|
81 | g1_average_sound *s=g1_average_rumbles;
|
---|
82 | for (int i=0; i<G1_T_RUMBLES; i++,s++)
|
---|
83 | {
|
---|
84 | if (s->t_contributors)
|
---|
85 | {
|
---|
86 | if (s->t_contributors!=1)
|
---|
87 | {
|
---|
88 | s->xv=s->yv=s->zv=0; // can't average velocity
|
---|
89 |
|
---|
90 | float oo_t=1.0/(float)s->t_contributors;
|
---|
91 | s->x*=oo_t;
|
---|
92 | s->y*=oo_t;
|
---|
93 | s->z*=oo_t;
|
---|
94 | }
|
---|
95 |
|
---|
96 | if (!g1_average_rumbles[i].playing)
|
---|
97 | {
|
---|
98 | switch (i)
|
---|
99 | {
|
---|
100 | case G1_RUMBLE_GROUND :
|
---|
101 | ground.play_looping(g1_average_rumbles[i]);
|
---|
102 | break;
|
---|
103 |
|
---|
104 | case G1_RUMBLE_HELI :
|
---|
105 | heli.play_looping(g1_average_rumbles[i]);
|
---|
106 | break;
|
---|
107 |
|
---|
108 | case G1_RUMBLE_JET :
|
---|
109 | jet.play_looping(g1_average_rumbles[i]);
|
---|
110 | break;
|
---|
111 |
|
---|
112 | case G1_RUMBLE_MISSILE :
|
---|
113 | missile.play_looping(g1_average_rumbles[i]);
|
---|
114 | break;
|
---|
115 | }
|
---|
116 | }
|
---|
117 | }
|
---|
118 | else if (g1_average_rumbles[i].playing)
|
---|
119 | s1_end_looping(g1_average_rumbles[i]);
|
---|
120 |
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | void g1_stop_sound_averages()
|
---|
126 | {
|
---|
127 | for (int i=0; i<G1_T_RUMBLES; i++)
|
---|
128 | if (g1_average_rumbles[i].playing)
|
---|
129 | s1_end_looping(g1_average_rumbles[i]);
|
---|
130 | }
|
---|