Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/plugins/logcleaner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ logcleaner
:tags: fort auto units

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

Usage
-----
Expand Down
15 changes: 7 additions & 8 deletions plugins/logcleaner/logcleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static bool clear_combat = false;
static bool clear_sparring = true;
static bool clear_hunting = false;

static constexpr int32_t CLEANUP_TICK_INTERVAL = 97;
static constexpr int32_t CYCLE_TICKS = 97;
static int32_t cycle_timestamp = 0;

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

cycle_timestamp = 0;
return CR_OK;
}

Expand Down Expand Up @@ -166,16 +168,13 @@ static void cleanupLogs() {
}

DFhackCExport command_result plugin_onupdate(color_ostream& out, state_change_event event) {
static int32_t tick_counter = 0;

if (!is_enabled || !world)
return CR_OK;
else if (world->frame_counter - cycle_timestamp < CYCLE_TICKS)
return CR_OK;

tick_counter++;
if (tick_counter >= CLEANUP_TICK_INTERVAL) {
tick_counter = 0;
cleanupLogs();
}
cycle_timestamp = world->frame_counter;
cleanupLogs();

return CR_OK;
}
Expand Down