Make window size and position persistent

This commit is contained in:
Phillip Stephens 2023-10-27 14:32:36 -07:00
parent c0e405cd55
commit a6392ab822
7 changed files with 87 additions and 4 deletions

View File

@ -362,9 +362,19 @@ public:
}
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<s32>(size.fb_width), static_cast<s32>(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<metaforce::Application>(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<uint16_t>(cvarCmns.getAnisotropy()),
.startFullscreen = cvarCmns.getFullscreen(),
.windowPosX = cvarCmns.getWindowPos().x,
.windowPosY = cvarCmns.getWindowPos().y,
.windowWidth = static_cast<uint>(cvarCmns.getWindowSize().x < 0 ? 0 : cvarCmns.getWindowSize().x),
.windowHeight = static_cast<uint>(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;

View File

@ -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<int, 2> 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<std::string>& 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);

View File

@ -8,7 +8,7 @@
#include <vector>
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 @@ public:
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 @@ public:
template <typename T>
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 @@ public:
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 @@ public:
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; }

View File

@ -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 =

View File

@ -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)); }

View File

@ -37,6 +37,10 @@ public:
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<const zeus::CVector2i>(name, help, value, flags);
}
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);
}

2
extern/aurora vendored

@ -1 +1 @@
Subproject commit 23b9ccb2ccda123a19b060b73495b3ba4e55988f
Subproject commit 5589b24df6f59bba0df8191f9f1f81478269cd99