- Removed the S_Sound() variant that allows for pointing the origin at an

arbitrary point. It has been replaced with a variant that takes a polyobject
  as a source, since that was the only use that couldn't be rewritten with the
  other variants. This also fixes the bug that polyobject sounds were not
  successfully saved and caused a crash when reloading the game. Note that
  this is a significant change to how equality of sound sources is determined,
  so some things may not behave quite the same as before. (Which would be a
  bug, but hopefully everything still sounds the same.)


SVN r1059 (trunk)
This commit is contained in:
Randy Heit 2008-07-01 04:06:56 +00:00
commit a3e8a0cefd
39 changed files with 473 additions and 251 deletions

View file

@ -67,8 +67,6 @@ extern HWND Window;
// Just some extra for music and whatever
#define NUM_EXTRA_SOFTWARE_CHANNELS 1
#define FIXED2FLOAT(x) ((x)/65536.f)
#define MAX_CHANNELS 256
#define SPECTRUM_SIZE 256
@ -1408,8 +1406,8 @@ FSoundChan *FMODSoundRenderer::StartSound(sfxinfo_t *sfx, float vol, int pitch,
CVAR(Float, snd_3dspread, 180, 0)
FSoundChan *FMODSoundRenderer::StartSound3D(sfxinfo_t *sfx, float vol, float distscale,
int pitch, int priority, float pos[3], float vel[3], sector_t *sector, int channum, int chanflags,
FSoundChan *reuse_chan)
int pitch, int priority, const FVector3 &pos, const FVector3 &vel, const sector_t *sector,
int channum, int chanflags, FSoundChan *reuse_chan)
{
int id = int(sfx - &S_sfx[0]);
FMOD_RESULT result;
@ -1480,7 +1478,7 @@ FSoundChan *FMODSoundRenderer::StartSound3D(sfxinfo_t *sfx, float vol, float dis
chan->setVolume(vol);
if (mode & FMOD_3D)
{
chan->set3DAttributes((FMOD_VECTOR *)pos, (FMOD_VECTOR *)vel);
chan->set3DAttributes((FMOD_VECTOR *)&pos[0], (FMOD_VECTOR *)&vel[0]);
chan->set3DSpread(snd_3dspread);
}
HandleChannelDelay(chan, reuse_chan, freq);
@ -1546,16 +1544,17 @@ void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reus
//
//==========================================================================
FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t *sfx, float pos[3], int channum, int chanflags, sector_t *sec, FMOD_MODE oldmode) const
FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t *sfx, const FVector3 &pos, int channum, int chanflags, const sector_t *sec, FMOD_MODE oldmode) const
{
if (players[consoleplayer].camera == NULL)
{
return oldmode;
}
float cpos[3];
cpos[0] = FIXED2FLOAT(players[consoleplayer].camera->x);
cpos[2] = FIXED2FLOAT(players[consoleplayer].camera->y);
cpos[1] = FIXED2FLOAT(players[consoleplayer].camera->z);
FVector3 cpos, mpos;
cpos.X = FIXED2FLOAT(players[consoleplayer].camera->x);
cpos.Y = FIXED2FLOAT(players[consoleplayer].camera->z);
cpos.Z = FIXED2FLOAT(players[consoleplayer].camera->y);
mpos = pos;
if ((chanflags & CHAN_AREA) && sec != NULL)
{
@ -1567,8 +1566,8 @@ FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t
// Are we inside the sector? If yes, the closest point is the one we're on.
if (P_PointInSector(players[consoleplayer].camera->x, players[consoleplayer].camera->y) == sec)
{
pos[0] = cpos[0];
pos[2] = cpos[2];
mpos[0] = cpos[0];
mpos[2] = cpos[2];
cx = players[consoleplayer].camera->x;
cy = players[consoleplayer].camera->y;
}
@ -1577,8 +1576,8 @@ FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t
// Find the closest point on the sector's boundary lines and use
// that as the perceived origin of the sound.
sec->ClosestPoint(players[consoleplayer].camera->x, players[consoleplayer].camera->y, cx, cy);
pos[0] = FIXED2FLOAT(cx);
pos[2] = FIXED2FLOAT(cy);
mpos[0] = FIXED2FLOAT(cx);
mpos[2] = FIXED2FLOAT(cy);
}
// Set sound height based on channel.
if (channum == CHAN_FLOOR)
@ -1598,13 +1597,12 @@ FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t
{
cz = players[consoleplayer].camera->z;
}
pos[1] = FIXED2FLOAT(cz);
mpos[1] = FIXED2FLOAT(cz);
// How far are we from the perceived sound origin? Within a certain
// short distance, we interpolate between 2D panning and full 3D panning.
const double interp_range = 32.0;
double dx = cpos[0] - pos[0], dy = cpos[1] - pos[1], dz = cpos[2] - pos[2];
double dist_sqr = dx*dx + dy*dy + dz*dz;
double dist_sqr = (cpos - mpos).LengthSquared();
if (dist_sqr == 0)
{
@ -1630,7 +1628,7 @@ FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t
}
return oldmode;
}
else if (cpos[0] == pos[0] && cpos[1] == pos[1] && cpos[2] == pos[2])
else if (cpos == mpos)
{ // Head relative
return (oldmode & ~FMOD_3D) | FMOD_2D;
}
@ -1754,7 +1752,7 @@ void FMODSoundRenderer::SetInactive(bool inactive)
//
//==========================================================================
void FMODSoundRenderer::UpdateSoundParams3D(FSoundChan *chan, float pos[3], float vel[3])
void FMODSoundRenderer::UpdateSoundParams3D(FSoundChan *chan, const FVector3 &pos, const FVector3 &vel)
{
if (chan == NULL || chan->SysChannel == NULL)
return;
@ -1771,7 +1769,7 @@ void FMODSoundRenderer::UpdateSoundParams3D(FSoundChan *chan, float pos[3], floa
{ // Only set the mode if it changed.
fchan->setMode(mode);
}
fchan->set3DAttributes((FMOD_VECTOR *)pos, (FMOD_VECTOR *)vel);
fchan->set3DAttributes((FMOD_VECTOR *)&pos[0], (FMOD_VECTOR *)&vel[0]);
}
//==========================================================================