mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-25 13:31:07 +00:00
This commit is contained in:
commit
558a7fcfb0
2 changed files with 107 additions and 11 deletions
|
@ -51,6 +51,7 @@
|
|||
#include "i_system.h"
|
||||
#include "d_player.h"
|
||||
#include "serializer.h"
|
||||
#include "v_text.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
@ -326,6 +327,99 @@ void S_HashSounds ()
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// S_CheckIntegrity
|
||||
//
|
||||
// Scans the entire sound list and looks for recursive definitions.
|
||||
//==========================================================================
|
||||
|
||||
static bool S_CheckSound(sfxinfo_t *startsfx, sfxinfo_t *sfx, TArray<sfxinfo_t *> &chain)
|
||||
{
|
||||
sfxinfo_t *me = sfx;
|
||||
bool success = true;
|
||||
unsigned siz = chain.Size();
|
||||
|
||||
if (sfx->bPlayerReserve)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// There is a bad link in here, but let's report it only for the sound that contains the broken definition.
|
||||
// Once that sound has been disabled this one will work again.
|
||||
if (chain.Find(sfx) < chain.Size())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
chain.Push(sfx);
|
||||
|
||||
if (me->bRandomHeader)
|
||||
{
|
||||
const FRandomSoundList *list = &S_rnd[me->link];
|
||||
for (int i = 0; i < list->NumSounds; ++i)
|
||||
{
|
||||
auto rsfx = &S_sfx[list->Sounds[i]];
|
||||
if (rsfx == startsfx)
|
||||
{
|
||||
Printf(TEXTCOLOR_RED "recursive sound $random found for %s:\n", startsfx->name);
|
||||
success = false;
|
||||
for (unsigned i = 1; i<chain.Size(); i++)
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE " -> %s\n", chain[i]->name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success &= S_CheckSound(startsfx, rsfx, chain);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (me->link != sfxinfo_t::NO_LINK)
|
||||
{
|
||||
me = &S_sfx[me->link];
|
||||
if (me == startsfx)
|
||||
{
|
||||
Printf(TEXTCOLOR_RED "recursive sound $alias found for %s:\n", startsfx->name);
|
||||
success = false;
|
||||
for (unsigned i = 1; i<chain.Size(); i++)
|
||||
{
|
||||
Printf(TEXTCOLOR_ORANGE " -> %s\n", chain[i]->name);
|
||||
}
|
||||
chain.Resize(siz);
|
||||
}
|
||||
else
|
||||
{
|
||||
success &= S_CheckSound(startsfx, me, chain);
|
||||
}
|
||||
}
|
||||
chain.Pop();
|
||||
return success;
|
||||
}
|
||||
|
||||
void S_CheckIntegrity()
|
||||
{
|
||||
TArray<sfxinfo_t *> chain;
|
||||
TArray<bool> broken;
|
||||
|
||||
broken.Resize(S_sfx.Size());
|
||||
memset(&broken[0], 0, sizeof(bool)*S_sfx.Size());
|
||||
for (unsigned i = 0; i < S_sfx.Size(); i++)
|
||||
{
|
||||
auto &sfx = S_sfx[i];
|
||||
broken[i] = !S_CheckSound(&sfx, &sfx, chain);
|
||||
}
|
||||
for (unsigned i = 0; i < S_sfx.Size(); i++)
|
||||
{
|
||||
if (broken[i])
|
||||
{
|
||||
auto &sfx = S_sfx[i];
|
||||
Printf(TEXTCOLOR_RED "Sound %s has been disabled\n", sfx.name);
|
||||
sfx.bRandomHeader = false;
|
||||
sfx.link = 0; // link to the empty sound.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// S_PickReplacement
|
||||
|
@ -334,13 +428,12 @@ void S_HashSounds ()
|
|||
// is not the head of a random list, then the sound passed is returned.
|
||||
//==========================================================================
|
||||
|
||||
int S_PickReplacement (int refid)
|
||||
int S_PickReplacement(int refid)
|
||||
{
|
||||
if (S_sfx[refid].bRandomHeader)
|
||||
while (S_sfx[refid].bRandomHeader)
|
||||
{
|
||||
const FRandomSoundList *list = &S_rnd[S_sfx[refid].link];
|
||||
|
||||
return list->Sounds[pr_randsound() % list->NumSounds];
|
||||
refid = list->Sounds[pr_randsound() % list->NumSounds];
|
||||
}
|
||||
return refid;
|
||||
}
|
||||
|
@ -941,6 +1034,7 @@ void S_ParseSndInfo (bool redefine)
|
|||
S_ShrinkPlayerSoundLists ();
|
||||
|
||||
sfx_empty = Wads.CheckNumForName ("dsempty", ns_sounds);
|
||||
S_CheckIntegrity();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -961,6 +1055,7 @@ void S_AddLocalSndInfo(int lump)
|
|||
}
|
||||
|
||||
S_ShrinkPlayerSoundLists ();
|
||||
S_CheckIntegrity();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -522,18 +522,19 @@ void S_CacheSound (sfxinfo_t *sfx)
|
|||
{
|
||||
return;
|
||||
}
|
||||
else if (sfx->bRandomHeader)
|
||||
sfxinfo_t *orig = sfx;
|
||||
while (!sfx->bRandomHeader && sfx->link != sfxinfo_t::NO_LINK)
|
||||
{
|
||||
S_CacheRandomSound (sfx);
|
||||
sfx = &S_sfx[sfx->link];
|
||||
}
|
||||
if (sfx->bRandomHeader)
|
||||
{
|
||||
S_CacheRandomSound(sfx);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (sfx->link != sfxinfo_t::NO_LINK)
|
||||
{
|
||||
sfx = &S_sfx[sfx->link];
|
||||
}
|
||||
S_LoadSound(sfx);
|
||||
sfx->bUsed = true;
|
||||
S_LoadSound (sfx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue