Merge commit '0d61e5a064382a7076b62d32b25c70298ee0706e'

This commit is contained in:
Gary Talent 2024-01-31 23:18:13 -06:00
commit dbcd37d7ea
6 changed files with 49 additions and 8 deletions

View File

@ -73,7 +73,7 @@ struct TileSheetSetEntrySection {
oxModelBegin(TileSheetSetEntrySection) oxModelBegin(TileSheetSetEntrySection)
oxModelField(begin) oxModelField(begin)
oxModelField(size) oxModelField(tiles)
oxModelEnd() oxModelEnd()
struct TileSheetSetEntry { struct TileSheetSetEntry {
@ -92,7 +92,7 @@ struct TileSheetSet {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
static constexpr auto Preloadable = true; static constexpr auto Preloadable = true;
int bpp = 0; int32_t bpp = 0;
ox::Vector<TileSheetSetEntry> entries; ox::Vector<TileSheetSetEntry> entries;
}; };
@ -101,6 +101,8 @@ oxModelBegin(TileSheetSet)
oxModelField(entries) oxModelField(entries)
oxModelEnd() oxModelEnd()
void addEntry(TileSheetSet &set, ox::FileAddress path, int32_t begin = 0, int32_t size = -1) noexcept;
ox::Error loadBgPalette( ox::Error loadBgPalette(
Context &ctx, Context &ctx,
size_t palBank, size_t palBank,

View File

@ -60,6 +60,15 @@ constexpr size_t colors(Palette const&pal, size_t page = 0) noexcept {
return 0; 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) oxModelBegin(NostalgiaPalette)
oxModelField(colors) oxModelField(colors)
oxModelEnd() oxModelEnd()

View File

@ -159,7 +159,10 @@ struct TileSheet {
std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept; std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept;
[[nodiscard]] [[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]] [[nodiscard]]
size_t getTileIdx(TileSheet const&ts, SubSheetId id) noexcept; size_t getTileIdx(TileSheet const&ts, SubSheetId id) noexcept;

View File

@ -30,6 +30,17 @@ Palette const TileSheetEditorModel::s_defaultPalette = {
.pages = {ox::Vector<Color16>(128)}, .pages = {ox::Vector<Color16>(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): TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
m_ctx(ctx), m_ctx(ctx),
m_path(path), m_path(path),
@ -37,6 +48,7 @@ TileSheetEditorModel::TileSheetEditorModel(turbine::Context &ctx, ox::StringView
// ignore failure to load palette // ignore failure to load palette
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value), m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value),
m_undoStack(undoStack) { m_undoStack(undoStack) {
normalizeSubsheets(m_img.subsheet);
m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated); m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated);
m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId); m_undoStack.changeTriggered.connect(this, &TileSheetEditorModel::markUpdatedCmdId);
} }

View File

@ -14,6 +14,7 @@ std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept {
return ptToIdx(pt, ss.columns); return ptToIdx(pt, ss.columns);
} }
[[nodiscard]]
static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept { static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept {
if (ss.id == id) { if (ss.id == id) {
return &ss; return &ss;
@ -26,6 +27,24 @@ static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSh
return {}; 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 { TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept {
return getSubsheet(ts.subsheet, id); return getSubsheet(ts.subsheet, id);
} }
@ -42,7 +61,7 @@ static ox::Optional<size_t> getPixelIdx(
if (auto out = getPixelIdx(child, id, idx, bpp)) { if (auto out = getPixelIdx(child, id, idx, bpp)) {
return out; return out;
} }
idx += pixelCnt(ss, bpp); idx += pixelCnt(child, bpp);
} }
return {}; return {};
} }

View File

@ -284,10 +284,6 @@ class AssetRef {
return *m_obj; return *m_obj;
} }
constexpr T const&&operator*() const && noexcept {
return *m_obj;
}
constexpr T const*operator->() const noexcept { constexpr T const*operator->() const noexcept {
return m_obj; return m_obj;
} }