summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/GameController.cpp31
-rw-r--r--src/game/GameController.h3
-rw-r--r--src/tasks/Task.cpp64
-rw-r--r--src/tasks/Task.h10
-rw-r--r--src/tasks/TaskWindow.cpp5
-rw-r--r--src/tasks/TaskWindow.h1
-rw-r--r--src/update/UpdateActivity.cpp28
-rw-r--r--src/update/UpdateActivity.h22
8 files changed, 148 insertions, 16 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 6ed6e0f..71e485d 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -10,6 +10,7 @@
#include "login/LoginController.h"
#include "interface/Point.h"
#include "dialogues/ErrorMessage.h"
+#include "dialogues/ConfirmPrompt.h"
#include "GameModelException.h"
#include "simulation/Air.h"
#include "Notification.h"
@@ -121,7 +122,8 @@ GameController::GameController():
ssave(NULL),
console(NULL),
tagsWindow(NULL),
- options(NULL)
+ options(NULL),
+ HasDone(false)
{
gameView = new GameView();
gameModel = new GameModel();
@@ -391,6 +393,13 @@ void GameController::Tick()
commandInterface->OnTick();
}
+void GameController::Exit()
+{
+ if(ui::Engine::Ref().GetWindow() == gameView)
+ ui::Engine::Ref().CloseWindow();
+ HasDone = true;
+}
+
void GameController::Update()
{
ui::Point pos = gameView->GetMousePosition();
@@ -629,6 +638,19 @@ std::string GameController::ElementResolve(int type)
void GameController::NotifyUpdateAvailable(Client * sender)
{
+ class UpdateConfirmation: public ConfirmDialogueCallback {
+ public:
+ GameController * c;
+ UpdateConfirmation(GameController * c_) { c = c_; }
+ virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
+ if (result == ConfirmPrompt::ResultOkay)
+ {
+ c->RunUpdater();
+ }
+ }
+ virtual ~UpdateConfirmation() { }
+ };
+
class UpdateNotification : public Notification
{
GameController * c;
@@ -638,7 +660,7 @@ void GameController::NotifyUpdateAvailable(Client * sender)
virtual void Action()
{
- c->RemoveNotification(this);
+ new ConfirmPrompt("Run Updater", "Are you sure you want to run the updater, please save any changes before updating", new UpdateConfirmation(c));
}
};
@@ -650,3 +672,8 @@ void GameController::RemoveNotification(Notification * notification)
gameModel->RemoveNotification(notification);
}
+void GameController::RunUpdater()
+{
+ Exit();
+}
+
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 269cdf5..c424656 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -42,6 +42,7 @@ private:
OptionsController * options;
CommandInterface * commandInterface;
public:
+ bool HasDone;
class LoginCallback;
class SearchCallback;
class RenderCallback;
@@ -60,6 +61,7 @@ public:
bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
void Tick();
+ void Exit();
void SetZoomEnabled(bool zoomEnable);
void SetZoomPosition(ui::Point position);
@@ -107,6 +109,7 @@ public:
void RemoveNotification(Notification * notification);
virtual void NotifyUpdateAvailable(Client * sender);
+ void RunUpdater();
};
#endif // GAMECONTROLLER_H
diff --git a/src/tasks/Task.cpp b/src/tasks/Task.cpp
index c20a0ea..ec0ae99 100644
--- a/src/tasks/Task.cpp
+++ b/src/tasks/Task.cpp
@@ -17,6 +17,8 @@ void Task::SetTaskListener(TaskListener * listener)
void Task::Start()
{
+ pthread_mutex_init (&taskMutex, NULL);
+ pthread_cond_init(&taskCond, NULL);
pthread_create(&doWorkThread, 0, &Task::doWork_helper, this);
}
@@ -35,6 +37,42 @@ bool Task::GetDone()
return done;
}
+void Task::Poll()
+{
+ int newProgress;
+ bool newDone;
+ std::string newStatus;
+ pthread_mutex_lock(&taskMutex);
+ newProgress = thProgress;
+ newDone = thDone;
+ newStatus = std::string(thStatus);
+ pthread_cond_signal(&taskCond);
+ pthread_mutex_unlock(&taskMutex);
+
+ if(newProgress!=progress) {
+ progress = newProgress;
+ if(listener)
+ listener->NotifyProgress(this);
+ }
+ if(newStatus!=status) {
+ status = newStatus;
+ if(listener)
+ listener->NotifyStatus(this);
+ }
+ if(newDone!=done)
+ {
+ done = newDone;
+ if(listener)
+ listener->NotifyDone(this);
+ }
+
+ if(done)
+ {
+ pthread_join(doWorkThread, NULL);
+ pthread_mutex_destroy(&taskMutex);
+ }
+}
+
Task::~Task()
{
@@ -59,26 +97,24 @@ void * Task::doWork_helper(void * ref)
void Task::notifyProgress(int progress)
{
- if(this->progress!=progress) {
- this->progress = progress;
- if(listener)
- listener->NotifyProgress(this);
- }
+ pthread_mutex_lock(&taskMutex);
+ pthread_cond_wait(&taskCond, &taskMutex);
+ thProgress = progress;
+ pthread_mutex_unlock(&taskMutex);
}
void Task::notifyStatus(std::string status)
{
- if(this->status!=status) {
- this->status = status;
- if(listener)
- listener->NotifyStatus(this);
- }
+ pthread_mutex_lock(&taskMutex);
+ pthread_cond_wait(&taskCond, &taskMutex);
+ thStatus = status;
+ pthread_mutex_unlock(&taskMutex);
}
void Task::notifyDone()
{
- if(listener)
- {
- done = true; listener->NotifyDone(this);
- }
+ pthread_mutex_lock(&taskMutex);
+ pthread_cond_wait(&taskCond, &taskMutex);
+ thDone = true;
+ pthread_mutex_unlock(&taskMutex);
}
diff --git a/src/tasks/Task.h b/src/tasks/Task.h
index 90463cb..d5ccd4b 100644
--- a/src/tasks/Task.h
+++ b/src/tasks/Task.h
@@ -20,16 +20,26 @@ public:
int GetProgress();
bool GetDone();
std::string GetStatus();
+ void Poll();
Task() {}
virtual ~Task();
protected:
int progress;
bool done;
std::string status;
+
+ int thProgress;
+ bool thDone;
+ std::string thStatus;
+
TaskListener * listener;
pthread_t doWorkThread;
+ pthread_mutex_t taskMutex;
+ pthread_cond_t taskCond;
+
virtual void doWork();
static void * doWork_helper(void * ref);
+
void notifyProgress(int progress);
void notifyStatus(std::string status);
void notifyDone();
diff --git a/src/tasks/TaskWindow.cpp b/src/tasks/TaskWindow.cpp
index ac22c79..e0e71bf 100644
--- a/src/tasks/TaskWindow.cpp
+++ b/src/tasks/TaskWindow.cpp
@@ -48,6 +48,11 @@ void TaskWindow::NotifyProgress(Task * task)
progress = task->GetProgress();
}
+void TaskWindow::OnTick(float dt)
+{
+ task->Poll();
+}
+
void TaskWindow::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
diff --git a/src/tasks/TaskWindow.h b/src/tasks/TaskWindow.h
index cacb59c..d7edf8b 100644
--- a/src/tasks/TaskWindow.h
+++ b/src/tasks/TaskWindow.h
@@ -25,6 +25,7 @@ public:
virtual void NotifyStatus(Task * task);
virtual void NotifyDone(Task * task);
virtual void NotifyProgress(Task * task);
+ virtual void OnTick(float dt);
virtual void OnDraw();
virtual ~TaskWindow();
};
diff --git a/src/update/UpdateActivity.cpp b/src/update/UpdateActivity.cpp
new file mode 100644
index 0000000..6072045
--- /dev/null
+++ b/src/update/UpdateActivity.cpp
@@ -0,0 +1,28 @@
+/*
+ * UpdateActivity.cpp
+ *
+ * Created on: Jun 20, 2012
+ * Author: Simon
+ */
+
+#include "UpdateActivity.h"
+#include "tasks/Task.h"
+
+class UpdateDownloadTask : public Task
+{
+ UpdateDownloadTask() {};
+ /*virtual void doWork()
+ {
+ while(1)
+ }*/
+};
+
+UpdateActivity::UpdateActivity() {
+ // TODO Auto-generated constructor stub
+
+}
+
+UpdateActivity::~UpdateActivity() {
+ // TODO Auto-generated destructor stub
+}
+
diff --git a/src/update/UpdateActivity.h b/src/update/UpdateActivity.h
new file mode 100644
index 0000000..6865fdf
--- /dev/null
+++ b/src/update/UpdateActivity.h
@@ -0,0 +1,22 @@
+/*
+ * UpdateActivity.h
+ *
+ * Created on: Jun 20, 2012
+ * Author: Simon
+ */
+
+#ifndef UPDATEACTIVITY_H_
+#define UPDATEACTIVITY_H_
+
+#include "interface/Window.h"
+#include "tasks/TaskWindow.h"
+
+class UpdateActivity {
+ Task * updateDownloadTask;
+ TaskWindow * updateWindow;
+public:
+ UpdateActivity();
+ virtual ~UpdateActivity();
+};
+
+#endif /* UPDATEACTIVITY_H_ */