Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.3KB

  1. #include "Kernel.h"
  2. namespace BlueCore
  3. {
  4. Kernel::Kernel() :
  5. _Changed(true), _Clear(false)
  6. {
  7. }
  8. void Kernel::addTask(KernelTask* task, int priority)
  9. {
  10. _AddedTasks.push_back(KernelTaskContainer (task, priority));
  11. _Changed = true;
  12. }
  13. void Kernel::removeTask(KernelTask* task)
  14. {
  15. _RemovedTasks.push_back(task );
  16. _Changed = true;
  17. }
  18. void Kernel::removeAllTasks()
  19. {
  20. _Clear = true;
  21. }
  22. void Kernel::setTaskPriority(KernelTask* task, int priority)
  23. {
  24. std::list<KernelTaskContainer>::iterator i;
  25. for (i = _Tasks.begin(); i != _Tasks.end(); i++)
  26. {
  27. if ((*i)._Task == task)
  28. {
  29. (*i)._Priority = priority;
  30. _Changed = true;
  31. return;
  32. }
  33. }
  34. }
  35. bool Kernel::tick()
  36. {
  37. if (_Changed)
  38. {
  39. std::list<KernelTaskContainer>::iterator i;
  40. for (i = _AddedTasks.begin(); i != _AddedTasks.end(); i++)
  41. {
  42. _Tasks.push_back( *i );
  43. }
  44. _AddedTasks.clear();
  45. _RemovedTasks.clear();
  46. _Tasks.sort();
  47. _Changed = false;
  48. }
  49. std::list<KernelTaskContainer>::iterator i = _Tasks.begin();
  50. std::list<KernelTaskContainer>::iterator end = _Tasks.end();
  51. if (i == end)
  52. return false;
  53. while (i != end)
  54. {
  55. if ((*i)._Task.valid())
  56. (*i)._Task->tick();
  57. i++;
  58. }
  59. if (_Clear)
  60. {
  61. _Tasks.clear();
  62. _Clear = false;
  63. }
  64. return true;
  65. }
  66. } // namespace BlueCore