From f3d0f8fd0e8f19d7aabf4e53817e432565f0ecfc Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 18 May 2020 20:19:17 +0200 Subject: [PATCH] #5231: Move ModelCache to core binary. Move some shared algorithm to scenelib, at least for the moment being. --- include/imodelcache.h | 6 ++ .../map/algorithm => libs/scene}/Traverse.cpp | 4 +- .../map/algorithm => libs/scene}/Traverse.h | 5 +- radiant/Makefile.am | 2 - radiant/map/Map.cpp | 16 ++--- radiant/map/Map.h | 4 -- radiant/map/MapResource.cpp | 4 +- radiant/map/algorithm/Export.cpp | 6 +- radiant/ui/modelselector/ModelSelector.cpp | 5 +- radiantcore/Makefile.am | 2 + .../map/algorithm/Models.cpp | 10 +-- .../map/algorithm/Models.h | 0 {radiant => radiantcore}/model/ModelCache.cpp | 21 ++++-- {radiant => radiantcore}/model/ModelCache.h | 7 +- tools/msvc/DarkRadiant.vcxproj | 6 -- tools/msvc/DarkRadiant.vcxproj.filters | 72 +++++++------------ tools/msvc/DarkRadiantCore.vcxproj | 4 ++ tools/msvc/DarkRadiantCore.vcxproj.filters | 15 ++++ tools/msvc/scenelib.vcxproj | 2 + tools/msvc/scenelib.vcxproj.filters | 6 ++ 20 files changed, 105 insertions(+), 92 deletions(-) rename {radiant/map/algorithm => libs/scene}/Traverse.cpp (97%) rename {radiant/map/algorithm => libs/scene}/Traverse.h (90%) rename {radiant => radiantcore}/map/algorithm/Models.cpp (88%) rename {radiant => radiantcore}/map/algorithm/Models.h (100%) rename {radiant => radiantcore}/model/ModelCache.cpp (88%) rename {radiant => radiantcore}/model/ModelCache.h (82%) diff --git a/include/imodelcache.h b/include/imodelcache.h index 63b9cb8e78..ff75f0ce86 100644 --- a/include/imodelcache.h +++ b/include/imodelcache.h @@ -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; diff --git a/radiant/map/algorithm/Traverse.cpp b/libs/scene/Traverse.cpp similarity index 97% rename from radiant/map/algorithm/Traverse.cpp rename to libs/scene/Traverse.cpp index 057981993f..ae6ab0b8a1 100644 --- a/radiant/map/algorithm/Traverse.cpp +++ b/libs/scene/Traverse.cpp @@ -2,7 +2,7 @@ #include "scenelib.h" -namespace map { +namespace scene { class IncludeSelectedWalker : public scene::NodeVisitor @@ -65,4 +65,4 @@ void traverse(const scene::INodePtr& root, scene::NodeVisitor& nodeExporter) root->traverseChildren(nodeExporter); } -} // namespace map +} // namespace diff --git a/radiant/map/algorithm/Traverse.h b/libs/scene/Traverse.h similarity index 90% rename from radiant/map/algorithm/Traverse.h rename to libs/scene/Traverse.h index 9f284ebd91..70cd56eb36 100644 --- a/radiant/map/algorithm/Traverse.h +++ b/libs/scene/Traverse.h @@ -2,7 +2,8 @@ #include "inode.h" -namespace map { +namespace scene +{ /** greebo: Traverses the entire scenegraph (used as entry point/TraverseFunc for map saving) */ @@ -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 diff --git a/radiant/Makefile.am b/radiant/Makefile.am index 4cae125422..1b8f54aee9 100644 --- a/radiant/Makefile.am +++ b/radiant/Makefile.am @@ -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 \ @@ -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 diff --git a/radiant/map/Map.cpp b/radiant/map/Map.cpp index 1186f9fd20..8a6f391ee5 100644 --- a/radiant/map/Map.cpp +++ b/radiant/map/Map.cpp @@ -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" @@ -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 ); @@ -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 ); @@ -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); @@ -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) @@ -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 @@ -819,11 +816,8 @@ void Map::initialiseModule(const ApplicationContext& ctx) void Map::shutdownModule() { - _scaledModelExporter.shutdown(); - GlobalSceneGraph().removeSceneObserver(this); - _modelScalePreserver.reset(); _startupMapLoader.reset(); _mapPositionManager.reset(); } diff --git a/radiant/map/Map.h b/radiant/map/Map.h index 2a406760dd..b95791fe8d 100644 --- a/radiant/map/Map.h +++ b/radiant/map/Map.h @@ -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" @@ -47,9 +45,7 @@ class Map : // A local helper object, observing the radiant module std::unique_ptr _startupMapLoader; - ScaledModelExporter _scaledModelExporter; std::unique_ptr _mapPositionManager; - std::unique_ptr _modelScalePreserver; // Map save timer, for displaying "changes from last n minutes will be lost" // messages diff --git a/radiant/map/MapResource.cpp b/radiant/map/MapResource.cpp index f15a99f71a..a020f50d49 100644 --- a/radiant/map/MapResource.cpp +++ b/radiant/map/MapResource.cpp @@ -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" @@ -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 { diff --git a/radiant/map/algorithm/Export.cpp b/radiant/map/algorithm/Export.cpp index d8805945bf..d3dddb2bb9 100644 --- a/radiant/map/algorithm/Export.cpp +++ b/radiant/map/algorithm/Export.cpp @@ -3,6 +3,7 @@ #include #include "i18n.h" #include "ifilesystem.h" +#include "imodelcache.h" #include "iundo.h" #include "itextstream.h" @@ -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 { @@ -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&) { diff --git a/radiant/ui/modelselector/ModelSelector.cpp b/radiant/ui/modelselector/ModelSelector.cpp index c65c166079..de929d32cd 100644 --- a/radiant/ui/modelselector/ModelSelector.cpp +++ b/radiant/ui/modelselector/ModelSelector.cpp @@ -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" @@ -27,8 +28,6 @@ #include -#include "map/algorithm/Models.h" - namespace ui { @@ -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) diff --git a/radiantcore/Makefile.am b/radiantcore/Makefile.am index 243a7df00f..31369ad69e 100644 --- a/radiantcore/Makefile.am +++ b/radiantcore/Makefile.am @@ -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 \ diff --git a/radiant/map/algorithm/Models.cpp b/radiantcore/map/algorithm/Models.cpp similarity index 88% rename from radiant/map/algorithm/Models.cpp rename to radiantcore/map/algorithm/Models.cpp index db3e73cf9e..d00ad042da 100644 --- a/radiant/map/algorithm/Models.cpp +++ b/radiantcore/map/algorithm/Models.cpp @@ -10,7 +10,7 @@ #include "imodelcache.h" #include "iscenegraph.h" -#include "ui/mainframe/ScreenUpdateBlocker.h" +#include "messages/ScopedLongRunningOperation.h" namespace map { @@ -90,12 +90,12 @@ class ModelRefreshWalker : void refreshModels(bool blockScreenUpdates) { - std::unique_ptr blocker; + std::unique_ptr 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 @@ -111,12 +111,12 @@ void refreshModels(bool blockScreenUpdates) void refreshSelectedModels(bool blockScreenUpdates) { - std::unique_ptr blocker; + std::unique_ptr 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 diff --git a/radiant/map/algorithm/Models.h b/radiantcore/map/algorithm/Models.h similarity index 100% rename from radiant/map/algorithm/Models.h rename to radiantcore/map/algorithm/Models.h diff --git a/radiant/model/ModelCache.cpp b/radiantcore/model/ModelCache.cpp similarity index 88% rename from radiant/model/ModelCache.cpp rename to radiantcore/model/ModelCache.cpp index c11dfbcb2b..3bbddfaa48 100644 --- a/radiant/model/ModelCache.cpp +++ b/radiantcore/model/ModelCache.cpp @@ -16,6 +16,7 @@ #include #include "map/algorithm/Models.h" +#include "map/algorithm/Export.h" namespace model { @@ -167,7 +168,7 @@ sigc::signal ModelCache::signal_modelsReloaded() // RegisterableModule implementation const std::string& ModelCache::getName() const { - static std::string _name("ModelCache"); + static std::string _name(MODULE_MODELCACHE); return _name; } @@ -189,9 +190,9 @@ 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() @@ -199,12 +200,22 @@ 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); } diff --git a/radiant/model/ModelCache.h b/radiantcore/model/ModelCache.h similarity index 82% rename from radiant/model/ModelCache.h rename to radiantcore/model/ModelCache.h index 0bc1f5fb26..788dae3b06 100644 --- a/radiant/model/ModelCache.h +++ b/radiantcore/model/ModelCache.h @@ -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 signal_modelsReloaded() override; @@ -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 diff --git a/tools/msvc/DarkRadiant.vcxproj b/tools/msvc/DarkRadiant.vcxproj index 4a9500d0d1..4c4a1b9f20 100644 --- a/tools/msvc/DarkRadiant.vcxproj +++ b/tools/msvc/DarkRadiant.vcxproj @@ -222,7 +222,6 @@ - @@ -679,7 +678,6 @@ - @@ -801,7 +799,6 @@ - @@ -959,7 +956,6 @@ - @@ -1013,7 +1009,6 @@ - @@ -1158,7 +1153,6 @@ - diff --git a/tools/msvc/DarkRadiant.vcxproj.filters b/tools/msvc/DarkRadiant.vcxproj.filters index 69cb6d9060..b664ef208a 100644 --- a/tools/msvc/DarkRadiant.vcxproj.filters +++ b/tools/msvc/DarkRadiant.vcxproj.filters @@ -170,9 +170,6 @@ {d29d1907-07b9-4549-a336-642933e4602b} - - {d4ec4e26-57e8-4f14-b256-14521d12ef43} - {26ca745d-bd90-4d70-beb3-89010a45515f} @@ -251,6 +248,9 @@ {9cc90f16-363b-40e1-84ae-be23c59e06c0} + + {6c3e2342-691d-460b-afdc-9ef38e58eaea} + @@ -358,9 +358,6 @@ src\map - - src\map\algorithm - src\modulesystem @@ -820,24 +817,9 @@ src\selection\manipulators - - src\model - - - src\model - - - src\model - src\ui\modelexport - - src\map\algorithm - - - src\map\algorithm - src @@ -1207,9 +1189,6 @@ src\ui\filters - - src\model - src\settings @@ -1234,6 +1213,18 @@ src\render + + src\model + + + src\model + + + src\model + + + src\map\algorithm + @@ -1389,9 +1380,6 @@ src\map\algorithm - - src\map\algorithm - src\map\algorithm @@ -1992,24 +1980,9 @@ src\selection\manipulators - - src\model - - - src\model - - - src\model - src\ui\modelexport - - src\map\algorithm - - - src\map\algorithm - src @@ -2367,9 +2340,6 @@ src\ui\filters - - src\model - src\settings @@ -2418,6 +2388,18 @@ src\render + + src\model + + + src\model + + + src\model + + + src\map\algorithm + diff --git a/tools/msvc/DarkRadiantCore.vcxproj b/tools/msvc/DarkRadiantCore.vcxproj index 6231be0e8a..51414dc8f4 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj +++ b/tools/msvc/DarkRadiantCore.vcxproj @@ -64,10 +64,12 @@ + + @@ -192,11 +194,13 @@ + + diff --git a/tools/msvc/DarkRadiantCore.vcxproj.filters b/tools/msvc/DarkRadiantCore.vcxproj.filters index a373429a3f..ba243d87e3 100644 --- a/tools/msvc/DarkRadiantCore.vcxproj.filters +++ b/tools/msvc/DarkRadiantCore.vcxproj.filters @@ -101,6 +101,9 @@ {9e9f3eed-43d3-462c-8219-68860002cc87} + + {50635729-2a97-494c-bfa5-8ff464096809} + @@ -409,6 +412,12 @@ src\model + + src\model + + + src\map\algorithm + @@ -876,5 +885,11 @@ src\model + + src\model + + + src\map\algorithm + \ No newline at end of file diff --git a/tools/msvc/scenelib.vcxproj b/tools/msvc/scenelib.vcxproj index fb68de56ea..6cecd9a039 100644 --- a/tools/msvc/scenelib.vcxproj +++ b/tools/msvc/scenelib.vcxproj @@ -118,6 +118,7 @@ + @@ -127,6 +128,7 @@ + diff --git a/tools/msvc/scenelib.vcxproj.filters b/tools/msvc/scenelib.vcxproj.filters index 74bfe91d3e..3b69ad81fa 100644 --- a/tools/msvc/scenelib.vcxproj.filters +++ b/tools/msvc/scenelib.vcxproj.filters @@ -18,6 +18,9 @@ scene + + scene + @@ -40,5 +43,8 @@ scene + + scene + \ No newline at end of file