diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 044f8ba64..f65772fad 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -232,34 +232,60 @@ GameController::~GameController() void GameController::HistoryRestore() { std::deque history = gameModel->GetHistory(); - if(history.size()) + unsigned int historyPosition = gameModel->GetHistoryPosition(); + if(historyPosition > 0 && historyPosition <= history.size()) { - Snapshot * snap = history.back(); - gameModel->GetSimulation()->Restore(*snap); - if(history.size()>1) + if (historyPosition == history.size()) { - history.pop_back(); - delete snap; - gameModel->SetHistory(history); + Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot(); + history.push_back(newSnap); } + Snapshot * snap = history[historyPosition - 1]; + gameModel->GetSimulation()->Restore(*snap); + gameModel->SetHistory(history); + gameModel->SetHistoryPosition(historyPosition - 1); } } void GameController::HistorySnapshot() { std::deque history = gameModel->GetHistory(); + unsigned int historyPosition = gameModel->GetHistoryPosition(); Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot(); if(newSnap) { + while (historyPosition < history.size()) + { + Snapshot * snap = history.back(); + history.pop_back(); + delete snap; + } if(history.size() >= 1) //History limit is current 1 { Snapshot * snap = history.front(); history.pop_front(); //snap->Particles.clear(); delete snap; + if (historyPosition > history.size()) + { + historyPosition--; + } } history.push_back(newSnap); gameModel->SetHistory(history); + gameModel->SetHistoryPosition(historyPosition + 1); + } +} + +void GameController::HistoryForward() +{ + std::deque history = gameModel->GetHistory(); + unsigned int historyPosition = gameModel->GetHistoryPosition(); + if(historyPosition < history.size() - 1) + { + Snapshot * snap = history[historyPosition + 1]; + gameModel->GetSimulation()->Restore(*snap); + gameModel->SetHistoryPosition(historyPosition + 1); } } diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index a42228f84..fb4a86444 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -73,6 +73,7 @@ public: void HistoryRestore(); void HistorySnapshot(); + void HistoryForward(); void AdjustGridSize(int direction); void InvertAirSim(); diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index d4afae62f..eeb443dab 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -28,6 +28,7 @@ GameModel::GameModel(): currentFile(NULL), currentUser(0, ""), toolStrength(1.0f), + historyPosition(0), activeColourPreset(0), colourSelector(false), colour(255, 0, 0, 255), @@ -423,11 +424,22 @@ std::deque GameModel::GetHistory() { return history; } + +unsigned int GameModel::GetHistoryPosition() +{ + return historyPosition; +} + void GameModel::SetHistory(std::deque newHistory) { history = newHistory; } +void GameModel::SetHistoryPosition(unsigned int newHistoryPosition) +{ + historyPosition = newHistoryPosition; +} + void GameModel::SetVote(int direction) { if(currentSave) diff --git a/src/gui/game/GameModel.h b/src/gui/game/GameModel.h index f3aca6b33..dd15a8766 100644 --- a/src/gui/game/GameModel.h +++ b/src/gui/game/GameModel.h @@ -65,6 +65,7 @@ private: User currentUser; float toolStrength; std::deque history; + unsigned int historyPosition; size_t activeColourPreset; std::vector colourPresets; @@ -129,7 +130,9 @@ public: void BuildQuickOptionMenu(GameController * controller); std::deque GetHistory(); + unsigned int GetHistoryPosition(); void SetHistory(std::deque newHistory); + void SetHistoryPosition(unsigned int newHistoryPosition); void UpdateQuickOptions(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index cdb51ac29..662cd3361 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1545,7 +1545,14 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool } break; case 'y': - c->SwitchAir(); + if (ctrl) + { + c->HistoryForward(); + } + else + { + c->SwitchAir(); + } break; case SDLK_ESCAPE: case 'q':