[nostalgia/core] Rename NostalgiaGraphic and NostalgiaPalette to TileSheet and Palette

This commit is contained in:
Gary Talent 2022-02-16 20:25:00 -06:00
parent 75f0b3a606
commit 462375aa5d
10 changed files with 35 additions and 35 deletions

View File

@ -23,14 +23,14 @@ constexpr uint16_t DispStat_irq_hblank = 1 << 4;
constexpr uint16_t DispStat_irq_vcount = 1 << 5; constexpr uint16_t DispStat_irq_vcount = 1 << 5;
struct GbaPaletteTarget { struct GbaPaletteTarget {
static constexpr auto TypeName = NostalgiaPalette::TypeName; static constexpr auto TypeName = Palette::TypeName;
static constexpr auto TypeVersion = NostalgiaPalette::TypeVersion; static constexpr auto TypeVersion = Palette::TypeVersion;
volatile uint16_t *palette = nullptr; volatile uint16_t *palette = nullptr;
}; };
struct GbaTileMapTarget { struct GbaTileMapTarget {
static constexpr auto TypeName = NostalgiaGraphic::TypeName; static constexpr auto TypeName = TileSheet::TypeName;
static constexpr auto TypeVersion = NostalgiaGraphic::TypeVersion; static constexpr auto TypeVersion = TileSheet::TypeVersion;
volatile uint16_t *bgCtl = nullptr; volatile uint16_t *bgCtl = nullptr;
ox::FileAddress defaultPalette; ox::FileAddress defaultPalette;
GbaPaletteTarget pal; GbaPaletteTarget pal;

View File

@ -29,13 +29,13 @@ enum class TileSheetSpace {
Sprite Sprite
}; };
struct NostalgiaPalette { struct Palette {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaPalette"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaPalette";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
ox::Vector<Color16> colors; ox::Vector<Color16> colors;
}; };
struct NostalgiaGraphic { struct TileSheet {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaGraphic"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaGraphic";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
int8_t bpp = 0; int8_t bpp = 0;
@ -43,7 +43,7 @@ struct NostalgiaGraphic {
int rows = 1; int rows = 1;
int columns = 1; int columns = 1;
ox::FileAddress defaultPalette; ox::FileAddress defaultPalette;
NostalgiaPalette pal; Palette pal;
ox::Vector<uint8_t> pixels; ox::Vector<uint8_t> pixels;
[[nodiscard]] [[nodiscard]]
@ -110,11 +110,11 @@ struct NostalgiaGraphic {
} }
}; };
oxModelBegin(NostalgiaPalette) oxModelBegin(Palette)
oxModelField(colors) oxModelField(colors)
oxModelEnd() oxModelEnd()
oxModelBegin(NostalgiaGraphic) oxModelBegin(TileSheet)
oxModelField(bpp) oxModelField(bpp)
oxModelField(rows) oxModelField(rows)
oxModelField(columns) oxModelField(columns)

View File

@ -71,10 +71,10 @@ class TileSheetEditor {
void resizeView(const geo::Vec2 &sz) noexcept; void resizeView(const geo::Vec2 &sz) noexcept;
[[nodiscard]] [[nodiscard]]
constexpr const NostalgiaGraphic &img() const noexcept; constexpr const TileSheet &img() const noexcept;
[[nodiscard]] [[nodiscard]]
constexpr const NostalgiaPalette &pal() const noexcept; constexpr const Palette &pal() const noexcept;
constexpr auto setPalIdx(auto palIdx) noexcept { constexpr auto setPalIdx(auto palIdx) noexcept {
m_palIdx = palIdx; m_palIdx = palIdx;
@ -118,11 +118,11 @@ class TileSheetEditor {
}; };
constexpr const NostalgiaGraphic &TileSheetEditor::img() const noexcept { constexpr const TileSheet &TileSheetEditor::img() const noexcept {
return m_model.img(); return m_model.img();
} }
constexpr const NostalgiaPalette &TileSheetEditor::pal() const noexcept { constexpr const Palette &TileSheetEditor::pal() const noexcept {
return m_model.pal(); return m_model.pal();
} }

View File

@ -9,9 +9,9 @@
namespace nostalgia::core { namespace nostalgia::core {
TileSheetEditorModel::TileSheetEditorModel(Context *ctx, const ox::String &path) { TileSheetEditorModel::TileSheetEditorModel(Context *ctx, const ox::String &path) {
oxRequireT(img, readObj<NostalgiaGraphic>(ctx, path.c_str())); oxRequireT(img, readObj<TileSheet>(ctx, path.c_str()));
m_img = *img; m_img = *img;
oxThrowError(readObj<NostalgiaPalette>(ctx, m_img.defaultPalette).moveTo(&m_pal)); oxThrowError(readObj<Palette>(ctx, m_img.defaultPalette).moveTo(&m_pal));
} }
void TileSheetEditorModel::cut() { void TileSheetEditorModel::cut() {

View File

@ -28,13 +28,13 @@ struct DrawCommand: public studio::UndoCommand {
uint32_t idx = 0; uint32_t idx = 0;
uint16_t oldPalIdx = 0; uint16_t oldPalIdx = 0;
}; };
NostalgiaGraphic *m_img = nullptr; TileSheet *m_img = nullptr;
ox::Vector<Change, 8> m_changes; ox::Vector<Change, 8> m_changes;
int m_palIdx = 0; int m_palIdx = 0;
bool *m_modelUpdated = nullptr; bool *m_modelUpdated = nullptr;
public: public:
constexpr DrawCommand(bool *updated, NostalgiaGraphic *img, std::size_t idx, int palIdx) noexcept { constexpr DrawCommand(bool *updated, TileSheet *img, std::size_t idx, int palIdx) noexcept {
m_modelUpdated = updated; m_modelUpdated = updated;
m_img = img; m_img = img;
m_changes.emplace_back(idx, m_img->getPixel(idx)); m_changes.emplace_back(idx, m_img->getPixel(idx));
@ -114,8 +114,8 @@ oxModelEnd()
class TileSheetEditorModel { class TileSheetEditorModel {
private: private:
NostalgiaGraphic m_img; TileSheet m_img;
AssetRef<NostalgiaPalette> m_pal; AssetRef<Palette> m_pal;
studio::UndoStack m_undoStack; studio::UndoStack m_undoStack;
DrawCommand *m_ongoingDrawCommand = nullptr; DrawCommand *m_ongoingDrawCommand = nullptr;
bool m_updated = false; bool m_updated = false;
@ -132,13 +132,13 @@ class TileSheetEditorModel {
void paste(); void paste();
[[nodiscard]] [[nodiscard]]
constexpr const NostalgiaGraphic &img() const noexcept; constexpr const TileSheet &img() const noexcept;
[[nodiscard]] [[nodiscard]]
constexpr NostalgiaGraphic &img() noexcept; constexpr TileSheet &img() noexcept;
[[nodiscard]] [[nodiscard]]
constexpr const NostalgiaPalette &pal() const noexcept; constexpr const Palette &pal() const noexcept;
void drawCommand(const geo::Point &pt, std::size_t palIdx) noexcept; void drawCommand(const geo::Point &pt, std::size_t palIdx) noexcept;
@ -175,15 +175,15 @@ class TileSheetEditorModel {
}; };
constexpr const NostalgiaGraphic &TileSheetEditorModel::img() const noexcept { constexpr const TileSheet &TileSheetEditorModel::img() const noexcept {
return m_img; return m_img;
} }
constexpr NostalgiaGraphic &TileSheetEditorModel::img() noexcept { constexpr TileSheet &TileSheetEditorModel::img() noexcept {
return m_img; return m_img;
} }
constexpr const NostalgiaPalette &TileSheetEditorModel::pal() const noexcept { constexpr const Palette &TileSheetEditorModel::pal() const noexcept {
return *m_pal; return *m_pal;
} }

View File

@ -30,7 +30,7 @@ void TileSheetGrid::draw(bool update, const geo::Vec2 &scroll) noexcept {
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(m_bufferSet.vertices.size() / VertexVboRowLength)); glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(m_bufferSet.vertices.size() / VertexVboRowLength));
} }
void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img) noexcept { void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet &img) noexcept {
// vao // vao
m_bufferSet.vao = glutils::generateVertexArrayObject(); m_bufferSet.vao = glutils::generateVertexArrayObject();
glBindVertexArray(m_bufferSet.vao); glBindVertexArray(m_bufferSet.vao);
@ -62,7 +62,7 @@ void TileSheetGrid::setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, f
memcpy(vbo, vertices, sizeof(vertices)); memcpy(vbo, vertices, sizeof(vertices));
} }
void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, glutils::BufferSet *bg) noexcept { void TileSheetGrid::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, glutils::BufferSet *bg) noexcept {
const auto pixSize = pixelSize(paneSize); const auto pixSize = pixelSize(paneSize);
const auto set = [bg, pixSize](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) { const auto set = [bg, pixSize](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) {
const auto vbo = &bg->vertices[i * VertexVboLength]; const auto vbo = &bg->vertices[i * VertexVboLength];

View File

@ -69,12 +69,12 @@ class TileSheetGrid {
void draw(bool update, const geo::Vec2 &scroll) noexcept; void draw(bool update, const geo::Vec2 &scroll) noexcept;
void initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img) noexcept; void initBufferSet(const geo::Vec2 &paneSize, const TileSheet &img) noexcept;
private: private:
static void setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::Vec2 &pixSize) noexcept; static void setBufferObject(geo::Point pt1, geo::Point pt2, Color32 c, float *vbo, const geo::Vec2 &pixSize) noexcept;
void setBufferObjects(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, glutils::BufferSet *bg) noexcept; void setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, glutils::BufferSet *bg) noexcept;
[[nodiscard]] [[nodiscard]]
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept;

View File

@ -29,7 +29,7 @@ void TileSheetPixels::draw(bool update, const geo::Vec2 &scroll) noexcept {
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m_bufferSet.elements.size()), GL_UNSIGNED_INT, nullptr); glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m_bufferSet.elements.size()), GL_UNSIGNED_INT, nullptr);
} }
void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal) noexcept { void TileSheetPixels::initBufferSet(const geo::Vec2 &paneSize, const TileSheet &img, const Palette &pal) noexcept {
// vao // vao
m_bufferSet.vao = glutils::generateVertexArrayObject(); m_bufferSet.vao = glutils::generateVertexArrayObject();
glBindVertexArray(m_bufferSet.vao); glBindVertexArray(m_bufferSet.vao);
@ -78,7 +78,7 @@ void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned v
memcpy(ebo, elms, sizeof(elms)); memcpy(ebo, elms, sizeof(elms));
} }
void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal, glutils::BufferSet *bg) noexcept { void TileSheetPixels::setBufferObjects(const geo::Vec2 &paneSize, const TileSheet &img, const Palette &pal, glutils::BufferSet *bg) noexcept {
const auto setPixel = [this, paneSize, bg, img, pal](std::size_t i, uint8_t p) { const auto setPixel = [this, paneSize, bg, img, pal](std::size_t i, uint8_t p) {
const auto color = pal.colors[p]; const auto color = pal.colors[p];
const auto pt = idxToPt(static_cast<int>(i), img.columns); const auto pt = idxToPt(static_cast<int>(i), img.columns);

View File

@ -48,7 +48,7 @@ class TileSheetPixels {
void draw(bool update, const geo::Vec2 &scroll) noexcept; void draw(bool update, const geo::Vec2 &scroll) noexcept;
void initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img, const NostalgiaPalette &pal) noexcept; void initBufferSet(const geo::Vec2 &paneSize, const TileSheet &img, const Palette &pal) noexcept;
[[nodiscard]] [[nodiscard]]
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept; geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept;
@ -56,7 +56,7 @@ class TileSheetPixels {
private: private:
void setPixelBufferObject(const geo::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) const noexcept; void setPixelBufferObject(const geo::Vec2 &paneS, unsigned vertexRow, float x, float y, Color16 color, float *vbo, GLuint *ebo) const noexcept;
void setBufferObjects(const geo::Vec2 &paneS, const NostalgiaGraphic &img, const NostalgiaPalette &pal, glutils::BufferSet *bg) noexcept; void setBufferObjects(const geo::Vec2 &paneS, const TileSheet &img, const Palette &pal, glutils::BufferSet *bg) noexcept;
}; };

View File

@ -27,8 +27,8 @@ ox::Error loadBgTileSheet(Context *ctx,
int section, int section,
const ox::FileAddress &tilesheetPath, const ox::FileAddress &tilesheetPath,
const ox::FileAddress &palettePath) noexcept { const ox::FileAddress &palettePath) noexcept {
oxRequire(tilesheet, readObj<NostalgiaGraphic>(ctx, tilesheetPath)); oxRequire(tilesheet, readObj<TileSheet>(ctx, tilesheetPath));
oxRequire(palette, readObj<NostalgiaPalette>(ctx, palettePath ? palettePath : tilesheet->defaultPalette)); oxRequire(palette, readObj<Palette>(ctx, palettePath ? palettePath : tilesheet->defaultPalette));
const unsigned bytesPerTile = tilesheet->bpp == 8 ? 64 : 32; const unsigned bytesPerTile = tilesheet->bpp == 8 ? 64 : 32;
const auto tiles = tilesheet->pixels.size() / bytesPerTile; const auto tiles = tilesheet->pixels.size() / bytesPerTile;
constexpr int width = 8; constexpr int width = 8;