From 904f432f7d5ac4499e2d181621b91fd5444ec10a Mon Sep 17 00:00:00 2001 From: SollyBunny Date: Sat, 30 Nov 2024 08:38:37 +0000 Subject: [PATCH] Simplify settings loading/saving --- CMakeLists.txt | 54 ++--- src/engine/client/client.cpp | 6 +- src/engine/config.h | 15 +- src/engine/shared/config.cpp | 193 ++++++------------ src/engine/shared/config.h | 41 ++-- src/engine/shared/config_variables.h | 21 +- ...variables.h => config_variables_tclient.h} | 10 +- .../client/components/tclient/bindwheel.cpp | 2 +- 8 files changed, 145 insertions(+), 197 deletions(-) rename src/engine/shared/{tater_variables.h => config_variables_tclient.h} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e925e04b864..bf5d07bb7e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ else() set(TARGET_BITS "64") endif() -if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" +if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "ARM64") if(TARGET_BITS STREQUAL "32") @@ -74,7 +74,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18) include(CheckLinkerFlag) endif() include(CheckSymbolExists) -if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")) +if(NOT(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")) include(CheckAtomic) endif() @@ -346,7 +346,7 @@ endif() if(MSVC) if(EXCEPTION_HANDLING) - add_cxx_compiler_flag_if_supported(OUR_FLAGS /DCONF_EXCEPTION_HANDLING) + add_cxx_compiler_flag_if_supported(OUR_FLAGS /DCONF_EXCEPTION_HANDLING) endif() endif() @@ -463,7 +463,7 @@ function(set_extra_dirs_include VARIABLE NAME LIBRARY) if(IS_BUNDLED) set(TMP_TARGET_OS ${TARGET_OS}) if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - set(TMP_TARGET_OS webasm) + set(TMP_TARGET_OS webasm) endif() set("HINTS_${VARIABLE}_INCLUDEDIR" "ddnet-libs/${NAME}/include" "ddnet-libs/${NAME}/include/${TMP_TARGET_OS}" PARENT_SCOPE) endif() @@ -731,18 +731,18 @@ elseif(TARGET_OS STREQUAL "mac") set(PLATFORM_CLIENT_LIBS ${COCOA} ${OPENGL}) set(PLATFORM_LIBS ${CARBON} ${SECURITY}) elseif(TARGET_OS STREQUAL "haiku") - set(PLATFORM_CLIENT) - find_package(OpenGL) - set(PLATFORM_LIBS GL network) - set(PLATFORM_CLIENT_LIBS ${OPENGL_gl_LIBRARY}) - set(PLATFORM_CLIENT_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) + set(PLATFORM_CLIENT) + find_package(OpenGL) + set(PLATFORM_LIBS GL network) + set(PLATFORM_CLIENT_LIBS ${OPENGL_gl_LIBRARY}) + set(PLATFORM_CLIENT_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) elseif(TARGET_OS STREQUAL "android") - set(PLATFORM_CLIENT - src/android/android_main.cpp - ) - set(PLATFORM_LIBS ${TW_ANDROID_LIBS}) - set(PLATFORM_CLIENT_LIBS ${PLATFORM_LIBS}) - set(PLATFORM_CLIENT_INCLUDE_DIRS) + set(PLATFORM_CLIENT + src/android/android_main.cpp + ) + set(PLATFORM_LIBS ${TW_ANDROID_LIBS}) + set(PLATFORM_CLIENT_LIBS ${PLATFORM_LIBS}) + set(PLATFORM_CLIENT_INCLUDE_DIRS) else() find_package(Notify) find_package(OpenGL) @@ -928,11 +928,11 @@ if(CMAKE_OSX_ARCHITECTURES) endif() set(RUST_SRC - ${RUST_BASE} - ${RUST_ENGINE_INTERFACE} - ${RUST_ENGINE_SHARED} - Cargo.toml - Cargo.lock + ${RUST_BASE} + ${RUST_ENGINE_INTERFACE} + ${RUST_ENGINE_SHARED} + Cargo.toml + Cargo.lock ) set(RUST_TARGETS engine_shared) if(NOT CMAKE_OSX_ARCHITECTURES) @@ -2062,6 +2062,7 @@ set_src(ENGINE_SHARED GLOB_RECURSE src/engine/shared config.cpp config.h config_variables.h + config_variables_tclient.h console.cpp console.h csv.cpp @@ -2129,7 +2130,6 @@ set_src(ENGINE_SHARED GLOB_RECURSE src/engine/shared storage.cpp stun.cpp stun.h - tater_variables.h teehistorian_ex.cpp teehistorian_ex.h teehistorian_ex_chunks.h @@ -2616,7 +2616,7 @@ if(CLIENT) ) endif() set_property(TARGET game-client - PROPERTY OUTPUT_NAME ${CLIENT_EXECUTABLE} + PROPERTY OUTPUT_NAME ${CLIENT_EXECUTABLE} ) target_link_libraries(game-client ${LIBS_CLIENT}) @@ -2809,7 +2809,7 @@ if(SERVER) $ ) set_property(TARGET game-server - PROPERTY OUTPUT_NAME ${SERVER_EXECUTABLE} + PROPERTY OUTPUT_NAME ${SERVER_EXECUTABLE} ) target_link_libraries(game-server ${LIBS_SERVER}) target_include_directories(game-server PRIVATE ${PNG_INCLUDE_DIRS}) @@ -2820,7 +2820,7 @@ if(SERVER) set(SERVER_LAUNCHER_SRC src/macos/server.mm) add_executable(game-server-launcher ${SERVER_LAUNCHER_SRC}) set_property(TARGET game-server-launcher - PROPERTY OUTPUT_NAME ${SERVER_EXECUTABLE}-Launcher + PROPERTY OUTPUT_NAME ${SERVER_EXECUTABLE}-Launcher ) target_link_libraries(game-server-launcher ${COCOA}) list(APPEND TARGETS_OWN game-server-launcher) @@ -3159,7 +3159,7 @@ set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) if(TARGET_OS AND TARGET_BITS) if(TARGET_OS STREQUAL "windows") - if (TARGET_CPU_ARCHITECTURE STREQUAL "arm64") + if(TARGET_CPU_ARCHITECTURE STREQUAL "arm64") set(CPACK_SYSTEM_NAME "win-arm64") else() set(CPACK_SYSTEM_NAME "win${TARGET_BITS}") @@ -3424,7 +3424,7 @@ foreach(ext zip tar.gz tar.xz) endforeach() foreach(target ${CPACK_TARGETS}) list(APPEND COPY_TARGET_COMMANDS COMMAND ${CMAKE_COMMAND} -E copy $ ${TMPDIR}/) - if(NOT TARGET_OS STREQUAL "mac" AND NOT (TARGET_OS STREQUAL "windows" AND TARGET_CPU_ARCHITECTURE STREQUAL "arm64")) + if(NOT TARGET_OS STREQUAL "mac" AND NOT(TARGET_OS STREQUAL "windows" AND TARGET_CPU_ARCHITECTURE STREQUAL "arm64")) list(APPEND STRIP_TARGET_COMMANDS COMMAND strip -s ${TMPDIR}/$) endif() endforeach() @@ -3616,7 +3616,7 @@ foreach(target ${TARGETS_OWN}) target_compile_definitions(${target} PRIVATE GAME_RELEASE_VERSION="${VERSION}") endif() if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - target_compile_definitions(${target} PRIVATE CONF_WEBASM) + target_compile_definitions(${target} PRIVATE CONF_WEBASM) endif() endforeach() diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 8cf54767a11..096d194fe69 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -4803,11 +4803,9 @@ int main(int argc, const char **argv) } // execute tclient config file - IOHANDLE File = pStorage->OpenFile(TCONFIG_FILE, IOFLAG_READ, IStorage::TYPE_ALL); - if(File) + if(pStorage->FileExists(CONFIG_FILE_TCLIENT, IStorage::TYPE_ALL)) { - io_close(File); - pConsole->ExecuteFile(TCONFIG_FILE); + pConsole->ExecuteFile(CONFIG_FILE_TCLIENT); } // execute autoexec file diff --git a/src/engine/config.h b/src/engine/config.h index 2cd5dcc4727..1a10855fbd8 100644 --- a/src/engine/config.h +++ b/src/engine/config.h @@ -5,6 +5,13 @@ #include "kernel.h" +enum EClient +{ + CFGCLIENT_NONE = 0, + CFGCLIENT_TCLIENT, + CFGCLIENT_MAX, +}; + class IConfigManager : public IInterface { MACRO_INTERFACE("config") @@ -17,13 +24,13 @@ class IConfigManager : public IInterface virtual void ResetGameSettings() = 0; virtual void SetReadOnly(const char *pScriptName, bool ReadOnly) = 0; virtual bool Save() = 0; - virtual bool TSave() = 0; virtual class CConfig *Values() = 0; - virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0; - virtual void RegisterTCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0; + virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData, EClient pClient = EClient::CFGCLIENT_NONE) = 0; + void RegisterCallbackTClient(SAVECALLBACKFUNC pfnFunc, void *pUserData) { RegisterCallback(pfnFunc, pUserData, EClient::CFGCLIENT_TCLIENT); } - virtual void WriteLine(const char *pLine) = 0; + virtual void WriteLine(const char *pLine, EClient pClient = EClient::CFGCLIENT_NONE) = 0; + void WriteLineTClient(const char *pLine) { WriteLine(pLine, EClient::CFGCLIENT_TCLIENT); } virtual void StoreUnknownCommand(const char *pCommand) = 0; diff --git a/src/engine/shared/config.cpp b/src/engine/shared/config.cpp index f16d3f0abd3..e0fd4047957 100644 --- a/src/engine/shared/config.cpp +++ b/src/engine/shared/config.cpp @@ -194,8 +194,8 @@ void SColorConfigVariable::ResetToOld() // ----- -SStringConfigVariable::SStringConfigVariable(IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, char *pStr, const char *pDefault, size_t MaxSize, char *pOldValue) : - SConfigVariable(pConsole, pScriptName, Type, Flags, pHelp), +SStringConfigVariable::SStringConfigVariable(EClient Client, IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, char *pStr, const char *pDefault, size_t MaxSize, char *pOldValue) : + SConfigVariable(Client, pConsole, pScriptName, Type, Flags, pHelp), m_pStr(pStr), m_pDefault(pDefault), m_MaxSize(MaxSize), @@ -276,8 +276,7 @@ CConfigManager::CConfigManager() { m_pConsole = nullptr; m_pStorage = nullptr; - m_ConfigFile = 0; - m_Failed = false; + mem_zero(m_Failed, sizeof(m_Failed)); } void CConfigManager::Init() @@ -285,6 +284,8 @@ void CConfigManager::Init() m_pConsole = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); + EClient Client; + const auto &&AddVariable = [this](SConfigVariable *pVariable) { m_vpAllVariables.push_back(pVariable); if((pVariable->m_Flags & CFGFLAG_GAME) != 0) @@ -295,7 +296,7 @@ void CConfigManager::Init() #define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Flags, Desc) \ { \ const char *pHelp = Min == Max ? Desc " (default: " #Def ")" : (Max == 0 ? Desc " (default: " #Def ", min: " #Min ")" : Desc " (default: " #Def ", min: " #Min ", max: " #Max ")"); \ - AddVariable(m_ConfigHeap.Allocate(m_pConsole, #ScriptName, SConfigVariable::VAR_INT, Flags, pHelp, &g_Config.m_##Name, Def, Min, Max)); \ + AddVariable(m_ConfigHeap.Allocate(Client, m_pConsole, #ScriptName, SConfigVariable::VAR_INT, Flags, pHelp, &g_Config.m_##Name, Def, Min, Max)); \ } #define MACRO_CONFIG_COL(Name, ScriptName, Def, Flags, Desc) \ @@ -304,7 +305,7 @@ void CConfigManager::Init() char *pHelp = static_cast(m_ConfigHeap.Allocate(HelpSize)); \ const bool Alpha = ((Flags)&CFGFLAG_COLALPHA) != 0; \ str_format(pHelp, HelpSize, "%s (default: $%0*X)", Desc, Alpha ? 8 : 6, color_cast(ColorHSLA(Def, Alpha)).Pack(Alpha)); \ - AddVariable(m_ConfigHeap.Allocate(m_pConsole, #ScriptName, SConfigVariable::VAR_COLOR, Flags, pHelp, &g_Config.m_##Name, Def)); \ + AddVariable(m_ConfigHeap.Allocate(Client, m_pConsole, #ScriptName, SConfigVariable::VAR_COLOR, Flags, pHelp, &g_Config.m_##Name, Def)); \ } #define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Flags, Desc) \ @@ -313,10 +314,13 @@ void CConfigManager::Init() char *pHelp = static_cast(m_ConfigHeap.Allocate(HelpSize)); \ str_format(pHelp, HelpSize, "%s (default: \"%s\", max length: %d)", Desc, Def, Len - 1); \ char *pOldValue = static_cast(m_ConfigHeap.Allocate(Len)); \ - AddVariable(m_ConfigHeap.Allocate(m_pConsole, #ScriptName, SConfigVariable::VAR_STRING, Flags, pHelp, g_Config.m_##Name, Def, Len, pOldValue)); \ + AddVariable(m_ConfigHeap.Allocate(Client, m_pConsole, #ScriptName, SConfigVariable::VAR_STRING, Flags, pHelp, g_Config.m_##Name, Def, Len, pOldValue)); \ } + Client = CFGCLIENT_NONE; #include "config_variables.h" + Client = CFGCLIENT_TCLIENT; +#include "config_variables_tclient.h" #undef MACRO_CONFIG_INT #undef MACRO_CONFIG_COL @@ -371,163 +375,92 @@ bool CConfigManager::Save() if(!m_pStorage || !g_Config.m_ClSaveSettings) return true; - char aConfigFileTmp[IO_MAX_PATH_LENGTH]; - m_ConfigFile = m_pStorage->OpenFile(IStorage::FormatTmpPath(aConfigFileTmp, sizeof(aConfigFileTmp), CONFIG_FILE), IOFLAG_WRITE, IStorage::TYPE_SAVE); + char aConfigTmpPath[EClient::CFGCLIENT_MAX][IO_MAX_PATH_LENGTH]; + + mem_zero(m_Failed, sizeof(m_Failed)); - if(!m_ConfigFile) + // Open temp files + for(int i = 0; i < EClient::CFGCLIENT_MAX; ++i) { - log_error("config", "ERROR: opening %s failed", aConfigFileTmp); - return false; + m_ConfigFile[i] = m_pStorage->OpenFile(IStorage::FormatTmpPath(aConfigTmpPath[i], sizeof(aConfigTmpPath[i]), ConfigFile(static_cast(i))), IOFLAG_WRITE, IStorage::TYPE_SAVE); + if(!m_ConfigFile[i]) + { + log_error("config", "ERROR: opening %s failed", aConfigTmpPath[i]); + return false; + } } - m_Failed = false; - + // Write variables char aLineBuf[2048]; for(const SConfigVariable *pVariable : m_vpAllVariables) { if((pVariable->m_Flags & CFGFLAG_SAVE) != 0 && !pVariable->IsDefault()) { + dbg_assert(pVariable->m_Client >= 0 && pVariable->m_Client < EClient::CFGCLIENT_MAX, "Client out of range"); pVariable->Serialize(aLineBuf, sizeof(aLineBuf)); - WriteLine(aLineBuf); + WriteLine(aLineBuf, pVariable->m_Client); } } - for(const auto &Callback : m_vCallbacks) + // Do callbacks + for(int i = 0; i < EClient::CFGCLIENT_MAX; ++i) { - Callback.m_pfnFunc(this, Callback.m_pUserData); + for(const auto &Callback : m_vCallbacks[i]) + Callback.m_pfnFunc(this, Callback.m_pUserData); } + // Write unknown commands for(const char *pCommand : m_vpUnknownCommands) - { WriteLine(pCommand); - } - - if(m_Failed) - { - log_error("config", "ERROR: writing to %s failed", aConfigFileTmp); - } - - if(io_sync(m_ConfigFile) != 0) - { - m_Failed = true; - log_error("config", "ERROR: synchronizing %s failed", aConfigFileTmp); - } - - if(io_close(m_ConfigFile) != 0) - { - m_Failed = true; - log_error("config", "ERROR: closing %s failed", aConfigFileTmp); - } - - m_ConfigFile = 0; - if(m_Failed) + // sync, close, error check + bool Failed = false; + for(int i = 0; i < EClient::CFGCLIENT_MAX; ++i) { - return false; - } - - if(!m_pStorage->RenameFile(aConfigFileTmp, CONFIG_FILE, IStorage::TYPE_SAVE)) - { - log_error("config", "ERROR: renaming %s to " CONFIG_FILE " failed", aConfigFileTmp); - return false; - } - TSave(); - return true; -} - -bool CConfigManager::TSave() -{ - if(!m_pStorage || !g_Config.m_ClSaveSettings) - return true; - - char aConfigFileTmp[IO_MAX_PATH_LENGTH]; - m_ConfigFile = m_pStorage->OpenFile(IStorage::FormatTmpPath(aConfigFileTmp, sizeof(aConfigFileTmp), TCONFIG_FILE), IOFLAG_WRITE, IStorage::TYPE_SAVE); - - if(!m_ConfigFile) - { - dbg_msg("config", "ERROR: opening %s failed", aConfigFileTmp); - return false; - } - - m_Failed = false; - - char aLineBuf[1024 * 2]; - char aEscapeBuf[1024 * 2]; - -#define MACRO_CONFIG_INT(Name, ScriptName, def, min, max, flags, desc) \ - if((flags)&CFGFLAG_SAVE && g_Config.m_##Name != def) \ - { \ - str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); \ - WriteLine(aLineBuf); \ - } -#define MACRO_CONFIG_COL(Name, ScriptName, def, flags, desc) \ - if((flags)&CFGFLAG_SAVE && g_Config.m_##Name != def) \ - { \ - str_format(aLineBuf, sizeof(aLineBuf), "%s %u", #ScriptName, g_Config.m_##Name); \ - WriteLine(aLineBuf); \ - } -#define MACRO_CONFIG_STR(Name, ScriptName, len, def, flags, desc) \ - if((flags)&CFGFLAG_SAVE && str_comp(g_Config.m_##Name, def) != 0) \ - { \ - EscapeParam(aEscapeBuf, g_Config.m_##Name, sizeof(aEscapeBuf)); \ - str_format(aLineBuf, sizeof(aLineBuf), "%s \"%s\"", #ScriptName, aEscapeBuf); \ - WriteLine(aLineBuf); \ - } - -#include "tater_variables.h" - -#undef MACRO_CONFIG_INT -#undef MACRO_CONFIG_COL -#undef MACRO_CONFIG_STR - - for(const auto &Callback : m_vTCallbacks) - { - Callback.m_pfnFunc(this, Callback.m_pUserData); - } - - if(io_sync(m_ConfigFile) != 0) - { - m_Failed = true; + if(io_sync(m_ConfigFile[i]) != 0) + { + m_Failed[i] = true; + log_error("config", "ERROR: synchronizing %s failed", aConfigTmpPath[i]); + } + if(io_close(m_ConfigFile[i]) != 0) + { + m_Failed[i] = true; + log_error("config", "ERROR: closing %s failed", aConfigTmpPath[i]); + } + if(m_Failed[i]) + { + log_error("config", "ERROR: writing to %s failed", aConfigTmpPath[i]); + Failed = true; + } } - - if(io_close(m_ConfigFile) != 0) - m_Failed = true; - - m_ConfigFile = 0; - - if(m_Failed) - { - dbg_msg("config", "ERROR: writing to %s failed", aConfigFileTmp); + if(Failed) return false; - } - if(!m_pStorage->RenameFile(aConfigFileTmp, TCONFIG_FILE, IStorage::TYPE_SAVE)) + for(int i = 0; i < EClient::CFGCLIENT_MAX; ++i) { - dbg_msg("config", "ERROR: renaming %s to " TCONFIG_FILE " failed", aConfigFileTmp); - return false; + if(!m_pStorage->RenameFile(aConfigTmpPath[i], ConfigFile(static_cast(i)), IStorage::TYPE_SAVE)) + { + log_error("config", "ERROR: renaming %s to %s failed", aConfigTmpPath[i], ConfigFile(static_cast(i))); + return false; + } } - log_info("config", "saved to " CONFIG_FILE); return true; } -void CConfigManager::RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) -{ - m_vCallbacks.emplace_back(pfnFunc, pUserData); -} - -void CConfigManager::RegisterTCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) +void CConfigManager::RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData, EClient pClient) { - m_vTCallbacks.emplace_back(pfnFunc, pUserData); + m_vCallbacks[pClient].emplace_back(pfnFunc, pUserData); } -void CConfigManager::WriteLine(const char *pLine) +void CConfigManager::WriteLine(const char *pLine, EClient pClient) { - if(!m_ConfigFile || - io_write(m_ConfigFile, pLine, str_length(pLine)) != static_cast(str_length(pLine)) || - !io_write_newline(m_ConfigFile)) + IOHANDLE ConfigFile = m_ConfigFile[pClient]; + if(!ConfigFile || + io_write(ConfigFile, pLine, str_length(pLine)) != static_cast(str_length(pLine)) || + !io_write_newline(ConfigFile)) { - m_Failed = true; + m_Failed[pClient] = true; } } diff --git a/src/engine/shared/config.h b/src/engine/shared/config.h index b15c2ea2d57..c15b203584c 100644 --- a/src/engine/shared/config.h +++ b/src/engine/shared/config.h @@ -15,12 +15,22 @@ #include #define CONFIG_FILE "settings_ddnet.cfg" +#define CONFIG_FILE_TCLIENT "settings_tclient.cfg" #define AUTOEXEC_FILE "autoexec.cfg" #define AUTOEXEC_CLIENT_FILE "autoexec_client.cfg" #define AUTOEXEC_SERVER_FILE "autoexec_server.cfg" -#define TCONFIG_FILE "settings_tclient.cfg" #define MAX_CALLBACKS 64; +inline const char *ConfigFile(EClient Client) { + switch(Client) + { + case CFGCLIENT_TCLIENT: + return CONFIG_FILE_TCLIENT; + default: + return CONFIG_FILE; + } +} + class CConfig { public: @@ -34,6 +44,7 @@ class CConfig static constexpr const char *ms_p##Name = Def; \ char m_##Name[Len]; // Flawfinder: ignore #include "config_variables.h" +#include "config_variables_tclient.h" #undef MACRO_CONFIG_INT #undef MACRO_CONFIG_COL #undef MACRO_CONFIG_STR @@ -70,6 +81,7 @@ struct SConfigVariable VAR_COLOR, VAR_STRING, }; + EClient m_Client; IConsole *m_pConsole; const char *m_pScriptName; EVariableType m_Type; @@ -79,7 +91,8 @@ struct SConfigVariable // but the underlying config variable can still be modified programatically. bool m_ReadOnly = false; - SConfigVariable(IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp) : + SConfigVariable(EClient Client, IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp) : + m_Client(Client), m_pConsole(pConsole), m_pScriptName(pScriptName), m_Type(Type), @@ -109,8 +122,8 @@ struct SIntConfigVariable : public SConfigVariable int m_Max; int m_OldValue; - SIntConfigVariable(IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, int *pVariable, int Default, int Min, int Max) : - SConfigVariable(pConsole, pScriptName, Type, Flags, pHelp), + SIntConfigVariable(EClient Client, IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, int *pVariable, int Default, int Min, int Max) : + SConfigVariable(Client, pConsole, pScriptName, Type, Flags, pHelp), m_pVariable(pVariable), m_Default(Default), m_Min(Min), @@ -140,8 +153,8 @@ struct SColorConfigVariable : public SConfigVariable bool m_Alpha; unsigned m_OldValue; - SColorConfigVariable(IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, unsigned *pVariable, unsigned Default) : - SConfigVariable(pConsole, pScriptName, Type, Flags, pHelp), + SColorConfigVariable(EClient Client, IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, unsigned *pVariable, unsigned Default) : + SConfigVariable(Client, pConsole, pScriptName, Type, Flags, pHelp), m_pVariable(pVariable), m_Default(Default), m_Alpha(Flags & CFGFLAG_COLALPHA), @@ -181,7 +194,7 @@ struct SStringConfigVariable : public SConfigVariable size_t m_MaxSize; char *m_pOldValue; - SStringConfigVariable(IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, char *pStr, const char *pDefault, size_t MaxSize, char *pOldValue); + SStringConfigVariable(EClient Client, IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, char *pStr, const char *pDefault, size_t MaxSize, char *pOldValue); ~SStringConfigVariable() override = default; static void CommandCallback(IConsole::IResult *pResult, void *pUserData); @@ -199,9 +212,8 @@ class CConfigManager : public IConfigManager IConsole *m_pConsole; class IStorage *m_pStorage; - IOHANDLE m_ConfigFile; - bool m_Failed; - + IOHANDLE m_ConfigFile[CFGCLIENT_MAX]; + bool m_Failed[CFGCLIENT_MAX]; struct SCallback { SAVECALLBACKFUNC m_pfnFunc; @@ -213,8 +225,7 @@ class CConfigManager : public IConfigManager { } }; - std::vector m_vCallbacks; - std::vector m_vTCallbacks; + std::vector m_vCallbacks[CFGCLIENT_MAX]; std::vector m_vpAllVariables; std::vector m_vpGameVariables; @@ -233,14 +244,12 @@ class CConfigManager : public IConfigManager void ResetGameSettings() override; void SetReadOnly(const char *pScriptName, bool ReadOnly) override; bool Save() override; - bool TSave() override; CConfig *Values() override { return &g_Config; } - void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) override; - void RegisterTCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) override; + void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData, EClient Client = EClient::CFGCLIENT_NONE) override; - void WriteLine(const char *pLine) override; + void WriteLine(const char *pLine, EClient Client = EClient::CFGCLIENT_NONE) override; void StoreUnknownCommand(const char *pCommand) override; diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 66e3f1c9331..80edff77be8 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -4,14 +4,12 @@ // This file can be included several times. #ifndef MACRO_CONFIG_INT -#error "The config macros must be defined" -#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Save, Desc) ; -#define MACRO_CONFIG_COL(Name, ScriptName, Def, Save, Desc) ; -#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Save, Desc) ; +#error "Config macros must be defined" +#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Save, Desc); +#define MACRO_CONFIG_COL(Name, ScriptName, Def, Save, Desc); +#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Save, Desc); #endif -#include "tater_variables.h" - // client MACRO_CONFIG_INT(ClPredict, cl_predict, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Predict client movements") MACRO_CONFIG_INT(ClPredictDummy, cl_predict_dummy, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Predict dummy movements") @@ -29,13 +27,14 @@ MACRO_CONFIG_INT(ClNameplates, cl_nameplates, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_ MACRO_CONFIG_INT(ClAfkEmote, cl_afk_emote, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show zzz emote next to afk players") MACRO_CONFIG_INT(ClNameplatesAlways, cl_nameplates_always, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Always show name plates disregarding of distance") MACRO_CONFIG_INT(ClNameplatesTeamcolors, cl_nameplates_teamcolors, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Use team colors for name plates") -MACRO_CONFIG_INT(ClNameplatesSize, cl_nameplates_size, 50, 0, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of the name plates from 0 to 100%") +MACRO_CONFIG_INT(ClNameplatesSize, cl_nameplates_size, 50, -50, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of the name plates") MACRO_CONFIG_INT(ClNameplatesClan, cl_nameplates_clan, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show clan in name plates") -MACRO_CONFIG_INT(ClNameplatesClanSize, cl_nameplates_clan_size, 30, 0, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of the clan plates from 0 to 100%") -MACRO_CONFIG_INT(ClNameplatesIds, cl_nameplates_ids, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show IDs in name plates") +MACRO_CONFIG_INT(ClNameplatesClanSize, cl_nameplates_clan_size, 30, -50, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of the clan plates") +MACRO_CONFIG_INT(ClNameplatesIds, cl_nameplates_ids, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show client IDs in name plates") MACRO_CONFIG_INT(ClNameplatesOwn, cl_nameplates_own, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show own name plate (useful for demo recording)") MACRO_CONFIG_INT(ClNameplatesFriendMark, cl_nameplates_friendmark, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show friend mark (♥) in name plates") MACRO_CONFIG_INT(ClNameplatesStrong, cl_nameplates_strong, 0, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show strong/weak in name plates (0 - off, 1 - icons, 2 - icons + numbers)") +MACRO_CONFIG_INT(ClNameplatesStrongSize, cl_nameplates_strong_size, 30, -50, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of strong/weak state icons and numbers") MACRO_CONFIG_INT(ClTextEntities, cl_text_entities, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Render textual entity data") MACRO_CONFIG_INT(ClTextEntitiesSize, cl_text_entities_size, 100, 1, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of textual entity data from 1 to 100%") MACRO_CONFIG_INT(ClStreamerMode, cl_streamer_mode, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Censor sensitive information such as /save password") @@ -86,6 +85,7 @@ MACRO_CONFIG_INT(ClMouseDeadzone, cl_mouse_deadzone, 0, 0, 3000, CFGFLAG_CLIENT MACRO_CONFIG_INT(ClMouseFollowfactor, cl_mouse_followfactor, 0, 0, 200, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Factor for the camera to follow the cursor") MACRO_CONFIG_INT(ClMouseMaxDistance, cl_mouse_max_distance, 400, 0, 5000, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Maximum cursor distance") MACRO_CONFIG_INT(ClMouseMinDistance, cl_mouse_min_distance, 0, 0, 5000, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Minimum cursor distance") +MACRO_CONFIG_INT(ClMousePositionMultiplier, cl_mouse_position_multiplier, 100, 1, 1000000, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "The percentage to multiply mouse position before rounding") MACRO_CONFIG_INT(ClDyncam, cl_dyncam, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Enable dyncam") MACRO_CONFIG_INT(ClDyncamMaxDistance, cl_dyncam_max_distance, 1000, 0, 2000, CFGFLAG_CLIENT | CFGFLAG_SAVE | CFGFLAG_INSENSITIVE, "Maximum dynamic camera cursor distance") @@ -683,7 +683,8 @@ MACRO_CONFIG_INT(ClChatOld, cl_chat_old, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, MACRO_CONFIG_INT(ClChatFontSize, cl_chat_size, 60, 10, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Chat font size") MACRO_CONFIG_INT(ClChatWidth, cl_chat_width, 200, 140, 400, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Chat width") -MACRO_CONFIG_INT(ClShowDirection, cl_show_direction, 1, 0, 3, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Show key presses (1 = other players', 2 = also your own, 3 = only your own") +MACRO_CONFIG_INT(ClShowDirection, cl_show_direction, 1, 0, 3, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Show key presses (1 = other players', 2 = everyone, 3 = only your own") +MACRO_CONFIG_INT(ClDirectionSize, cl_direction_size, 30, -50, 100, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Size of key press icons") MACRO_CONFIG_INT(ClOldGunPosition, cl_old_gun_position, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Tees hold gun a bit higher like in TW 0.6.1 and older") MACRO_CONFIG_INT(ClConfirmDisconnectTime, cl_confirm_disconnect_time, 20, -1, 1440, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Confirmation popup before disconnecting after game time (in minutes, -1 to turn off, 0 to always turn on)") MACRO_CONFIG_INT(ClConfirmQuitTime, cl_confirm_quit_time, 20, -1, 1440, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Confirmation popup before quitting after game time (in minutes, -1 to turn off, 0 to always turn on)") diff --git a/src/engine/shared/tater_variables.h b/src/engine/shared/config_variables_tclient.h similarity index 98% rename from src/engine/shared/tater_variables.h rename to src/engine/shared/config_variables_tclient.h index cf5f09d1442..bab289e358c 100644 --- a/src/engine/shared/tater_variables.h +++ b/src/engine/shared/config_variables_tclient.h @@ -1,13 +1,13 @@ // This file can be included several times. #ifndef MACRO_CONFIG_INT -#error "The config macros must be defined" -#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Save, Desc) ; -#define MACRO_CONFIG_COL(Name, ScriptName, Def, Save, Desc) ; -#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Save, Desc) ; +#error "Config macros must be defined" +#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Save, Desc); +#define MACRO_CONFIG_COL(Name, ScriptName, Def, Save, Desc); +#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Save, Desc); #endif -// Tater Client Variables +// TClient Client Variables MACRO_CONFIG_INT(ClRunOnJoinConsole, tc_run_on_join_console, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Whether to use run on join in chat or console") MACRO_CONFIG_INT(ClRunOnJoinDelay, tc_run_on_join_delay, 2, 7, 50000, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Tick Delay before using run on join") diff --git a/src/game/client/components/tclient/bindwheel.cpp b/src/game/client/components/tclient/bindwheel.cpp index 218bf2f93c1..3cbb1bfa8cc 100644 --- a/src/game/client/components/tclient/bindwheel.cpp +++ b/src/game/client/components/tclient/bindwheel.cpp @@ -109,7 +109,7 @@ void CBindWheel::OnConsoleInit() { IConfigManager *pConfigManager = Kernel()->RequestInterface(); if(pConfigManager) - pConfigManager->RegisterTCallback(ConfigSaveCallback, this); + pConfigManager->RegisterCallbackTClient(ConfigSaveCallback, this); Console()->Register("+bindwheel", "", CFGFLAG_CLIENT, ConOpenBindwheel, this, "Open bindwheel selector"); Console()->Register("+bindwheel_execute_hover", "", CFGFLAG_CLIENT, ConExecuteHover, this, "Execute hovered bindwheel bind");