Skip to content

Commit

Permalink
#5231: Move ModelCache to core binary. Move some shared algorithm to …
Browse files Browse the repository at this point in the history
…scenelib, at least for the moment being.
  • Loading branch information
codereader committed May 18, 2020
1 parent f5697d3 commit f3d0f8f
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 92 deletions.
6 changes: 6 additions & 0 deletions include/imodelcache.h
Expand Up @@ -33,6 +33,12 @@ class IModelCache :
*/
virtual IModelPtr getModel(const std::string& modelPath) = 0;

// This reloads all models in the map
virtual void refreshModels(bool blockScreenUpdates = true) = 0;

// This reloads all selected models in the map
virtual void refreshSelectedModels(bool blockScreenUpdates = true) = 0;

// Clears a specific model from the cache
virtual void removeModel(const std::string& modelPath) = 0;

Expand Down
Expand Up @@ -2,7 +2,7 @@

#include "scenelib.h"

namespace map {
namespace scene {

class IncludeSelectedWalker :
public scene::NodeVisitor
Expand Down Expand Up @@ -65,4 +65,4 @@ void traverse(const scene::INodePtr& root, scene::NodeVisitor& nodeExporter)
root->traverseChildren(nodeExporter);
}

} // namespace map
} // namespace
5 changes: 3 additions & 2 deletions radiant/map/algorithm/Traverse.h → libs/scene/Traverse.h
Expand Up @@ -2,7 +2,8 @@

#include "inode.h"

namespace map {
namespace scene
{

/** greebo: Traverses the entire scenegraph (used as entry point/TraverseFunc for map saving)
*/
Expand All @@ -12,4 +13,4 @@ void traverse(const scene::INodePtr& root, scene::NodeVisitor& nodeExporter);
*/
void traverseSelected(const scene::INodePtr& root, scene::NodeVisitor& nodeExporter);

} // namespace map
} // namespace
2 changes: 0 additions & 2 deletions radiant/Makefile.am
Expand Up @@ -345,7 +345,6 @@ darkradiant_SOURCES = main.cpp \
map/algorithm/MapImporter.cpp \
map/algorithm/Import.cpp \
map/algorithm/Export.cpp \
map/algorithm/Models.cpp \
map/CounterManager.cpp \
map/RegionManager.cpp \
map/PointFile.cpp \
Expand All @@ -361,7 +360,6 @@ darkradiant_SOURCES = main.cpp \
clipper/Clipper.cpp \
log/Console.cpp \
undo/UndoSystem.cpp \
model/ModelCache.cpp \
model/ModelScalePreserver.cpp \
model/ModelExporter.cpp \
model/ScaledModelExporter.cpp
Expand Down
16 changes: 5 additions & 11 deletions radiant/map/Map.cpp
Expand Up @@ -41,7 +41,7 @@
#include "map/MapResource.h"
#include "map/algorithm/Import.h"
#include "map/algorithm/Export.h"
#include "map/algorithm/Traverse.h"
#include "scene/Traverse.h"
#include "map/algorithm/MapExporter.h"
#include "model/ModelExporter.h"
#include "model/ModelScalePreserver.h"
Expand Down Expand Up @@ -397,7 +397,7 @@ bool Map::saveDirect(const std::string& filename, const MapFormatPtr& mapFormat)
bool result = MapResource::saveFile(
*format,
GlobalSceneGraph().root(),
map::traverse, // TraversalFunc
scene::traverse, // TraversalFunc
filename
);

Expand Down Expand Up @@ -425,7 +425,7 @@ bool Map::saveSelected(const std::string& filename, const MapFormatPtr& mapForma
bool success = MapResource::saveFile(
*format,
GlobalSceneGraph().root(),
map::traverseSelected, // TraversalFunc
scene::traverseSelected, // TraversalFunc
filename
);

Expand Down Expand Up @@ -695,7 +695,7 @@ void Map::exportMap(const cmd::ArgumentList& args)

MapResource::saveFile(*fileInfo.mapFormat,
GlobalSceneGraph().root(),
traverse,
scene::traverse,
fileInfo.fullPath);

GlobalMap().emitMapEvent(MapSaved);
Expand Down Expand Up @@ -754,7 +754,7 @@ void Map::exportSelected(std::ostream& out, const MapFormatPtr& format)
MapExporter exporter(*writer, GlobalSceneGraph().root(), out);

// Pass the traverseSelected function and start writing selected nodes
exporter.exportMap(GlobalSceneGraph().root(), traverseSelected);
exporter.exportMap(GlobalSceneGraph().root(), scene::traverseSelected);
}

void Map::emitMapEvent(MapEvent ev)
Expand Down Expand Up @@ -806,9 +806,6 @@ void Map::initialiseModule(const ApplicationContext& ctx)
// Add the Map-related commands to the EventManager
registerCommands();

_scaledModelExporter.initialise();
_modelScalePreserver.reset(new ModelScalePreserver);

MapFileManager::registerFileTypes();

// Register an info file module to save the map property bag
Expand All @@ -819,11 +816,8 @@ void Map::initialiseModule(const ApplicationContext& ctx)

void Map::shutdownModule()
{
_scaledModelExporter.shutdown();

GlobalSceneGraph().removeSceneObserver(this);

_modelScalePreserver.reset();
_startupMapLoader.reset();
_mapPositionManager.reset();
}
Expand Down
4 changes: 0 additions & 4 deletions radiant/map/Map.h
Expand Up @@ -10,8 +10,6 @@
#include "imodule.h"
#include "math/Vector3.h"

#include "model/ScaledModelExporter.h"
#include "model/ModelScalePreserver.h"
#include "StartupMapLoader.h"
#include "MapPositionManager.h"

Expand Down Expand Up @@ -47,9 +45,7 @@ class Map :

// A local helper object, observing the radiant module
std::unique_ptr<StartupMapLoader> _startupMapLoader;
ScaledModelExporter _scaledModelExporter;
std::unique_ptr<MapPositionManager> _mapPositionManager;
std::unique_ptr<ModelScalePreserver> _modelScalePreserver;

// Map save timer, for displaying "changes from last n minutes will be lost"
// messages
Expand Down
4 changes: 2 additions & 2 deletions radiant/map/MapResource.cpp
Expand Up @@ -22,7 +22,7 @@
#include "os/path.h"
#include "os/file.h"
#include "os/fs.h"
#include "map/algorithm/Traverse.h"
#include "scene/Traverse.h"
#include "stream/TextFileInputStream.h"
#include "scenelib.h"

Expand Down Expand Up @@ -161,7 +161,7 @@ bool MapResource::save(const MapFormatPtr& mapFormat)
if (path_is_absolute(fullpath.c_str()))
{
// Save the actual file
success = saveFile(*format, _mapRoot, map::traverse, fullpath);
success = saveFile(*format, _mapRoot, scene::traverse, fullpath);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions radiant/map/algorithm/Export.cpp
Expand Up @@ -3,6 +3,7 @@
#include <stdexcept>
#include "i18n.h"
#include "ifilesystem.h"
#include "imodelcache.h"
#include "iundo.h"
#include "itextstream.h"

Expand All @@ -15,8 +16,7 @@
#include "string/case_conv.h"
#include "model/ModelExporter.h"
#include "registry/registry.h"
#include "Traverse.h"
#include "Models.h"
#include "scene/Traverse.h"

namespace map
{
Expand Down Expand Up @@ -127,7 +127,7 @@ void exportSelectedAsModel(const ModelExportOptions& options)
Node_getEntity(modelNode)->setKeyValue("model", relativeModelPath);

// It's possible that the export overwrote a model we're already using in this map, refresh it
refreshSelectedModels(false);
GlobalModelCache().refreshSelectedModels(false);
}
catch (selection::algorithm::EntityCreationException&)
{
Expand Down
5 changes: 2 additions & 3 deletions radiant/ui/modelselector/ModelSelector.cpp
Expand Up @@ -7,6 +7,7 @@
#include "itextstream.h"
#include "iregistry.h"
#include "imainframe.h"
#include "imodelcache.h"
#include "imodel.h"
#include "modelskin.h"
#include "imodelcache.h"
Expand All @@ -27,8 +28,6 @@

#include <functional>

#include "map/algorithm/Models.h"

namespace ui
{

Expand Down Expand Up @@ -484,7 +483,7 @@ void ModelSelector::onReloadModels(wxCommandEvent& ev)
_preselectedModel = getSelectedValue(_columns.vfspath);

// This will fire the models reloaded signal after some time
map::algorithm::refreshModels(false);
GlobalModelCache().refreshModels(false);
}

void ModelSelector::onReloadSkins(wxCommandEvent& ev)
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/Makefile.am
Expand Up @@ -84,10 +84,12 @@ libradiantcore_la_SOURCES = Radiant.cpp \
log/LogStreamBuf.cpp \
log/LogWriter.cpp \
log/StringLogDevice.cpp \
map/algorithm/Models.cpp \
map/format/MapFormatManager.cpp \
map/namespace/ComplexName.cpp \
map/namespace/Namespace.cpp \
map/namespace/NamespaceFactory.cpp \
model/ModelCache.cpp \
model/ModelFormatManager.cpp \
model/NullModel.cpp \
model/NullModelNode.cpp \
Expand Down
Expand Up @@ -10,7 +10,7 @@
#include "imodelcache.h"
#include "iscenegraph.h"

#include "ui/mainframe/ScreenUpdateBlocker.h"
#include "messages/ScopedLongRunningOperation.h"

namespace map
{
Expand Down Expand Up @@ -90,12 +90,12 @@ class ModelRefreshWalker :

void refreshModels(bool blockScreenUpdates)
{
std::unique_ptr<ui::ScreenUpdateBlocker> blocker;
std::unique_ptr<radiant::ScopedLongRunningOperation> blocker;

if (blockScreenUpdates)
{
// Disable screen updates for the scope of this function
blocker.reset(new ui::ScreenUpdateBlocker(_("Processing..."), _("Reloading Models")));
blocker.reset(new radiant::ScopedLongRunningOperation(_("Reloading Models")));
}

// Clear the model cache
Expand All @@ -111,12 +111,12 @@ void refreshModels(bool blockScreenUpdates)

void refreshSelectedModels(bool blockScreenUpdates)
{
std::unique_ptr<ui::ScreenUpdateBlocker> blocker;
std::unique_ptr<radiant::ScopedLongRunningOperation> blocker;

if (blockScreenUpdates)
{
// Disable screen updates for the scope of this function
blocker.reset(new ui::ScreenUpdateBlocker(_("Processing..."), _("Reloading Models")));
blocker.reset(new radiant::ScopedLongRunningOperation(_("Reloading Models")));
}

// Find all models in the current selection
Expand Down
File renamed without changes.
21 changes: 16 additions & 5 deletions radiant/model/ModelCache.cpp → radiantcore/model/ModelCache.cpp
Expand Up @@ -16,6 +16,7 @@
#include <functional>

#include "map/algorithm/Models.h"
#include "map/algorithm/Export.h"

namespace model
{
Expand Down Expand Up @@ -167,7 +168,7 @@ sigc::signal<void> ModelCache::signal_modelsReloaded()
// RegisterableModule implementation
const std::string& ModelCache::getName() const
{
static std::string _name("ModelCache");
static std::string _name(MODULE_MODELCACHE);
return _name;
}

Expand All @@ -189,22 +190,32 @@ void ModelCache::initialiseModule(const ApplicationContext& ctx)
rMessage() << getName() << "::initialiseModule called." << std::endl;

GlobalCommandSystem().addCommand("RefreshModels",
std::bind(&ModelCache::refreshModels, this, std::placeholders::_1));
std::bind(&ModelCache::refreshModelsCmd, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("RefreshSelectedModels",
std::bind(&ModelCache::refreshSelectedModels, this, std::placeholders::_1));
std::bind(&ModelCache::refreshSelectedModelsCmd, this, std::placeholders::_1));
}

void ModelCache::shutdownModule()
{
clear();
}

void ModelCache::refreshModels(const cmd::ArgumentList& args)
void ModelCache::refreshModels(bool blockScreenUpdates)
{
map::algorithm::refreshModels(blockScreenUpdates);
}

void ModelCache::refreshSelectedModels(bool blockScreenUpdates)
{
map::algorithm::refreshSelectedModels(blockScreenUpdates);
}

void ModelCache::refreshModelsCmd(const cmd::ArgumentList& args)
{
map::algorithm::refreshModels(true);
}

void ModelCache::refreshSelectedModels(const cmd::ArgumentList& args)
void ModelCache::refreshSelectedModelsCmd(const cmd::ArgumentList& args)
{
map::algorithm::refreshSelectedModels(true);
}
Expand Down
7 changes: 5 additions & 2 deletions radiant/model/ModelCache.h → radiantcore/model/ModelCache.h
Expand Up @@ -34,6 +34,9 @@ class ModelCache :
void removeModel(const std::string& modelPath) override;
void clear() override;

void refreshModels(bool blockScreenUpdates = true) override;
void refreshSelectedModels(bool blockScreenUpdates = true) override;

// Public events
sigc::signal<void> signal_modelsReloaded() override;

Expand All @@ -45,8 +48,8 @@ class ModelCache :

private:
// Command targets
void refreshModels(const cmd::ArgumentList& args);
void refreshSelectedModels(const cmd::ArgumentList& args);
void refreshModelsCmd(const cmd::ArgumentList& args);
void refreshSelectedModelsCmd(const cmd::ArgumentList& args);
};

} // namespace model
6 changes: 0 additions & 6 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -222,7 +222,6 @@
<ClCompile Include="..\..\radiant\map\algorithm\Import.cpp" />
<ClCompile Include="..\..\radiant\map\algorithm\MapExporter.cpp" />
<ClCompile Include="..\..\radiant\map\algorithm\MapImporter.cpp" />
<ClCompile Include="..\..\radiant\map\algorithm\Models.cpp" />
<ClCompile Include="..\..\radiant\map\algorithm\Skins.cpp" />
<ClCompile Include="..\..\radiant\map\EditingStopwatch.cpp" />
<ClCompile Include="..\..\radiant\map\EditingStopwatchInfoFileModule.cpp" />
Expand Down Expand Up @@ -679,7 +678,6 @@
<ClCompile Include="..\..\radiant\modelfile\RenderablePicoModel.cpp" />
<ClCompile Include="..\..\radiant\modelfile\RenderablePicoSurface.cpp" />
<ClCompile Include="..\..\radiant\modelfile\WavefrontExporter.cpp" />
<ClCompile Include="..\..\radiant\model\ModelCache.cpp" />
<ClCompile Include="..\..\radiant\model\ModelExporter.cpp" />
<ClCompile Include="..\..\radiant\model\ModelScalePreserver.cpp" />
<ClCompile Include="..\..\radiant\model\ScaledModelExporter.cpp" />
Expand Down Expand Up @@ -801,7 +799,6 @@
<ClCompile Include="..\..\radiant\map\RegionManager.cpp" />
<ClCompile Include="..\..\radiant\map\RootNode.cpp" />
<ClCompile Include="..\..\radiant\map\StartupMapLoader.cpp" />
<ClCompile Include="..\..\radiant\map\algorithm\Traverse.cpp" />
<ClCompile Include="..\..\radiant\modulesystem\ApplicationContextImpl.cpp" />
<ClCompile Include="..\..\radiant\patch\Patch.cpp" />
<ClCompile Include="..\..\radiant\patch\PatchModule.cpp" />
Expand Down Expand Up @@ -959,7 +956,6 @@
<ClInclude Include="..\..\radiant\map\algorithm\Import.h" />
<ClInclude Include="..\..\radiant\map\algorithm\MapExporter.h" />
<ClInclude Include="..\..\radiant\map\algorithm\MapImporter.h" />
<ClInclude Include="..\..\radiant\map\algorithm\Models.h" />
<ClInclude Include="..\..\radiant\map\algorithm\Skins.h" />
<ClInclude Include="..\..\radiant\map\EditingStopwatch.h" />
<ClInclude Include="..\..\radiant\map\EditingStopwatchInfoFileModule.h" />
Expand Down Expand Up @@ -1013,7 +1009,6 @@
<ClInclude Include="..\..\radiant\modelfile\RenderablePicoModel.h" />
<ClInclude Include="..\..\radiant\modelfile\RenderablePicoSurface.h" />
<ClInclude Include="..\..\radiant\modelfile\WavefrontExporter.h" />
<ClInclude Include="..\..\radiant\model\ModelCache.h" />
<ClInclude Include="..\..\radiant\model\ModelExporter.h" />
<ClInclude Include="..\..\radiant\model\ModelScalePreserver.h" />
<ClInclude Include="..\..\radiant\model\ScaledModelExporter.h" />
Expand Down Expand Up @@ -1158,7 +1153,6 @@
<ClInclude Include="..\..\radiant\map\ShaderBreakdown.h" />
<ClInclude Include="..\..\radiant\map\StartupMapLoader.h" />
<ClInclude Include="..\..\radiant\map\algorithm\Clone.h" />
<ClInclude Include="..\..\radiant\map\algorithm\Traverse.h" />
<ClInclude Include="..\..\radiant\map\algorithm\WorldspawnArgFinder.h" />
<ClInclude Include="..\..\radiant\modulesystem\ApplicationContextImpl.h" />
<ClInclude Include="..\..\radiant\patch\Patch.h" />
Expand Down

0 comments on commit f3d0f8f

Please sign in to comment.