Compare commits

...

4 Commits

Author SHA1 Message Date
ff05d860c4 [turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd
Some checks failed
Build / build (push) Has been cancelled
2024-12-10 01:49:20 -06:00
7679403742 [turbine] Add init wrapper that takes FS path 2024-12-06 23:20:30 -06:00
c51a45e1ba [olympic] Cleanup 2024-12-06 00:22:33 -06:00
a6e24ff2b6 [ox/std] Add CString type alias 2024-12-06 00:20:03 -06:00
10 changed files with 32 additions and 12 deletions

View File

@ -61,6 +61,8 @@ using uint_t = unsigned;
namespace ox {
using CString = char const*;
/**
* Aliases type T in size and alignment to allow allocating space for a T
* without running the constructor.

View File

@ -45,7 +45,7 @@ ox::Error run(
ox::StringView project,
ox::StringView appName,
ox::StringView projectDataDir,
ox::SpanView<char const*> argv) noexcept;
ox::SpanView<ox::CString> argv) noexcept;
namespace OLYMPIC_PROJECT_NAMESPACE {
void registerKeelModules() noexcept;

View File

@ -101,6 +101,6 @@ ox::Error run(
[[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView appName,
ox::StringView projectDataDir,
ox::SpanView<char const*> argv) noexcept {
ox::SpanView<ox::CString> argv) noexcept {
return ::run(argv, projectDataDir);
}

View File

@ -71,6 +71,6 @@ ox::Error run(
ox::StringView project,
ox::StringView appName,
ox::StringView projectDataDir,
ox::SpanView<char const*> args) noexcept {
ox::SpanView<ox::CString> args) noexcept {
return studio::run(ox::sfmt("{} {}", project, appName), projectDataDir, args);
}

View File

@ -18,6 +18,8 @@ using TimeMs = uint64_t;
ox::Result<ContextUPtr> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept;
ox::Result<ContextUPtr> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept;
ox::Error run(Context &ctx) noexcept;
// Returns the number of milliseconds that have passed since the start of the

View File

@ -18,6 +18,11 @@ target_include_directories(
../include
)
target_sources(
Turbine PUBLIC
turbine.cpp
)
target_link_libraries(
Turbine PUBLIC
Keel

View File

@ -20,7 +20,7 @@ class Context {
ox::AnyPtr applicationData;
// GLFW impl data ////////////////////////////////////////////////////////
int uninterruptedRefreshes = 3;
TimeMs mandatoryRefreshPeriodEnd{};
ox::UPtr<BaseClipboardObject> clipboard;
struct GLFWwindow *window = nullptr;
int refreshWithinMs = 0;

View File

@ -72,14 +72,16 @@ static void handleKeyPress(Context &ctx, int key, bool down) noexcept {
static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
}
static constexpr TimeMs MandatoryRefreshPeriod = 168;
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 25;
ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod;
}
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 25;
ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod;
if (action == GLFW_PRESS) {
handleKeyPress(*ctx, key, true);
} else if (action == GLFW_RELEASE) {

View File

@ -88,14 +88,10 @@ ox::Error run(Context &ctx) noexcept {
tickFps(ctx, ticks);
draw(ctx);
auto const realSleepTime = ox::min(static_cast<uint64_t>(ctx.refreshWithinMs), sleepTime);
if (realSleepTime) {
if (ctx.uninterruptedRefreshes) {
--ctx.uninterruptedRefreshes;
} else {
if (realSleepTime && ctx.mandatoryRefreshPeriodEnd >= ticks) {
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
}
}
}
shutdown(ctx);
return {};
}

View File

@ -0,0 +1,13 @@
#include <keel/keel.hpp>
#include <turbine/turbine.hpp>
namespace turbine {
ox::Result<ContextUPtr> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept {
oxRequireM(fs, keel::loadRomFs(fsPath));
return init(std::move(fs), appName);
}
}