mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 14:51:40 +00:00
- merged string table callbacks with system callbacks.
This commit is contained in:
parent
f30285b0ce
commit
f6240ef428
4 changed files with 11 additions and 28 deletions
|
@ -23,6 +23,7 @@ struct SystemCallbacks
|
|||
FString(*GetPlayerName)(int i);
|
||||
bool (*DispatchEvent)(event_t* ev);
|
||||
bool (*CheckGame)(const char* nm);
|
||||
int (*GetGender)();
|
||||
};
|
||||
|
||||
extern SystemCallbacks sysCallbacks;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "filesystem.h"
|
||||
#include "sc_man.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())
|
||||
{
|
||||
bool ok = false;
|
||||
if (callbacks && callbacks->ValidFilter)
|
||||
if (sysCallbacks.CheckGame)
|
||||
{
|
||||
auto filter = filterstr.Split(" ", FString::TOK_SKIPEMPTY);
|
||||
for (auto& entry : filter)
|
||||
{
|
||||
if (callbacks->ValidFilter(entry))
|
||||
if (sysCallbacks.CheckGame(entry))
|
||||
{
|
||||
ok = true;
|
||||
break;
|
||||
|
@ -356,7 +357,7 @@ void FStringTable::LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer)
|
|||
sc.MustGetStringName("ifgame");
|
||||
sc.MustGetStringName("(");
|
||||
sc.MustGetString();
|
||||
skip |= (!callbacks || !callbacks->ValidFilter || !callbacks->ValidFilter(sc.String));
|
||||
skip |= (!sysCallbacks.CheckGame || !sysCallbacks.CheckGame(sc.String));
|
||||
sc.MustGetStringName(")");
|
||||
sc.MustGetString();
|
||||
|
||||
|
@ -564,7 +565,7 @@ const char *FStringTable::GetString(const char *name, uint32_t *langtable, int g
|
|||
{
|
||||
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;
|
||||
FName nm(name, true);
|
||||
if (nm != NAME_None)
|
||||
|
@ -597,7 +598,7 @@ const char *FStringTable::GetLanguageString(const char *name, uint32_t langtable
|
|||
{
|
||||
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;
|
||||
FName nm(name, true);
|
||||
if (nm != NAME_None)
|
||||
|
|
|
@ -50,13 +50,6 @@
|
|||
#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
|
||||
{
|
||||
int filenum;
|
||||
|
@ -108,7 +101,6 @@ public:
|
|||
return GetString(name, nullptr);
|
||||
}
|
||||
bool exists(const char *name);
|
||||
void SetCallbacks(StringtableCallbacks* cb) { callbacks = cb; }
|
||||
|
||||
void InsertString(int lumpnum, int langid, FName label, const FString& string);
|
||||
|
||||
|
@ -118,8 +110,7 @@ private:
|
|||
StringMacroMap allMacros;
|
||||
LangMap allStrings;
|
||||
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
|
||||
StringtableCallbacks* callbacks = nullptr;
|
||||
|
||||
|
||||
void LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer);
|
||||
TArray<TArray<FString>> parseCSV(const TArray<uint8_t> &buffer);
|
||||
bool ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer);
|
||||
|
|
|
@ -2741,11 +2741,6 @@ static bool System_DispatchEvent(event_t* ev)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool System_CheckGame(const char* name)
|
||||
{
|
||||
return CheckGame(name, false);
|
||||
}
|
||||
|
||||
bool System_NetGame()
|
||||
{
|
||||
return netgame;
|
||||
|
@ -3055,13 +3050,6 @@ static int D_DoomMain_Internal (void)
|
|||
buttonMap.GetButton(Button_Mlook)->bReleaseLock = true;
|
||||
buttonMap.GetButton(Button_Klook)->bReleaseLock = true;
|
||||
|
||||
static StringtableCallbacks stblcb =
|
||||
{
|
||||
StrTable_ValidFilter,
|
||||
StrTable_GetGender
|
||||
};
|
||||
GStrings.SetCallbacks(&stblcb);
|
||||
|
||||
sysCallbacks = {
|
||||
System_WantGuiCapture,
|
||||
System_WantLeftButton,
|
||||
|
@ -3078,7 +3066,9 @@ static int D_DoomMain_Internal (void)
|
|||
System_M_Dim,
|
||||
System_GetPlayerName,
|
||||
System_DispatchEvent,
|
||||
System_CheckGame,
|
||||
StrTable_ValidFilter,
|
||||
StrTable_GetGender
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue