X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=ABM2%2FEngine%2FKernel.cpp;h=35d4afce603cc425a1fe83b2275477380459315b;hb=5ddbdf638ea3b2fe93de5b7746ac827c21fc5633;hp=42e112bc7f52653f576b32e758c8d68c9ebdcea1;hpb=11384142f7b4616ae227d6bde5b8b50a158e9e3c;p=matthijs%2FABM2.git diff --git a/ABM2/Engine/Kernel.cpp b/ABM2/Engine/Kernel.cpp index 42e112b..35d4afc 100755 --- a/ABM2/Engine/Kernel.cpp +++ b/ABM2/Engine/Kernel.cpp @@ -27,19 +27,22 @@ int CKernel::Execute() { #ifdef WIN32 MSG msg; +#endif // WIN32 while(taskList.size()) { { PROFILE("Kernel task loop"); - //DWORD starting_point = GetTickCount(); + DWORD starting_point = GetTickCount(); +#ifdef WIN32 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } +#endif // WIN32 std::list< CMMPointer >::iterator it, thisIt; @@ -63,19 +66,20 @@ int CKernel::Execute() } } IMMObject::CollectGarbage(); - //DWORD end_point = GetTickCount(); -// Sleep(50 - (end_point-starting_point)); + DWORD end_point = GetTickCount(); + /* Sleep if we didn't use up too much time already */ + if (starting_point + 50 > end_point) + Sleep(50 - (end_point-starting_point)); } #ifdef _DEBUG CProfileSample::Output(); #endif } -#endif // WIN32 return 0; } -bool CKernel::AddTask(CMMPointer t) +bool CKernel::AddTask(const CMMPointer &t) { if(!t->Start())return false; @@ -90,7 +94,7 @@ bool CKernel::AddTask(CMMPointer t) return true; } -void CKernel::SuspendTask(CMMPointer t) +void CKernel::SuspendTask(const CMMPointer &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()) @@ -101,7 +105,7 @@ void CKernel::SuspendTask(CMMPointer t) } } -void CKernel::ResumeTask(CMMPointer t) +void CKernel::ResumeTask(const CMMPointer &t) { if(std::find(pausedTaskList.begin(),pausedTaskList.end(),t)!=pausedTaskList.end()) { @@ -118,7 +122,7 @@ void CKernel::ResumeTask(CMMPointer t) } } -void CKernel::RemoveTask(CMMPointer t) +void CKernel::RemoveTask(const CMMPointer &t) { if(std::find(taskList.begin(),taskList.end(),t)!=taskList.end()) {