diff --git a/hecl/extern/athena b/hecl/extern/athena index ec49377fc..de55c9acd 160000 --- a/hecl/extern/athena +++ b/hecl/extern/athena @@ -1 +1 @@ -Subproject commit ec49377fcd20748ae4490cd18afc9abefa11e7be +Subproject commit de55c9acdfebb4f05310b24a0a5b865bcbc811b9 diff --git a/hecl/include/hecl/CVar.hpp b/hecl/include/hecl/CVar.hpp index 37f5e4c7a..32a832342 100755 --- a/hecl/include/hecl/CVar.hpp +++ b/hecl/include/hecl/CVar.hpp @@ -9,97 +9,46 @@ namespace hecl { -namespace DNACVAR -{ -enum class EType : atUint8 -{ - Boolean, - Integer, - Float, - Literal, - Vec4f -}; - -enum EFlags -{ - System = (1 << 0), - Game = (1 << 1), - Editor = (1 << 2), - Gui = (1 << 3), - Cheat = (1 << 4), - Hidden = (1 << 5), - ReadOnly = (1 << 6), - Archive = (1 << 7), - InternalArchivable = (1 << 8), - Modified = (1 << 9), - ModifyRestart = (1 << 10) /*!< If this bit is set, any modification will inform the user that a restart is required */ -}; -ENABLE_BITWISE_ENUM(EFlags) - -class CVar : public athena::io::DNAYaml -{ -public: - DECL_YAML - String<-1> m_name; - String<-1> m_value; -}; - -struct CVarContainer : public athena::io::DNAYaml -{ - DECL_YAML - Value magic = 'CVAR'; - Value cvarCount; - Vector cvars; -}; - -} - -class CVarManager; -class CVar : protected DNACVAR::CVar +class CVar { friend class CVarManager; - Delete _d; - public: - typedef std::function ListenerFunc; + enum EFlags + { + System = (1 << 0), + Game = (1 << 1), + Editor = (1 << 2), + Gui = (1 << 3), + Cheat = (1 << 4), + Hidden = (1 << 5), + ReadOnly = (1 << 6), + Archive = (1 << 7), + InternalArchivable = (1 << 8), + Modified = (1 << 9), + ModifyRestart = (1 << 10) /*!< If this bit is set, any modification will inform the user that a restart is required */ + }; +protected: + std::string m_name; + std::string m_help; + EFlags m_flags; + EFlags m_oldFlags; + bool m_wasDeserialized = false; + bool m_unlocked = false; - using EType = DNACVAR::EType; - using EFlags = DNACVAR::EFlags; - - CVar(std::string_view name, std::string_view value, std::string_view help, EType type, EFlags flags, CVarManager& parent); - CVar(std::string_view name, std::string_view value, std::string_view help, EFlags flags, CVarManager& parent); - CVar(std::string_view name, float value, std::string_view help, EFlags flags, CVarManager& parent); - CVar(std::string_view name, bool value, std::string_view help, EFlags flags, CVarManager& parent); - CVar(std::string_view name, int value, std::string_view help, EFlags flags, CVarManager& parent); - CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags, CVarManager& parent); - - - std::string_view name() const { return m_name; } - std::string_view rawHelp() const { return m_help; } + virtual bool _fromString(std::string_view sv) = 0; +public: + CVar(std::string_view name, std::string_view help, EFlags flags); + virtual ~CVar() = default; + std::string name() const { return m_name; } std::string help() const; - std::string value() const { return m_value; } + std::string rawHelp() const { return m_help; } + virtual std::string toString() const=0; + bool fromString(std::string_view v); + virtual void deserialize(athena::io::YAMLDocReader& reader) = 0; + virtual void serialize(athena::io::YAMLDocWriter& writer) const = 0; + virtual bool hasDefaultValue() const = 0; + virtual std::string defaultValueString() const = 0; - atVec4f toVec4f(bool* isValid = nullptr) const; - float toFloat(bool* isValid = nullptr) const; - bool toBoolean(bool* isValid = nullptr) const; - int toInteger(bool* isValid = nullptr) const; - const std::wstring toWideLiteral(bool* isValid = nullptr) const; - const std::string toLiteral(bool* isValid = nullptr) const; - - bool fromVec4f(const atVec4f& val); - bool fromFloat(float val); - bool fromBoolean(bool val); - bool fromInteger(int val); - bool fromLiteral(std::string_view val); - bool fromLiteral(std::wstring_view val); - bool fromLiteralToType(std::string_view val, bool setDefault = false); - bool fromLiteralToType(std::wstring_view val, bool setDefault = false); - - bool isFloat() const { return m_type == EType::Float; } - bool isBoolean() const { return m_type == EType::Boolean; } - bool isInteger() const { return m_type == EType::Integer; } - bool isLiteral() const { return m_type == EType::Literal; } - bool isVec4f() const { return m_type == EType::Vec4f; } bool isModified() const; bool modificationRequiresRestart() const; bool isReadOnly() const; @@ -108,46 +57,36 @@ public: bool isArchive() const; bool isInternalArchivable() const; bool wasDeserialized() const; - bool hasDefaultValue() const; void clearModified(); void setModified(); - EType type() const { return m_type; } EFlags flags() const { return m_flags; } - - /*! - * \brief Unlocks the CVar for writing if it is ReadOnly. - * Handle with care!!! if you use unlock(), make sure - * you lock the cvar using lock() - * \see lock - */ void unlock(); - - /*! - * \brief Locks the CVar to prevent writing if it is ReadOnly. - * Unlike its partner function unlock, lock is harmless - * \see unlock - */ void lock(); - - void addListener(ListenerFunc func) { m_listeners.push_back(func); } - -private: - void dispatch(); - EType m_type; - std::string m_help; - std::string m_defaultValue; - EFlags m_flags; - EFlags m_oldFlags; - bool m_unlocked = false; - bool m_wasDeserialized = false; - - CVarManager& m_mgr; - - std::vector m_listeners; }; +ENABLE_BITWISE_ENUM(CVar::EFlags) +template +class TCVar : public CVar +{ +protected: + T& m_value; + T m_defaultValue; + bool _fromString(std::string_view sv); +public: + TCVar(T& value, std::string_view name, std::string_view help, EFlags flags); + + virtual std::string toString() const; + std::wstring toWideString() const; + virtual void deserialize(athena::io::YAMLDocReader& reader); + virtual void serialize(athena::io::YAMLDocWriter& writer) const; + virtual bool hasDefaultValue() const; + + T value() const; + T defaultValue() const; + std::string defaultValueString() const; +}; class CVarUnlocker { @@ -157,6 +96,102 @@ public: ~CVarUnlocker() { if (m_cvar) m_cvar->lock(); } }; +class Vec3fCVar : public CVar +{ + atVec3f& m_value; + atVec3f m_defaultValue; + bool _fromString(std::string_view v); +public: + Vec3fCVar(atVec3f& value, std::string_view name, std::string_view help, EFlags flags); + + std::string toString() const; + bool hasDefaultValue() const; + void deserialize(athena::io::YAMLDocReader& reader); + void serialize(athena::io::YAMLDocWriter& writer) const; + atVec3f value() const { return m_value; } + atVec3f defaultValue() const { return m_defaultValue; } + + std::string defaultValueString() const; +}; + +class Vec3dCVar : public CVar +{ + atVec3d& m_value; + atVec3d m_defaultValue; + bool _fromString(std::string_view v); +public: + Vec3dCVar(atVec3d& value, std::string_view name, std::string_view help, EFlags flags); + + std::string toString() const; + bool hasDefaultValue() const; + void deserialize(athena::io::YAMLDocReader& reader); + void serialize(athena::io::YAMLDocWriter& writer) const; + atVec3d value() const { return m_value; } + atVec3d defaultValue() const { return m_defaultValue; } + std::string defaultValueString() const; +}; + +class Vec4fCVar : public CVar +{ + atVec4f& m_value; + atVec4f m_defaultValue; + bool _fromString(std::string_view v); +public: + Vec4fCVar(atVec4f& value, std::string_view name, std::string_view help, EFlags flags); + virtual ~Vec4fCVar() = default; + + std::string toString() const; + bool hasDefaultValue() const; + void deserialize(athena::io::YAMLDocReader& reader); + void serialize(athena::io::YAMLDocWriter& writer) const; + atVec4f value() const { return m_value; } + atVec4f defaultValue() const { return m_defaultValue; } + std::string defaultValueString() const; +}; + +class Vec4dCVar : public CVar +{ + atVec4d& m_value; + atVec4d m_defaultValue; + bool _fromString(std::string_view v); +public: + Vec4dCVar(atVec4d& value, std::string_view name, std::string_view help, EFlags flags); + + std::string toString() const; + bool hasDefaultValue() const; + void deserialize(athena::io::YAMLDocReader& reader); + void serialize(athena::io::YAMLDocWriter& writer) const; + atVec4d value() const { return m_value; } + atVec4d defaultValue() const { return m_defaultValue; } + std::string defaultValueString() const; +}; + +class StringCVar : public CVar +{ + std::string& m_value; + std::string m_defaultValue; + bool _fromString(std::string_view v); +public: + StringCVar(std::string& value, std::string_view name, std::string_view help, EFlags flags); + + std::string toString() const; + bool hasDefaultValue() const; + void deserialize(athena::io::YAMLDocReader& reader); + void serialize(athena::io::YAMLDocWriter& writer) const; + const std::string& value() const { return m_value; } + const std::string& defaultValue() const { return m_defaultValue; } + std::string defaultValueString() const { return defaultValue(); } +}; + +using BoolCVar = TCVar; +using Int16CVar = TCVar; +using Uint16CVar = TCVar; +using Int32CVar = TCVar; +using Uint32CVar = TCVar; +using Int64CVar = TCVar; +using Uint64CVar = TCVar; +using FloatCVar = TCVar; +using DoubleCVar = TCVar; } #endif // CVAR_HPP diff --git a/hecl/include/hecl/CVarCommons.hpp b/hecl/include/hecl/CVarCommons.hpp index 0f29f2a42..bdaf0fa43 100644 --- a/hecl/include/hecl/CVarCommons.hpp +++ b/hecl/include/hecl/CVarCommons.hpp @@ -12,61 +12,61 @@ namespace hecl using namespace std::literals; #ifdef _WIN32 -#define DEFAULT_GRAPHICS_API "D3D11"sv +#define DEFAULT_GRAPHICS_API "D3D11" #elif defined(__APPLE__) -#define DEFAULT_GRAPHICS_API "Metal"sv +#define DEFAULT_GRAPHICS_API "Metal" #else -#define DEFAULT_GRAPHICS_API "OpenGL"sv +#define DEFAULT_GRAPHICS_API "OpenGL" #endif class CVarCommons { CVarManager& m_mgr; - CVar* m_graphicsApi; - CVar* m_drawSamples; - CVar* m_texAnisotropy; + std::string m_graphicsApi = DEFAULT_GRAPHICS_API; + uint32_t m_drawSamples = 1; + uint32_t m_texAnisotropy = 1; public: CVarCommons(CVarManager& manager) : m_mgr(manager) { - m_graphicsApi = m_mgr.findOrMakeCVar("graphicsApi"sv, + m_mgr.findOrMakeCVar("graphicsApi"sv, "API to use for rendering graphics"sv, - DEFAULT_GRAPHICS_API, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart); - m_drawSamples = m_mgr.findOrMakeCVar("drawSamples"sv, + m_graphicsApi, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart); + m_mgr.findOrMakeCVar("drawSamples"sv, "Number of MSAA samples to use for render targets"sv, - 1, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart); - m_texAnisotropy = m_mgr.findOrMakeCVar("texAnisotropy"sv, + m_drawSamples, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart); + m_mgr.findOrMakeCVar("texAnisotropy"sv, "Number of anisotropic samples to use for sampling textures"sv, - 1, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart); + m_texAnisotropy, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart); } std::string getGraphicsApi() const { - return m_graphicsApi->toLiteral(); + return m_graphicsApi; } void setGraphicsApi(std::string_view api) { - m_graphicsApi->fromLiteral(api); + m_graphicsApi = api; } uint32_t getSamples() const { - return uint32_t(std::max(1, m_drawSamples->toInteger())); + return std::max(uint32_t(1), m_drawSamples); } void setSamples(uint32_t v) { - m_drawSamples->fromInteger(std::max(uint32_t(1), v)); + m_drawSamples = std::max(uint32_t(1), v); } uint32_t getAnisotropy() const { - return uint32_t(std::max(1, m_texAnisotropy->toInteger())); + return std::max(uint32_t(1), m_texAnisotropy); } - void setAnisotropy(uint32_t v) const + void setAnisotropy(uint32_t v) { - m_texAnisotropy->fromInteger(std::max(uint32_t(1), v)); + m_texAnisotropy = std::max(uint32_t(1), v); } void serialize() diff --git a/hecl/include/hecl/CVarManager.hpp b/hecl/include/hecl/CVarManager.hpp index dc9ab3941..ab20acf94 100755 --- a/hecl/include/hecl/CVarManager.hpp +++ b/hecl/include/hecl/CVarManager.hpp @@ -7,20 +7,21 @@ namespace hecl { + +extern BoolCVar* com_developer; +extern StringCVar* com_configfile; +extern BoolCVar* com_enableCheats; + namespace Runtime { class FileStoreManager; } -extern CVar* com_developer; -extern CVar* com_configfile; -extern CVar* com_enableCheats; class CVarManager final { - using CVarContainer = DNACVAR::CVarContainer; template - 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, T& value, CVar::EFlags flags) { - CVar* ret(new CVar(name, value, help, flags, *this)); + TCVar* ret = new TCVar(value, name, help, flags); if (registerCVar(ret)) { deserialize(ret); @@ -31,7 +32,10 @@ class CVarManager final } hecl::Runtime::FileStoreManager& m_store; + std::string m_configFile = "config"; bool m_useBinary; + bool m_developerMode = false; + bool m_enableCheats = false; static CVarManager* m_instance; public: CVarManager() = delete; @@ -42,16 +46,34 @@ public: ~CVarManager(); void update(); - CVar* newCVar(std::string_view name, std::string_view help, const atVec4f& value, CVar::EFlags flags) - { return _newCVar(name, help, value, flags); } - CVar* newCVar(std::string_view name, std::string_view help, std::string_view value, CVar::EFlags flags) - { return _newCVar(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, atVec3f& value, CVar::EFlags flags) + { return new Vec3fCVar(value, name, help, flags); } + CVar* newCVar(std::string_view name, std::string_view help, atVec3d& value, CVar::EFlags flags) + { return new Vec3dCVar(value, name, help, flags); } + CVar* newCVar(std::string_view name, std::string_view help, atVec4f& value, CVar::EFlags flags) + { return new Vec4fCVar(value, name, help, flags); } + CVar* newCVar(std::string_view name, std::string_view help, atVec4d& value, CVar::EFlags flags) + { return new Vec4dCVar(value, name, help, flags); } + CVar* newCVar(std::string_view name, std::string_view help, std::string& value, CVar::EFlags flags) + { return new StringCVar(value, name, help, flags); } + CVar* newCVar(std::string_view name, std::string_view help, bool& value, CVar::EFlags flags) { return _newCVar(name, help, value, flags); } - 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(name, help, value, flags); } - CVar* newCVar(std::string_view name, std::string_view help, int value, CVar::EFlags flags) - { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, double& value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, int16_t& value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, uint16_t& value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, int32_t& value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, uint32_t& value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, int64_t& value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } + CVar* newCVar(std::string_view name, std::string_view help, uint64_t& value, CVar::EFlags flags) + { return _newCVar(name, help, value, flags); } bool registerCVar(CVar* cvar); diff --git a/hecl/include/hecl/Console.hpp b/hecl/include/hecl/Console.hpp index 8bed36598..f4c23d755 100644 --- a/hecl/include/hecl/Console.hpp +++ b/hecl/include/hecl/Console.hpp @@ -10,7 +10,7 @@ namespace hecl { -class CVar; +class CVarManager; struct SConsoleCommand { std::string m_displayName; @@ -60,6 +60,7 @@ public: }; private: + CVarManager* m_cvarMgr; std::unordered_map m_commands; std::vector> m_log; int m_logOffset; @@ -71,12 +72,10 @@ private: bool m_overwrite : 1; bool m_cursorAtEnd : 1; State m_state = State::Closed; - CVar* m_conSpeed; - CVar* m_conHeight; - float m_cachedConSpeed; - float m_cachedConHeight; + float m_conSpeed = 1.f; + float m_conHeight = 0.5f; public: - Console(class CVarManager*); + Console(CVarManager*); void registerCommand(std::string_view name, std::string_view helpText, std::string_view usage, const std::function&)>&& func); void executeString(const std::string& strToExec); @@ -88,6 +87,7 @@ public: void report(Level level, const char *fmt, va_list list); void report(Level level, const char* fmt, ...); + void init(); void proc(); void draw(boo::IGraphicsCommandQueue* gfxQ); void handleCharCode(unsigned long chr, boo::EModifierKey mod, bool repeat); diff --git a/hecl/lib/CVar.cpp b/hecl/lib/CVar.cpp index 9cf5c41b3..a52840e44 100755 --- a/hecl/lib/CVar.cpp +++ b/hecl/lib/CVar.cpp @@ -1,6 +1,5 @@ #include "hecl/hecl.hpp" #include "hecl/CVar.hpp" -#include "hecl/CVarManager.hpp" #include #include @@ -8,427 +7,40 @@ namespace hecl { -extern CVar* com_developer; -extern CVar* com_enableCheats; - using namespace std::literals; +extern BoolCVar* com_developer; +extern BoolCVar* com_enableCheats; -CVar::CVar(std::string_view name, std::string_view value, std::string_view help, EType type, EFlags flags, CVarManager& parent) - : m_mgr(parent) +CVar::CVar(std::string_view name, std::string_view help, CVar::EFlags flags) + : m_name(name) + , m_help(help) + , m_flags(flags) { - m_name = std::string(name); - m_value = std::string(value); - m_defaultValue = std::string(value); - m_help = help; - m_type = type; - m_flags = flags; -} - -CVar::CVar(std::string_view name, std::string_view value, std::string_view help, CVar::EFlags flags, CVarManager& parent) -: m_mgr(parent) -{ - m_flags = flags; - m_name = std::string(name); - m_help = help; - m_type = EType::Literal; - - // Unlock the cvar for writing if readonly - unlock(); - - fromLiteral(value); - m_defaultValue = m_value; - - // Lock the cvar - lock(); - // Clear the modified flag, just incase lock didn't do it. - m_flags = flags; -} - -CVar::CVar(std::string_view name, const atVec4f& value, std::string_view help, EFlags flags, CVarManager& parent) - : m_mgr(parent) -{ - m_name = std::string(name); - m_help = help; - m_type = EType::Vec4f; - m_flags = flags; - - // Unlock the cvar for writing if readonly - unlock(); - - fromVec4f(value); - m_defaultValue = m_value; - - // Lock the cvar - lock(); - // Clear the modified flag, just incase lock didn't do it. - m_flags = flags; -} - -CVar::CVar(std::string_view name, float value, std::string_view help, EFlags flags, CVarManager& parent) - : m_mgr(parent) -{ - m_name = std::string(name); - m_help = help; - m_type = EType::Float; - m_flags = flags; - - // Unlock the cvar for writing if readonly - unlock(); - - fromFloat(value); - m_defaultValue = m_value; - - // Lock the cvar - lock(); - // Clear the modified flag, just incase lock didn't do it. - m_flags = flags; -} - -CVar::CVar(std::string_view name, bool value, std::string_view help, CVar::EFlags flags, CVarManager& parent) - : m_mgr(parent) -{ - m_name = std::string(name); - m_help = help; - m_type = EType::Boolean; - m_flags = flags; - - // Unlock the cvar for writing if readonly - unlock(); - - fromBoolean(value); - m_defaultValue = m_value; - - // Lock the cvar - lock(); - // Clear the modified flag, just incase lock didn't do it. - m_flags = flags; -} - -CVar::CVar(std::string_view name, int value, std::string_view help, CVar::EFlags flags, CVarManager& parent) - : m_mgr(parent) -{ - m_name = std::string(name); - m_help = help; - m_type = EType::Integer; - m_flags = flags; - - // Unlock the cvar for writing if readonly - unlock(); - - fromInteger(value); - m_defaultValue = m_value; - - // Lock the cvar - lock(); - // Clear the modified flag, just incase lock didn't do it. - m_flags = flags; } std::string CVar::help() const { - return std::string(m_help + (m_defaultValue != std::string() ? "\ndefault: " + m_defaultValue : "") + - (isReadOnly() ? "[ReadOnly]" : "")); + return std::string(m_help + (hasDefaultValue() ? " (default: " + defaultValueString() : "") + + (isReadOnly() ? " [ReadOnly]" : "")) + ")"; } -atVec4f CVar::toVec4f(bool* isValid) const +bool CVar::fromString(std::string_view v) { - if (m_type != EType::Vec4f) - { - if (isValid != nullptr) - *isValid = false; - - return atVec4f{}; - } - - if (isValid != nullptr) - *isValid = true; - - atVec4f vec; - std::sscanf(m_value.c_str(), "%f %f %f %f", &vec.vec[0], &vec.vec[1], &vec.vec[2], &vec.vec[3]); - - return vec; -} - -float CVar::toFloat(bool* isValid) const -{ - if (m_type != EType::Float) - { - if (isValid) - *isValid = false; - return 0.0f; - } - - return strtof(m_value.c_str(), nullptr); -} - -bool CVar::toBoolean(bool* isValid) const -{ - if (m_type != EType::Boolean) - { - if (isValid) - *isValid = false; - - return false; - } - - // We don't want to modify the original value; - std::string tmp = m_value; - athena::utility::tolower(tmp); - - if (!tmp.compare("yes") || !tmp.compare("true") || !tmp.compare("1")) - { - if (isValid) - *isValid = true; - return true; - } - else if (!tmp.compare("no") || !tmp.compare("false") || !tmp.compare("0")) - { - if (isValid) - *isValid = true; - return false; - } - - if (isValid) - *isValid = false; - - return false; -} - -int CVar::toInteger(bool* isValid) const -{ - if (m_type != EType::Integer) - { - if (isValid) - *isValid = false; - return 0; - } - - return strtol(m_value.c_str(), nullptr, 0); -} - -const std::string CVar::toLiteral(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 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::fromVec4f(const atVec4f& val) -{ - if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) + if (isCheat() && (com_developer && !com_developer->value() && !com_enableCheats->value())) return false; else if (isCheat()) return false; - if (m_type != EType::Vec4f) + if (isReadOnly() && (com_developer && !com_developer->value())) return false; - if (isReadOnly() && (com_developer && !com_developer->toBoolean())) - return false; - - m_value.assign(hecl::Format("%f %f %f %f", val.vec[0], val.vec[1], val.vec[2], val.vec[3])); - m_flags |= EFlags::Modified; - return true; + bool ret = _fromString(v); + if (ret) + m_flags |= EFlags::Modified; + return ret; } -bool CVar::fromFloat(float val) -{ - if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) - return false; - else if (isCheat()) - return false; - - if (m_type != EType::Float) - return false; - - if (isReadOnly() && (com_developer && !com_developer->toBoolean())) - return false; - - m_value.assign(hecl::Format("%f", val)); - setModified(); - return true; -} - -bool CVar::fromBoolean(bool val) -{ - if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) - return false; - else if (isCheat()) - return false; - - if (m_type != EType::Boolean) - return false; - - if (isReadOnly() && (com_developer && !com_developer->toBoolean())) - return false; - - if (val) - m_value = "true"sv; - else - m_value = "false"sv; - - setModified(); - return true; -} - -bool CVar::fromInteger(int val) -{ - if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) - return false; - else if (isCheat()) - return false; - - if (m_type != EType::Integer) - return false; - - if (isReadOnly() && (com_developer && !com_developer->toBoolean())) - return false; - - m_value = hecl::Format("%i", val); - setModified(); - return true; -} - -bool CVar::fromLiteral(std::string_view val) -{ - if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) - return false; - else if (isCheat()) - return false; - - if (m_type != EType::Literal) - return false; - - if (isReadOnly() && (com_developer && !com_developer->toBoolean())) - return false; - - m_value.assign(val); - setModified(); - return true; -} - -bool CVar::fromLiteral(std::wstring_view val) -{ - if (isCheat() && (com_developer && !com_developer->toBoolean() && !com_enableCheats->toBoolean())) - return false; - else if (isCheat()) - 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::fromLiteralToType(std::string_view val, bool setDefault) -{ - switch (m_type) - { - case EType::Literal: return fromLiteral(val); - case EType::Boolean: - { - std::stringstream ss; - ss << std::boolalpha << val; - bool v; - ss >> v; - return fromBoolean(v); - } - case EType::Float: - { - std::stringstream ss; - ss << val; - float v; - ss >> v; - return fromFloat(v); - } - case EType::Integer: - { - std::stringstream ss; - ss << val; - int v; - ss >> v; - return fromInteger(v); - } - case EType::Vec4f: - { - atVec4f vec; - std::sscanf(val.data(), "%f %f %f %f", &vec.vec[0], &vec.vec[1], &vec.vec[2], &vec.vec[3]); - return fromVec4f(vec); - } - } - if (setDefault) - m_value = m_defaultValue; - return false; -} - -bool CVar::fromLiteralToType(std::wstring_view val, bool setDefault) -{ - switch (m_type) - { - case EType::Literal: return fromLiteral(val); - case EType::Boolean: - { - std::wstringstream ss; - ss << std::boolalpha << val; - bool v; - ss >> v; - return fromBoolean(v); - } - case EType::Float: - { - std::wstringstream ss; - ss << val; - float v; - ss >> v; - return fromFloat(v); - } - case EType::Integer: - { - std::wstringstream ss; - ss << val; - int v; - ss >> v; - return fromInteger(v); - } - case EType::Vec4f: - { - atVec4f vec; - std::swscanf(val.data(), L"%f %f %f %f", &vec.vec[0], &vec.vec[1], &vec.vec[2], &vec.vec[3]); - return fromVec4f(vec); - } - } - if (setDefault) - m_value = m_defaultValue; - return false; -} - -bool CVar::isModified() const { return int(m_flags & EFlags::Modified) != 0;} +bool CVar::isModified() const { return int(m_flags & EFlags::Modified) != 0; } bool CVar::modificationRequiresRestart() const { return int(m_flags & EFlags::ModifyRestart) != 0; } bool CVar::isReadOnly() const { return int(m_flags & EFlags::ReadOnly) != 0; } @@ -443,8 +55,6 @@ bool CVar::isInternalArchivable() const { return int(m_flags & EFlags::InternalA bool CVar::wasDeserialized() const { return m_wasDeserialized; } -bool CVar::hasDefaultValue() const { return m_defaultValue == m_value; } - void CVar::clearModified() { if (!modificationRequiresRestart()) @@ -472,10 +82,293 @@ void CVar::lock() } } -void CVar::dispatch() +template +TCVar::TCVar(T& value, std::string_view name, std::string_view description, EFlags flags) + : CVar(name, description, flags) + , m_value(value) + , m_defaultValue(value) { - for (const ListenerFunc& listen : m_listeners) - listen(this); -} +} + +template +std::string TCVar::toString() const +{ + std::stringstream ss; + ss << std::boolalpha << m_value; + return ss.str(); +} + +template +std::wstring TCVar::toWideString() const +{ + return hecl::UTF8ToWide(toString()); +} + +template +bool TCVar::_fromString(std::string_view v) +{ + T tmp; + std::stringstream ss; + ss << std::boolalpha << v; + ss >> tmp; + if (ss.good()) + m_value = tmp; + + return ss.good(); +} + +template +void TCVar::deserialize(athena::io::YAMLDocReader &reader) +{ + m_value = reader.readVal(m_name.c_str()); +} + +template +void TCVar::serialize(athena::io::YAMLDocWriter& writer) const +{ + writer.writeVal(m_name.c_str(), m_value); +} + +template +bool TCVar::hasDefaultValue() const +{ + return m_value == m_defaultValue; +} + + +template +T TCVar::value() const +{ + return m_value; +} + +template +T TCVar::defaultValue() const +{ + return m_defaultValue; +} + +template +std::string TCVar::defaultValueString() const +{ + std::stringstream ss; + ss << std::boolalpha << m_defaultValue; + return ss.str(); +} + +Vec3fCVar::Vec3fCVar(atVec3f &value, std::string_view name, std::string_view description, CVar::EFlags flags) + : CVar(name, description, flags) + , m_value(value) + , m_defaultValue(value) +{} + +std::string Vec3fCVar::toString() const +{ + return athena::utility::sprintf("%f %f %f", double(m_value.vec[0]), double(m_value.vec[1]), double(m_value.vec[2])); +} + +bool Vec3fCVar::_fromString(std::string_view v) +{ + float x, y, z; + if (std::sscanf(v.data(), "%f %f %f", &x, &y, &z) != 3) + return false; + m_value.vec[0] = x; + m_value.vec[1] = y; + m_value.vec[2] = y; + return true; +} + +bool Vec3fCVar::hasDefaultValue() const +{ + return !memcmp(&m_value.vec, &m_defaultValue.vec[0], sizeof(atVec3f)); +} + +void Vec3fCVar::deserialize(athena::io::YAMLDocReader& reader) +{ + m_value = reader.readVec3f(m_name.c_str()); +} + +void Vec3fCVar::serialize(athena::io::YAMLDocWriter& writer) const +{ + writer.writeVec3f(m_name.c_str(), m_value); +} + +std::string Vec3fCVar::defaultValueString() const +{ + return athena::utility::sprintf("%f %f %f", double(m_defaultValue.vec[0]), double(m_defaultValue.vec[1]), double(m_defaultValue.vec[2])); +} + +Vec3dCVar::Vec3dCVar(atVec3d &value, std::string_view name, std::string_view description, CVar::EFlags flags) + : CVar(name, description, flags) + , m_value(value) + , m_defaultValue(value) +{} + +std::string Vec3dCVar::toString() const +{ + return athena::utility::sprintf("%lf %lf %lf", m_value.vec[0], m_value.vec[1], m_value.vec[2]); +} + +bool Vec3dCVar::_fromString(std::string_view v) +{ + double x, y, z; + if (std::sscanf(v.data(), "%lf %lf %lf", &x, &y, &z) != 3) + return false; + m_value.vec[0] = x; + m_value.vec[1] = y; + m_value.vec[2] = y; + return true; +} + +bool Vec3dCVar::hasDefaultValue() const +{ + return !memcmp(&m_value.vec, &m_defaultValue.vec[0], sizeof(atVec3d)); +} + +void Vec3dCVar::deserialize(athena::io::YAMLDocReader& reader) +{ + m_value = reader.readVec3d(m_name.c_str()); +} + +void Vec3dCVar::serialize(athena::io::YAMLDocWriter& writer) const +{ + writer.writeVec3d(m_name.c_str(), m_value); +} + +std::string Vec3dCVar::defaultValueString() const +{ + return athena::utility::sprintf("%g %g %g", m_defaultValue.vec[0], m_defaultValue.vec[1], m_defaultValue.vec[2]); +} + +Vec4fCVar::Vec4fCVar(atVec4f &value, std::string_view name, std::string_view description, CVar::EFlags flags) + : CVar(name, description, flags) + , m_value(value) + , m_defaultValue(value) +{} + +std::string Vec4fCVar::toString() const +{ + return athena::utility::sprintf("%g %g %g %g", &m_value.vec[0], &m_value.vec[1], &m_value.vec[2], &m_value.vec[3]); +} + +bool Vec4fCVar::_fromString(std::string_view v) +{ + float x, y, z, w; + if (std::sscanf(v.data(), "%f %f %f %f", &x, &y, &z, &w) != 4) + return false; + m_value.vec[0] = x; + m_value.vec[1] = y; + m_value.vec[2] = y; + m_value.vec[3] = w; + return true; +} + +bool Vec4fCVar::hasDefaultValue() const +{ + return !memcmp(&m_value.vec, &m_defaultValue.vec[0], sizeof(atVec4f)); +} + +void Vec4fCVar::deserialize(athena::io::YAMLDocReader& reader) +{ + m_value = reader.readVec4f(m_name.c_str()); +} + +void Vec4fCVar::serialize(athena::io::YAMLDocWriter& writer) const +{ + writer.writeVec4f(m_name.c_str(), m_value); +} + +std::string Vec4fCVar::defaultValueString() const +{ + return athena::utility::sprintf("%f %f %f", &m_defaultValue.vec[0], &m_defaultValue.vec[1], &m_defaultValue.vec[2]); +} + +Vec4dCVar::Vec4dCVar(atVec4d &value, std::string_view name, std::string_view description, CVar::EFlags flags) +: CVar(name, description, flags) +, m_value(value) +, m_defaultValue(value) +{} + +std::string Vec4dCVar::toString() const +{ + return athena::utility::sprintf("%f %f %f %f", m_value.vec[0], m_value.vec[1], m_value.vec[2], m_value.vec[3]); +} + +bool Vec4dCVar::_fromString(std::string_view v) +{ + double x, y, z, w; + if (std::sscanf(v.data(), "%lf %lf %lf %lf", &x, &y, &z, &w) != 4) + return false; + m_value.vec[0] = x; + m_value.vec[1] = y; + m_value.vec[2] = y; + m_value.vec[3] = w; + return true; +} + +bool Vec4dCVar::hasDefaultValue() const +{ + return !memcmp(&m_value.vec, &m_defaultValue.vec[0], sizeof(atVec4d)); +} + +void Vec4dCVar::deserialize(athena::io::YAMLDocReader& reader) +{ + m_value = reader.readVec4d(m_name.c_str()); +} + +void Vec4dCVar::serialize(athena::io::YAMLDocWriter& writer) const +{ + writer.writeVec4d(m_name.c_str(), m_value); +} + +std::string Vec4dCVar::defaultValueString() const +{ + return athena::utility::sprintf("%g %g %g", m_defaultValue.vec[0], m_defaultValue.vec[1], m_defaultValue.vec[2]); +} + +StringCVar::StringCVar(std::string& value, std::string_view name, std::string_view help, CVar::EFlags flags) +: CVar(name, help, flags) +, m_value(value) +, m_defaultValue(value) +{ +} + +std::string StringCVar::toString() const +{ + return m_value; +} + +bool StringCVar::_fromString(std::string_view v) +{ + m_value = v; + return true; +} + +bool StringCVar::hasDefaultValue() const +{ + return m_value == m_defaultValue; +} + +void StringCVar::deserialize(athena::io::YAMLDocReader& reader) +{ + m_value = reader.readString(m_name.c_str()); +} + +void StringCVar::serialize(athena::io::YAMLDocWriter& writer) const +{ + writer.writeString(m_name.c_str(), m_value.c_str()); +} + + +template class TCVar; +template class TCVar; +template class TCVar; +template class TCVar; +template class TCVar; +template class TCVar; +template class TCVar; +template class TCVar; +template class TCVar; + } diff --git a/hecl/lib/CVarManager.cpp b/hecl/lib/CVarManager.cpp index 630f3556d..28cd98ba5 100755 --- a/hecl/lib/CVarManager.cpp +++ b/hecl/lib/CVarManager.cpp @@ -9,9 +9,10 @@ namespace hecl { -CVar* com_developer = nullptr; -CVar* com_configfile = nullptr; -CVar* com_enableCheats = nullptr; +BoolCVar* com_developer = nullptr; +StringCVar* com_configfile = nullptr; +BoolCVar* com_enableCheats = nullptr; + CVarManager* CVarManager::m_instance = nullptr; @@ -21,9 +22,9 @@ CVarManager::CVarManager(hecl::Runtime::FileStoreManager& store, bool useBinary) m_useBinary(useBinary) { m_instance = this; - 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::ReadOnly | CVar::EFlags::InternalArchivable)); - com_enableCheats = newCVar("iamaweiner", "Enable cheats", false, (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::Hidden)); + com_configfile = dynamic_cast(findOrMakeCVar("config", "File to store configuration", m_configFile, CVar::EFlags::System)); + com_developer = dynamic_cast(findOrMakeCVar("developer", "Enables developer mode", m_developerMode, (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::InternalArchivable))); + com_enableCheats = dynamic_cast(findOrMakeCVar("iamaweiner", "Enable cheats", m_enableCheats, (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::Hidden))); } CVarManager::~CVarManager() @@ -35,7 +36,6 @@ void CVarManager::update() for (const std::pair& pair : m_cvars) if (pair.second->isModified()) { - pair.second->dispatch(); pair.second->clearModified(); } } @@ -86,88 +86,53 @@ void CVarManager::deserialize(CVar* cvar) if (!cvar || (!cvar->isArchive() && !cvar->isInternalArchivable())) return; - CVarContainer container; #if _WIN32 - hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toWideLiteral(); + hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + hecl::UTF8ToWide(m_configFile); #else - hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toLiteral(); + hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + m_configFile; #endif hecl::Sstat st; - if (m_useBinary) + filename += _S(".yaml"); + if (hecl::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode)) + return; + athena::io::FileReader reader(filename); + if (reader.isOpen()) { - filename += _S(".bin"); - if (hecl::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode)) - return; - athena::io::FileReader reader(filename); - if (reader.isOpen()) - container.read(reader); - } - else - { - filename += _S(".yaml"); - if (hecl::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode)) - return; - athena::io::FileReader reader(filename); - if (reader.isOpen()) - container.fromYAMLStream(reader); - } - - - 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()) + athena::io::YAMLDocReader doc; + doc.parse(&reader); + if (doc.hasVal(cvar->name().c_str())) { - DNACVAR::CVar& tmp = *serialized; - - if (cvar->m_value != tmp.m_value) - { - cvar->unlock(); - cvar->fromLiteralToType(tmp.m_value, true); - cvar->m_wasDeserialized = true; - cvar->lock(); - } + cvar->unlock(); + cvar->deserialize(doc); + cvar->m_wasDeserialized = true;; + cvar->lock(); } } } void CVarManager::serialize() { - CVarContainer container; - for (const std::pair& pair : m_cvars) - if (pair.second->isArchive() || (pair.second->isInternalArchivable() && pair.second->wasDeserialized() && !pair.second->hasDefaultValue())) - { - CVar tmp = *pair.second; - container.cvars.push_back(tmp); - } - - container.cvarCount = atUint32(container.cvars.size()); #if _WIN32 - hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toWideLiteral(); + hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + hecl::UTF8ToWide(m_configFile); #else - hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toLiteral(); + hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + m_configFile; #endif - if (m_useBinary) + filename += _S(".yaml"); + athena::io::FileWriter writer(filename); + if (writer.isOpen()) { - filename += _S(".bin"); - athena::io::FileWriter writer(filename); - if (writer.isOpen()) - container.write(writer); - } - else - { - filename += _S(".yaml"); - athena::io::FileWriter writer(filename); - if (writer.isOpen()) - container.toYAMLStream(writer); + athena::io::YAMLDocWriter doc(nullptr); + for (const std::pair& pair : m_cvars) + if (pair.second->isArchive() || (pair.second->isInternalArchivable() && pair.second->wasDeserialized() && !pair.second->hasDefaultValue())) + pair.second->serialize(doc); + doc.finish(&writer); } } + CVarManager* CVarManager::instance() { return m_instance; @@ -204,8 +169,9 @@ void CVarManager::setCVar(Console* con, const std::vector &args) for (; it != args.end(); ++it) value += " " + *it; - if (!cv->fromLiteralToType(value)) + if (!cv->fromString(value)) con->report(Console::Level::Warning, "Unable to cvar '%s' to value '%s'", args[0].c_str(), value.c_str()); + } void CVarManager::getCVar(Console* con, const std::vector &args) @@ -225,7 +191,7 @@ void CVarManager::getCVar(Console* con, const std::vector &args) } const CVar* cv = m_cvars[cvName]; - con->report(Console::Level::Info, "'%s' = '%s'", cv->name().data(), cv->value().c_str()); + con->report(Console::Level::Info, "'%s' = '%s'", cv->name().data(), cv->toString().c_str()); } bool CVarManager::restartRequired() const @@ -241,17 +207,15 @@ bool CVarManager::restartRequired() const bool CVarManager::suppressDeveloper() { - bool oldDeveloper = com_developer->toBoolean(); - CVarUnlocker unlock(com_developer); - com_developer->fromBoolean(false); - + bool oldDeveloper = m_developerMode; + m_developerMode = false; return oldDeveloper; + } void CVarManager::restoreDeveloper(bool oldDeveloper) { - CVarUnlocker unlock(com_developer); - com_developer->fromBoolean(oldDeveloper); + m_developerMode = oldDeveloper; } } diff --git a/hecl/lib/Console.cpp b/hecl/lib/Console.cpp index 1979d8a24..422b16c4c 100644 --- a/hecl/lib/Console.cpp +++ b/hecl/lib/Console.cpp @@ -7,19 +7,10 @@ namespace hecl { Console* Console::m_instance = nullptr; Console::Console(CVarManager* cvarMgr) - : m_overwrite(false) + : m_cvarMgr(cvarMgr) + , m_overwrite(false) , m_cursorAtEnd(false) { - m_instance = this; - registerCommand("help", "Prints information about a given function", "", std::bind(&Console::help, this, std::placeholders::_1, std::placeholders::_2)); - registerCommand("listCommands", "Prints a list of all available Commands", "", std::bind(&Console::listCommands, this, std::placeholders::_1, std::placeholders::_2)); - registerCommand("listCVars", "Lists all available CVars", "", std::bind(&CVarManager::list, cvarMgr, std::placeholders::_1, std::placeholders::_2)); - registerCommand("setCVar", "Sets a given Console Variable to the specified value", " ", std::bind(&CVarManager::setCVar, cvarMgr, std::placeholders::_1, std::placeholders::_2)); - registerCommand("getCVar", "Prints the value stored in the specified Console Variable", "", std::bind(&CVarManager::getCVar, cvarMgr, std::placeholders::_1, std::placeholders::_2)); - m_conSpeed = cvarMgr->findOrMakeCVar("con_speed", "Speed at which the console opens and closes, calculated as pixels per second", 1.f, - hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive); - m_conHeight = cvarMgr->findOrMakeCVar("con_height", "Maximum absolute height of the console, height is calculated from the top of the window, expects values ranged from [0.f,1.f]", 0.5f, - hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive); } void Console::registerCommand(std::string_view name, std::string_view helpText, std::string_view usage, const std::function &)>&& func) @@ -112,20 +103,22 @@ void Console::report(Level level, const char* fmt, ...) va_end(ap); } +void Console::init() +{ + m_instance = this; + registerCommand("help", "Prints information about a given function", "", std::bind(&Console::help, this, std::placeholders::_1, std::placeholders::_2)); + registerCommand("listCommands", "Prints a list of all available Commands", "", std::bind(&Console::listCommands, this, std::placeholders::_1, std::placeholders::_2)); + registerCommand("listCVars", "Lists all available CVars", "", std::bind(&CVarManager::list, m_cvarMgr, std::placeholders::_1, std::placeholders::_2)); + registerCommand("setCVar", "Sets a given Console Variable to the specified value", " ", std::bind(&CVarManager::setCVar, m_cvarMgr, std::placeholders::_1, std::placeholders::_2)); + registerCommand("getCVar", "Prints the value stored in the specified Console Variable", "", std::bind(&CVarManager::getCVar, m_cvarMgr, std::placeholders::_1, std::placeholders::_2)); + m_cvarMgr->findOrMakeCVar("con_speed", "Speed at which the console opens and closes, calculated as pixels per second", m_conSpeed, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive); + m_cvarMgr->findOrMakeCVar("con_height", "Maximum absolute height of the console, height is calculated from the top of the window, expects values ranged from [0.f,1.f]", m_conHeight, + hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive); +} + void Console::proc() { - if (m_conHeight->isModified()) - { - m_cachedConHeight = m_conHeight->toFloat(); - m_conHeight->clearModified(); - } - - if (m_conSpeed->isModified()) - { - m_cachedConSpeed = m_conSpeed->toFloat(); - m_conSpeed->clearModified(); - } - if (m_state == State::Opened) { printf("\r%s ", m_commandString.c_str()); diff --git a/hecl/test/main.cpp b/hecl/test/main.cpp index 3fc9cd3c2..563639a0b 100644 --- a/hecl/test/main.cpp +++ b/hecl/test/main.cpp @@ -62,13 +62,14 @@ struct HECLApplicationCallback : boo::IApplicationCallback m_cvarManager(m_fileStoreMgr), m_console(&m_cvarManager) { - m_console.registerCommand("quit"sv, "Quits application"sv, "", std::bind(&HECLApplicationCallback::quit, this, std::placeholders::_1, std::placeholders::_2)); } virtual ~HECLApplicationCallback(); int appMain(boo::IApplication* app) { + m_console.init(); + m_console.registerCommand("quit"sv, "Quits application"sv, "", std::bind(&HECLApplicationCallback::quit, this, std::placeholders::_1, std::placeholders::_2)); hecl::VerbosityLevel = 2; /* Setup boo window */ @@ -101,6 +102,18 @@ struct HECLApplicationCallback : boo::IApplicationCallback } } vuboData; + /* Make ramp texture */ + using Pixel = uint8_t[4]; + static Pixel tex[256][256]; + for (int i=0 ; i<256 ; ++i) + for (int j=0 ; j<256 ; ++j) + { + tex[i][j][0] = uint8_t(i); + tex[i][j][1] = uint8_t(i); + tex[i][j][2] = 0; + tex[i][j][3] = 0xff; + } + std::mutex initmt; std::condition_variable initcv; std::mutex loadmt; @@ -166,17 +179,6 @@ struct HECLApplicationCallback : boo::IApplicationCallback /* Construct quad mesh against boo factory */ hecl::Runtime::HMDLData testData(ctx, testMetaBuf, quad, ibo); - /* Make ramp texture */ - using Pixel = uint8_t[4]; - static Pixel tex[256][256]; - for (int i=0 ; i<256 ; ++i) - for (int j=0 ; j<256 ; ++j) - { - tex[i][j][0] = uint8_t(i); - tex[i][j][1] = uint8_t(i); - tex[i][j][2] = 0; - tex[i][j][3] = 0xff; - } boo::ObjToken texture = ctx.newStaticTexture(256, 256, 1, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat, tex, 256*256*4).get();