mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-29 23:52:22 +00:00
more improvements to the sound offsetting
This commit is contained in:
parent
2f7d686a3c
commit
1d1982fddf
3 changed files with 23 additions and 26 deletions
|
@ -43,6 +43,7 @@ typedef struct sfx_s sfx_t;
|
|||
struct sfx_s
|
||||
{
|
||||
const char *name;
|
||||
sfx_t *owner;
|
||||
|
||||
unsigned int length;
|
||||
unsigned int loopstart;
|
||||
|
|
|
@ -546,12 +546,25 @@ SND_SetListener (const vec3_t origin, const vec3_t forward, const vec3_t right,
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
snd_check_channels (channel_t *target_chan, const channel_t *check,
|
||||
const sfx_t *osfx)
|
||||
{
|
||||
if (!check || check == target_chan)
|
||||
return 0;
|
||||
if (check->sfx->owner == osfx->owner && !check->pos) {
|
||||
int skip = rand () % (int) (0.01 * snd_shm->speed);
|
||||
target_chan->pos = -skip;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
||||
float fvol, float attenuation)
|
||||
{
|
||||
int vol;
|
||||
unsigned int skip;
|
||||
channel_t *target_chan, *check;
|
||||
sfx_t *osfx;
|
||||
|
||||
|
@ -562,7 +575,7 @@ SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
|||
sfx->loopstart != (unsigned) -1);
|
||||
if (!target_chan)
|
||||
return;
|
||||
|
||||
Sys_Printf ("SND_StartSound: %s\n", sfx->name);
|
||||
vol = fvol * 255;
|
||||
|
||||
// spatialize
|
||||
|
@ -581,32 +594,12 @@ SND_StartSound (int entnum, int entchannel, sfx_t *sfx, const vec3_t origin,
|
|||
|
||||
// if an identical sound has also been started this frame, offset the pos
|
||||
// a bit to keep it from just making the first one louder
|
||||
for (check = dynamic_channels; check; check = check->next) {
|
||||
if (!check || check == target_chan)
|
||||
continue;
|
||||
if (check->sfx == osfx && !check->pos) {
|
||||
skip = rand () % (int) (0.01 * snd_shm->speed);
|
||||
target_chan->pos = -skip;
|
||||
//if (skip >= target_chan->end)
|
||||
// skip = target_chan->end - 1;
|
||||
//target_chan->pos += skip;
|
||||
//target_chan->end -= skip;
|
||||
for (check = dynamic_channels; check; check = check->next)
|
||||
if (snd_check_channels (target_chan, check, osfx))
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (check = looped_dynamic_channels; check; check = check->next) {
|
||||
if (!check || check == target_chan)
|
||||
continue;
|
||||
if (check->sfx == osfx && !check->pos) {
|
||||
skip = rand () % (int) (0.01 * snd_shm->speed);
|
||||
target_chan->pos = -skip;
|
||||
//if (skip >= target_chan->end)
|
||||
// skip = target_chan->end - 1;
|
||||
//target_chan->pos += skip;
|
||||
//target_chan->end -= skip;
|
||||
for (check = looped_dynamic_channels; check; check = check->next)
|
||||
if (snd_check_channels (target_chan, check, osfx))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!osfx->retain (osfx))
|
||||
return; // couldn't load the sound's data
|
||||
target_chan->sfx = osfx;
|
||||
|
|
|
@ -70,6 +70,7 @@ snd_sfx_free (void *_sfx, void *unused)
|
|||
sfx_t *sfx = (sfx_t *) _sfx;
|
||||
free ((char *) sfx->name);
|
||||
sfx->name = 0;
|
||||
sfx->owner = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -122,6 +123,7 @@ SND_SFX_StreamOpen (sfx_t *sfx, void *file,
|
|||
sfx_t *new_sfx = calloc (1, sizeof (sfx_t));
|
||||
|
||||
new_sfx->name = sfx->name;
|
||||
new_sfx->owner = sfx;
|
||||
new_sfx->wavinfo = SND_CacheWavinfo;
|
||||
new_sfx->touch = new_sfx->retain = SND_StreamRetain;
|
||||
new_sfx->release = SND_StreamRelease;
|
||||
|
@ -175,6 +177,7 @@ SND_LoadSound (const char *name)
|
|||
|
||||
sfx = &snd_sfx[snd_num_sfx++];
|
||||
sfx->name = strdup (name);
|
||||
sfx->owner = sfx;
|
||||
SND_Load (sfx);
|
||||
Hash_Add (snd_sfx_hash, sfx);
|
||||
return sfx;
|
||||
|
|
Loading…
Reference in a new issue