From 294c4547d00eef99e24f473c826dd70cc99c98a7 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 23 Feb 2022 22:12:41 -0600 Subject: [PATCH] [nostalgia/core] Remove TileSheet::SubSheet::size --- src/nostalgia/core/gfx.hpp | 37 +++++++++++++++++++++++---------- src/nostalgia/core/typeconv.cpp | 1 - 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index c840a0e4..31c13920 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -62,10 +62,13 @@ struct TileSheet { static constexpr auto TypeVersion = 1; ox::BString<32> name; uint64_t begin = 0; - uint64_t size = 0; - int rows = 1; int columns = 1; + int rows = 1; ox::Vector subsheets; + + constexpr SubSheet() noexcept = default; + constexpr SubSheet(const char *pName, int pColumns, int pRows) noexcept: name(pName), columns(pColumns), rows(pRows) { + } }; static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheet"; @@ -76,7 +79,15 @@ struct TileSheet { SubSheet subsheet; [[nodiscard]] - constexpr const auto &getSubSheet(const SubSheetIdx &idx, std::size_t idxIt, const SubSheet *pSubsheet) const noexcept { + constexpr static const auto &getSubSheet(const SubSheetIdx &idx, std::size_t idxIt, const SubSheet *pSubsheet) noexcept { + if (idxIt == idx.size()) { + return *pSubsheet; + } + return getSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[idx[idxIt]]); + } + + [[nodiscard]] + constexpr static auto &getSubSheet(const SubSheetIdx &idx, std::size_t idxIt, SubSheet *pSubsheet) noexcept { if (idxIt == idx.size()) { return *pSubsheet; } @@ -89,16 +100,21 @@ struct TileSheet { } [[nodiscard]] - constexpr auto &getSubSheet(const SubSheetIdx &idx, std::size_t idxIt, const SubSheet *pSubsheet) noexcept { - if (idxIt == idx.size()) { - return *pSubsheet; - } - return getSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[idx[idxIt]]); + constexpr auto &getSubSheet(const SubSheetIdx &idx) noexcept { + return getSubSheet(idx, 0, &subsheet); } [[nodiscard]] - constexpr auto &getSubSheet(const SubSheetIdx &idx) noexcept { - return getSubSheet(idx, 0, &subsheet); + constexpr static auto rmSubSheet(const SubSheetIdx &idx, std::size_t idxIt, SubSheet *pSubsheet) noexcept { + if (idxIt == idx.size() - 1) { + return pSubsheet->subsheets.erase(idx[idxIt]).error; + } + return rmSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[idx[idxIt]]); + } + + [[nodiscard]] + constexpr auto rmSubSheet(const SubSheetIdx &idx) noexcept { + return rmSubSheet(idx, 0, &subsheet); } [[nodiscard]] @@ -213,7 +229,6 @@ oxModelEnd() oxModelBegin(TileSheet::SubSheet) oxModelField(name); oxModelField(begin); - oxModelField(size); oxModelField(rows); oxModelField(columns); oxModelField(subsheets) diff --git a/src/nostalgia/core/typeconv.cpp b/src/nostalgia/core/typeconv.cpp index 37d5eb0c..7deec7c4 100644 --- a/src/nostalgia/core/typeconv.cpp +++ b/src/nostalgia/core/typeconv.cpp @@ -14,7 +14,6 @@ struct NostalgiaGraphicToTileSheetConverter: public Convertersubsheet.name = "Root"; dst->subsheet.rows = src->rows; dst->subsheet.columns = src->columns; - dst->subsheet.size = src->pixels.size(); dst->defaultPalette = std::move(src->defaultPalette); dst->pixels = std::move(src->pixels); return OxError(0);