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
class CGlobalTimer : public ITask\r
{\r
public:\r
- CGlobalTimer();\r
+ CGlobalTimer(CKernel* kernel);\r
virtual ~CGlobalTimer();\r
AUTO_SIZE;\r
\r
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
class CInputTask : public ITask \r
{\r
public:\r
- CInputTask();\r
+ CInputTask(CKernel* kernel);\r
virtual ~CInputTask();\r
\r
bool Start();\r
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
// Construction/Destruction\r
//////////////////////////////////////////////////////////////////////\r
\r
-CSoundTask::CSoundTask()\r
+CSoundTask::CSoundTask(CKernel* kernel) : ITask(kernel)\r
{\r
\r
}\r
class CSoundTask : public ITask \r
{\r
public:\r
- CSoundTask();\r
+ CSoundTask(CKernel* kernel);\r
virtual ~CSoundTask();\r
\r
bool Start();\r
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
class CVideoUpdate : public ITask \r
{\r
public:\r
- CVideoUpdate();\r
+ CVideoUpdate(CKernel* kernel);\r
virtual ~CVideoUpdate();\r
AUTO_SIZE;\r
\r
\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
\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
void move_left();\r
\r
DWORD old_counter;\r
- CKernel *kernel;\r
};\r
\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
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
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