Skip to content

Commit

Permalink
Take history snapshot before setting save (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
krawthekrow authored and jacob1 committed Mar 20, 2017
1 parent e13e31c commit 1c12d1e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/gui/game/GameController.cpp
Expand Up @@ -51,6 +51,7 @@ class GameController::SearchCallback: public ControllerCallback
{
try
{
cc->HistorySnapshot();
cc->gameModel->SetSave(cc->search->GetLoadedSave());
cc->search->ReleaseLoadedSave();
}
Expand All @@ -73,6 +74,7 @@ class GameController::SaveOpenCallback: public ControllerCallback
{
try
{
cc->HistorySnapshot();
cc->LoadSave(cc->activePreview->GetSaveInfo());
}
catch(GameModelException & ex)
Expand Down Expand Up @@ -144,7 +146,6 @@ GameController::GameController():

gameView->AttachController(this);
gameModel->AddObserver(gameView);
gameModel->SetAllowHistory();

gameView->SetDebugHUD(Client::Ref().GetPrefBool("Renderer.DebugMode", false));

Expand Down Expand Up @@ -253,11 +254,6 @@ void GameController::HistoryRestore()

void GameController::HistorySnapshot()
{
// callbacks during initialization create two empty snapshots on startup
// Prevent that from happening here
if (!gameModel->GetAllowHistory())
return;

std::deque<Snapshot*> history = gameModel->GetHistory();
unsigned int historyPosition = gameModel->GetHistoryPosition();
Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot();
Expand Down Expand Up @@ -288,6 +284,8 @@ void GameController::HistorySnapshot()
void GameController::HistoryForward()
{
std::deque<Snapshot*> history = gameModel->GetHistory();
if (!history.size())
return;
unsigned int historyPosition = gameModel->GetHistoryPosition();
unsigned int newHistoryPosition = std::min((size_t)historyPosition+1, history.size());
Snapshot *snap;
Expand Down Expand Up @@ -1252,6 +1250,7 @@ void GameController::OpenLocalBrowse()
virtual ~LocalSaveOpenCallback() {};
virtual void FileSelected(SaveFile* file)
{
c->HistorySnapshot();
c->LoadSaveFile(file);
delete file;
}
Expand Down Expand Up @@ -1488,6 +1487,7 @@ void GameController::ChangeBrush()

void GameController::ClearSim()
{
HistorySnapshot();
gameModel->SetSave(NULL);
gameModel->ClearSimulation();
}
Expand All @@ -1496,10 +1496,12 @@ void GameController::ReloadSim()
{
if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
{
HistorySnapshot();
gameModel->SetSave(gameModel->GetSave());
}
else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave())
{
HistorySnapshot();
gameModel->SetSaveFile(gameModel->GetSaveFile());
}
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/game/GameModel.cpp
Expand Up @@ -28,7 +28,6 @@ GameModel::GameModel():
currentFile(NULL),
currentUser(0, ""),
toolStrength(1.0f),
allowHistory(false),
redoHistory(NULL),
historyPosition(0),
activeColourPreset(0),
Expand Down
3 changes: 0 additions & 3 deletions src/gui/game/GameModel.h
Expand Up @@ -64,7 +64,6 @@ class GameModel
Tool * regularToolset[4];
User currentUser;
float toolStrength;
bool allowHistory;
std::deque<Snapshot*> history;
Snapshot *redoHistory;
unsigned int historyPosition;
Expand Down Expand Up @@ -132,8 +131,6 @@ class GameModel
void BuildFavoritesMenu();
void BuildQuickOptionMenu(GameController * controller);

bool GetAllowHistory() { return allowHistory; }
void SetAllowHistory() { allowHistory = true; }
std::deque<Snapshot*> GetHistory();
unsigned int GetHistoryPosition();
void SetHistory(std::deque<Snapshot*> newHistory);
Expand Down
1 change: 0 additions & 1 deletion src/gui/game/GameView.cpp
Expand Up @@ -1035,7 +1035,6 @@ void GameView::NotifySaveChanged(GameModel * sender)
}
saveSimulationButton->Enabled = (saveSimulationButtonEnabled || ctrlBehaviour);
SetSaveButtonTooltips();
c->HistorySnapshot();
}

void GameView::NotifyBrushChanged(GameModel * sender)
Expand Down

0 comments on commit 1c12d1e

Please sign in to comment.