From ff2eb5b11bcfeec814063872115b2874150c6ecb Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 31 Jan 2024 23:15:53 -0600 Subject: [PATCH 1/6] [olympic/keel] Remove const r-value funcion from AssetRef --- src/olympic/keel/include/keel/assetmanager.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/olympic/keel/include/keel/assetmanager.hpp b/src/olympic/keel/include/keel/assetmanager.hpp index 39c3a07f..f27667f1 100644 --- a/src/olympic/keel/include/keel/assetmanager.hpp +++ b/src/olympic/keel/include/keel/assetmanager.hpp @@ -284,10 +284,6 @@ class AssetRef { return *m_obj; } - constexpr T const&&operator*() const && noexcept { - return *m_obj; - } - constexpr T const*operator->() const noexcept { return m_obj; } From 1dff26d895ce0400d23a6db51f3ca0cb92d4d459 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 31 Jan 2024 23:16:41 -0600 Subject: [PATCH 2/6] [nostalgia/core] Add getTileCnt and fix getTileIdx --- src/nostalgia/modules/core/src/tilesheet.cpp | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/nostalgia/modules/core/src/tilesheet.cpp b/src/nostalgia/modules/core/src/tilesheet.cpp index 67b2c2e0..58ebc156 100644 --- a/src/nostalgia/modules/core/src/tilesheet.cpp +++ b/src/nostalgia/modules/core/src/tilesheet.cpp @@ -14,6 +14,7 @@ std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept { return ptToIdx(pt, ss.columns); } +[[nodiscard]] static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept { if (ss.id == id) { return &ss; @@ -26,6 +27,24 @@ static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSh return {}; } +[[nodiscard]] +static size_t getTileCnt(TileSheet::SubSheet const&ss, int const bpp) noexcept { + if (ss.subsheets.empty()) { + auto const bytesPerTile = bpp == 4 ? 32u : 64u; + return ss.pixels.size() / bytesPerTile; + } else { + size_t out{}; + for (auto const&child : ss.subsheets) { + out += getTileCnt(child, bpp); + } + return out; + } +} + +size_t getTileCnt(TileSheet const&ts) noexcept { + return getTileCnt(ts.subsheet, ts.bpp); +} + TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept { return getSubsheet(ts.subsheet, id); } @@ -42,7 +61,7 @@ static ox::Optional getPixelIdx( if (auto out = getPixelIdx(child, id, idx, bpp)) { return out; } - idx += pixelCnt(ss, bpp); + idx += pixelCnt(child, bpp); } return {}; } From 9c026e1a6ca2d408091230179946f559c8b123b6 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 31 Jan 2024 23:17:09 -0600 Subject: [PATCH 3/6] [nostalgia/core/studio] Add function to remove unused data from TileSheets --- .../studio/tilesheeteditor/tilesheeteditormodel.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index b82a932a..7694efa9 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -30,6 +30,17 @@ Palette const TileSheetEditorModel::s_defaultPalette = { .pages = {ox::Vector(128)}, }; +// delete pixels of all non-leaf nodes +static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept { + if (ss.subsheets.empty()) { + for (auto &child : ss.subsheets) { + normalizeSubsheets(child); + } + } else { + ss.pixels.clear(); + } +} + TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack): m_ctx(ctx), m_path(path), @@ -37,6 +48,7 @@ TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView // ignore failure to load palette m_pal(readObj(keelCtx(m_ctx), m_img.defaultPalette).value), m_undoStack(undoStack) { + normalizeSubsheets(m_img.subsheet); m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated); m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId); } From 5972d8acef2469cd66c7923518304b4aa147574d Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 31 Jan 2024 23:17:28 -0600 Subject: [PATCH 4/6] [nostalgia/core] Fix TileSetEntry model --- src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp index 90340117..ca017384 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/gfx.hpp @@ -73,7 +73,7 @@ struct TileSheetSetEntrySection { oxModelBegin(TileSheetSetEntrySection) oxModelField(begin) - oxModelField(size) + oxModelField(tiles) oxModelEnd() struct TileSheetSetEntry { @@ -92,7 +92,7 @@ struct TileSheetSet { static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet"; static constexpr auto TypeVersion = 1; static constexpr auto Preloadable = true; - int bpp = 0; + int32_t bpp = 0; ox::Vector entries; }; @@ -101,6 +101,8 @@ oxModelBegin(TileSheetSet) oxModelField(entries) oxModelEnd() +void addEntry(TileSheetSet &set, ox::FileAddress path, int32_t begin = 0, int32_t size = -1) noexcept; + ox::Error loadBgPalette( Context &ctx, size_t palBank, From 2667be88f65a569df9ceedbcc449e558196109d4 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 31 Jan 2024 23:17:46 -0600 Subject: [PATCH 5/6] [nostalgia/core] Add largestPage function for Palette --- .../modules/core/include/nostalgia/core/palette.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp b/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp index 06eba728..72f97859 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/palette.hpp @@ -60,6 +60,15 @@ constexpr size_t colors(Palette const&pal, size_t page = 0) noexcept { return 0; } +[[nodiscard]] +constexpr size_t largestPage(Palette const&pal) noexcept { + size_t out{}; + for (auto const&page : pal.pages) { + out = ox::max(out, page.size()); + } + return out; +} + oxModelBegin(NostalgiaPalette) oxModelField(colors) oxModelEnd() From 10a12f2ab20199df580da5bd7d8d22bae0a58cf0 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 31 Jan 2024 23:17:59 -0600 Subject: [PATCH 6/6] [nostalgia/core] Add getTileCnt to header --- .../modules/core/include/nostalgia/core/tilesheet.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp index 06beb9c5..3de737d1 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp @@ -159,7 +159,10 @@ struct TileSheet { std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept; [[nodiscard]] -TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept; +size_t getTileCnt(TileSheet const&ts) noexcept; + +[[nodiscard]] +TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId id) noexcept; [[nodiscard]] size_t getTileIdx(TileSheet const&ts, SubSheetId id) noexcept;