- ensure that sfxinfo_t is always fully initialized, regardless how the setup is performed.

The recent pitch additions did not do this on all possible paths.
This commit is contained in:
Christoph Oelckers 2020-10-10 10:21:50 +02:00
parent 4deb7593b5
commit a6842b6482
3 changed files with 30 additions and 93 deletions

View file

@ -50,7 +50,6 @@ enum
}; };
static FRandom pr_soundpitch ("SoundPitch"); static FRandom pr_soundpitch ("SoundPitch");
SoundEngine* soundEngine; SoundEngine* soundEngine;
int sfx_empty = -1;
//========================================================================== //==========================================================================
// //
@ -713,10 +712,9 @@ sfxinfo_t *SoundEngine::LoadSound(sfxinfo_t *sfx)
{ {
unsigned int i; unsigned int i;
// If the sound doesn't exist, replace it with the empty sound. if (sfx->lumpnum == sfx_empty)
if (sfx->lumpnum == -1)
{ {
sfx->lumpnum = sfx_empty; return sfx;
} }
// See if there is another sound already initialized with this lump. If so, // See if there is another sound already initialized with this lump. If so,
@ -1532,31 +1530,12 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc
S_sfx.Reserve(1); S_sfx.Reserve(1);
sfxinfo_t &newsfx = S_sfx.Last(); sfxinfo_t &newsfx = S_sfx.Last();
newsfx.data.Clear();
newsfx.name = logicalname; newsfx.name = logicalname;
newsfx.lumpnum = lump; newsfx.lumpnum = lump;
newsfx.next = 0; newsfx.next = 0;
newsfx.index = 0;
newsfx.Volume = 1;
newsfx.Attenuation = 1;
newsfx.PitchMask = CurrentPitchMask; newsfx.PitchMask = CurrentPitchMask;
newsfx.DefPitch = 0.0;
newsfx.DefPitchMax = 0.0;
newsfx.NearLimit = nearlimit; newsfx.NearLimit = nearlimit;
newsfx.LimitRange = 256 * 256;
newsfx.bRandomHeader = false;
newsfx.bLoadRAW = false;
newsfx.b16bit = false;
newsfx.bUsed = false;
newsfx.bSingular = false;
newsfx.bTentative = false;
newsfx.ResourceId = resid; newsfx.ResourceId = resid;
newsfx.RawRate = 0;
newsfx.link = sfxinfo_t::NO_LINK;
newsfx.Rolloff.RolloffType = ROLLOFF_Doom;
newsfx.Rolloff.MinDistance = 0;
newsfx.Rolloff.MaxDistance = 0;
newsfx.LoopStart = -1;
if (resid >= 0) ResIdMap[resid] = S_sfx.Size() - 1; if (resid >= 0) ResIdMap[resid] = S_sfx.Size() - 1;
return (int)S_sfx.Size()-1; return (int)S_sfx.Size()-1;

View file

@ -8,7 +8,12 @@ struct FRandomSoundList
uint32_t Owner = 0; uint32_t Owner = 0;
}; };
extern int sfx_empty; enum
{
sfx_empty = -1
};
// //
// SoundFX struct. // SoundFX struct.
@ -17,71 +22,38 @@ struct sfxinfo_t
{ {
// Next field is for use by the system sound interface. // Next field is for use by the system sound interface.
// A non-null data means the sound has been loaded. // A non-null data means the sound has been loaded.
SoundHandle data; SoundHandle data{};
FString name; // [RH] Sound name defined in SNDINFO FString name; // [RH] Sound name defined in SNDINFO
int lumpnum; // lump number of sfx int lumpnum = sfx_empty; // lump number of sfx
unsigned int next, index; // [RH] For hashing unsigned int next = -1, index = 0; // [RH] For hashing
float Volume; float Volume = 1.f;
int ResourceId; // Resource ID as implemented by Blood. Not used by Doom but added for completeness. int ResourceId = -1; // Resource ID as implemented by Blood. Not used by Doom but added for completeness.
uint8_t PitchMask; float LimitRange = 256*256; // Range for sound limiting (squared for faster computations)
int16_t NearLimit; // 0 means unlimited float DefPitch = 0.f; // A defined pitch instead of a random one the sound plays at, similar to A_StartSound.
float LimitRange; // Range for sound limiting (squared for faster computations) float DefPitchMax = 0.f; // Randomized range with stronger control over pitch itself.
float DefPitch; // A defined pitch instead of a random one the sound plays at, similar to A_StartSound.
float DefPitchMax; // Randomized range with stronger control over pitch itself.
unsigned bRandomHeader:1; int16_t NearLimit = 4; // 0 means unlimited.
unsigned bLoadRAW:1; uint8_t PitchMask = 0;
unsigned b16bit:1; bool bRandomHeader = false;
unsigned bUsed:1; bool bLoadRAW = false;
unsigned bSingular:1; bool b16bit = false;
bool bUsed = false;
bool bSingular = false;
bool bTentative = true;
unsigned bTentative:1;
TArray<int> UserData; TArray<int> UserData;
int RawRate; // Sample rate to use when bLoadRAW is true int RawRate = 0; // Sample rate to use when bLoadRAW is true
int LoopStart = -1; // -1 means no specific loop defined
int LoopStart; // -1 means no specific loop defined unsigned int link = NO_LINK;;
unsigned int link;
enum { NO_LINK = 0xffffffff }; enum { NO_LINK = 0xffffffff };
FRolloffInfo Rolloff; FRolloffInfo Rolloff{};
float Attenuation; // Multiplies the attenuation passed to S_Sound. float Attenuation = 1.f; // Multiplies the attenuation passed to S_Sound.
void MarkUsed(); // Marks this sound as used.
void Clear()
{
data.Clear();
lumpnum = -1; // lump number of sfx
next = -1;
index = 0; // [RH] For hashing
Volume = 1.f;
ResourceId = -1;
PitchMask = 0;
NearLimit = 4; // 0 means unlimited
LimitRange = 256*256;
bRandomHeader = false;
bLoadRAW = false;
b16bit= false;
bUsed = false;
bSingular = false;
bTentative = true;
RawRate = 0; // Sample rate to use when bLoadRAW is true
LoopStart = 0; // -1 means no specific loop defined
link = NO_LINK;
Rolloff = {};
Attenuation = 1.f;
}
}; };
// Rolloff types // Rolloff types

View file

@ -766,7 +766,6 @@ void S_ParseSndInfo (bool redefine)
S_ShrinkPlayerSoundLists (); S_ShrinkPlayerSoundLists ();
sfx_empty = fileSystem.CheckNumForName ("dsempty", ns_sounds);
S_CheckIntegrity(); S_CheckIntegrity();
} }
@ -1671,19 +1670,6 @@ int S_FindSkinnedSoundEx (AActor *actor, const char *name, const char *extendedn
return S_FindSkinnedSound (actor, id); return S_FindSkinnedSound (actor, id);
} }
//==========================================================================
//
// sfxinfo_t :: MarkUsed
//
// Marks this sound for precaching.
//
//==========================================================================
void sfxinfo_t::MarkUsed()
{
bUsed = true;
}
//========================================================================== //==========================================================================
// //
// S_MarkPlayerSounds // S_MarkPlayerSounds