mirror of https://github.com/AxioDL/metaforce.git
Finalize CVarManager (for now)
This commit is contained in:
parent
59708f4478
commit
a21aef6fa3
|
@ -1,6 +1,7 @@
|
||||||
make_dnalist(liblist
|
make_dnalist(liblist
|
||||||
CMDL
|
CMDL
|
||||||
CVar)
|
CVar)
|
||||||
|
|
||||||
add_library(DNACommon
|
add_library(DNACommon
|
||||||
DNACommon.hpp DNACommon.cpp
|
DNACommon.hpp DNACommon.cpp
|
||||||
${liblist}
|
${liblist}
|
||||||
|
|
|
@ -2,21 +2,19 @@
|
||||||
#define _DNACOMMON_CVAR_HPP_
|
#define _DNACOMMON_CVAR_HPP_
|
||||||
|
|
||||||
#include <Athena/Global.hpp>
|
#include <Athena/Global.hpp>
|
||||||
#include <type_traits>
|
|
||||||
#include "DNACommon.hpp"
|
#include "DNACommon.hpp"
|
||||||
|
|
||||||
namespace Retro
|
namespace Retro
|
||||||
{
|
{
|
||||||
namespace DNACVAR
|
namespace DNACVAR
|
||||||
{
|
{
|
||||||
enum class EType
|
enum class EType : atUint8
|
||||||
{
|
{
|
||||||
Boolean,
|
Boolean,
|
||||||
Integer,
|
Integer,
|
||||||
Float,
|
Float,
|
||||||
Literal,
|
Literal,
|
||||||
Color,
|
Color
|
||||||
Bind
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EFlags
|
enum EFlags
|
||||||
|
@ -24,12 +22,13 @@ enum EFlags
|
||||||
All = -1, // NOTE: is this really necessary? It seems rather overkill
|
All = -1, // NOTE: is this really necessary? It seems rather overkill
|
||||||
System = (1 << 0),
|
System = (1 << 0),
|
||||||
Game = (1 << 1),
|
Game = (1 << 1),
|
||||||
Gui = (1 << 2),
|
Editor = (1 << 2),
|
||||||
Cheat = (1 << 3),
|
Gui = (1 << 3),
|
||||||
Hidden = (1 << 4),
|
Cheat = (1 << 4),
|
||||||
ReadOnly = (1 << 5),
|
Hidden = (1 << 5),
|
||||||
Archive = (1 << 6),
|
ReadOnly = (1 << 6),
|
||||||
Modified = (1 << 7)
|
Archive = (1 << 7),
|
||||||
|
Modified = (1 << 8)
|
||||||
};
|
};
|
||||||
ENABLE_BITWISE_ENUM(EFlags)
|
ENABLE_BITWISE_ENUM(EFlags)
|
||||||
|
|
||||||
|
@ -40,7 +39,14 @@ public:
|
||||||
String<-1> m_name;
|
String<-1> m_name;
|
||||||
String<-1> m_value;
|
String<-1> m_value;
|
||||||
Value<EType> m_type;
|
Value<EType> m_type;
|
||||||
Value<EFlags> m_flags;
|
};
|
||||||
|
|
||||||
|
struct CVarContainer : BigYAML
|
||||||
|
{
|
||||||
|
DECL_YAML
|
||||||
|
Value<atUint32> magic = 'CVAR';
|
||||||
|
Value<atUint32> cvarCount;
|
||||||
|
Vector<CVar, DNA_COUNT(cvarCount)> cvars;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,30 @@
|
||||||
#include <LogVisor/LogVisor.hpp>
|
#include <LogVisor/LogVisor.hpp>
|
||||||
#include <boo/boo.hpp>
|
#include <boo/boo.hpp>
|
||||||
#include <Specter/Specter.hpp>
|
#include <Specter/Specter.hpp>
|
||||||
|
#include <Runtime/CVarManager.hpp>
|
||||||
|
#include <Runtime/CGameAllocator.hpp>
|
||||||
|
|
||||||
namespace RUDE
|
namespace RUDE
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Application : boo::IApplicationCallback
|
struct Application : boo::IApplicationCallback
|
||||||
{
|
{
|
||||||
|
Retro::CGameAllocator m_allocator;
|
||||||
HECL::Runtime::FileStoreManager m_fileMgr;
|
HECL::Runtime::FileStoreManager m_fileMgr;
|
||||||
Specter::FontCache m_fontCache;
|
Specter::FontCache m_fontCache;
|
||||||
Specter::RootView m_rootView;
|
Specter::RootView m_rootView;
|
||||||
|
Retro::CVarManager m_cvarManager;
|
||||||
boo::IWindow* m_mainWindow;
|
boo::IWindow* m_mainWindow;
|
||||||
bool m_running = true;
|
bool m_running = true;
|
||||||
|
|
||||||
Application() : m_fileMgr(_S("rude")), m_fontCache(m_fileMgr), m_rootView(m_fontCache) {}
|
Application() : m_fileMgr(_S("rude")), m_fontCache(m_fileMgr), m_rootView(m_fontCache), m_cvarManager(m_fileMgr, true){}
|
||||||
|
|
||||||
int appMain(boo::IApplication* app)
|
int appMain(boo::IApplication* app)
|
||||||
{
|
{
|
||||||
|
m_allocator.Initialize();
|
||||||
m_mainWindow = app->newWindow(_S("RUDE"));
|
m_mainWindow = app->newWindow(_S("RUDE"));
|
||||||
m_rootView.setWindow(m_mainWindow, 1.0f);
|
m_rootView.setWindow(m_mainWindow, 1.0f);
|
||||||
|
m_cvarManager.serialize();
|
||||||
|
|
||||||
while (m_running)
|
while (m_running)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +32,7 @@ struct Application : boo::IApplicationCallback
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void appQuitting(boo::IApplication*)
|
void appQuitting(boo::IApplication*)
|
||||||
|
|
|
@ -15,6 +15,8 @@ else()
|
||||||
list(APPEND PLAT_SRCS CMemoryCardSysNix.cpp CCallStackNix.cpp)
|
list(APPEND PLAT_SRCS CMemoryCardSysNix.cpp CCallStackNix.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
make_dnalist(CVarManager.hpp)
|
||||||
|
|
||||||
add_library(RuntimeCommon
|
add_library(RuntimeCommon
|
||||||
CMemory.hpp CMemory.cpp
|
CMemory.hpp CMemory.cpp
|
||||||
CMemoryCardSys.hpp
|
CMemoryCardSys.hpp
|
||||||
|
@ -68,7 +70,7 @@ add_library(RuntimeCommon
|
||||||
rstl.hpp rstl.cpp
|
rstl.hpp rstl.cpp
|
||||||
GameGlobalObjects.hpp
|
GameGlobalObjects.hpp
|
||||||
CVar.hpp CVar.cpp
|
CVar.hpp CVar.cpp
|
||||||
CVarManager.hpp CVarManager.cpp
|
CVarManager.cpp
|
||||||
RetroTypes.hpp
|
RetroTypes.hpp
|
||||||
GCNTypes.hpp
|
GCNTypes.hpp
|
||||||
${PLAT_SRCS})
|
${PLAT_SRCS})
|
||||||
|
|
|
@ -7,7 +7,11 @@
|
||||||
|
|
||||||
namespace Retro
|
namespace Retro
|
||||||
{
|
{
|
||||||
CVar::CVar(const std::string& name, const std::string &value, const std::string &help, EType type, EFlags flags, CVarManager* parent)
|
extern CVar* com_developer;
|
||||||
|
extern CVar* com_enableCheats;
|
||||||
|
|
||||||
|
CVar::CVar(const std::string& name, const std::string &value, const std::string &help, EType type, EFlags flags, CVarManager& parent)
|
||||||
|
: m_mgr(parent)
|
||||||
{
|
{
|
||||||
m_name= name;
|
m_name= name;
|
||||||
m_value = value;
|
m_value = value;
|
||||||
|
@ -16,10 +20,10 @@ CVar::CVar(const std::string& name, const std::string &value, const std::string
|
||||||
m_type = type;
|
m_type = type;
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
m_allowedWrite = false;
|
m_allowedWrite = false;
|
||||||
m_mgr = parent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CVar::CVar(const std::string& name, const std::string& value, const std::string& help, CVar::EFlags flags, CVarManager* parent)
|
CVar::CVar(const std::string& name, const std::string& value, const std::string& help, CVar::EFlags flags, CVarManager& parent)
|
||||||
|
: m_mgr(parent)
|
||||||
{
|
{
|
||||||
// Unlock the cvar for writing if readonly
|
// Unlock the cvar for writing if readonly
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -29,7 +33,6 @@ CVar::CVar(const std::string& name, const std::string& value, const std::string&
|
||||||
m_type = EType::Literal;
|
m_type = EType::Literal;
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
m_allowedWrite = false;
|
m_allowedWrite = false;
|
||||||
m_mgr = parent;
|
|
||||||
|
|
||||||
fromLiteral(value);
|
fromLiteral(value);
|
||||||
m_defaultValue = m_value;
|
m_defaultValue = m_value;
|
||||||
|
@ -40,7 +43,8 @@ CVar::CVar(const std::string& name, const std::string& value, const std::string&
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
CVar::CVar(const std::string& name, const Zeus::CColor& value, const std::string& help, EFlags flags, CVarManager* parent)
|
CVar::CVar(const std::string& name, const Zeus::CColor& value, const std::string& help, EFlags flags, CVarManager& parent)
|
||||||
|
: m_mgr(parent)
|
||||||
{
|
{
|
||||||
// Unlock the cvar for writing if readonly
|
// Unlock the cvar for writing if readonly
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -50,7 +54,6 @@ CVar::CVar(const std::string& name, const Zeus::CColor& value, const std::string
|
||||||
m_type = EType::Color;
|
m_type = EType::Color;
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
m_allowedWrite = false;
|
m_allowedWrite = false;
|
||||||
m_mgr = parent;
|
|
||||||
|
|
||||||
fromColor(value);
|
fromColor(value);
|
||||||
m_defaultValue = m_value;
|
m_defaultValue = m_value;
|
||||||
|
@ -61,7 +64,8 @@ CVar::CVar(const std::string& name, const Zeus::CColor& value, const std::string
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
CVar::CVar(const std::string& name, float value, const std::string& help, EFlags flags, CVarManager* parent)
|
CVar::CVar(const std::string& name, float value, const std::string& help, EFlags flags, CVarManager& parent)
|
||||||
|
: m_mgr(parent)
|
||||||
{
|
{
|
||||||
// Unlock the cvar for writing if readonly
|
// Unlock the cvar for writing if readonly
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -71,7 +75,6 @@ CVar::CVar(const std::string& name, float value, const std::string& help, EFlags
|
||||||
m_type = EType::Float;
|
m_type = EType::Float;
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
m_allowedWrite = false;
|
m_allowedWrite = false;
|
||||||
m_mgr = parent;
|
|
||||||
|
|
||||||
fromFloat(value);
|
fromFloat(value);
|
||||||
m_defaultValue = m_value;
|
m_defaultValue = m_value;
|
||||||
|
@ -82,7 +85,8 @@ CVar::CVar(const std::string& name, float value, const std::string& help, EFlags
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
CVar::CVar(const std::string& name, bool value, const std::string& help, CVar::EFlags flags, CVarManager* parent)
|
CVar::CVar(const std::string& name, bool value, const std::string& help, CVar::EFlags flags, CVarManager& parent)
|
||||||
|
: m_mgr(parent)
|
||||||
{
|
{
|
||||||
// Unlock the cvar for writing if readonly
|
// Unlock the cvar for writing if readonly
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -92,7 +96,6 @@ CVar::CVar(const std::string& name, bool value, const std::string& help, CVar::E
|
||||||
m_type = EType::Boolean;
|
m_type = EType::Boolean;
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
m_allowedWrite = false;
|
m_allowedWrite = false;
|
||||||
m_mgr = parent;
|
|
||||||
|
|
||||||
fromBoolean(value);
|
fromBoolean(value);
|
||||||
m_defaultValue = m_value;
|
m_defaultValue = m_value;
|
||||||
|
@ -103,7 +106,8 @@ CVar::CVar(const std::string& name, bool value, const std::string& help, CVar::E
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
CVar::CVar(const std::string& name, int value, const std::string& help, CVar::EFlags flags, CVarManager* parent)
|
CVar::CVar(const std::string& name, int value, const std::string& help, CVar::EFlags flags, CVarManager& parent)
|
||||||
|
: m_mgr(parent)
|
||||||
{
|
{
|
||||||
// Unlock the cvar for writing if readonly
|
// Unlock the cvar for writing if readonly
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -113,7 +117,6 @@ CVar::CVar(const std::string& name, int value, const std::string& help, CVar::EF
|
||||||
m_type = EType::Integer;
|
m_type = EType::Integer;
|
||||||
m_flags = flags;
|
m_flags = flags;
|
||||||
m_allowedWrite = false;
|
m_allowedWrite = false;
|
||||||
m_mgr = parent;
|
|
||||||
|
|
||||||
fromInteger(value);
|
fromInteger(value);
|
||||||
m_defaultValue = m_value;
|
m_defaultValue = m_value;
|
||||||
|
@ -211,8 +214,7 @@ int CVar::toInteger(bool* isValid) const
|
||||||
return strtol(m_value.c_str(), nullptr, 0);
|
return strtol(m_value.c_str(), nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string CVar::toLiteral(bool* isValid) const
|
||||||
const std::string& CVar::toLiteral(bool* isValid) const
|
|
||||||
{
|
{
|
||||||
if (m_type != EType::Literal /*&& (com_developer && com_developer->toBoolean())*/)
|
if (m_type != EType::Literal /*&& (com_developer && com_developer->toBoolean())*/)
|
||||||
{
|
{
|
||||||
|
@ -226,6 +228,20 @@ const std::string& CVar::toLiteral(bool* isValid) const
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::wstring CVar::toWideLiteral(bool* isValid) const
|
||||||
|
{
|
||||||
|
if (m_type != EType::Literal /*&& (com_developer && com_developer->toBoolean())*/)
|
||||||
|
{
|
||||||
|
if (isValid != nullptr)
|
||||||
|
*isValid = false;
|
||||||
|
}
|
||||||
|
else if (isValid != nullptr)
|
||||||
|
*isValid = true;
|
||||||
|
|
||||||
|
// Even if it's not a literal, it's still safe to return
|
||||||
|
return HECL::UTF8ToWide(m_value);
|
||||||
|
}
|
||||||
|
|
||||||
bool CVar::fromColor(const Zeus::CColor& val)
|
bool CVar::fromColor(const Zeus::CColor& val)
|
||||||
{
|
{
|
||||||
if (isCheat())
|
if (isCheat())
|
||||||
|
@ -310,6 +326,22 @@ bool CVar::fromLiteral(const std::string& val)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CVar::fromLiteral(const std::wstring& val)
|
||||||
|
{
|
||||||
|
if (isCheat() /*&& (!com_developer->toBoolean() && !com_enableCheats->toBoolean())*/)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_type != EType::Literal)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (isReadOnly() /*&& (com_developer && !com_developer->toBoolean())*/)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_value.assign(HECL::WideToUTF8(val));
|
||||||
|
setModified();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CVar::isModified() const { return int(m_flags & EFlags::Modified) != 0;}
|
bool CVar::isModified() const { return int(m_flags & EFlags::Modified) != 0;}
|
||||||
|
|
||||||
bool CVar::isReadOnly() const { return int(m_flags & EFlags::ReadOnly) != 0; }
|
bool CVar::isReadOnly() const { return int(m_flags & EFlags::ReadOnly) != 0; }
|
||||||
|
|
|
@ -11,16 +11,18 @@ namespace Retro
|
||||||
class CVarManager;
|
class CVarManager;
|
||||||
class CVar : protected DNACVAR::CVar
|
class CVar : protected DNACVAR::CVar
|
||||||
{
|
{
|
||||||
|
friend class CVarManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using EType = DNACVAR::EType;
|
using EType = DNACVAR::EType;
|
||||||
using EFlags = DNACVAR::EFlags;
|
using EFlags = DNACVAR::EFlags;
|
||||||
|
|
||||||
CVar(const std::string& name, const std::string& value, const std::string& help, EType type, EFlags flags, CVarManager* parent);
|
CVar(const std::string& name, const std::string& value, const std::string& help, EType type, EFlags flags, CVarManager& parent);
|
||||||
CVar(const std::string& name, const std::string& value, const std::string& help, EFlags flags, CVarManager* parent);
|
CVar(const std::string& name, const std::string& value, const std::string& help, EFlags flags, CVarManager& parent);
|
||||||
CVar(const std::string& name, const Zeus::CColor& value, const std::string& help, EFlags flags, CVarManager* parent);
|
CVar(const std::string& name, const Zeus::CColor& value, const std::string& help, EFlags flags, CVarManager& parent);
|
||||||
CVar(const std::string& name, float value, const std::string& help, EFlags flags, CVarManager* parent);
|
CVar(const std::string& name, float value, const std::string& help, EFlags flags, CVarManager& parent);
|
||||||
CVar(const std::string& name, bool value, const std::string& help, EFlags flags, CVarManager* parent);
|
CVar(const std::string& name, bool value, const std::string& help, EFlags flags, CVarManager& parent);
|
||||||
CVar(const std::string& name, int value, const std::string& help, EFlags flags, CVarManager* parent);
|
CVar(const std::string& name, int value, const std::string& help, EFlags flags, CVarManager& parent);
|
||||||
|
|
||||||
|
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
|
@ -30,13 +32,15 @@ public:
|
||||||
float toFloat(bool* isValid = nullptr) const;
|
float toFloat(bool* isValid = nullptr) const;
|
||||||
bool toBoolean(bool* isValid = nullptr) const;
|
bool toBoolean(bool* isValid = nullptr) const;
|
||||||
int toInteger(bool* isValid = nullptr) const;
|
int toInteger(bool* isValid = nullptr) const;
|
||||||
const std::string& toLiteral(bool* isValid = nullptr) const;
|
const std::wstring toWideLiteral(bool* isValid = nullptr) const;
|
||||||
|
const std::string toLiteral(bool* isValid = nullptr) const;
|
||||||
|
|
||||||
bool fromColor(const Zeus::CColor& val);
|
bool fromColor(const Zeus::CColor& val);
|
||||||
bool fromFloat(float val);
|
bool fromFloat(float val);
|
||||||
bool fromBoolean(bool val);
|
bool fromBoolean(bool val);
|
||||||
bool fromInteger(int val);
|
bool fromInteger(int val);
|
||||||
bool fromLiteral(const std::string& val);
|
bool fromLiteral(const std::string& val);
|
||||||
|
bool fromLiteral(const std::wstring& val);
|
||||||
|
|
||||||
bool isFloat() const { return m_type == EType::Float; }
|
bool isFloat() const { return m_type == EType::Float; }
|
||||||
bool isBoolean() const { return m_type == EType::Boolean; }
|
bool isBoolean() const { return m_type == EType::Boolean; }
|
||||||
|
@ -72,9 +76,10 @@ public:
|
||||||
private:
|
private:
|
||||||
std::string m_help;
|
std::string m_help;
|
||||||
std::string m_defaultValue;
|
std::string m_defaultValue;
|
||||||
|
EFlags m_flags;
|
||||||
bool m_allowedWrite;
|
bool m_allowedWrite;
|
||||||
|
|
||||||
const CVarManager* m_mgr;
|
CVarManager& m_mgr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,34 @@
|
||||||
#include "CVarManager.hpp"
|
#include "CVarManager.hpp"
|
||||||
#include "CVar.hpp"
|
#include "CVar.hpp"
|
||||||
|
#include <Athena/FileWriter.hpp>
|
||||||
#include <Athena/Utility.hpp>
|
#include <Athena/Utility.hpp>
|
||||||
|
#include <HECL/Runtime.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace Retro
|
namespace Retro
|
||||||
{
|
{
|
||||||
CVarManager::CVarManager()
|
|
||||||
|
CVar* com_developer = nullptr;
|
||||||
|
CVar* com_configfile = nullptr;
|
||||||
|
CVar* com_enableCheats = nullptr;
|
||||||
|
CVar* r_clearColor = nullptr;
|
||||||
|
|
||||||
|
LogVisor::LogModule CVarLog("CVarManager");
|
||||||
|
CVarManager::CVarManager(HECL::Runtime::FileStoreManager& store, bool useBinary)
|
||||||
|
: m_store(store),
|
||||||
|
m_useBinary(useBinary)
|
||||||
{
|
{
|
||||||
|
com_configfile = newCVar("config", "File to store configuration", std::string("config"), CVar::EFlags::System);
|
||||||
|
com_developer = newCVar("developer", "Enables developer mode", false, (CVar::EFlags::System | CVar::EFlags::Cheat | CVar::EFlags::ReadOnly));
|
||||||
|
com_enableCheats = newCVar("iamaweiner", "Enable cheats", false, (CVar::EFlags::System | CVar::EFlags::Archive | CVar::EFlags::ReadOnly | CVar::EFlags::Hidden));
|
||||||
|
r_clearColor = newCVar("r_clearcolor", "Sets the clear color for the frame buffer", Zeus::CColor{Zeus::Comp8(255), 255, 255}, (CVar::EFlags::System | CVar::EFlags::Archive));
|
||||||
}
|
}
|
||||||
|
|
||||||
CVarManager::~CVarManager()
|
CVarManager::~CVarManager()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVarManager::initialize()
|
bool CVarManager::registerCVar(CVar* cvar)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CVarManager::registerCVar(std::shared_ptr<CVar> cvar)
|
|
||||||
{
|
{
|
||||||
std::string tmp = cvar->name();
|
std::string tmp = cvar->name();
|
||||||
Athena::utility::tolower(tmp);
|
Athena::utility::tolower(tmp);
|
||||||
|
@ -28,7 +39,7 @@ bool CVarManager::registerCVar(std::shared_ptr<CVar> cvar)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CVar> CVarManager::findCVar(const std::string &name)
|
CVar* CVarManager::findCVar(const std::string &name)
|
||||||
{
|
{
|
||||||
std::string tmp = std::string(name);
|
std::string tmp = std::string(name);
|
||||||
Athena::utility::tolower(tmp);
|
Athena::utility::tolower(tmp);
|
||||||
|
@ -38,40 +49,124 @@ std::shared_ptr<CVar> CVarManager::findCVar(const std::string &name)
|
||||||
return m_cvars[tmp];
|
return m_cvars[tmp];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<CVar>> CVarManager::archivedCVars() const
|
std::vector<CVar*> CVarManager::archivedCVars() const
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<CVar>> ret;
|
std::vector<CVar*> ret;
|
||||||
for (std::pair<std::string, std::shared_ptr<CVar>> pair : m_cvars)
|
for (std::pair<std::string, CVar*> pair : m_cvars)
|
||||||
{
|
if (pair.second->isArchive())
|
||||||
if (int(pair.second->flags() & CVar::EFlags::Archive) != 0)
|
|
||||||
ret.push_back(pair.second);
|
ret.push_back(pair.second);
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<CVar>> CVarManager::cvars() const
|
std::vector<CVar*> CVarManager::cvars() const
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<CVar>> ret;
|
std::vector<CVar*> ret;
|
||||||
for (std::pair<std::string, std::shared_ptr<CVar>> pair : m_cvars)
|
for (std::pair<std::string, CVar*> pair : m_cvars)
|
||||||
ret.push_back(pair.second);
|
ret.push_back(pair.second);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CVarManager::deserialize(CVar* cvar)
|
||||||
|
{
|
||||||
|
if (!cvar || !cvar->isArchive())
|
||||||
|
return;
|
||||||
|
|
||||||
|
CVarContainer container;
|
||||||
|
#if _WIN32
|
||||||
|
HECL::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toWideLiteral();
|
||||||
|
#else
|
||||||
|
HECL::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toLiteral();
|
||||||
|
#endif
|
||||||
|
HECL::Sstat st;
|
||||||
|
if (HECL::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_useBinary)
|
||||||
|
{
|
||||||
|
filename += _S(".bin");
|
||||||
|
Athena::io::FileReader reader(filename);
|
||||||
|
if (reader.isOpen())
|
||||||
|
container.read(reader);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filename += _S(".yaml");
|
||||||
|
FILE* f = HECL::Fopen(filename.c_str(), _S("rb"));
|
||||||
|
if (f)
|
||||||
|
container.fromYAMLFile(f);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (container.cvars.size() > 0)
|
||||||
|
{
|
||||||
|
auto serialized = std::find_if(container.cvars.begin(), container.cvars.end(), [&cvar](const DNACVAR::CVar& c) -> bool
|
||||||
|
{ return c.m_name == cvar->name(); });
|
||||||
|
|
||||||
|
if (serialized != container.cvars.end())
|
||||||
|
{
|
||||||
|
DNACVAR::CVar tmp = *serialized;
|
||||||
|
if (tmp.m_type != cvar->type())
|
||||||
|
{
|
||||||
|
CVarLog.report(LogVisor::Error, _S("Stored type for %s does not match actual type!"), tmp.m_name.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cvar->m_value = tmp.m_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CVarManager::serialize()
|
||||||
|
{
|
||||||
|
CVarContainer container;
|
||||||
|
for (const std::pair<std::string, CVar*>& pair : m_cvars)
|
||||||
|
if (pair.second->isArchive())
|
||||||
|
{
|
||||||
|
CVar tmp = *pair.second;
|
||||||
|
container.cvars.push_back(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
container.cvarCount = container.cvars.size();
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
HECL::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toWideLiteral();
|
||||||
|
#else
|
||||||
|
HECL::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toLiteral();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (m_useBinary)
|
||||||
|
{
|
||||||
|
filename += _S(".bin");
|
||||||
|
Athena::io::FileWriter writer(filename);
|
||||||
|
if (writer.isOpen())
|
||||||
|
container.write(writer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filename += _S(".yaml");
|
||||||
|
FILE* f = HECL::Fopen(filename.c_str(), _S("wb"));
|
||||||
|
if (f)
|
||||||
|
container.toYAMLFile(f);
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CVarManager::suppressDeveloper()
|
bool CVarManager::suppressDeveloper()
|
||||||
{
|
{
|
||||||
/*bool oldDeveloper = com_developer->toBoolean();
|
bool oldDeveloper = com_developer->toBoolean();
|
||||||
CVarUnlocker unlock(com_developer);
|
CVarUnlocker unlock(com_developer);
|
||||||
com_developer->fromBoolean(false);*/
|
com_developer->fromBoolean(false);
|
||||||
|
|
||||||
return false; //oldDeveloper;
|
return oldDeveloper;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVarManager::restoreDeveloper(bool oldDeveloper)
|
void CVarManager::restoreDeveloper(bool oldDeveloper)
|
||||||
{
|
{
|
||||||
// CVarUnlocker unlock(com_developer);
|
CVarUnlocker unlock(com_developer);
|
||||||
// com_developer->fromBoolean(oldDeveloper);
|
com_developer->fromBoolean(oldDeveloper);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,51 +3,65 @@
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
|
||||||
#include "CVar.hpp"
|
#include "CVar.hpp"
|
||||||
|
|
||||||
|
namespace HECL
|
||||||
|
{
|
||||||
|
namespace Runtime
|
||||||
|
{
|
||||||
|
class FileStoreManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
namespace Retro
|
namespace Retro
|
||||||
{
|
{
|
||||||
|
|
||||||
class CVarManager
|
class CVarManager
|
||||||
{
|
{
|
||||||
|
using CVarContainer = DNACVAR::CVarContainer;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::shared_ptr<CVar> _newCVar(const std::string& name, const std::string& help, const T& value, CVar::EFlags flags)
|
CVar* _newCVar(const std::string& name, const std::string& help, const T& value, CVar::EFlags flags)
|
||||||
{
|
{
|
||||||
std::shared_ptr<CVar> ret(new CVar(name, value, help, flags, this));
|
CVar* ret(new CVar(name, value, help, flags, *this));
|
||||||
if (registerCVar(ret))
|
if (registerCVar(ret))
|
||||||
|
{
|
||||||
|
deserialize(ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
delete ret;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HECL::Runtime::FileStoreManager& m_store;
|
||||||
|
bool m_useBinary;
|
||||||
public:
|
public:
|
||||||
CVarManager();
|
CVarManager(HECL::Runtime::FileStoreManager& store, bool useBinary = false);
|
||||||
~CVarManager();
|
~CVarManager();
|
||||||
|
|
||||||
void initialize();
|
CVar* newCVar(const std::string& name, const std::string& help, const Zeus::CColor& value, CVar::EFlags flags)
|
||||||
|
|
||||||
std::shared_ptr<CVar> newCVar(const std::string& name, const std::string& help, const Zeus::CColor& value, CVar::EFlags flags)
|
|
||||||
{ return _newCVar<Zeus::CColor>(name, help, value, flags); }
|
{ return _newCVar<Zeus::CColor>(name, help, value, flags); }
|
||||||
std::shared_ptr<CVar> newCVar(const std::string& name, const std::string& help, const std::string& value, CVar::EFlags flags)
|
CVar* newCVar(const std::string& name, const std::string& help, const std::string& value, CVar::EFlags flags)
|
||||||
{ return _newCVar<std::string>(name, help, value, flags); }
|
{ return _newCVar<std::string>(name, help, value, flags); }
|
||||||
std::shared_ptr<CVar> newCVar(const std::string& name, const std::string& help, bool value, CVar::EFlags flags)
|
CVar* newCVar(const std::string& name, const std::string& help, bool value, CVar::EFlags flags)
|
||||||
{ return _newCVar<bool>(name, help, value, flags); }
|
{ return _newCVar<bool>(name, help, value, flags); }
|
||||||
std::shared_ptr<CVar> newCVar(const std::string& name, const std::string& help, float value, CVar::EFlags flags)
|
CVar* newCVar(const std::string& name, const std::string& help, float value, CVar::EFlags flags)
|
||||||
{ return _newCVar<float>(name, help, value, flags); }
|
{ return _newCVar<float>(name, help, value, flags); }
|
||||||
std::shared_ptr<CVar> newCVar(const std::string& name, const std::string& help, int value, CVar::EFlags flags)
|
CVar* newCVar(const std::string& name, const std::string& help, int value, CVar::EFlags flags)
|
||||||
{ return _newCVar<int>(name, help, value, flags); }
|
{ return _newCVar<int>(name, help, value, flags); }
|
||||||
|
|
||||||
bool registerCVar(std::shared_ptr<CVar> cvar);
|
bool registerCVar(CVar* cvar);
|
||||||
|
|
||||||
std::shared_ptr<CVar>findCVar(const std::string& name);
|
CVar*findCVar(const std::string& name);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<CVar>> archivedCVars() const;
|
std::vector<CVar*> archivedCVars() const;
|
||||||
std::vector<std::shared_ptr<CVar>> cvars() const;
|
std::vector<CVar*> cvars() const;
|
||||||
|
|
||||||
|
void deserialize(CVar* cvar);
|
||||||
|
void serialize();
|
||||||
private:
|
private:
|
||||||
bool suppressDeveloper();
|
bool suppressDeveloper();
|
||||||
void restoreDeveloper(bool oldDeveloper);
|
void restoreDeveloper(bool oldDeveloper);
|
||||||
|
|
||||||
std::unordered_map<std::string, std::shared_ptr<CVar>> m_cvars;
|
std::unordered_map<std::string, CVar*> m_cvars;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue