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();
}
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(),

View File

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

View File

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

View File

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

View File

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

View File

@ -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
{

View File

@ -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) {}

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)
{

View File

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

View File

@ -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() {

View File

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

View File

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

View File

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

View File

@ -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), "");

View File

@ -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() {

View File

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

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
#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(Save & save);
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(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){ this->userName = userName; }
string GetUserName(){ return userName; }
void SetUserName(string userName);
string GetUserName();
void SetID(int id){ this->id = id; }
int GetID(){ return id; }
void SetID(int id);
int GetID();
void SetVotesUp(int votesUp){ this->votesUp = votesUp; }
int GetVotesUp(){ return votesUp; }
void SetVotesUp(int votesUp);
int GetVotesUp();
void SetVotesDown(int votesDown){ this->votesDown = votesDown; }
int GetVotesDown(){ return votesDown; }
void SetVotesDown(int votesDown);
int GetVotesDown();
unsigned char * GetData() { return data; }
unsigned char * GetData();
void SetData(unsigned char * data_);
int GetDataLength();
};
#endif // SAVE_H

View File

@ -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)
{
delete activePreview;
activePreview = NULL;
}
}
void SearchController::Exit()
{
if(ui::Engine::Ref().GetWindow() == searchView)
{
ui::Engine::Ref().CloseWindow();
delete activePreview;
}
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());
}

View File

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

View File

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

View File

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

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();
virtual ~SearchView();
void AttachController(SearchController * _c) { c = _c; }
virtual void OnTick(float dt);
};
#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 "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)
{

View File

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