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