[nostalgia/core] Move most TileSheet functions to cpp file
This commit is contained in:
parent
5eaa86a934
commit
4ab710b155
@ -7,6 +7,7 @@
|
|||||||
#include <ox/std/array.hpp>
|
#include <ox/std/array.hpp>
|
||||||
#include <ox/std/point.hpp>
|
#include <ox/std/point.hpp>
|
||||||
#include <ox/std/size.hpp>
|
#include <ox/std/size.hpp>
|
||||||
|
#include <ox/std/span.hpp>
|
||||||
#include <ox/std/types.hpp>
|
#include <ox/std/types.hpp>
|
||||||
#include <ox/model/def.hpp>
|
#include <ox/model/def.hpp>
|
||||||
|
|
||||||
@ -73,97 +74,39 @@ struct TileSheet {
|
|||||||
ox::Vector<uint8_t> pixels;
|
ox::Vector<uint8_t> pixels;
|
||||||
|
|
||||||
constexpr SubSheet() noexcept = default;
|
constexpr SubSheet() noexcept = default;
|
||||||
constexpr SubSheet(const SubSheet &other) noexcept {
|
constexpr SubSheet(SubSheet const&other) noexcept = default;
|
||||||
id = other.id;
|
SubSheet(SubSheet &&other) noexcept;
|
||||||
name = other.name;
|
SubSheet(
|
||||||
columns = other.columns;
|
|
||||||
rows = other.rows;
|
|
||||||
subsheets = other.subsheets;
|
|
||||||
pixels = other.pixels;
|
|
||||||
}
|
|
||||||
constexpr SubSheet(SubSheet &&other) noexcept {
|
|
||||||
id = other.id;
|
|
||||||
name = std::move(other.name);
|
|
||||||
columns = other.columns;
|
|
||||||
rows = other.rows;
|
|
||||||
subsheets = std::move(other.subsheets);
|
|
||||||
pixels = std::move(other.pixels);
|
|
||||||
other.name = "";
|
|
||||||
other.columns = 0;
|
|
||||||
other.rows = 0;
|
|
||||||
}
|
|
||||||
constexpr SubSheet(
|
|
||||||
SubSheetId pId,
|
SubSheetId pId,
|
||||||
ox::CRStringView pName,
|
ox::CRStringView pName,
|
||||||
int pColumns,
|
int pColumns,
|
||||||
int pRows,
|
int pRows,
|
||||||
int bpp) noexcept:
|
int bpp) noexcept;
|
||||||
id(pId), name(pName), columns(pColumns), rows(pRows),
|
SubSheet(
|
||||||
pixels(static_cast<std::size_t>(columns * rows * PixelsPerTile) / (bpp == 4 ? 2u : 1u)) {
|
|
||||||
}
|
|
||||||
constexpr SubSheet(
|
|
||||||
SubSheetId pId,
|
SubSheetId pId,
|
||||||
ox::CRStringView pName,
|
ox::CRStringView pName,
|
||||||
int pColumns,
|
int pColumns,
|
||||||
int pRows,
|
int pRows,
|
||||||
ox::Vector<uint8_t> pPixels) noexcept:
|
ox::Vector<uint8_t> pPixels) noexcept;
|
||||||
id(pId), name(pName), columns(pColumns), rows(pRows), pixels(std::move(pPixels)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr SubSheet &operator=(const SubSheet &other) noexcept = default;
|
constexpr SubSheet &operator=(const SubSheet &other) noexcept = default;
|
||||||
|
|
||||||
constexpr SubSheet &operator=(SubSheet &&other) noexcept {
|
SubSheet &operator=(SubSheet &&other) noexcept;
|
||||||
name = std::move(other.name);
|
|
||||||
columns = other.columns;
|
|
||||||
rows = other.rows;
|
|
||||||
subsheets = std::move(other.subsheets);
|
|
||||||
pixels = std::move(other.pixels);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto idx(const ox::Point &pt) const noexcept {
|
std::size_t idx(const ox::Point &pt) const noexcept;
|
||||||
return ptToIdx(pt, columns);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads all pixels of this sheet or its children into the given pixel list
|
* Reads all pixels of this sheet or its children into the given pixel list
|
||||||
* @param pixels
|
* @param pixels
|
||||||
*/
|
*/
|
||||||
constexpr void readPixelsTo(ox::Vector<uint8_t> *pPixels, int8_t pBpp) const noexcept {
|
void readPixelsTo(ox::Vector<uint8_t> *pPixels, int8_t pBpp) const noexcept;
|
||||||
if (!subsheets.empty()) {
|
|
||||||
for (auto &s: subsheets) {
|
|
||||||
s.readPixelsTo(pPixels);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pBpp == 4) {
|
|
||||||
for (auto p: this->pixels) {
|
|
||||||
pPixels->emplace_back(static_cast<uint8_t>(p & 0b1111));
|
|
||||||
pPixels->emplace_back(static_cast<uint8_t>(p >> 4));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (auto p: this->pixels) {
|
|
||||||
pPixels->emplace_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads all pixels of this sheet or its children into the given pixel list
|
* Reads all pixels of this sheet or its children into the given pixel list
|
||||||
* @param pixels
|
* @param pixels
|
||||||
*/
|
*/
|
||||||
constexpr void readPixelsTo(ox::Vector<uint8_t> *pPixels) const noexcept {
|
void readPixelsTo(ox::Vector<uint8_t> *pPixels) const noexcept;
|
||||||
if (!subsheets.empty()) {
|
|
||||||
for (auto &s: subsheets) {
|
|
||||||
s.readPixelsTo(pPixels);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (auto p : this->pixels) {
|
|
||||||
pPixels->emplace_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr std::size_t size() const noexcept {
|
constexpr std::size_t size() const noexcept {
|
||||||
@ -171,54 +114,25 @@ struct TileSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr std::size_t unusedPixels() const noexcept {
|
std::size_t unusedPixels() const noexcept;
|
||||||
std::size_t childrenSize = 0;
|
|
||||||
for (auto &c : subsheets) {
|
|
||||||
childrenSize += c.size();
|
|
||||||
}
|
|
||||||
return size() - childrenSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr uint8_t getPixel4Bpp(std::size_t idx) const noexcept {
|
uint8_t getPixel4Bpp(std::size_t idx) const noexcept;
|
||||||
if (idx & 1) {
|
|
||||||
return this->pixels[idx / 2] >> 4;
|
|
||||||
} else {
|
|
||||||
return this->pixels[idx / 2] & 0b0000'1111;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr uint8_t getPixel8Bpp(std::size_t idx) const noexcept {
|
uint8_t getPixel8Bpp(std::size_t idx) const noexcept;
|
||||||
return this->pixels[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto getPixel(int8_t pBpp, std::size_t idx) const noexcept {
|
uint8_t getPixel(int8_t pBpp, std::size_t idx) const noexcept;
|
||||||
if (pBpp == 4) {
|
|
||||||
return getPixel4Bpp(idx);
|
|
||||||
} else {
|
|
||||||
return getPixel8Bpp(idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto getPixel4Bpp(const ox::Point &pt) const noexcept {
|
uint8_t getPixel4Bpp(const ox::Point &pt) const noexcept;
|
||||||
const auto idx = ptToIdx(pt, columns);
|
|
||||||
return getPixel4Bpp(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto getPixel8Bpp(const ox::Point &pt) const noexcept {
|
uint8_t getPixel8Bpp(const ox::Point &pt) const noexcept;
|
||||||
const auto idx = ptToIdx(pt, columns);
|
|
||||||
return getPixel8Bpp(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto getPixel(int8_t pBpp, const ox::Point &pt) const noexcept {
|
uint8_t getPixel(int8_t pBpp, const ox::Point &pt) const noexcept;
|
||||||
const auto idx = ptToIdx(pt, columns);
|
|
||||||
return getPixel(pBpp, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr auto walkPixels(int8_t pBpp, auto callback) const noexcept {
|
constexpr auto walkPixels(int8_t pBpp, auto callback) const noexcept {
|
||||||
if (pBpp == 4) {
|
if (pBpp == 4) {
|
||||||
@ -242,36 +156,11 @@ struct TileSheet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void setPixel(int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept {
|
void setPixel(int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept;
|
||||||
auto &pixel = this->pixels[static_cast<std::size_t>(idx / 2)];
|
|
||||||
if (pBpp == 4) {
|
|
||||||
if (idx & 1) {
|
|
||||||
pixel = static_cast<uint8_t>((pixel & 0b0000'1111) | (palIdx << 4));
|
|
||||||
} else {
|
|
||||||
pixel = (pixel & 0b1111'0000) | (palIdx);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pixel = palIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void setPixel(int8_t pBpp, const ox::Point &pt, uint8_t palIdx) noexcept {
|
void setPixel(int8_t pBpp, const ox::Point &pt, uint8_t palIdx) noexcept;
|
||||||
const auto idx = ptToIdx(pt, columns);
|
|
||||||
setPixel(pBpp, idx, palIdx);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr auto setPixelCount(int8_t pBpp, std::size_t cnt) noexcept {
|
ox::Error setPixelCount(int8_t pBpp, std::size_t cnt) noexcept;
|
||||||
switch (pBpp) {
|
|
||||||
case 4:
|
|
||||||
pixels.resize(cnt / 2);
|
|
||||||
return OxError(0);
|
|
||||||
case 8:
|
|
||||||
pixels.resize(cnt);
|
|
||||||
return OxError(0);
|
|
||||||
default:
|
|
||||||
return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a count of the pixels in this sheet, and not that of its children.
|
* Gets a count of the pixels in this sheet, and not that of its children.
|
||||||
@ -279,66 +168,25 @@ struct TileSheet {
|
|||||||
* @return a count of the pixels in this sheet
|
* @return a count of the pixels in this sheet
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr unsigned pixelCnt(int8_t pBpp) const noexcept {
|
unsigned pixelCnt(int8_t pBpp) const noexcept;
|
||||||
const auto pixelsSize = static_cast<unsigned>(pixels.size());
|
|
||||||
return pBpp == 4 ? pixelsSize * 2 : pixelsSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the offset in tiles of the desired subsheet.
|
* Gets the offset in tiles of the desired subsheet.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Result<unsigned> getTileOffset(
|
ox::Result<unsigned> getTileOffset(
|
||||||
const auto &pNamePath,
|
ox::SpanView<ox::StringView> const&pNamePath,
|
||||||
int8_t pBpp,
|
int8_t pBpp,
|
||||||
std::size_t pIt = 0,
|
std::size_t pIt = 0,
|
||||||
unsigned pCurrentTotal = 0) const noexcept {
|
unsigned pCurrentTotal = 0) const noexcept;
|
||||||
// pIt == pNamePath.size() - 1 &&
|
|
||||||
if (name != pNamePath[pIt]) {
|
|
||||||
return OxError(2, "Wrong branch");
|
|
||||||
}
|
|
||||||
if (pIt == pNamePath.size() - 1) {
|
|
||||||
return pCurrentTotal;
|
|
||||||
}
|
|
||||||
for (auto &sub : subsheets) {
|
|
||||||
auto [offset, err] = sub.getTileOffset(
|
|
||||||
pNamePath, pBpp, pIt + 1, pCurrentTotal);
|
|
||||||
if (!err) {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
pCurrentTotal += sub.pixelCnt(pBpp) / PixelsPerTile;
|
|
||||||
}
|
|
||||||
return OxError(1, "SubSheet not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Result<SubSheetId> getIdFor(
|
ox::Result<SubSheetId> getIdFor(
|
||||||
const auto &pNamePath,
|
ox::SpanView<ox::StringView> const&pNamePath,
|
||||||
std::size_t pIt = 0) const noexcept {
|
std::size_t pIt = 0) const noexcept;
|
||||||
for (auto &sub : subsheets) {
|
|
||||||
if (sub.name == pNamePath[pIt]) {
|
|
||||||
if (pIt == pNamePath.size()) {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
return getIdFor(pNamePath, pIt + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return OxError(1, "SubSheet not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ox::Result<ox::StringView> getNameFor(SubSheetId pId) const noexcept {
|
ox::Result<ox::StringView> getNameFor(SubSheetId pId) const noexcept;
|
||||||
if (id == pId) {
|
|
||||||
return ox::StringView(name);
|
|
||||||
}
|
|
||||||
for (const auto &sub : subsheets) {
|
|
||||||
const auto [name, err] = sub.getNameFor(pId);
|
|
||||||
if (!err) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return OxError(1, "SubSheet not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -358,43 +206,15 @@ struct TileSheet {
|
|||||||
subsheet(std::move(other.subsheet)) {
|
subsheet(std::move(other.subsheet)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto &operator=(const TileSheet &other) noexcept {
|
TileSheet &operator=(const TileSheet &other) noexcept;
|
||||||
if (this != &other) {
|
|
||||||
bpp = other.bpp;
|
TileSheet &operator=(TileSheet &&other) noexcept;
|
||||||
idIt = other.idIt;
|
|
||||||
defaultPalette = other.defaultPalette;
|
|
||||||
subsheet = other.subsheet;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
inline auto &operator=(TileSheet &&other) noexcept {
|
|
||||||
bpp = other.bpp;
|
|
||||||
idIt = other.idIt;
|
|
||||||
defaultPalette = std::move(other.defaultPalette);
|
|
||||||
subsheet = std::move(other.subsheet);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto validateSubSheetIdx(
|
SubSheetIdx validateSubSheetIdx(
|
||||||
const SubSheetIdx &pIdx,
|
const SubSheetIdx &pIdx,
|
||||||
std::size_t pIdxIt,
|
std::size_t pIdxIt,
|
||||||
const SubSheet *pSubsheet) noexcept {
|
const SubSheet *pSubsheet) noexcept;
|
||||||
if (pIdxIt == pIdx.size()) {
|
|
||||||
return pIdx;
|
|
||||||
}
|
|
||||||
const auto currentIdx = pIdx[pIdxIt];
|
|
||||||
if (pSubsheet->subsheets.size() <= currentIdx) {
|
|
||||||
auto out = pIdx;
|
|
||||||
if (!pSubsheet->subsheets.empty()) {
|
|
||||||
*out.back().value = pSubsheet->subsheets.size() - 1;
|
|
||||||
} else {
|
|
||||||
out.pop_back();
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
return validateSubSheetIdx(pIdx, pIdxIt + 1, &pSubsheet->subsheets[pIdx[pIdxIt]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* validateSubSheetIdx takes a SubSheetIdx and moves the index to the
|
* validateSubSheetIdx takes a SubSheetIdx and moves the index to the
|
||||||
@ -404,112 +224,55 @@ struct TileSheet {
|
|||||||
* @return a valid version of idx
|
* @return a valid version of idx
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto validateSubSheetIdx(const SubSheetIdx &idx) noexcept {
|
SubSheetIdx validateSubSheetIdx(const SubSheetIdx &idx) noexcept;
|
||||||
return validateSubSheetIdx(idx, 0, &subsheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static const SubSheet &getSubSheet(
|
static const SubSheet &getSubSheet(
|
||||||
const SubSheetIdx &idx,
|
const SubSheetIdx &idx,
|
||||||
std::size_t idxIt,
|
std::size_t idxIt,
|
||||||
const SubSheet *pSubsheet) noexcept {
|
const SubSheet *pSubsheet) noexcept;
|
||||||
if (idxIt == idx.size()) {
|
|
||||||
return *pSubsheet;
|
|
||||||
}
|
|
||||||
const auto currentIdx = idx[idxIt];
|
|
||||||
if (pSubsheet->subsheets.size() < currentIdx) {
|
|
||||||
return *pSubsheet;
|
|
||||||
}
|
|
||||||
return getSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[currentIdx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static SubSheet &getSubSheet(
|
static SubSheet &getSubSheet(
|
||||||
const SubSheetIdx &idx,
|
const SubSheetIdx &idx,
|
||||||
std::size_t idxIt,
|
std::size_t idxIt,
|
||||||
SubSheet *pSubsheet) noexcept {
|
SubSheet *pSubsheet) noexcept;
|
||||||
if (idxIt == idx.size()) {
|
|
||||||
return *pSubsheet;
|
|
||||||
}
|
|
||||||
return getSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[idx[idxIt]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr const SubSheet &getSubSheet(const SubSheetIdx &idx) const noexcept {
|
const SubSheet &getSubSheet(const SubSheetIdx &idx) const noexcept;
|
||||||
return getSubSheet(idx, 0, &subsheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr SubSheet &getSubSheet(const SubSheetIdx &idx) noexcept {
|
SubSheet &getSubSheet(const SubSheetIdx &idx) noexcept;
|
||||||
return getSubSheet(idx, 0, &subsheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ox::Error addSubSheet(const SubSheetIdx &idx) noexcept {
|
ox::Error addSubSheet(const SubSheetIdx &idx) noexcept;
|
||||||
auto &parent = getSubSheet(idx);
|
|
||||||
if (parent.subsheets.size() < 2) {
|
|
||||||
parent.subsheets.emplace_back(idIt++, ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1, bpp);
|
|
||||||
} else {
|
|
||||||
parent.subsheets.emplace_back(idIt++, "Subsheet 0", parent.columns, parent.rows, bpp);
|
|
||||||
parent.subsheets.emplace_back(idIt++, "Subsheet 1", 1, 1, bpp);
|
|
||||||
}
|
|
||||||
return OxError(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static auto rmSubSheet(
|
static ox::Error rmSubSheet(
|
||||||
const SubSheetIdx &idx,
|
const SubSheetIdx &idx,
|
||||||
std::size_t idxIt,
|
std::size_t idxIt,
|
||||||
SubSheet *pSubsheet) noexcept {
|
SubSheet *pSubsheet) noexcept;
|
||||||
if (idxIt == idx.size() - 1) {
|
|
||||||
return pSubsheet->subsheets.erase(idx[idxIt]).error;
|
|
||||||
}
|
|
||||||
return rmSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[idx[idxIt]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto rmSubSheet(const SubSheetIdx &idx) noexcept {
|
ox::Error rmSubSheet(const SubSheetIdx &idx) noexcept;
|
||||||
return rmSubSheet(idx, 0, &subsheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto getPixel4Bpp(
|
uint8_t getPixel4Bpp(
|
||||||
const ox::Point &pt,
|
const ox::Point &pt,
|
||||||
const SubSheetIdx &subsheetIdx) const noexcept {
|
const SubSheetIdx &subsheetIdx) const noexcept;
|
||||||
oxAssert(bpp == 4, "TileSheet::getPixel4Bpp: wrong bpp");
|
|
||||||
auto &s = this->getSubSheet(subsheetIdx);
|
|
||||||
const auto idx = ptToIdx(pt, s.columns);
|
|
||||||
return s.getPixel4Bpp(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto getPixel8Bpp(
|
uint8_t getPixel8Bpp(
|
||||||
const ox::Point &pt,
|
const ox::Point &pt,
|
||||||
const SubSheetIdx &subsheetIdx) const noexcept {
|
const SubSheetIdx &subsheetIdx) const noexcept;
|
||||||
oxAssert(bpp == 8, "TileSheet::getPixel8Bpp: wrong bpp");
|
|
||||||
auto &s = this->getSubSheet(subsheetIdx);
|
ox::Result<SubSheetId> getIdFor(ox::CRStringView path) const noexcept;
|
||||||
const auto idx = ptToIdx(pt, s.columns);
|
|
||||||
return s.getPixel8Bpp(idx);
|
ox::Result<unsigned> getTileOffset(ox::CRStringView pNamePath) const noexcept;
|
||||||
}
|
|
||||||
|
ox::Result<ox::StringView> getNameFor(SubSheetId pId) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto getIdFor(ox::CRStringView path) const noexcept {
|
ox::Vector<uint8_t> pixels() const noexcept;
|
||||||
return subsheet.getIdFor(ox::split<8>(path, '.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ox::Result<unsigned> getTileOffset(const auto &pNamePath) const noexcept {
|
|
||||||
return subsheet.getTileOffset(ox::split<8>(pNamePath, '.'), bpp);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ox::Result<ox::StringView> getNameFor(SubSheetId pId) const noexcept {
|
|
||||||
return subsheet.getNameFor(pId);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
auto pixels() const noexcept {
|
|
||||||
ox::Vector<uint8_t> out;
|
|
||||||
subsheet.readPixelsTo(&out);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
int m_palIdx = 0;
|
int m_palIdx = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr DrawCommand(
|
DrawCommand(
|
||||||
TileSheet &img,
|
TileSheet &img,
|
||||||
TileSheet::SubSheetIdx subSheetIdx,
|
TileSheet::SubSheetIdx subSheetIdx,
|
||||||
std::size_t idx,
|
std::size_t idx,
|
||||||
@ -115,7 +115,7 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
m_palIdx = palIdx;
|
m_palIdx = palIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr DrawCommand(
|
DrawCommand(
|
||||||
TileSheet &img,
|
TileSheet &img,
|
||||||
TileSheet::SubSheetIdx subSheetIdx,
|
TileSheet::SubSheetIdx subSheetIdx,
|
||||||
const ox::Vector<std::size_t> &idxList,
|
const ox::Vector<std::size_t> &idxList,
|
||||||
@ -129,7 +129,7 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
m_palIdx = palIdx;
|
m_palIdx = palIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto append(std::size_t idx) noexcept {
|
auto append(std::size_t idx) noexcept {
|
||||||
auto &subsheet = m_img.getSubSheet(m_subSheetIdx);
|
auto &subsheet = m_img.getSubSheet(m_subSheetIdx);
|
||||||
if (m_changes.back().value->idx != idx && subsheet.getPixel(m_img.bpp, idx) != m_palIdx) {
|
if (m_changes.back().value->idx != idx && subsheet.getPixel(m_img.bpp, idx) != m_palIdx) {
|
||||||
// duplicate entries are bad
|
// duplicate entries are bad
|
||||||
@ -248,7 +248,7 @@ class AddSubSheetCommand: public TileSheetCommand {
|
|||||||
ox::Vector<TileSheet::SubSheetIdx, 2> m_addedSheets;
|
ox::Vector<TileSheet::SubSheetIdx, 2> m_addedSheets;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr AddSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx parentIdx) noexcept:
|
AddSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx parentIdx) noexcept:
|
||||||
m_img(img),
|
m_img(img),
|
||||||
m_parentIdx(std::move(parentIdx)) {
|
m_parentIdx(std::move(parentIdx)) {
|
||||||
auto &parent = m_img.getSubSheet(m_parentIdx);
|
auto &parent = m_img.getSubSheet(m_parentIdx);
|
||||||
@ -313,7 +313,7 @@ class RmSubSheetCommand: public TileSheetCommand {
|
|||||||
TileSheet::SubSheet m_sheet;
|
TileSheet::SubSheet m_sheet;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept:
|
RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept:
|
||||||
m_img(img),
|
m_img(img),
|
||||||
m_idx(std::move(idx)) {
|
m_idx(std::move(idx)) {
|
||||||
m_parentIdx = idx;
|
m_parentIdx = idx;
|
||||||
@ -354,7 +354,7 @@ class InsertTilesCommand: public TileSheetCommand {
|
|||||||
ox::Vector<uint8_t> m_deletedPixels = {};
|
ox::Vector<uint8_t> m_deletedPixels = {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr InsertTilesCommand(
|
InsertTilesCommand(
|
||||||
TileSheet &img,
|
TileSheet &img,
|
||||||
TileSheet::SubSheetIdx idx,
|
TileSheet::SubSheetIdx idx,
|
||||||
std::size_t tileIdx,
|
std::size_t tileIdx,
|
||||||
@ -419,7 +419,7 @@ class DeleteTilesCommand: public TileSheetCommand {
|
|||||||
ox::Vector<uint8_t> m_deletedPixels = {};
|
ox::Vector<uint8_t> m_deletedPixels = {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr DeleteTilesCommand(
|
DeleteTilesCommand(
|
||||||
TileSheet &img,
|
TileSheet &img,
|
||||||
TileSheet::SubSheetIdx idx,
|
TileSheet::SubSheetIdx idx,
|
||||||
std::size_t tileIdx,
|
std::size_t tileIdx,
|
||||||
@ -485,7 +485,7 @@ class UpdateSubSheetCommand: public TileSheetCommand {
|
|||||||
int m_newRows = 0;
|
int m_newRows = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr UpdateSubSheetCommand(
|
UpdateSubSheetCommand(
|
||||||
TileSheet &img,
|
TileSheet &img,
|
||||||
TileSheet::SubSheetIdx idx,
|
TileSheet::SubSheetIdx idx,
|
||||||
const ox::String &name,
|
const ox::String &name,
|
||||||
|
@ -76,13 +76,13 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
|||||||
void setActiveSubsheet(const TileSheet::SubSheetIdx&) noexcept;
|
void setActiveSubsheet(const TileSheet::SubSheetIdx&) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr const TileSheet::SubSheet *activeSubSheet() const noexcept {
|
const TileSheet::SubSheet *activeSubSheet() const noexcept {
|
||||||
auto &activeSubSheet = m_img.getSubSheet(m_activeSubsSheetIdx);
|
auto &activeSubSheet = m_img.getSubSheet(m_activeSubsSheetIdx);
|
||||||
return &activeSubSheet;
|
return &activeSubSheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr TileSheet::SubSheet *activeSubSheet() noexcept {
|
TileSheet::SubSheet *activeSubSheet() noexcept {
|
||||||
auto &activeSubSheet = m_img.getSubSheet(m_activeSubsSheetIdx);
|
auto &activeSubSheet = m_img.getSubSheet(m_activeSubsSheetIdx);
|
||||||
return &activeSubSheet;
|
return &activeSubSheet;
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,362 @@
|
|||||||
#include <ox/std/vector.hpp>
|
#include <ox/std/vector.hpp>
|
||||||
|
|
||||||
#include <nostalgia/core/ptidxconv.hpp>
|
#include <nostalgia/core/ptidxconv.hpp>
|
||||||
|
#include <nostalgia/core/tilesheet.hpp>
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
TileSheet::SubSheet::SubSheet(SubSheet &&other) noexcept:
|
||||||
|
id (other.id),
|
||||||
|
name (std::move(other.name)),
|
||||||
|
columns (other.columns),
|
||||||
|
rows (other.rows),
|
||||||
|
subsheets(std::move(other.subsheets)),
|
||||||
|
pixels (std::move(other.pixels)) {
|
||||||
|
other.name = "";
|
||||||
|
other.columns = {};
|
||||||
|
other.rows = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
TileSheet::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(
|
||||||
|
SubSheetId pId,
|
||||||
|
ox::CRStringView pName,
|
||||||
|
int pColumns,
|
||||||
|
int pRows,
|
||||||
|
ox::Vector<uint8_t> pPixels) noexcept:
|
||||||
|
id(pId),
|
||||||
|
name(pName),
|
||||||
|
columns(pColumns),
|
||||||
|
rows(pRows),
|
||||||
|
pixels(std::move(pPixels)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
TileSheet::SubSheet &TileSheet::SubSheet::operator=(TileSheet::SubSheet &&other) noexcept {
|
||||||
|
name = std::move(other.name);
|
||||||
|
columns = other.columns;
|
||||||
|
rows = other.rows;
|
||||||
|
subsheets = std::move(other.subsheets);
|
||||||
|
pixels = std::move(other.pixels);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t TileSheet::SubSheet::idx(const ox::Point &pt) const noexcept {
|
||||||
|
return ptToIdx(pt, columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileSheet::SubSheet::readPixelsTo(ox::Vector<uint8_t> *pPixels, int8_t pBpp) const noexcept {
|
||||||
|
if (!subsheets.empty()) {
|
||||||
|
for (auto &s: subsheets) {
|
||||||
|
s.readPixelsTo(pPixels);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (pBpp == 4) {
|
||||||
|
for (auto p: this->pixels) {
|
||||||
|
pPixels->emplace_back(static_cast<uint8_t>(p & 0b1111));
|
||||||
|
pPixels->emplace_back(static_cast<uint8_t>(p >> 4));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (auto p: this->pixels) {
|
||||||
|
pPixels->emplace_back(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileSheet::SubSheet::readPixelsTo(ox::Vector<uint8_t> *pPixels) const noexcept {
|
||||||
|
if (!subsheets.empty()) {
|
||||||
|
for (auto &s: subsheets) {
|
||||||
|
s.readPixelsTo(pPixels);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (auto p : this->pixels) {
|
||||||
|
pPixels->emplace_back(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t TileSheet::SubSheet::unusedPixels() const noexcept {
|
||||||
|
std::size_t childrenSize = 0;
|
||||||
|
for (auto &c : subsheets) {
|
||||||
|
childrenSize += c.size();
|
||||||
|
}
|
||||||
|
return size() - childrenSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::SubSheet::getPixel4Bpp(std::size_t idx) const noexcept {
|
||||||
|
if (idx & 1) {
|
||||||
|
return this->pixels[idx / 2] >> 4;
|
||||||
|
} else {
|
||||||
|
return this->pixels[idx / 2] & 0b0000'1111;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::SubSheet::getPixel8Bpp(std::size_t idx) const noexcept {
|
||||||
|
return this->pixels[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::SubSheet::getPixel(int8_t pBpp, std::size_t idx) const noexcept {
|
||||||
|
if (pBpp == 4) {
|
||||||
|
return getPixel4Bpp(idx);
|
||||||
|
} else {
|
||||||
|
return getPixel8Bpp(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::SubSheet::getPixel4Bpp(const ox::Point &pt) const noexcept {
|
||||||
|
const auto idx = ptToIdx(pt, columns);
|
||||||
|
return getPixel4Bpp(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::SubSheet::getPixel8Bpp(const ox::Point &pt) const noexcept {
|
||||||
|
const auto idx = ptToIdx(pt, columns);
|
||||||
|
return getPixel8Bpp(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::SubSheet::getPixel(int8_t pBpp, const ox::Point &pt) const noexcept {
|
||||||
|
const auto idx = ptToIdx(pt, columns);
|
||||||
|
return getPixel(pBpp, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileSheet::SubSheet::setPixel(int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept {
|
||||||
|
auto &pixel = this->pixels[static_cast<std::size_t>(idx / 2)];
|
||||||
|
if (pBpp == 4) {
|
||||||
|
if (idx & 1) {
|
||||||
|
pixel = static_cast<uint8_t>((pixel & 0b0000'1111) | (palIdx << 4));
|
||||||
|
} else {
|
||||||
|
pixel = (pixel & 0b1111'0000) | (palIdx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pixel = palIdx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileSheet::SubSheet::setPixel(int8_t pBpp, const ox::Point &pt, uint8_t palIdx) noexcept {
|
||||||
|
const auto idx = ptToIdx(pt, columns);
|
||||||
|
setPixel(pBpp, idx, palIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error TileSheet::SubSheet::setPixelCount(int8_t pBpp, std::size_t cnt) noexcept {
|
||||||
|
switch (pBpp) {
|
||||||
|
case 4:
|
||||||
|
pixels.resize(cnt / 2);
|
||||||
|
return OxError(0);
|
||||||
|
case 8:
|
||||||
|
pixels.resize(cnt);
|
||||||
|
return OxError(0);
|
||||||
|
default:
|
||||||
|
return OxError(1, "Invalid pBpp used for TileSheet::SubSheet::setPixelCount");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned TileSheet::SubSheet::pixelCnt(int8_t pBpp) const noexcept {
|
||||||
|
const auto pixelsSize = static_cast<unsigned>(pixels.size());
|
||||||
|
return pBpp == 4 ? pixelsSize * 2 : pixelsSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Result<unsigned> TileSheet::SubSheet::getTileOffset(
|
||||||
|
ox::SpanView<ox::StringView> const&pNamePath,
|
||||||
|
int8_t pBpp,
|
||||||
|
std::size_t pIt,
|
||||||
|
unsigned pCurrentTotal) const noexcept {
|
||||||
|
// pIt == pNamePath.size() - 1 &&
|
||||||
|
if (name != pNamePath[pIt]) {
|
||||||
|
return OxError(2, "Wrong branch");
|
||||||
|
}
|
||||||
|
if (pIt == pNamePath.size() - 1) {
|
||||||
|
return pCurrentTotal;
|
||||||
|
}
|
||||||
|
for (auto &sub : subsheets) {
|
||||||
|
auto [offset, err] = sub.getTileOffset(
|
||||||
|
pNamePath, pBpp, pIt + 1, pCurrentTotal);
|
||||||
|
if (!err) {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
pCurrentTotal += sub.pixelCnt(pBpp) / PixelsPerTile;
|
||||||
|
}
|
||||||
|
return OxError(1, "SubSheet not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Result<SubSheetId> TileSheet::SubSheet::getIdFor(
|
||||||
|
ox::SpanView<ox::StringView> const&pNamePath,
|
||||||
|
std::size_t pIt) const noexcept {
|
||||||
|
for (auto &sub : subsheets) {
|
||||||
|
if (sub.name == pNamePath[pIt]) {
|
||||||
|
if (pIt == pNamePath.size()) {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
return getIdFor(pNamePath, pIt + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OxError(1, "SubSheet not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Result<ox::StringView> TileSheet::SubSheet::getNameFor(SubSheetId pId) const noexcept {
|
||||||
|
if (id == pId) {
|
||||||
|
return ox::StringView(name);
|
||||||
|
}
|
||||||
|
for (const auto &sub : subsheets) {
|
||||||
|
const auto [name, err] = sub.getNameFor(pId);
|
||||||
|
if (!err) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OxError(1, "SubSheet not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TileSheet &TileSheet::operator=(const TileSheet &other) noexcept {
|
||||||
|
if (this != &other) {
|
||||||
|
bpp = other.bpp;
|
||||||
|
idIt = other.idIt;
|
||||||
|
defaultPalette = other.defaultPalette;
|
||||||
|
subsheet = other.subsheet;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TileSheet &TileSheet::operator=(TileSheet &&other) noexcept {
|
||||||
|
bpp = other.bpp;
|
||||||
|
idIt = other.idIt;
|
||||||
|
defaultPalette = std::move(other.defaultPalette);
|
||||||
|
subsheet = std::move(other.subsheet);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TileSheet::SubSheetIdx TileSheet::validateSubSheetIdx(
|
||||||
|
const SubSheetIdx &pIdx,
|
||||||
|
std::size_t pIdxIt,
|
||||||
|
const SubSheet *pSubsheet) noexcept {
|
||||||
|
if (pIdxIt == pIdx.size()) {
|
||||||
|
return pIdx;
|
||||||
|
}
|
||||||
|
const auto currentIdx = pIdx[pIdxIt];
|
||||||
|
if (pSubsheet->subsheets.size() <= currentIdx) {
|
||||||
|
auto out = pIdx;
|
||||||
|
if (!pSubsheet->subsheets.empty()) {
|
||||||
|
*out.back().value = pSubsheet->subsheets.size() - 1;
|
||||||
|
} else {
|
||||||
|
out.pop_back();
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
return validateSubSheetIdx(pIdx, pIdxIt + 1, &pSubsheet->subsheets[pIdx[pIdxIt]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TileSheet::SubSheetIdx TileSheet::validateSubSheetIdx(const SubSheetIdx &idx) noexcept {
|
||||||
|
return validateSubSheetIdx(idx, 0, &subsheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
const TileSheet::SubSheet &TileSheet::getSubSheet(
|
||||||
|
const TileSheet::SubSheetIdx &idx,
|
||||||
|
std::size_t idxIt,
|
||||||
|
const SubSheet *pSubsheet) noexcept {
|
||||||
|
if (idxIt == idx.size()) {
|
||||||
|
return *pSubsheet;
|
||||||
|
}
|
||||||
|
const auto currentIdx = idx[idxIt];
|
||||||
|
if (pSubsheet->subsheets.size() < currentIdx) {
|
||||||
|
return *pSubsheet;
|
||||||
|
}
|
||||||
|
return getSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[currentIdx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TileSheet::SubSheet &TileSheet::getSubSheet(
|
||||||
|
const TileSheet::SubSheetIdx &idx,
|
||||||
|
std::size_t idxIt,
|
||||||
|
TileSheet::SubSheet *pSubsheet) noexcept {
|
||||||
|
if (idxIt == idx.size()) {
|
||||||
|
return *pSubsheet;
|
||||||
|
}
|
||||||
|
return getSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[idx[idxIt]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const TileSheet::SubSheet &TileSheet::getSubSheet(const TileSheet::SubSheetIdx &idx) const noexcept {
|
||||||
|
return getSubSheet(idx, 0, &subsheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
TileSheet::SubSheet &TileSheet::getSubSheet(const TileSheet::SubSheetIdx &idx) noexcept {
|
||||||
|
return getSubSheet(idx, 0, &subsheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error TileSheet::addSubSheet(const TileSheet::SubSheetIdx &idx) noexcept {
|
||||||
|
auto &parent = getSubSheet(idx);
|
||||||
|
if (parent.subsheets.size() < 2) {
|
||||||
|
parent.subsheets.emplace_back(idIt++, ox::sfmt("Subsheet {}", parent.subsheets.size()), 1, 1, bpp);
|
||||||
|
} else {
|
||||||
|
parent.subsheets.emplace_back(idIt++, "Subsheet 0", parent.columns, parent.rows, bpp);
|
||||||
|
parent.subsheets.emplace_back(idIt++, "Subsheet 1", 1, 1, bpp);
|
||||||
|
}
|
||||||
|
return OxError(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error TileSheet::rmSubSheet(
|
||||||
|
const SubSheetIdx &idx,
|
||||||
|
std::size_t idxIt,
|
||||||
|
SubSheet *pSubsheet) noexcept {
|
||||||
|
if (idxIt == idx.size() - 1) {
|
||||||
|
return pSubsheet->subsheets.erase(idx[idxIt]).error;
|
||||||
|
}
|
||||||
|
return rmSubSheet(idx, idxIt + 1, &pSubsheet->subsheets[idx[idxIt]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Error TileSheet::rmSubSheet(const TileSheet::SubSheetIdx &idx) noexcept {
|
||||||
|
return rmSubSheet(idx, 0, &subsheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::getPixel4Bpp(
|
||||||
|
const ox::Point &pt,
|
||||||
|
const TileSheet::SubSheetIdx &subsheetIdx) const noexcept {
|
||||||
|
oxAssert(bpp == 4, "TileSheet::getPixel4Bpp: wrong bpp");
|
||||||
|
auto &s = this->getSubSheet(subsheetIdx);
|
||||||
|
const auto idx = ptToIdx(pt, s.columns);
|
||||||
|
return s.getPixel4Bpp(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t TileSheet::getPixel8Bpp(
|
||||||
|
const ox::Point &pt,
|
||||||
|
const TileSheet::SubSheetIdx &subsheetIdx) const noexcept {
|
||||||
|
oxAssert(bpp == 8, "TileSheet::getPixel8Bpp: wrong bpp");
|
||||||
|
auto &s = this->getSubSheet(subsheetIdx);
|
||||||
|
const auto idx = ptToIdx(pt, s.columns);
|
||||||
|
return s.getPixel8Bpp(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Result<SubSheetId> TileSheet::getIdFor(ox::CRStringView path) const noexcept {
|
||||||
|
return subsheet.getIdFor(ox::split<8>(path, '.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Result<unsigned> TileSheet::getTileOffset(ox::CRStringView pNamePath) const noexcept {
|
||||||
|
return subsheet.getTileOffset(ox::split<8>(pNamePath, '.'), bpp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Result<ox::StringView> TileSheet::getNameFor(SubSheetId pId) const noexcept {
|
||||||
|
return subsheet.getNameFor(pId);
|
||||||
|
}
|
||||||
|
|
||||||
|
ox::Vector<uint8_t> TileSheet::pixels() const noexcept {
|
||||||
|
ox::Vector<uint8_t> out;
|
||||||
|
subsheet.readPixelsTo(&out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ox::Vector<uint32_t> resizeTileSheetData(
|
ox::Vector<uint32_t> resizeTileSheetData(
|
||||||
ox::Vector<uint32_t> const&srcPixels,
|
ox::Vector<uint32_t> const&srcPixels,
|
||||||
ox::Size const&srcSize,
|
ox::Size const&srcSize,
|
||||||
int scale = 2) noexcept {
|
int scale) noexcept {
|
||||||
ox::Vector<uint32_t> dst;
|
ox::Vector<uint32_t> dst;
|
||||||
auto dstWidth = srcSize.width * scale;
|
auto dstWidth = srcSize.width * scale;
|
||||||
auto dstHeight = srcSize.height * scale;
|
auto dstHeight = srcSize.height * scale;
|
||||||
|
Loading…
Reference in New Issue
Block a user