123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "TickOrganizer.h"
- #include "Constants.h"
- TickOrganizer::TickOrganizer()
- : ReferenceCounter()
- {
- queue = new TickQueue();
- workerCount = NUM_TICK_WORKERS;
- workers = new TickWorker * [workerCount];
- for (int i = 0; i < workerCount; i++)
- workers[i] = new TickWorker(queue);
- }
- TickOrganizer::~TickOrganizer()
- {
- queue->requestExit();
- for (int i = 0; i < workerCount; i++)
- {
- workers[i]->warteAufThread(10000);
- workers[i]->ende();
- workers[i]->release();
- }
- queue->release();
- delete[] workers;
- }
- void TickOrganizer::nextTick()
- {
- queue->startNextTick(&tickSources);
- bool notWaiting = 0;
- do
- {
- queue->waitForEmpty();
- for (int i = 0; i < workerCount; i++)
- notWaiting |= !workers[i]->isWaiting();
- } while (notWaiting);
- }
- void TickOrganizer::addTickSource(Block* zBlock)
- {
- tickSources.add(zBlock);
- }
- void TickOrganizer::removeTickSource(Block* zBlock)
- {
- int index = 0;
- for (Block* block : tickSources)
- {
- if (block == zBlock)
- {
- tickSources.remove(index);
- return;
- }
- index++;
- }
- }
|