Revises manageJobStartedEvent, and adds comments

develop
Josh Cooper 2022-03-11 13:54:22 -08:00 committed by Myk
parent c8e7869375
commit 3f05859780
1 changed files with 15 additions and 10 deletions

@ -441,21 +441,26 @@ static void manageJobStartedEvent(color_ostream& out){
multimap<Plugin*,EventHandler> copy(handlers[EventType::JOB_STARTED].begin(), handlers[EventType::JOB_STARTED].end());
int32_t tick = df::global::world->frame_counter;
// compile a list of newly started jobs
std::vector<df::job*> newly_started_jobs;
for(auto &iter : copy) { //iterate handlers
auto &handler = iter.second;
// build a list of newly started jobs
for ( df::job_list_link* link = df::global::world->jobs.list.next; link != NULL; link = link->next ) {
df::job* job = link->item;
if (job && Job::getWorker(job)) {
if (startedJobs.emplace(job).second) {
newly_started_jobs.push_back(job);
}
for ( df::job_list_link* link = df::global::world->jobs.list.next; link != NULL; link = link->next ) {
df::job* job = link->item;
// the jobs must have a worker to start
if (job && Job::getWorker(job)) {
// cross-reference against existing list of jobs with workers
if (startedJobs.emplace(job).second) {
// must be new
newly_started_jobs.push_back(job);
}
}
}
// iterate the event handlers
for(auto &iter : copy) {
auto &handler = iter.second;
// make sure the frequency of this handler is obeyed
if (tick - eventLastTick[handler.eventHandler] >= handler.freq) {
eventLastTick[handler.eventHandler] = tick;
// send the handler the new jobs
for(auto job : newly_started_jobs){
handler.eventHandler(out, (void*)job);
}