- Blood: add a dummy sound entry at index 0.

Parts of the sound system treat entry 0 as "no sound" so nothing placed there would play.
This made the one custom sound in "The Way of Ira" not play because as the last sound being defined it ended up in the first, invalid slot.
This commit is contained in:
Christoph Oelckers 2021-04-12 00:10:43 +02:00
parent d25838fe15
commit f87e40131f
4 changed files with 54 additions and 48 deletions

View file

@ -208,50 +208,50 @@ void S_SerializeSounds(FSerializer& arc)
{ {
FSoundChan* chan; FSoundChan* chan;
GSnd->Sync(true); GSnd->Sync(true);
if (arc.isWriting()) if (arc.isWriting())
{
// Count channels and accumulate them so we can store them in
// reverse order. That way, they will be in the same order when
// reloaded later as they are now.
TArray<FSoundChan*> chans = soundEngine->AllActiveChannels();
if (chans.Size() > 0 && arc.BeginArray("sounds"))
{ {
// Count channels and accumulate them so we can store them in for (unsigned int i = chans.Size(); i-- != 0; )
// reverse order. That way, they will be in the same order when
// reloaded later as they are now.
TArray<FSoundChan*> chans = soundEngine->AllActiveChannels();
if (chans.Size() > 0 && arc.BeginArray("sounds"))
{ {
for (unsigned int i = chans.Size(); i-- != 0; ) // Replace start time with sample position.
{ uint64_t start = chans[i]->StartTime;
// Replace start time with sample position. chans[i]->StartTime = GSnd ? GSnd->GetPosition(chans[i]) : 0;
uint64_t start = chans[i]->StartTime; arc(nullptr, *chans[i]);
chans[i]->StartTime = GSnd ? GSnd->GetPosition(chans[i]) : 0; chans[i]->StartTime = start;
arc(nullptr, *chans[i]);
chans[i]->StartTime = start;
}
arc.EndArray();
} }
arc.EndArray();
} }
else }
else
{
unsigned int count;
soundEngine->StopAllChannels();
if (arc.BeginArray("sounds"))
{ {
unsigned int count; count = arc.ArraySize();
for (unsigned int i = 0; i < count; ++i)
soundEngine->StopAllChannels();
if (arc.BeginArray("sounds"))
{ {
count = arc.ArraySize(); chan = (FSoundChan*)soundEngine->GetChannel(nullptr);
for (unsigned int i = 0; i < count; ++i) arc(nullptr, *chan);
{ // Sounds always start out evicted when restored from a save.
chan = (FSoundChan*)soundEngine->GetChannel(nullptr); chan->ChanFlags |= CHANF_EVICTED | CHANF_ABSTIME;
arc(nullptr, *chan);
// Sounds always start out evicted when restored from a save.
chan->ChanFlags |= CHANF_EVICTED | CHANF_ABSTIME;
}
arc.EndArray();
} }
// Add a small delay so that eviction only runs once the game is up and runnnig. arc.EndArray();
soundEngine->SetRestartTime(I_GetTime() + 2);
} }
GSnd->Sync(false); // Add a small delay so that eviction only runs once the game is up and runnnig.
GSnd->UpdateSounds(); soundEngine->SetRestartTime(I_GetTime() + 2);
}
GSnd->Sync(false);
GSnd->UpdateSounds();
} }
//========================================================================== //==========================================================================
@ -297,3 +297,18 @@ CCMD(playsoundid)
} }
} }
} }
//==========================================================================
//
// CCMD listsounds
//
//==========================================================================
CCMD(listsounds)
{
auto& S_sfx = soundEngine->GetSounds();
for (unsigned i = 0; i < S_sfx.Size(); i++)
{
Printf("%4d: name = %s, resId = %d, lumpnum = %d\n", i, S_sfx[i].name.GetChars(), S_sfx[i].ResourceId, S_sfx[i].lumpnum);
}
}

View file

@ -58,15 +58,6 @@ public:
}; };
void sfxInit(void)
{
soundEngine = new BloodSoundEngine;
}
void sfxTerm()
{
}
//========================================================================== //==========================================================================
// //
// //

View file

@ -106,7 +106,8 @@ static void S_AddBloodSFX(int lumpnum)
void sndInit(void) void sndInit(void)
{ {
sfxInit(); soundEngine = new BloodSoundEngine;
soundEngine->AddSoundLump("", 0, 0, -1, 6); // add a dummy entry at index #0
for (int i = fileSystem.GetNumEntries() - 1; i >= 0; i--) for (int i = fileSystem.GetNumEntries() - 1; i >= 0; i--)
{ {
auto type = fileSystem.GetResourceType(i); auto type = fileSystem.GetResourceType(i);
@ -117,7 +118,8 @@ void sndInit(void)
} }
else if (!stricmp(type, "WAV") || !stricmp(type, "OGG") || !stricmp(type, "FLAC") || !stricmp(type, "VOC")) else if (!stricmp(type, "WAV") || !stricmp(type, "OGG") || !stricmp(type, "FLAC") || !stricmp(type, "VOC"))
{ {
soundEngine->AddSoundLump(fileSystem.GetFileFullName(i), i, 0, fileSystem.GetResourceId(i)| 0x40000000, 6); // mark the resource ID as special. if (fileSystem.GetFileNamespace(i) != ns_music)
soundEngine->AddSoundLump(fileSystem.GetFileFullName(i), i, 0, fileSystem.GetResourceId(i)| 0x40000000, 6); // mark the resource ID as special.
} }
} }
soundEngine->HashSounds(); soundEngine->HashSounds();

View file

@ -50,8 +50,6 @@ void sndProcess(void);
void sndTerm(void); void sndTerm(void);
void sndInit(void); void sndInit(void);
void sfxInit(void);
void sfxTerm(void);
void sfxPlay3DSound(int x, int y, int z, int soundId, int nSector); void sfxPlay3DSound(int x, int y, int z, int soundId, int nSector);
void sfxPlay3DSound(spritetype *pSprite, int soundId, int a3 = -1, int a4 = 0); void sfxPlay3DSound(spritetype *pSprite, int soundId, int a3 = -1, int a4 = 0);
void sfxPlay3DSoundCP(spritetype* pSprite, int soundId, int a3 = -1, int a4 = 0, int pitch = 0, int volume = 0); void sfxPlay3DSoundCP(spritetype* pSprite, int soundId, int a3 = -1, int a4 = 0, int pitch = 0, int volume = 0);