From 7f4b91b1c9a70e3eeb040ad41ab778393d349470 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 22 Nov 2020 06:46:51 +0100 Subject: [PATCH] #5425: Use wxTimer to have the auto-save code running on the main thread --- radiant/map/AutoSaver.cpp | 12 +++++++----- radiant/map/AutoSaver.h | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/radiant/map/AutoSaver.cpp b/radiant/map/AutoSaver.cpp index 8a92b5922d..9b5e622aca 100644 --- a/radiant/map/AutoSaver.cpp +++ b/radiant/map/AutoSaver.cpp @@ -96,14 +96,14 @@ void AutoMapSaver::startTimer() { if (!_timer) return; - _timer->start(_interval * 1000); + _timer->Start(static_cast(_interval * 1000)); } void AutoMapSaver::stopTimer() { if (!_timer) return; - _timer->stop(); + _timer->Stop(); } void AutoMapSaver::saveSnapshot() @@ -325,9 +325,9 @@ void AutoMapSaver::constructPreferences() page.appendEntry(_("Max total Snapshot size per map (MB)"), RKEY_AUTOSAVE_MAX_SNAPSHOT_FOLDER_SIZE); } -void AutoMapSaver::onIntervalReached() +void AutoMapSaver::onIntervalReached(wxTimerEvent& ev) { - checkSave(); + checkSave(); } void AutoMapSaver::onMapEvent(IMap::MapEvent ev) @@ -371,7 +371,9 @@ void AutoMapSaver::initialiseModule(const IApplicationContext& ctx) { rMessage() << getName() << "::initialiseModule called." << std::endl; - _timer.reset(new util::Timer(_interval * 1000, std::bind(&AutoMapSaver::onIntervalReached, this))); + _timer.reset(new wxTimer(this)); + + Bind(wxEVT_TIMER, &AutoMapSaver::onIntervalReached, this); constructPreferences(); diff --git a/radiant/map/AutoSaver.h b/radiant/map/AutoSaver.h index 147bbcacaa..a86e0b6d58 100644 --- a/radiant/map/AutoSaver.h +++ b/radiant/map/AutoSaver.h @@ -9,7 +9,8 @@ #include #include #include "os/fs.h" -#include "time/Timer.h" +#include +#include /* greebo: The AutoMapSaver class lets itself being called in distinct intervals * and saves the map files either to snapshots or to a single yyyy.autosave.map file. @@ -19,6 +20,7 @@ namespace map { class AutoMapSaver : + public wxEvtHandler, public RegisterableModule { // TRUE, if autosaving is enabled @@ -30,8 +32,8 @@ class AutoMapSaver : // The autosave interval stored in seconds unsigned long _interval; - // The timer object that triggers the callback - std::unique_ptr _timer; + // The timer object that triggers the callback + wxSharedPtr _timer; std::size_t _changes; @@ -72,7 +74,7 @@ class AutoMapSaver : void saveSnapshot(); // This gets called when the interval time is over - void onIntervalReached(); + void onIntervalReached(wxTimerEvent& ev); void collectExistingSnapshots(std::map& existingSnapshots, const fs::path& snapshotPath, const std::string& mapName);