- calculate proper distances in the sound code.

The original code didn't factor in that z has a different scale than x and y and use a function  with severe precision issues.
Fixes #81
This commit is contained in:
Christoph Oelckers 2020-07-31 00:08:39 +02:00
parent e211c7c91f
commit d0909b8224

View file

@ -197,9 +197,12 @@ static int GetPositionInfo(int spriteNum, int soundNum, int sectNum,
int userflags = snd ? snd[kFlags] : 0; int userflags = snd ? snd[kFlags] : 0;
int dist_adjust = snd ? snd[kVolAdjust] : 0; int dist_adjust = snd ? snd[kVolAdjust] : 0;
FVector3 sndorg = GetSoundPos(pos);
FVector3 campos = GetSoundPos(cam);
if (sp->picnum != TILE_APLAYER || sp->yvel != screenpeek) if (sp->picnum != TILE_APLAYER || sp->yvel != screenpeek)
{ {
orgsndist = sndist = FindDistance3D(cam->x - pos->x, cam->y - pos->y, (cam->z - pos->z)); orgsndist = sndist = int(16 * (sndorg - campos).Length());
if ((userflags & (SF_GLOBAL | SF_DTAG)) != SF_GLOBAL && sp->picnum == MUSICANDSFX && sp->lotag < 999 && (sector[sp->sectnum].lotag & 0xff) < ST_9_SLIDING_ST_DOOR) if ((userflags & (SF_GLOBAL | SF_DTAG)) != SF_GLOBAL && sp->picnum == MUSICANDSFX && sp->lotag < 999 && (sector[sp->sectnum].lotag & 0xff) < ST_9_SLIDING_ST_DOOR)
sndist = divscale14(sndist, sp->hitag + 1); sndist = divscale14(sndist, sp->hitag + 1);
@ -223,8 +226,6 @@ static int GetPositionInfo(int spriteNum, int soundNum, int sectNum,
if (sndPos) if (sndPos)
{ {
FVector3 sndorg = GetSoundPos(pos);
FVector3 campos = GetSoundPos(cam);
// Now calculate the virtual position in sound system coordinates. // Now calculate the virtual position in sound system coordinates.
FVector3 sndvec = sndorg - campos; FVector3 sndvec = sndorg - campos;
if (orgsndist > 0) if (orgsndist > 0)