diff --git a/src/nostalgia/core/gfx.cpp b/src/nostalgia/core/gfx.cpp index a3956344..7ad75c8a 100644 --- a/src/nostalgia/core/gfx.cpp +++ b/src/nostalgia/core/gfx.cpp @@ -7,7 +7,7 @@ namespace nostalgia::core { // map ASCII values to the nostalgia charset -char charMap[128] = { +ox::Array charMap = { 0, 0, 0, diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index 5fb9d2a9..8bc1e478 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -4,8 +4,10 @@ #pragma once +#include #include #include + #include #include @@ -15,7 +17,7 @@ namespace nostalgia::core { -extern char charMap[128]; +extern ox::Array charMap; class Drawer { public: @@ -92,7 +94,8 @@ struct TileSheet { other.rows = 0; } constexpr SubSheet(const char *pName, int pColumns, int pRows, int bpp) noexcept: - name(pName), columns(pColumns), rows(pRows), pixels(static_cast(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) { + name(pName), columns(pColumns), rows(pRows), + pixels(static_cast(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) { } constexpr SubSheet(const char *pName, int pColumns, int pRows, ox::Vector pPixels) noexcept: name(pName), columns(pColumns), rows(pRows), pixels(std::move(pPixels)) { @@ -125,7 +128,7 @@ struct TileSheet { * Reads all pixels of this sheet or its children into the given pixel list * @param pixels */ - void readPixelsTo(ox::Vector *pPixels, int8_t bpp) const noexcept { + constexpr void readPixelsTo(ox::Vector *pPixels, int8_t bpp) const noexcept { if (subsheets.size()) { for (auto &s: subsheets) { s.readPixelsTo(pPixels); @@ -148,7 +151,7 @@ struct TileSheet { * Reads all pixels of this sheet or its children into the given pixel list * @param pixels */ - void readPixelsTo(ox::Vector *pPixels) const noexcept { + constexpr void readPixelsTo(ox::Vector *pPixels) const noexcept { if (subsheets.size()) { for (auto &s: subsheets) { s.readPixelsTo(pPixels); @@ -217,14 +220,19 @@ struct TileSheet { constexpr auto walkPixels(int8_t pBpp, auto callback) const noexcept { if (pBpp == 4) { - for (std::size_t i = 0; i < pixels.size(); ++i) { + const auto pixelCnt = ox::min(static_cast(columns * rows * PixelsPerTile) / 2, + pixels.size()); + //oxAssert(pixels.size() == pixelCnt, "Pixel count does not match rows and columns"); + for (std::size_t i = 0; i < pixelCnt; ++i) { const auto colorIdx1 = pixels[i] & 0xF; const auto colorIdx2 = pixels[i] >> 4; callback(i * 2 + 0, colorIdx1); callback(i * 2 + 1, colorIdx2); } } else { - for (std::size_t i = 0; i < pixels.size(); ++i) { + const auto pixelCnt = ox::min(static_cast(columns * rows * PixelsPerTile), + pixels.size()); + for (std::size_t i = 0; i < pixelCnt; ++i) { const auto p = pixels[i]; callback(i, p); } @@ -334,7 +342,8 @@ struct TileSheet { } [[nodiscard]] - constexpr static const auto &getSubSheet(const SubSheetIdx &idx, std::size_t idxIt, const SubSheet *pSubsheet) noexcept { + constexpr static const auto &getSubSheet(const SubSheetIdx &idx, std::size_t idxIt, + const SubSheet *pSubsheet) noexcept { if (idxIt == idx.size()) { return *pSubsheet; } @@ -502,7 +511,8 @@ void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept; /** * @param section describes which section of the selected TileSheetSpace to use (e.g. MEM_PALLETE_BG[section]) */ -ox::Error loadBgTileSheet(Context *ctx, unsigned cbb, const ox::FileAddress &tilesheet, const ox::FileAddress &palette = nullptr) noexcept; +ox::Error loadBgTileSheet(Context *ctx, unsigned cbb, const ox::FileAddress &tilesheet, + const ox::FileAddress &palette = nullptr) noexcept; ox::Error loadSpriteTileSheet(Context *ctx, unsigned section, @@ -517,7 +527,8 @@ void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept; void hideSprite(Context *ctx, unsigned) noexcept; -void setSprite(Context *ctx, unsigned idx, unsigned x, unsigned y, unsigned tileIdx, unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0) noexcept; +void setSprite(Context *ctx, unsigned idx, unsigned x, unsigned y, unsigned tileIdx, + unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0) noexcept; void setSprite(Context *ctx, const Sprite &s) noexcept;