Instead of going through a global callback function set the string table's default gender at the start of each frame

This will perform the CVAR lookup only once per frame, not once per string.
This commit is contained in:
Christoph Oelckers 2024-04-21 10:30:40 +02:00
parent ebd4ebf298
commit f2d7bbea99
4 changed files with 7 additions and 10 deletions

View file

@ -31,7 +31,6 @@ struct SystemCallbacks
FString(*GetPlayerName)(int i);
bool (*DispatchEvent)(event_t* ev);
bool (*CheckGame)(const char* nm);
int (*GetGender)();
void (*MenuClosed)();
bool (*CheckMenudefOption)(const char* opt);
void (*ConsoleToggled)(int state);

View file

@ -164,7 +164,7 @@ bool FStringTable::readMacros(const char* buffer, size_t size)
auto data = parseCSV(buffer, size);
allMacros.Clear();
for (unsigned i = 1; i < size; i++)
for (unsigned i = 1; i < data.Size(); i++)
{
auto macroname = data[i][0];
FName name = macroname.GetChars();
@ -583,7 +583,7 @@ const char *FStringTable::CheckString(const char *name, uint32_t *langtable, int
{
return nullptr;
}
if (gender == -1 && sysCallbacks.GetGender) gender = sysCallbacks.GetGender();
if (gender == -1) gender = defaultgender;
if (gender < 0 || gender > 3) gender = 0;
FName nm(name, true);
if (nm != NAME_None)
@ -623,7 +623,7 @@ const char *FStringTable::GetLanguageString(const char *name, uint32_t langtable
{
return nullptr;
}
if (gender == -1 && sysCallbacks.GetGender) gender = sysCallbacks.GetGender();
if (gender == -1) gender = defaultgender;
if (gender < 0 || gender > 3) gender = 0;
FName nm(name, true);
if (nm != NAME_None)

View file

@ -101,6 +101,7 @@ public:
bool exists(const char *name);
void InsertString(int filenum, int langid, FName label, const FString& string);
void SetDefaultGender(int gender) { defaultgender = gender; }
private:
@ -108,6 +109,7 @@ private:
StringMacroMap allMacros;
LangMap allStrings;
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
int defaultgender = 0;
void LoadLanguage (int lumpnum, const char* buffer, size_t size);
TArray<TArray<FString>> parseCSV(const char* buffer, size_t size);

View file

@ -1197,6 +1197,8 @@ void D_DoomLoop ()
{
try
{
GStrings.SetDefaultGender(players[consoleplayer].userinfo.GetGender()); // cannot be done when the CVAR changes because we don't know if it's for the consoleplayer.
// frame syncronous IO operations
if (gametic > lasttic)
{
@ -2639,11 +2641,6 @@ void Mlook_ReleaseHandler()
}
}
int StrTable_GetGender()
{
return players[consoleplayer].userinfo.GetGender();
}
bool StrTable_ValidFilter(const char* str)
{
if (gameinfo.gametype == GAME_Strife && (gameinfo.flags & GI_SHAREWARE) && !stricmp(str, "strifeteaser")) return true;
@ -3647,7 +3644,6 @@ static int D_DoomMain_Internal (void)
System_GetPlayerName,
System_DispatchEvent,
StrTable_ValidFilter,
StrTable_GetGender,
nullptr,
CheckSkipGameOptionBlock,
System_ConsoleToggled,