Squashed 'deps/nostalgia/' changes from 430cae16..5e90f8d4

5e90f8d4 [studio] Move task runner to draw call
fd4619bc [studio,turbine] Fix Turbine sleep logic, tweak Studio default sleep values
128ddb2c [turbine/gba] Fix ticksMs function signature
f34704d8 [nostalgia/core/studio] Fix AddSubsheetCommand::undo to undo ID idx change
fb5d3545 [nostalgia/core/studio] Cleanup
2180f7bf [nostalgia/core] Fix validateSubSheetIdx
dcad4440 [keel] Make GBA AssetRef changeable

git-subtree-dir: deps/nostalgia
git-subtree-split: 5e90f8d45434fa36b6e113357cf05a6cf53bfae5
This commit is contained in:
2024-06-02 11:33:36 -05:00
parent a0d6019480
commit fc2dec6438
13 changed files with 48 additions and 51 deletions

View File

@@ -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;
}

View File

@@ -71,7 +71,7 @@ ox::Result<ContextUPtr> init(
void shutdown(Context&) noexcept {
}
uint64_t ticksMs(Context&) noexcept {
uint64_t ticksMs(Context const&) noexcept {
return g_timerMs;
}

View File

@@ -22,8 +22,7 @@ class Context {
int uninterruptedRefreshes = 3;
ox::UPtr<BaseClipboardObject> clipboard;
struct GLFWwindow *window = nullptr;
// sets screen refresh to constant instead of only on event
bool constantRefresh = true;
int refreshWithinMs = 0;
ox::Vector<gl::Drawer*, 5> drawers;
int64_t startTime = 0;
uint64_t wakeupTime = 0;

View File

@@ -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);
}
}

View File

@@ -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<int>(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<double>(realSleepTime) / 1000);
}
}
}