- replace the homegrown hash chain in the sound engine with a TMap.

This commit is contained in:
Christoph Oelckers 2022-11-24 23:35:08 +01:00
parent a825dfb8ca
commit c60fea678d
3 changed files with 17 additions and 37 deletions

View file

@ -1465,21 +1465,11 @@ void SoundEngine::Reset()
FSoundID SoundEngine::FindSound(const char* logicalname)
{
int i;
if (logicalname != NULL)
{
i = S_sfx[MakeKey(logicalname) % S_sfx.Size()].index;
while ((i != 0) && stricmp(S_sfx[i].name, logicalname))
i = S_sfx[i].next;
return FSoundID::fromInt(i);
}
else
{
return NO_SOUND;
}
if (!logicalname) return NO_SOUND;
FName name(logicalname, true);
if (name == NAME_None) return NO_SOUND;
auto p = SoundMap.CheckKey(name);
return p ? *p : NO_SOUND;
}
FSoundID SoundEngine::FindSoundByResID(int resid)
@ -1498,11 +1488,13 @@ FSoundID SoundEngine::FindSoundByResID(int resid)
FSoundID SoundEngine::FindSoundNoHash(const char* logicalname)
{
unsigned int i;
if (!logicalname) return NO_SOUND;
FName name(logicalname, true);
if (name == NAME_None) return NO_SOUND;
for (i = 1; i < S_sfx.Size(); i++)
for (unsigned i = 1; i < S_sfx.Size(); i++)
{
if (stricmp(S_sfx[i].name, logicalname) == 0)
if (S_sfx[i].name == name)
{
return FSoundID::fromInt(i);
}
@ -1565,7 +1557,6 @@ FSoundID SoundEngine::AddSoundLump(const char* logicalname, int lump, int Curren
newsfx.name = logicalname;
newsfx.lumpnum = lump;
newsfx.next = 0;
newsfx.PitchMask = CurrentPitchMask;
newsfx.NearLimit = nearlimit;
newsfx.ResourceId = resid;
@ -1694,25 +1685,13 @@ FSoundID SoundEngine::PickReplacement(FSoundID refid)
void SoundEngine::HashSounds()
{
unsigned int i;
unsigned int j;
unsigned int size;
S_sfx.ShrinkToFit();
size = S_sfx.Size();
SoundMap.Clear();
ResIdMap.Clear();
// Mark all buckets as empty
for (i = 0; i < size; i++)
S_sfx[i].index = 0;
// Now set up the chains
for (i = 1; i < size; i++)
for (unsigned i = 1; i < S_sfx.Size(); i++)
{
j = MakeKey(S_sfx[i].name) % size;
S_sfx[i].next = S_sfx[j].index;
S_sfx[j].index = i;
SoundMap.Insert(S_sfx[i].name, FSoundID::fromInt(i));
if (S_sfx[i].ResourceId != -1)
{
ResIdMap.Insert(S_sfx[i].ResourceId, FSoundID::fromInt(i));

View file

@ -1,6 +1,7 @@
#pragma once
#include "i_sound.h"
#include "name.h"
enum
{
@ -78,10 +79,9 @@ constexpr FSoundID INVALID_SOUND = FSoundID::fromInt(-1);
// A non-null data means the sound has been loaded.
SoundHandle data{};
FString name; // [RH] Sound name defined in SNDINFO
FName name; // [RH] Sound name defined in SNDINFO
int lumpnum = sfx_empty; // lump number of sfx
unsigned int next = -1, index = 0; // [RH] For hashing
float Volume = 1.f;
int ResourceId = -1; // Resource ID as implemented by Blood. Not used by Doom but added for completeness.
@ -192,6 +192,7 @@ protected:
TArray<sfxinfo_t> S_sfx;
FRolloffInfo S_Rolloff{};
TArray<uint8_t> S_SoundCurve;
TMap<FName, FSoundID> SoundMap;
TMap<int, FSoundID> ResIdMap;
TArray<FRandomSoundList> S_rnd;
bool blockNewSounds = false;

View file

@ -766,7 +766,7 @@ void S_WorldTourMappingsForOldSounds()
for(unsigned i = 1; i < maxsnd; i++)
{
auto sfx = soundEngine->GetSfx(FSoundID::fromInt(i));
auto fname = sfx->name;
FString fname = sfx->name.GetChars();
if (!fname.Right(4).CompareNoCase(".ogg"))
{
// All names here follow the same convention. We must strip the "sound/" folder and replace the extension to get the original VOCs.