From 389159728c866f9ef40686aa64e54459579d5389 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 13 Nov 2016 19:43:10 -0500 Subject: [PATCH] Configurable undo history Note: Each undo adds 16.7 MB of RAM usage, max is 200 (3.4GB), but don't set it to this --- src/gui/game/GameController.cpp | 2 +- src/gui/game/GameModel.cpp | 17 +++++++++++++++++ src/gui/game/GameModel.h | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 10e966d5f..ecddde0c4 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -260,7 +260,7 @@ void GameController::HistorySnapshot() history.pop_back(); delete snap; } - if (history.size() >= 1) + if (history.size() >= gameModel->GetUndoHistoryLimit()) { Snapshot * snap = history.front(); history.pop_front(); diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index c44634a95..a8d5cf57e 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -134,6 +134,11 @@ GameModel::GameModel(): colourPresets.push_back(ui::Colour(0, 255, 0)); colourPresets.push_back(ui::Colour(0, 0, 255)); colourPresets.push_back(ui::Colour(0, 0, 0)); + + undoHistoryLimit = Client::Ref().GetPrefInteger("UndoHistoryLimit", 1); + // cap due to memory usage (this is about 3.4GB of RAM) + if (undoHistoryLimit > 200) + undoHistoryLimit = 200; } GameModel::~GameModel() @@ -161,6 +166,8 @@ GameModel::~GameModel() Client::Ref().SetPref("Decoration.Blue", (int)colour.Blue); Client::Ref().SetPref("Decoration.Alpha", (int)colour.Alpha); + Client::Ref().SetPref("UndoHistoryLimit", undoHistoryLimit); + Favorite::Ref().SaveFavoritesToPrefs(); for (size_t i = 0; i < menuList.size(); i++) @@ -451,6 +458,16 @@ void GameModel::SetRedoHistory(Snapshot * redo) redoHistory = redo; } +unsigned int GameModel::GetUndoHistoryLimit() +{ + return undoHistoryLimit; +} + +void GameModel::SetUndoHistoryLimit(unsigned int undoHistoryLimit_) +{ + undoHistoryLimit = undoHistoryLimit_; +} + void GameModel::SetVote(int direction) { if(currentSave) diff --git a/src/gui/game/GameModel.h b/src/gui/game/GameModel.h index ea0f7879d..3727d8172 100644 --- a/src/gui/game/GameModel.h +++ b/src/gui/game/GameModel.h @@ -67,6 +67,7 @@ private: std::deque history; Snapshot *redoHistory; unsigned int historyPosition; + unsigned int undoHistoryLimit; size_t activeColourPreset; std::vector colourPresets; @@ -136,6 +137,8 @@ public: void SetHistoryPosition(unsigned int newHistoryPosition); Snapshot * GetRedoHistory(); void SetRedoHistory(Snapshot * redo); + unsigned int GetUndoHistoryLimit(); + void SetUndoHistoryLimit(unsigned int undoHistoryLimit_); void UpdateQuickOptions();