* Make every ITask know about the Kernel in which the run.
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 20:00:28 +0000 (22:00 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Mon, 11 Jun 2007 20:00:28 +0000 (22:00 +0200)
12 files changed:
ABM2/Engine/GlobalTimer.cpp
ABM2/Engine/GlobalTimer.h
ABM2/Engine/InputTask.cpp
ABM2/Engine/InputTask.h
ABM2/Engine/Kernel.h
ABM2/Engine/SoundTask.cpp
ABM2/Engine/SoundTask.h
ABM2/Engine/VideoUpdate.cpp
ABM2/Engine/VideoUpdate.h
ABM2/Playground.cpp
ABM2/Playground.h
ABM2/main.cpp

index 54c68adccf02755d216d5eec9f0c53e732cd81bd..e7b299993b015d1380096cae13d3ce560ea8347b 100755 (executable)
@@ -13,7 +13,7 @@ float CGlobalTimer::dT=0;
 unsigned long CGlobalTimer::lastFrameIndex=0;\r
 unsigned long CGlobalTimer::thisFrameIndex=0;\r
 \r
-CGlobalTimer::CGlobalTimer()\r
+CGlobalTimer::CGlobalTimer(CKernel *kernel) : ITask(kernel)\r
 {\r
 \r
 }\r
index e644210504aa84a80790de83d8c1413fca5d678f..ea587d10a52961f770b600d1d1f71eb2f3799b77 100755 (executable)
@@ -14,7 +14,7 @@
 class CGlobalTimer : public ITask\r
 {\r
 public:\r
-       CGlobalTimer();\r
+       CGlobalTimer(CKernel* kernel);\r
        virtual ~CGlobalTimer();\r
        AUTO_SIZE;\r
        \r
index ed50c7705cb96f6af003cfcc55cf6f4069b9c103..016b419655195e25cddadfe0cad727c9d9953e0f 100755 (executable)
@@ -27,7 +27,7 @@ int CInputTask::dY=0;
 unsigned int CInputTask::buttons=0;\r
 unsigned int CInputTask::oldButtons=0;\r
 \r
-CInputTask::CInputTask()\r
+CInputTask::CInputTask(CKernel* kernel) : ITask(kernel)\r
 {\r
 #ifdef WIN32\r
        din = NULL;\r
index 0fea22b5de820387d7f91fbbfaca98a925dd653d..b81f80ab503c6349365d7985813fd66964b283ef 100755 (executable)
@@ -18,7 +18,7 @@
 class CInputTask : public ITask  \r
 {\r
 public:\r
-       CInputTask();\r
+       CInputTask(CKernel* kernel);\r
        virtual ~CInputTask();\r
 \r
        bool Start();\r
index a09f11a15c151bd31d2d81a5dd963fb7cb4d0a7a..5e0df13539fb802f2215616a8bf78651ee347d6b 100755 (executable)
@@ -43,15 +43,25 @@ protected:
 class ITask : public IMMObject\r
 {\r
 public:\r
-       ITask(){canKill=false;priority=5000;}\r
+       /** Keeps a normal pointer to the kernel, to prevent pointer loops */\r
+       ITask(CKernel* kernel){this->kernel = kernel, this->canKill=false;this->priority=5000;}\r
        virtual bool Start()=0;\r
        virtual void OnSuspend(){};\r
        virtual void Update()=0;\r
        virtual void OnResume(){};\r
        virtual void Stop()=0;\r
 \r
+\r
+\r
        bool canKill;\r
        long priority;\r
+protected:\r
+       /**\r
+        * Returns a pointer to the current kernel\r
+        */\r
+       CKernel *getKernel() {return this->kernel;}\r
+private:\r
+       CKernel* kernel;\r
 };\r
 \r
 #endif // !defined(AFX_KERNEL_H__4E822B7D_1078_4F70_BC8F_3BB4F83ED0AF__INCLUDED_)\r
index d1e212478d40bcb7601fe7a686c5016ea617d35e..e832cf5aeb8e16f0d240944a7108936a7f4bf097 100755 (executable)
@@ -8,7 +8,7 @@
 // Construction/Destruction\r
 //////////////////////////////////////////////////////////////////////\r
 \r
-CSoundTask::CSoundTask()\r
+CSoundTask::CSoundTask(CKernel* kernel) : ITask(kernel)\r
 {\r
 \r
 }\r
index 3eae04588d4f8fc2f66d1f5817e1f459a29244da..f93bda7aaa6da4bee433ca52c7d57ec9db92b924 100755 (executable)
@@ -14,7 +14,7 @@
 class CSoundTask : public ITask  \r
 {\r
 public:\r
-       CSoundTask();\r
+       CSoundTask(CKernel* kernel);\r
        virtual ~CSoundTask();\r
 \r
        bool Start();\r
index 1d66b9cc39461de4c26f38eaee734301ffd11aaa..bdbe563878bd7d7f8919dd73095dd1b834b8502f 100755 (executable)
@@ -24,7 +24,7 @@ int CVideoUpdate::scrWidth=640;
 int CVideoUpdate::scrHeight=480;\r
 int CVideoUpdate::scrBPP=16;\r
 \r
-CVideoUpdate::CVideoUpdate()\r
+CVideoUpdate::CVideoUpdate(CKernel* kernel) : ITask(kernel)\r
 {\r
        assert(screenWidth && screenHeight && screenBPP);\r
        this->g = new Graphics(scrWidth, scrHeight, 16, false);\r
index 0bf5d4dd2823286ee0b8399da9147b482b0b6a79..5ed88bbf7902923e0f017d0a6c313bdfd728d996 100755 (executable)
@@ -16,7 +16,7 @@
 class CVideoUpdate : public ITask  \r
 {\r
 public:\r
-       CVideoUpdate();\r
+       CVideoUpdate(CKernel* kernel);\r
        virtual ~CVideoUpdate();\r
        AUTO_SIZE;\r
 \r
index c1876418a4713d0203b61a96359092fe0df83a56..41c8b4b55fd81e407adec9a2e3202dc2f2fbdb0d 100755 (executable)
@@ -10,9 +10,7 @@ LPD3DXFONT font;
 \r
 #endif\r
 \r
-Playground::Playground(CKernel* kernel) {\r
-       this->kernel = kernel;\r
-}\r
+Playground::Playground(CKernel* kernel) : ITask(kernel) { }\r
 \r
 bool Playground::Start()\r
 {\r
@@ -127,7 +125,7 @@ bool Playground::Start()
 \r
 void Playground::Update()\r
 {\r
-       CMMPointer<Sprite> s = this->kernel->getSpriteManager()->getSprite(SPR_FIELD);\r
+       CMMPointer<Sprite> s = this->getKernel()->getSpriteManager()->getSprite(SPR_FIELD);\r
        \r
        s->blit(0, 0, 1.0, 1.0, 0, 0, COLOUR_RGBA(0, 0, 255, 255));\r
        #ifdef WIN32\r
index 7c14f7c3be3759d1b9e39e2dfaf06e4a45687a19..20d10522c07eee8628b45c322b86460ac338aa7f 100755 (executable)
@@ -77,5 +77,4 @@ private:
        void move_left();\r
 \r
        DWORD old_counter;\r
-       CKernel *kernel;\r
 };\r
index 210382e119bf86f02aeceb9219f0a31240361bbb..ed5e35f43ecc30fced089788e1c313be1ed07975 100755 (executable)
@@ -135,7 +135,7 @@ void CApplication::Run(int argc, char *argv[])
 \r
        //create a couple of singletons\r
        new CSettingsManager();\r
-       new CKernel();\r
+       CKernel *kernel = new CKernel();\r
 \r
        //parse the 'settings.eng' file\r
        CSettingsManager::GetSingleton().ParseFile("settings.esf");\r
@@ -146,28 +146,28 @@ void CApplication::Run(int argc, char *argv[])
                for(int i=1;i<argc;i++)\r
                        CSettingsManager::GetSingleton().ParseSetting(std::string(argv[i]));\r
        \r
-       videoTask = new CVideoUpdate();\r
+       videoTask = new CVideoUpdate(kernel);\r
        videoTask->priority=10000;\r
-       CKernel::GetSingleton().AddTask(CMMPointer<ITask>(videoTask));\r
+       kernel->AddTask(CMMPointer<ITask>(videoTask));\r
 \r
-       inputTask = new CInputTask();\r
+       inputTask = new CInputTask(kernel);\r
        inputTask->priority=20;\r
-       CKernel::GetSingleton().AddTask(CMMPointer<ITask>(inputTask));\r
+       kernel->AddTask(CMMPointer<ITask>(inputTask));\r
 \r
-       soundTask = new CSoundTask();\r
+       soundTask = new CSoundTask(kernel);\r
        soundTask->priority=50;\r
-       CKernel::GetSingleton().AddTask(CMMPointer<ITask>(soundTask));\r
+       kernel->AddTask(CMMPointer<ITask>(soundTask));\r
 \r
-       globalTimer=new CGlobalTimer();\r
+       globalTimer=new CGlobalTimer(kernel);\r
        globalTimer->priority=10;\r
-       CKernel::GetSingleton().AddTask(CMMPointer<ITask>(globalTimer));\r
+       kernel->AddTask(CMMPointer<ITask>(globalTimer));\r
 \r
        CSpriteManager *sm = new CSpriteManager(videoTask->getGraphics(), defaultSprites);\r
-       CKernel::GetSingleton().setSpriteManager(sm);\r
+       kernel->setSpriteManager(sm);\r
 \r
-       Playground game(&CKernel::GetSingleton());\r
+       Playground game(kernel);\r
        game.priority=100;\r
-       CKernel::GetSingleton().AddTask(CMMPointer<ITask>(&game));\r
+       kernel->AddTask(CMMPointer<ITask>(&game));\r
 \r
 \r
        //set up the profiler with an output handler\r
@@ -175,10 +175,10 @@ void CApplication::Run(int argc, char *argv[])
        CProfileSample::outputHandler=&profileLogHandler;\r
 \r
        //main game loop\r
-       CKernel::GetSingleton().Execute();\r
+       kernel->Execute();\r
        \r
        //clean up singletons\r
-       delete CKernel::GetSingletonPtr();\r
+       delete kernel;\r
        delete CSettingsManager::GetSingletonPtr();\r
 }\r
 \r