Skip to content

Commit 8a89563

Browse files
authored
Merge pull request #5727 from Bumber64/logcleaner-ticks
Fix `logcleaner` to use ticks
2 parents a3ac172 + 80b4446 commit 8a89563

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

docs/plugins/logcleaner.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ logcleaner
55
:tags: fort auto units
66

77
This plugin prevents spam from cluttering your announcement history and filling
8-
the 3000-item reports buffer. It runs every 100 ticks and clears selected report
9-
types from both the global reports buffer and per-unit logs.
8+
the 3000-item reports buffer. It runs approximately every 100 ticks and clears
9+
selected report types from both the global reports buffer and per-unit logs.
1010

1111
Usage
1212
-----

plugins/logcleaner/logcleaner.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static bool clear_combat = false;
3131
static bool clear_sparring = true;
3232
static bool clear_hunting = false;
3333

34-
static constexpr int32_t CLEANUP_TICK_INTERVAL = 97;
34+
static constexpr int32_t CYCLE_TICKS = 97;
35+
static int32_t cycle_timestamp = 0;
3536

3637
static void cleanupLogs();
3738
static command_result do_command(color_ostream& out, std::vector<std::string>& params);
@@ -116,6 +117,7 @@ DFhackCExport command_result plugin_load_site_data(color_ostream& out) {
116117
clear_sparring = config.get_bool(CONFIG_CLEAR_SPARING);
117118
clear_hunting = config.get_bool(CONFIG_CLEAR_HUNTING);
118119

120+
cycle_timestamp = 0;
119121
return CR_OK;
120122
}
121123

@@ -166,16 +168,13 @@ static void cleanupLogs() {
166168
}
167169

168170
DFhackCExport command_result plugin_onupdate(color_ostream& out, state_change_event event) {
169-
static int32_t tick_counter = 0;
170-
171171
if (!is_enabled || !world)
172172
return CR_OK;
173+
else if (world->frame_counter - cycle_timestamp < CYCLE_TICKS)
174+
return CR_OK;
173175

174-
tick_counter++;
175-
if (tick_counter >= CLEANUP_TICK_INTERVAL) {
176-
tick_counter = 0;
177-
cleanupLogs();
178-
}
176+
cycle_timestamp = world->frame_counter;
177+
cleanupLogs();
179178

180179
return CR_OK;
181180
}

0 commit comments

Comments
 (0)