From: Matthijs Kooijman Date: Mon, 11 Jun 2007 20:00:28 +0000 (+0200) Subject: * Make every ITask know about the Kernel in which the run. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=c100d6f67b06abb348319e277a66b6b7ab0c4bd5;p=matthijs%2FABM2.git * Make every ITask know about the Kernel in which the run. --- diff --git a/ABM2/Engine/GlobalTimer.cpp b/ABM2/Engine/GlobalTimer.cpp index 54c68ad..e7b2999 100755 --- a/ABM2/Engine/GlobalTimer.cpp +++ b/ABM2/Engine/GlobalTimer.cpp @@ -13,7 +13,7 @@ float CGlobalTimer::dT=0; unsigned long CGlobalTimer::lastFrameIndex=0; unsigned long CGlobalTimer::thisFrameIndex=0; -CGlobalTimer::CGlobalTimer() +CGlobalTimer::CGlobalTimer(CKernel *kernel) : ITask(kernel) { } diff --git a/ABM2/Engine/GlobalTimer.h b/ABM2/Engine/GlobalTimer.h index e644210..ea587d1 100755 --- a/ABM2/Engine/GlobalTimer.h +++ b/ABM2/Engine/GlobalTimer.h @@ -14,7 +14,7 @@ class CGlobalTimer : public ITask { public: - CGlobalTimer(); + CGlobalTimer(CKernel* kernel); virtual ~CGlobalTimer(); AUTO_SIZE; diff --git a/ABM2/Engine/InputTask.cpp b/ABM2/Engine/InputTask.cpp index ed50c77..016b419 100755 --- a/ABM2/Engine/InputTask.cpp +++ b/ABM2/Engine/InputTask.cpp @@ -27,7 +27,7 @@ int CInputTask::dY=0; unsigned int CInputTask::buttons=0; unsigned int CInputTask::oldButtons=0; -CInputTask::CInputTask() +CInputTask::CInputTask(CKernel* kernel) : ITask(kernel) { #ifdef WIN32 din = NULL; diff --git a/ABM2/Engine/InputTask.h b/ABM2/Engine/InputTask.h index 0fea22b..b81f80a 100755 --- a/ABM2/Engine/InputTask.h +++ b/ABM2/Engine/InputTask.h @@ -18,7 +18,7 @@ class CInputTask : public ITask { public: - CInputTask(); + CInputTask(CKernel* kernel); virtual ~CInputTask(); bool Start(); diff --git a/ABM2/Engine/Kernel.h b/ABM2/Engine/Kernel.h index a09f11a..5e0df13 100755 --- a/ABM2/Engine/Kernel.h +++ b/ABM2/Engine/Kernel.h @@ -43,15 +43,25 @@ protected: class ITask : public IMMObject { public: - ITask(){canKill=false;priority=5000;} + /** Keeps a normal pointer to the kernel, to prevent pointer loops */ + ITask(CKernel* kernel){this->kernel = kernel, this->canKill=false;this->priority=5000;} virtual bool Start()=0; virtual void OnSuspend(){}; virtual void Update()=0; virtual void OnResume(){}; virtual void Stop()=0; + + bool canKill; long priority; +protected: + /** + * Returns a pointer to the current kernel + */ + CKernel *getKernel() {return this->kernel;} +private: + CKernel* kernel; }; #endif // !defined(AFX_KERNEL_H__4E822B7D_1078_4F70_BC8F_3BB4F83ED0AF__INCLUDED_) diff --git a/ABM2/Engine/SoundTask.cpp b/ABM2/Engine/SoundTask.cpp index d1e2124..e832cf5 100755 --- a/ABM2/Engine/SoundTask.cpp +++ b/ABM2/Engine/SoundTask.cpp @@ -8,7 +8,7 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -CSoundTask::CSoundTask() +CSoundTask::CSoundTask(CKernel* kernel) : ITask(kernel) { } diff --git a/ABM2/Engine/SoundTask.h b/ABM2/Engine/SoundTask.h index 3eae045..f93bda7 100755 --- a/ABM2/Engine/SoundTask.h +++ b/ABM2/Engine/SoundTask.h @@ -14,7 +14,7 @@ class CSoundTask : public ITask { public: - CSoundTask(); + CSoundTask(CKernel* kernel); virtual ~CSoundTask(); bool Start(); diff --git a/ABM2/Engine/VideoUpdate.cpp b/ABM2/Engine/VideoUpdate.cpp index 1d66b9c..bdbe563 100755 --- a/ABM2/Engine/VideoUpdate.cpp +++ b/ABM2/Engine/VideoUpdate.cpp @@ -24,7 +24,7 @@ int CVideoUpdate::scrWidth=640; int CVideoUpdate::scrHeight=480; int CVideoUpdate::scrBPP=16; -CVideoUpdate::CVideoUpdate() +CVideoUpdate::CVideoUpdate(CKernel* kernel) : ITask(kernel) { assert(screenWidth && screenHeight && screenBPP); this->g = new Graphics(scrWidth, scrHeight, 16, false); diff --git a/ABM2/Engine/VideoUpdate.h b/ABM2/Engine/VideoUpdate.h index 0bf5d4d..5ed88bb 100755 --- a/ABM2/Engine/VideoUpdate.h +++ b/ABM2/Engine/VideoUpdate.h @@ -16,7 +16,7 @@ class CVideoUpdate : public ITask { public: - CVideoUpdate(); + CVideoUpdate(CKernel* kernel); virtual ~CVideoUpdate(); AUTO_SIZE; diff --git a/ABM2/Playground.cpp b/ABM2/Playground.cpp index c187641..41c8b4b 100755 --- a/ABM2/Playground.cpp +++ b/ABM2/Playground.cpp @@ -10,9 +10,7 @@ LPD3DXFONT font; #endif -Playground::Playground(CKernel* kernel) { - this->kernel = kernel; -} +Playground::Playground(CKernel* kernel) : ITask(kernel) { } bool Playground::Start() { @@ -127,7 +125,7 @@ bool Playground::Start() void Playground::Update() { - CMMPointer s = this->kernel->getSpriteManager()->getSprite(SPR_FIELD); + CMMPointer s = this->getKernel()->getSpriteManager()->getSprite(SPR_FIELD); s->blit(0, 0, 1.0, 1.0, 0, 0, COLOUR_RGBA(0, 0, 255, 255)); #ifdef WIN32 diff --git a/ABM2/Playground.h b/ABM2/Playground.h index 7c14f7c..20d1052 100755 --- a/ABM2/Playground.h +++ b/ABM2/Playground.h @@ -77,5 +77,4 @@ private: void move_left(); DWORD old_counter; - CKernel *kernel; }; diff --git a/ABM2/main.cpp b/ABM2/main.cpp index 210382e..ed5e35f 100755 --- a/ABM2/main.cpp +++ b/ABM2/main.cpp @@ -135,7 +135,7 @@ void CApplication::Run(int argc, char *argv[]) //create a couple of singletons new CSettingsManager(); - new CKernel(); + CKernel *kernel = new CKernel(); //parse the 'settings.eng' file CSettingsManager::GetSingleton().ParseFile("settings.esf"); @@ -146,28 +146,28 @@ void CApplication::Run(int argc, char *argv[]) for(int i=1;ipriority=10000; - CKernel::GetSingleton().AddTask(CMMPointer(videoTask)); + kernel->AddTask(CMMPointer(videoTask)); - inputTask = new CInputTask(); + inputTask = new CInputTask(kernel); inputTask->priority=20; - CKernel::GetSingleton().AddTask(CMMPointer(inputTask)); + kernel->AddTask(CMMPointer(inputTask)); - soundTask = new CSoundTask(); + soundTask = new CSoundTask(kernel); soundTask->priority=50; - CKernel::GetSingleton().AddTask(CMMPointer(soundTask)); + kernel->AddTask(CMMPointer(soundTask)); - globalTimer=new CGlobalTimer(); + globalTimer=new CGlobalTimer(kernel); globalTimer->priority=10; - CKernel::GetSingleton().AddTask(CMMPointer(globalTimer)); + kernel->AddTask(CMMPointer(globalTimer)); CSpriteManager *sm = new CSpriteManager(videoTask->getGraphics(), defaultSprites); - CKernel::GetSingleton().setSpriteManager(sm); + kernel->setSpriteManager(sm); - Playground game(&CKernel::GetSingleton()); + Playground game(kernel); game.priority=100; - CKernel::GetSingleton().AddTask(CMMPointer(&game)); + kernel->AddTask(CMMPointer(&game)); //set up the profiler with an output handler @@ -175,10 +175,10 @@ void CApplication::Run(int argc, char *argv[]) CProfileSample::outputHandler=&profileLogHandler; //main game loop - CKernel::GetSingleton().Execute(); + kernel->Execute(); //clean up singletons - delete CKernel::GetSingletonPtr(); + delete kernel; delete CSettingsManager::GetSingletonPtr(); }