I've got to a point where I can no longer be bothered to think of a proper commit comment

This commit is contained in:
Simon Robertshaw 2012-01-26 01:13:33 +00:00
parent b2d3257ae9
commit 9e1be78bc2
28 changed files with 423 additions and 58 deletions

View File

@ -40,6 +40,12 @@ Client::~Client()
http_done(); 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) LoginStatus Client::Login(string username, string password, User & user)
{ {
lastError = ""; lastError = "";
@ -140,16 +146,16 @@ Save * Client::GetSave(int saveID, int saveDate)
json::String tempUsername = objDocument["Username"]; json::String tempUsername = objDocument["Username"];
json::String tempName = objDocument["Name"]; json::String tempName = objDocument["Name"];
json::String tempDescription = objDocument["Description"]; json::String tempDescription = objDocument["Description"];
json::String tempDate = objDocument["Date"]; json::Number tempDate = objDocument["Date"];
json::Boolean tempPublished = objDocument["Published"]; json::Boolean tempPublished = objDocument["Published"];
return new Save( return new Save(
tempID.Value(), tempID.Value(),
tempDate.Value(),
tempScoreUp.Value(), tempScoreUp.Value(),
tempScoreDown.Value(), tempScoreDown.Value(),
tempUsername.Value(), tempUsername.Value(),
tempName.Value(), tempName.Value(),
tempDescription.Value(), tempDescription.Value(),
tempDate.Value(),
tempPublished.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++) for(int j = 0; j < savesArray.Size(); j++)
{ {
json::Number tempID = savesArray[j]["ID"]; json::Number tempID = savesArray[j]["ID"];
json::Number tempDate = savesArray[j]["Date"];
json::Number tempScoreUp = savesArray[j]["ScoreUp"]; json::Number tempScoreUp = savesArray[j]["ScoreUp"];
json::Number tempScoreDown = savesArray[j]["ScoreDown"]; json::Number tempScoreDown = savesArray[j]["ScoreDown"];
json::String tempUsername = savesArray[j]["Username"]; 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( saveArray->push_back(
new Save( new Save(
tempID.Value(), tempID.Value(),
tempDate.Value(),
tempScoreUp.Value(), tempScoreUp.Value(),
tempScoreDown.Value(), tempScoreDown.Value(),
tempUsername.Value(), tempUsername.Value(),

View File

@ -29,6 +29,7 @@ private:
public: public:
Client(); Client();
~Client(); ~Client();
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
LoginStatus Login(string username, string password, User & user); LoginStatus Login(string username, string password, User & user);
void ClearThumbnailRequests(); void ClearThumbnailRequests();
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount); std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount);

View File

@ -4,6 +4,7 @@
#include "Config.h" #include "Config.h"
#include "GameController.h" #include "GameController.h"
#include "GameModel.h" #include "GameModel.h"
#include "search/Save.h"
#include "search/SearchController.h" #include "search/SearchController.h"
#include "render/RenderController.h" #include "render/RenderController.h"
#include "login/LoginController.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(): GameController::GameController():
search(NULL), search(NULL),
renderOptions(NULL), renderOptions(NULL),
@ -117,6 +149,18 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue)
void GameController::Update() void GameController::Update()
{ {
//gameModel->GetSimulation()->update_particles(); //gameModel->GetSimulation()->update_particles();
if(renderOptions && renderOptions->HasExited)
{
delete renderOptions;
renderOptions = NULL;
}
if(search && search->HasExited)
{
delete search;
search = NULL;
}
if(loginWindow && loginWindow->HasExited) if(loginWindow && loginWindow->HasExited)
{ {
delete loginWindow; delete loginWindow;
@ -146,7 +190,7 @@ void GameController::SetActiveTool(Tool * tool)
void GameController::OpenSearch() void GameController::OpenSearch()
{ {
search = new SearchController(); search = new SearchController(new SearchCallback(this));
ui::Engine::Ref().ShowWindow(search->GetView()); ui::Engine::Ref().ShowWindow(search->GetView());
} }
@ -168,7 +212,7 @@ void GameController::OpenDisplayOptions()
void GameController::OpenRenderOptions() void GameController::OpenRenderOptions()
{ {
renderOptions = new RenderController(gameModel->GetRenderer()); renderOptions = new RenderController(gameModel->GetRenderer(), new RenderCallback(this));
ui::Engine::Ref().ShowWindow(renderOptions->GetView()); ui::Engine::Ref().ShowWindow(renderOptions->GetView());
} }

View File

@ -26,6 +26,8 @@ private:
LoginController * loginWindow; LoginController * loginWindow;
public: public:
class LoginCallback; class LoginCallback;
class SearchCallback;
class RenderCallback;
GameController(); GameController();
~GameController(); ~GameController();
GameView * GetView(); GameView * GetView();

View File

@ -122,6 +122,7 @@ Save * GameModel::GetSave()
void GameModel::SetSave(Save * newSave) void GameModel::SetSave(Save * newSave)
{ {
currentSave = newSave; currentSave = newSave;
sim->Load(currentSave->GetData(), currentSave->GetDataLength());
notifySaveChanged(); notifySaveChanged();
} }

View File

@ -327,6 +327,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
{ {
if(sender->GetSave()) if(sender->GetSave())
{ {
saveSimulationButton->SetText(sender->GetSave()->name);
reloadButton->Enabled = true; reloadButton->Enabled = true;
if(sender->GetSave()->GetID()) //Online saves have an ID, local saves have an ID of 0 and a filename if(sender->GetSave()->GetID()) //Online saves have an ID, local saves have an ID of 0 and a filename
{ {

View File

@ -46,7 +46,6 @@ public:
sim->create_parts(position.X, position.Y, 1, 1, toolID, 0, brush); 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) { 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); 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) {} virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {}

View File

@ -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) if(button != 1)
{ {

View File

@ -39,7 +39,7 @@ public:
std::string ButtonText; std::string ButtonText;
virtual void OnMouseClick(int x, int y, unsigned int button); 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 OnMouseUp(int x, int y, unsigned int button);
virtual void OnMouseEnter(int x, int y); virtual void OnMouseEnter(int x, int y);

View File

@ -8,8 +8,11 @@
#include "PreviewController.h" #include "PreviewController.h"
#include "PreviewView.h" #include "PreviewView.h"
#include "PreviewModel.h" #include "PreviewModel.h"
#include "Controller.h"
PreviewController::PreviewController(int saveID) { PreviewController::PreviewController(int saveID, ControllerCallback * callback):
HasExited(false)
{
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
previewModel = new PreviewModel(); previewModel = new PreviewModel();
previewView = new PreviewView(); previewView = new PreviewView();
@ -17,6 +20,34 @@ PreviewController::PreviewController(int saveID) {
previewView->AttachController(this); previewView->AttachController(this);
previewModel->UpdateSave(saveID, 0); 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() { PreviewController::~PreviewController() {

View File

@ -10,14 +10,22 @@
#include "preview/PreviewModel.h" #include "preview/PreviewModel.h"
#include "preview/PreviewView.h" #include "preview/PreviewView.h"
#include "Controller.h"
#include "search/Save.h"
class PreviewModel; class PreviewModel;
class PreviewView; class PreviewView;
class PreviewController { class PreviewController {
PreviewModel * previewModel; PreviewModel * previewModel;
PreviewView * previewView; PreviewView * previewView;
ControllerCallback * callback;
public: public:
PreviewController(int saveID); bool HasExited;
PreviewController(int saveID, ControllerCallback * callback);
void Exit();
void DoOpen();
bool GetDoOpen();
Save * GetSave();
PreviewView * GetView() { return previewView; } PreviewView * GetView() { return previewView; }
virtual ~PreviewController(); virtual ~PreviewController();
}; };

View File

@ -10,7 +10,8 @@
PreviewModel::PreviewModel(): PreviewModel::PreviewModel():
save(NULL), save(NULL),
savePreview(NULL) savePreview(NULL),
doOpen(false)
{ {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
@ -24,6 +25,16 @@ void PreviewModel::UpdateSave(int saveID, int saveDate)
notifyPreviewChanged(); notifyPreviewChanged();
} }
void PreviewModel::SetDoOpen(bool doOpen)
{
this->doOpen = doOpen;
}
bool PreviewModel::GetDoOpen()
{
return doOpen;
}
Thumbnail * PreviewModel::GetPreview() Thumbnail * PreviewModel::GetPreview()
{ {
return savePreview; return savePreview;
@ -57,6 +68,9 @@ void PreviewModel::AddObserver(PreviewView * observer) {
} }
PreviewModel::~PreviewModel() { PreviewModel::~PreviewModel() {
// TODO Auto-generated destructor stub if(save)
delete save;
if(savePreview)
delete savePreview;
} }

View File

@ -17,6 +17,7 @@ using namespace std;
class PreviewView; class PreviewView;
class PreviewModel { class PreviewModel {
bool doOpen;
vector<PreviewView*> observers; vector<PreviewView*> observers;
Save * save; Save * save;
Thumbnail * savePreview; Thumbnail * savePreview;
@ -28,6 +29,8 @@ public:
Save * GetSave(); Save * GetSave();
void AddObserver(PreviewView * observer); void AddObserver(PreviewView * observer);
void UpdateSave(int saveID, int saveDate); void UpdateSave(int saveID, int saveDate);
bool GetDoOpen();
void SetDoOpen(bool doOpen);
virtual ~PreviewModel(); virtual ~PreviewModel();
}; };

View File

@ -14,8 +14,19 @@ PreviewView::PreviewView():
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)), ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
savePreview(NULL) 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 = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(100, 16), "Open");
openButton->SetActionCallback(new OpenAction(this));
AddComponent(openButton); AddComponent(openButton);
saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+5), ui::Point(100, 16), ""); saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+5), ui::Point(100, 16), "");

View File

@ -7,7 +7,9 @@
#include "RenderController.h" #include "RenderController.h"
RenderController::RenderController(Renderer * ren) { RenderController::RenderController(Renderer * ren, ControllerCallback * callback):
HasExited(false)
{
renderView = new RenderView(); renderView = new RenderView();
renderModel = new RenderModel(); renderModel = new RenderModel();
@ -15,6 +17,18 @@ RenderController::RenderController(Renderer * ren) {
renderModel->AddObserver(renderView); renderModel->AddObserver(renderView);
renderModel->SetRenderer(ren); 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() { RenderController::~RenderController() {

View File

@ -11,14 +11,18 @@
#include "RenderView.h" #include "RenderView.h"
#include "RenderModel.h" #include "RenderModel.h"
#include "Renderer.h" #include "Renderer.h"
#include "Controller.h"
class RenderView; class RenderView;
class RenderModel; class RenderModel;
class RenderController { class RenderController {
RenderView * renderView; RenderView * renderView;
RenderModel * renderModel; RenderModel * renderModel;
ControllerCallback * callback;
public: public:
RenderController(Renderer * ren); bool HasExited;
RenderController(Renderer * ren, ControllerCallback * callback = NULL);
void Exit();
RenderView * GetView() { return renderView; } RenderView * GetView() { return renderView; }
virtual ~RenderController(); virtual ~RenderController();
}; };

87
src/search/Save.cpp Normal file
View File

@ -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;
}

View File

@ -2,6 +2,9 @@
#define SAVE_H #define SAVE_H
#include <string> #include <string>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std; using namespace std;
@ -9,57 +12,43 @@ class Save
{ {
private: private:
int id; int id;
int date;
int votesUp, votesDown; int votesUp, votesDown;
unsigned char * data; unsigned char * data;
int dataLength;
public: public:
Save(int _id, int _votesUp, int _votesDown, string _userName, string _name): Save(Save & save);
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_): Save(int _id, int _date, int _votesUp, int _votesDown, string _userName, string _name);
id(_id),
votesUp(_votesUp), Save(int _id, int date_, int _votesUp, int _votesDown, string _userName, string _name, string description_, bool published_);
votesDown(_votesDown),
userName(_userName),
name(_name),
Description(description_),
Date(date_),
Published(published_)
{
}
string userName; string userName;
string name; string name;
string Description; string Description;
string Date;
bool Published; bool Published;
void SetName(string name){ this->name = name; } void SetName(string name);
string GetName(){ return name; } string GetName();
void SetUserName(string userName){ this->userName = userName; } void SetUserName(string userName);
string GetUserName(){ return userName; } string GetUserName();
void SetID(int id){ this->id = id; } void SetID(int id);
int GetID(){ return id; } int GetID();
void SetVotesUp(int votesUp){ this->votesUp = votesUp; } void SetVotesUp(int votesUp);
int GetVotesUp(){ return votesUp; } int GetVotesUp();
void SetVotesDown(int votesDown){ this->votesDown = votesDown; } void SetVotesDown(int votesDown);
int GetVotesDown(){ return votesDown; } int GetVotesDown();
unsigned char * GetData() { return data; } unsigned char * GetData();
void SetData(unsigned char * data_);
int GetDataLength();
}; };
#endif // SAVE_H #endif // SAVE_H

View File

@ -5,8 +5,24 @@
#include "interface/Panel.h" #include "interface/Panel.h"
#include "preview/PreviewController.h" #include "preview/PreviewController.h"
SearchController::SearchController(): class SearchController::OpenCallback: public ControllerCallback
activePreview(NULL) {
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(); searchModel = new SearchModel();
searchView = new SearchView(); searchView = new SearchView();
@ -15,19 +31,42 @@ SearchController::SearchController():
searchModel->UpdateSaveList(1, ""); searchModel->UpdateSaveList(1, "");
this->callback = callback;
//Set up interface //Set up interface
//windowPanel.AddChild(); //windowPanel.AddChild();
} }
SearchController::~SearchController() Save * SearchController::GetLoadedSave()
{ {
if(activePreview) return searchModel->GetLoadedSave();
}
void SearchController::Update()
{
if(activePreview && activePreview->HasExited)
{
delete activePreview;
activePreview = NULL;
}
}
void SearchController::Exit()
{
if(ui::Engine::Ref().GetWindow() == searchView)
{ {
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();
delete activePreview;
} }
if(callback)
callback->ControllerExit();
HasExited = true;
}
SearchController::~SearchController()
{
delete searchModel; delete searchModel;
delete searchView; if(searchView)
delete searchView;
} }
void SearchController::DoSearch(std::string query) void SearchController::DoSearch(std::string query)
@ -66,6 +105,6 @@ void SearchController::ShowOwn(bool show)
void SearchController::OpenSave(int saveID) void SearchController::OpenSave(int saveID)
{ {
activePreview = new PreviewController(saveID); activePreview = new PreviewController(saveID, new OpenCallback(this));
ui::Engine::Ref().ShowWindow(activePreview->GetView()); ui::Engine::Ref().ShowWindow(activePreview->GetView());
} }

View File

@ -5,6 +5,9 @@
#include "SearchModel.h" #include "SearchModel.h"
#include "SearchView.h" #include "SearchView.h"
#include "preview/PreviewController.h" #include "preview/PreviewController.h"
#include "Controller.h"
#include "Save.h"
class SearchView; class SearchView;
class SearchModel; class SearchModel;
class SearchController class SearchController
@ -13,16 +16,22 @@ private:
SearchModel * searchModel; SearchModel * searchModel;
SearchView * searchView; SearchView * searchView;
PreviewController * activePreview; PreviewController * activePreview;
ControllerCallback * callback;
public: public:
SearchController(); class OpenCallback;
bool HasExited;
SearchController(ControllerCallback * callback = NULL);
~SearchController(); ~SearchController();
SearchView * GetView() { return searchView; } SearchView * GetView() { return searchView; }
void Exit();
void DoSearch(std::string query); void DoSearch(std::string query);
void NextPage(); void NextPage();
void PrevPage(); void PrevPage();
void ChangeSort(); void ChangeSort();
void ShowOwn(bool show); void ShowOwn(bool show);
void OpenSave(int saveID); void OpenSave(int saveID);
void Update();
Save * GetLoadedSave();
}; };
#endif // SEARCHCONTROLLER_H #endif // SEARCHCONTROLLER_H

View File

@ -5,7 +5,8 @@
SearchModel::SearchModel(): SearchModel::SearchModel():
currentSort("votes"), currentSort("votes"),
showOwn(false) showOwn(false),
loadedSave(NULL)
{ {
} }
@ -30,6 +31,15 @@ void SearchModel::UpdateSaveList(int pageNumber, std::string query)
notifySaveListChanged(); notifySaveListChanged();
} }
void SearchModel::SetLoadedSave(Save * save)
{
loadedSave = save;
}
Save * SearchModel::GetLoadedSave(){
return loadedSave;
}
vector<Save*> SearchModel::GetSaveList() vector<Save*> SearchModel::GetSaveList()
{ {
return saveList; return saveList;
@ -79,3 +89,9 @@ void SearchModel::notifyShowOwnChanged()
cObserver->NotifyShowOwnChanged(this); cObserver->NotifyShowOwnChanged(this);
} }
} }
SearchModel::~SearchModel()
{
if(loadedSave)
delete loadedSave;
}

View File

@ -13,6 +13,7 @@ class SearchView;
class SearchModel class SearchModel
{ {
private: private:
Save * loadedSave;
string currentSort; string currentSort;
string lastQuery; string lastQuery;
string lastError; string lastError;
@ -27,6 +28,7 @@ private:
void notifyShowOwnChanged(); void notifyShowOwnChanged();
public: public:
SearchModel(); SearchModel();
virtual ~SearchModel();
void AddObserver(SearchView * observer); void AddObserver(SearchView * observer);
void UpdateSaveList(int pageNumber, std::string query); void UpdateSaveList(int pageNumber, std::string query);
vector<Save*> GetSaveList(); vector<Save*> GetSaveList();
@ -38,6 +40,8 @@ public:
string GetSort() { return currentSort; } string GetSort() { return currentSort; }
void SetShowOwn(bool show) { showOwn = show; UpdateSaveList(1, lastQuery); notifyShowOwnChanged(); } void SetShowOwn(bool show) { showOwn = show; UpdateSaveList(1, lastQuery); notifyShowOwnChanged(); }
bool GetShowOwn() { return showOwn; } bool GetShowOwn() { return showOwn; }
void SetLoadedSave(Save * save);
Save * GetLoadedSave();
}; };
#endif // SEARCHMODEL_H #endif // SEARCHMODEL_H

View File

@ -212,3 +212,8 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
} }
} }
} }
void SearchView::OnTick(float dt)
{
c->Update();
}

View File

@ -34,6 +34,7 @@ public:
SearchView(); SearchView();
virtual ~SearchView(); virtual ~SearchView();
void AttachController(SearchController * _c) { c = _c; } void AttachController(SearchController * _c) { c = _c; }
virtual void OnTick(float dt);
}; };
#endif // SEARCHVIEW_H #endif // SEARCHVIEW_H

View File

@ -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;
}

View File

@ -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_ */

View File

@ -6,6 +6,17 @@
#include "ElementFunctions.h" #include "ElementFunctions.h"
#include "Air.h" #include "Air.h"
#include "Gravity.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) void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
{ {

View File

@ -204,7 +204,9 @@ public:
int sandcolour_r; int sandcolour_r;
int sandcolour_g; int sandcolour_g;
int sandcolour_b; //TODO: Make a single variable 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_blocking(int t, int x, int y);
int is_boundary(int pt, 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); int find_next_boundary(int pt, int *x, int *y, int dm, int *em);