Skip to content

Commit f2d7bbe

Browse files
committed
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.
1 parent ebd4ebf commit f2d7bbe

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

src/common/engine/i_interface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ struct SystemCallbacks
3131
FString(*GetPlayerName)(int i);
3232
bool (*DispatchEvent)(event_t* ev);
3333
bool (*CheckGame)(const char* nm);
34-
int (*GetGender)();
3534
void (*MenuClosed)();
3635
bool (*CheckMenudefOption)(const char* opt);
3736
void (*ConsoleToggled)(int state);

src/common/engine/stringtable.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ bool FStringTable::readMacros(const char* buffer, size_t size)
164164
auto data = parseCSV(buffer, size);
165165

166166
allMacros.Clear();
167-
for (unsigned i = 1; i < size; i++)
167+
for (unsigned i = 1; i < data.Size(); i++)
168168
{
169169
auto macroname = data[i][0];
170170
FName name = macroname.GetChars();
@@ -583,7 +583,7 @@ const char *FStringTable::CheckString(const char *name, uint32_t *langtable, int
583583
{
584584
return nullptr;
585585
}
586-
if (gender == -1 && sysCallbacks.GetGender) gender = sysCallbacks.GetGender();
586+
if (gender == -1) gender = defaultgender;
587587
if (gender < 0 || gender > 3) gender = 0;
588588
FName nm(name, true);
589589
if (nm != NAME_None)
@@ -623,7 +623,7 @@ const char *FStringTable::GetLanguageString(const char *name, uint32_t langtable
623623
{
624624
return nullptr;
625625
}
626-
if (gender == -1 && sysCallbacks.GetGender) gender = sysCallbacks.GetGender();
626+
if (gender == -1) gender = defaultgender;
627627
if (gender < 0 || gender > 3) gender = 0;
628628
FName nm(name, true);
629629
if (nm != NAME_None)

src/common/engine/stringtable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ class FStringTable
101101
bool exists(const char *name);
102102

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

105106
private:
106107

107108
FString activeLanguage;
108109
StringMacroMap allMacros;
109110
LangMap allStrings;
110111
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
112+
int defaultgender = 0;
111113

112114
void LoadLanguage (int lumpnum, const char* buffer, size_t size);
113115
TArray<TArray<FString>> parseCSV(const char* buffer, size_t size);

src/d_main.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,8 @@ void D_DoomLoop ()
11971197
{
11981198
try
11991199
{
1200+
GStrings.SetDefaultGender(players[consoleplayer].userinfo.GetGender()); // cannot be done when the CVAR changes because we don't know if it's for the consoleplayer.
1201+
12001202
// frame syncronous IO operations
12011203
if (gametic > lasttic)
12021204
{
@@ -2639,11 +2641,6 @@ void Mlook_ReleaseHandler()
26392641
}
26402642
}
26412643

2642-
int StrTable_GetGender()
2643-
{
2644-
return players[consoleplayer].userinfo.GetGender();
2645-
}
2646-
26472644
bool StrTable_ValidFilter(const char* str)
26482645
{
26492646
if (gameinfo.gametype == GAME_Strife && (gameinfo.flags & GI_SHAREWARE) && !stricmp(str, "strifeteaser")) return true;
@@ -3647,7 +3644,6 @@ static int D_DoomMain_Internal (void)
36473644
System_GetPlayerName,
36483645
System_DispatchEvent,
36493646
StrTable_ValidFilter,
3650-
StrTable_GetGender,
36513647
nullptr,
36523648
CheckSkipGameOptionBlock,
36533649
System_ConsoleToggled,

0 commit comments

Comments
 (0)