mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 04:11:18 +00:00
Sound refactor backport step 2: flattened split-somethings
branch
This commit is contained in:
parent
732861f0d4
commit
64189da28f
1 changed files with 79 additions and 48 deletions
101
src/s_sound.c
101
src/s_sound.c
|
@ -451,6 +451,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
|
|||
sfxinfo_t *sfx;
|
||||
INT32 sep, pitch, priority, cnum;
|
||||
boolean anyListeners = false;
|
||||
boolean itsUs = false;
|
||||
INT32 i;
|
||||
|
||||
listener_t listener[MAXSPLITSCREENPLAYERS];
|
||||
|
@ -473,10 +474,8 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
|
|||
if (i == 0 && democam.soundmobj)
|
||||
{
|
||||
listenmobj[i] = democam.soundmobj;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player->awayviewtics)
|
||||
else if (player->awayviewtics)
|
||||
{
|
||||
listenmobj[i] = player->awayviewmobj;
|
||||
}
|
||||
|
@ -484,6 +483,11 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
|
|||
{
|
||||
listenmobj[i] = player->mo;
|
||||
}
|
||||
|
||||
if (origin && origin == listenmobj[i])
|
||||
{
|
||||
itsUs = true;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HW3SOUND
|
||||
|
@ -538,40 +542,55 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
|
|||
// Initialize sound parameters
|
||||
pitch = NORM_PITCH;
|
||||
priority = NORM_PRIORITY;
|
||||
sep = NORM_SEP;
|
||||
|
||||
i = 0; // sensible default
|
||||
|
||||
for (i = splitscreen; i >= 0; i--)
|
||||
{
|
||||
// Copy the sound for the splitscreen players!
|
||||
if (listenmobj[i] == NULL && i != 0)
|
||||
// Check to see if it is audible, and if not, modify the params
|
||||
if (origin && !itsUs)
|
||||
{
|
||||
boolean audible = false;
|
||||
if (splitscreen > 0)
|
||||
{
|
||||
fixed_t recdist = INT32_MAX;
|
||||
UINT8 j = 0;
|
||||
|
||||
for (; j <= splitscreen; j++)
|
||||
{
|
||||
fixed_t thisdist = INT32_MAX;
|
||||
|
||||
if (!listenmobj[j])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check to see if it is audible, and if not, modify the params
|
||||
if (origin && origin != listenmobj[i])
|
||||
{
|
||||
boolean rc = S_AdjustSoundParams(listenmobj[i], origin, &volume, &sep, &pitch, sfx);
|
||||
thisdist = P_AproxDistance(listener[j].x - origin->x, listener[j].y - origin->y);
|
||||
|
||||
if (!rc)
|
||||
if (thisdist >= recdist)
|
||||
{
|
||||
continue; // Maybe the other player can hear it...
|
||||
continue;
|
||||
}
|
||||
|
||||
recdist = thisdist;
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (listenmobj[i])
|
||||
{
|
||||
audible = S_AdjustSoundParams(listenmobj[i], origin, &volume, &sep, &pitch, sfx);
|
||||
|
||||
if (origin->x == listener[i].x && origin->y == listener[i].y)
|
||||
{
|
||||
sep = NORM_SEP;
|
||||
}
|
||||
}
|
||||
else if (i > 0 && !origin)
|
||||
|
||||
if (!audible)
|
||||
{
|
||||
// Do not play origin-less sounds for the splitscreen players.
|
||||
// The first player will be able to hear it just fine,
|
||||
// we really don't want it playing twice.
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
sep = NORM_SEP;
|
||||
}
|
||||
|
||||
// This is supposed to handle the loading/caching.
|
||||
|
@ -829,46 +848,58 @@ void S_UpdateSounds(void)
|
|||
{
|
||||
boolean itsUs = false;
|
||||
|
||||
for (i = 0; i <= splitscreen; i++)
|
||||
{
|
||||
if (c->origin == players[displayplayers[i]].mo)
|
||||
for (i = splitscreen; i >= 0; i--)
|
||||
{
|
||||
if (c->origin != listenmobj[i])
|
||||
continue;
|
||||
|
||||
itsUs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (itsUs == false)
|
||||
{
|
||||
const mobj_t *soundmobj = c->origin;
|
||||
fixed_t recdist = INT32_MAX;
|
||||
UINT8 p = 0;
|
||||
const mobj_t *origin = c->origin;
|
||||
|
||||
for (i = 0; i <= splitscreen; i++)
|
||||
i = 0;
|
||||
|
||||
if (splitscreen > 0)
|
||||
{
|
||||
fixed_t recdist = INT32_MAX;
|
||||
UINT8 j = 0;
|
||||
|
||||
for (; j <= splitscreen; j++)
|
||||
{
|
||||
fixed_t thisdist = INT32_MAX;
|
||||
|
||||
if (!listenmobj[i])
|
||||
if (!listenmobj[j])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
thisdist = P_AproxDistance(listener[i].x - soundmobj->x, listener[i].y - soundmobj->y);
|
||||
thisdist = P_AproxDistance(listener[j].x - origin->x, listener[j].y - origin->y);
|
||||
|
||||
if (thisdist < recdist)
|
||||
if (thisdist >= recdist)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
recdist = thisdist;
|
||||
p = i;
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (listenmobj[p])
|
||||
if (listenmobj[i])
|
||||
{
|
||||
audible = S_AdjustSoundParams(
|
||||
listenmobj[p], c->origin,
|
||||
listenmobj[i], c->origin,
|
||||
&volume, &sep, &pitch,
|
||||
c->sfxinfo
|
||||
);
|
||||
|
||||
if (origin->x == listener[i].x && origin->y == listener[i].y)
|
||||
{
|
||||
sep = NORM_SEP;
|
||||
}
|
||||
}
|
||||
|
||||
if (audible)
|
||||
|
|
Loading…
Reference in a new issue