-
Notifications
You must be signed in to change notification settings - Fork 2
/
Kernel.cpp
125 lines (105 loc) · 2.47 KB
/
Kernel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Kernel.cpp: implementation of the CKernel class.
//
//////////////////////////////////////////////////////////////////////
#include "engine.h"
#include "Kernel.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CKernel::CKernel()
{
SDL_Init(0);
//glfwInit();
//SDLNet_Init();
}
CKernel::~CKernel()
{
//SDLNet_Quit();
SDL_Quit();
//glfwTerminate();
}
int CKernel::Execute()
{
PROFILE("Kernel execute");
while(taskList.size())
{
std::list< CMMPointer<ITask> >::iterator it, thisIt;
for(it=taskList.begin();it!=taskList.end();)
{
ITask *t=(*it);
it++;
if(!t->canKill)t->Update();
}
//loop again to remove dead tasks
for(it=taskList.begin();it!=taskList.end();)
{
ITask *t=(*it);
thisIt=it; it++;
if(t->canKill)
{
t->Stop();
// 25-07-03 - updated this to use erase() rather than remove()
taskList.erase(thisIt);
t=0;
}
}
IMMObject::CollectGarbage();
}
//#ifdef _DEBUG
//CProfileSample::Output();
//#endif
return 0;
}
bool CKernel::AddTask(CMMPointer<ITask> t)
{
if(!t->Start())return false;
//keep the order of priorities straight
std::list< CMMPointer<ITask> >::iterator it;
for(it=taskList.begin();it!=taskList.end();it++)
{
CMMPointer<ITask> &comp=(*it);
if(comp->priority>t->priority)break;
}
taskList.insert(it,t);
return true;
}
void CKernel::SuspendTask(CMMPointer<ITask> &t)
{
//check that this task is in our list - we don't want to suspend a task that isn't running
if(std::find(taskList.begin(),taskList.end(),t)!=taskList.end())
{
t->OnSuspend();
taskList.remove(t);
pausedTaskList.push_back(t);
}
}
void CKernel::ResumeTask(CMMPointer<ITask> &t)
{
if(std::find(pausedTaskList.begin(),pausedTaskList.end(),t)!=pausedTaskList.end())
{
t->OnResume();
pausedTaskList.remove(t);
//keep the order of priorities straight
std::list< CMMPointer<ITask> >::iterator it;
for(it=taskList.begin();it!=taskList.end();it++)
{
CMMPointer<ITask> &comp=(*it);
if(comp->priority>t->priority)break;
}
taskList.insert(it,t);
}
}
void CKernel::RemoveTask(CMMPointer<ITask> &t)
{
if(std::find(taskList.begin(),taskList.end(),t)!=taskList.end())
{
t->canKill=true;
}
}
void CKernel::KillAllTasks()
{
for(std::list< CMMPointer<ITask> >::iterator it=taskList.begin();it!=taskList.end();it++)
{
(*it)->canKill=true;
}
}