2018-10-06 20:38:44 -07:00
|
|
|
#pragma once
|
2015-12-02 13:11:10 -08:00
|
|
|
|
2019-09-04 14:22:05 -07:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2015-12-02 13:11:10 -08:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
2019-09-04 14:22:05 -07:00
|
|
|
|
|
|
|
#include "hecl/CVar.hpp"
|
2018-04-29 20:11:37 -07:00
|
|
|
#include "hecl/SystemChar.hpp"
|
2015-12-02 13:11:10 -08:00
|
|
|
|
2018-12-07 21:18:42 -08:00
|
|
|
namespace hecl {
|
|
|
|
namespace Runtime {
|
2015-12-02 13:11:10 -08:00
|
|
|
class FileStoreManager;
|
|
|
|
}
|
2018-01-21 18:40:11 -08:00
|
|
|
extern CVar* com_developer;
|
|
|
|
extern CVar* com_configfile;
|
|
|
|
extern CVar* com_enableCheats;
|
2019-06-05 17:07:29 -07:00
|
|
|
extern CVar* com_cubemaps;
|
2018-12-07 21:18:42 -08:00
|
|
|
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) {
|
2019-09-29 05:44:01 -07:00
|
|
|
if (CVar* ret = registerCVar(std::make_unique<CVar>(name, value, help, flags))) {
|
2018-12-07 21:18:42 -08:00
|
|
|
deserialize(ret);
|
|
|
|
return ret;
|
2015-12-02 13:11:10 -08:00
|
|
|
}
|
2018-12-07 21:18:42 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-12-02 13:11:10 -08:00
|
|
|
|
2018-12-07 21:18:42 -08:00
|
|
|
hecl::Runtime::FileStoreManager& m_store;
|
|
|
|
bool m_useBinary;
|
|
|
|
static CVarManager* m_instance;
|
2015-12-03 17:43:29 -08:00
|
|
|
|
2018-12-07 21:18:42 -08:00
|
|
|
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();
|
|
|
|
|
2019-09-29 05:44:01 -07:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const atVec2f& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<atVec2f>(name, help, value, flags);
|
|
|
|
}
|
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const atVec2d& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<atVec2d>(name, help, value, flags);
|
|
|
|
}
|
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const atVec3f& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<atVec3f>(name, help, value, flags);
|
|
|
|
}
|
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const atVec3d& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<atVec3d>(name, help, value, flags);
|
|
|
|
}
|
2018-12-07 21:18:42 -08:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const atVec4f& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<atVec4f>(name, help, value, flags);
|
|
|
|
}
|
2019-09-29 05:44:01 -07:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, const atVec4d& value, CVar::EFlags flags) {
|
|
|
|
return _newCVar<atVec4d>(name, help, value, flags);
|
|
|
|
}
|
2018-12-07 21:18:42 -08: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);
|
|
|
|
}
|
2019-09-29 05:44:01 -07:00
|
|
|
// Float and double are internally identical, all floating point values are stored as `double`
|
2018-12-07 21:18:42 -08:00
|
|
|
CVar* newCVar(std::string_view name, std::string_view help, float value, CVar::EFlags flags) {
|
2019-09-29 05:44:01 -07:00
|
|
|
return _newCVar<double>(name, help, static_cast<double>(value), flags);
|
2018-12-07 21:18:42 -08:00
|
|
|
}
|
2019-09-29 05:44:01 -07:00
|
|
|
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);
|
2018-12-07 21:18:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-09-29 05:44:01 -07:00
|
|
|
std::vector<CVar*> cvars(CVar::EFlags filter = CVar::EFlags::Any) const;
|
2018-12-07 21:18:42 -08:00
|
|
|
|
|
|
|
void deserialize(CVar* cvar);
|
|
|
|
void serialize();
|
|
|
|
|
|
|
|
static CVarManager* instance();
|
|
|
|
|
2019-09-29 05:44:01 -07:00
|
|
|
void proc();
|
|
|
|
|
2018-12-07 21:18:42 -08:00
|
|
|
void list(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 setDeveloperMode(bool v, bool setDeserialized = false);
|
2019-01-26 15:21:30 -08:00
|
|
|
void setCheatsEnabled(bool v, bool setDeserialized = false);
|
2018-12-07 21:18:42 -08:00
|
|
|
bool restartRequired() const;
|
|
|
|
|
|
|
|
void parseCommandLine(const std::vector<SystemString>& args);
|
2018-04-29 20:11:37 -07:00
|
|
|
|
2015-12-02 13:11:10 -08:00
|
|
|
private:
|
2018-12-07 21:18:42 -08:00
|
|
|
bool suppressDeveloper();
|
|
|
|
void restoreDeveloper(bool oldDeveloper);
|
2015-12-02 13:11:10 -08:00
|
|
|
|
2018-12-07 21:18:42 -08:00
|
|
|
std::unordered_map<std::string, std::unique_ptr<CVar>> m_cvars;
|
|
|
|
std::unordered_map<std::string, std::string> m_deferedCVars;
|
2015-12-02 13:11:10 -08:00
|
|
|
};
|
|
|
|
|
2018-12-07 21:18:42 -08:00
|
|
|
} // namespace hecl
|