diff --git a/src/olympic/studio/applib/src/main.cpp b/src/olympic/studio/applib/src/main.cpp index b38ec361..e0145492 100644 --- a/src/olympic/studio/applib/src/main.cpp +++ b/src/olympic/studio/applib/src/main.cpp @@ -31,7 +31,7 @@ class StudioUIDrawer: public turbine::gl::Drawer { static int updateHandler(turbine::Context &ctx) noexcept { auto sctx = turbine::applicationData(ctx); sctx->ui.update(); - return 16; + return 1000; } static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept { @@ -47,7 +47,7 @@ static ox::Error runApp( turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName); turbine::setUpdateHandler(*ctx, updateHandler); turbine::setKeyEventHandler(*ctx, keyEventHandler); - turbine::setConstantRefresh(*ctx, false); + turbine::setRefreshWithin(*ctx, 0); StudioUI ui(*ctx, projectDataDir); StudioUIDrawer drawer(ui); turbine::gl::addDrawer(*ctx, &drawer); @@ -68,7 +68,7 @@ static ox::Error run( static_cast(time << 1) }); // run app - auto const err = runApp(appName, projectDataDir, ox::UPtr(nullptr)); + auto const err = runApp(appName, projectDataDir, ox::UPtr{}); oxAssert(err, "Something went wrong..."); return err; } diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index 4fc92069..1c43eed2 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -212,7 +212,6 @@ void StudioUI::drawTabs() noexcept { } if (m_activeEditorOnLastDraw != e.get()) [[unlikely]] { m_activeEditor->onActivated(); - turbine::setConstantRefresh(m_ctx, m_activeEditor->requiresConstantRefresh()); } e->draw(m_sctx); m_activeEditorOnLastDraw = e.get(); diff --git a/src/olympic/turbine/include/turbine/gfx.hpp b/src/olympic/turbine/include/turbine/gfx.hpp index 0d2b135f..7e863cbb 100644 --- a/src/olympic/turbine/include/turbine/gfx.hpp +++ b/src/olympic/turbine/include/turbine/gfx.hpp @@ -43,6 +43,12 @@ ox::Bounds getWindowBounds(Context &ctx) noexcept; ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept; -void setConstantRefresh(Context &ctx, bool r) noexcept; +/** + * Tells Turbine to refresh the screen within the specified period of time. + * If the requested value is greater than the current value, the call has no effect. + * @param ctx - Context + * @param ms - milliseconds + */ +void setRefreshWithin(Context &ctx, int ms) noexcept; } diff --git a/src/olympic/turbine/src/glfw/context.hpp b/src/olympic/turbine/src/glfw/context.hpp index 6a08a7db..6a6cd1d6 100644 --- a/src/olympic/turbine/src/glfw/context.hpp +++ b/src/olympic/turbine/src/glfw/context.hpp @@ -22,8 +22,7 @@ class Context { int uninterruptedRefreshes = 3; ox::UPtr clipboard; struct GLFWwindow *window = nullptr; - // sets screen refresh to constant instead of only on event - bool constantRefresh = true; + int refreshWithinMs = 0; ox::Vector drawers; int64_t startTime = 0; uint64_t wakeupTime = 0; diff --git a/src/olympic/turbine/src/glfw/gfx.cpp b/src/olympic/turbine/src/glfw/gfx.cpp index e3883f26..9eeef906 100644 --- a/src/olympic/turbine/src/glfw/gfx.cpp +++ b/src/olympic/turbine/src/glfw/gfx.cpp @@ -260,8 +260,8 @@ ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept { return {}; } -void setConstantRefresh(Context &ctx, bool r) noexcept { - ctx.constantRefresh = r; +void setRefreshWithin(Context &ctx, int ms) noexcept { + ctx.refreshWithinMs = ox::min(ms, ctx.refreshWithinMs); } } diff --git a/src/olympic/turbine/src/glfw/turbine.cpp b/src/olympic/turbine/src/glfw/turbine.cpp index 7003e863..2865423c 100644 --- a/src/olympic/turbine/src/glfw/turbine.cpp +++ b/src/olympic/turbine/src/glfw/turbine.cpp @@ -69,6 +69,7 @@ static void tickFps(Context &ctx, uint64_t nowMs) noexcept { ox::Error run(Context &ctx) noexcept { int sleepTime = 0; while (!glfwWindowShouldClose(ctx.window)) { + ctx.refreshWithinMs = 10 * 1000; // refresh within 10 seconds glfwPollEvents(); auto const ticks = ticksMs(ctx); if (ctx.wakeupTime <= ticks) { @@ -79,15 +80,16 @@ ox::Error run(Context &ctx) noexcept { ctx.wakeupTime = ~uint64_t(0); } } else { - sleepTime = 10; + sleepTime = static_cast(ctx.wakeupTime - ticks); } tickFps(ctx, ticks); draw(ctx); - if (!ctx.constantRefresh) { + auto const realSleepTime = ox::min(ctx.refreshWithinMs, sleepTime); + if (realSleepTime) { if (ctx.uninterruptedRefreshes) { --ctx.uninterruptedRefreshes; } else { - glfwWaitEventsTimeout(sleepTime); + glfwWaitEventsTimeout(static_cast(realSleepTime) / 1000); } } }