summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-09 18:42:07 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-09 18:42:07 (GMT)
commit050ad82155344d9ff0db551386c804154bceb560 (patch)
tree34e938679d13c1b5e7676bc213236bbf399f581f /src/game
parentc408e035faf88f968ea208d48ced4b7c3c9dc32d (diff)
downloadpowder-050ad82155344d9ff0db551386c804154bceb560.zip
powder-050ad82155344d9ff0db551386c804154bceb560.tar.gz
Unify stamp and clipboard placement code, GameSave translation and transoformation working (not particularly well)
Diffstat (limited to 'src/game')
-rw-r--r--src/game/GameController.cpp41
-rw-r--r--src/game/GameController.h8
-rw-r--r--src/game/GameModel.cpp34
-rw-r--r--src/game/GameModel.h5
-rw-r--r--src/game/GameView.cpp86
-rw-r--r--src/game/GameView.h8
6 files changed, 114 insertions, 68 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index e0e8673..7c70797 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -107,6 +107,7 @@ public:
if(cc->localBrowser->GetSave())
{
cc->gameModel->SetStamp(cc->localBrowser->GetSave()->GetGameSave());
+ cc->LoadStamp();
}
else
cc->gameModel->SetStamp(NULL);
@@ -168,20 +169,11 @@ GameView * GameController::GetView()
return gameView;
}
-void GameController::PlaceStamp(ui::Point position)
+void GameController::PlaceSave(ui::Point position)
{
- if(gameModel->GetStamp())
+ if(gameModel->GetPlaceSave())
{
- gameModel->GetSimulation()->Load(position.X, position.Y, gameModel->GetStamp());
- gameModel->SetPaused(gameModel->GetPaused());
- }
-}
-
-void GameController::PlaceClipboard(ui::Point position)
-{
- if(gameModel->GetClipboard())
- {
- gameModel->GetSimulation()->Load(position.X, position.Y, gameModel->GetClipboard());
+ gameModel->GetSimulation()->Load(position.X, position.Y, gameModel->GetPlaceSave());
gameModel->SetPaused(gameModel->GetPaused());
}
}
@@ -309,6 +301,31 @@ void GameController::DrawPoints(int toolSelection, queue<ui::Point*> & pointQueu
}
}
+void GameController::LoadClipboard()
+{
+ gameModel->SetPlaceSave(gameModel->GetClipboard());
+}
+
+void GameController::LoadStamp()
+{
+ gameModel->SetPlaceSave(gameModel->GetStamp());
+}
+
+void GameController::TranslateSave(ui::Point point)
+{
+ matrix2d transform = m2d_identity;
+ vector2d translate = v2d_new(point.X, point.Y);
+ gameModel->GetPlaceSave()->Transform(transform, translate);
+ gameModel->SetPlaceSave(gameModel->GetPlaceSave());
+}
+
+void GameController::TransformSave(matrix2d transform)
+{
+ vector2d translate = v2d_zero;
+ gameModel->GetPlaceSave()->Transform(transform, translate);
+ gameModel->SetPlaceSave(gameModel->GetPlaceSave());
+}
+
void GameController::ToolClick(int toolSelection, ui::Point point)
{
Simulation * sim = gameModel->GetSimulation();
diff --git a/src/game/GameController.h b/src/game/GameController.h
index f2d05b9..e75cf49 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -85,17 +85,21 @@ public:
void OpenRenderOptions();
void OpenSaveWindow();
void OpenStamps();
- void PlaceStamp(ui::Point position);
- void PlaceClipboard(ui::Point position);
+ void PlaceSave(ui::Point position);
void ClearSim();
void ReloadSim();
void Vote(int direction);
void ChangeBrush();
void ShowConsole();
void FrameStep();
+ void TranslateSave(ui::Point point);
+ void TransformSave(matrix2d transform);
ui::Point PointTranslate(ui::Point point);
ui::Point NormaliseBlockCoord(ui::Point point);
std::string ElementResolve(int type);
+
+ void LoadClipboard();
+ void LoadStamp();
};
#endif // GAMECONTROLLER_H
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 362eddd..36aef35 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -18,7 +18,8 @@ GameModel::GameModel():
currentSave(NULL),
colourSelector(false),
clipboard(NULL),
- stamp(NULL)
+ stamp(NULL),
+ placeSave(NULL)
{
sim = new Simulation();
ren = new Renderer(ui::Engine::Ref().g, sim);
@@ -430,7 +431,17 @@ void GameModel::SetStamp(GameSave * save)
if(stamp)
delete stamp;
stamp = new GameSave(*save);
- notifyStampChanged();
+}
+
+void GameModel::SetPlaceSave(GameSave * save)
+{
+ if(save != placeSave)
+ delete placeSave;
+ if(save != placeSave)
+ placeSave = new GameSave(*save);
+ else if(!save)
+ placeSave = NULL;
+ notifyPlaceSaveChanged();
}
void GameModel::AddStamp(GameSave * save)
@@ -439,7 +450,6 @@ void GameModel::AddStamp(GameSave * save)
delete stamp;
stamp = new GameSave(*save);
Client::Ref().AddStamp(save);
- notifyClipboardChanged();
}
void GameModel::SetClipboard(GameSave * save)
@@ -447,7 +457,6 @@ void GameModel::SetClipboard(GameSave * save)
if(clipboard)
delete clipboard;
clipboard = save;
- notifyClipboardChanged();
}
GameSave * GameModel::GetClipboard()
@@ -455,6 +464,11 @@ GameSave * GameModel::GetClipboard()
return clipboard;
}
+GameSave * GameModel::GetPlaceSave()
+{
+ return placeSave;
+}
+
GameSave * GameModel::GetStamp()
{
return stamp;
@@ -577,19 +591,11 @@ void GameModel::notifyZoomChanged()
}
}
-void GameModel::notifyStampChanged()
-{
- for(int i = 0; i < observers.size(); i++)
- {
- observers[i]->NotifyStampChanged(this);
- }
-}
-
-void GameModel::notifyClipboardChanged()
+void GameModel::notifyPlaceSaveChanged()
{
for(int i = 0; i < observers.size(); i++)
{
- observers[i]->NotifyClipboardChanged(this);
+ observers[i]->NotifyPlaceSaveChanged(this);
}
}
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index 5c8b0aa..9faf5fc 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -36,6 +36,7 @@ private:
//unsigned char * clipboardData;
GameSave * stamp;
GameSave * clipboard;
+ GameSave * placeSave;
deque<string> consoleLog;
vector<GameView*> observers;
vector<Tool*> toolList;
@@ -63,7 +64,7 @@ private:
void notifyUserChanged();
void notifyZoomChanged();
void notifyClipboardChanged();
- void notifyStampChanged();
+ void notifyPlaceSaveChanged();
void notifyColourSelectorColourChanged();
void notifyColourSelectorVisibilityChanged();
void notifyLogChanged(string entry);
@@ -113,10 +114,12 @@ public:
void SetStamp(GameSave * newStamp);
void AddStamp(GameSave * save);
void SetClipboard(GameSave * save);
+ void SetPlaceSave(GameSave * save);
void Log(string message);
deque<string> GetLog();
GameSave * GetClipboard();
GameSave * GetStamp();
+ GameSave * GetPlaceSave();
};
#endif // GAMEMODEL_H
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 89d9fac..dbc2294 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -29,8 +29,7 @@ GameView::GameView():
selectMode(SelectNone),
selectPoint1(0, 0),
selectPoint2(0, 0),
- stampThumb(NULL),
- clipboardThumb(NULL),
+ placeSaveThumb(NULL),
mousePosition(0, 0)
{
int currentX = 1;
@@ -493,7 +492,7 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
mousePosition = c->PointTranslate(ui::Point(x, y));
if(selectMode!=SelectNone)
{
- if(selectMode==PlaceStamp || selectMode==PlaceClipboard)
+ if(selectMode==PlaceSave)
selectPoint1 = ui::Point(x, y);
if(selectPoint1.X!=-1)
selectPoint2 = ui::Point(x, y);
@@ -544,9 +543,9 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
{
if(button==BUTTON_LEFT)
{
- if(selectMode==PlaceStamp || selectMode==PlaceClipboard)
+ if(selectMode==PlaceSave)
{
- Thumbnail * tempThumb = selectMode==PlaceStamp?stampThumb:clipboardThumb;
+ Thumbnail * tempThumb = placeSaveThumb;
if(tempThumb)
{
int thumbX = selectPoint2.X - (tempThumb->Size.X/2);
@@ -562,10 +561,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
if(thumbY+(tempThumb->Size.Y)>=YRES)
thumbY = YRES-tempThumb->Size.Y;
- if(selectMode==PlaceStamp)
- c->PlaceStamp(ui::Point(thumbX, thumbY));
- if(selectMode==PlaceClipboard)
- c->PlaceClipboard(ui::Point(thumbX, thumbY));
+ c->PlaceSave(ui::Point(thumbX, thumbY));
}
}
else
@@ -646,6 +642,40 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{
if(selectMode!=SelectNone)
{
+ if(selectMode==PlaceSave)
+ {
+ switch(key)
+ {
+ case KEY_RIGHT:
+ case 'd':
+ c->TranslateSave(ui::Point(1, 0));
+ break;
+ case KEY_LEFT:
+ case 'a':
+ c->TranslateSave(ui::Point(-1, 0));
+ break;
+ case KEY_UP:
+ case 'w':
+ c->TranslateSave(ui::Point(0, -1));
+ break;
+ case KEY_DOWN:
+ case 's':
+ c->TranslateSave(ui::Point(0, 1));
+ break;
+ case 'r':
+ if(shift)
+ {
+ //Flip
+ c->TransformSave(m2d_new(-1,0,0,1));
+ }
+ else
+ {
+ //Rotate 90deg
+ c->TransformSave(m2d_new(0,1,-1,0));
+ }
+ break;
+ }
+ }
return;
}
switch(key)
@@ -703,15 +733,14 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
}
break;
case 'v':
- if(ctrl && clipboardThumb)
+ if(ctrl)
{
- selectMode = PlaceClipboard;
+ c->LoadClipboard();
selectPoint2 = ui::Point(-1, -1);
selectPoint1 = selectPoint2;
}
break;
case 'l':
- selectMode = PlaceStamp;
selectPoint2 = ui::Point(-1, -1);
selectPoint1 = selectPoint2;
c->OpenStamps();
@@ -746,9 +775,7 @@ void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bo
void GameView::OnTick(float dt)
{
- if(selectMode==PlaceStamp && !stampThumb)
- selectMode = SelectNone;
- if(selectMode==PlaceClipboard&& !clipboardThumb)
+ if(selectMode==PlaceSave && !placeSaveThumb)
selectMode = SelectNone;
if(zoomEnabled && !zoomCursorFixed)
c->SetZoomPosition(currentMouse);
@@ -828,29 +855,20 @@ void GameView::NotifyLogChanged(GameModel * sender, string entry)
logEntries.pop_back();
}
-void GameView::NotifyClipboardChanged(GameModel * sender)
+void GameView::NotifyPlaceSaveChanged(GameModel * sender)
{
- if(clipboardThumb)
- delete clipboardThumb;
- if(sender->GetClipboard())
+ if(placeSaveThumb)
+ delete placeSaveThumb;
+ if(sender->GetPlaceSave())
{
- clipboardThumb = SaveRenderer::Ref().Render(sender->GetClipboard());
+ placeSaveThumb = SaveRenderer::Ref().Render(sender->GetPlaceSave());
+ selectMode = PlaceSave;
}
else
- clipboardThumb = NULL;
-}
-
-
-void GameView::NotifyStampChanged(GameModel * sender)
-{
- if(stampThumb)
- delete stampThumb;
- if(sender->GetStamp())
{
- stampThumb = SaveRenderer::Ref().Render(sender->GetStamp());
+ placeSaveThumb = NULL;
+ selectMode = SelectNone;
}
- else
- stampThumb = NULL;
}
void GameView::changeColour()
@@ -890,9 +908,9 @@ void GameView::OnDraw()
if(selectMode!=SelectNone)
{
- if(selectMode==PlaceStamp || selectMode==PlaceClipboard)
+ if(selectMode==PlaceSave)
{
- Thumbnail * tempThumb = selectMode==PlaceStamp?stampThumb:clipboardThumb;
+ Thumbnail * tempThumb = placeSaveThumb;
if(tempThumb && selectPoint2.X!=-1)
{
int thumbX = selectPoint2.X - (tempThumb->Size.X/2);
diff --git a/src/game/GameView.h b/src/game/GameView.h
index 85f60ed..b7c6989 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -23,7 +23,7 @@ enum DrawMode
enum SelectMode
{
- SelectNone, SelectStamp, SelectCopy, PlaceClipboard, PlaceStamp
+ SelectNone, SelectStamp, SelectCopy, PlaceSave
};
class GameController;
@@ -73,8 +73,7 @@ private:
ui::Point mousePosition;
- Thumbnail * clipboardThumb;
- Thumbnail * stampThumb;
+ Thumbnail * placeSaveThumb;
Particle sample;
@@ -99,8 +98,7 @@ public:
void NotifyZoomChanged(GameModel * sender);
void NotifyColourSelectorVisibilityChanged(GameModel * sender);
void NotifyColourSelectorColourChanged(GameModel * sender);
- void NotifyClipboardChanged(GameModel * sender);
- void NotifyStampChanged(GameModel * sender);
+ void NotifyPlaceSaveChanged(GameModel * sender);
void NotifyLogChanged(GameModel * sender, string entry);
virtual void OnMouseMove(int x, int y, int dx, int dy);
virtual void OnMouseDown(int x, int y, unsigned button);