From 85a41f46dc657e581c504d4457cd33a912110bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Aug 2022 16:52:20 +0200 Subject: [PATCH] Allow `tune` command to list current tuning parameter value Extend `tune` so the current value of a given tuning variable is printed if no new value is given, so it works like commands in the console. For example `tune player_collision` will print the current value of the variable, whereas `tune player_collision 0` will change the value like before. --- src/game/client/gameclient.cpp | 2 +- src/game/server/gamecontext.cpp | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 5d8debd9d..a0098ba85 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -163,7 +163,7 @@ void CGameClient::OnConsoleInit() Console()->Register("kill", "", CFGFLAG_CLIENT, ConKill, this, "Kill yourself to restart"); // register server dummy commands for tab completion - Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value"); + Console()->Register("tune", "s[tuning] ?i[value]", CFGFLAG_SERVER, 0, 0, "Tune variable to value or show current value"); Console()->Register("tune_reset", "?s[tuning]", CFGFLAG_SERVER, 0, 0, "Reset all or one tuning variable to default"); Console()->Register("tunes", "", CFGFLAG_SERVER, 0, 0, "List all tuning variables and their values"); Console()->Register("change_map", "?r[map]", CFGFLAG_SERVER, 0, 0, "Change map"); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index c3edf2e97..baa456dd3 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2550,20 +2550,34 @@ void CGameContext::ConTuneParam(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; const char *pParamName = pResult->GetString(0); - float NewValue = pResult->GetFloat(1); char aBuf[256]; - if(pSelf->Tuning()->Set(pParamName, NewValue) && pSelf->Tuning()->Get(pParamName, &NewValue)) + if(pResult->NumArguments() == 2) { - str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); - pSelf->SendTuningParams(-1); + float NewValue = pResult->GetFloat(1); + if(pSelf->Tuning()->Set(pParamName, NewValue) && pSelf->Tuning()->Get(pParamName, &NewValue)) + { + str_format(aBuf, sizeof(aBuf), "%s changed to %.2f", pParamName, NewValue); + pSelf->SendTuningParams(-1); + } + else + { + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + } } else { - str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); + float Value; + if(pSelf->Tuning()->Get(pParamName, &Value)) + { + str_format(aBuf, sizeof(aBuf), "%s %.2f", pParamName, Value); + } + else + { + str_format(aBuf, sizeof(aBuf), "No such tuning parameter: %s", pParamName); + } } + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf); } void CGameContext::ConToggleTuneParam(IConsole::IResult *pResult, void *pUserData) @@ -3167,7 +3181,7 @@ void CGameContext::OnConsoleInit() m_pEngine = Kernel()->RequestInterface(); m_pStorage = Kernel()->RequestInterface(); - Console()->Register("tune", "s[tuning] i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneParam, this, "Tune variable to value"); + Console()->Register("tune", "s[tuning] ?i[value]", CFGFLAG_SERVER | CFGFLAG_GAME, ConTuneParam, this, "Tune variable to value or show current value"); Console()->Register("toggle_tune", "s[tuning] i[value 1] i[value 2]", CFGFLAG_SERVER | CFGFLAG_GAME, ConToggleTuneParam, this, "Toggle tune variable"); Console()->Register("tune_reset", "?s[tuning]", CFGFLAG_SERVER, ConTuneReset, this, "Reset all or one tuning variable to default"); Console()->Register("tunes", "", CFGFLAG_SERVER, ConTunes, this, "List all tuning variables and their values");