TickOrganizer.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }
  35. void TickOrganizer::addTickSource( Block* zBlock )
  36. {
  37. tickSources.add( zBlock );
  38. }
  39. void TickOrganizer::removeTickSource( Block* zBlock )
  40. {
  41. int index = 0;
  42. for( Block* block : tickSources )
  43. {
  44. if( block == zBlock )
  45. {
  46. tickSources.remove( index );
  47. return;
  48. }
  49. index++;
  50. }
  51. }