- merged string table and system callbacks.

This commit is contained in:
Christoph Oelckers 2020-10-04 21:15:51 +02:00
parent 5d76cbcbdb
commit 7f6b02c451
5 changed files with 12 additions and 28 deletions

View file

@ -22,6 +22,8 @@ struct SystemCallbacks
void (*MenuDim)(); void (*MenuDim)();
FString(*GetPlayerName)(int i); FString(*GetPlayerName)(int i);
bool (*DispatchEvent)(event_t* ev); bool (*DispatchEvent)(event_t* ev);
bool (*CheckGame)(const char* nm);
int (*GetGender)();
}; };
extern SystemCallbacks sysCallbacks; extern SystemCallbacks sysCallbacks;

View file

@ -39,6 +39,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "sc_man.h" #include "sc_man.h"
#include "printf.h" #include "printf.h"
#include "i_interface.h"
//========================================================================== //==========================================================================
// //
@ -237,12 +238,12 @@ bool FStringTable::ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer)
if (filterstr.IsNotEmpty()) if (filterstr.IsNotEmpty())
{ {
bool ok = false; bool ok = false;
if (callbacks && callbacks->ValidFilter) if (sysCallbacks.CheckGame)
{ {
auto filter = filterstr.Split(" ", FString::TOK_SKIPEMPTY); auto filter = filterstr.Split(" ", FString::TOK_SKIPEMPTY);
for (auto& entry : filter) for (auto& entry : filter)
{ {
if (callbacks->ValidFilter(entry)) if (sysCallbacks.CheckGame(entry))
{ {
ok = true; ok = true;
break; break;
@ -356,7 +357,7 @@ void FStringTable::LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer)
sc.MustGetStringName("ifgame"); sc.MustGetStringName("ifgame");
sc.MustGetStringName("("); sc.MustGetStringName("(");
sc.MustGetString(); sc.MustGetString();
skip |= (!callbacks || !callbacks->ValidFilter || !callbacks->ValidFilter(sc.String)); skip |= (!sysCallbacks.CheckGame || !sysCallbacks.CheckGame(sc.String));
sc.MustGetStringName(")"); sc.MustGetStringName(")");
sc.MustGetString(); sc.MustGetString();
@ -564,7 +565,7 @@ const char *FStringTable::GetString(const char *name, uint32_t *langtable, int g
{ {
return nullptr; return nullptr;
} }
if (gender == -1 && callbacks && callbacks->GetPlayerGender) gender = callbacks->GetPlayerGender(); if (gender == -1 && sysCallbacks.GetGender) gender = sysCallbacks.GetGender();
if (gender < 0 || gender > 3) gender = 0; if (gender < 0 || gender > 3) gender = 0;
FName nm(name, true); FName nm(name, true);
if (nm != NAME_None) if (nm != NAME_None)
@ -597,7 +598,7 @@ const char *FStringTable::GetLanguageString(const char *name, uint32_t langtable
{ {
return nullptr; return nullptr;
} }
if (gender == -1 && callbacks && callbacks->GetPlayerGender) gender = callbacks->GetPlayerGender(); if (gender == -1 && sysCallbacks.GetGender) gender = sysCallbacks.GetGender();
if (gender < 0 || gender > 3) gender = 0; if (gender < 0 || gender > 3) gender = 0;
FName nm(name, true); FName nm(name, true);
if (nm != NAME_None) if (nm != NAME_None)

View file

@ -50,13 +50,6 @@
#include "name.h" #include "name.h"
struct StringtableCallbacks
{
// These two functions would create a dependency on the game code so they are installed as callbacks.
bool (*ValidFilter)(const char* str);
int (*GetPlayerGender)();
};
struct TableElement struct TableElement
{ {
int filenum; int filenum;
@ -108,7 +101,6 @@ public:
return GetString(name, nullptr); return GetString(name, nullptr);
} }
bool exists(const char *name); bool exists(const char *name);
void SetCallbacks(StringtableCallbacks* cb) { callbacks = cb; }
void InsertString(int lumpnum, int langid, FName label, const FString& string); void InsertString(int lumpnum, int langid, FName label, const FString& string);
@ -118,7 +110,6 @@ private:
StringMacroMap allMacros; StringMacroMap allMacros;
LangMap allStrings; LangMap allStrings;
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet; TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
StringtableCallbacks* callbacks = nullptr;
void LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer); void LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer);
TArray<TArray<FString>> parseCSV(const TArray<uint8_t> &buffer); TArray<TArray<FString>> parseCSV(const TArray<uint8_t> &buffer);

View file

@ -159,12 +159,6 @@ int StrTable_GetGender()
bool validFilter(const char* str); bool validFilter(const char* str);
static StringtableCallbacks stblcb =
{
validFilter,
StrTable_GetGender
};
extern int chatmodeon; extern int chatmodeon;
bool System_WantGuiCapture() bool System_WantGuiCapture()
@ -516,6 +510,8 @@ int GameMain()
nullptr, nullptr,
nullptr, nullptr,
System_DispatchEvent, System_DispatchEvent,
validFilter,
StrTable_GetGender,
}; };
try try

View file

@ -175,13 +175,7 @@ FTextureID GetMenuTexture(const char* const name)
static void SkipSubBlock(FScanner &sc) static void SkipSubBlock(FScanner &sc)
{ {
sc.MustGetStringName("{"); sc.MustGetStringName("{");
int depth = 1; sc.SkipToEndOfBlock();
while (depth > 0)
{
sc.MustGetString();
if (sc.Compare("{")) depth++;
if (sc.Compare("}")) depth--;
}
} }
//============================================================================= //=============================================================================