diff --git a/docs/changelog.txt b/docs/changelog.txt index 3c928792d..5e72e359c 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -37,6 +37,11 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ================================================================================ # Future +## Fixes +- `autochop`, `autodump`, `autogems`, `automelt`, `autotrade`, `buildingplan`, `dwarfmonitor`, `fix-unit-occupancy`, `fortplan`, `stockflow`: fix issues with periodic tasks not working for some time after save/load cycles +- `buildingplan`, `fortplan`: stop running before a world has fully loaded +- `autogems`: stop running repeatedly when paused + ## Misc Improvements - `mousequery`: - migrated several features from TWBT's fork diff --git a/plugins/autochop.cpp b/plugins/autochop.cpp index 858989a97..eccd16035 100644 --- a/plugins/autochop.cpp +++ b/plugins/autochop.cpp @@ -864,16 +864,12 @@ DFhackCExport command_result plugin_onupdate (color_ostream &out) if(!Maps::IsValid()) return CR_OK; - static decltype(world->frame_counter) last_frame_count = 0; - if (DFHack::World::ReadPauseState()) return CR_OK; - if (world->frame_counter - last_frame_count < 1200) // Check every day + if (world->frame_counter % 1200 != 0) // Check every day return CR_OK; - last_frame_count = world->frame_counter; - do_autochop(); return CR_OK; diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index b70c7f83c..97d266333 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -160,16 +160,12 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if(!Maps::IsValid()) return CR_OK; - static decltype(world->frame_counter) last_frame_count = 0; - if (DFHack::World::ReadPauseState()) return CR_OK; - if (world->frame_counter - last_frame_count < DELTA_TICKS) + if (world->frame_counter % DELTA_TICKS != 0) return CR_OK; - last_frame_count = world->frame_counter; - monitor.doCycle(); return CR_OK; diff --git a/plugins/autogems.cpp b/plugins/autogems.cpp index ee255846d..3ec8d769b 100644 --- a/plugins/autogems.cpp +++ b/plugins/autogems.cpp @@ -41,7 +41,6 @@ typedef int32_t mat_index; typedef std::map gem_map; bool running = false; -decltype(world->frame_counter) last_frame_count = 0; const char *tagline = "Creates a new Workshop Order setting, automatically cutting rough gems."; const char *usage = ( " enable autogems\n" @@ -218,8 +217,7 @@ void create_jobs() { } DFhackCExport command_result plugin_onupdate(color_ostream &out) { - if (running && (world->frame_counter - last_frame_count >= DELTA_TICKS)) { - last_frame_count = world->frame_counter; + if (running && !World::ReadPauseState() && (world->frame_counter % DELTA_TICKS == 0)) { create_jobs(); } @@ -336,7 +334,6 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan // Determine whether auto gem cutting has been disabled for this fort. auto config = World::GetPersistentData(CONFIG_KEY); running = config.isValid() && !config.ival(0); - last_frame_count = world->frame_counter; read_config(out); } } else if (event == DFHack::SC_MAP_UNLOADED) { diff --git a/plugins/automelt.cpp b/plugins/automelt.cpp index c01981603..852b324d6 100644 --- a/plugins/automelt.cpp +++ b/plugins/automelt.cpp @@ -168,16 +168,12 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if(!Maps::IsValid()) return CR_OK; - static decltype(world->frame_counter) last_frame_count = 0; - if (DFHack::World::ReadPauseState()) return CR_OK; - if (world->frame_counter - last_frame_count < DELTA_TICKS) + if (world->frame_counter % DELTA_TICKS != 0) return CR_OK; - last_frame_count = world->frame_counter; - monitor.doCycle(); return CR_OK; diff --git a/plugins/autotrade.cpp b/plugins/autotrade.cpp index ca3f456ec..623fd5c1e 100644 --- a/plugins/autotrade.cpp +++ b/plugins/autotrade.cpp @@ -339,16 +339,12 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) if(!Maps::IsValid()) return CR_OK; - static decltype(world->frame_counter) last_frame_count = 0; - if (DFHack::World::ReadPauseState()) return CR_OK; - if (world->frame_counter - last_frame_count < DELTA_TICKS) + if (world->frame_counter % DELTA_TICKS != 0) return CR_OK; - last_frame_count = world->frame_counter; - monitor.doCycle(); return CR_OK; diff --git a/plugins/buildingplan.cpp b/plugins/buildingplan.cpp index 37bb069a4..433e405ef 100644 --- a/plugins/buildingplan.cpp +++ b/plugins/buildingplan.cpp @@ -25,10 +25,8 @@ static bool is_planmode_enabled(df::building_type type) #define DAY_TICKS 1200 DFhackCExport command_result plugin_onupdate(color_ostream &out) { - static decltype(world->frame_counter) last_frame_count = 0; - if ((world->frame_counter - last_frame_count) >= DAY_TICKS/2) + if (Maps::IsValid() && !World::ReadPauseState() && world->frame_counter % (DAY_TICKS/2) == 0) { - last_frame_count = world->frame_counter; planner.doCycle(); roomMonitor.doCycle(); } diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index cf920e84e..3b911d340 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -1843,8 +1843,6 @@ DFhackCExport command_result plugin_onupdate (color_ostream &out) if(!Maps::IsValid()) return CR_OK; - static decltype(world->frame_counter) last_frame_count = 0; - bool is_paused = DFHack::World::ReadPauseState(); if (is_paused) { @@ -1855,10 +1853,8 @@ DFhackCExport command_result plugin_onupdate (color_ostream &out) } else { - if (world->frame_counter - last_frame_count < DELTA_TICKS) + if (world->frame_counter % DELTA_TICKS != 0) return CR_OK; - - last_frame_count = world->frame_counter; } update_dwarf_stats(is_paused); diff --git a/plugins/fix-unit-occupancy.cpp b/plugins/fix-unit-occupancy.cpp index b3cac47c5..b2e5d23ae 100644 --- a/plugins/fix-unit-occupancy.cpp +++ b/plugins/fix-unit-occupancy.cpp @@ -211,27 +211,13 @@ DFhackCExport command_result plugin_enable (color_ostream &out, bool enable) DFhackCExport command_result plugin_onupdate (color_ostream &out) { - static unsigned tick = UINT_MAX; - static decltype(world->frame_counter) old_world_frame = 0; if (is_enabled && World::isFortressMode()) { - // only increment tick when the world has changed - if (old_world_frame != world->frame_counter) + if (world->frame_counter % run_interval == 0 && !World::ReadPauseState()) { - old_world_frame = world->frame_counter; - tick++; - } - if (tick > run_interval) - { - tick = 0; fix_unit_occupancy(out); } } - else - { - tick = INT_MAX; - old_world_frame = 0; - } return CR_OK; } diff --git a/plugins/fortplan.cpp b/plugins/fortplan.cpp index 8609cb13c..a123348d2 100644 --- a/plugins/fortplan.cpp +++ b/plugins/fortplan.cpp @@ -88,10 +88,8 @@ DFhackCExport command_result plugin_init ( color_ostream &out, vector frame_counter) last_frame_count = 0; - if ((world->frame_counter - last_frame_count) >= DAY_TICKS/2) + if (Maps::IsValid() && !World::ReadPauseState() && world->frame_counter % (DAY_TICKS/2) == 0) { - last_frame_count = world->frame_counter; planner.doCycle(); } diff --git a/plugins/stockflow.cpp b/plugins/stockflow.cpp index 7cfc8ce0d..06635d8c0 100644 --- a/plugins/stockflow.cpp +++ b/plugins/stockflow.cpp @@ -247,16 +247,12 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out) { if (!Maps::IsValid()) return CR_OK; - static decltype(world->frame_counter) last_frame_count = 0; - if (DFHack::World::ReadPauseState()) return CR_OK; - if (world->frame_counter - last_frame_count < DELTA_TICKS) + if (world->frame_counter % DELTA_TICKS != 0) return CR_OK; - last_frame_count = world->frame_counter; - helper.cycle(out); return CR_OK;