diff --git a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp index a86edb06..911d7cb6 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp @@ -78,6 +78,6 @@ void setSprite(Context &ctx, Sprite const&s) noexcept; } namespace nostalgia::core::gl { -void drawMainView(core::Context&, ox::Size const&) noexcept; +void draw(core::Context&, ox::Size const&) noexcept; } diff --git a/src/nostalgia/modules/core/src/opengl/gfx.cpp b/src/nostalgia/modules/core/src/opengl/gfx.cpp index 5984c784..37463944 100644 --- a/src/nostalgia/modules/core/src/opengl/gfx.cpp +++ b/src/nostalgia/modules/core/src/opengl/gfx.cpp @@ -34,7 +34,7 @@ namespace renderer { Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {} void Drawer::draw(turbine::Context &tctx) noexcept { - core::gl::drawMainView(m_ctx, turbine::getScreenSize(tctx)); + core::gl::draw(m_ctx, turbine::getScreenSize(tctx)); } constexpr ox::StringView bgvshadTmpl = R"( @@ -633,7 +633,7 @@ void setTile( namespace gl { -void drawMainView(core::Context &ctx, ox::Size const&renderSz) noexcept { +void draw(core::Context &ctx, ox::Size const&renderSz) noexcept { glViewport(0, 0, renderSz.width, renderSz.height); glutils::clearScreen(); auto &gctx = glctx(ctx); diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp index added798..e0212800 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.cpp @@ -15,11 +15,11 @@ namespace nostalgia::core { -PaletteEditorImGui::PaletteEditorImGui(turbine::Context *ctx, ox::String path): +PaletteEditorImGui::PaletteEditorImGui(turbine::Context &ctx, ox::String path): m_ctx(ctx), m_itemPath(std::move(path)), m_itemName(m_itemPath.substr(std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset() + 1)), - m_pal(*keel::readObj(m_ctx->keelCtx, ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) { + m_pal(*keel::readObj(m_ctx.keelCtx, ox::FileAddress(m_itemPath.c_str())).unwrapThrow()) { } const ox::String &PaletteEditorImGui::itemName() const noexcept { @@ -125,7 +125,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept { int r = red16(c); int g = green16(c); int b = blue16(c); - int a = alpha16(c); + int const a = alpha16(c); ImGui::InputInt("Red", &r, 1, 5); ImGui::InputInt("Green", &g, 1, 5); ImGui::InputInt("Blue", &b, 1, 5); @@ -139,7 +139,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept { } ox::Error PaletteEditorImGui::saveItem() noexcept { - const auto sctx = applicationData(*m_ctx); + const auto sctx = applicationData(m_ctx); return sctx->project->writeObj(m_itemPath, m_pal); } diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp index f93804ad..834e654d 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor-imgui.hpp @@ -14,16 +14,14 @@ namespace nostalgia::core { class PaletteEditorImGui: public studio::Editor { private: - turbine::Context *m_ctx = nullptr; + turbine::Context &m_ctx; ox::String m_itemPath; ox::String m_itemName; Palette m_pal; std::size_t m_selectedRow = 0; - PaletteEditorImGui() noexcept = default; - public: - PaletteEditorImGui(turbine::Context *ctx, ox::String path); + PaletteEditorImGui(turbine::Context &ctx, ox::String path); /** * Returns the name of item being edited. diff --git a/src/nostalgia/modules/core/src/studio/studiomodule.cpp b/src/nostalgia/modules/core/src/studio/studiomodule.cpp index 7d261b5c..15f5c80f 100644 --- a/src/nostalgia/modules/core/src/studio/studiomodule.cpp +++ b/src/nostalgia/modules/core/src/studio/studiomodule.cpp @@ -12,14 +12,14 @@ namespace nostalgia::core { class StudioModule: public studio::Module { - ox::Vector editors(turbine::Context *ctx) const noexcept final { + ox::Vector editors(turbine::Context &ctx) const noexcept final { return { studio::editorMaker(ctx, FileExt_ng), studio::editorMaker(ctx, FileExt_npal), }; } - ox::Vector> itemMakers(turbine::Context*) const noexcept final { + ox::Vector> itemMakers(turbine::Context&) const noexcept final { ox::Vector> out; out.emplace_back(ox::make>("Tile Sheet", "TileSheets", FileExt_ng)); out.emplace_back(ox::make>("Palette", "Palettes", FileExt_npal)); diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp index aefebf94..600c09a6 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.cpp @@ -38,14 +38,15 @@ ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const return OxError(static_cast(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8))); } -TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::String path): m_tileSheetEditor(ctx, path) { - m_ctx = ctx; - m_itemPath = std::move(path); +TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context &ctx, ox::String path): + m_ctx(ctx), + m_itemPath(std::move(path)), + m_tileSheetEditor(m_ctx, m_itemPath) { const auto lastSlash = ox::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); m_itemName = m_itemPath.substr(lastSlash + 1); // init palette idx const auto &palPath = model()->palPath(); - auto sctx = applicationData(*m_ctx); + auto sctx = applicationData(m_ctx); const auto &palList = sctx->project->fileList(core::FileExt_npal); for (std::size_t i = 0; const auto &pal : palList) { if (palPath == pal) { @@ -305,7 +306,7 @@ void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept { const auto wheelh = io.MouseWheelH; if (wheel != 0) { const auto zoomMod = ox::defines::OS == ox::OS::Darwin ? - io.KeySuper : turbine::buttonDown(*m_ctx, turbine::Key::Mod_Ctrl); + io.KeySuper : turbine::buttonDown(m_ctx, turbine::Key::Mod_Ctrl); m_tileSheetEditor.scrollV(fbSize, wheel, zoomMod); } if (wheelh != 0) { @@ -345,7 +346,7 @@ void TileSheetEditorImGui::drawTileSheet(const ox::Vec2 &fbSize) noexcept { } void TileSheetEditorImGui::drawPaletteSelector() noexcept { - auto sctx = applicationData(*m_ctx); + auto sctx = applicationData(m_ctx); const auto &files = sctx->project->fileList(core::FileExt_npal); const auto first = m_selectedPaletteIdx < files.size() ? files[m_selectedPaletteIdx].c_str() : ""; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp index 808712bc..cfe25002 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor-imgui.hpp @@ -43,7 +43,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { void close() noexcept; }; std::size_t m_selectedPaletteIdx = 0; - turbine::Context *m_ctx = nullptr; + turbine::Context &m_ctx; ox::Vector m_paletteList; SubSheetEditor m_subsheetEditor; ox::String m_itemPath; @@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::BaseEditor { Tool m_tool = Tool::Draw; public: - TileSheetEditorImGui(turbine::Context *ctx, ox::String path); + TileSheetEditorImGui(turbine::Context &ctx, ox::String path); ~TileSheetEditorImGui() override = default; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp index 7deade63..a7babd99 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.cpp @@ -563,13 +563,13 @@ class PaletteChangeCommand: public TileSheetCommand { }; -TileSheetEditorModel::TileSheetEditorModel(turbine::Context *ctx, ox::StringView path): +TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path): m_ctx(ctx), m_path(path) { - oxRequireT(img, readObj(ctx->keelCtx, m_path)); + oxRequireT(img, readObj(m_ctx.keelCtx, m_path)); m_img = *img; if (m_img.defaultPalette) { - oxThrowError(readObj(ctx->keelCtx, m_img.defaultPalette).moveTo(&m_pal)); + oxThrowError(readObj(m_ctx.keelCtx, m_img.defaultPalette).moveTo(&m_pal)); } m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated); m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId); @@ -592,7 +592,7 @@ void TileSheetEditorModel::cut() { } const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin; const auto pt2 = ox::Point(s->columns * TileWidth, s->rows * TileHeight); - turbine::setClipboardObject(*m_ctx, std::move(cb)); + turbine::setClipboardObject(m_ctx, std::move(cb)); pushCommand(ox::make>(m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); } @@ -609,11 +609,11 @@ void TileSheetEditorModel::copy() { cb->addPixel(pt, c); } } - turbine::setClipboardObject(*m_ctx, std::move(cb)); + turbine::setClipboardObject(m_ctx, std::move(cb)); } void TileSheetEditorModel::paste() { - auto [cb, err] = turbine::getClipboardObject(*m_ctx); + auto [cb, err] = turbine::getClipboardObject(m_ctx); if (err) { oxLogError(err); oxErrf("Could not read clipboard: {}", toStr(err)); @@ -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.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes()); - auto out = m_ctx->keelCtx.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->keelCtx.pathToUuid.at(path)); + oxRequire(uuid, m_ctx.keelCtx.pathToUuid.at(path)); pushCommand(ox::make(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(cmdId) == CommandId::PaletteChange) { - oxReturnError(readObj(m_ctx->keelCtx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal)); + oxReturnError(readObj(m_ctx.keelCtx, ox::StringView(m_img.defaultPalette.getPath().value)).moveTo(&m_pal)); } auto tsCmd = dynamic_cast(cmd); auto idx = m_img.validateSubSheetIdx(tsCmd->subsheetIdx()); @@ -772,7 +772,7 @@ void TileSheetEditorModel::ackUpdate() noexcept { } ox::Error TileSheetEditorModel::saveFile() noexcept { - const auto sctx = applicationData(*m_ctx); + const auto sctx = applicationData(m_ctx); return sctx->project->writeObj(m_path, m_img); } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp index 5fc3009f..3eb37c0e 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditormodel.hpp @@ -29,14 +29,14 @@ class TileSheetEditorModel: public ox::SignalHandler { studio::UndoStack m_undoStack; class DrawCommand *m_ongoingDrawCommand = nullptr; bool m_updated = false; - turbine::Context *m_ctx = nullptr; + turbine::Context &m_ctx; ox::String m_path; bool m_selectionOngoing = false; ox::Point m_selectionOrigin = {-1, -1}; ox::Bounds m_selectionBounds = {{-1, -1}, {-1, -1}}; public: - TileSheetEditorModel(turbine::Context *ctx, ox::StringView path); + TileSheetEditorModel(turbine::Context &ctx, ox::StringView path); ~TileSheetEditorModel() override = default; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp index a4da5243..4852ec0b 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.cpp @@ -11,8 +11,9 @@ namespace nostalgia::core { -TileSheetEditorView::TileSheetEditorView(turbine::Context *ctx, ox::StringView path): - m_model(ctx, path), m_pixelsDrawer(&m_model) { +TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path): + m_model(ctx, path), + m_pixelsDrawer(&m_model) { // build shaders oxThrowError(m_pixelsDrawer.buildShader()); oxThrowError(m_pixelGridDrawer.buildShader()); diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp index 4a555125..e5e73a3f 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditorview.hpp @@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler { std::size_t m_palIdx = 0; public: - TileSheetEditorView(turbine::Context *ctx, ox::StringView path); + TileSheetEditorView(turbine::Context &ctx, ox::StringView path); ~TileSheetEditorView() override = default; diff --git a/src/nostalgia/modules/scene/src/keel/typeconv.cpp b/src/nostalgia/modules/scene/src/keel/typeconv.cpp index 5a3b15a7..b502b2ff 100644 --- a/src/nostalgia/modules/scene/src/keel/typeconv.cpp +++ b/src/nostalgia/modules/scene/src/keel/typeconv.cpp @@ -18,7 +18,7 @@ constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) no } } -constexpr void setLayerAttachments(unsigned layer, const TileDoc &srcTile, SceneStatic::Tile &dstTile) noexcept { +constexpr void setLayerAttachments(unsigned layer, TileDoc const&srcTile, SceneStatic::Tile &dstTile) noexcept { setTopEdge( dstTile.layerAttachments, adjustLayerAttachment(layer, srcTile.layerAttachments[0])); diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp index 2d72964c..2aa4a734 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp @@ -10,11 +10,11 @@ namespace nostalgia::scene { -SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::String path): +SceneEditorImGui::SceneEditorImGui(turbine::Context &ctx, ox::StringView path): m_ctx(ctx), m_itemPath(std::move(path)), - m_editor(&m_ctx, m_itemPath), - m_view(&m_ctx, m_editor.scene()) { + m_editor(m_ctx, m_itemPath), + m_view(m_ctx, m_editor.scene()) { const auto lastSlash = std::find(m_itemPath.rbegin(), m_itemPath.rend(), '/').offset(); m_itemName = m_itemPath.substr(lastSlash + 1); setRequiresConstantRefresh(false); diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp index 0e8c70cf..5e25385c 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp @@ -23,7 +23,7 @@ class SceneEditorImGui: public studio::Editor { SceneEditorView m_view; public: - SceneEditorImGui(turbine::Context &ctx, ox::String path); + SceneEditorImGui(turbine::Context &ctx, ox::StringView path); /** * Returns the name of item being edited. diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditor.cpp index dcfba4f6..c82af46d 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor.cpp @@ -8,10 +8,9 @@ namespace nostalgia::scene { -SceneEditor::SceneEditor(turbine::Context *ctx, ox::CRStringView path) { - m_ctx = ctx; - oxRequireT(scn, keel::readObj(m_ctx->keelCtx, path)); - m_scene = *scn; +SceneEditor::SceneEditor(turbine::Context &ctx, ox::CRStringView path): + m_ctx(ctx), + m_scene(*keel::readObj(m_ctx.keelCtx, path).unwrapThrow()) { } } diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor.hpp b/src/nostalgia/modules/scene/src/studio/sceneeditor.hpp index 6d1a2e30..7a0e5f1f 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor.hpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor.hpp @@ -13,15 +13,16 @@ namespace nostalgia::scene { class SceneEditor { private: - turbine::Context *m_ctx = nullptr; + turbine::Context &m_ctx; ox::String m_itemName; ox::String m_itemPath; SceneStatic m_scene; public: - SceneEditor(turbine::Context *ctx, ox::CRStringView path); + SceneEditor(turbine::Context &ctx, ox::CRStringView path); - const SceneStatic &scene() noexcept { + [[nodiscard]] + SceneStatic const&scene() const noexcept { return m_scene; } diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp index 5d5831e3..2aec80b3 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditorview.cpp @@ -8,10 +8,10 @@ namespace nostalgia::scene { -SceneEditorView::SceneEditorView(turbine::Context *tctx, const SceneStatic &sceneStatic): +SceneEditorView::SceneEditorView(turbine::Context &tctx, SceneStatic const&sceneStatic): m_sceneStatic(sceneStatic), m_scene(m_sceneStatic) { - oxThrowError(core::init(*tctx, {.glInstallDrawer = false}).moveTo(&m_cctx)); + oxThrowError(core::init(tctx, {.glInstallDrawer = false}).moveTo(&m_cctx)); } ox::Error SceneEditorView::setupScene() noexcept { @@ -23,10 +23,10 @@ void SceneEditorView::draw(int width, int height) noexcept { glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height); } const glutils::FrameBufferBind frameBufferBind(m_frameBuffer); - core::gl::drawMainView(*m_cctx, {width, height}); + core::gl::draw(*m_cctx, {width, height}); } -const glutils::FrameBuffer &SceneEditorView::framebuffer() const noexcept { +glutils::FrameBuffer const&SceneEditorView::framebuffer() const noexcept { return m_frameBuffer; } diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditorview.hpp b/src/nostalgia/modules/scene/src/studio/sceneeditorview.hpp index 19653d15..66ffa856 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditorview.hpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditorview.hpp @@ -15,19 +15,19 @@ class SceneEditorView { private: ox::UPtr m_cctx; - const SceneStatic &m_sceneStatic; + SceneStatic const&m_sceneStatic; Scene m_scene; glutils::FrameBuffer m_frameBuffer; public: - SceneEditorView(turbine::Context *ctx, const SceneStatic &sceneStatic); + SceneEditorView(turbine::Context &ctx, SceneStatic const&sceneStatic); ox::Error setupScene() noexcept; void draw(int width, int height) noexcept; [[nodiscard]] - const glutils::FrameBuffer &framebuffer() const noexcept; + glutils::FrameBuffer const&framebuffer() const noexcept; }; diff --git a/src/nostalgia/modules/scene/src/studio/studiomodule.cpp b/src/nostalgia/modules/scene/src/studio/studiomodule.cpp index 446e9d3d..ee69c9f2 100644 --- a/src/nostalgia/modules/scene/src/studio/studiomodule.cpp +++ b/src/nostalgia/modules/scene/src/studio/studiomodule.cpp @@ -10,22 +10,17 @@ namespace nostalgia::scene { class StudioModule: public studio::Module { public: - ox::Vector editors(turbine::Context *ctx) const noexcept override; - ox::Vector> itemMakers(turbine::Context*) const noexcept override; + ox::Vector editors(turbine::Context &ctx) const noexcept override; + ox::Vector> itemMakers(turbine::Context&) const noexcept override; }; -ox::Vector StudioModule::editors(turbine::Context *ctx) const noexcept { +ox::Vector StudioModule::editors(turbine::Context &ctx) const noexcept { return { - { - {ox::String("nscn")}, - [ctx](ox::CRStringView path) -> ox::Result { - return ox::makeCatch(*ctx, ox::String(path)); - } - }, + studio::editorMaker(ctx, "nscn"), }; } -ox::Vector> StudioModule::itemMakers(turbine::Context*) const noexcept { +ox::Vector> StudioModule::itemMakers(turbine::Context&) const noexcept { ox::Vector> out; return out; } diff --git a/src/nostalgia/modules/scene/src/studio/typeconv.cpp b/src/nostalgia/modules/scene/src/studio/typeconv.cpp deleted file mode 100644 index d600d4ff..00000000 --- a/src/nostalgia/modules/scene/src/studio/typeconv.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include -#include - -#include "typeconv.hpp" - -namespace nostalgia::scene { - -[[nodiscard]] -constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) noexcept { - if (attachment == 0) { - return layer; - } else { - return attachment - 1; - } -} - -constexpr void setLayerAttachments(unsigned layer, const TileDoc &srcTile, SceneStatic::Tile &dstTile) noexcept { - setTopEdge( - dstTile.layerAttachments, - adjustLayerAttachment(layer, srcTile.layerAttachments[0])); - setBottomEdge( - dstTile.layerAttachments, - adjustLayerAttachment(layer, srcTile.layerAttachments[1])); - setLeftEdge( - dstTile.layerAttachments, - adjustLayerAttachment(layer, srcTile.layerAttachments[2])); - setRightEdge( - dstTile.layerAttachments, - adjustLayerAttachment(layer, srcTile.layerAttachments[3])); -} - -ox::Error SceneDocToSceneStaticConverter::convert( - keel::Context *ctx, - SceneDoc *src, - SceneStatic *dst) const noexcept { - oxRequire(ts, keel::readObj(ctx, src->tilesheet)); - const auto layerCnt = src->tiles.size(); - dst->setLayerCnt(layerCnt); - dst->tilesheet = ox::FileAddress(src->tilesheet); - dst->palettes.reserve(src->palettes.size()); - for (const auto &pal : src->palettes) { - dst->palettes.emplace_back(pal); - } - for (auto layerIdx = 0u; const auto &layer : src->tiles) { - const auto layerDim = src->size(layerIdx); - auto dstLayer = dst->layer(layerIdx); - dstLayer.setDimensions(layerDim); - for (auto tileIdx = 0u; const auto &row : layer) { - for (const auto &srcTile : row) { - auto dstTile = dstLayer.tile(tileIdx); - dstTile.tileType = srcTile.type; - oxRequire(path, srcTile.getSubsheetPath(*ts)); - oxRequire(mapIdx, ts->getTileOffset(path)); - dstTile.tileMapIdx = static_cast(mapIdx); - setLayerAttachments(layerIdx, srcTile, dstTile); - ++tileIdx; - } - } - ++layerIdx; - } - return {}; -} - -} diff --git a/src/nostalgia/modules/scene/src/studio/typeconv.hpp b/src/nostalgia/modules/scene/src/studio/typeconv.hpp deleted file mode 100644 index e9a2342e..00000000 --- a/src/nostalgia/modules/scene/src/studio/typeconv.hpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -#include - -namespace nostalgia::scene { - -class SceneDocToSceneStaticConverter: public keel::Converter { - ox::Error convert(keel::Context*, SceneDoc *src, SceneStatic *dst) const noexcept final; -}; - -} diff --git a/src/studio/applib/src/studioapp.cpp b/src/studio/applib/src/studioapp.cpp index c31a80b0..c39dc50c 100644 --- a/src/studio/applib/src/studioapp.cpp +++ b/src/studio/applib/src/studioapp.cpp @@ -260,10 +260,10 @@ void StudioUI::loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept } void StudioUI::loadModule(const studio::Module *mod) noexcept { - for (const auto &editorMaker : mod->editors(m_ctx)) { + for (const auto &editorMaker : mod->editors(*m_ctx)) { loadEditorMaker(editorMaker); } - for (auto &im : mod->itemMakers(m_ctx)) { + for (auto &im : mod->itemMakers(*m_ctx)) { m_newMenu.addItemMaker(std::move(im)); } } diff --git a/src/studio/modlib/include/studio/module.hpp b/src/studio/modlib/include/studio/module.hpp index 95dd8dfb..2359cb26 100644 --- a/src/studio/modlib/include/studio/module.hpp +++ b/src/studio/modlib/include/studio/module.hpp @@ -27,18 +27,18 @@ class Module { public: virtual ~Module() noexcept = default; - virtual ox::Vector editors(turbine::Context *ctx) const; + virtual ox::Vector editors(turbine::Context &ctx) const; - virtual ox::Vector> itemMakers(turbine::Context*) const; + virtual ox::Vector> itemMakers(turbine::Context&) const; }; template [[nodiscard]] -studio::EditorMaker editorMaker(turbine::Context *ctx, ox::CRStringView ext) noexcept { +studio::EditorMaker editorMaker(turbine::Context &ctx, ox::CRStringView ext) noexcept { return { {ox::String(ext)}, - [ctx](ox::CRStringView path) -> ox::Result { + [&ctx](ox::CRStringView path) -> ox::Result { return ox::makeCatch(ctx, ox::String(path)); } }; diff --git a/src/studio/modlib/src/module.cpp b/src/studio/modlib/src/module.cpp index 18f3a001..12d31b35 100644 --- a/src/studio/modlib/src/module.cpp +++ b/src/studio/modlib/src/module.cpp @@ -6,11 +6,11 @@ namespace studio { -ox::Vector Module::editors(turbine::Context*) const { +ox::Vector Module::editors(turbine::Context&) const { return {}; } -ox::Vector> Module::itemMakers(turbine::Context*) const { +ox::Vector> Module::itemMakers(turbine::Context&) const { return {}; }