Skip to content

Commit

Permalink
#5425: Move AutoSaver to UI module to migrate the code to work on the…
Browse files Browse the repository at this point in the history
… UI thread.
  • Loading branch information
codereader committed Nov 22, 2020
1 parent dfdb8dd commit 89eadaa
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 32 deletions.
3 changes: 3 additions & 0 deletions include/imap.h
Expand Up @@ -135,6 +135,9 @@ class IMap :
*/
virtual std::string getMapName() const = 0;

// Returns true if this map is still unnamed (never saved yet)
virtual bool isUnnamed() const = 0;

/**
* Signal fired when the name of this map is changing.
*/
Expand Down
1 change: 1 addition & 0 deletions radiant/Makefile.am
Expand Up @@ -192,5 +192,6 @@ darkradiant_SOURCES = main.cpp \
settings/Win32Registry.cpp \
settings/LocalisationModule.cpp \
settings/LocalisationProvider.cpp \
map/AutoSaver.cpp \
map/StartupMapLoader.cpp \
log/Console.cpp
15 changes: 7 additions & 8 deletions radiantcore/map/AutoSaver.cpp → radiant/map/AutoSaver.cpp
Expand Up @@ -21,7 +21,6 @@
#include <limits.h>
#include "string/string.h"
#include "string/convert.h"
#include "map/Map.h"
#include "module/StaticModule.h"
#include "messages/NotificationMessage.h"
#include "messages/AutomaticMapSaveRequest.h"
Expand Down Expand Up @@ -141,7 +140,7 @@ void AutoMapSaver::saveSnapshot()
rMessage() << "Autosaving snapshot to " << filename << std::endl;

// Dump to map to the next available filename
GlobalMap().saveDirect(filename);
GlobalCommandSystem().executeCommand("SaveMapCopyAs", filename);

handleSnapshotSizeLimit(existingSnapshots, snapshotPath, mapName);
}
Expand Down Expand Up @@ -255,7 +254,7 @@ void AutoMapSaver::checkSave()
if (_enabled)
{
// only snapshot if not working on an unnamed map
if (_snapshotsEnabled && !GlobalMap().isUnnamed())
if (_snapshotsEnabled && !GlobalMapModule().isUnnamed())
{
try
{
Expand All @@ -268,7 +267,7 @@ void AutoMapSaver::checkSave()
}
else
{
if (GlobalMap().isUnnamed())
if (GlobalMapModule().isUnnamed())
{
// Get the maps path (within the mod path)
std::string autoSaveFilename = GlobalGameManager().getMapPath();
Expand All @@ -283,12 +282,12 @@ void AutoMapSaver::checkSave()
rMessage() << "Autosaving unnamed map to " << autoSaveFilename << std::endl;

// Invoke the save call
GlobalMap().saveDirect(autoSaveFilename);
GlobalCommandSystem().executeCommand("SaveMapCopyAs", autoSaveFilename);
}
else
{
// Construct the new filename (e.g. "test_autosave.map")
std::string filename = GlobalMap().getMapName();
std::string filename = GlobalMapModule().getMapName();
std::string extension = os::getExtension(filename);

// Cut off the extension
Expand All @@ -299,7 +298,7 @@ void AutoMapSaver::checkSave()
rMessage() << "Autosaving map to " << filename << std::endl;

// Invoke the save call
GlobalMap().saveDirect(filename);
GlobalCommandSystem().executeCommand("SaveMapCopyAs", filename);
}
}
}
Expand Down Expand Up @@ -387,7 +386,7 @@ void AutoMapSaver::initialiseModule(const IApplicationContext& ctx)
));

// Get notified when the map is loaded afresh
_signalConnections.push_back(GlobalMap().signal_mapEvent().connect(
_signalConnections.push_back(GlobalMapModule().signal_mapEvent().connect(
sigc::mem_fun(*this, &AutoMapSaver::onMapEvent)
));

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion radiantcore/Makefile.am
Expand Up @@ -144,7 +144,6 @@ libradiantcore_la_SOURCES = Radiant.cpp \
map/namespace/ComplexName.cpp \
map/namespace/Namespace.cpp \
map/namespace/NamespaceFactory.cpp \
map/AutoSaver.cpp \
map/CounterManager.cpp \
map/EditingStopwatch.cpp \
map/EditingStopwatchInfoFileModule.cpp \
Expand Down
41 changes: 31 additions & 10 deletions radiantcore/map/Map.cpp
Expand Up @@ -571,22 +571,34 @@ bool Map::saveAs()

void Map::saveCopyAs()
{
// Let's see if we can remember a
if (_lastCopyMapName.empty()) {
// Let's see if we can remember a map name from a previous save
if (_lastCopyMapName.empty())
{
_lastCopyMapName = getMapName();
}

MapFileSelection fileInfo =
MapFileManager::getMapFileSelection(false, _("Save Copy As..."), filetype::TYPE_MAP, _lastCopyMapName);
auto fileInfo = MapFileManager::getMapFileSelection(false,
_("Save Copy As..."), filetype::TYPE_MAP, _lastCopyMapName);

if (!fileInfo.fullPath.empty())
{
// Remember the last name
_lastCopyMapName = fileInfo.fullPath;
saveCopyAs(fileInfo.fullPath, fileInfo.mapFormat);
}
}

// Return the result of the actual save method
saveDirect(fileInfo.fullPath, fileInfo.mapFormat);
void Map::saveCopyAs(const std::string& absolutePath, const MapFormatPtr& mapFormat)
{
if (absolutePath.empty())
{
rWarning() << "Map::saveCopyAs: path must not be empty" << std::endl;
return;
}

// Remember the last name
_lastCopyMapName = absolutePath;

// Return the result of the actual save method
saveDirect(absolutePath, mapFormat);
}

void Map::loadPrefabAt(const cmd::ArgumentList& args)
Expand Down Expand Up @@ -640,7 +652,16 @@ void Map::loadPrefabAt(const cmd::ArgumentList& args)

void Map::saveMapCopyAs(const cmd::ArgumentList& args)
{
GlobalMap().saveCopyAs();
if (args.size() == 0 || args[0].getString().empty())
{
// Use the overload without arguments, it will ask for a file name
GlobalMap().saveCopyAs();
}
else
{
// Pass the first argument we got
GlobalMap().saveCopyAs(args[0].getString());
}
}

void Map::registerCommands()
Expand All @@ -653,7 +674,7 @@ void Map::registerCommands()
GlobalCommandSystem().addCommand("SaveSelectedAsPrefab", Map::saveSelectedAsPrefab);
GlobalCommandSystem().addCommand("SaveMap", Map::saveMap);
GlobalCommandSystem().addCommand("SaveMapAs", Map::saveMapAs);
GlobalCommandSystem().addCommand("SaveMapCopyAs", Map::saveMapCopyAs);
GlobalCommandSystem().addCommand("SaveMapCopyAs", Map::saveMapCopyAs, { cmd::ARGTYPE_STRING | cmd::ARGTYPE_OPTIONAL });
GlobalCommandSystem().addCommand("ExportMap", Map::exportMap);
GlobalCommandSystem().addCommand("SaveSelected", Map::exportSelection);
GlobalCommandSystem().addCommand("ReloadSkins", map::algorithm::reloadSkins);
Expand Down
9 changes: 8 additions & 1 deletion radiantcore/map/Map.h
Expand Up @@ -84,7 +84,7 @@ class Map :

/** greebo: Returns true if the map has not been named yet.
*/
bool isUnnamed() const;
bool isUnnamed() const override;

/** greebo: Updates the name of the map (and triggers an update
* of the mainframe window title)
Expand Down Expand Up @@ -125,6 +125,13 @@ class Map :
*/
void saveCopyAs();

/**
* Saves a copy of the current map to the given path, using the
* given format (which may be an empty reference, in which case the map format
* will be guessed from the filename).
*/
void saveCopyAs(const std::string& absolutePath, const MapFormatPtr& mapFormat = MapFormatPtr());

/** greebo: Saves the current selection to the target <filename>.
*/
void saveSelected(const std::string& filename, const MapFormatPtr& mapFormat = MapFormatPtr());
Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -205,6 +205,7 @@
<ClCompile Include="..\..\radiant\eventmanager\Toggle.cpp" />
<ClCompile Include="..\..\radiant\eventmanager\WidgetToggle.cpp" />
<ClCompile Include="..\..\radiant\main.cpp" />
<ClCompile Include="..\..\radiant\map\AutoSaver.cpp" />
<ClCompile Include="..\..\radiant\map\StartupMapLoader.cpp" />
<ClCompile Include="..\..\radiant\precompiled.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand Down Expand Up @@ -392,6 +393,7 @@
<ClInclude Include="..\..\radiant\eventmanager\Statement.h" />
<ClInclude Include="..\..\radiant\eventmanager\Toggle.h" />
<ClInclude Include="..\..\radiant\eventmanager\WidgetToggle.h" />
<ClInclude Include="..\..\radiant\map\AutoSaver.h" />
<ClInclude Include="..\..\radiant\map\StartupMapLoader.h" />
<ClInclude Include="..\..\radiant\precompiled.h" />
<ClInclude Include="..\..\radiant\RadiantApp.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -670,6 +670,9 @@
<ClCompile Include="..\..\radiant\ui\EntityClassColourManager.cpp">
<Filter>src\ui</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\map\AutoSaver.cpp">
<Filter>src\map</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\camera\CameraSettings.h">
Expand Down Expand Up @@ -1290,6 +1293,9 @@
<ClInclude Include="..\..\radiant\ui\common\SoundShaderDefinitionView.h">
<Filter>src\ui\common</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\map\AutoSaver.h">
<Filter>src\map</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down
3 changes: 0 additions & 3 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -101,7 +101,6 @@
<ClCompile Include="..\..\radiantcore\map\algorithm\MapImporter.cpp" />
<ClCompile Include="..\..\radiantcore\map\algorithm\Models.cpp" />
<ClCompile Include="..\..\radiantcore\map\algorithm\Skins.cpp" />
<ClCompile Include="..\..\radiantcore\map\AutoSaver.cpp" />
<ClCompile Include="..\..\radiantcore\map\CounterManager.cpp" />
<ClCompile Include="..\..\radiantcore\map\EditingStopwatch.cpp" />
<ClCompile Include="..\..\radiantcore\map\EditingStopwatchInfoFileModule.cpp" />
Expand Down Expand Up @@ -802,11 +801,9 @@
<ClInclude Include="..\..\radiantcore\map\algorithm\MapImporter.h" />
<ClInclude Include="..\..\radiantcore\map\algorithm\Models.h" />
<ClInclude Include="..\..\radiantcore\map\algorithm\Skins.h" />
<ClInclude Include="..\..\radiantcore\map\AutoSaver.h" />
<ClInclude Include="..\..\radiantcore\map\CounterManager.h" />
<ClInclude Include="..\..\radiantcore\map\EditingStopwatch.h" />
<ClInclude Include="..\..\radiantcore\map\EditingStopwatchInfoFileModule.h" />
<ClInclude Include="..\..\radiantcore\map\EntityBreakdown.h" />
<ClInclude Include="..\..\radiantcore\map\format\Doom3MapFormat.h" />
<ClInclude Include="..\..\radiantcore\map\format\Doom3MapReader.h" />
<ClInclude Include="..\..\radiantcore\map\format\Doom3MapWriter.h" />
Expand Down
9 changes: 0 additions & 9 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -925,9 +925,6 @@
<ClCompile Include="..\..\radiantcore\map\infofile\InfoFileManager.cpp">
<Filter>src\map\infofile</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\map\AutoSaver.cpp">
<Filter>src\map</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\map\EditingStopwatch.cpp">
<Filter>src\map</Filter>
</ClCompile>
Expand Down Expand Up @@ -1953,18 +1950,12 @@
<ClInclude Include="..\..\radiantcore\map\infofile\InfoFileManager.h">
<Filter>src\map\infofile</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\map\AutoSaver.h">
<Filter>src\map</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\map\EditingStopwatch.h">
<Filter>src\map</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\map\EditingStopwatchInfoFileModule.h">
<Filter>src\map</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\map\EntityBreakdown.h">
<Filter>src\map</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\map\Map.h">
<Filter>src\map</Filter>
</ClInclude>
Expand Down

0 comments on commit 89eadaa

Please sign in to comment.