From b2d3257ae944a3ea3b57dc8ee4171b1b2f85483e Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 25 Jan 2012 19:18:24 +0000 Subject: Better way of managing Controllers diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 85518f7..5399cf8 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -19,8 +19,6 @@ public: virtual void ControllerExit() { cc->gameModel->SetUser(cc->loginWindow->GetUser()); - delete cc->loginWindow; - cc->loginWindow = NULL; } }; @@ -116,9 +114,14 @@ void GameController::DrawPoints(queue & pointQueue) } } -void GameController::Tick() +void GameController::Update() { //gameModel->GetSimulation()->update_particles(); + if(loginWindow && loginWindow->HasExited) + { + delete loginWindow; + loginWindow = NULL; + } } void GameController::SetPaused(bool pauseState) diff --git a/src/game/GameController.h b/src/game/GameController.h index 157df99..4f076fd 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -31,7 +31,7 @@ public: GameView * GetView(); void AdjustBrushSize(int direction); void DrawPoints(queue & pointQueue); - void Tick(); + void Update(); void SetPaused(bool pauseState); void SetPaused(); void SetActiveMenu(Menu * menu); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 70f6663..4695227 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -414,7 +414,7 @@ void GameView::OnTick(float dt) { c->DrawPoints(pointQueue); } - c->Tick(); + c->Update(); } void GameView::OnDraw() diff --git a/src/login/LoginController.cpp b/src/login/LoginController.cpp index a3162be..1a21fc6 100644 --- a/src/login/LoginController.cpp +++ b/src/login/LoginController.cpp @@ -8,7 +8,9 @@ #include "LoginController.h" #include "client/User.h" -LoginController::LoginController(ControllerCallback * callback) { +LoginController::LoginController(ControllerCallback * callback): + HasExited(false) +{ // TODO Auto-generated constructor stub loginView = new LoginView(); loginModel = new LoginModel(); @@ -38,6 +40,7 @@ void LoginController::Exit() } if(callback) callback->ControllerExit(); + HasExited = true; } LoginController::~LoginController() { diff --git a/src/login/LoginController.h b/src/login/LoginController.h index eb15d64..b20e187 100644 --- a/src/login/LoginController.h +++ b/src/login/LoginController.h @@ -23,6 +23,7 @@ class LoginController { LoginModel * loginModel; ControllerCallback * callback; public: + bool HasExited; LoginController(ControllerCallback * callback = NULL); void Login(string username, string password); void Exit(); -- cgit v0.9.2-21-gd62e