[keel,nostalgia,studio,turbine] Make turbine::Context have a keel::Context instead of being one
This commit is contained in:
parent
d4eaade326
commit
c5233e0d1d
@ -2,6 +2,7 @@
|
||||
add_library(
|
||||
Keel
|
||||
asset.cpp
|
||||
keel.cpp
|
||||
media.cpp
|
||||
module.cpp
|
||||
pack.cpp
|
||||
|
31
src/keel/keel.cpp
Normal file
31
src/keel/keel.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "keel.hpp"
|
||||
|
||||
namespace keel {
|
||||
|
||||
ox::Error init(
|
||||
keel::Context *ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::CRStringView appName) noexcept {
|
||||
ctx->appName = appName;
|
||||
oxIgnoreError(setRomFs(ctx, std::move(fs)));
|
||||
#ifndef OX_BARE_METAL
|
||||
const auto &mods = modules();
|
||||
for (auto &mod : mods) {
|
||||
// register type converters
|
||||
for (auto c : mod->converters()) {
|
||||
ctx->converters.emplace_back(c);
|
||||
}
|
||||
// register pack transforms
|
||||
for (auto c : mod->packTransforms()) {
|
||||
ctx->packTransforms.emplace_back(c);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@ -14,24 +14,15 @@
|
||||
|
||||
namespace keel {
|
||||
|
||||
ox::Error init(
|
||||
keel::Context *ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::CRStringView appName) noexcept;
|
||||
|
||||
template<typename Ctx = keel::Context>
|
||||
ox::Result<ox::UPtr<Ctx>> init(ox::UPtr<ox::FileSystem> &&fs, ox::CRStringView appName) noexcept {
|
||||
auto ctx = ox::make_unique<Ctx>();
|
||||
ctx->appName = appName;
|
||||
oxIgnoreError(setRomFs(ctx.get(), std::move(fs)));
|
||||
#ifndef OX_BARE_METAL
|
||||
const auto &mods = modules();
|
||||
for (auto &mod : mods) {
|
||||
// register type converters
|
||||
for (auto c : mod->converters()) {
|
||||
ctx->converters.emplace_back(c);
|
||||
}
|
||||
// register pack transforms
|
||||
for (auto c : mod->packTransforms()) {
|
||||
ctx->packTransforms.emplace_back(c);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
oxReturnError(keel::init(ctx.get(), std::move(fs), appName));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ struct GbaContext: public core::Context {
|
||||
|
||||
[[nodiscard]]
|
||||
const auto &rom() const noexcept {
|
||||
return *turbineCtx->rom;
|
||||
return *turbine::rom(*turbineCtx);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -133,18 +133,20 @@ static ox::Error loadBgTileSheet(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error loadBgTileSheet(Context *ctx,
|
||||
unsigned cbb,
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
ox::Error loadBgTileSheet(
|
||||
Context *ctx,
|
||||
unsigned cbb,
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
|
||||
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
|
||||
}
|
||||
|
||||
ox::Error loadSpriteTileSheet(Context *ctx,
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context *ctx,
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
||||
oxRequire(ts, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(tilesheetAddr));
|
||||
|
@ -76,7 +76,6 @@ static constexpr auto bgVertexRow(unsigned x, unsigned y) noexcept {
|
||||
}
|
||||
|
||||
static void setSpriteBufferObject(
|
||||
Context*,
|
||||
unsigned vi,
|
||||
float enabled,
|
||||
float x,
|
||||
@ -110,7 +109,6 @@ static void setSpriteBufferObject(
|
||||
}
|
||||
|
||||
static void setTileBufferObject(
|
||||
Context*,
|
||||
unsigned vi,
|
||||
float x,
|
||||
float y,
|
||||
@ -139,22 +137,21 @@ static void setTileBufferObject(
|
||||
memcpy(ebo, elms.data(), sizeof(elms));
|
||||
}
|
||||
|
||||
static void initSpriteBufferObjects(Context *ctx, glutils::BufferSet *bs) noexcept {
|
||||
static void initSpriteBufferObjects(glutils::BufferSet *bs) noexcept {
|
||||
for (auto i = 0u; i < SpriteCount; ++i) {
|
||||
auto vbo = &bs->vertices[i * static_cast<std::size_t>(SpriteVertexVboLength)];
|
||||
auto ebo = &bs->elements[i * static_cast<std::size_t>(SpriteVertexEboLength)];
|
||||
setSpriteBufferObject(ctx, i * SpriteVertexVboRows, 0, 0, 0, 0, false, vbo, ebo);
|
||||
setSpriteBufferObject(i * SpriteVertexVboRows, 0, 0, 0, 0, false, vbo, ebo);
|
||||
}
|
||||
}
|
||||
|
||||
static void initBackgroundBufferObjects(Context *ctx, glutils::BufferSet *bg) noexcept {
|
||||
static void initBackgroundBufferObjects(glutils::BufferSet *bg) noexcept {
|
||||
for (auto x = 0u; x < TileColumns; ++x) {
|
||||
for (auto y = 0u; y < TileRows; ++y) {
|
||||
const auto i = bgVertexRow(x, y);
|
||||
auto vbo = &bg->vertices[i * static_cast<std::size_t>(BgVertexVboLength)];
|
||||
auto ebo = &bg->elements[i * static_cast<std::size_t>(BgVertexEboLength)];
|
||||
setTileBufferObject(
|
||||
ctx,
|
||||
static_cast<unsigned>(i * BgVertexVboRows),
|
||||
static_cast<float>(x),
|
||||
static_cast<float>(y),
|
||||
@ -165,15 +162,14 @@ static void initBackgroundBufferObjects(Context *ctx, glutils::BufferSet *bg) no
|
||||
}
|
||||
}
|
||||
|
||||
static void initSpritesBufferset(
|
||||
Context *ctx, GLuint shader, glutils::BufferSet *bs) noexcept {
|
||||
static void initSpritesBufferset(GLuint shader, glutils::BufferSet *bs) noexcept {
|
||||
// vao
|
||||
bs->vao = glutils::generateVertexArrayObject();
|
||||
glBindVertexArray(bs->vao);
|
||||
// vbo & ebo
|
||||
bs->vbo = glutils::generateBuffer();
|
||||
bs->ebo = glutils::generateBuffer();
|
||||
initSpriteBufferObjects(ctx, bs);
|
||||
initSpriteBufferObjects(bs);
|
||||
glutils::sendVbo(*bs);
|
||||
glutils::sendEbo(*bs);
|
||||
// vbo layout
|
||||
@ -191,7 +187,6 @@ static void initSpritesBufferset(
|
||||
}
|
||||
|
||||
static void initBackgroundBufferset(
|
||||
Context *ctx,
|
||||
GLuint shader,
|
||||
glutils::BufferSet *bg) noexcept {
|
||||
// vao
|
||||
@ -200,7 +195,7 @@ static void initBackgroundBufferset(
|
||||
// vbo & ebo
|
||||
bg->vbo = glutils::generateBuffer();
|
||||
bg->ebo = glutils::generateBuffer();
|
||||
initBackgroundBufferObjects(ctx, bg);
|
||||
initBackgroundBufferObjects(bg);
|
||||
glutils::sendVbo(*bg);
|
||||
glutils::sendEbo(*bg);
|
||||
// vbo layout
|
||||
@ -349,11 +344,11 @@ ox::Error initGfx(
|
||||
oxReturnError(
|
||||
glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx.spriteShader));
|
||||
for (auto &bg : gctx.cbbs) {
|
||||
initBackgroundBufferset(ctx, gctx.bgShader, &bg);
|
||||
initBackgroundBufferset(gctx.bgShader, &bg);
|
||||
}
|
||||
if (initParams.glInstallDrawer) {
|
||||
turbine::gl::addDrawer(gctx.turbineCtx, &gctx.drawer);
|
||||
initSpritesBufferset(ctx, gctx.spriteShader, &gctx.spriteBlocks);
|
||||
initSpritesBufferset(gctx.spriteShader, &gctx.spriteBlocks);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@ -399,7 +394,7 @@ ox::Error loadBgTileSheet(
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto &kctx = gctx.turbineCtx;
|
||||
auto &kctx = gctx.turbineCtx.keelCtx;
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||
@ -413,7 +408,7 @@ ox::Error loadSpriteTileSheet(
|
||||
const ox::FileAddress &tilesheetAddr,
|
||||
const ox::FileAddress &paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto &kctx = gctx.turbineCtx;
|
||||
auto &kctx = gctx.turbineCtx.keelCtx;
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||
@ -473,7 +468,7 @@ void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept {
|
||||
void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
||||
initBackgroundBufferObjects(&gctx, &bg);
|
||||
initBackgroundBufferObjects(&bg);
|
||||
bg.updated = true;
|
||||
}
|
||||
|
||||
@ -481,7 +476,7 @@ void hideSprite(Context *ctx, unsigned idx) noexcept {
|
||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||
auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
||||
auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
||||
renderer::setSpriteBufferObject(ctx, idx * renderer::SpriteVertexVboRows, 0,
|
||||
renderer::setSpriteBufferObject(idx * renderer::SpriteVertexVboRows, 0,
|
||||
0, 0, 0, false, vbo, ebo);
|
||||
gctx.spriteBlocks.updated = true;
|
||||
}
|
||||
@ -526,7 +521,7 @@ void setSprite(
|
||||
const auto cidx = idx + i;
|
||||
auto vbo = &gctx.spriteBlocks.vertices[cidx * renderer::SpriteVertexVboLength];
|
||||
auto ebo = &gctx.spriteBlocks.elements[cidx * renderer::SpriteVertexEboLength];
|
||||
renderer::setSpriteBufferObject(ctx, cidx * renderer::SpriteVertexVboRows, 1,
|
||||
renderer::setSpriteBufferObject(cidx * renderer::SpriteVertexVboRows, 1,
|
||||
fX, fY, tileIdx + i, flipX, vbo, ebo);
|
||||
++i;
|
||||
};
|
||||
@ -565,7 +560,6 @@ void setTile(
|
||||
auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
||||
auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
||||
renderer::setTileBufferObject(
|
||||
ctx,
|
||||
static_cast<unsigned>(i * renderer::BgVertexVboRows),
|
||||
static_cast<float>(x),
|
||||
static_cast<float>(y),
|
||||
|
@ -26,7 +26,7 @@ ox::Result<PaletteEditorImGui*> PaletteEditorImGui::make(turbine::Context *ctx,
|
||||
out->m_itemPath = path;
|
||||
const auto lastSlash = std::find(out->m_itemPath.rbegin(), out->m_itemPath.rend(), '/').offset();
|
||||
out->m_itemName = out->m_itemPath.substr(lastSlash + 1);
|
||||
oxRequire(pal, keel::readObj<Palette>(out->m_ctx, ox::FileAddress(out->m_itemPath.c_str())));
|
||||
oxRequire(pal, keel::readObj<Palette>(&out->m_ctx->keelCtx, ox::FileAddress(out->m_itemPath.c_str())));
|
||||
out->m_pal = *pal;
|
||||
return out.release();
|
||||
}
|
||||
@ -148,7 +148,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
|
||||
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
||||
oxReturnError(sctx->project->writeObj(m_itemPath, &m_pal));
|
||||
oxReturnError(m_ctx->assetManager.setAsset(m_itemPath, m_pal));
|
||||
oxReturnError(m_ctx->keelCtx.assetManager.setAsset(m_itemPath, m_pal));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -566,10 +566,10 @@ class PaletteChangeCommand: public TileSheetCommand {
|
||||
TileSheetEditorModel::TileSheetEditorModel(turbine::Context *ctx, ox::String path):
|
||||
m_ctx(ctx),
|
||||
m_path(std::move(path)) {
|
||||
oxRequireT(img, readObj<TileSheet>(ctx, m_path));
|
||||
oxRequireT(img, readObj<TileSheet>(&ctx->keelCtx, m_path));
|
||||
m_img = *img;
|
||||
if (m_img.defaultPalette) {
|
||||
oxThrowError(readObj<Palette>(ctx, m_img.defaultPalette).moveTo(&m_pal));
|
||||
oxThrowError(readObj<Palette>(&ctx->keelCtx, m_img.defaultPalette).moveTo(&m_pal));
|
||||
}
|
||||
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
|
||||
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
|
||||
@ -633,7 +633,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
constexpr ox::StringView uuidPrefix = "uuid://";
|
||||
if (ox::beginsWith(path, uuidPrefix)) {
|
||||
auto uuid = ox::StringView(path + uuidPrefix.bytes(), ox_strlen(path) - uuidPrefix.bytes());
|
||||
auto out = m_ctx->uuidToPath.at(uuid);
|
||||
auto out = m_ctx->keelCtx.uuidToPath.at(uuid);
|
||||
if (out.error) {
|
||||
return {};
|
||||
}
|
||||
@ -644,7 +644,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
||||
}
|
||||
|
||||
ox::Error TileSheetEditorModel::setPalette(const ox::String &path) noexcept {
|
||||
oxRequire(uuid, m_ctx->pathToUuid.at(path));
|
||||
oxRequire(uuid, m_ctx->keelCtx.pathToUuid.at(path));
|
||||
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
|
||||
return {};
|
||||
}
|
||||
@ -752,7 +752,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(const studio::UndoCommand *cmd)
|
||||
m_updated = true;
|
||||
const auto cmdId = cmd->commandId();
|
||||
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
|
||||
oxReturnError(readObj<Palette>(m_ctx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal));
|
||||
oxReturnError(readObj<Palette>(&m_ctx->keelCtx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal));
|
||||
}
|
||||
auto tsCmd = dynamic_cast<const TileSheetCommand*>(cmd);
|
||||
auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx());
|
||||
@ -774,7 +774,7 @@ void TileSheetEditorModel::ackUpdate() noexcept {
|
||||
ox::Error TileSheetEditorModel::saveFile() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
||||
oxReturnError(sctx->project->writeObj(m_path, &m_img));
|
||||
return m_ctx->assetManager.setAsset(m_path, m_img).error;
|
||||
return m_ctx->keelCtx.assetManager.setAsset(m_path, m_img).error;
|
||||
}
|
||||
|
||||
bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {
|
||||
|
@ -50,7 +50,7 @@ void SceneEditorImGui::onActivated() noexcept {
|
||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||
const auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
||||
oxReturnError(sctx->project->writeObj(m_itemPath, &m_editor.scene()));
|
||||
oxReturnError(m_ctx->assetManager.setAsset(m_itemPath, m_editor.scene()));
|
||||
oxReturnError(m_ctx->keelCtx.assetManager.setAsset(m_itemPath, m_editor.scene()));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace nostalgia::scene {
|
||||
|
||||
SceneEditor::SceneEditor(turbine::Context *ctx, ox::CRStringView path) {
|
||||
m_ctx = ctx;
|
||||
oxRequireT(scn, keel::readObj<SceneStatic>(m_ctx, path));
|
||||
oxRequireT(scn, keel::readObj<SceneStatic>(&m_ctx->keelCtx, path));
|
||||
m_scene = *scn;
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,12 @@ static void keyEventHandler(turbine::Context &tctx, turbine::Key key, bool down)
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
||||
ox::Error run(ox::UniquePtr<ox::FileSystem> &&fs) noexcept {
|
||||
oxTraceInitHook();
|
||||
oxRequireM(tctx, turbine::init(std::move(fs), "Nostalgia"));
|
||||
oxRequireM(cctx, core::init(tctx.get()));
|
||||
constexpr ox::FileAddress SceneAddr("/Scenes/Chester.nscn");
|
||||
oxRequire(scn, keel::readObj<scene::SceneStatic>(tctx.get(), SceneAddr));
|
||||
oxRequire(scn, keel::readObj<scene::SceneStatic>(&tctx->keelCtx, SceneAddr));
|
||||
turbine::setUpdateHandler(*tctx, updateHandler);
|
||||
turbine::setKeyEventHandler(*tctx, keyEventHandler);
|
||||
s_scene.emplace(*scn);
|
||||
|
@ -3,5 +3,6 @@
|
||||
*/
|
||||
|
||||
#include <ox/std/memory.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
|
||||
typename ox::Error run(ox::UniquePtr<class ox::FileSystem> fs) noexcept;
|
||||
typename ox::Error run(ox::UniquePtr<ox::FileSystem> &&fs) noexcept;
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace studio {
|
||||
|
||||
AboutPopup::AboutPopup(turbine::Context &ctx) noexcept {
|
||||
m_text = ox::sfmt("{} - dev build", ctx.appName);
|
||||
m_text = ox::sfmt("{} - dev build", ctx.keelCtx.appName);
|
||||
}
|
||||
|
||||
void AboutPopup::open() noexcept {
|
||||
|
@ -45,7 +45,7 @@ static ox::Error runApp(
|
||||
ox::String projectDataDir,
|
||||
ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
||||
oxRequireM(ctx, turbine::init(std::move(fs), appName));
|
||||
turbine::setWindowTitle(*ctx, ctx->appName);
|
||||
turbine::setWindowTitle(*ctx, ctx->keelCtx.appName);
|
||||
turbine::setUpdateHandler(*ctx, updateHandler);
|
||||
turbine::setKeyEventHandler(*ctx, keyEventHandler);
|
||||
turbine::setConstantRefresh(*ctx, false);
|
||||
|
@ -27,7 +27,7 @@ class ProjectExplorer: public studio::Widget {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::FileSystem *romFs() noexcept {
|
||||
return m_ctx->rom.get();
|
||||
return rom(*m_ctx);
|
||||
}
|
||||
|
||||
// slots
|
||||
|
@ -42,7 +42,7 @@ StudioUI::StudioUI(turbine::Context *ctx, ox::String projectDir) noexcept:
|
||||
ImGui::GetIO().IniFilename = nullptr;
|
||||
loadModules();
|
||||
// open project and files
|
||||
const auto [config, err] = studio::readConfig<StudioConfig>(ctx);
|
||||
const auto [config, err] = studio::readConfig<StudioConfig>(&ctx->keelCtx);
|
||||
m_showProjectExplorer = config.showProjectExplorer;
|
||||
if (!err) {
|
||||
oxIgnoreError(openProject(config.projectPath));
|
||||
@ -215,7 +215,7 @@ void StudioUI::drawTabs() noexcept {
|
||||
if (ImGui::BeginTabItem(e->itemDisplayName().c_str(), &open, flags)) {
|
||||
if (m_activeEditor != e.get()) {
|
||||
m_activeEditor = e.get();
|
||||
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
|
||||
studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) {
|
||||
config->activeTabItemName = m_activeEditor->itemName();
|
||||
});
|
||||
}
|
||||
@ -268,7 +268,7 @@ void StudioUI::loadModules() noexcept {
|
||||
|
||||
void StudioUI::toggleProjectExplorer() noexcept {
|
||||
m_showProjectExplorer = !m_showProjectExplorer;
|
||||
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
|
||||
studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) {
|
||||
config->showProjectExplorer = m_showProjectExplorer;
|
||||
});
|
||||
}
|
||||
@ -295,16 +295,16 @@ void StudioUI::save() noexcept {
|
||||
|
||||
ox::Error StudioUI::openProject(ox::CRStringView path) noexcept {
|
||||
oxRequireM(fs, keel::loadRomFs(path));
|
||||
oxReturnError(keel::setRomFs(m_ctx, std::move(fs)));
|
||||
turbine::setWindowTitle(*m_ctx, ox::sfmt("{} - {}", m_ctx->appName, path));
|
||||
m_project = ox::make_unique<studio::Project>(m_ctx, path, m_projectDir);
|
||||
oxReturnError(keel::setRomFs(&m_ctx->keelCtx, std::move(fs)));
|
||||
turbine::setWindowTitle(*m_ctx, ox::sfmt("{} - {}", m_ctx->keelCtx.appName, path));
|
||||
m_project = ox::make_unique<studio::Project>(&m_ctx->keelCtx, path, m_projectDir);
|
||||
auto sctx = applicationData<studio::StudioContext>(*m_ctx);
|
||||
sctx->project = m_project.get();
|
||||
m_project->fileAdded.connect(m_projectExplorer.get(), &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_project->fileDeleted.connect(m_projectExplorer.get(), &ProjectExplorer::refreshProjectTreeModel);
|
||||
m_openFiles.clear();
|
||||
m_editors.clear();
|
||||
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
|
||||
studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) {
|
||||
config->projectPath = path;
|
||||
config->openFiles.clear();
|
||||
});
|
||||
@ -354,7 +354,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
|
||||
m_activeEditorUpdatePending = editor;
|
||||
}
|
||||
// save to config
|
||||
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
|
||||
studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) {
|
||||
if (!config->openFiles.contains(path)) {
|
||||
config->openFiles.emplace_back(path);
|
||||
}
|
||||
@ -368,7 +368,7 @@ ox::Error StudioUI::closeFile(const ox::String &path) noexcept {
|
||||
}
|
||||
oxIgnoreError(m_openFiles.erase(std::remove(m_openFiles.begin(), m_openFiles.end(), path)));
|
||||
// save to config
|
||||
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
|
||||
studio::editConfig<StudioConfig>(&m_ctx->keelCtx, [&](StudioConfig *config) {
|
||||
oxIgnoreError(config->openFiles.erase(std::remove(config->openFiles.begin(), config->openFiles.end(), path)));
|
||||
});
|
||||
return OxError(0);
|
||||
|
@ -50,7 +50,7 @@ class ItemMakerT: public ItemMaker {
|
||||
ox::Error write(turbine::Context *ctx, ox::CRStringView pName) const noexcept override {
|
||||
const auto path = ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
|
||||
auto sctx = turbine::applicationData<studio::StudioContext>(*ctx);
|
||||
keel::createUuidMapping(ctx, path, ox::UUID::generate().unwrap());
|
||||
keel::createUuidMapping(&ctx->keelCtx, path, ox::UUID::generate().unwrap());
|
||||
return sctx->project->writeObj(path, &item, fmt);
|
||||
}
|
||||
};
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user