From eb45b3708b0c2404a6644fe6cfe0af82473c0419 Mon Sep 17 00:00:00 2001 From: ephphatha Date: Tue, 5 Apr 2022 00:28:59 +1000 Subject: [PATCH] Only save stash pages containing items Viewing a stash page results in an entry being created in the stashGrids map. If the player flicks through the entire stash without actually storing an item they end up with ~20kb of unnecessary data in the stash file when they next save. --- Source/loadsave.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 96ae43c4c..d3cae16d3 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -2102,11 +2102,23 @@ void SaveStash() file.WriteLE(Stash.gold); - // Current stash size is 50 pages, expanding to 100 in the near future. Will definitely fit in a 32 bit value. - file.WriteLE(static_cast(Stash.stashGrids.size())); + std::vector pagesToSave; for (const auto &stashPage : Stash.stashGrids) { - file.WriteLE(stashPage.first); - for (const auto &row : stashPage.second) { + if (std::any_of(stashPage.second.cbegin(), stashPage.second.cend(), [](const auto &row) { + return std::any_of(row.cbegin(), row.cend(), [](auto cell) { + return cell > 0; + }); + })) { + // found a page that contains at least one item + pagesToSave.push_back(stashPage.first); + } + }; + + // Current stash size is 100 pages. Will definitely fit in a 32 bit value. + file.WriteLE(static_cast(pagesToSave.size())); + for (const auto &page : pagesToSave) { + file.WriteLE(page); + for (const auto &row : Stash.stashGrids[page]) { for (uint16_t cell : row) { file.WriteLE(cell); }