Files
o3de/Code/Legacy/CrySystem/XConsoleVariable.h
T
lumberyard-employee-dm 447832dd81 Updated the GameApplication to mount the engine.pak (#4128)
* Updated the GameApplication to mount the engine.pak

This allows loading the autoexec.cfg and bootstrap.game.<config>.<platform>.setreg from the engine.pak files
The engine.pak is searched for in the following order: <ExecutableDirectory>/engine.pak, followed by <ProjectCacheRoot>/engine.pak

Removed a lot of unused APIs from the AZ::IO::Archive feature suite
Updated many of the AZ::IO::Archive classes to use AZ::IO::Path internally.
The logic to search for files within an Archive has been updated to use AZ::IO::Path and to remove case-insensitve string comparisons
Somehow removed the CryFile dependency on anything Cry

Updated the Settings Registry to support reading from the FileIOBase and therefore Archive files in the GameLauncher via the `SetUseFileIO` function

Removed AzFramework Dependency on md5 3rdParty library

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Linux build fix

Added an include of <stdio.h> before the <rapidxml/rapidxml.h> include as it usesnprintf.

Added `static` to the constexpr constants in ExtractFileDescription in SettingsRegistryImpl.cpp to fix clang compile issue

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the case used to mount the Engine PAK file in the GameApplication to be Engine.pak to match the other locations where it is mounted

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the proper FFont call to FileIOBase::Size to supply the correct
integer type of AZ::u64 instead of size_t
This fixes building on platforms where size_t is type defined to be
unsigned long

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed segmentation fault in Archive::Unregister when outputing the filename of the Archive file being closed

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fix calls to OpenPack in the Legacy LevelSystem

The LevelSystem was calling the incorrect overload of OpenPack that
accepts BindRoot for the mounted level.pak instead of the overload that
that passes a memory block object.

This was causing the level pak files to be mounted using an invalid
directory, causing file accesses inside the level pak to fail.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the error messages in the ZipDir CacheFactory class to use AZ_Warning directly

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the ArchiveFileIO m_trackedFiles container to store mapped type as an AZ::IO::Path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-09-16 11:01:00 -05:00

318 lines
11 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <IConsole.h>
#include <ISystem.h>
#include <AzCore/std/function/function_template.h>
class CXConsole;
class CXConsoleVariableBase
: public ICVar
{
public:
//! constructor
//! \param pConsole must not be 0
CXConsoleVariableBase(CXConsole* pConsole, const char* sName, int nFlags, const char* help);
//! destructor
virtual ~CXConsoleVariableBase();
// interface ICVar --------------------------------------------------------------------------------------
void ClearFlags(int flags) override;
int GetFlags() const override;
int SetFlags(int flags) override;
const char* GetName() const override;
const char* GetHelp() override;
void Release() override;
void ForceSet(const char* s) override;
void SetOnChangeCallback(ConsoleVarFunc pChangeFunc) override;
uint64 AddOnChangeFunctor(const AZStd::function<void()>& pChangeFunctor) override;
ConsoleVarFunc GetOnChangeCallback() const override;
bool ShouldReset() const { return (m_nFlags & VF_RESETTABLE) != 0; }
void Reset() override
{
if (ShouldReset())
{
ResetImpl();
}
}
virtual void ResetImpl() = 0;
void SetLimits(float min, float max) override;
void GetLimits(float& min, float& max) override;
bool HasCustomLimits() override;
int GetRealIVal() const override { return GetIVal(); }
bool IsConstCVar() const override {return (m_nFlags & VF_CONST_CVAR) != 0; }
void SetDataProbeString(const char* pDataProbeString) override
{
CRY_ASSERT(m_pDataProbeString == NULL);
m_pDataProbeString = new char[ strlen(pDataProbeString) + 1 ];
azstrcpy(m_pDataProbeString, strlen(pDataProbeString) + 1, pDataProbeString);
}
const char* GetDataProbeString() const override;
protected: // ------------------------------------------------------------------------------------------
virtual const char* GetOwnDataProbeString() const
{
return GetString();
}
void CallOnChangeFunctions();
char* m_szName; // if VF_COPYNAME then this data need to be deleteed, otherwise it's pointer to .dll/.exe
char* m_psHelp; // pointer to the help string, might be 0
char* m_pDataProbeString; // value client is required to have for data probes
int m_nFlags; // e.g. VF_CHEAT, ...
using ChangeFunctorContainer = std::vector<std::pair<int, AZStd::function<void ()>> >;
ChangeFunctorContainer m_changeFunctors;
ConsoleVarFunc m_pChangeFunc; // Callback function that is called when this variable changes.
CXConsole* m_pConsole; // used for the callback OnBeforeVarChange()
float m_valueMin;
float m_valueMax;
bool m_hasCustomLimits;
};
//////////////////////////////////////////////////////////////////////////
class CXConsoleVariableString
: public CXConsoleVariableBase
{
public:
// constructor
CXConsoleVariableString(CXConsole* pConsole, const char* sName, const char* szDefault, int nFlags, const char* help)
: CXConsoleVariableBase(pConsole, sName, nFlags, help)
{
if (szDefault)
{
m_sValue = szDefault;
m_sDefault = szDefault;
}
}
// interface ICVar --------------------------------------------------------------------------------------
int GetIVal() const override { return atoi(m_sValue.c_str()); }
int64 GetI64Val() const override { return _atoi64(m_sValue.c_str()); }
float GetFVal() const override { return (float)atof(m_sValue.c_str()); }
const char* GetString() const override { return m_sValue.c_str(); }
void ResetImpl() override
{
Set(m_sDefault.c_str());
}
void Set(const char* s) override;
void Set(float f) override;
void Set(int i) override;
int GetType() override { return CVAR_STRING; }
private: // --------------------------------------------------------------------------------------------
AZStd::string m_sValue;
AZStd::string m_sDefault; //!<
};
class CXConsoleVariableInt
: public CXConsoleVariableBase
{
public:
// constructor
CXConsoleVariableInt(CXConsole* pConsole, const char* sName, const int iDefault, int nFlags, const char* help)
: CXConsoleVariableBase(pConsole, sName, nFlags, help)
, m_iValue(iDefault)
, m_iDefault(iDefault)
{
}
// interface ICVar --------------------------------------------------------------------------------------
int GetIVal() const override { return m_iValue; }
int64 GetI64Val() const override { return m_iValue; }
float GetFVal() const override { return (float)GetIVal(); }
const char* GetString() const override;
void ResetImpl() override { Set(m_iDefault); }
void Set(const char* s) override;
void Set(float f) override;
void Set(int i) override;
int GetType() override { return CVAR_INT; }
protected: // --------------------------------------------------------------------------------------------
int m_iValue;
int m_iDefault; //!<
};
//////////////////////////////////////////////////////////////////////////
class CXConsoleVariableFloat
: public CXConsoleVariableBase
{
public:
// constructor
CXConsoleVariableFloat(CXConsole* pConsole, const char* sName, const float fDefault, int nFlags, const char* help)
: CXConsoleVariableBase(pConsole, sName, nFlags, help)
, m_fValue(fDefault)
, m_fDefault(fDefault)
{
}
// interface ICVar --------------------------------------------------------------------------------------
int GetIVal() const override { return (int)m_fValue; }
int64 GetI64Val() const override { return (int64)m_fValue; }
float GetFVal() const override { return m_fValue; }
const char* GetString() const override;
void ResetImpl() override { Set(m_fDefault); }
void Set(const char* s) override;
void Set(float f) override;
void Set(int i) override;
int GetType() override { return CVAR_FLOAT; }
protected:
const char* GetOwnDataProbeString() const override
{
static char szReturnString[8];
sprintf_s(szReturnString, "%.1g", m_fValue);
return szReturnString;
}
private: // --------------------------------------------------------------------------------------------
float m_fValue;
float m_fDefault; //!<
};
class CXConsoleVariableIntRef
: public CXConsoleVariableBase
{
public:
//! constructor
//!\param pVar must not be 0
CXConsoleVariableIntRef(CXConsole* pConsole, const char* sName, int32* pVar, int nFlags, const char* help)
: CXConsoleVariableBase(pConsole, sName, nFlags, help)
, m_iValue(*pVar)
, m_iDefault(*pVar)
{
assert(pVar);
}
// interface ICVar --------------------------------------------------------------------------------------
int GetIVal() const override { return m_iValue; }
int64 GetI64Val() const override { return m_iValue; }
float GetFVal() const override { return (float)m_iValue; }
const char* GetString() const override;
void ResetImpl() override { Set(m_iDefault); }
void Set(const char* s) override;
void Set(float f) override;
void Set(int i) override;
int GetType() override { return CVAR_INT; }
private: // --------------------------------------------------------------------------------------------
int& m_iValue;
int m_iDefault; //!<
};
class CXConsoleVariableStringRef
: public CXConsoleVariableBase
{
public:
//! constructor
//!\param userBuf must not be 0
CXConsoleVariableStringRef(CXConsole* pConsole, const char* sName, const char** userBuf, const char* defaultValue, int nFlags, const char* help)
: CXConsoleVariableBase(pConsole, sName, nFlags, help)
, m_sValue(defaultValue)
, m_sDefault(defaultValue)
, m_userPtr(*userBuf)
{
m_userPtr = m_sValue.c_str();
assert(userBuf);
}
// interface ICVar --------------------------------------------------------------------------------------
int GetIVal() const override { return atoi(m_sValue.c_str()); }
int64 GetI64Val() const override { return _atoi64(m_sValue.c_str()); }
float GetFVal() const override { return (float)atof(m_sValue.c_str()); }
const char* GetString() const override
{
return m_sValue.c_str();
}
void ResetImpl() override { Set(m_sDefault.c_str()); }
void Set(const char* s) override;
void Set(float f) override
{
AZStd::fixed_string<32> s = AZStd::fixed_string<32>::format("%g", f);
Set(s.c_str());
}
void Set(int i) override
{
AZStd::fixed_string<32> s = AZStd::fixed_string<32>::format("%d", i);
Set(s.c_str());
}
int GetType() override { return CVAR_STRING; }
private: // --------------------------------------------------------------------------------------------
AZStd::string m_sValue;
AZStd::string m_sDefault;
const char*& m_userPtr; //!<
};
class CXConsoleVariableFloatRef
: public CXConsoleVariableBase
{
public:
//! constructor
//!\param pVar must not be 0
CXConsoleVariableFloatRef(CXConsole* pConsole, const char* sName, float* pVar, int nFlags, const char* help)
: CXConsoleVariableBase(pConsole, sName, nFlags, help)
, m_fValue(*pVar)
, m_fDefault(*pVar)
{
assert(pVar);
}
// interface ICVar --------------------------------------------------------------------------------------
int GetIVal() const override { return (int)m_fValue; }
int64 GetI64Val() const override { return (int64)m_fValue; }
float GetFVal() const override { return m_fValue; }
const char* GetString() const override;
void ResetImpl() override { Set(m_fDefault); }
void Set(const char* s) override;
void Set(float f) override;
void Set(int i) override;
int GetType() override { return CVAR_FLOAT; }
protected:
const char *GetOwnDataProbeString() const override
{
static char szReturnString[8];
sprintf_s(szReturnString, "%.1g", m_fValue);
return szReturnString;
}
private: // --------------------------------------------------------------------------------------------
float& m_fValue;
float m_fDefault; //!<
};