From 8679f6b5a36a360d50772002de5348bba9a775d1 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 25 May 2023 00:37:43 -0500 Subject: [PATCH] [nostalgia/core] Make core::setMainViewEnabled take a Context --- src/nostalgia/core/context.hpp | 2 ++ src/nostalgia/core/gfx.hpp | 6 ------ src/nostalgia/core/opengl/gfx_opengl.cpp | 14 +++++++------- src/nostalgia/studio/main.cpp | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 09831523d..2c158bc9c 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -15,6 +15,7 @@ #include "input.hpp" namespace nostalgia::core::gl { +void setMainViewEnabled(core::Context *ctx, bool enabled) noexcept; void drawMainView(core::Context*) noexcept; void setRenderSize(core::Context*, int width, int height) noexcept; geo::Size getRenderSize(core::Context*) noexcept; @@ -105,6 +106,7 @@ class Context: public keel::Context { unsigned spriteSize, unsigned flipX) noexcept; friend void hideSprite(Context *ctx, unsigned idx) noexcept; + friend void gl::setMainViewEnabled(core::Context *ctx, bool enabled) noexcept; friend void gl::drawMainView(core::Context*) noexcept; friend void gl::setRenderSize(core::Context*, int width, int height) noexcept; friend geo::Size gl::getRenderSize(core::Context*) noexcept; diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 9de4bf2eb..57423a4d1 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -18,12 +18,6 @@ namespace nostalgia::core { -namespace gl { - -void setMainViewEnabled(bool) noexcept; - -} - extern ox::Array charMap; class Drawer { diff --git a/src/nostalgia/core/opengl/gfx_opengl.cpp b/src/nostalgia/core/opengl/gfx_opengl.cpp index df8c7ada4..cc0ae5ec0 100644 --- a/src/nostalgia/core/opengl/gfx_opengl.cpp +++ b/src/nostalgia/core/opengl/gfx_opengl.cpp @@ -20,12 +20,6 @@ void ImGui_Impl_NewFrame() noexcept; namespace gl { -static bool mainViewEnabled = true; - -void setMainViewEnabled(bool enabled) noexcept { - mainViewEnabled = enabled; -} - } namespace renderer { @@ -73,6 +67,7 @@ struct GlImplData { glutils::GLProgram spriteShader; int64_t prevFpsCheckTime = 0; uint64_t draws = 0; + bool mainViewEnabled = true; ox::Array cbbs; SpriteBlockset spriteBlocks; ox::Array spriteStates; @@ -448,7 +443,7 @@ void draw(Context *ctx) noexcept { glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); // render - if (gl::mainViewEnabled) { + if (id->mainViewEnabled) { gl::drawMainView(ctx); } for (const auto cd : ctx->drawers) { @@ -557,6 +552,11 @@ void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) no namespace gl { +void setMainViewEnabled(core::Context *ctx, bool enabled) noexcept { + const auto id = ctx->rendererData(); + id->mainViewEnabled = enabled; +} + void drawMainView(core::Context *ctx) noexcept { const auto id = ctx->rendererData(); renderer::drawBackgrounds(ctx, id); diff --git a/src/nostalgia/studio/main.cpp b/src/nostalgia/studio/main.cpp index 19b194dc7..635242445 100644 --- a/src/nostalgia/studio/main.cpp +++ b/src/nostalgia/studio/main.cpp @@ -48,7 +48,7 @@ static ox::Error run(ox::UniquePtr fs) noexcept { core::setUpdateHandler(ctx.get(), updateHandler); core::setKeyEventHandler(ctx.get(), keyEventHandler); core::setConstantRefresh(ctx.get(), false); - core::gl::setMainViewEnabled(false); + core::gl::setMainViewEnabled(ctx.get(), false); studio::StudioContext studioCtx; core::setApplicationData(ctx.get(), &studioCtx); StudioUI ui(ctx.get());