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
This commit is contained in:
jacob1 2016-11-13 19:43:10 -05:00
parent 25a2d9b5b5
commit 389159728c
3 changed files with 21 additions and 1 deletions

View File

@ -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();

View File

@ -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)

View File

@ -67,6 +67,7 @@ private:
std::deque<Snapshot*> history;
Snapshot *redoHistory;
unsigned int historyPosition;
unsigned int undoHistoryLimit;
size_t activeColourPreset;
std::vector<ui::Colour> 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();