summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-26 01:13:33 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-26 01:13:33 (GMT)
commit9e1be78bc21d1fb76a19ce12ef36193aea6e2b93 (patch)
tree081b67d551bb44fecbf6deb99b6c44ea9789614c /src
parentb2d3257ae944a3ea3b57dc8ee4171b1b2f85483e (diff)
downloadpowder-9e1be78bc21d1fb76a19ce12ef36193aea6e2b93.zip
powder-9e1be78bc21d1fb76a19ce12ef36193aea6e2b93.tar.gz
I've got to a point where I can no longer be bothered to think of a proper commit comment
Diffstat (limited to 'src')
-rw-r--r--src/client/Client.cpp12
-rw-r--r--src/client/Client.h1
-rw-r--r--src/game/GameController.cpp48
-rw-r--r--src/game/GameController.h2
-rw-r--r--src/game/GameModel.cpp1
-rw-r--r--src/game/GameView.cpp1
-rw-r--r--src/game/Tool.h1
-rw-r--r--src/interface/Button.cpp2
-rw-r--r--src/interface/Button.h2
-rw-r--r--src/preview/PreviewController.cpp33
-rw-r--r--src/preview/PreviewController.h10
-rw-r--r--src/preview/PreviewModel.cpp18
-rw-r--r--src/preview/PreviewModel.h3
-rw-r--r--src/preview/PreviewView.cpp13
-rw-r--r--src/render/RenderController.cpp16
-rw-r--r--src/render/RenderController.h6
-rw-r--r--src/search/Save.cpp87
-rw-r--r--src/search/Save.h59
-rw-r--r--src/search/SearchController.cpp53
-rw-r--r--src/search/SearchController.h11
-rw-r--r--src/search/SearchModel.cpp18
-rw-r--r--src/search/SearchModel.h4
-rw-r--r--src/search/SearchView.cpp5
-rw-r--r--src/search/SearchView.h1
-rw-r--r--src/simulation/SaveLoader.cpp38
-rw-r--r--src/simulation/SaveLoader.h23
-rw-r--r--src/simulation/Simulation.cpp11
-rw-r--r--src/simulation/Simulation.h4
28 files changed, 424 insertions, 59 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index b6fe2a4..ad12da4 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -40,6 +40,12 @@ Client::~Client()
http_done();
}
+unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength)
+{
+ dataLength = 0;
+ return NULL;
+}
+
LoginStatus Client::Login(string username, string password, User & user)
{
lastError = "";
@@ -140,16 +146,16 @@ Save * Client::GetSave(int saveID, int saveDate)
json::String tempUsername = objDocument["Username"];
json::String tempName = objDocument["Name"];
json::String tempDescription = objDocument["Description"];
- json::String tempDate = objDocument["Date"];
+ json::Number tempDate = objDocument["Date"];
json::Boolean tempPublished = objDocument["Published"];
return new Save(
tempID.Value(),
+ tempDate.Value(),
tempScoreUp.Value(),
tempScoreDown.Value(),
tempUsername.Value(),
tempName.Value(),
tempDescription.Value(),
- tempDate.Value(),
tempPublished.Value()
);
}
@@ -241,6 +247,7 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
for(int j = 0; j < savesArray.Size(); j++)
{
json::Number tempID = savesArray[j]["ID"];
+ json::Number tempDate = savesArray[j]["Date"];
json::Number tempScoreUp = savesArray[j]["ScoreUp"];
json::Number tempScoreDown = savesArray[j]["ScoreDown"];
json::String tempUsername = savesArray[j]["Username"];
@@ -248,6 +255,7 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
saveArray->push_back(
new Save(
tempID.Value(),
+ tempDate.Value(),
tempScoreUp.Value(),
tempScoreDown.Value(),
tempUsername.Value(),
diff --git a/src/client/Client.h b/src/client/Client.h
index 15ab03a..1b3bb02 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -29,6 +29,7 @@ private:
public:
Client();
~Client();
+ unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
LoginStatus Login(string username, string password, User & user);
void ClearThumbnailRequests();
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount);
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 5399cf8..e8efe0b 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -4,6 +4,7 @@
#include "Config.h"
#include "GameController.h"
#include "GameModel.h"
+#include "search/Save.h"
#include "search/SearchController.h"
#include "render/RenderController.h"
#include "login/LoginController.h"
@@ -22,6 +23,37 @@ public:
}
};
+
+class GameController::SearchCallback: public ControllerCallback
+{
+ GameController * cc;
+public:
+ SearchCallback(GameController * cc_) { cc = cc_; }
+ virtual void ControllerExit()
+ {
+ if(cc->search->GetLoadedSave())
+ {
+ if(cc->gameModel->GetSave())
+ {
+ delete cc->gameModel->GetSave();
+ }
+ cc->gameModel->SetSave(new Save(*(cc->search->GetLoadedSave())));
+ }
+ }
+};
+
+
+class GameController::RenderCallback: public ControllerCallback
+{
+ GameController * cc;
+public:
+ RenderCallback(GameController * cc_) { cc = cc_; }
+ virtual void ControllerExit()
+ {
+ //cc->gameModel->SetUser(cc->loginWindow->GetUser());
+ }
+};
+
GameController::GameController():
search(NULL),
renderOptions(NULL),
@@ -117,6 +149,18 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
void GameController::Update()
{
//gameModel->GetSimulation()->update_particles();
+ if(renderOptions && renderOptions->HasExited)
+ {
+ delete renderOptions;
+ renderOptions = NULL;
+ }
+
+ if(search && search->HasExited)
+ {
+ delete search;
+ search = NULL;
+ }
+
if(loginWindow && loginWindow->HasExited)
{
delete loginWindow;
@@ -146,7 +190,7 @@ void GameController::SetActiveTool(Tool * tool)
void GameController::OpenSearch()
{
- search = new SearchController();
+ search = new SearchController(new SearchCallback(this));
ui::Engine::Ref().ShowWindow(search->GetView());
}
@@ -168,7 +212,7 @@ void GameController::OpenDisplayOptions()
void GameController::OpenRenderOptions()
{
- renderOptions = new RenderController(gameModel->GetRenderer());
+ renderOptions = new RenderController(gameModel->GetRenderer(), new RenderCallback(this));
ui::Engine::Ref().ShowWindow(renderOptions->GetView());
}
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 4f076fd..28edd86 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -26,6 +26,8 @@ private:
LoginController * loginWindow;
public:
class LoginCallback;
+ class SearchCallback;
+ class RenderCallback;
GameController();
~GameController();
GameView * GetView();
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 33eb143..3085b09 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -122,6 +122,7 @@ Save * GameModel::GetSave()
void GameModel::SetSave(Save * newSave)
{
currentSave = newSave;
+ sim->Load(currentSave->GetData(), currentSave->GetDataLength());
notifySaveChanged();
}
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 4695227..163c2f7 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -327,6 +327,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
{
if(sender->GetSave())
{
+ saveSimulationButton->SetText(sender->GetSave()->name);
reloadButton->Enabled = true;
if(sender->GetSave()->GetID()) //Online saves have an ID, local saves have an ID of 0 and a filename
{
diff --git a/src/game/Tool.h b/src/game/Tool.h
index 4777e6d..1cf8ce4 100644
--- a/src/game/Tool.h
+++ b/src/game/Tool.h
@@ -46,7 +46,6 @@ public:
sim->create_parts(position.X, position.Y, 1, 1, toolID, 0, brush);
}
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
- std::cout << position1.X << toolID << brush << std::endl;
sim->create_line(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush);
}
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}
diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp
index 782d89b..8fe847e 100644
--- a/src/interface/Button.cpp
+++ b/src/interface/Button.cpp
@@ -152,7 +152,7 @@ void Button::Draw(const Point& screenPos)
}
}
-void Button::OnMouseUnclick(int x, int y, unsigned int button)
+void Button::OnMouseUp(int x, int y, unsigned int button)
{
if(button != 1)
{
diff --git a/src/interface/Button.h b/src/interface/Button.h
index fe4e9f9..1075b32 100644
--- a/src/interface/Button.h
+++ b/src/interface/Button.h
@@ -39,7 +39,7 @@ public:
std::string ButtonText;
virtual void OnMouseClick(int x, int y, unsigned int button);
- virtual void OnMouseUnclick(int x, int y, unsigned int button);
+ virtual void OnMouseUp(int x, int y, unsigned int button);
//virtual void OnMouseUp(int x, int y, unsigned int button);
virtual void OnMouseEnter(int x, int y);
diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp
index ef5da4e..db3cdee 100644
--- a/src/preview/PreviewController.cpp
+++ b/src/preview/PreviewController.cpp
@@ -8,8 +8,11 @@
#include "PreviewController.h"
#include "PreviewView.h"
#include "PreviewModel.h"
+#include "Controller.h"
-PreviewController::PreviewController(int saveID) {
+PreviewController::PreviewController(int saveID, ControllerCallback * callback):
+ HasExited(false)
+{
// TODO Auto-generated constructor stub
previewModel = new PreviewModel();
previewView = new PreviewView();
@@ -17,6 +20,34 @@ PreviewController::PreviewController(int saveID) {
previewView->AttachController(this);
previewModel->UpdateSave(saveID, 0);
+
+ this->callback = callback;
+}
+
+Save * PreviewController::GetSave()
+{
+ return previewModel->GetSave();
+}
+
+bool PreviewController::GetDoOpen()
+{
+ return previewModel->GetDoOpen();
+}
+
+void PreviewController::DoOpen()
+{
+ previewModel->SetDoOpen(true);
+}
+
+void PreviewController::Exit()
+{
+ if(ui::Engine::Ref().GetWindow() == previewView)
+ {
+ ui::Engine::Ref().CloseWindow();
+ }
+ if(callback)
+ callback->ControllerExit();
+ HasExited = true;
}
PreviewController::~PreviewController() {
diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h
index 373ff03..452d686 100644
--- a/src/preview/PreviewController.h
+++ b/src/preview/PreviewController.h
@@ -10,14 +10,22 @@
#include "preview/PreviewModel.h"
#include "preview/PreviewView.h"
+#include "Controller.h"
+#include "search/Save.h"
class PreviewModel;
class PreviewView;
class PreviewController {
PreviewModel * previewModel;
PreviewView * previewView;
+ ControllerCallback * callback;
public:
- PreviewController(int saveID);
+ bool HasExited;
+ PreviewController(int saveID, ControllerCallback * callback);
+ void Exit();
+ void DoOpen();
+ bool GetDoOpen();
+ Save * GetSave();
PreviewView * GetView() { return previewView; }
virtual ~PreviewController();
};
diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp
index 0e03490..07396cb 100644
--- a/src/preview/PreviewModel.cpp
+++ b/src/preview/PreviewModel.cpp
@@ -10,7 +10,8 @@
PreviewModel::PreviewModel():
save(NULL),
- savePreview(NULL)
+ savePreview(NULL),
+ doOpen(false)
{
// TODO Auto-generated constructor stub
@@ -24,6 +25,16 @@ void PreviewModel::UpdateSave(int saveID, int saveDate)
notifyPreviewChanged();
}
+void PreviewModel::SetDoOpen(bool doOpen)
+{
+ this->doOpen = doOpen;
+}
+
+bool PreviewModel::GetDoOpen()
+{
+ return doOpen;
+}
+
Thumbnail * PreviewModel::GetPreview()
{
return savePreview;
@@ -57,6 +68,9 @@ void PreviewModel::AddObserver(PreviewView * observer) {
}
PreviewModel::~PreviewModel() {
- // TODO Auto-generated destructor stub
+ if(save)
+ delete save;
+ if(savePreview)
+ delete savePreview;
}
diff --git a/src/preview/PreviewModel.h b/src/preview/PreviewModel.h
index 764771a..23ac2d7 100644
--- a/src/preview/PreviewModel.h
+++ b/src/preview/PreviewModel.h
@@ -17,6 +17,7 @@ using namespace std;
class PreviewView;
class PreviewModel {
+ bool doOpen;
vector<PreviewView*> observers;
Save * save;
Thumbnail * savePreview;
@@ -28,6 +29,8 @@ public:
Save * GetSave();
void AddObserver(PreviewView * observer);
void UpdateSave(int saveID, int saveDate);
+ bool GetDoOpen();
+ void SetDoOpen(bool doOpen);
virtual ~PreviewModel();
};
diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp
index 9d76fe7..d0bd6da 100644
--- a/src/preview/PreviewView.cpp
+++ b/src/preview/PreviewView.cpp
@@ -14,8 +14,19 @@ PreviewView::PreviewView():
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
savePreview(NULL)
{
- // TODO Auto-generated constructor stub
+ class OpenAction: public ui::ButtonAction
+ {
+ PreviewView * v;
+ public:
+ OpenAction(PreviewView * v_){ v = v_; }
+ virtual void ActionCallback(ui::Button * sender)
+ {
+ v->c->DoOpen();
+ v->c->Exit();
+ }
+ };
openButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(100, 16), "Open");
+ openButton->SetActionCallback(new OpenAction(this));
AddComponent(openButton);
saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+5), ui::Point(100, 16), "");
diff --git a/src/render/RenderController.cpp b/src/render/RenderController.cpp
index 6f7f72e..01a5d4e 100644
--- a/src/render/RenderController.cpp
+++ b/src/render/RenderController.cpp
@@ -7,7 +7,9 @@
#include "RenderController.h"
-RenderController::RenderController(Renderer * ren) {
+RenderController::RenderController(Renderer * ren, ControllerCallback * callback):
+ HasExited(false)
+{
renderView = new RenderView();
renderModel = new RenderModel();
@@ -15,6 +17,18 @@ RenderController::RenderController(Renderer * ren) {
renderModel->AddObserver(renderView);
renderModel->SetRenderer(ren);
+ this->callback = callback;
+}
+
+void RenderController::Exit()
+{
+ if(ui::Engine::Ref().GetWindow() == renderView)
+ {
+ ui::Engine::Ref().CloseWindow();
+ }
+ if(callback)
+ callback->ControllerExit();
+ HasExited = true;
}
RenderController::~RenderController() {
diff --git a/src/render/RenderController.h b/src/render/RenderController.h
index 1c574c1..704d6d4 100644
--- a/src/render/RenderController.h
+++ b/src/render/RenderController.h
@@ -11,14 +11,18 @@
#include "RenderView.h"
#include "RenderModel.h"
#include "Renderer.h"
+#include "Controller.h"
class RenderView;
class RenderModel;
class RenderController {
RenderView * renderView;
RenderModel * renderModel;
+ ControllerCallback * callback;
public:
- RenderController(Renderer * ren);
+ bool HasExited;
+ RenderController(Renderer * ren, ControllerCallback * callback = NULL);
+ void Exit();
RenderView * GetView() { return renderView; }
virtual ~RenderController();
};
diff --git a/src/search/Save.cpp b/src/search/Save.cpp
new file mode 100644
index 0000000..6a5925d
--- /dev/null
+++ b/src/search/Save.cpp
@@ -0,0 +1,87 @@
+/*
+ * Save.cpp
+ *
+ * Created on: Jan 26, 2012
+ * Author: Simon
+ */
+
+#include "Save.h"
+#include "client/Client.h"
+
+Save::Save(Save & save) :
+ userName(save.userName), name(save.name), Description(save.Description), date(
+ save.date), Published(save.Published), id(save.id), votesUp(
+ save.votesUp), votesDown(save.votesDown), data(NULL) {
+ if (save.data) {
+ std::cout << data << " " << save.data << std::endl;
+ data = (unsigned char *) malloc(save.dataLength);
+ memcpy(data, save.data, save.dataLength);
+ dataLength = save.dataLength;
+ }
+}
+
+Save::Save(int _id, int _date, int _votesUp, int _votesDown, string _userName,
+ string _name) :
+ id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
+ _name), Description("No description provided"), date(_date), Published(
+ true), data(NULL) {
+}
+
+Save::Save(int _id, int date_, int _votesUp, int _votesDown, string _userName,
+ string _name, string description_, bool published_) :
+ id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
+ _name), Description(description_), date(date_), Published(
+ published_), data(NULL) {
+}
+
+void Save::SetName(string name) {
+ this->name = name;
+}
+string Save::GetName() {
+ return name;
+}
+
+void Save::SetUserName(string userName) {
+ this->userName = userName;
+}
+string Save::GetUserName() {
+ return userName;
+}
+
+void Save::SetID(int id) {
+ this->id = id;
+}
+int Save::GetID() {
+ return id;
+}
+
+void Save::SetVotesUp(int votesUp) {
+ this->votesUp = votesUp;
+}
+int Save::GetVotesUp() {
+ return votesUp;
+}
+
+void Save::SetVotesDown(int votesDown) {
+ this->votesDown = votesDown;
+}
+int Save::GetVotesDown() {
+ return votesDown;
+}
+
+unsigned char * Save::GetData() {
+ if (!data) {
+ data = Client::Ref().GetSaveData(id, date, dataLength);
+ }
+ return data;
+}
+void Save::SetData(unsigned char * data_) {
+ data = data_;
+}
+
+int Save::GetDataLength() {
+ if (!data) {
+ data = Client::Ref().GetSaveData(id, date, dataLength);
+ }
+ return dataLength;
+}
diff --git a/src/search/Save.h b/src/search/Save.h
index 0a011ab..3186e2a 100644
--- a/src/search/Save.h
+++ b/src/search/Save.h
@@ -2,6 +2,9 @@
#define SAVE_H
#include <string>
+#include <stdlib.h>
+#include <iostream>
+#include <string.h>
using namespace std;
@@ -9,57 +12,43 @@ class Save
{
private:
int id;
+ int date;
int votesUp, votesDown;
unsigned char * data;
+ int dataLength;
public:
- Save(int _id, int _votesUp, int _votesDown, string _userName, string _name):
- id(_id),
- votesUp(_votesUp),
- votesDown(_votesDown),
- userName(_userName),
- name(_name),
- Description("No description provided"),
- Date("0/0/0"),
- Published(true)
- {
- }
-
- Save(int _id, int _votesUp, int _votesDown, string _userName, string _name, string description_, string date_, bool published_):
- id(_id),
- votesUp(_votesUp),
- votesDown(_votesDown),
- userName(_userName),
- name(_name),
- Description(description_),
- Date(date_),
- Published(published_)
- {
- }
+ Save(Save & save);
+
+ Save(int _id, int _date, int _votesUp, int _votesDown, string _userName, string _name);
+
+ Save(int _id, int date_, int _votesUp, int _votesDown, string _userName, string _name, string description_, bool published_);
string userName;
string name;
string Description;
- string Date;
bool Published;
- void SetName(string name){ this->name = name; }
- string GetName(){ return name; }
+ void SetName(string name);
+ string GetName();
+
+ void SetUserName(string userName);
+ string GetUserName();
- void SetUserName(string userName){ this->userName = userName; }
- string GetUserName(){ return userName; }
+ void SetID(int id);
+ int GetID();
- void SetID(int id){ this->id = id; }
- int GetID(){ return id; }
+ void SetVotesUp(int votesUp);
+ int GetVotesUp();
- void SetVotesUp(int votesUp){ this->votesUp = votesUp; }
- int GetVotesUp(){ return votesUp; }
+ void SetVotesDown(int votesDown);
+ int GetVotesDown();
- void SetVotesDown(int votesDown){ this->votesDown = votesDown; }
- int GetVotesDown(){ return votesDown; }
+ unsigned char * GetData();
+ void SetData(unsigned char * data_);
- unsigned char * GetData() { return data; }
+ int GetDataLength();
};
#endif // SAVE_H
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index 46a353c..96f759e 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -5,8 +5,24 @@
#include "interface/Panel.h"
#include "preview/PreviewController.h"
-SearchController::SearchController():
- activePreview(NULL)
+class SearchController::OpenCallback: public ControllerCallback
+{
+ SearchController * cc;
+public:
+ OpenCallback(SearchController * cc_) { cc = cc_; }
+ virtual void ControllerExit()
+ {
+ if(cc->activePreview->GetDoOpen())
+ {
+ cc->searchModel->SetLoadedSave(new Save(*(cc->activePreview->GetSave())));
+ cc->Exit();
+ }
+ }
+};
+
+SearchController::SearchController(ControllerCallback * callback):
+ activePreview(NULL),
+ HasExited(false)
{
searchModel = new SearchModel();
searchView = new SearchView();
@@ -15,19 +31,42 @@ SearchController::SearchController():
searchModel->UpdateSaveList(1, "");
+ this->callback = callback;
+
//Set up interface
//windowPanel.AddChild();
}
-SearchController::~SearchController()
+Save * SearchController::GetLoadedSave()
{
- if(activePreview)
+ return searchModel->GetLoadedSave();
+}
+
+void SearchController::Update()
+{
+ if(activePreview && activePreview->HasExited)
{
- ui::Engine::Ref().CloseWindow();
delete activePreview;
+ activePreview = NULL;
}
+}
+
+void SearchController::Exit()
+{
+ if(ui::Engine::Ref().GetWindow() == searchView)
+ {
+ ui::Engine::Ref().CloseWindow();
+ }
+ if(callback)
+ callback->ControllerExit();
+ HasExited = true;
+}
+
+SearchController::~SearchController()
+{
delete searchModel;
- delete searchView;
+ if(searchView)
+ delete searchView;
}
void SearchController::DoSearch(std::string query)
@@ -66,6 +105,6 @@ void SearchController::ShowOwn(bool show)
void SearchController::OpenSave(int saveID)
{
- activePreview = new PreviewController(saveID);
+ activePreview = new PreviewController(saveID, new OpenCallback(this));
ui::Engine::Ref().ShowWindow(activePreview->GetView());
}
diff --git a/src/search/SearchController.h b/src/search/SearchController.h
index d67743e..e015648 100644
--- a/src/search/SearchController.h
+++ b/src/search/SearchController.h
@@ -5,6 +5,9 @@
#include "SearchModel.h"
#include "SearchView.h"
#include "preview/PreviewController.h"
+#include "Controller.h"
+#include "Save.h"
+
class SearchView;
class SearchModel;
class SearchController
@@ -13,16 +16,22 @@ private:
SearchModel * searchModel;
SearchView * searchView;
PreviewController * activePreview;
+ ControllerCallback * callback;
public:
- SearchController();
+ class OpenCallback;
+ bool HasExited;
+ SearchController(ControllerCallback * callback = NULL);
~SearchController();
SearchView * GetView() { return searchView; }
+ void Exit();
void DoSearch(std::string query);
void NextPage();
void PrevPage();
void ChangeSort();
void ShowOwn(bool show);
void OpenSave(int saveID);
+ void Update();
+ Save * GetLoadedSave();
};
#endif // SEARCHCONTROLLER_H
diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp
index adb8cad..d9a4a1e 100644
--- a/src/search/SearchModel.cpp
+++ b/src/search/SearchModel.cpp
@@ -5,7 +5,8 @@
SearchModel::SearchModel():
currentSort("votes"),
- showOwn(false)
+ showOwn(false),
+ loadedSave(NULL)
{
}
@@ -30,6 +31,15 @@ void SearchModel::UpdateSaveList(int pageNumber, std::string query)
notifySaveListChanged();
}
+void SearchModel::SetLoadedSave(Save * save)
+{
+ loadedSave = save;
+}
+
+Save * SearchModel::GetLoadedSave(){
+ return loadedSave;
+}
+
vector<Save*> SearchModel::GetSaveList()
{
return saveList;
@@ -79,3 +89,9 @@ void SearchModel::notifyShowOwnChanged()
cObserver->NotifyShowOwnChanged(this);
}
}
+
+SearchModel::~SearchModel()
+{
+ if(loadedSave)
+ delete loadedSave;
+}
diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h
index 0ed7d86..e99e4ca 100644
--- a/src/search/SearchModel.h
+++ b/src/search/SearchModel.h
@@ -13,6 +13,7 @@ class SearchView;
class SearchModel
{
private:
+ Save * loadedSave;
string currentSort;
string lastQuery;
string lastError;
@@ -27,6 +28,7 @@ private:
void notifyShowOwnChanged();
public:
SearchModel();
+ virtual ~SearchModel();
void AddObserver(SearchView * observer);
void UpdateSaveList(int pageNumber, std::string query);
vector<Save*> GetSaveList();
@@ -38,6 +40,8 @@ public:
string GetSort() { return currentSort; }
void SetShowOwn(bool show) { showOwn = show; UpdateSaveList(1, lastQuery); notifyShowOwnChanged(); }
bool GetShowOwn() { return showOwn; }
+ void SetLoadedSave(Save * save);
+ Save * GetLoadedSave();
};
#endif // SEARCHMODEL_H
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index e589d20..8e5360f 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -212,3 +212,8 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
}
}
}
+
+void SearchView::OnTick(float dt)
+{
+ c->Update();
+}
diff --git a/src/search/SearchView.h b/src/search/SearchView.h
index 370877e..a2a5297 100644
--- a/src/search/SearchView.h
+++ b/src/search/SearchView.h
@@ -34,6 +34,7 @@ public:
SearchView();
virtual ~SearchView();
void AttachController(SearchController * _c) { c = _c; }
+ virtual void OnTick(float dt);
};
#endif // SEARCHVIEW_H
diff --git a/src/simulation/SaveLoader.cpp b/src/simulation/SaveLoader.cpp
new file mode 100644
index 0000000..350b54a
--- /dev/null
+++ b/src/simulation/SaveLoader.cpp
@@ -0,0 +1,38 @@
+/*
+ * SaveLoader.cpp
+ *
+ * Created on: Jan 26, 2012
+ * Author: Simon
+ */
+
+#include "SaveLoader.h"
+
+int SaveLoader::LoadSave(unsigned char * data, int dataLength, Simulation * sim)
+{
+ return 0;
+}
+
+unsigned char * SaveLoader::BuildSave(int & dataLength, Simulation * sim)
+{
+ return 0;
+}
+
+int SaveLoader::OPSLoadSave(unsigned char * data, int dataLength, Simulation * sim)
+{
+ return 0;
+}
+
+unsigned char * SaveLoader::OPSBuildSave(int & dataLength, Simulation * sim)
+{
+ return 0;
+}
+
+int SaveLoader::PSVLoadSave(unsigned char * data, int dataLength, Simulation * sim)
+{
+ return 0;
+}
+
+unsigned char * PSVBuildSave(int & dataLength, Simulation * sim)
+{
+ return 0;
+}
diff --git a/src/simulation/SaveLoader.h b/src/simulation/SaveLoader.h
new file mode 100644
index 0000000..e517a2b
--- /dev/null
+++ b/src/simulation/SaveLoader.h
@@ -0,0 +1,23 @@
+/*
+ * SaveLoader.h
+ *
+ * Created on: Jan 26, 2012
+ * Author: Simon
+ */
+
+#ifndef SAVELOADER_H_
+#define SAVELOADER_H_
+
+#include "Simulation.h"
+
+class SaveLoader {
+public:
+ static int LoadSave(unsigned char * data, int dataLength, Simulation * sim);
+ static unsigned char * BuildSave(int & dataLength, Simulation * sim);
+ static int OPSLoadSave(unsigned char * data, int dataLength, Simulation * sim);
+ static unsigned char * OPSBuildSave(int & dataLength, Simulation * sim);
+ static int PSVLoadSave(unsigned char * data, int dataLength, Simulation * sim);
+ static unsigned char * PSVBuildSave(int & dataLength, Simulation * sim);
+};
+
+#endif /* SAVELOADER_H_ */
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 243b903..8932863 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -6,6 +6,17 @@
#include "ElementFunctions.h"
#include "Air.h"
#include "Gravity.h"
+#include "SaveLoader.h"
+
+int Simulation::Load(unsigned char * data, int dataLength)
+{
+ return SaveLoader::LoadSave(data, dataLength, this);
+}
+
+unsigned char * Simulation::Save(int & dataLength)
+{
+ return SaveLoader::BuildSave(dataLength, this);
+}
void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
{
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index c36a18f..8a1ed16 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -204,7 +204,9 @@ public:
int sandcolour_r;
int sandcolour_g;
int sandcolour_b; //TODO: Make a single variable
- //Stuff
+ //TODO: Inlines for performance
+ int Load(unsigned char * data, int dataLength);
+ unsigned char * Save(int & dataLength);
int is_blocking(int t, int x, int y);
int is_boundary(int pt, int x, int y);
int find_next_boundary(int pt, int *x, int *y, int dm, int *em);