[nostalgia/gfx/studio] Cleanup
All checks were successful
Build / build (push) Successful in 2m53s

This commit is contained in:
2025-06-17 20:45:24 -05:00
parent 05f42150a1
commit 7415ce4bd9
9 changed files with 48 additions and 50 deletions

View File

@ -8,7 +8,7 @@
namespace nostalgia::gfx { namespace nostalgia::gfx {
RemovePageCommand::RemovePageCommand(Palette &pal, size_t idx) noexcept: RemovePageCommand::RemovePageCommand(Palette &pal, size_t const idx) noexcept:
m_pal(pal), m_pal(pal),
m_idx(idx) {} m_idx(idx) {}

View File

@ -9,13 +9,13 @@ namespace nostalgia::gfx {
UpdateColorCommand::UpdateColorCommand( UpdateColorCommand::UpdateColorCommand(
Palette &pal, Palette &pal,
size_t page, size_t const page,
size_t idx, size_t const idx,
Color16 newColor): Color16 const newColor):
m_pal(pal), m_pal{pal},
m_page(page), m_page{page},
m_idx(idx), m_idx{idx},
m_altColor(newColor) { m_altColor{newColor} {
if (color(m_pal, m_page, m_idx) == newColor) { if (color(m_pal, m_page, m_idx) == newColor) {
throw studio::NoChangesException(); throw studio::NoChangesException();
} }

View File

@ -13,20 +13,19 @@ DeleteTilesCommand::DeleteTilesCommand(
TileSheet::SubSheetIdx idx, TileSheet::SubSheetIdx idx,
std::size_t const tileIdx, std::size_t const tileIdx,
std::size_t const tileCnt) noexcept: std::size_t const tileCnt) noexcept:
m_img(img), m_img{img},
m_idx(std::move(idx)) { m_idx{std::move(idx)},
constexpr unsigned bytesPerTile = PixelsPerTile; m_deletePos{tileIdx * PixelsPerTile},
m_deletePos = tileIdx * bytesPerTile; m_deleteSz{tileCnt * PixelsPerTile},
m_deleteSz = tileCnt * bytesPerTile; m_deletedPixels{[this] {
m_deletedPixels.resize(m_deleteSz); ox::Vector<uint8_t> deletedPixels(m_deleteSz);
// copy pixels to be erased // copy pixels to be erased
{ auto const &s = getSubSheet(m_img, m_idx);
auto &s = getSubSheet(m_img, m_idx); auto const dst = deletedPixels.begin();
auto dst = m_deletedPixels.begin(); auto const src = s.pixels.begin() + m_deletePos;
auto src = s.pixels.begin() + m_deletePos; ox::copy_n(src, m_deleteSz, dst);
ox::copy_n(src, m_deleteSz, dst); return deletedPixels;
} }()} {}
}
ox::Error DeleteTilesCommand::redo() noexcept { ox::Error DeleteTilesCommand::redo() noexcept {
auto &s = getSubSheet(m_img, m_idx); auto &s = getSubSheet(m_img, m_idx);

View File

@ -11,10 +11,10 @@ namespace nostalgia::gfx {
class DeleteTilesCommand: public TileSheetCommand { class DeleteTilesCommand: public TileSheetCommand {
private: private:
TileSheet &m_img; TileSheet &m_img;
TileSheet::SubSheetIdx m_idx; TileSheet::SubSheetIdx const m_idx;
std::size_t m_deletePos = 0; std::size_t const m_deletePos = 0;
std::size_t m_deleteSz = 0; std::size_t const m_deleteSz = 0;
ox::Vector<uint8_t> m_deletedPixels = {}; ox::Vector<uint8_t> const m_deletedPixels;
public: public:
DeleteTilesCommand( DeleteTilesCommand(

View File

@ -62,11 +62,11 @@ constexpr void iterateLine(ox::Point const &a, ox::Point const &b, auto const &f
DrawCommand::DrawCommand( DrawCommand::DrawCommand(
TileSheet &img, TileSheet &img,
TileSheet::SubSheetIdx subSheetIdx, TileSheet::SubSheetIdx subSheetIdx,
std::size_t idx, std::size_t const idx,
int const palIdx) noexcept: int const palIdx) noexcept:
m_img(img), m_img{img},
m_subSheetIdx(std::move(subSheetIdx)), m_subSheetIdx{std::move(subSheetIdx)},
m_palIdx(palIdx) { m_palIdx{palIdx} {
auto &subsheet = getSubSheet(m_img, m_subSheetIdx); auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
m_changes.emplace_back(static_cast<uint32_t>(idx), getPixel(subsheet, idx)); m_changes.emplace_back(static_cast<uint32_t>(idx), getPixel(subsheet, idx));
} }

View File

@ -12,19 +12,19 @@ InsertTilesCommand::InsertTilesCommand(
std::size_t const tileIdx, std::size_t const tileIdx,
std::size_t const tileCnt) noexcept: std::size_t const tileCnt) noexcept:
m_img{img}, m_img{img},
m_idx{std::move(idx)} { m_idx{std::move(idx)},
m_insertPos = tileIdx * PixelsPerTile; m_insertPos{tileIdx * PixelsPerTile},
m_insertCnt = tileCnt * PixelsPerTile; m_insertCnt{tileCnt * PixelsPerTile},
m_deletedPixels.resize(m_insertCnt); m_insertedPixels{[this] {
// copy pixels to be erased ox::Vector<uint8_t> insertedPixels(m_insertCnt);
{ // copy pixels to be erased
auto &s = getSubSheet(m_img, m_idx); auto &s = getSubSheet(m_img, m_idx);
auto &p = s.pixels; auto &p = s.pixels;
auto const dst = m_deletedPixels.begin(); auto const dst = insertedPixels.begin();
auto const src = p.begin() + p.size() - m_insertCnt; auto const src = p.begin() + p.size() - m_insertCnt;
ox::copy_n(src, m_insertCnt, dst); ox::copy_n(src, m_insertCnt, dst);
} return insertedPixels;
} }()} {}
OX_ALLOW_UNSAFE_BUFFERS_BEGIN OX_ALLOW_UNSAFE_BUFFERS_BEGIN
@ -52,7 +52,7 @@ ox::Error InsertTilesCommand::undo() noexcept {
auto const src = &p[srcIdx]; auto const src = &p[srcIdx];
ox::memmove(dst1, src, sz); ox::memmove(dst1, src, sz);
} }
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); ox::memcpy(dst2, m_insertedPixels.data(), m_insertedPixels.size());
return {}; return {};
} }

View File

@ -11,10 +11,10 @@ namespace nostalgia::gfx {
class InsertTilesCommand: public TileSheetCommand { class InsertTilesCommand: public TileSheetCommand {
private: private:
TileSheet &m_img; TileSheet &m_img;
TileSheet::SubSheetIdx m_idx; TileSheet::SubSheetIdx const m_idx;
std::size_t m_insertPos = 0; std::size_t const m_insertPos{};
std::size_t m_insertCnt = 0; std::size_t const m_insertCnt{};
ox::Vector<uint8_t> m_deletedPixels = {}; ox::Vector<uint8_t> const m_insertedPixels;
public: public:
InsertTilesCommand( InsertTilesCommand(

View File

@ -15,7 +15,6 @@ UpdateSubSheetCommand::UpdateSubSheetCommand(
m_img{img}, m_img{img},
m_idx{std::move(idx)}, m_idx{std::move(idx)},
m_sheet{getSubSheet(m_img, m_idx)} { m_sheet{getSubSheet(m_img, m_idx)} {
m_sheet = getSubSheet(m_img, m_idx);
m_sheet.name = std::move(name); m_sheet.name = std::move(name);
OX_THROW_ERROR(resizeSubsheet(m_sheet, {cols, rows})); OX_THROW_ERROR(resizeSubsheet(m_sheet, {cols, rows}));
} }

View File

@ -11,7 +11,7 @@ namespace nostalgia::gfx {
class UpdateSubSheetCommand: public TileSheetCommand { class UpdateSubSheetCommand: public TileSheetCommand {
private: private:
TileSheet &m_img; TileSheet &m_img;
TileSheet::SubSheetIdx m_idx; TileSheet::SubSheetIdx const m_idx;
TileSheet::SubSheet m_sheet; TileSheet::SubSheet m_sheet;
public: public: