[keel,nostalgia,studio,turbine] Make turbine::Context have a keel::Context instead of being one
This commit is contained in:
@ -40,7 +40,7 @@ class ClipboardObject: public BaseClipboardObject {
|
||||
void shutdown(Context &ctx) noexcept;
|
||||
|
||||
// User Input Output
|
||||
class Context: public keel::Context {
|
||||
class Context {
|
||||
friend constexpr void setApplicationData(Context &ctx, void *applicationData) noexcept;
|
||||
template<typename T>
|
||||
friend constexpr T *applicationData(Context &ctx) noexcept;
|
||||
@ -51,24 +51,33 @@ class Context: public keel::Context {
|
||||
public:
|
||||
UpdateHandler updateHandler = [](Context&) -> int {return 0;};
|
||||
ox::UPtr<BaseClipboardObject> clipboard;
|
||||
keel::Context keelCtx;
|
||||
|
||||
protected:
|
||||
KeyEventHandler m_keyEventHandler = nullptr;
|
||||
void *m_applicationData = nullptr;
|
||||
|
||||
public:
|
||||
Context() noexcept = default;
|
||||
|
||||
Context(Context &other) noexcept = delete;
|
||||
Context(const Context &other) noexcept = delete;
|
||||
Context(const Context &&other) noexcept = delete;
|
||||
|
||||
public:
|
||||
inline ~Context() noexcept {
|
||||
shutdown(*this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
constexpr auto *rom(Context &ctx) noexcept {
|
||||
return ctx.keelCtx.rom.get();
|
||||
}
|
||||
|
||||
constexpr const auto *rom(const Context &ctx) noexcept {
|
||||
return ctx.keelCtx.rom.get();
|
||||
}
|
||||
|
||||
constexpr void setApplicationData(Context &ctx, void *applicationData) noexcept {
|
||||
ctx.m_applicationData = applicationData;
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
if(TURBINE_BUILD_TYPE STREQUAL "GBA")
|
||||
enable_language(CXX ASM)
|
||||
endif()
|
||||
|
||||
add_library(Turbine-GBA OBJECT)
|
||||
target_sources(
|
||||
Turbine-GBA PRIVATE
|
||||
@ -13,6 +9,7 @@ target_sources(
|
||||
)
|
||||
|
||||
if(TURBINE_BUILD_TYPE STREQUAL "GBA")
|
||||
enable_language(ASM)
|
||||
set_source_files_properties(turbine.arm.cpp irq.arm.cpp PROPERTIES COMPILE_FLAGS -marm)
|
||||
target_sources(
|
||||
Turbine-GBA PRIVATE
|
||||
|
@ -39,4 +39,12 @@ ox::Size getScreenSize(Context&) noexcept {
|
||||
return {240, 160};
|
||||
}
|
||||
|
||||
ox::Bounds getWindowBounds(Context&) noexcept {
|
||||
return {0, 0, 240, 160};
|
||||
}
|
||||
|
||||
ox::Error setWindowBounds(Context&, const ox::Bounds&) noexcept {
|
||||
return OxError(1, "setWindowBounds not supported on GBA");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,9 +55,10 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
|
||||
}
|
||||
|
||||
ox::Result<ox::UniquePtr<turbine::Context>> init(ox::UPtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
|
||||
oxRequireM(ctx, keel::init<gba::Context>(std::move(fs), appName));
|
||||
auto ctx = ox::make_unique<gba::Context>();
|
||||
oxReturnError(keel::init(&ctx->keelCtx, std::move(fs), appName));
|
||||
#ifdef OX_BARE_METAL
|
||||
oxReturnError(findPreloadSection().moveTo(&ctx->preloadSectionOffset));
|
||||
oxReturnError(findPreloadSection().moveTo(&ctx->keelCtx.preloadSectionOffset));
|
||||
#endif
|
||||
oxReturnError(initGfx(*ctx));
|
||||
initTimer();
|
||||
|
@ -39,4 +39,8 @@ int getScreenHeight(Context &ctx) noexcept;
|
||||
[[nodiscard]]
|
||||
ox::Size getScreenSize(Context &ctx) noexcept;
|
||||
|
||||
ox::Bounds getWindowBounds(Context &ctx) noexcept;
|
||||
|
||||
ox::Error setWindowBounds(Context &ctx, const ox::Bounds &bnds) noexcept;
|
||||
|
||||
}
|
||||
|
@ -214,8 +214,8 @@ ox::Error initGfx(Context &ctx) noexcept {
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
}
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
auto cstr = ox_malloca(ctx.appName.bytes() + 1, char);
|
||||
ox_strncpy(cstr.get(), ctx.appName.data(), ctx.appName.bytes());
|
||||
auto cstr = ox_malloca(ctx.keelCtx.appName.bytes() + 1, char);
|
||||
ox_strncpy(cstr.get(), ctx.keelCtx.appName.data(), ctx.keelCtx.appName.bytes());
|
||||
gctx.window = glfwCreateWindow(240 * Scale, 160 * Scale, cstr, nullptr, nullptr);
|
||||
if (gctx.window == nullptr) {
|
||||
return OxError(1, "Could not open GLFW window");
|
||||
@ -275,6 +275,21 @@ ox::Size getScreenSize(Context &ctx) noexcept {
|
||||
return {w, h};
|
||||
}
|
||||
|
||||
ox::Bounds getWindowBounds(Context &ctx) noexcept {
|
||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
||||
ox::Bounds bnds;
|
||||
glfwGetWindowPos(gctx.window, &bnds.x, &bnds.y);
|
||||
glfwGetWindowSize(gctx.window, &bnds.width, &bnds.height);
|
||||
return bnds;
|
||||
}
|
||||
|
||||
ox::Error setWindowBounds(Context &ctx, const ox::Bounds &bnds) noexcept {
|
||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
||||
glfwSetWindowPos(gctx.window, bnds.x, bnds.y);
|
||||
glfwSetWindowSize(gctx.window, bnds.width, bnds.height);
|
||||
return {};
|
||||
}
|
||||
|
||||
void setConstantRefresh(Context &ctx, bool r) noexcept {
|
||||
auto &gctx = static_cast<GlfwContext&>(ctx);
|
||||
gctx.constantRefresh = r;
|
||||
|
@ -15,7 +15,8 @@
|
||||
namespace turbine {
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> fs, ox::CRStringView appName) noexcept {
|
||||
oxRequireM(ctx, keel::init<GlfwContext>(std::move(fs), appName));
|
||||
auto ctx = ox::make_unique<GlfwContext>();
|
||||
oxReturnError(keel::init(&ctx->keelCtx, std::move(fs), appName));
|
||||
using namespace std::chrono;
|
||||
ctx->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
|
||||
glfwInit();
|
||||
|
Reference in New Issue
Block a user