diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/removepagecommand.cpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/removepagecommand.cpp index 1376b0f0d..2aa47af58 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/removepagecommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/removepagecommand.cpp @@ -8,7 +8,7 @@ namespace nostalgia::gfx { -RemovePageCommand::RemovePageCommand(Palette &pal, size_t idx) noexcept: +RemovePageCommand::RemovePageCommand(Palette &pal, size_t const idx) noexcept: m_pal(pal), m_idx(idx) {} diff --git a/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/updatecolorcommand.cpp b/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/updatecolorcommand.cpp index b1c9eb640..0947119f6 100644 --- a/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/updatecolorcommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/paletteeditor/commands/updatecolorcommand.cpp @@ -9,13 +9,13 @@ namespace nostalgia::gfx { UpdateColorCommand::UpdateColorCommand( Palette &pal, - size_t page, - size_t idx, - Color16 newColor): - m_pal(pal), - m_page(page), - m_idx(idx), - m_altColor(newColor) { + size_t const page, + size_t const idx, + Color16 const newColor): + m_pal{pal}, + m_page{page}, + m_idx{idx}, + m_altColor{newColor} { if (color(m_pal, m_page, m_idx) == newColor) { throw studio::NoChangesException(); } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.cpp index 9940b18ff..9350df0d2 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.cpp @@ -13,20 +13,19 @@ DeleteTilesCommand::DeleteTilesCommand( TileSheet::SubSheetIdx idx, std::size_t const tileIdx, std::size_t const tileCnt) noexcept: - m_img(img), - m_idx(std::move(idx)) { - constexpr unsigned bytesPerTile = PixelsPerTile; - m_deletePos = tileIdx * bytesPerTile; - m_deleteSz = tileCnt * bytesPerTile; - m_deletedPixels.resize(m_deleteSz); - // copy pixels to be erased - { - auto &s = getSubSheet(m_img, m_idx); - auto dst = m_deletedPixels.begin(); - auto src = s.pixels.begin() + m_deletePos; - ox::copy_n(src, m_deleteSz, dst); - } -} + m_img{img}, + m_idx{std::move(idx)}, + m_deletePos{tileIdx * PixelsPerTile}, + m_deleteSz{tileCnt * PixelsPerTile}, + m_deletedPixels{[this] { + ox::Vector deletedPixels(m_deleteSz); + // copy pixels to be erased + auto const &s = getSubSheet(m_img, m_idx); + auto const dst = deletedPixels.begin(); + auto const src = s.pixels.begin() + m_deletePos; + ox::copy_n(src, m_deleteSz, dst); + return deletedPixels; + }()} {} ox::Error DeleteTilesCommand::redo() noexcept { auto &s = getSubSheet(m_img, m_idx); diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.hpp index 846c2283b..a0e0b34ba 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/deletetilescommand.hpp @@ -11,10 +11,10 @@ namespace nostalgia::gfx { class DeleteTilesCommand: public TileSheetCommand { private: TileSheet &m_img; - TileSheet::SubSheetIdx m_idx; - std::size_t m_deletePos = 0; - std::size_t m_deleteSz = 0; - ox::Vector m_deletedPixels = {}; + TileSheet::SubSheetIdx const m_idx; + std::size_t const m_deletePos = 0; + std::size_t const m_deleteSz = 0; + ox::Vector const m_deletedPixels; public: DeleteTilesCommand( diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp index 0b8f59a72..ea5ced0c6 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp @@ -62,11 +62,11 @@ constexpr void iterateLine(ox::Point const &a, ox::Point const &b, auto const &f DrawCommand::DrawCommand( TileSheet &img, TileSheet::SubSheetIdx subSheetIdx, - std::size_t idx, + std::size_t const idx, int const palIdx) noexcept: - m_img(img), - m_subSheetIdx(std::move(subSheetIdx)), - m_palIdx(palIdx) { + m_img{img}, + m_subSheetIdx{std::move(subSheetIdx)}, + m_palIdx{palIdx} { auto &subsheet = getSubSheet(m_img, m_subSheetIdx); m_changes.emplace_back(static_cast(idx), getPixel(subsheet, idx)); } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.cpp index 7bc7fd0f6..15109eb56 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.cpp @@ -12,19 +12,19 @@ InsertTilesCommand::InsertTilesCommand( std::size_t const tileIdx, std::size_t const tileCnt) noexcept: m_img{img}, - m_idx{std::move(idx)} { - m_insertPos = tileIdx * PixelsPerTile; - m_insertCnt = tileCnt * PixelsPerTile; - m_deletedPixels.resize(m_insertCnt); - // copy pixels to be erased - { - auto &s = getSubSheet(m_img, m_idx); - auto &p = s.pixels; - auto const dst = m_deletedPixels.begin(); - auto const src = p.begin() + p.size() - m_insertCnt; - ox::copy_n(src, m_insertCnt, dst); - } -} + m_idx{std::move(idx)}, + m_insertPos{tileIdx * PixelsPerTile}, + m_insertCnt{tileCnt * PixelsPerTile}, + m_insertedPixels{[this] { + ox::Vector insertedPixels(m_insertCnt); + // copy pixels to be erased + auto &s = getSubSheet(m_img, m_idx); + auto &p = s.pixels; + auto const dst = insertedPixels.begin(); + auto const src = p.begin() + p.size() - m_insertCnt; + ox::copy_n(src, m_insertCnt, dst); + return insertedPixels; + }()} {} OX_ALLOW_UNSAFE_BUFFERS_BEGIN @@ -52,7 +52,7 @@ ox::Error InsertTilesCommand::undo() noexcept { auto const src = &p[srcIdx]; ox::memmove(dst1, src, sz); } - ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); + ox::memcpy(dst2, m_insertedPixels.data(), m_insertedPixels.size()); return {}; } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.hpp index 49f77ab5c..220311bdd 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/inserttilescommand.hpp @@ -11,10 +11,10 @@ namespace nostalgia::gfx { class InsertTilesCommand: public TileSheetCommand { private: TileSheet &m_img; - TileSheet::SubSheetIdx m_idx; - std::size_t m_insertPos = 0; - std::size_t m_insertCnt = 0; - ox::Vector m_deletedPixels = {}; + TileSheet::SubSheetIdx const m_idx; + std::size_t const m_insertPos{}; + std::size_t const m_insertCnt{}; + ox::Vector const m_insertedPixels; public: InsertTilesCommand( diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp index 9d084e3f8..e4d7c8ab5 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp @@ -15,7 +15,6 @@ UpdateSubSheetCommand::UpdateSubSheetCommand( m_img{img}, m_idx{std::move(idx)}, m_sheet{getSubSheet(m_img, m_idx)} { - m_sheet = getSubSheet(m_img, m_idx); m_sheet.name = std::move(name); OX_THROW_ERROR(resizeSubsheet(m_sheet, {cols, rows})); } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp index b2c55117c..4969488a8 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp @@ -11,7 +11,7 @@ namespace nostalgia::gfx { class UpdateSubSheetCommand: public TileSheetCommand { private: TileSheet &m_img; - TileSheet::SubSheetIdx m_idx; + TileSheet::SubSheetIdx const m_idx; TileSheet::SubSheet m_sheet; public: