TickOrganizer.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "TickOrganizer.h"
  2. #include "Constants.h"
  3. TickOrganizer::TickOrganizer()
  4. : ReferenceCounter()
  5. {
  6. queue = new TickQueue();
  7. workerCount = NUM_TICK_WORKERS;
  8. workers = new TickWorker * [workerCount];
  9. for (int i = 0; i < workerCount; i++)
  10. workers[i] = new TickWorker(queue);
  11. }
  12. TickOrganizer::~TickOrganizer()
  13. {
  14. queue->requestExit();
  15. for (int i = 0; i < workerCount; i++)
  16. {
  17. workers[i]->warteAufThread(10000);
  18. workers[i]->ende();
  19. workers[i]->release();
  20. }
  21. queue->release();
  22. delete[] workers;
  23. }
  24. void TickOrganizer::nextTick()
  25. {
  26. queue->startNextTick(&tickSources);
  27. bool notWaiting = 0;
  28. do
  29. {
  30. queue->waitForEmpty();
  31. for (int i = 0; i < workerCount; i++)
  32. notWaiting |= !workers[i]->isWaiting();
  33. } while (notWaiting);
  34. queue->postTick();
  35. }
  36. void TickOrganizer::addTickSource(Block* zBlock)
  37. {
  38. tickSources.add(zBlock);
  39. }
  40. void TickOrganizer::removeTickSource(Block* zBlock)
  41. {
  42. int index = 0;
  43. for (Block* block : tickSources)
  44. {
  45. if (block == zBlock)
  46. {
  47. tickSources.remove(index);
  48. return;
  49. }
  50. index++;
  51. }
  52. }