From 92645ccb5be21bd12c9d1df8c6e5f9f537e0029c Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Tue, 8 Nov 2022 12:43:23 -0800 Subject: [PATCH 1/2] Fixes JOB_STARTED event --- docs/changelog.txt | 1 + library/modules/EventManager.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 7f15d5279..793e91858 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -42,6 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `tiletypes`: no longer resets dig priority to the default when updating other properties of a tile - `automaterial`: fix rendering errors with box boundary markers - Core: fix the segmentation fault with the REPORT event in EventManager +- Core: fix the new JOB_STARTED event only sending each event once, to the first handler listed ## Misc Improvements - `blueprint`: new ``--smooth`` option for recording all smoothed floors and walls instead of just the ones that require smoothing for later carving diff --git a/library/modules/EventManager.cpp b/library/modules/EventManager.cpp index d8f8543a0..eb41bbeaf 100644 --- a/library/modules/EventManager.cpp +++ b/library/modules/EventManager.cpp @@ -444,12 +444,14 @@ static void manageJobStartedEvent(color_ostream& out) { // iterate event handler callbacks multimap copy(handlers[EventType::JOB_STARTED].begin(), handlers[EventType::JOB_STARTED].end()); - for (auto &key_value : copy) { - auto &handler = key_value.second; - for (df::job_list_link* link = df::global::world->jobs.list.next; link != nullptr; link = link->next) { - df::job* job = link->item; + for (df::job_list_link* link = df::global::world->jobs.list.next; link != nullptr; link = link->next) { + df::job* job = link->item; + bool send = false; + for (auto &key_value : copy) { + auto &handler = key_value.second; // the jobs must have a worker to start - if (job && Job::getWorker(job) && !startedJobs.count(job->id)) { + if (send || (job && Job::getWorker(job) && !startedJobs.count(job->id))) { + send = true; startedJobs.emplace(job->id); handler.eventHandler(out, job); } From f3ae19391420586ffa242ea3fb7955fae786b08c Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Wed, 9 Nov 2022 16:49:35 -0800 Subject: [PATCH 2/2] Update EventManager.cpp --- library/modules/EventManager.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/library/modules/EventManager.cpp b/library/modules/EventManager.cpp index eb41bbeaf..16f21ffdd 100644 --- a/library/modules/EventManager.cpp +++ b/library/modules/EventManager.cpp @@ -446,13 +446,11 @@ static void manageJobStartedEvent(color_ostream& out) { multimap copy(handlers[EventType::JOB_STARTED].begin(), handlers[EventType::JOB_STARTED].end()); for (df::job_list_link* link = df::global::world->jobs.list.next; link != nullptr; link = link->next) { df::job* job = link->item; - bool send = false; - for (auto &key_value : copy) { - auto &handler = key_value.second; - // the jobs must have a worker to start - if (send || (job && Job::getWorker(job) && !startedJobs.count(job->id))) { - send = true; - startedJobs.emplace(job->id); + if (job && Job::getWorker(job) && !startedJobs.count(job->id)) { + startedJobs.emplace(job->id); + for (auto &key_value : copy) { + auto &handler = key_value.second; + // the jobs must have a worker to start handler.eventHandler(out, job); } }