Encapsulate CTuningParams::ms_apNames with CTuningParams::Name

This commit is contained in:
Robert Müller 2022-08-09 17:05:28 +02:00
parent 85a41f46dc
commit 680abb6405
4 changed files with 8 additions and 7 deletions

View file

@ -119,7 +119,7 @@ void CDebugHud::RenderTuning()
TextRender()->Text(0x0, x - w, y + Count * 6, 5, aBuf, -1.0f);
x += 5.0f;
TextRender()->Text(0x0, x, y + Count * 6, 5, CTuningParams::ms_apNames[i], -1.0f);
TextRender()->Text(0x0, x, y + Count * 6, 5, CTuningParams::Name(i), -1.0f);
Count++;
}

View file

@ -34,7 +34,7 @@ bool CTuningParams::Get(int Index, float *pValue) const
bool CTuningParams::Set(const char *pName, float Value)
{
for(int i = 0; i < Num(); i++)
if(str_comp_nocase(pName, ms_apNames[i]) == 0)
if(str_comp_nocase(pName, Name(i)) == 0)
return Set(i, Value);
return false;
}
@ -42,7 +42,7 @@ bool CTuningParams::Set(const char *pName, float Value)
bool CTuningParams::Get(const char *pName, float *pValue) const
{
for(int i = 0; i < Num(); i++)
if(str_comp_nocase(pName, ms_apNames[i]) == 0)
if(str_comp_nocase(pName, Name(i)) == 0)
return Get(i, pValue);
return false;

View file

@ -40,6 +40,8 @@ public:
class CTuningParams
{
static const char *ms_apNames[];
public:
CTuningParams()
{
@ -49,8 +51,6 @@ public:
#undef MACRO_TUNING_PARAM
}
static const char *ms_apNames[];
#define MACRO_TUNING_PARAM(Name, ScriptName, Value, Description) CTuneParam m_##Name;
#include "tuning.h"
#undef MACRO_TUNING_PARAM
@ -63,6 +63,7 @@ public:
bool Set(const char *pName, float Value);
bool Get(int Index, float *pValue) const;
bool Get(const char *pName, float *pValue) const;
static const char *Name(int Index) { return ms_apNames[Index]; }
};
inline void StrToInts(int *pInts, int Num, const char *pStr)

View file

@ -2639,7 +2639,7 @@ void CGameContext::ConTunes(IConsole::IResult *pResult, void *pUserData)
{
float Value;
pSelf->Tuning()->Get(i, &Value);
str_format(aBuf, sizeof(aBuf), "%s %.2f", pSelf->Tuning()->ms_apNames[i], Value);
str_format(aBuf, sizeof(aBuf), "%s %.2f", CTuningParams::Name(i), Value);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf);
}
}
@ -2678,7 +2678,7 @@ void CGameContext::ConTuneDumpZone(IConsole::IResult *pResult, void *pUserData)
{
float Value;
pSelf->TuningList()[List].Get(i, &Value);
str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, pSelf->TuningList()[List].ms_apNames[i], Value);
str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, CTuningParams::Name(i), Value);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf);
}
}