diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index e4f03d86..cd842632 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -20,6 +20,7 @@ class Context; class Drawer { public: virtual ~Drawer() = default; + virtual void draw(Context*) noexcept = 0; }; @@ -28,15 +29,16 @@ class Context { friend constexpr void setApplicationData(Context *ctx, void *applicationData) noexcept; template friend constexpr T *applicationData(Context *ctx) noexcept; + friend constexpr void setConstantRefresh(Context *ctx, bool) noexcept; friend bool bgStatus(Context *ctx, unsigned bg) noexcept; friend common::Size getScreenSize(Context *ctx) noexcept; friend int getScreenHeight(Context *ctx) noexcept; friend int getScreenWidth(Context *ctx) noexcept; friend ox::Error initGfx(Context *ctx) noexcept; friend ox::Error loadBgTileSheet(Context *ctx, - int section, - const ox::FileAddress &tilesheetPath, - const ox::FileAddress &palettePath) noexcept; + int section, + const ox::FileAddress &tilesheetPath, + const ox::FileAddress &palettePath) noexcept; friend ox::Error run(Context *ctx) noexcept; friend ox::Error shutdown(Context *ctx) noexcept; friend ox::Result> init(ox::UniquePtr fs, const char *appName) noexcept; @@ -50,10 +52,8 @@ class Context { friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept; friend void setClipboardText(Context *ctx, const ox::String &text) noexcept; friend void setEventHandler(Context *ctx, event_handler h) noexcept; - friend void setRendererData(Context *ctx, void *rendererData) noexcept; friend void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcept; friend void setWindowTitle(Context *ctx, const char *title) noexcept; - friend void setWindowerData(Context *ctx, void *windowerData) noexcept; public: ox::UniquePtr rom; @@ -62,13 +62,17 @@ class Context { #ifndef OX_BARE_METAL AssetManager assetManager; #endif + protected: +#ifndef OX_BARE_METAL + // sets screen refresh to constant instead of only on event + bool constantRefresh = false; +#endif + void *m_customData = nullptr; + private: void *m_windowerData = nullptr; void *m_rendererData = nullptr; - protected: - void *m_customData = nullptr; - public: Context() noexcept = default; @@ -109,5 +113,11 @@ constexpr T *applicationData(Context *ctx) noexcept { return static_cast(ctx->m_customData); } +constexpr void setConstantRefresh([[maybe_unused]] Context *ctx, [[maybe_unused]] bool r) noexcept { +#ifndef OX_BARE_METAL + ctx->constantRefresh = r; +#endif +} + } diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index e3d33f48..6564ef8c 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -48,7 +48,9 @@ ox::Error run(Context *ctx) noexcept { } draw(ctx); glfwSwapBuffers(id->window); - glfwWaitEventsTimeout(sleepTime); + if (!ctx->constantRefresh) { + glfwWaitEventsTimeout(sleepTime); + } } // destroy GLFW window renderer::shutdown(ctx, ctx->rendererData());