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, 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() 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; 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); } 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 {}; } 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; }