[nostalgia/core] Remove id from TileSheetV3::Subsheet, add TileSheetV4
Some checks failed
Build / build (push) Has been cancelled

This commit is contained in:
Gary Talent 2023-12-26 17:28:41 -06:00
parent 9c19655ce2
commit 6a2954f82b
8 changed files with 125 additions and 27 deletions

View File

@ -61,7 +61,7 @@ struct TileSheetV2 {
using SubSheetId = int32_t;
struct TileSheet {
struct TileSheetV3 {
using SubSheetIdx = ox::Vector<std::size_t, 4>;
struct SubSheet {
@ -73,6 +73,36 @@ struct TileSheet {
int rows = 0;
ox::Vector<SubSheet> subsheets;
ox::Vector<uint8_t> pixels;
constexpr SubSheet() noexcept = default;
SubSheet(
SubSheetId pId,
ox::CRStringView pName,
int pColumns,
int pRows,
int bpp) noexcept;
};
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheet";
static constexpr auto TypeVersion = 3;
int8_t bpp = 4;
SubSheetId idIt = 0;
ox::FileAddress defaultPalette;
SubSheet subsheet{0, "Root", 1, 1, bpp};
};
struct TileSheet {
using SubSheetIdx = ox::Vector<std::size_t, 4>;
struct SubSheet {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheet.SubSheet";
static constexpr auto TypeVersion = 4;
SubSheetId id = 0;
ox::String name;
int columns = 0;
int rows = 0;
ox::Vector<SubSheet> subsheets;
ox::Vector<uint8_t> pixels;
constexpr SubSheet() noexcept = default;
constexpr SubSheet(SubSheet const&other) noexcept = default;
@ -189,7 +219,7 @@ struct TileSheet {
};
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheet";
static constexpr auto TypeVersion = 3;
static constexpr auto TypeVersion = 4;
int8_t bpp = 4;
SubSheetId idIt = 0;
ox::FileAddress defaultPalette;
@ -274,11 +304,11 @@ struct TileSheet {
};
using TileSheetV3 = TileSheet;
using TileSheetV4 = TileSheet;
struct CompactTileSheet {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.CompactTileSheet";
static constexpr auto TypeVersion = 1;
static constexpr auto TypeVersion = 2;
int8_t bpp = 0;
ox::FileAddress defaultPalette;
ox::Vector<uint8_t> pixels = {};
@ -294,9 +324,9 @@ oxModelBegin(TileSheetV1)
oxModelEnd()
oxModelBegin(TileSheetV2::SubSheet)
oxModelField(name);
oxModelField(rows);
oxModelField(columns);
oxModelField(name)
oxModelField(rows)
oxModelField(columns)
oxModelField(subsheets)
oxModelField(pixels)
oxModelEnd()
@ -308,10 +338,9 @@ oxModelBegin(TileSheetV2)
oxModelEnd()
oxModelBegin(TileSheetV3::SubSheet)
oxModelField(id);
oxModelField(name);
oxModelField(rows);
oxModelField(columns);
oxModelField(name)
oxModelField(rows)
oxModelField(columns)
oxModelField(subsheets)
oxModelField(pixels)
oxModelEnd()
@ -323,6 +352,22 @@ oxModelBegin(TileSheetV3)
oxModelField(subsheet)
oxModelEnd()
oxModelBegin(TileSheetV4::SubSheet)
oxModelField(id)
oxModelField(name)
oxModelField(rows)
oxModelField(columns)
oxModelField(subsheets)
oxModelField(pixels)
oxModelEnd()
oxModelBegin(TileSheetV4)
oxModelField(bpp)
oxModelField(idIt)
oxModelField(defaultPalette)
oxModelField(subsheet)
oxModelEnd()
oxModelBegin(CompactTileSheet)
oxModelField(bpp)
oxModelField(defaultPalette)

View File

@ -18,7 +18,8 @@ class KeelModule: public keel::Module {
private:
NostalgiaPaletteToPaletteConverter m_nostalgiaPaletteToPaletteConverter;
TileSheetV1ToTileSheetV2Converter m_tileSheetV1ToTileSheetV2Converter;
TileSheetV2ToTileSheetV3Converter m_tileSheetV2ToTileSheetConverter;
TileSheetV2ToTileSheetV3Converter m_tileSheetV2ToTileSheetV3Converter;
TileSheetV3ToTileSheetV4Converter m_tileSheetV3ToTileSheetV4Converter;
TileSheetToCompactTileSheetConverter m_tileSheetToCompactTileSheetConverter;
public:
@ -32,7 +33,8 @@ class KeelModule: public keel::Module {
return {
keel::generateTypeDesc<TileSheetV1>,
keel::generateTypeDesc<TileSheetV2>,
keel::generateTypeDesc<TileSheet>,
keel::generateTypeDesc<TileSheetV3>,
keel::generateTypeDesc<TileSheetV4>,
keel::generateTypeDesc<CompactTileSheet>,
keel::generateTypeDesc<Palette>,
};
@ -43,7 +45,8 @@ class KeelModule: public keel::Module {
return {
&m_nostalgiaPaletteToPaletteConverter,
&m_tileSheetV1ToTileSheetV2Converter,
&m_tileSheetV2ToTileSheetConverter,
&m_tileSheetV2ToTileSheetV3Converter,
&m_tileSheetV3ToTileSheetV4Converter,
&m_tileSheetToCompactTileSheetConverter,
};
}
@ -57,8 +60,9 @@ class KeelModule: public keel::Module {
const auto typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::buildTypeId<TileSheetV1>() ||
typeId == ox::buildTypeId<TileSheetV2>() ||
typeId == ox::buildTypeId<TileSheet>()) {
typeId == ox::buildTypeId<TileSheetV2>() ||
typeId == ox::buildTypeId<TileSheetV3>() ||
typeId == ox::buildTypeId<TileSheetV4>()) {
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
}

View File

@ -53,6 +53,34 @@ ox::Error TileSheetV2ToTileSheetV3Converter::convert(
return {};
}
void TileSheetV3ToTileSheetV4Converter::convertSubsheet(
TileSheetV3::SubSheet &src,
TileSheetV4::SubSheet &dst,
SubSheetId &idIt) noexcept {
dst.id = idIt;
dst.name = std::move(src.name);
dst.columns = src.columns;
dst.rows = src.rows;
dst.pixels = std::move(src.pixels);
++idIt;
dst.subsheets.resize(src.subsheets.size());
for (auto i = 0u; i < src.subsheets.size(); ++i) {
convertSubsheet(src.subsheets[i], dst.subsheets[i], idIt);
}
}
ox::Error TileSheetV3ToTileSheetV4Converter::convert(
keel::Context&,
TileSheetV3 &src,
TileSheetV4 &dst) const noexcept {
dst.bpp = src.bpp;
dst.idIt = src.idIt;
dst.defaultPalette = std::move(src.defaultPalette);
convertSubsheet(src.subsheet, dst.subsheet, dst.idIt);
return {};
}
ox::Error TileSheetToCompactTileSheetConverter::convert(
keel::Context&,
TileSheet &src,

View File

@ -25,11 +25,19 @@ class TileSheetV1ToTileSheetV2Converter: public keel::Converter<TileSheetV1, Til
};
class TileSheetV2ToTileSheetV3Converter: public keel::Converter<TileSheetV2, TileSheetV3> {
static void convertSubsheet(
TileSheetV2::SubSheet &src,
TileSheetV3::SubSheet &dst,
SubSheetId &idIt) noexcept;
ox::Error convert(keel::Context&, TileSheetV2 &src, TileSheetV3 &dst) const noexcept final;
};
class TileSheetV3ToTileSheetV4Converter: public keel::Converter<TileSheetV3, TileSheetV4> {
static void convertSubsheet(
TileSheetV2::SubSheet &src,
TileSheetV3::SubSheet &dst,
TileSheetV3::SubSheet &src,
TileSheetV4::SubSheet &dst,
SubSheetId &idIt) noexcept;
ox::Error convert(keel::Context&, TileSheetV2 &src, TileSheetV3 &dst) const noexcept final;
ox::Error convert(keel::Context&, TileSheetV3 &src, TileSheetV4 &dst) const noexcept final;
};
class TileSheetToCompactTileSheetConverter: public keel::Converter<TileSheet, CompactTileSheet> {

View File

@ -13,7 +13,7 @@ namespace nostalgia::core {
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
m_model(ctx, path, undoStack),
m_pixelsDrawer(&m_model) {
m_pixelsDrawer(m_model) {
// build shaders
oxThrowError(m_pixelsDrawer.buildShader());
oxThrowError(m_pixelGridDrawer.buildShader());

View File

@ -9,7 +9,7 @@
namespace nostalgia::core {
TileSheetPixels::TileSheetPixels(TileSheetEditorModel *model) noexcept: m_model(model) {
TileSheetPixels::TileSheetPixels(TileSheetEditorModel &model) noexcept: m_model(model) {
}
void TileSheetPixels::setPixelSizeMod(float sm) noexcept {
@ -94,15 +94,15 @@ void TileSheetPixels::setPixelBufferObject(
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
// set buffer lengths
const auto subSheet = m_model->activeSubSheet();
const auto pal = m_model->pal();
const auto subSheet = m_model.activeSubSheet();
const auto pal = m_model.pal();
const auto width = subSheet->columns * TileWidth;
const auto height = subSheet->rows * TileHeight;
const auto pixels = static_cast<unsigned>(width * height);
m_bufferSet.vertices.resize(pixels * VertexVboLength);
m_bufferSet.elements.resize(pixels * VertexEboLength);
// set pixels
subSheet->walkPixels(m_model->img().bpp, [&](std::size_t i, uint8_t p) {
subSheet->walkPixels(m_model.img().bpp, [&](std::size_t i, uint8_t p) {
auto color = pal->color(p);
const auto pt = idxToPt(static_cast<int>(i), subSheet->columns);
const auto fx = static_cast<float>(pt.x);
@ -115,7 +115,7 @@ void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
if (i * VertexEboLength + VertexEboLength > m_bufferSet.elements.size()) {
return;
}
if (m_model->pixelSelected(i)) {
if (m_model.pixelSelected(i)) {
const auto r = red16(color) / 2;
const auto g = (green16(color) + 20) / 2;
const auto b = (blue16(color) + 31) / 2;

View File

@ -43,10 +43,10 @@ class TileSheetPixels {
float m_pixelSizeMod = 1;
glutils::GLProgram m_shader;
glutils::BufferSet m_bufferSet;
const class TileSheetEditorModel *m_model = nullptr;
const class TileSheetEditorModel &m_model;
public:
explicit TileSheetPixels(class TileSheetEditorModel *model) noexcept;
explicit TileSheetPixels(class TileSheetEditorModel &model) noexcept;
void setPixelSizeMod(float sm) noexcept;

View File

@ -10,6 +10,19 @@
namespace nostalgia::core {
TileSheetV3::SubSheet::SubSheet(
SubSheetId pId,
ox::CRStringView pName,
int pColumns,
int pRows,
int bpp) noexcept:
id(pId),
name(pName),
columns(pColumns),
rows(pRows),
pixels(static_cast<std::size_t>(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) {
}
TileSheet::SubSheet::SubSheet(SubSheet &&other) noexcept:
id (other.id),
name (std::move(other.name)),