diff options
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/interface/AvatarButton.cpp | 2 | ||||
| -rw-r--r-- | src/gui/interface/AvatarButton.h | 2 | ||||
| -rw-r--r-- | src/gui/interface/SaveButton.cpp | 2 | ||||
| -rw-r--r-- | src/gui/interface/SaveButton.h | 2 | ||||
| -rw-r--r-- | src/gui/preview/PreviewModel.cpp | 263 | ||||
| -rw-r--r-- | src/gui/preview/PreviewModel.h | 44 | ||||
| -rw-r--r-- | src/gui/profile/ProfileActivity.cpp | 2 | ||||
| -rw-r--r-- | src/gui/profile/ProfileActivity.h | 2 | ||||
| -rw-r--r-- | src/gui/save/LocalSaveActivity.cpp | 2 | ||||
| -rw-r--r-- | src/gui/save/LocalSaveActivity.h | 2 | ||||
| -rw-r--r-- | src/gui/save/ServerSaveActivity.cpp | 2 | ||||
| -rw-r--r-- | src/gui/save/ServerSaveActivity.h | 2 |
12 files changed, 93 insertions, 234 deletions
diff --git a/src/gui/interface/AvatarButton.cpp b/src/gui/interface/AvatarButton.cpp index e385c77..9176964 100644 --- a/src/gui/interface/AvatarButton.cpp +++ b/src/gui/interface/AvatarButton.cpp @@ -40,7 +40,7 @@ void AvatarButton::Tick(float dt) } } -void AvatarButton::OnResponseReady(void * imagePtr) +void AvatarButton::OnResponseReady(void * imagePtr, int identifier) { VideoBuffer * image = (VideoBuffer*)imagePtr; if(image) diff --git a/src/gui/interface/AvatarButton.h b/src/gui/interface/AvatarButton.h index 26b4348..d13f747 100644 --- a/src/gui/interface/AvatarButton.h +++ b/src/gui/interface/AvatarButton.h @@ -38,7 +38,7 @@ public: virtual void Draw(const Point& screenPos); virtual void Tick(float dt); - virtual void OnResponseReady(void * imagePtr); + virtual void OnResponseReady(void * imagePtr, int identifier); virtual void DoAction(); diff --git a/src/gui/interface/SaveButton.cpp b/src/gui/interface/SaveButton.cpp index 7ea4198..7e67e48 100644 --- a/src/gui/interface/SaveButton.cpp +++ b/src/gui/interface/SaveButton.cpp @@ -128,7 +128,7 @@ SaveButton::~SaveButton() delete file; } -void SaveButton::OnResponseReady(void * imagePtr) +void SaveButton::OnResponseReady(void * imagePtr, int identifier) { VideoBuffer * image = (VideoBuffer*)imagePtr; if(image) diff --git a/src/gui/interface/SaveButton.h b/src/gui/interface/SaveButton.h index 7bb77c4..4b9682a 100644 --- a/src/gui/interface/SaveButton.h +++ b/src/gui/interface/SaveButton.h @@ -58,7 +58,7 @@ public: virtual void Draw(const Point& screenPos); virtual void Tick(float dt); - virtual void OnResponseReady(void * imagePtr); + virtual void OnResponseReady(void * imagePtr, int identifier); void SetSelected(bool selected_) { selected = selected_; } bool GetSelected() { return selected; } diff --git a/src/gui/preview/PreviewModel.cpp b/src/gui/preview/PreviewModel.cpp index 6776445..2f58107 100644 --- a/src/gui/preview/PreviewModel.cpp +++ b/src/gui/preview/PreviewModel.cpp @@ -5,68 +5,18 @@ #include "PreviewModelException.h" PreviewModel::PreviewModel(): + doOpen(false), save(NULL), - saveComments(NULL), saveData(NULL), - doOpen(false), - commentsTotal(0), - commentsPageNumber(1), + saveComments(NULL), commentBoxEnabled(false), - updateSaveDataInfo(NULL), - updateSaveInfoInfo(NULL), - updateSaveCommentsInfo(NULL) + commentsLoaded(false), + commentsTotal(0), + commentsPageNumber(1) { } -void * PreviewModel::updateSaveInfoT(void * obj) -{ - SaveInfo * tempSave = Client::Ref().GetSave(((threadInfo*)obj)->saveID, ((threadInfo*)obj)->saveDate); - ((threadInfo*)obj)->threadFinished = true; - if (((threadInfo*)obj)->previewExited) - { - if (tempSave) - delete tempSave; - delete obj; - } - return tempSave; -} - -void * PreviewModel::updateSaveDataT(void * obj) -{ - int tempDataSize; - unsigned char * tempData = Client::Ref().GetSaveData(((threadInfo*)obj)->saveID, ((threadInfo*)obj)->saveDate, tempDataSize); - SaveData * tempSave = new SaveData(tempData, tempDataSize); - ((threadInfo*)obj)->threadFinished = true; - if (((threadInfo*)obj)->previewExited) - { - if (tempSave) - delete tempSave; - if (tempData) - free(tempData); - delete obj; - } - return tempSave; -} - -void * PreviewModel::updateSaveCommentsT(void * obj) -{ - std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(((threadInfo*)obj)->saveID, (((threadInfo*)obj)->saveDate-1)*20, 20); //saveDate is used as commentsPageNumber - ((threadInfo*)obj)->threadFinished = true; - if (((threadInfo*)obj)->previewExited) - { - if (tempComments) - { - for(int i = 0; i < tempComments->size(); i++) - delete tempComments->at(i); - tempComments->clear(); - delete tempComments; - } - delete obj; - } - return tempComments; -} - void PreviewModel::SetFavourite(bool favourite) { if(save) @@ -107,8 +57,6 @@ void PreviewModel::UpdateSave(int saveID, int saveDate) } if (saveData) { - if (saveData->data) - free(saveData->data); delete saveData; saveData = NULL; } @@ -123,32 +71,13 @@ void PreviewModel::UpdateSave(int saveID, int saveDate) notifySaveChanged(); notifySaveCommentsChanged(); - if (!updateSaveDataInfo) - updateSaveDataInfo = new threadInfo(saveID, saveDate); - if (updateSaveDataInfo->threadFinished) - { - updateSaveDataInfo->threadFinished = false; - pthread_create(&updateSaveDataThread, 0, &PreviewModel::updateSaveDataT, updateSaveDataInfo); - } - - if (!updateSaveInfoInfo) - updateSaveInfoInfo = new threadInfo(saveID, saveDate); - if(updateSaveInfoInfo->threadFinished) - { - updateSaveInfoInfo->threadFinished = false; - pthread_create(&updateSaveInfoThread, 0, &PreviewModel::updateSaveInfoT, updateSaveInfoInfo); - } + RequestBroker::Ref().Start(Client::Ref().GetSaveDataAsync(saveID, saveDate), this, 1); + RequestBroker::Ref().Start(Client::Ref().GetSaveAsync(saveID, saveDate), this, 2); - if (!GetDoOpen()) + if(!GetDoOpen()) { - if (!updateSaveCommentsInfo) - updateSaveCommentsInfo = new threadInfo(saveID, commentsPageNumber); - if (updateSaveCommentsInfo->threadFinished) - { - commentsLoaded = false; - updateSaveCommentsInfo->threadFinished = false; - pthread_create(&updateSaveCommentsThread, 0, &PreviewModel::updateSaveCommentsT, updateSaveCommentsInfo); - } + commentsLoaded = false; + RequestBroker::Ref().Start(Client::Ref().GetCommentsAsync(saveID, (commentsPageNumber-1)*20, 20), this, 3); } } @@ -184,32 +113,77 @@ bool PreviewModel::GetCommentsLoaded() void PreviewModel::UpdateComments(int pageNumber) { - commentsLoaded = false; - if(saveComments) - { - for(int i = 0; i < saveComments->size(); i++) - delete saveComments->at(i); - saveComments->clear(); - delete saveComments; - saveComments = NULL; + if(commentsLoaded){ + commentsLoaded = false; + if(saveComments) + { + for(int i = 0; i < saveComments->size(); i++) + delete saveComments->at(i); + saveComments->clear(); + delete saveComments; + saveComments = NULL; + } + + commentsPageNumber = pageNumber; + if(!GetDoOpen()) + RequestBroker::Ref().Start(Client::Ref().GetCommentsAsync(tSaveID, (commentsPageNumber-1)*20, 20), this, 3); + + notifySaveCommentsChanged(); + notifyCommentsPageChanged(); } +} - //resultCount = 0; - commentsPageNumber = pageNumber; - notifySaveCommentsChanged(); - notifyCommentsPageChanged(); +void PreviewModel::OnResponseReady(void * object, int identifier) +{ + if(identifier == 1){ + if(saveData) + delete saveData; + saveData = (std::vector<unsigned char>*)object; + } + if(identifier == 2){ + if(save) + delete save; + save = (SaveInfo*)object; + } + if(identifier == 3){ + if(saveComments) + { + for(int i = 0; i < saveComments->size(); i++) + delete saveComments->at(i); + saveComments->clear(); + delete saveComments; + saveComments = NULL; + } + saveComments = (std::vector<SaveComment*>*)object; + std::cout << object << std::endl; + commentsLoaded = true; + notifySaveCommentsChanged(); + } - //Threading - if (!updateSaveCommentsInfo) - updateSaveCommentsInfo = new threadInfo(tSaveID, commentsPageNumber); - if (updateSaveCommentsInfo->threadFinished) - { - commentsLoaded = false; - updateSaveCommentsInfo->threadFinished = false; - pthread_create(&updateSaveCommentsThread, 0, &PreviewModel::updateSaveCommentsT, updateSaveCommentsInfo); + if(identifier == 1 || identifier == 2) { + if (save && saveData) + { + commentsTotal = save->Comments; + try + { + save->SetGameSave(new GameSave(*saveData)); + } + catch(ParseException &e) + { + throw PreviewModelException("Save file corrupt or from newer version"); + } + notifySaveChanged(); + notifyCommentsPageChanged(); + } } } + +void PreviewModel::Update() +{ + +} + std::vector<SaveComment*> * PreviewModel::GetComments() { return saveComments; @@ -256,89 +230,14 @@ void PreviewModel::AddObserver(PreviewView * observer) observer->NotifyCommentBoxEnabledChanged(this); } -void PreviewModel::Update() -{ - if (updateSaveDataInfo && updateSaveDataInfo->threadFinished) - { - pthread_join(updateSaveDataThread, (void**)(&saveData)); - delete updateSaveDataInfo; - updateSaveDataInfo = NULL; - - if (save && saveData) - { - commentsTotal = save->Comments; - try - { - save->SetGameSave(new GameSave((char*)saveData->data, saveData->length)); - } - catch(ParseException &e) - { - throw PreviewModelException("Save file corrupt or from newer version"); - } - notifySaveChanged(); - notifyCommentsPageChanged(); - } - } - - if (updateSaveInfoInfo && updateSaveInfoInfo->threadFinished) - { - if (save) - { - delete save; - save = NULL; - } - pthread_join(updateSaveInfoThread, (void**)(&save)); - delete updateSaveInfoInfo; - updateSaveInfoInfo = NULL; - - if (save && saveData) - { - commentsTotal = save->Comments; - try - { - save->SetGameSave(new GameSave((char*)saveData->data, saveData->length)); - } - catch(ParseException &e) - { - throw PreviewModelException("Save file corrupt or from newer version"); - } - notifyCommentsPageChanged(); - } - notifySaveChanged(); - - if(!save) - throw PreviewModelException("Unable to load save"); - } - - if (updateSaveCommentsInfo && updateSaveCommentsInfo->threadFinished) - { - if(saveComments) - { - for(int i = 0; i < saveComments->size(); i++) - delete saveComments->at(i); - saveComments->clear(); - delete saveComments; - saveComments = NULL; - } - - commentsLoaded = true; - pthread_join(updateSaveCommentsThread, (void**)(&saveComments)); - delete updateSaveCommentsInfo; - updateSaveCommentsInfo = NULL; - notifySaveCommentsChanged(); - } -} PreviewModel::~PreviewModel() { - if (updateSaveDataInfo) - updateSaveDataInfo->previewExited = true; - if (updateSaveInfoInfo) - updateSaveInfoInfo->previewExited = true; - if (updateSaveCommentsInfo) - updateSaveCommentsInfo->previewExited = true; + RequestBroker::Ref().DetachRequestListener(this); if(save) delete save; + if (saveData) + delete saveData; if(saveComments) { for(int i = 0; i < saveComments->size(); i++) @@ -346,10 +245,4 @@ PreviewModel::~PreviewModel() saveComments->clear(); delete saveComments; } - if (saveData) - { - if (saveData->data) - free(saveData->data); - delete saveData; - } } diff --git a/src/gui/preview/PreviewModel.h b/src/gui/preview/PreviewModel.h index 1918552..8e8eabf 100644 --- a/src/gui/preview/PreviewModel.h +++ b/src/gui/preview/PreviewModel.h @@ -9,41 +9,16 @@ #include "client/SaveInfo.h" #include "gui/preview/Comment.h" #include "gui/search/Thumbnail.h" +#include "client/requestbroker/RequestListener.h" using namespace std; -struct SaveData -{ - SaveData(unsigned char * data_, int len): - data(data_), - length(len) - { - } - unsigned char * data; - int length; -}; - -struct threadInfo { - threadInfo(int saveID_, int saveDate_): - threadFinished(true), - previewExited(false), - saveID(saveID_), - saveDate(saveDate_) - { - } - bool threadFinished; - bool previewExited; - int saveID; - int saveDate; -}; - class PreviewView; -class PreviewModel { +class PreviewModel: RequestListener { bool doOpen; - bool commentBoxEnabled; vector<PreviewView*> observers; SaveInfo * save; - SaveData *saveData; + std::vector<unsigned char> * saveData; std::vector<SaveComment*> * saveComments; void notifySaveChanged(); void notifySaveCommentsChanged(); @@ -55,21 +30,11 @@ class PreviewModel { int tSaveDate; // + bool commentBoxEnabled; bool commentsLoaded; int commentsTotal; int commentsPageNumber; - threadInfo * updateSaveDataInfo; - pthread_t updateSaveDataThread; - static void * updateSaveDataT(void * obj); - - threadInfo * updateSaveInfoInfo; - pthread_t updateSaveInfoThread; - static void * updateSaveInfoT(void * obj); - - threadInfo * updateSaveCommentsInfo; - pthread_t updateSaveCommentsThread; - static void * updateSaveCommentsT(void * obj); public: PreviewModel(); SaveInfo * GetSave(); @@ -89,6 +54,7 @@ public: bool GetDoOpen(); void SetDoOpen(bool doOpen); void Update(); + virtual void OnResponseReady(void * object, int identifier); virtual ~PreviewModel(); }; diff --git a/src/gui/profile/ProfileActivity.cpp b/src/gui/profile/ProfileActivity.cpp index d690aa5..6c667a4 100644 --- a/src/gui/profile/ProfileActivity.cpp +++ b/src/gui/profile/ProfileActivity.cpp @@ -167,7 +167,7 @@ void ProfileActivity::setUserInfo(UserInfo newInfo) //exit(0); } -void ProfileActivity::OnResponseReady(void * userDataPtr) +void ProfileActivity::OnResponseReady(void * userDataPtr, int identifier) { if(loading) { diff --git a/src/gui/profile/ProfileActivity.h b/src/gui/profile/ProfileActivity.h index ed10e65..53966e3 100644 --- a/src/gui/profile/ProfileActivity.h +++ b/src/gui/profile/ProfileActivity.h @@ -18,7 +18,7 @@ class ProfileActivity: public WindowActivity, public RequestListener { public: ProfileActivity(std::string username); virtual ~ProfileActivity(); - virtual void OnResponseReady(void * userDataPtr); + virtual void OnResponseReady(void * userDataPtr, int identifier); virtual void OnDraw(); }; diff --git a/src/gui/save/LocalSaveActivity.cpp b/src/gui/save/LocalSaveActivity.cpp index 65e9dfb..a295987 100644 --- a/src/gui/save/LocalSaveActivity.cpp +++ b/src/gui/save/LocalSaveActivity.cpp @@ -133,7 +133,7 @@ void LocalSaveActivity::OnDraw() } } -void LocalSaveActivity::OnResponseReady(void * imagePtr) +void LocalSaveActivity::OnResponseReady(void * imagePtr, int identifier) { if(thumbnail) delete thumbnail; diff --git a/src/gui/save/LocalSaveActivity.h b/src/gui/save/LocalSaveActivity.h index 4668dd3..47d3938 100644 --- a/src/gui/save/LocalSaveActivity.h +++ b/src/gui/save/LocalSaveActivity.h @@ -34,6 +34,6 @@ public: void saveWrite(std::string finalFilename); virtual void Save(); virtual void OnDraw(); - virtual void OnResponseReady(void * imagePtr); + virtual void OnResponseReady(void * imagePtr, int identifier); virtual ~LocalSaveActivity(); }; diff --git a/src/gui/save/ServerSaveActivity.cpp b/src/gui/save/ServerSaveActivity.cpp index 7e83847..c129799 100644 --- a/src/gui/save/ServerSaveActivity.cpp +++ b/src/gui/save/ServerSaveActivity.cpp @@ -335,7 +335,7 @@ void ServerSaveActivity::OnDraw() } } -void ServerSaveActivity::OnResponseReady(void * imagePtr) +void ServerSaveActivity::OnResponseReady(void * imagePtr, int identifier) { if(thumbnail) delete thumbnail; diff --git a/src/gui/save/ServerSaveActivity.h b/src/gui/save/ServerSaveActivity.h index c18425b..267939b 100644 --- a/src/gui/save/ServerSaveActivity.h +++ b/src/gui/save/ServerSaveActivity.h @@ -31,7 +31,7 @@ public: virtual void ShowPublishingInfo(); virtual void ShowRules(); virtual void OnDraw(); - virtual void OnResponseReady(void * imagePtr); + virtual void OnResponseReady(void * imagePtr, int identifier); virtual void OnTick(float dt); virtual ~ServerSaveActivity(); protected: |
