metaforce/hecl/include/hecl/CVarManager.hpp

77 lines
2.3 KiB
C++
Executable File

#ifndef CVARMANAGER_HPP
#define CVARMANAGER_HPP
#include <unordered_map>
#include <vector>
#include "CVar.hpp"
namespace hecl
{
namespace Runtime
{
class FileStoreManager;
}
class CVarManager final
{
using CVarContainer = DNACVAR::CVarContainer;
template <typename T>
CVar* _newCVar(std::string_view name, std::string_view help, const T& value, CVar::EFlags flags)
{
CVar* ret(new CVar(name, value, help, flags, *this));
if (registerCVar(ret))
{
if (ret->isArchive())
deserialize(ret);
return ret;
}
delete ret;
return nullptr;
}
hecl::Runtime::FileStoreManager& m_store;
bool m_useBinary;
static CVarManager* m_instance;
public:
CVarManager() = delete;
CVarManager(const CVarManager&) = delete;
CVarManager& operator=(const CVarManager&) = delete;
CVarManager& operator=(const CVarManager&&) = delete;
CVarManager(hecl::Runtime::FileStoreManager& store, bool useBinary = false);
~CVarManager();
void update();
CVar* newCVar(std::string_view name, std::string_view help, const atVec4f& value, CVar::EFlags flags)
{ return _newCVar<atVec4f>(name, help, value, 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); }
CVar* newCVar(std::string_view name, std::string_view help, bool value, CVar::EFlags flags)
{ return _newCVar<bool>(name, help, value, flags); }
CVar* newCVar(std::string_view name, std::string_view help, float value, CVar::EFlags flags)
{ return _newCVar<float>(name, help, value, flags); }
CVar* newCVar(std::string_view name, std::string_view help, int value, CVar::EFlags flags)
{ return _newCVar<int>(name, help, value, flags); }
bool registerCVar(CVar* cvar);
CVar* findCVar(std::string_view name);
std::vector<CVar*> archivedCVars() const;
std::vector<CVar*> cvars() const;
void deserialize(CVar* cvar);
void serialize();
static CVarManager* instance();
private:
bool suppressDeveloper();
void restoreDeveloper(bool oldDeveloper);
std::unordered_map<std::string, CVar*> m_cvars;
};
}
#endif // CVARMANAGER_HPP