Skip to content

Commit

Permalink
Instead of going through a global callback function set the string ta…
Browse files Browse the repository at this point in the history
…ble's default gender at the start of each frame

This will perform the CVAR lookup only once per frame, not once per string.
  • Loading branch information
coelckers committed Apr 21, 2024
1 parent ebd4ebf commit f2d7bbe
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/common/engine/i_interface.h
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/common/engine/stringtable.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/common/engine/stringtable.h
Expand Up @@ -101,13 +101,15 @@ class FStringTable
bool exists(const char *name);

void InsertString(int filenum, int langid, FName label, const FString& string);
void SetDefaultGender(int gender) { defaultgender = gender; }

private:

FString activeLanguage;
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);
Expand Down
8 changes: 2 additions & 6 deletions src/d_main.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3647,7 +3644,6 @@ static int D_DoomMain_Internal (void)
System_GetPlayerName,
System_DispatchEvent,
StrTable_ValidFilter,
StrTable_GetGender,
nullptr,
CheckSkipGameOptionBlock,
System_ConsoleToggled,
Expand Down

0 comments on commit f2d7bbe

Please sign in to comment.