[nostalgia/core] Add missing change for constant refresh option

This commit is contained in:
Gary Talent 2022-02-12 14:47:54 -06:00
parent 34221f086c
commit 142c78db0e
2 changed files with 21 additions and 9 deletions

View File

@ -20,6 +20,7 @@ class Context;
class Drawer { class Drawer {
public: public:
virtual ~Drawer() = default; virtual ~Drawer() = default;
virtual void draw(Context*) noexcept = 0; virtual void draw(Context*) noexcept = 0;
}; };
@ -28,15 +29,16 @@ class Context {
friend constexpr void setApplicationData(Context *ctx, void *applicationData) noexcept; friend constexpr void setApplicationData(Context *ctx, void *applicationData) noexcept;
template<typename T> template<typename T>
friend constexpr T *applicationData(Context *ctx) noexcept; friend constexpr T *applicationData(Context *ctx) noexcept;
friend constexpr void setConstantRefresh(Context *ctx, bool) noexcept;
friend bool bgStatus(Context *ctx, unsigned bg) noexcept; friend bool bgStatus(Context *ctx, unsigned bg) noexcept;
friend common::Size getScreenSize(Context *ctx) noexcept; friend common::Size getScreenSize(Context *ctx) noexcept;
friend int getScreenHeight(Context *ctx) noexcept; friend int getScreenHeight(Context *ctx) noexcept;
friend int getScreenWidth(Context *ctx) noexcept; friend int getScreenWidth(Context *ctx) noexcept;
friend ox::Error initGfx(Context *ctx) noexcept; friend ox::Error initGfx(Context *ctx) noexcept;
friend ox::Error loadBgTileSheet(Context *ctx, friend ox::Error loadBgTileSheet(Context *ctx,
int section, int section,
const ox::FileAddress &tilesheetPath, const ox::FileAddress &tilesheetPath,
const ox::FileAddress &palettePath) noexcept; const ox::FileAddress &palettePath) noexcept;
friend ox::Error run(Context *ctx) noexcept; friend ox::Error run(Context *ctx) noexcept;
friend ox::Error shutdown(Context *ctx) noexcept; friend ox::Error shutdown(Context *ctx) noexcept;
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept; friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept;
@ -50,10 +52,8 @@ class Context {
friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept; friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
friend void setClipboardText(Context *ctx, const ox::String &text) noexcept; friend void setClipboardText(Context *ctx, const ox::String &text) noexcept;
friend void setEventHandler(Context *ctx, event_handler h) 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 setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcept;
friend void setWindowTitle(Context *ctx, const char *title) noexcept; friend void setWindowTitle(Context *ctx, const char *title) noexcept;
friend void setWindowerData(Context *ctx, void *windowerData) noexcept;
public: public:
ox::UniquePtr<ox::FileSystem> rom; ox::UniquePtr<ox::FileSystem> rom;
@ -62,13 +62,17 @@ class Context {
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL
AssetManager assetManager; AssetManager assetManager;
#endif #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: private:
void *m_windowerData = nullptr; void *m_windowerData = nullptr;
void *m_rendererData = nullptr; void *m_rendererData = nullptr;
protected:
void *m_customData = nullptr;
public: public:
Context() noexcept = default; Context() noexcept = default;
@ -109,5 +113,11 @@ constexpr T *applicationData(Context *ctx) noexcept {
return static_cast<T*>(ctx->m_customData); return static_cast<T*>(ctx->m_customData);
} }
constexpr void setConstantRefresh([[maybe_unused]] Context *ctx, [[maybe_unused]] bool r) noexcept {
#ifndef OX_BARE_METAL
ctx->constantRefresh = r;
#endif
}
} }

View File

@ -48,7 +48,9 @@ ox::Error run(Context *ctx) noexcept {
} }
draw(ctx); draw(ctx);
glfwSwapBuffers(id->window); glfwSwapBuffers(id->window);
glfwWaitEventsTimeout(sleepTime); if (!ctx->constantRefresh) {
glfwWaitEventsTimeout(sleepTime);
}
} }
// destroy GLFW window // destroy GLFW window
renderer::shutdown(ctx, ctx->rendererData<void>()); renderer::shutdown(ctx, ctx->rendererData<void>());