[nostalgia/core] Rename NostalgiaGraphic and NostalgiaPalette to TileSheet and Palette
This commit is contained in:
parent
75f0b3a606
commit
462375aa5d
@ -23,14 +23,14 @@ constexpr uint16_t DispStat_irq_hblank = 1 << 4;
|
||||
constexpr uint16_t DispStat_irq_vcount = 1 << 5;
|
||||
|
||||
struct GbaPaletteTarget {
|
||||
static constexpr auto TypeName = NostalgiaPalette::TypeName;
|
||||
static constexpr auto TypeVersion = NostalgiaPalette::TypeVersion;
|
||||
static constexpr auto TypeName = Palette::TypeName;
|
||||
static constexpr auto TypeVersion = Palette::TypeVersion;
|
||||
volatile uint16_t *palette = nullptr;
|
||||
};
|
||||
|
||||
struct GbaTileMapTarget {
|
||||
static constexpr auto TypeName = NostalgiaGraphic::TypeName;
|
||||
static constexpr auto TypeVersion = NostalgiaGraphic::TypeVersion;
|
||||
static constexpr auto TypeName = TileSheet::TypeName;
|
||||
static constexpr auto TypeVersion = TileSheet::TypeVersion;
|
||||
volatile uint16_t *bgCtl = nullptr;
|
||||
ox::FileAddress defaultPalette;
|
||||
GbaPaletteTarget pal;
|
||||
|
@ -29,13 +29,13 @@ enum class TileSheetSpace {
|
||||
Sprite
|
||||
};
|
||||
|
||||
struct NostalgiaPalette {
|
||||
struct Palette {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaPalette";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
ox::Vector<Color16> colors;
|
||||
};
|
||||
|
||||
struct NostalgiaGraphic {
|
||||
struct TileSheet {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.NostalgiaGraphic";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
int8_t bpp = 0;
|
||||
@ -43,7 +43,7 @@ struct NostalgiaGraphic {
|
||||
int rows = 1;
|
||||
int columns = 1;
|
||||
ox::FileAddress defaultPalette;
|
||||
NostalgiaPalette pal;
|
||||
Palette pal;
|
||||
ox::Vector<uint8_t> pixels;
|
||||
|
||||
[[nodiscard]]
|
||||
@ -110,11 +110,11 @@ struct NostalgiaGraphic {
|
||||
}
|
||||
};
|
||||
|
||||
oxModelBegin(NostalgiaPalette)
|
||||
oxModelBegin(Palette)
|
||||
oxModelField(colors)
|
||||
oxModelEnd()
|
||||
|
||||
oxModelBegin(NostalgiaGraphic)
|
||||
oxModelBegin(TileSheet)
|
||||
oxModelField(bpp)
|
||||
oxModelField(rows)
|
||||
oxModelField(columns)
|
||||
|
@ -71,10 +71,10 @@ class TileSheetEditor {
|
||||
void resizeView(const geo::Vec2 &sz) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const NostalgiaGraphic &img() const noexcept;
|
||||
constexpr const TileSheet &img() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const NostalgiaPalette &pal() const noexcept;
|
||||
constexpr const Palette &pal() const noexcept;
|
||||
|
||||
constexpr auto setPalIdx(auto palIdx) noexcept {
|
||||
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();
|
||||
}
|
||||
|
||||
constexpr const NostalgiaPalette &TileSheetEditor::pal() const noexcept {
|
||||
constexpr const Palette &TileSheetEditor::pal() const noexcept {
|
||||
return m_model.pal();
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,9 @@
|
||||
namespace nostalgia::core {
|
||||
|
||||
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;
|
||||
oxThrowError(readObj<NostalgiaPalette>(ctx, m_img.defaultPalette).moveTo(&m_pal));
|
||||
oxThrowError(readObj<Palette>(ctx, m_img.defaultPalette).moveTo(&m_pal));
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::cut() {
|
||||
|
@ -28,13 +28,13 @@ struct DrawCommand: public studio::UndoCommand {
|
||||
uint32_t idx = 0;
|
||||
uint16_t oldPalIdx = 0;
|
||||
};
|
||||
NostalgiaGraphic *m_img = nullptr;
|
||||
TileSheet *m_img = nullptr;
|
||||
ox::Vector<Change, 8> m_changes;
|
||||
int m_palIdx = 0;
|
||||
bool *m_modelUpdated = nullptr;
|
||||
|
||||
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_img = img;
|
||||
m_changes.emplace_back(idx, m_img->getPixel(idx));
|
||||
@ -114,8 +114,8 @@ oxModelEnd()
|
||||
class TileSheetEditorModel {
|
||||
|
||||
private:
|
||||
NostalgiaGraphic m_img;
|
||||
AssetRef<NostalgiaPalette> m_pal;
|
||||
TileSheet m_img;
|
||||
AssetRef<Palette> m_pal;
|
||||
studio::UndoStack m_undoStack;
|
||||
DrawCommand *m_ongoingDrawCommand = nullptr;
|
||||
bool m_updated = false;
|
||||
@ -132,13 +132,13 @@ class TileSheetEditorModel {
|
||||
void paste();
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const NostalgiaGraphic &img() const noexcept;
|
||||
constexpr const TileSheet &img() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr NostalgiaGraphic &img() noexcept;
|
||||
constexpr TileSheet &img() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const NostalgiaPalette &pal() const noexcept;
|
||||
constexpr const Palette &pal() const 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;
|
||||
}
|
||||
|
||||
constexpr NostalgiaGraphic &TileSheetEditorModel::img() noexcept {
|
||||
constexpr TileSheet &TileSheetEditorModel::img() noexcept {
|
||||
return m_img;
|
||||
}
|
||||
|
||||
constexpr const NostalgiaPalette &TileSheetEditorModel::pal() const noexcept {
|
||||
constexpr const Palette &TileSheetEditorModel::pal() const noexcept {
|
||||
return *m_pal;
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const NostalgiaGraphic &img) noexcept {
|
||||
void TileSheetGrid::initBufferSet(const geo::Vec2 &paneSize, const TileSheet &img) noexcept {
|
||||
// vao
|
||||
m_bufferSet.vao = glutils::generateVertexArrayObject();
|
||||
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));
|
||||
}
|
||||
|
||||
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 set = [bg, pixSize](unsigned i, geo::Point pt1, geo::Point pt2, Color32 c) {
|
||||
const auto vbo = &bg->vertices[i * VertexVboLength];
|
||||
|
@ -69,12 +69,12 @@ class TileSheetGrid {
|
||||
|
||||
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:
|
||||
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]]
|
||||
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
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
|
||||
m_bufferSet.vao = glutils::generateVertexArrayObject();
|
||||
glBindVertexArray(m_bufferSet.vao);
|
||||
@ -78,7 +78,7 @@ void TileSheetPixels::setPixelBufferObject(const geo::Vec2 &paneSize, unsigned v
|
||||
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 color = pal.colors[p];
|
||||
const auto pt = idxToPt(static_cast<int>(i), img.columns);
|
||||
|
@ -48,7 +48,7 @@ class TileSheetPixels {
|
||||
|
||||
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]]
|
||||
geo::Vec2 pixelSize(const geo::Vec2 &paneSize) const noexcept;
|
||||
@ -56,7 +56,7 @@ class TileSheetPixels {
|
||||
private:
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
@ -27,8 +27,8 @@ ox::Error loadBgTileSheet(Context *ctx,
|
||||
int section,
|
||||
const ox::FileAddress &tilesheetPath,
|
||||
const ox::FileAddress &palettePath) noexcept {
|
||||
oxRequire(tilesheet, readObj<NostalgiaGraphic>(ctx, tilesheetPath));
|
||||
oxRequire(palette, readObj<NostalgiaPalette>(ctx, palettePath ? palettePath : tilesheet->defaultPalette));
|
||||
oxRequire(tilesheet, readObj<TileSheet>(ctx, tilesheetPath));
|
||||
oxRequire(palette, readObj<Palette>(ctx, palettePath ? palettePath : tilesheet->defaultPalette));
|
||||
const unsigned bytesPerTile = tilesheet->bpp == 8 ? 64 : 32;
|
||||
const auto tiles = tilesheet->pixels.size() / bytesPerTile;
|
||||
constexpr int width = 8;
|
||||
|
Loading…
x
Reference in New Issue
Block a user