Skip to content

Commit

Permalink
Configurable undo history
Browse files Browse the repository at this point in the history
Note: Each undo adds 16.7 MB of RAM usage, max is 200 (3.4GB), but don't set it to this
  • Loading branch information
jacob1 committed Nov 14, 2016
1 parent 25a2d9b commit 3891597
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gui/game/GameController.cpp
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions src/gui/game/GameModel.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/gui/game/GameModel.h
Expand Up @@ -67,6 +67,7 @@ class GameModel
std::deque<Snapshot*> history;
Snapshot *redoHistory;
unsigned int historyPosition;
unsigned int undoHistoryLimit;

size_t activeColourPreset;
std::vector<ui::Colour> colourPresets;
Expand Down Expand Up @@ -136,6 +137,8 @@ class GameModel
void SetHistoryPosition(unsigned int newHistoryPosition);
Snapshot * GetRedoHistory();
void SetRedoHistory(Snapshot * redo);
unsigned int GetUndoHistoryLimit();
void SetUndoHistoryLimit(unsigned int undoHistoryLimit_);

void UpdateQuickOptions();

Expand Down

0 comments on commit 3891597

Please sign in to comment.