2021-02-01 05:12:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-02-21 02:28:07 +00:00
|
|
|
#include "Runtime/ConsoleVariables/CVar.hpp"
|
2021-02-01 05:12:09 +00:00
|
|
|
|
2022-02-21 02:28:07 +00:00
|
|
|
namespace metaforce {
|
2021-02-01 05:12:09 +00:00
|
|
|
class FileStoreManager;
|
|
|
|
extern CVar* com_developer;
|
|
|
|
extern CVar* com_configfile;
|
|
|
|
extern CVar* com_enableCheats;
|
|
|
|
extern CVar* com_cubemaps;
|
|
|
|
class CVarManager final {
|
2022-02-21 02:28:07 +00:00
|
|
|
using CVarContainer = StoreCVar::CVarContainer;
|
2021-02-01 05:12:09 +00:00
|
|
|
template <typename T>
|
|
|
|
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))) {
|
|
|
|
deserialize(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-02-21 02:28:07 +00:00
|
|
|
FileStoreManager& m_store;
|
2021-02-01 05:12:09 +00:00
|
|
|
bool m_useBinary;
|
|
|
|
static CVarManager* m_instance;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CVarManager() = delete;
|
|
|
|
CVarManager(const CVarManager&) = delete;
|
|
|
|
CVarManager& operator=(const CVarManager&) = delete;
|
|
|
|
CVarManager& operator=(const CVarManager&&) = delete;
|
2022-02-21 02:28:07 +00:00
|
|
|
CVarManager(FileStoreManager& store, bool useBinary = false);
|
2021-02-01 05:12:09 +00:00
|
|
|
~CVarManager();
|
|
|
|
|
2022-02-21 02:28:07 +00:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector2f& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<const zeus::CVector2f>(name, help, value, flags);
|
2021-02-01 05:12:09 +00:00
|
|
|
}
|
2022-02-21 02:28:07 +00:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector2d& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<const zeus::CVector2d>(name, help, value, flags);
|
2021-02-01 05:12:09 +00:00
|
|
|
}
|
2022-02-21 02:28:07 +00:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector3f& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<const zeus::CVector3f>(name, help, value, flags);
|
2021-02-01 05:12:09 +00:00
|
|
|
}
|
2022-02-21 02:28:07 +00:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector3d& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<const zeus::CVector3d>(name, help, value, flags);
|
2021-02-01 05:12:09 +00:00
|
|
|
}
|
2022-02-21 02:28:07 +00:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector4f& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<const zeus::CVector4f>(name, help, value, flags);
|
2021-02-01 05:12:09 +00:00
|
|
|
}
|
2022-02-21 02:28:07 +00:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector4d& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<const zeus::CVector4d>(name, help, value, flags);
|
2021-02-01 05:12:09 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
// 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) {
|
|
|
|
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) {
|
|
|
|
return _newCVar<double>(name, help, value, flags);
|
|
|
|
}
|
|
|
|
// 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) {
|
|
|
|
return _newCVar<int32_t>(name, help, value, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
CVar* registerCVar(std::unique_ptr<CVar>&& cvar);
|
|
|
|
|
|
|
|
CVar* findCVar(std::string_view name);
|
|
|
|
template <class... _Args>
|
|
|
|
CVar* findOrMakeCVar(std::string_view name, _Args&&... args) {
|
|
|
|
if (CVar* cv = findCVar(name))
|
|
|
|
return cv;
|
|
|
|
return newCVar(name, std::forward<_Args>(args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CVar*> archivedCVars() const;
|
|
|
|
std::vector<CVar*> cvars(CVar::EFlags filter = CVar::EFlags::Any) const;
|
|
|
|
|
|
|
|
void deserialize(CVar* cvar);
|
|
|
|
void serialize();
|
|
|
|
|
|
|
|
static CVarManager* instance();
|
|
|
|
|
|
|
|
void proc();
|
|
|
|
|
|
|
|
void setDeveloperMode(bool v, bool setDeserialized = false);
|
|
|
|
void setCheatsEnabled(bool v, bool setDeserialized = false);
|
|
|
|
bool restartRequired() const;
|
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
void parseCommandLine(const std::vector<std::string>& args);
|
2021-02-01 05:12:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool suppressDeveloper();
|
|
|
|
void restoreDeveloper(bool oldDeveloper);
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::unique_ptr<CVar>> m_cvars;
|
|
|
|
std::unordered_map<std::string, std::string> m_deferedCVars;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace hecl
|