From 375388c0f16a0de1b16575578ad49e8318a1c80f Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 30 Jul 2025 01:51:46 -0500 Subject: [PATCH] Squashed 'deps/nostalgia/' changes from e27eee50..f7c3c02c f7c3c02c Merge commit '1bfb7f99c215e2c74556bd3281f44962b8faaa96' 8f0f1fea [nostalgia/gfx/studio] Make editors use Project::loadObj for their primary assets 2f36a3f6 [studio] Add File -> Reload Project menu item 07e5bf90 [keel] Make keel attempt to delete all existing assets when FS is changed aacff3da [ox/std] Fix UPtr::reset to conform to unique_ptr::reset git-subtree-dir: deps/nostalgia git-subtree-split: f7c3c02c4cbe676ea116ea53f1f31b27f668cd98 --- deps/ox/src/ox/std/memory.hpp | 3 +-- .../src/studio/paletteeditor/paletteeditor-imgui.cpp | 2 +- .../studio/tilesheeteditor/tilesheeteditormodel.cpp | 2 +- src/olympic/keel/include/keel/asset.hpp | 5 ++--- src/olympic/keel/src/media.cpp | 3 +++ src/olympic/studio/applib/src/studioui.cpp | 12 ++++++++---- src/olympic/studio/modlib/include/studio/project.hpp | 7 ++++++- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/deps/ox/src/ox/std/memory.hpp b/deps/ox/src/ox/std/memory.hpp index f5f3f9f..f145d9a 100644 --- a/deps/ox/src/ox/std/memory.hpp +++ b/deps/ox/src/ox/std/memory.hpp @@ -213,8 +213,7 @@ class UniquePtr { return m_t; } - template - constexpr void reset(UniquePtr &&other = UniquePtr()) { + constexpr void reset(UniquePtr &&other = UniquePtr()) { auto t = m_t; m_t = other.release(); Deleter()(t); diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp index 8a6d38e..d113814 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -72,7 +72,7 @@ PaletteEditorImGui::PaletteEditorImGui(studio::Context &sctx, ox::StringParam pa Editor(sctx, std::move(path)), m_sctx(sctx), m_tctx(sctx.tctx), - m_pal(*keel::readObj(keelCtx(m_tctx), itemPath()).unwrapThrow()) { + m_pal(m_sctx.project->loadObj(itemPath()).unwrapThrow()) { undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand); m_pageRenameDlg.inputSubmitted.connect(this, &PaletteEditorImGui::renamePage); } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index 5d61185..5fb6ccf 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -49,7 +49,7 @@ TileSheetEditorModel::TileSheetEditorModel( m_sctx{sctx}, m_tctx{m_sctx.tctx}, m_path{std::move(path)}, - m_img{*readObj(keelCtx(m_tctx), m_path).unwrapThrow()}, + m_img{m_sctx.project->loadObj(m_path).unwrapThrow()}, // ignore failure to load palette m_pal{readObj(keelCtx(m_tctx), m_img.defaultPalette).value}, m_undoStack{undoStack} { diff --git a/src/olympic/keel/include/keel/asset.hpp b/src/olympic/keel/include/keel/asset.hpp index ce0272e..1dd0548 100644 --- a/src/olympic/keel/include/keel/asset.hpp +++ b/src/olympic/keel/include/keel/asset.hpp @@ -25,12 +25,11 @@ ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexce template ox::Result readAsset(ox::BufferView buff) noexcept { - std::size_t offset = 0; auto const err = readUuidHeader(buff).error; if (!err) { - offset = K1HdrSz; // the size of K1 headers + buff += K1HdrSz; // the size of K1 headers } - auto out = ox::readClaw(buff + offset); + auto out = ox::readClaw(buff); OX_RETURN_ERROR(out); OX_RETURN_ERROR(ensureValid(out.value)); return out; diff --git a/src/olympic/keel/src/media.cpp b/src/olympic/keel/src/media.cpp index 8dba38f..24c2ccb 100644 --- a/src/olympic/keel/src/media.cpp +++ b/src/olympic/keel/src/media.cpp @@ -261,6 +261,9 @@ namespace keel { ox::Error setRomFs(Context &ctx, ox::UPtr &&fs, DuplicateSet &duplicateSet) noexcept { ctx.rom = std::move(fs); clearUuidMap(ctx); +#ifndef OX_BARE_METAL + ctx.assetManager.gc(); +#endif return buildUuidMap(ctx, &duplicateSet); } diff --git a/src/olympic/studio/applib/src/studioui.cpp b/src/olympic/studio/applib/src/studioui.cpp index 16ecb96..3b91045 100644 --- a/src/olympic/studio/applib/src/studioui.cpp +++ b/src/olympic/studio/applib/src/studioui.cpp @@ -250,6 +250,9 @@ void StudioUI::drawMenu() noexcept { if (ImGui::MenuItem("Open Project...", STUDIO_CTRL "+O")) { m_taskRunner.add(*ox::make(this, &StudioUI::openProjectPath)); } + if (ImGui::MenuItem("Reload Project")) { + oxLogError(openProjectPath(m_project->projectPath())); + } if (ImGui::BeginMenu("Recent Projects", m_recentProjects.size() > 1)) { for (size_t i = 1; i < m_recentProjects.size(); ++i) { auto const &p = m_recentProjects[i]; @@ -636,6 +639,9 @@ ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept { ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept { OX_REQUIRE_M(fs, keel::loadRomFs(path.view())); + m_project.reset(); + m_openFiles.clear(); + m_editors.clear(); keel::DuplicateSet ds; OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs), ds)); if (ds.size()) { @@ -649,8 +655,8 @@ ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept { m_messagePopup.show(msg); } OX_RETURN_ERROR( - ox::make_unique_catch(keelCtx(m_tctx), std::move(path), m_projectDataDir) - .moveTo(m_project)); + ox::make_unique_catch(keelCtx(m_tctx), std::move(path), m_projectDataDir) + .moveTo(m_project)); m_sctx.project = m_project.get(); m_activeEditor = nullptr; m_activeEditorOnLastDraw = nullptr; @@ -665,8 +671,6 @@ ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept { m_project->dirDeleted.connect(this, &StudioUI::handleDeleteDir); m_project->fileDeleted.connect(this, &StudioUI::handleDeleteFile); m_project->fileMoved.connect(this, &StudioUI::handleMoveFile); - m_openFiles.clear(); - m_editors.clear(); studio::editConfig(keelCtx(m_tctx), [&](StudioConfig &config) { auto const pcIt = std::find_if( config.projects.begin(), config.projects.end(), diff --git a/src/olympic/studio/modlib/include/studio/project.hpp b/src/olympic/studio/modlib/include/studio/project.hpp index 6d9bd27..f514e3c 100644 --- a/src/olympic/studio/modlib/include/studio/project.hpp +++ b/src/olympic/studio/modlib/include/studio/project.hpp @@ -185,10 +185,15 @@ ox::Error Project::writeObj(ox::StringViewCR path, T const &obj) noexcept { template ox::Result Project::loadObj(ox::StringViewCR path) const noexcept { - OX_REQUIRE(buff, loadBuff(path)); + OX_REQUIRE_M(buff, loadBuff(path)); if constexpr(ox::is_same_v) { return keel::readAsset(m_typeStore, buff); } else { + OX_REQUIRE(typeId, keel::readAssetTypeId(buff)); + if (typeId != ox::ModelTypeId_v) { + OX_REQUIRE(ah, keel::readAssetHeader(buff)); + OX_RETURN_ERROR(keel::convertBuffToBuff(m_kctx, buff, ah.clawHdr.fmt).moveTo(buff)); + } return keel::readAsset(buff); } }