Skip to content

Commit

Permalink
#5425: Use wxTimer to have the auto-save code running on the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 22, 2020
1 parent 89eadaa commit 7f4b91b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 7 additions & 5 deletions radiant/map/AutoSaver.cpp
Expand Up @@ -96,14 +96,14 @@ void AutoMapSaver::startTimer()
{
if (!_timer) return;

_timer->start(_interval * 1000);
_timer->Start(static_cast<int>(_interval * 1000));
}

void AutoMapSaver::stopTimer()
{
if (!_timer) return;

_timer->stop();
_timer->Stop();
}

void AutoMapSaver::saveSnapshot()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down
10 changes: 6 additions & 4 deletions radiant/map/AutoSaver.h
Expand Up @@ -9,7 +9,8 @@
#include <vector>
#include <sigc++/connection.h>
#include "os/fs.h"
#include "time/Timer.h"
#include <wx/timer.h>
#include <wx/sharedptr.h>

/* 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.
Expand All @@ -19,6 +20,7 @@ namespace map
{

class AutoMapSaver :
public wxEvtHandler,
public RegisterableModule
{
// TRUE, if autosaving is enabled
Expand All @@ -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<util::Timer> _timer;
// The timer object that triggers the callback
wxSharedPtr<wxTimer> _timer;

std::size_t _changes;

Expand Down Expand Up @@ -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<int, std::string>& existingSnapshots,
const fs::path& snapshotPath, const std::string& mapName);
Expand Down

0 comments on commit 7f4b91b

Please sign in to comment.