diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index d41c96f85..fcab14d4b 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -362,9 +362,19 @@ struct Application { } void onAppWindowResized(const AuroraWindowSize& size) noexcept { + if (size.width != m_cvarCommons.getWindowSize().x || size.height != m_cvarCommons.getWindowSize().y) { + m_cvarCommons.m_windowSize->fromVec2i(zeus::CVector2i(size.width, size.height)); + } + CGraphics::SetViewportResolution({static_cast(size.fb_width), static_cast(size.fb_height)}); } + void onAppWindowMoved(const AuroraWindowPos& pos) { + if (pos.x > 0 && pos.y > 0 && (pos.x != m_cvarCommons.getWindowPos().x || pos.y != m_cvarCommons.getWindowPos().y)) { + m_cvarCommons.m_windowPos->fromVec2i(zeus::CVector2i(pos.x, pos.y)); + } + } + void onAppDisplayScaleChanged(float scale) noexcept { ImGuiEngine_Initialize(scale); } void onControllerAdded(uint32_t which) noexcept { m_imGuiConsole.ControllerAdded(which); } @@ -519,6 +529,8 @@ int main(int argc, char** argv) { g_app = std::make_unique(argc, argv, fileMgr, cvarMgr, cvarCmns); std::string configPath{fileMgr.getStoreRoot()}; + + const AuroraConfig config{ .appName = "Metaforce", .configPath = configPath.c_str(), @@ -526,6 +538,10 @@ int main(int argc, char** argv) { .msaa = cvarCmns.getSamples(), .maxTextureAnisotropy = static_cast(cvarCmns.getAnisotropy()), .startFullscreen = cvarCmns.getFullscreen(), + .windowPosX = cvarCmns.getWindowPos().x, + .windowPosY = cvarCmns.getWindowPos().y, + .windowWidth = static_cast(cvarCmns.getWindowSize().x < 0 ? 0 : cvarCmns.getWindowSize().x), + .windowHeight = static_cast(cvarCmns.getWindowSize().y < 0 ? 0 : cvarCmns.getWindowSize().y), .iconRGBA8 = icon.data.get(), .iconWidth = icon.width, .iconHeight = icon.height, @@ -551,6 +567,9 @@ int main(int argc, char** argv) { case AURORA_WINDOW_RESIZED: g_app->onAppWindowResized(event->windowSize); break; + case AURORA_WINDOW_MOVED: + g_app->onAppWindowMoved(event->windowPos); + break; case AURORA_CONTROLLER_ADDED: g_app->onControllerAdded(event->controller); break; diff --git a/Runtime/ConsoleVariables/CVar.cpp b/Runtime/ConsoleVariables/CVar.cpp index e59c458f0..701e3403b 100644 --- a/Runtime/ConsoleVariables/CVar.cpp +++ b/Runtime/ConsoleVariables/CVar.cpp @@ -20,6 +20,12 @@ CVar::CVar(std::string_view name, std::string_view value, std::string_view help, init(flags); } +CVar::CVar(std::string_view name, const zeus::CVector2i& value, std::string_view help, EFlags flags) +: CVar(name, help, EType::Vec2i) { + fromVec2i(value); + init(flags); +} + CVar::CVar(std::string_view name, const zeus::CVector2f& value, std::string_view help, EFlags flags) : CVar(name, help, EType::Vec2f) { fromVec2f(value); @@ -84,6 +90,23 @@ std::string CVar::help() const { return m_help + (m_defaultValue.empty() ? "" : "\ndefault: " + m_defaultValue) + (isReadOnly() ? " [ReadOnly]" : ""); } +zeus::CVector2i CVar::toVec2i(bool* isValid) const { + if (m_type != EType::Vec2i) { + if (isValid != nullptr) + *isValid = false; + + return {}; + } + + if (isValid != nullptr) + *isValid = true; + + std::array f; + std::sscanf(m_value.c_str(), "%i %i", &f[0], &f[1]); + return {f[0], f[1]}; +} + + zeus::CVector2f CVar::toVec2f(bool* isValid) const { if (m_type != EType::Vec2f) { if (isValid != nullptr) @@ -242,6 +265,15 @@ std::string CVar::toLiteral(bool* isValid) const { return m_value; } +bool CVar::fromVec2i(const zeus::CVector2i& val) { + if (!safeToModify(EType::Vec2i)) + return false; + + m_value.assign(fmt::format(FMT_STRING("{} {}"), val.x, val.y)); + m_flags |= EFlags::Modified; + return true; +} + bool CVar::fromVec2f(const zeus::CVector2f& val) { if (!safeToModify(EType::Vec2f)) return false; @@ -433,6 +465,20 @@ void CVar::dispatch() { } } +bool isInt(std::string_view v) { + char* p; + std::strtol(v.data(), &p, 10); + return p != nullptr && *p == 0; +} + +bool isInt(const std::vector& v) { + for (auto& s : v) { + if (!isInt(s)) + return false; + } + return true; +} + bool isReal(std::string_view v) { char* p; std::strtod(v.data(), &p); @@ -468,6 +514,8 @@ bool CVar::isValidInput(std::string_view input) const { } case EType::Literal: return true; + case EType::Vec2i: + return parts.size() == 2 && isInt(parts); case EType::Vec2f: case EType::Vec2d: return parts.size() == 2 && isReal(parts); diff --git a/Runtime/ConsoleVariables/CVar.hpp b/Runtime/ConsoleVariables/CVar.hpp index 9c2fb3b41..772392783 100644 --- a/Runtime/ConsoleVariables/CVar.hpp +++ b/Runtime/ConsoleVariables/CVar.hpp @@ -8,7 +8,7 @@ #include namespace metaforce { namespace StoreCVar { -enum class EType : uint32_t { Boolean, Signed, Unsigned, Real, Literal, Vec2f, Vec2d, Vec3f, Vec3d, Vec4f, Vec4d }; +enum class EType : uint32_t { Boolean, Signed, Unsigned, Real, Literal, Vec2i, Vec2f, Vec2d, Vec3f, Vec3d, Vec4f, Vec4d }; enum class EFlags { None = 0, System = (1 << 0), @@ -53,6 +53,7 @@ class CVar : protected StoreCVar::CVar { using EFlags = StoreCVar::EFlags; CVar(std::string_view name, std::string_view value, std::string_view help, EFlags flags); + CVar(std::string_view name, const zeus::CVector2i& value, std::string_view help, EFlags flags); CVar(std::string_view name, const zeus::CVector2f& value, std::string_view help, EFlags flags); CVar(std::string_view name, const zeus::CVector2d& value, std::string_view help, EFlags flags); CVar(std::string_view name, const zeus::CVector3f& value, std::string_view help, EFlags flags); @@ -72,6 +73,7 @@ class CVar : protected StoreCVar::CVar { template inline bool toValue(T& value) const; + zeus::CVector2i toVec2i(bool* isValid = nullptr) const; zeus::CVector2f toVec2f(bool* isValid = nullptr) const; zeus::CVector2d toVec2d(bool* isValid = nullptr) const; zeus::CVector3f toVec3f(bool* isValid = nullptr) const; @@ -88,6 +90,7 @@ class CVar : protected StoreCVar::CVar { inline bool fromValue(T value) { return false; } + bool fromVec2i(const zeus::CVector2i& val); bool fromVec2f(const zeus::CVector2f& val); bool fromVec2d(const zeus::CVector2d& val); bool fromVec3f(const zeus::CVector3f& val); @@ -101,6 +104,7 @@ class CVar : protected StoreCVar::CVar { bool fromLiteral(std::string_view val); bool fromLiteralToType(std::string_view val); + bool isVec2i() const { return m_type == EType::Vec2i; } bool isVec2f() const { return m_type == EType::Vec2f; } bool isVec2d() const { return m_type == EType::Vec2d; } bool isVec3f() const { return m_type == EType::Vec3f; } diff --git a/Runtime/ConsoleVariables/CVarCommons.cpp b/Runtime/ConsoleVariables/CVarCommons.cpp index 6dbfc3b3a..cbd631049 100644 --- a/Runtime/ConsoleVariables/CVarCommons.cpp +++ b/Runtime/ConsoleVariables/CVarCommons.cpp @@ -19,6 +19,10 @@ CVarCommons::CVarCommons(CVarManager& manager) : m_mgr(manager) { CVar::EFlags::System | CVar::EFlags::Archive | CVar::EFlags::ModifyRestart); m_variableDt = m_mgr.findOrMakeCVar("variableDt", "Enable variable delta time (experimental)", false, (CVar::EFlags::System | CVar::EFlags::Archive | CVar::EFlags::ModifyRestart)); + m_windowSize = m_mgr.findOrMakeCVar("windowSize", "Stores the last known window size", zeus::CVector2i(1280, 960), + (CVar::EFlags::System | CVar::EFlags::Archive)); + m_windowPos = m_mgr.findOrMakeCVar("windowPos", "Stores the last known window position", zeus::CVector2i(-1, -1), + (CVar::EFlags::System | CVar::EFlags::Archive)); m_debugOverlayPlayerInfo = m_mgr.findOrMakeCVar( "debugOverlay.playerInfo"sv, "Displays information about the player, such as location and orientation"sv, false, @@ -58,8 +62,8 @@ CVarCommons::CVarCommons(CVarManager& manager) : m_mgr(manager) { m_mgr.findOrMakeCVar("debugOverlay.drawCallInfo"sv, "Displays the current number of draw calls per frame"sv, false, CVar::EFlags::Game | CVar::EFlags::Archive | CVar::EFlags::ReadOnly); m_debugOverlayBufferInfo = - m_mgr.findOrMakeCVar("debugOverlay.bufferInfo"sv, "Displays the current buffer memory usage per frame"sv, - false, CVar::EFlags::Game | CVar::EFlags::Archive | CVar::EFlags::ReadOnly); + m_mgr.findOrMakeCVar("debugOverlay.bufferInfo"sv, "Displays the current buffer memory usage per frame"sv, false, + CVar::EFlags::Game | CVar::EFlags::Archive | CVar::EFlags::ReadOnly); m_debugOverlayShowInput = m_mgr.findOrMakeCVar("debugOverlay.showInput"sv, "Displays controller input"sv, false, CVar::EFlags::Game | CVar::EFlags::Archive | CVar::EFlags::ReadOnly); m_debugOverlayCorner = diff --git a/Runtime/ConsoleVariables/CVarCommons.hpp b/Runtime/ConsoleVariables/CVarCommons.hpp index 7a055b5a4..fa821d8b6 100644 --- a/Runtime/ConsoleVariables/CVarCommons.hpp +++ b/Runtime/ConsoleVariables/CVarCommons.hpp @@ -27,6 +27,8 @@ struct CVarCommons { CVar* m_texAnisotropy = nullptr; CVar* m_deepColor = nullptr; CVar* m_variableDt = nullptr; + CVar* m_windowSize = nullptr; + CVar* m_windowPos = nullptr; CVar* m_debugOverlayPlayerInfo = nullptr; CVar* m_debugOverlayWorldInfo = nullptr; @@ -68,6 +70,8 @@ struct CVarCommons { void setSamples(uint32_t v) { m_drawSamples->fromInteger(std::max(uint32_t(1), v)); } uint32_t getAnisotropy() const { return std::max(1u, uint32_t(m_texAnisotropy->toUnsigned())); } + zeus::CVector2i getWindowSize() const { return m_windowSize->toVec2i(); } + zeus::CVector2i getWindowPos() const { return m_windowPos->toVec2i(); } void setAnisotropy(uint32_t v) { m_texAnisotropy->fromInteger(std::max(1u, v)); } diff --git a/Runtime/ConsoleVariables/CVarManager.hpp b/Runtime/ConsoleVariables/CVarManager.hpp index bec4275c7..f13dad26c 100644 --- a/Runtime/ConsoleVariables/CVarManager.hpp +++ b/Runtime/ConsoleVariables/CVarManager.hpp @@ -37,6 +37,10 @@ class CVarManager final { CVarManager(FileStoreManager& store, bool useBinary = false); ~CVarManager(); + CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector2i& value, CVar::EFlags flags) { + return _newCVar(name, help, value, flags); + } + CVar* newCVar(std::string_view name, std::string_view help, const zeus::CVector2f& value, CVar::EFlags flags) { return _newCVar(name, help, value, flags); } diff --git a/extern/aurora b/extern/aurora index 23b9ccb2c..5589b24df 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit 23b9ccb2ccda123a19b060b73495b3ba4e55988f +Subproject commit 5589b24df6f59bba0df8191f9f1f81478269cd99