|
|
@ -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(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 ) {
|
|
|
|
for ( df::job_list_link* link = df::global::world->jobs.list.next; link != NULL; link = link->next ) {
|
|
|
|
df::job* job = link->item;
|
|
|
|
df::job* job = link->item;
|
|
|
|
|
|
|
|
// the jobs must have a worker to start
|
|
|
|
if (job && Job::getWorker(job)) {
|
|
|
|
if (job && Job::getWorker(job)) {
|
|
|
|
|
|
|
|
// cross-reference against existing list of jobs with workers
|
|
|
|
if (startedJobs.emplace(job).second) {
|
|
|
|
if (startedJobs.emplace(job).second) {
|
|
|
|
|
|
|
|
// must be new
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|