2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-13 06:45:53 +00:00

Fix extraneous CRLFs

This commit is contained in:
Luke Street 2021-02-01 05:12:09 +00:00
parent c78676b1fd
commit bde5f2c007
2 changed files with 440 additions and 440 deletions

View File

@ -1,320 +1,320 @@
#pragma once #pragma once
#include <functional> #include <functional>
#include <string> #include <string>
#include <vector> #include <vector>
#include <athena/DNAYaml.hpp> #include <athena/DNAYaml.hpp>
#include <athena/Global.hpp> #include <athena/Global.hpp>
#include <athena/Types.hpp> #include <athena/Types.hpp>
namespace hecl { namespace hecl {
namespace DNACVAR { namespace DNACVAR {
enum class EType : atUint8 { Boolean, Signed, Unsigned, Real, Literal, Vec2f, Vec2d, Vec3f, Vec3d, Vec4f, Vec4d }; enum class EType : atUint8 { Boolean, Signed, Unsigned, Real, Literal, Vec2f, Vec2d, Vec3f, Vec3d, Vec4f, Vec4d };
enum class EFlags { enum class EFlags {
None = 0, None = 0,
System = (1 << 0), System = (1 << 0),
Game = (1 << 1), Game = (1 << 1),
Editor = (1 << 2), Editor = (1 << 2),
Gui = (1 << 3), Gui = (1 << 3),
Cheat = (1 << 4), Cheat = (1 << 4),
Hidden = (1 << 5), Hidden = (1 << 5),
ReadOnly = (1 << 6), ReadOnly = (1 << 6),
Archive = (1 << 7), Archive = (1 << 7),
InternalArchivable = (1 << 8), InternalArchivable = (1 << 8),
Modified = (1 << 9), Modified = (1 << 9),
ModifyRestart = (1 << 10), //!< If this bit is set, any modification will inform the user that a restart is required ModifyRestart = (1 << 10), //!< If this bit is set, any modification will inform the user that a restart is required
Color = (1 << 11), //!< If this bit is set, Vec3f and Vec4f will be displayed in the console with a colored square Color = (1 << 11), //!< If this bit is set, Vec3f and Vec4f will be displayed in the console with a colored square
NoDeveloper = (1 << 12), //!< Not even developer mode can modify this NoDeveloper = (1 << 12), //!< Not even developer mode can modify this
Any = -1 Any = -1
}; };
ENABLE_BITWISE_ENUM(EFlags) ENABLE_BITWISE_ENUM(EFlags)
class CVar : public athena::io::DNA<athena::Endian::Big> { class CVar : public athena::io::DNA<athena::Endian::Big> {
public: public:
AT_DECL_DNA AT_DECL_DNA
String<-1> m_name; String<-1> m_name;
String<-1> m_value; String<-1> m_value;
}; };
struct CVarContainer : public athena::io::DNA<athena::Endian::Big> { struct CVarContainer : public athena::io::DNA<athena::Endian::Big> {
AT_DECL_DNA AT_DECL_DNA
Value<atUint32> magic = 'CVAR'; Value<atUint32> magic = 'CVAR';
Value<atUint32> cvarCount; Value<atUint32> cvarCount;
Vector<CVar, AT_DNA_COUNT(cvarCount)> cvars; Vector<CVar, AT_DNA_COUNT(cvarCount)> cvars;
}; };
} // namespace DNACVAR } // namespace DNACVAR
class CVarManager; class CVarManager;
class CVar : protected DNACVAR::CVar { class CVar : protected DNACVAR::CVar {
friend class CVarManager; friend class CVarManager;
Delete _d; Delete _d;
public: public:
typedef std::function<void(CVar*)> ListenerFunc; typedef std::function<void(CVar*)> ListenerFunc;
using EType = DNACVAR::EType; using EType = DNACVAR::EType;
using EFlags = DNACVAR::EFlags; using EFlags = DNACVAR::EFlags;
CVar(std::string_view name, std::string_view value, std::string_view help, EFlags flags); CVar(std::string_view name, std::string_view value, std::string_view help, EFlags flags);
CVar(std::string_view name, const atVec2f& value, std::string_view help, EFlags flags); CVar(std::string_view name, const atVec2f& value, std::string_view help, EFlags flags);
CVar(std::string_view name, const atVec2d& value, std::string_view help, EFlags flags); CVar(std::string_view name, const atVec2d& value, std::string_view help, EFlags flags);
CVar(std::string_view name, const atVec3f& value, std::string_view help, EFlags flags); CVar(std::string_view name, const atVec3f& value, std::string_view help, EFlags flags);
CVar(std::string_view name, const atVec3d& value, std::string_view help, EFlags flags); CVar(std::string_view name, const atVec3d& value, std::string_view help, EFlags flags);
CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags); CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags);
CVar(std::string_view name, const atVec4d& value, std::string_view help, EFlags flags); CVar(std::string_view name, const atVec4d& value, std::string_view help, EFlags flags);
CVar(std::string_view name, double value, std::string_view help, EFlags flags); CVar(std::string_view name, double value, std::string_view help, EFlags flags);
CVar(std::string_view name, bool value, std::string_view help, EFlags flags); CVar(std::string_view name, bool value, std::string_view help, EFlags flags);
CVar(std::string_view name, int32_t value, std::string_view help, EFlags flags); CVar(std::string_view name, int32_t value, std::string_view help, EFlags flags);
CVar(std::string_view name, uint32_t value, std::string_view help, EFlags flags); CVar(std::string_view name, uint32_t value, std::string_view help, EFlags flags);
std::string_view name() const { return m_name; } std::string_view name() const { return m_name; }
std::string_view rawHelp() const { return m_help; } std::string_view rawHelp() const { return m_help; }
std::string help() const; std::string help() const;
std::string value() const { return m_value; } std::string value() const { return m_value; }
template <typename T> template <typename T>
inline bool toValue(T& value) const; inline bool toValue(T& value) const;
atVec2f toVec2f(bool* isValid = nullptr) const; atVec2f toVec2f(bool* isValid = nullptr) const;
atVec2d toVec2d(bool* isValid = nullptr) const; atVec2d toVec2d(bool* isValid = nullptr) const;
atVec3f toVec3f(bool* isValid = nullptr) const; atVec3f toVec3f(bool* isValid = nullptr) const;
atVec3d toVec3d(bool* isValid = nullptr) const; atVec3d toVec3d(bool* isValid = nullptr) const;
atVec4f toVec4f(bool* isValid = nullptr) const; atVec4f toVec4f(bool* isValid = nullptr) const;
atVec4d toVec4d(bool* isValid = nullptr) const; atVec4d toVec4d(bool* isValid = nullptr) const;
double toReal(bool* isValid = nullptr) const; double toReal(bool* isValid = nullptr) const;
bool toBoolean(bool* isValid = nullptr) const; bool toBoolean(bool* isValid = nullptr) const;
int32_t toSigned(bool* isValid = nullptr) const; int32_t toSigned(bool* isValid = nullptr) const;
uint32_t toUnsigned(bool* isValid = nullptr) const; uint32_t toUnsigned(bool* isValid = nullptr) const;
std::wstring toWideLiteral(bool* isValid = nullptr) const; std::wstring toWideLiteral(bool* isValid = nullptr) const;
std::string toLiteral(bool* isValid = nullptr) const; std::string toLiteral(bool* isValid = nullptr) const;
template <typename T> template <typename T>
inline bool fromValue(T value) { inline bool fromValue(T value) {
return false; return false;
} }
bool fromVec2f(const atVec2f& val); bool fromVec2f(const atVec2f& val);
bool fromVec2d(const atVec2d& val); bool fromVec2d(const atVec2d& val);
bool fromVec3f(const atVec3f& val); bool fromVec3f(const atVec3f& val);
bool fromVec3d(const atVec3d& val); bool fromVec3d(const atVec3d& val);
bool fromVec4f(const atVec4f& val); bool fromVec4f(const atVec4f& val);
bool fromVec4d(const atVec4d& val); bool fromVec4d(const atVec4d& val);
bool fromReal(double val); bool fromReal(double val);
bool fromBoolean(bool val); bool fromBoolean(bool val);
bool fromInteger(int32_t val); bool fromInteger(int32_t val);
bool fromInteger(uint32_t val); bool fromInteger(uint32_t val);
bool fromLiteral(std::string_view val); bool fromLiteral(std::string_view val);
bool fromLiteral(std::wstring_view val); bool fromLiteral(std::wstring_view val);
bool fromLiteralToType(std::string_view val); bool fromLiteralToType(std::string_view val);
bool fromLiteralToType(std::wstring_view val); bool fromLiteralToType(std::wstring_view val);
bool isVec2f() const { return m_type == EType::Vec2f; } bool isVec2f() const { return m_type == EType::Vec2f; }
bool isVec2d() const { return m_type == EType::Vec2d; } bool isVec2d() const { return m_type == EType::Vec2d; }
bool isVec3f() const { return m_type == EType::Vec3f; } bool isVec3f() const { return m_type == EType::Vec3f; }
bool isVec3d() const { return m_type == EType::Vec3d; } bool isVec3d() const { return m_type == EType::Vec3d; }
bool isVec4f() const { return m_type == EType::Vec4f; } bool isVec4f() const { return m_type == EType::Vec4f; }
bool isVec4d() const { return m_type == EType::Vec4d; } bool isVec4d() const { return m_type == EType::Vec4d; }
bool isFloat() const { return m_type == EType::Real; } bool isFloat() const { return m_type == EType::Real; }
bool isBoolean() const { return m_type == EType::Boolean; } bool isBoolean() const { return m_type == EType::Boolean; }
bool isInteger() const { return m_type == EType::Signed || m_type == EType::Unsigned; } bool isInteger() const { return m_type == EType::Signed || m_type == EType::Unsigned; }
bool isLiteral() const { return m_type == EType::Literal; } bool isLiteral() const { return m_type == EType::Literal; }
bool isModified() const; bool isModified() const;
bool modificationRequiresRestart() const; bool modificationRequiresRestart() const;
bool isReadOnly() const; bool isReadOnly() const;
bool isCheat() const; bool isCheat() const;
bool isHidden() const; bool isHidden() const;
bool isArchive() const; bool isArchive() const;
bool isInternalArchivable() const; bool isInternalArchivable() const;
bool isNoDeveloper() const; bool isNoDeveloper() const;
bool isColor() const; bool isColor() const;
bool wasDeserialized() const; bool wasDeserialized() const;
bool hasDefaultValue() const; bool hasDefaultValue() const;
EType type() const { return m_type; } EType type() const { return m_type; }
EFlags flags() const { return (m_unlocked ? m_oldFlags : m_flags); } EFlags flags() const { return (m_unlocked ? m_oldFlags : m_flags); }
/*! /*!
* \brief Unlocks the CVar for writing if it is ReadOnly. * \brief Unlocks the CVar for writing if it is ReadOnly.
* <b>Handle with care!!!</b> if you use unlock(), make sure * <b>Handle with care!!!</b> if you use unlock(), make sure
* you lock the cvar using lock() * you lock the cvar using lock()
* \see lock * \see lock
*/ */
void unlock(); void unlock();
/*! /*!
* \brief Locks the CVar to prevent writing if it is ReadOnly. * \brief Locks the CVar to prevent writing if it is ReadOnly.
* Unlike its partner function unlock, lock is harmless * Unlike its partner function unlock, lock is harmless
* \see unlock * \see unlock
*/ */
void lock(); void lock();
void addListener(ListenerFunc func) { m_listeners.push_back(std::move(func)); } void addListener(ListenerFunc func) { m_listeners.push_back(std::move(func)); }
bool isValidInput(std::string_view input) const; bool isValidInput(std::string_view input) const;
bool isValidInput(std::wstring_view input) const; bool isValidInput(std::wstring_view input) const;
private: private:
CVar(std::string_view name, std::string_view help, EType type) : m_help(help), m_type(type) { m_name = name; } CVar(std::string_view name, std::string_view help, EType type) : m_help(help), m_type(type) { m_name = name; }
void dispatch(); void dispatch();
void clearModified(); void clearModified();
void setModified(); void setModified();
std::string m_help; std::string m_help;
EType m_type; EType m_type;
std::string m_defaultValue; std::string m_defaultValue;
EFlags m_flags = EFlags::None; EFlags m_flags = EFlags::None;
EFlags m_oldFlags = EFlags::None; EFlags m_oldFlags = EFlags::None;
bool m_unlocked = false; bool m_unlocked = false;
bool m_wasDeserialized = false; bool m_wasDeserialized = false;
std::vector<ListenerFunc> m_listeners; std::vector<ListenerFunc> m_listeners;
bool safeToModify(EType type) const; bool safeToModify(EType type) const;
void init(EFlags flags, bool removeColor = true); void init(EFlags flags, bool removeColor = true);
}; };
template <> template <>
inline bool CVar::toValue(atVec2f& value) const { inline bool CVar::toValue(atVec2f& value) const {
bool isValid = false; bool isValid = false;
value = toVec2f(&isValid); value = toVec2f(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(atVec2d& value) const { inline bool CVar::toValue(atVec2d& value) const {
bool isValid = false; bool isValid = false;
value = toVec2d(&isValid); value = toVec2d(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(atVec3f& value) const { inline bool CVar::toValue(atVec3f& value) const {
bool isValid = false; bool isValid = false;
value = toVec3f(&isValid); value = toVec3f(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(atVec3d& value) const { inline bool CVar::toValue(atVec3d& value) const {
bool isValid = false; bool isValid = false;
value = toVec3d(&isValid); value = toVec3d(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(atVec4f& value) const { inline bool CVar::toValue(atVec4f& value) const {
bool isValid = false; bool isValid = false;
value = toVec4f(&isValid); value = toVec4f(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(atVec4d& value) const { inline bool CVar::toValue(atVec4d& value) const {
bool isValid = false; bool isValid = false;
value = toVec4d(&isValid); value = toVec4d(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(double& value) const { inline bool CVar::toValue(double& value) const {
bool isValid = false; bool isValid = false;
value = toReal(&isValid); value = toReal(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(float& value) const { inline bool CVar::toValue(float& value) const {
bool isValid = false; bool isValid = false;
value = static_cast<float>(toReal(&isValid)); value = static_cast<float>(toReal(&isValid));
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(bool& value) const { inline bool CVar::toValue(bool& value) const {
bool isValid = false; bool isValid = false;
value = toBoolean(&isValid); value = toBoolean(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(int32_t& value) const { inline bool CVar::toValue(int32_t& value) const {
bool isValid = false; bool isValid = false;
value = toSigned(&isValid); value = toSigned(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(uint32_t& value) const { inline bool CVar::toValue(uint32_t& value) const {
bool isValid = false; bool isValid = false;
value = toUnsigned(&isValid); value = toUnsigned(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(std::wstring& value) const { inline bool CVar::toValue(std::wstring& value) const {
bool isValid = false; bool isValid = false;
value = toWideLiteral(&isValid); value = toWideLiteral(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::toValue(std::string& value) const { inline bool CVar::toValue(std::string& value) const {
bool isValid = false; bool isValid = false;
value = toLiteral(&isValid); value = toLiteral(&isValid);
return isValid; return isValid;
} }
template <> template <>
inline bool CVar::fromValue(const atVec2f& val) { inline bool CVar::fromValue(const atVec2f& val) {
return fromVec2f(val); return fromVec2f(val);
} }
template <> template <>
inline bool CVar::fromValue(const atVec2d& val) { inline bool CVar::fromValue(const atVec2d& val) {
return fromVec2d(val); return fromVec2d(val);
} }
template <> template <>
inline bool CVar::fromValue(const atVec3f& val) { inline bool CVar::fromValue(const atVec3f& val) {
return fromVec3f(val); return fromVec3f(val);
} }
template <> template <>
inline bool CVar::fromValue(const atVec3d& val) { inline bool CVar::fromValue(const atVec3d& val) {
return fromVec3d(val); return fromVec3d(val);
} }
template <> template <>
inline bool CVar::fromValue(const atVec4f& val) { inline bool CVar::fromValue(const atVec4f& val) {
return fromVec4f(val); return fromVec4f(val);
} }
template <> template <>
inline bool CVar::fromValue(const atVec4d& val) { inline bool CVar::fromValue(const atVec4d& val) {
return fromVec4d(val); return fromVec4d(val);
} }
template <> template <>
inline bool CVar::fromValue(float val) { inline bool CVar::fromValue(float val) {
return fromReal(val); return fromReal(val);
} }
template <> template <>
inline bool CVar::fromValue(double val) { inline bool CVar::fromValue(double val) {
return fromReal(val); return fromReal(val);
} }
template <> template <>
inline bool CVar::fromValue(bool val) { inline bool CVar::fromValue(bool val) {
return fromBoolean(val); return fromBoolean(val);
} }
template <> template <>
inline bool CVar::fromValue(int32_t val) { inline bool CVar::fromValue(int32_t val) {
return fromInteger(val); return fromInteger(val);
} }
template <> template <>
inline bool CVar::fromValue(uint32_t val) { inline bool CVar::fromValue(uint32_t val) {
return fromInteger(val); return fromInteger(val);
} }
template <> template <>
inline bool CVar::fromValue(std::string_view val) { inline bool CVar::fromValue(std::string_view val) {
return fromLiteral(val); return fromLiteral(val);
} }
template <> template <>
inline bool CVar::fromValue(std::wstring_view val) { inline bool CVar::fromValue(std::wstring_view val) {
return fromLiteral(val); return fromLiteral(val);
} }
class CVarUnlocker { class CVarUnlocker {
CVar* m_cvar; CVar* m_cvar;
public: public:
CVarUnlocker(CVar* cvar) : m_cvar(cvar) { CVarUnlocker(CVar* cvar) : m_cvar(cvar) {
if (m_cvar) if (m_cvar)
m_cvar->unlock(); m_cvar->unlock();
} }
~CVarUnlocker() { ~CVarUnlocker() {
if (m_cvar) if (m_cvar)
m_cvar->lock(); m_cvar->lock();
} }
}; };
} // namespace hecl } // namespace hecl

View File

@ -1,120 +1,120 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "hecl/CVar.hpp" #include "hecl/CVar.hpp"
#include "hecl/SystemChar.hpp" #include "hecl/SystemChar.hpp"
namespace hecl { namespace hecl {
namespace Runtime { namespace Runtime {
class FileStoreManager; class FileStoreManager;
} }
extern CVar* com_developer; extern CVar* com_developer;
extern CVar* com_configfile; extern CVar* com_configfile;
extern CVar* com_enableCheats; extern CVar* com_enableCheats;
extern CVar* com_cubemaps; extern CVar* com_cubemaps;
class CVarManager final { class CVarManager final {
using CVarContainer = DNACVAR::CVarContainer; using CVarContainer = DNACVAR::CVarContainer;
template <typename T> template <typename T>
CVar* _newCVar(std::string_view name, std::string_view help, const T& value, CVar::EFlags flags) { CVar* _newCVar(std::string_view name, std::string_view help, const T& value, CVar::EFlags flags) {
if (CVar* ret = registerCVar(std::make_unique<CVar>(name, value, help, flags))) { if (CVar* ret = registerCVar(std::make_unique<CVar>(name, value, help, flags))) {
deserialize(ret); deserialize(ret);
return ret; return ret;
} }
return nullptr; return nullptr;
} }
hecl::Runtime::FileStoreManager& m_store; hecl::Runtime::FileStoreManager& m_store;
bool m_useBinary; bool m_useBinary;
static CVarManager* m_instance; static CVarManager* m_instance;
public: public:
CVarManager() = delete; CVarManager() = delete;
CVarManager(const CVarManager&) = delete; CVarManager(const CVarManager&) = delete;
CVarManager& operator=(const CVarManager&) = delete; CVarManager& operator=(const CVarManager&) = delete;
CVarManager& operator=(const CVarManager&&) = delete; CVarManager& operator=(const CVarManager&&) = delete;
CVarManager(hecl::Runtime::FileStoreManager& store, bool useBinary = false); CVarManager(hecl::Runtime::FileStoreManager& store, bool useBinary = false);
~CVarManager(); ~CVarManager();
CVar* newCVar(std::string_view name, std::string_view help, const atVec2f& value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, const atVec2f& value, CVar::EFlags flags) {
return _newCVar<atVec2f>(name, help, value, flags); return _newCVar<atVec2f>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, const atVec2d& value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, const atVec2d& value, CVar::EFlags flags) {
return _newCVar<atVec2d>(name, help, value, flags); return _newCVar<atVec2d>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, const atVec3f& value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, const atVec3f& value, CVar::EFlags flags) {
return _newCVar<atVec3f>(name, help, value, flags); return _newCVar<atVec3f>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, const atVec3d& value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, const atVec3d& value, CVar::EFlags flags) {
return _newCVar<atVec3d>(name, help, value, flags); return _newCVar<atVec3d>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, const atVec4f& value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, const atVec4f& value, CVar::EFlags flags) {
return _newCVar<atVec4f>(name, help, value, flags); return _newCVar<atVec4f>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, const atVec4d& value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, const atVec4d& value, CVar::EFlags flags) {
return _newCVar<atVec4d>(name, help, value, flags); return _newCVar<atVec4d>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, std::string_view value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, std::string_view value, CVar::EFlags flags) {
return _newCVar<std::string_view>(name, help, value, flags); return _newCVar<std::string_view>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, bool value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, bool value, CVar::EFlags flags) {
return _newCVar<bool>(name, help, value, flags); return _newCVar<bool>(name, help, value, flags);
} }
// Float and double are internally identical, all floating point values are stored as `double` // Float and double are internally identical, all floating point values are stored as `double`
CVar* newCVar(std::string_view name, std::string_view help, float value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, float value, CVar::EFlags flags) {
return _newCVar<double>(name, help, static_cast<double>(value), flags); return _newCVar<double>(name, help, static_cast<double>(value), flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, double value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, double value, CVar::EFlags flags) {
return _newCVar<double>(name, help, value, flags); return _newCVar<double>(name, help, value, flags);
} }
// Integer CVars can be seamlessly converted between either type, the distinction is to make usage absolutely clear // Integer CVars can be seamlessly converted between either type, the distinction is to make usage absolutely clear
CVar* newCVar(std::string_view name, std::string_view help, int32_t value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, int32_t value, CVar::EFlags flags) {
return _newCVar<int32_t>(name, help, value, flags); return _newCVar<int32_t>(name, help, value, flags);
} }
CVar* newCVar(std::string_view name, std::string_view help, uint32_t value, CVar::EFlags flags) { CVar* newCVar(std::string_view name, std::string_view help, uint32_t value, CVar::EFlags flags) {
return _newCVar<uint32_t>(name, help, value, flags); return _newCVar<uint32_t>(name, help, value, flags);
} }
CVar* registerCVar(std::unique_ptr<CVar>&& cvar); CVar* registerCVar(std::unique_ptr<CVar>&& cvar);
CVar* findCVar(std::string_view name); CVar* findCVar(std::string_view name);
template <class... _Args> template <class... _Args>
CVar* findOrMakeCVar(std::string_view name, _Args&&... args) { CVar* findOrMakeCVar(std::string_view name, _Args&&... args) {
if (CVar* cv = findCVar(name)) if (CVar* cv = findCVar(name))
return cv; return cv;
return newCVar(name, std::forward<_Args>(args)...); return newCVar(name, std::forward<_Args>(args)...);
} }
std::vector<CVar*> archivedCVars() const; std::vector<CVar*> archivedCVars() const;
std::vector<CVar*> cvars(CVar::EFlags filter = CVar::EFlags::Any) const; std::vector<CVar*> cvars(CVar::EFlags filter = CVar::EFlags::Any) const;
void deserialize(CVar* cvar); void deserialize(CVar* cvar);
void serialize(); void serialize();
static CVarManager* instance(); static CVarManager* instance();
void proc(); void proc();
void list(class Console* con, const std::vector<std::string>& args); void list(class Console* con, const std::vector<std::string>& args);
void setCVar(class Console* con, const std::vector<std::string>& args); void setCVar(class Console* con, const std::vector<std::string>& args);
void getCVar(class Console* con, const std::vector<std::string>& args); void getCVar(class Console* con, const std::vector<std::string>& args);
void setDeveloperMode(bool v, bool setDeserialized = false); void setDeveloperMode(bool v, bool setDeserialized = false);
void setCheatsEnabled(bool v, bool setDeserialized = false); void setCheatsEnabled(bool v, bool setDeserialized = false);
bool restartRequired() const; bool restartRequired() const;
void parseCommandLine(const std::vector<SystemString>& args); void parseCommandLine(const std::vector<SystemString>& args);
private: private:
bool suppressDeveloper(); bool suppressDeveloper();
void restoreDeveloper(bool oldDeveloper); void restoreDeveloper(bool oldDeveloper);
std::unordered_map<std::string, std::unique_ptr<CVar>> m_cvars; std::unordered_map<std::string, std::unique_ptr<CVar>> m_cvars;
std::unordered_map<std::string, std::string> m_deferedCVars; std::unordered_map<std::string, std::string> m_deferedCVars;
}; };
} // namespace hecl } // namespace hecl