Move the ambient level check out of the sound renderer.

Instead, the client gets the current leaf and passes ambient_sound_level
from the leaf to S_Update.
This commit is contained in:
Bill Currie 2012-02-13 13:44:29 +09:00
parent f389715730
commit 9a91aff93c
14 changed files with 42 additions and 37 deletions

View File

@ -44,7 +44,7 @@ typedef void (*P_S_StartSound) (int entnum, int entchannel, struct sfx_s *sfx, c
typedef void (*P_S_StaticSound) (struct sfx_s *sfx, const vec3_t origin, float vol, float attenuation);
typedef void (*P_S_StopSound) (int entnum, int entchannel);
typedef struct sfx_s * (*P_S_PrecacheSound) (const char *sample);
typedef void (*P_S_Update) (const vec3_t origin, const vec3_t v_forward, const vec3_t v_right, const vec3_t v_up);
typedef void (*P_S_Update) (const vec3_t origin, const vec3_t v_forward, const vec3_t v_right, const vec3_t v_up, const byte *ambient_sound_level);
typedef void (*P_S_StopAllSounds) (void);
typedef void (*P_S_ExtraUpdate) (void);
typedef void (*P_S_LocalSound) (const char *s);
@ -73,7 +73,6 @@ typedef struct snd_render_funcs_s {
} snd_render_funcs_t;
typedef struct snd_render_data_s {
struct model_s **worldmodel;
double *host_frametime;
int *viewentity;

View File

@ -73,12 +73,10 @@ struct model_s;
//@{
/** Initialize the sound engine.
\param worldmodel pointer to the main engine's world model pointer
\param viewentity pointer to view entity index
\param host_frametime pointer to host frame time difference
*/
void S_Init (struct model_s **worldmodel, int *viewentity,
double *host_frametime);
void S_Init (int *viewentity, double *host_frametime);
/** Initialize the Cvars for the sound engine. Call before calling S_Init().
*/
@ -135,9 +133,12 @@ void S_StopAllSounds(void);
\param v_forward 3d vector of the client's facing direction
\param v_right 3d vector of the client's rightward direction
\param v_up 3d vector of the client's upward direction
\param ambient_sound_level NUM_AMBIENTS bytes indicating current ambient
sound levels
*/
void S_Update (const vec3_t origin, const vec3_t v_forward,
const vec3_t v_right, const vec3_t v_up);
const vec3_t v_right, const vec3_t v_up,
const byte *ambient_sound_level);
/** Render some more sound without updating the client's position/orientation.
*/

View File

@ -342,7 +342,8 @@ void SND_AmbientOn (void);
\param v_up 3d vector of the client's upward direction
*/
void SND_SetListener (const vec3_t origin, const vec3_t v_forward,
const vec3_t v_right, const vec3_t v_up);
const vec3_t v_right, const vec3_t v_up,
const byte *ambient_sound_level);
/** Stop all sounds from playing.
*/

View File

@ -59,7 +59,6 @@ cd_xmms_la_SOURCES= cd_xmms.c
sound_libs= \
@snd_output_static_plugin_libs@ \
@snd_render_static_plugin_libs@ \
$(top_builddir)/libs/models/libQFmodels.la \
$(top_builddir)/libs/gamecode/libQFgamecode.la \
$(top_builddir)/libs/util/libQFutil.la

View File

@ -379,22 +379,17 @@ SND_AmbientOn (void)
}
static void
s_updateAmbientSounds (void)
s_updateAmbientSounds (const byte *ambient_sound_level)
{
float vol;
int ambient_channel;
channel_t *chan;
sfx_t *sfx;
mleaf_t *l;
if (!snd_ambient)
return;
// calc ambient sound levels
if (!snd_render_data.worldmodel || !*snd_render_data.worldmodel)
return;
l = Mod_PointInLeaf (listener_origin, *snd_render_data.worldmodel);
if (!l || !ambient_level->value) {
if (!ambient_sound_level || !ambient_level->value) {
// if we're not in a leaf (huh?) or ambients have been turned off,
// stop all ambient channels.
for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS;
@ -433,7 +428,7 @@ s_updateAmbientSounds (void)
// sfx will be written to chan->sfx later to ensure mixer doesn't use
// channel prematurely.
vol = ambient_level->value * l->ambient_sound_level[ambient_channel];
vol = ambient_level->value * ambient_sound_level[ambient_channel];
if (vol < 8)
vol = 0;
@ -528,7 +523,7 @@ s_combine_channel (channel_t *combine, channel_t *ch)
void
SND_SetListener (const vec3_t origin, const vec3_t forward, const vec3_t right,
const vec3_t up)
const vec3_t up, const byte *ambient_sound_level)
{
int i, j;
channel_t *combine, *ch;
@ -539,7 +534,7 @@ SND_SetListener (const vec3_t origin, const vec3_t forward, const vec3_t right,
VectorCopy (up, listener_up);
// update general area ambient sound sources
s_updateAmbientSounds ();
s_updateAmbientSounds (ambient_sound_level);
// update spatialization for dynamic sounds
for (ch = dynamic_channels; ch; ch = ch->next)

View File

@ -208,12 +208,12 @@ s_update_ (void)
*/
static void
s_update (const vec3_t origin, const vec3_t forward, const vec3_t right,
const vec3_t up)
const vec3_t up, const byte *ambient_sound_level)
{
if (!sound_started || (snd_blocked > 0))
return;
SND_SetListener (origin, forward, right, up);
SND_SetListener (origin, forward, right, up, ambient_sound_level);
// mix some sound
s_update_ ();

View File

@ -94,7 +94,7 @@ s_finish_channels (void)
static void
s_update (const vec3_t origin, const vec3_t forward, const vec3_t right,
const vec3_t up)
const vec3_t up, const byte *ambient_sound_level)
{
double now = Sys_DoubleTime ();
@ -119,7 +119,7 @@ s_update (const vec3_t origin, const vec3_t forward, const vec3_t right,
}
return;
}
SND_SetListener (origin, forward, right, up);
SND_SetListener (origin, forward, right, up, ambient_sound_level);
}
static void

View File

@ -59,7 +59,6 @@ snd_render_data_t snd_render_data = {
0,
0,
0,
0,
&snd_paintedtime,
0,
};

View File

@ -35,7 +35,6 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/cvar.h"
#include "QF/sound.h"
#include "QF/model.h"
#include "QF/plugin.h"
#include "QF/qargs.h"
#include "QF/sys.h"
@ -58,7 +57,7 @@ static plugin_list_t snd_render_list[] = {
VISIBLE void
S_Init (struct model_s **worldmodel, int *viewentity, double *host_frametime)
S_Init (int *viewentity, double *host_frametime)
{
if (COM_CheckParm ("-nosound"))
return;
@ -82,7 +81,6 @@ S_Init (struct model_s **worldmodel, int *viewentity, double *host_frametime)
PI_UnloadPlugin (snd_output_module);
snd_output_module = NULL;
} else {
snd_render_module->data->snd_render->worldmodel = worldmodel;
snd_render_module->data->snd_render->viewentity = viewentity;
snd_render_module->data->snd_render->host_frametime =
host_frametime;
@ -171,10 +169,11 @@ S_PrecacheSound (const char *sample)
VISIBLE void
S_Update (const vec3_t origin, const vec3_t v_forward, const vec3_t v_right,
const vec3_t v_up)
const vec3_t v_up, const byte *ambient_sound_level)
{
if (snd_render_funcs)
snd_render_funcs->pS_Update (origin, v_forward, v_right, v_up);
snd_render_funcs->pS_Update (origin, v_forward, v_right, v_up,
ambient_sound_level);
}
VISIBLE void

View File

@ -77,7 +77,7 @@ init (void)
PI_Init ();
S_Init_Cvars ();
S_Init (0, 0, 0);
S_Init (0, 0);
Cmd_StuffCmds (testsound_cbuf);
}
@ -91,7 +91,7 @@ main (int argc, const char *argv[])
while (1) {
Cbuf_Execute_Stack (testsound_cbuf);
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin, 0);
usleep(20 * 1000);
}
Sys_Quit ();

View File

@ -515,7 +515,7 @@ CL_Init (cbuf_t *cbuf)
IN_Init (cbuf);
Draw_Init ();
R_Init ();
S_Init (&cl.worldmodel, &viewentity, &host_frametime);
S_Init (&viewentity, &host_frametime);
CDAudio_Init ();
Sbar_Init ();

View File

@ -607,10 +607,16 @@ Host_ClientFrame (void)
// update audio
if (cls.signon == SIGNONS) {
S_Update (r_origin, vpn, vright, vup);
mleaf_t *l;
byte *asl = 0;
l = Mod_PointInLeaf (r_origin, cl.worldmodel);
if (l)
asl = l->ambient_sound_level;
S_Update (r_origin, vpn, vright, vup, asl);
R_DecayLights (host_frametime);
} else
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin, 0);
CDAudio_Update ();

View File

@ -161,7 +161,7 @@ R_DecayLights (double frametime)
void
S_Update (const vec3_t origin, const vec3_t v_forward, const vec3_t v_right,
const vec3_t v_up)
const vec3_t v_up, const byte *ambient_sound_level)
{
}

View File

@ -1189,7 +1189,7 @@ CL_Init (void)
Draw_Init ();
Mod_Init ();
R_Init ();
S_Init (&cl.worldmodel, &viewentity, &host_frametime);
S_Init (&viewentity, &host_frametime);
CDAudio_Init ();
Sbar_Init ();
@ -1660,10 +1660,16 @@ Host_Frame (float time)
// update audio
if (cls.state == ca_active) {
S_Update (r_origin, vpn, vright, vup);
mleaf_t *l;
byte *asl = 0;
l = Mod_PointInLeaf (r_origin, cl.worldmodel);
if (l)
asl = l->ambient_sound_level;
S_Update (r_origin, vpn, vright, vup, asl);
R_DecayLights (host_frametime);
} else
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin, 0);
CDAudio_Update ();