summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-16 21:03:40 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-16 21:03:40 (GMT)
commitedad8f46af6cf2403c2ffa77ecfa138ae1b9f8d9 (patch)
tree94ac1023a0241e27176d63aabee26fd1b876e08b /src/game
parentf19c7f62c77f6a3e8f5728e015166b0c625f5f67 (diff)
downloadpowder-edad8f46af6cf2403c2ffa77ecfa138ae1b9f8d9.zip
powder-edad8f46af6cf2403c2ffa77ecfa138ae1b9f8d9.tar.gz
Undo/Snapshots, fixes #118
Diffstat (limited to 'src/game')
-rw-r--r--src/game/GameController.cpp35
-rw-r--r--src/game/GameController.h3
-rw-r--r--src/game/GameModel.cpp9
-rw-r--r--src/game/GameModel.h4
-rw-r--r--src/game/GameView.cpp22
5 files changed, 68 insertions, 5 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 5237af7..91c64c0 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -23,6 +23,7 @@
#include "save/LocalSaveActivity.h"
#include "save/ServerSaveActivity.h"
#include "interface/Keys.h"
+#include "simulation/Snapshot.h"
using namespace std;
@@ -187,6 +188,40 @@ GameController::~GameController()
delete gameView;
}
+void GameController::HistoryRestore()
+{
+ std::deque<Snapshot*> history = gameModel->GetHistory();
+ if(history.size())
+ {
+ Snapshot * snap = history.back();
+ gameModel->GetSimulation()->Restore(*snap);
+ if(history.size()>1)
+ {
+ history.pop_back();
+ delete snap;
+ gameModel->SetHistory(history);
+ }
+ }
+}
+
+void GameController::HistorySnapshot()
+{
+ std::deque<Snapshot*> history = gameModel->GetHistory();
+ Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot();
+ if(newSnap)
+ {
+ if(history.size() >= 1) //History limit is current 1
+ {
+ Snapshot * snap = history.front();
+ history.pop_front();
+ //snap->Particles.clear();
+ delete snap;
+ }
+ history.push_back(newSnap);
+ gameModel->SetHistory(history);
+ }
+}
+
GameView * GameController::GetView()
{
return gameView;
diff --git a/src/game/GameController.h b/src/game/GameController.h
index c6d41b5..625ab60 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -69,6 +69,9 @@ public:
void Install();
+ void HistoryRestore();
+ void HistorySnapshot();
+
void AdjustGridSize(int direction);
void InvertAirSim();
void LoadRenderPreset(RenderPreset preset);
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 9505397..8512a9a 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -253,6 +253,15 @@ void GameModel::BuildMenus()
notifyLastToolChanged();
}
+std::deque<Snapshot*> GameModel::GetHistory()
+{
+ return history;
+}
+void GameModel::SetHistory(std::deque<Snapshot*> newHistory)
+{
+ history = newHistory;
+}
+
void GameModel::SetVote(int direction)
{
if(currentSave)
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index 33cf119..0531f87 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -57,6 +57,7 @@ private:
bool colourSelector;
ui::Colour colour;
float toolStrength;
+ std::deque<Snapshot*> history;
std::string infoTip;
std::string toolTip;
@@ -100,6 +101,9 @@ public:
void BuildMenus();
void BuildQuickOptionMenu();
+ std::deque<Snapshot*> GetHistory();
+ void SetHistory(std::deque<Snapshot*> newHistory);
+
void UpdateQuickOptions();
void SetToolStrength(float value);
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index af13797..5b6629b 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -984,6 +984,8 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
if(button == BUTTON_MIDDLE)
toolIndex = 2;
isMouseDown = true;
+ if(!pointQueue.size())
+ c->HistorySnapshot();
if(drawMode == DrawRect || drawMode == DrawLine)
{
drawPoint1 = ui::Point(x, y);
@@ -1230,9 +1232,16 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
c->ChangeBrush();
break;
case 'z':
- isMouseDown = false;
- zoomCursorFixed = false;
- c->SetZoomEnabled(true);
+ if(ctrl)
+ {
+ c->HistoryRestore();
+ }
+ else
+ {
+ isMouseDown = false;
+ zoomCursorFixed = false;
+ c->SetZoomEnabled(true);
+ }
break;
case '`':
c->ShowConsole();
@@ -1384,8 +1393,11 @@ void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bo
disableShiftBehaviour();
break;
case 'z':
- if(!zoomCursorFixed && !alt)
- c->SetZoomEnabled(false);
+ if(!ctrl)
+ {
+ if(!zoomCursorFixed && !alt)
+ c->SetZoomEnabled(false);
+ }
break;
}
}