[nostalgia/core] Remove id from TileSheetV3::Subsheet, add TileSheetV4
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
parent
9c19655ce2
commit
6a2954f82b
@ -61,7 +61,7 @@ struct TileSheetV2 {
|
|||||||
|
|
||||||
using SubSheetId = int32_t;
|
using SubSheetId = int32_t;
|
||||||
|
|
||||||
struct TileSheet {
|
struct TileSheetV3 {
|
||||||
using SubSheetIdx = ox::Vector<std::size_t, 4>;
|
using SubSheetIdx = ox::Vector<std::size_t, 4>;
|
||||||
|
|
||||||
struct SubSheet {
|
struct SubSheet {
|
||||||
@ -73,6 +73,36 @@ struct TileSheet {
|
|||||||
int rows = 0;
|
int rows = 0;
|
||||||
ox::Vector<SubSheet> subsheets;
|
ox::Vector<SubSheet> subsheets;
|
||||||
ox::Vector<uint8_t> pixels;
|
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() noexcept = default;
|
||||||
constexpr SubSheet(SubSheet const&other) 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 TypeName = "net.drinkingtea.nostalgia.core.TileSheet";
|
||||||
static constexpr auto TypeVersion = 3;
|
static constexpr auto TypeVersion = 4;
|
||||||
int8_t bpp = 4;
|
int8_t bpp = 4;
|
||||||
SubSheetId idIt = 0;
|
SubSheetId idIt = 0;
|
||||||
ox::FileAddress defaultPalette;
|
ox::FileAddress defaultPalette;
|
||||||
@ -274,11 +304,11 @@ struct TileSheet {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using TileSheetV3 = TileSheet;
|
using TileSheetV4 = TileSheet;
|
||||||
|
|
||||||
struct CompactTileSheet {
|
struct CompactTileSheet {
|
||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.CompactTileSheet";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.CompactTileSheet";
|
||||||
static constexpr auto TypeVersion = 1;
|
static constexpr auto TypeVersion = 2;
|
||||||
int8_t bpp = 0;
|
int8_t bpp = 0;
|
||||||
ox::FileAddress defaultPalette;
|
ox::FileAddress defaultPalette;
|
||||||
ox::Vector<uint8_t> pixels = {};
|
ox::Vector<uint8_t> pixels = {};
|
||||||
@ -294,9 +324,9 @@ oxModelBegin(TileSheetV1)
|
|||||||
oxModelEnd()
|
oxModelEnd()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV2::SubSheet)
|
oxModelBegin(TileSheetV2::SubSheet)
|
||||||
oxModelField(name);
|
oxModelField(name)
|
||||||
oxModelField(rows);
|
oxModelField(rows)
|
||||||
oxModelField(columns);
|
oxModelField(columns)
|
||||||
oxModelField(subsheets)
|
oxModelField(subsheets)
|
||||||
oxModelField(pixels)
|
oxModelField(pixels)
|
||||||
oxModelEnd()
|
oxModelEnd()
|
||||||
@ -308,10 +338,9 @@ oxModelBegin(TileSheetV2)
|
|||||||
oxModelEnd()
|
oxModelEnd()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV3::SubSheet)
|
oxModelBegin(TileSheetV3::SubSheet)
|
||||||
oxModelField(id);
|
oxModelField(name)
|
||||||
oxModelField(name);
|
oxModelField(rows)
|
||||||
oxModelField(rows);
|
oxModelField(columns)
|
||||||
oxModelField(columns);
|
|
||||||
oxModelField(subsheets)
|
oxModelField(subsheets)
|
||||||
oxModelField(pixels)
|
oxModelField(pixels)
|
||||||
oxModelEnd()
|
oxModelEnd()
|
||||||
@ -323,6 +352,22 @@ oxModelBegin(TileSheetV3)
|
|||||||
oxModelField(subsheet)
|
oxModelField(subsheet)
|
||||||
oxModelEnd()
|
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)
|
oxModelBegin(CompactTileSheet)
|
||||||
oxModelField(bpp)
|
oxModelField(bpp)
|
||||||
oxModelField(defaultPalette)
|
oxModelField(defaultPalette)
|
||||||
|
@ -18,7 +18,8 @@ class KeelModule: public keel::Module {
|
|||||||
private:
|
private:
|
||||||
NostalgiaPaletteToPaletteConverter m_nostalgiaPaletteToPaletteConverter;
|
NostalgiaPaletteToPaletteConverter m_nostalgiaPaletteToPaletteConverter;
|
||||||
TileSheetV1ToTileSheetV2Converter m_tileSheetV1ToTileSheetV2Converter;
|
TileSheetV1ToTileSheetV2Converter m_tileSheetV1ToTileSheetV2Converter;
|
||||||
TileSheetV2ToTileSheetV3Converter m_tileSheetV2ToTileSheetConverter;
|
TileSheetV2ToTileSheetV3Converter m_tileSheetV2ToTileSheetV3Converter;
|
||||||
|
TileSheetV3ToTileSheetV4Converter m_tileSheetV3ToTileSheetV4Converter;
|
||||||
TileSheetToCompactTileSheetConverter m_tileSheetToCompactTileSheetConverter;
|
TileSheetToCompactTileSheetConverter m_tileSheetToCompactTileSheetConverter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -32,7 +33,8 @@ class KeelModule: public keel::Module {
|
|||||||
return {
|
return {
|
||||||
keel::generateTypeDesc<TileSheetV1>,
|
keel::generateTypeDesc<TileSheetV1>,
|
||||||
keel::generateTypeDesc<TileSheetV2>,
|
keel::generateTypeDesc<TileSheetV2>,
|
||||||
keel::generateTypeDesc<TileSheet>,
|
keel::generateTypeDesc<TileSheetV3>,
|
||||||
|
keel::generateTypeDesc<TileSheetV4>,
|
||||||
keel::generateTypeDesc<CompactTileSheet>,
|
keel::generateTypeDesc<CompactTileSheet>,
|
||||||
keel::generateTypeDesc<Palette>,
|
keel::generateTypeDesc<Palette>,
|
||||||
};
|
};
|
||||||
@ -43,7 +45,8 @@ class KeelModule: public keel::Module {
|
|||||||
return {
|
return {
|
||||||
&m_nostalgiaPaletteToPaletteConverter,
|
&m_nostalgiaPaletteToPaletteConverter,
|
||||||
&m_tileSheetV1ToTileSheetV2Converter,
|
&m_tileSheetV1ToTileSheetV2Converter,
|
||||||
&m_tileSheetV2ToTileSheetConverter,
|
&m_tileSheetV2ToTileSheetV3Converter,
|
||||||
|
&m_tileSheetV3ToTileSheetV4Converter,
|
||||||
&m_tileSheetToCompactTileSheetConverter,
|
&m_tileSheetToCompactTileSheetConverter,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -57,8 +60,9 @@ class KeelModule: public keel::Module {
|
|||||||
const auto typeId = ox::buildTypeId(
|
const auto typeId = ox::buildTypeId(
|
||||||
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
|
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
|
||||||
if (typeId == ox::buildTypeId<TileSheetV1>() ||
|
if (typeId == ox::buildTypeId<TileSheetV1>() ||
|
||||||
typeId == ox::buildTypeId<TileSheetV2>() ||
|
typeId == ox::buildTypeId<TileSheetV2>() ||
|
||||||
typeId == ox::buildTypeId<TileSheet>()) {
|
typeId == ox::buildTypeId<TileSheetV3>() ||
|
||||||
|
typeId == ox::buildTypeId<TileSheetV4>()) {
|
||||||
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
|
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
|
||||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,34 @@ ox::Error TileSheetV2ToTileSheetV3Converter::convert(
|
|||||||
return {};
|
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(
|
ox::Error TileSheetToCompactTileSheetConverter::convert(
|
||||||
keel::Context&,
|
keel::Context&,
|
||||||
TileSheet &src,
|
TileSheet &src,
|
||||||
|
@ -25,11 +25,19 @@ class TileSheetV1ToTileSheetV2Converter: public keel::Converter<TileSheetV1, Til
|
|||||||
};
|
};
|
||||||
|
|
||||||
class TileSheetV2ToTileSheetV3Converter: public keel::Converter<TileSheetV2, TileSheetV3> {
|
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(
|
static void convertSubsheet(
|
||||||
TileSheetV2::SubSheet &src,
|
TileSheetV3::SubSheet &src,
|
||||||
TileSheetV3::SubSheet &dst,
|
TileSheetV4::SubSheet &dst,
|
||||||
SubSheetId &idIt) noexcept;
|
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> {
|
class TileSheetToCompactTileSheetConverter: public keel::Converter<TileSheet, CompactTileSheet> {
|
||||||
|
@ -13,7 +13,7 @@ namespace nostalgia::core {
|
|||||||
|
|
||||||
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
|
TileSheetEditorView::TileSheetEditorView(turbine::Context &ctx, ox::StringView path, studio::UndoStack &undoStack):
|
||||||
m_model(ctx, path, undoStack),
|
m_model(ctx, path, undoStack),
|
||||||
m_pixelsDrawer(&m_model) {
|
m_pixelsDrawer(m_model) {
|
||||||
// build shaders
|
// build shaders
|
||||||
oxThrowError(m_pixelsDrawer.buildShader());
|
oxThrowError(m_pixelsDrawer.buildShader());
|
||||||
oxThrowError(m_pixelGridDrawer.buildShader());
|
oxThrowError(m_pixelGridDrawer.buildShader());
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
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 {
|
void TileSheetPixels::setPixelSizeMod(float sm) noexcept {
|
||||||
@ -94,15 +94,15 @@ void TileSheetPixels::setPixelBufferObject(
|
|||||||
|
|
||||||
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
|
||||||
// set buffer lengths
|
// set buffer lengths
|
||||||
const auto subSheet = m_model->activeSubSheet();
|
const auto subSheet = m_model.activeSubSheet();
|
||||||
const auto pal = m_model->pal();
|
const auto pal = m_model.pal();
|
||||||
const auto width = subSheet->columns * TileWidth;
|
const auto width = subSheet->columns * TileWidth;
|
||||||
const auto height = subSheet->rows * TileHeight;
|
const auto height = subSheet->rows * TileHeight;
|
||||||
const auto pixels = static_cast<unsigned>(width * height);
|
const auto pixels = static_cast<unsigned>(width * height);
|
||||||
m_bufferSet.vertices.resize(pixels * VertexVboLength);
|
m_bufferSet.vertices.resize(pixels * VertexVboLength);
|
||||||
m_bufferSet.elements.resize(pixels * VertexEboLength);
|
m_bufferSet.elements.resize(pixels * VertexEboLength);
|
||||||
// set pixels
|
// 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);
|
auto color = pal->color(p);
|
||||||
const auto pt = idxToPt(static_cast<int>(i), subSheet->columns);
|
const auto pt = idxToPt(static_cast<int>(i), subSheet->columns);
|
||||||
const auto fx = static_cast<float>(pt.x);
|
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()) {
|
if (i * VertexEboLength + VertexEboLength > m_bufferSet.elements.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_model->pixelSelected(i)) {
|
if (m_model.pixelSelected(i)) {
|
||||||
const auto r = red16(color) / 2;
|
const auto r = red16(color) / 2;
|
||||||
const auto g = (green16(color) + 20) / 2;
|
const auto g = (green16(color) + 20) / 2;
|
||||||
const auto b = (blue16(color) + 31) / 2;
|
const auto b = (blue16(color) + 31) / 2;
|
||||||
|
@ -43,10 +43,10 @@ class TileSheetPixels {
|
|||||||
float m_pixelSizeMod = 1;
|
float m_pixelSizeMod = 1;
|
||||||
glutils::GLProgram m_shader;
|
glutils::GLProgram m_shader;
|
||||||
glutils::BufferSet m_bufferSet;
|
glutils::BufferSet m_bufferSet;
|
||||||
const class TileSheetEditorModel *m_model = nullptr;
|
const class TileSheetEditorModel &m_model;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TileSheetPixels(class TileSheetEditorModel *model) noexcept;
|
explicit TileSheetPixels(class TileSheetEditorModel &model) noexcept;
|
||||||
|
|
||||||
void setPixelSizeMod(float sm) noexcept;
|
void setPixelSizeMod(float sm) noexcept;
|
||||||
|
|
||||||
|
@ -10,6 +10,19 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
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:
|
TileSheet::SubSheet::SubSheet(SubSheet &&other) noexcept:
|
||||||
id (other.id),
|
id (other.id),
|
||||||
name (std::move(other.name)),
|
name (std::move(other.name)),
|
||||||
|
Loading…
Reference in New Issue
Block a user