12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #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);
- queue->postTick();
- }
- 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++;
- }
- }
|