mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-18 15:42:34 +00:00
- Changed sound interface so that all references to game data like actors
and sectors are done in s_sound.cpp and not in fmodsound.cpp. Also removed several 'sector' parameters because they were never used inside the sound code. SVN r1200 (trunk)
This commit is contained in:
parent
535f7d92ba
commit
bcbd2162b7
8 changed files with 108 additions and 47 deletions
|
@ -1,3 +1,8 @@
|
|||
September 6, 2008 (Changes by Graf Zahl)
|
||||
- Changed sound interface so that all references to game data like actors
|
||||
and sectors are done in s_sound.cpp and not in fmodsound.cpp. Also removed
|
||||
several 'sector' parameters because they were never used inside the sound code.
|
||||
|
||||
September 5, 2008
|
||||
- Added the "extended" keyword for episode definitions to define episodes
|
||||
that are only available in the extended version of Heretic.
|
||||
|
|
|
@ -110,6 +110,7 @@ static void CalcPolyobjSoundOrg(const FPolyObj *poly, fixed_t *x, fixed_t *y, fi
|
|||
static FSoundChan *S_StartSound(AActor *mover, const sector_t *sec, const FPolyObj *poly,
|
||||
const FVector3 *pt, int channel, FSoundID sound_id, float volume, float attenuation);
|
||||
static sfxinfo_t *S_LoadSound(sfxinfo_t *sfx);
|
||||
static void S_SetListener(SoundListener &listener, AActor *listenactor);
|
||||
|
||||
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
||||
|
||||
|
@ -988,7 +989,9 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO
|
|||
}
|
||||
else if (attenuation > 0)
|
||||
{
|
||||
chan = GSnd->StartSound3D (sfx, volume, attenuation, pitch, basepriority, pos, vel, sec, channel, chanflags, NULL);
|
||||
SoundListener listener;
|
||||
S_SetListener(listener, players[consoleplayer].camera);
|
||||
chan = GSnd->StartSound3D (sfx, &listener, volume, attenuation, pitch, basepriority, pos, vel, channel, chanflags, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1073,8 +1076,11 @@ void S_RestartSound(FSoundChan *chan)
|
|||
return;
|
||||
}
|
||||
|
||||
ochan = GSnd->StartSound3D(sfx, chan->Volume, chan->DistanceScale, chan->Pitch,
|
||||
chan->Priority, pos, vel, chan->Sector, chan->EntChannel, chan->ChanFlags, chan);
|
||||
SoundListener listener;
|
||||
S_SetListener(listener, players[consoleplayer].camera);
|
||||
|
||||
ochan = GSnd->StartSound3D(sfx, &listener, chan->Volume, chan->DistanceScale, chan->Pitch,
|
||||
chan->Priority, pos, vel, chan->EntChannel, chan->ChanFlags, chan);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1570,9 +1576,10 @@ void S_RestoreEvictedChannels()
|
|||
// Updates music & sounds
|
||||
//==========================================================================
|
||||
|
||||
void S_UpdateSounds (void *listener_p)
|
||||
void S_UpdateSounds (AActor *listenactor)
|
||||
{
|
||||
FVector3 pos, vel;
|
||||
SoundListener listener;
|
||||
|
||||
I_UpdateMusic();
|
||||
|
||||
|
@ -1587,19 +1594,23 @@ void S_UpdateSounds (void *listener_p)
|
|||
S_ActivatePlayList(false);
|
||||
}
|
||||
|
||||
// should never happen
|
||||
S_SetListener(listener, listenactor);
|
||||
|
||||
for (FSoundChan *chan = Channels; chan != NULL; chan = chan->NextChan)
|
||||
{
|
||||
if ((chan->ChanFlags & (CHAN_EVICTED | CHAN_IS3D)) == CHAN_IS3D)
|
||||
{
|
||||
CalcPosVel(chan, &pos, &vel);
|
||||
GSnd->UpdateSoundParams3D(chan, pos, vel);
|
||||
GSnd->UpdateSoundParams3D(&listener, chan, pos, vel);
|
||||
}
|
||||
chan->ChanFlags &= ~CHAN_JUSTSTARTED;
|
||||
}
|
||||
|
||||
SN_UpdateActiveSequences();
|
||||
|
||||
GSnd->UpdateListener();
|
||||
|
||||
GSnd->UpdateListener(&listener);
|
||||
GSnd->UpdateSounds();
|
||||
|
||||
if (level.time >= RestartEvictionsAt)
|
||||
|
@ -1609,6 +1620,43 @@ void S_UpdateSounds (void *listener_p)
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Sets the internal listener structure
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void S_SetListener(SoundListener &listener, AActor *listenactor)
|
||||
{
|
||||
if (listenactor != NULL)
|
||||
{
|
||||
listener.angle = (float)(listenactor->angle) * ((float)PI / 2147483648.f);
|
||||
/*
|
||||
listener.velocity.X = listenactor->momx * (TICRATE/65536.f);
|
||||
listener.velocity.Y = listenactor->momz * (TICRATE/65536.f);
|
||||
listener.velocity.Z = listenactor->momy * (TICRATE/65536.f);
|
||||
*/
|
||||
listener.velocity.Zero();
|
||||
listener.position.X = FIXED2FLOAT(listenactor->x);
|
||||
listener.position.Y = FIXED2FLOAT(listenactor->y);
|
||||
listener.position.Z = FIXED2FLOAT(listenactor->z);
|
||||
listener.underwater = listenactor->waterlevel == 3;
|
||||
listener.ZoneNumber = listenactor->Sector->ZoneNumber;
|
||||
listener.valid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
listener.angle = 0;
|
||||
listener.position.Zero();
|
||||
listener.velocity.Zero();
|
||||
listener.underwater=false;
|
||||
listener.ZoneNumber=0;
|
||||
listener.valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// (FArchive &) << (FSoundID &)
|
||||
|
|
|
@ -327,7 +327,7 @@ void S_ResumeSound ();
|
|||
//
|
||||
// Updates music & sounds
|
||||
//
|
||||
void S_UpdateSounds (void *listener);
|
||||
void S_UpdateSounds (AActor *listener);
|
||||
|
||||
void S_RestoreEvictedChannels();
|
||||
|
||||
|
|
|
@ -51,13 +51,11 @@ extern HWND Window;
|
|||
#include "c_cvars.h"
|
||||
#include "i_system.h"
|
||||
#include "gi.h"
|
||||
#include "actor.h"
|
||||
#include "r_state.h"
|
||||
#include "w_wad.h"
|
||||
#include "i_music.h"
|
||||
#include "i_musicinterns.h"
|
||||
#include "v_text.h"
|
||||
#include "p_local.h"
|
||||
#include "v_palette.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
@ -1402,8 +1400,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, const FVector3 &pos, const FVector3 &vel, const sector_t *sector,
|
||||
FSoundChan *FMODSoundRenderer::StartSound3D(sfxinfo_t *sfx, SoundListener *listener, float vol, float distscale,
|
||||
int pitch, int priority, const FVector3 &pos, const FVector3 &vel,
|
||||
int channum, int chanflags, FSoundChan *reuse_chan)
|
||||
{
|
||||
int id = int(sfx - &S_sfx[0]);
|
||||
|
@ -1465,7 +1463,7 @@ FSoundChan *FMODSoundRenderer::StartSound3D(sfxinfo_t *sfx, float vol, float dis
|
|||
{
|
||||
mode = (mode & ~FMOD_LOOP_OFF) | FMOD_LOOP_NORMAL;
|
||||
}
|
||||
mode = SetChanHeadSettings(chan, sfx, pos, channum, chanflags, sector, mode);
|
||||
mode = SetChanHeadSettings(listener, chan, sfx, pos, channum, chanflags, mode);
|
||||
chan->setMode(mode);
|
||||
chan->setChannelGroup((chanflags & (CHAN_UI | CHAN_NOPAUSE)) ? SfxGroup : PausableSfx);
|
||||
|
||||
|
@ -1543,16 +1541,17 @@ void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reus
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
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
|
||||
FMOD_MODE FMODSoundRenderer::SetChanHeadSettings(SoundListener *listener, FMOD::Channel *chan, sfxinfo_t *sfx,
|
||||
const FVector3 &pos, int channum, int chanflags,
|
||||
FMOD_MODE oldmode) const
|
||||
{
|
||||
if (players[consoleplayer].camera == NULL)
|
||||
if (!listener->valid)
|
||||
{
|
||||
return oldmode;
|
||||
}
|
||||
FVector3 cpos, mpos;
|
||||
cpos.X = FIXED2FLOAT(players[consoleplayer].camera->x);
|
||||
cpos.Y = FIXED2FLOAT(players[consoleplayer].camera->z);
|
||||
cpos.Z = FIXED2FLOAT(players[consoleplayer].camera->y);
|
||||
|
||||
cpos = listener->position;
|
||||
|
||||
if (chanflags & CHAN_AREA)
|
||||
{
|
||||
|
@ -1725,7 +1724,7 @@ void FMODSoundRenderer::SetInactive(bool inactive)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FMODSoundRenderer::UpdateSoundParams3D(FSoundChan *chan, const FVector3 &pos, const FVector3 &vel)
|
||||
void FMODSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel)
|
||||
{
|
||||
if (chan == NULL || chan->SysChannel == NULL)
|
||||
return;
|
||||
|
@ -1737,7 +1736,7 @@ void FMODSoundRenderer::UpdateSoundParams3D(FSoundChan *chan, const FVector3 &po
|
|||
{
|
||||
oldmode = FMOD_3D | FMOD_SOFTWARE;
|
||||
}
|
||||
mode = SetChanHeadSettings(fchan, chan->SfxInfo, pos, chan->EntChannel, chan->ChanFlags, chan->Sector, oldmode);
|
||||
mode = SetChanHeadSettings(listener, fchan, chan->SfxInfo, pos, chan->EntChannel, chan->ChanFlags, oldmode);
|
||||
if (mode != oldmode)
|
||||
{ // Only set the mode if it changed.
|
||||
fchan->setMode(mode);
|
||||
|
@ -1751,32 +1750,30 @@ void FMODSoundRenderer::UpdateSoundParams3D(FSoundChan *chan, const FVector3 &po
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FMODSoundRenderer::UpdateListener()
|
||||
void FMODSoundRenderer::UpdateListener(SoundListener *listener)
|
||||
{
|
||||
AActor *listener = players[consoleplayer].camera;
|
||||
float angle;
|
||||
FMOD_VECTOR pos, vel;
|
||||
FMOD_VECTOR forward;
|
||||
FMOD_VECTOR up;
|
||||
|
||||
if (listener == NULL)
|
||||
if (!listener->valid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Set velocity to 0 to prevent crazy doppler shifts just from running.
|
||||
vel.x = 0;//listener->momx * (TICRATE/65536.f);
|
||||
vel.y = 0;//listener->momz * (TICRATE/65536.f);
|
||||
vel.z = 0;//listener->momy * (TICRATE/65536.f);
|
||||
pos.x = listener->x / 65536.f;
|
||||
pos.y = listener->z / 65536.f;
|
||||
pos.z = listener->y / 65536.f;
|
||||
|
||||
angle = (float)(listener->angle) * ((float)PI / 2147483648.f);
|
||||
vel.x = listener->velocity.X;
|
||||
vel.z = listener->velocity.Y;
|
||||
vel.y = listener->velocity.Z;
|
||||
pos.x = listener->position.X;
|
||||
pos.z = listener->position.Y;
|
||||
pos.y = listener->position.Z;
|
||||
|
||||
forward.x = cosf(angle);
|
||||
float angle = listener->angle;
|
||||
forward.x = cos(angle);
|
||||
forward.y = 0;
|
||||
forward.z = sinf(angle);
|
||||
forward.z = sin(angle);
|
||||
|
||||
up.x = 0;
|
||||
up.y = 1;
|
||||
|
@ -1793,9 +1790,9 @@ void FMODSoundRenderer::UpdateListener()
|
|||
}
|
||||
else
|
||||
{
|
||||
underwater = (listener->waterlevel == 3 && snd_waterlp);
|
||||
underwater = (listener->underwater && snd_waterlp);
|
||||
assert (zones != NULL);
|
||||
env = zones[listener->Sector->ZoneNumber].Environment;
|
||||
env = zones[listener->ZoneNumber].Environment;
|
||||
if (env == NULL)
|
||||
{
|
||||
env = DefaultEnvironments[0];
|
||||
|
@ -1812,7 +1809,7 @@ void FMODSoundRenderer::UpdateListener()
|
|||
if (underwater || env->SoftwareWater)
|
||||
{
|
||||
//PausableSfx->setPitch(0.64171f); // This appears to be what Duke 3D uses
|
||||
PausableSfx->setPitch(0.7937005f); // Approx. 4 semitones lower; what Nash suggesetd
|
||||
PausableSfx->setPitch(0.7937005f); // Approx. 4 semitones lower; what Nash suggested
|
||||
if (WaterLP != NULL)
|
||||
{
|
||||
if (LastWaterLP != snd_waterlp)
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
// Starts a sound.
|
||||
FSoundChan *StartSound (sfxinfo_t *sfx, float vol, int pitch, int chanflags, FSoundChan *reuse_chan);
|
||||
FSoundChan *StartSound3D (sfxinfo_t *sfx, float vol, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, const sector_t *sector, int channum, int chanflags, FSoundChan *reuse_chan);
|
||||
FSoundChan *StartSound3D (sfxinfo_t *sfx, SoundListener *listener, float vol, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, int channum, int chanflags, FSoundChan *reuse_chan);
|
||||
|
||||
// Stops a sound channel.
|
||||
void StopSound (FSoundChan *chan);
|
||||
|
@ -44,9 +44,9 @@ public:
|
|||
void SetInactive (bool inactive);
|
||||
|
||||
// Updates the position of a sound channel.
|
||||
void UpdateSoundParams3D (FSoundChan *chan, const FVector3 &pos, const FVector3 &vel);
|
||||
void UpdateSoundParams3D (SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel);
|
||||
|
||||
void UpdateListener ();
|
||||
void UpdateListener (SoundListener *listener);
|
||||
void UpdateSounds ();
|
||||
|
||||
void PrintStatus ();
|
||||
|
@ -69,7 +69,7 @@ private:
|
|||
|
||||
void HandleChannelDelay(FMOD::Channel *chan, FSoundChan *reuse_chan, float freq) const;
|
||||
FSoundChan *CommonChannelSetup(FMOD::Channel *chan, FSoundChan *reuse_chan) const;
|
||||
FMOD_MODE SetChanHeadSettings(FMOD::Channel *chan, sfxinfo_t *sfx, const FVector3 &pos, int channum, int chanflags, const sector_t *sec, FMOD_MODE oldmode) const;
|
||||
FMOD_MODE SetChanHeadSettings(SoundListener *listener, FMOD::Channel *chan, sfxinfo_t *sfx, const FVector3 &pos, int channum, int chanflags, FMOD_MODE oldmode) const;
|
||||
void DoLoad (void **slot, sfxinfo_t *sfx);
|
||||
void getsfx (sfxinfo_t *sfx);
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ public:
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
FSoundChan *StartSound3D (sfxinfo_t *sfx, float vol, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, const sector_t *sector, int channum, int chanflags, FSoundChan *reuse_chan)
|
||||
FSoundChan *StartSound3D (sfxinfo_t *sfx, SoundListener *listener, float vol, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, int channum, int chanflags, FSoundChan *reuse_chan)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -184,11 +184,11 @@ public:
|
|||
}
|
||||
|
||||
// Updates the volume, separation, and pitch of a sound channel.
|
||||
void UpdateSoundParams3D (FSoundChan *chan, const FVector3 &pos, const FVector3 &vel)
|
||||
void UpdateSoundParams3D (SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel)
|
||||
{
|
||||
}
|
||||
|
||||
void UpdateListener ()
|
||||
void UpdateListener (SoundListener *)
|
||||
{
|
||||
}
|
||||
void UpdateSounds ()
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#define __I_SOUND__
|
||||
|
||||
#include "s_sound.h"
|
||||
#include "vectors.h"
|
||||
|
||||
enum ECodecType
|
||||
{
|
||||
|
@ -43,6 +44,16 @@ enum ECodecType
|
|||
CODEC_Vorbis,
|
||||
};
|
||||
|
||||
struct SoundListener
|
||||
{
|
||||
FVector3 position;
|
||||
FVector3 velocity;
|
||||
float angle;
|
||||
bool underwater;
|
||||
bool valid;
|
||||
int ZoneNumber;
|
||||
};
|
||||
|
||||
class SoundStream
|
||||
{
|
||||
public:
|
||||
|
@ -91,7 +102,7 @@ public:
|
|||
|
||||
// Starts a sound.
|
||||
virtual FSoundChan *StartSound (sfxinfo_t *sfx, float vol, int pitch, int chanflags, FSoundChan *reuse_chan) = 0;
|
||||
virtual FSoundChan *StartSound3D (sfxinfo_t *sfx, float vol, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, const sector_t *sector, int channum, int chanflags, FSoundChan *reuse_chan) = 0;
|
||||
virtual FSoundChan *StartSound3D (sfxinfo_t *sfx, SoundListener *listener, float vol, float distscale, int pitch, int priority, const FVector3 &pos, const FVector3 &vel, int channum, int chanflags, FSoundChan *reuse_chan) = 0;
|
||||
|
||||
// Stops a sound channel.
|
||||
virtual void StopSound (FSoundChan *chan) = 0;
|
||||
|
@ -109,9 +120,9 @@ public:
|
|||
virtual void SetInactive(bool inactive) = 0;
|
||||
|
||||
// Updates the volume, separation, and pitch of a sound channel.
|
||||
virtual void UpdateSoundParams3D (FSoundChan *chan, const FVector3 &pos, const FVector3 &vel) = 0;
|
||||
virtual void UpdateSoundParams3D (SoundListener *listener, FSoundChan *chan, const FVector3 &pos, const FVector3 &vel) = 0;
|
||||
|
||||
virtual void UpdateListener () = 0;
|
||||
virtual void UpdateListener (SoundListener *) = 0;
|
||||
virtual void UpdateSounds () = 0;
|
||||
|
||||
virtual bool IsValid () = 0;
|
||||
|
|
|
@ -1348,7 +1348,7 @@ GOTWATER = "Picked up a glass of water.";
|
|||
GOTREPELLENT = "Picked up slime repellent.";
|
||||
GOTBREAKFAST = "Supercharge Breakfast!";
|
||||
GOTCBLUEKEY = "Picked up a blue key.";
|
||||
GOTCYELLOWKEY = "Picked up a yallow key.";
|
||||
GOTCYELLOWKEY = "Picked up a yellow key.";
|
||||
GOTCREDKEY = "Picked up a red key.";
|
||||
GOTFRUIT = "Picked up a bowl of fruit.";
|
||||
GOTVEGETABLESNEED = "Picked up some needed vegetables!";
|
||||
|
|
Loading…
Reference in a new issue