Merge commit '2da3579818c8cbb50ad4b346f5fbc9e5304e682f'
This commit is contained in:
@ -39,7 +39,7 @@ ox::Result<T> readConfig(keel::Context &ctx, ox::CRStringView name) noexcept {
|
||||
ox::PassThroughFS fs(configPath(ctx));
|
||||
auto const [buff, err] = fs.read(path);
|
||||
if (err) {
|
||||
oxErrf("Could not read config file: {}\n", toStr(err));
|
||||
//oxErrf("Could not read config file: {} - {}\n", path, toStr(err));
|
||||
return err;
|
||||
}
|
||||
return ox::readOC<T>(buff);
|
||||
@ -57,13 +57,13 @@ ox::Error writeConfig(keel::Context &ctx, ox::CRStringView name, T const&data) n
|
||||
auto const path = ox::sfmt("/{}.json", detail::slashesToPct(name));
|
||||
ox::PassThroughFS fs(configPath(ctx));
|
||||
if (auto const err = fs.mkdir("/", true)) {
|
||||
oxErrf("Could not create config directory: {}\n", toStr(err));
|
||||
//oxErrf("Could not create config directory: {} - {}\n", path, toStr(err));
|
||||
return err;
|
||||
}
|
||||
oxRequireM(buff, ox::writeOC(data));
|
||||
*buff.back().value = '\n';
|
||||
if (auto const err = fs.write(path, buff.data(), buff.size())) {
|
||||
oxErrf("Could not read config file: {}\n", toStr(err));
|
||||
//oxErrf("Could not read config file: {} - {}\n", path, toStr(err));
|
||||
return OxError(2, "Could not read config file");
|
||||
}
|
||||
return {};
|
||||
|
@ -14,7 +14,7 @@ namespace turbine {
|
||||
|
||||
class Context {
|
||||
public:
|
||||
UpdateHandler updateHandler = [](Context&) -> int {return 0;};
|
||||
UpdateHandler updateHandler = [](Context&) -> int {return -1;};
|
||||
keel::Context keelCtx;
|
||||
KeyEventHandler keyEventHandler = nullptr;
|
||||
ox::AnyPtr applicationData;
|
||||
|
@ -68,24 +68,26 @@ static void tickFps(Context &ctx, uint64_t nowMs) noexcept {
|
||||
}
|
||||
|
||||
ox::Error run(Context &ctx) noexcept {
|
||||
int sleepTime = 0;
|
||||
uint64_t sleepTime = 0;
|
||||
while (!glfwWindowShouldClose(ctx.window)) {
|
||||
ctx.refreshWithinMs = 10 * 1000; // refresh within 10 seconds
|
||||
glfwPollEvents();
|
||||
auto const ticks = ticksMs(ctx);
|
||||
if (ctx.wakeupTime <= ticks) {
|
||||
sleepTime = ctx.updateHandler(ctx);
|
||||
if (sleepTime >= 0) {
|
||||
ctx.wakeupTime = ticks + static_cast<unsigned>(sleepTime);
|
||||
auto const st = ctx.updateHandler(ctx);
|
||||
if (st >= 0) {
|
||||
ctx.wakeupTime = ticks + static_cast<unsigned>(st);
|
||||
sleepTime = static_cast<uint64_t>(st);
|
||||
} else {
|
||||
ctx.wakeupTime = ~uint64_t(0);
|
||||
sleepTime = ctx.wakeupTime - ticks;
|
||||
}
|
||||
} else {
|
||||
sleepTime = static_cast<int>(ctx.wakeupTime - ticks);
|
||||
sleepTime = ctx.wakeupTime - ticks;
|
||||
}
|
||||
tickFps(ctx, ticks);
|
||||
draw(ctx);
|
||||
auto const realSleepTime = ox::min(ctx.refreshWithinMs, sleepTime);
|
||||
auto const realSleepTime = ox::min(static_cast<uint64_t>(ctx.refreshWithinMs), sleepTime);
|
||||
if (realSleepTime) {
|
||||
if (ctx.uninterruptedRefreshes) {
|
||||
--ctx.uninterruptedRefreshes;
|
||||
|
Reference in New Issue
Block a user