[studio,turbine] Fix Turbine sleep logic, tweak Studio default sleep values
All checks were successful
Build / build (push) Successful in 2m34s
All checks were successful
Build / build (push) Successful in 2m34s
This commit is contained in:
parent
128ddb2ca6
commit
fd4619bc25
@ -31,7 +31,7 @@ class StudioUIDrawer: public turbine::gl::Drawer {
|
|||||||
static int updateHandler(turbine::Context &ctx) noexcept {
|
static int updateHandler(turbine::Context &ctx) noexcept {
|
||||||
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
||||||
sctx->ui.update();
|
sctx->ui.update();
|
||||||
return 16;
|
return 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept {
|
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::setWindowTitle(*ctx, keelCtx(*ctx).appName);
|
||||||
turbine::setUpdateHandler(*ctx, updateHandler);
|
turbine::setUpdateHandler(*ctx, updateHandler);
|
||||||
turbine::setKeyEventHandler(*ctx, keyEventHandler);
|
turbine::setKeyEventHandler(*ctx, keyEventHandler);
|
||||||
turbine::setConstantRefresh(*ctx, false);
|
turbine::setRefreshWithin(*ctx, 0);
|
||||||
StudioUI ui(*ctx, projectDataDir);
|
StudioUI ui(*ctx, projectDataDir);
|
||||||
StudioUIDrawer drawer(ui);
|
StudioUIDrawer drawer(ui);
|
||||||
turbine::gl::addDrawer(*ctx, &drawer);
|
turbine::gl::addDrawer(*ctx, &drawer);
|
||||||
@ -68,7 +68,7 @@ static ox::Error run(
|
|||||||
static_cast<uint64_t>(time << 1)
|
static_cast<uint64_t>(time << 1)
|
||||||
});
|
});
|
||||||
// run app
|
// run app
|
||||||
auto const err = runApp(appName, projectDataDir, ox::UPtr<ox::FileSystem>(nullptr));
|
auto const err = runApp(appName, projectDataDir, ox::UPtr<ox::FileSystem>{});
|
||||||
oxAssert(err, "Something went wrong...");
|
oxAssert(err, "Something went wrong...");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,6 @@ void StudioUI::drawTabs() noexcept {
|
|||||||
}
|
}
|
||||||
if (m_activeEditorOnLastDraw != e.get()) [[unlikely]] {
|
if (m_activeEditorOnLastDraw != e.get()) [[unlikely]] {
|
||||||
m_activeEditor->onActivated();
|
m_activeEditor->onActivated();
|
||||||
turbine::setConstantRefresh(m_ctx, m_activeEditor->requiresConstantRefresh());
|
|
||||||
}
|
}
|
||||||
e->draw(m_sctx);
|
e->draw(m_sctx);
|
||||||
m_activeEditorOnLastDraw = e.get();
|
m_activeEditorOnLastDraw = e.get();
|
||||||
|
@ -43,6 +43,12 @@ ox::Bounds getWindowBounds(Context &ctx) noexcept;
|
|||||||
|
|
||||||
ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,7 @@ class Context {
|
|||||||
int uninterruptedRefreshes = 3;
|
int uninterruptedRefreshes = 3;
|
||||||
ox::UPtr<BaseClipboardObject> clipboard;
|
ox::UPtr<BaseClipboardObject> clipboard;
|
||||||
struct GLFWwindow *window = nullptr;
|
struct GLFWwindow *window = nullptr;
|
||||||
// sets screen refresh to constant instead of only on event
|
int refreshWithinMs = 0;
|
||||||
bool constantRefresh = true;
|
|
||||||
ox::Vector<gl::Drawer*, 5> drawers;
|
ox::Vector<gl::Drawer*, 5> drawers;
|
||||||
int64_t startTime = 0;
|
int64_t startTime = 0;
|
||||||
uint64_t wakeupTime = 0;
|
uint64_t wakeupTime = 0;
|
||||||
|
@ -260,8 +260,8 @@ ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void setConstantRefresh(Context &ctx, bool r) noexcept {
|
void setRefreshWithin(Context &ctx, int ms) noexcept {
|
||||||
ctx.constantRefresh = r;
|
ctx.refreshWithinMs = ox::min(ms, ctx.refreshWithinMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ static void tickFps(Context &ctx, uint64_t nowMs) noexcept {
|
|||||||
ox::Error run(Context &ctx) noexcept {
|
ox::Error run(Context &ctx) noexcept {
|
||||||
int sleepTime = 0;
|
int sleepTime = 0;
|
||||||
while (!glfwWindowShouldClose(ctx.window)) {
|
while (!glfwWindowShouldClose(ctx.window)) {
|
||||||
|
ctx.refreshWithinMs = 10 * 1000; // refresh within 10 seconds
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
auto const ticks = ticksMs(ctx);
|
auto const ticks = ticksMs(ctx);
|
||||||
if (ctx.wakeupTime <= ticks) {
|
if (ctx.wakeupTime <= ticks) {
|
||||||
@ -79,15 +80,16 @@ ox::Error run(Context &ctx) noexcept {
|
|||||||
ctx.wakeupTime = ~uint64_t(0);
|
ctx.wakeupTime = ~uint64_t(0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sleepTime = 10;
|
sleepTime = static_cast<int>(ctx.wakeupTime - ticks);
|
||||||
}
|
}
|
||||||
tickFps(ctx, ticks);
|
tickFps(ctx, ticks);
|
||||||
draw(ctx);
|
draw(ctx);
|
||||||
if (!ctx.constantRefresh) {
|
auto const realSleepTime = ox::min(ctx.refreshWithinMs, sleepTime);
|
||||||
|
if (realSleepTime) {
|
||||||
if (ctx.uninterruptedRefreshes) {
|
if (ctx.uninterruptedRefreshes) {
|
||||||
--ctx.uninterruptedRefreshes;
|
--ctx.uninterruptedRefreshes;
|
||||||
} else {
|
} else {
|
||||||
glfwWaitEventsTimeout(sleepTime);
|
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user