From 70af0f0073bdd91c0c2b162a69d58c769c1aa0a3 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 7 Nov 2016 13:38:17 +0100 Subject: [PATCH] Add an option to the configuration manager to append the scene name to the cache directory (closing #159) --- .../openspace/engine/configurationmanager.h | 2 ++ openspace.cfg | 1 + src/engine/configurationmanager.cpp | 1 + src/engine/configurationmanager_doc.inl | 17 +++++++++--- src/engine/openspaceengine.cpp | 26 +++++++++++++++++-- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index 3f57aa59d9..f63649a8b6 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -109,6 +109,8 @@ public: /// The key that stores the switch for enabling/disabling the rendering on a master /// computer static const std::string KeyRenderingMethod; + /// The key that determines whether a new cache folder is used for each scene file + static const std::string KeyPerSceneCache; /// The key that stores the http proxy settings for the downloadmanager static const std::string KeyHttpProxy; /// The key that stores the address of the http proxy diff --git a/openspace.cfg b/openspace.cfg index 26fb6f447d..995794fb20 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -66,6 +66,7 @@ return { File = "${DOCUMENTATION}/FactoryDocumentation.html" }, ShutdownCountdown = 3, + -- PerSceneCache = true, DownloadRequestURL = "http://data.openspaceproject.com/request.cgi", RenderingMethod = "Framebuffer" --RenderingMethod = "ABuffer" -- alternative: "Framebuffer" diff --git a/src/engine/configurationmanager.cpp b/src/engine/configurationmanager.cpp index 2e326d520c..6cdfc6d496 100644 --- a/src/engine/configurationmanager.cpp +++ b/src/engine/configurationmanager.cpp @@ -70,6 +70,7 @@ const string ConfigurationManager::KeyCapabilitiesVerbosity = const string ConfigurationManager::KeyShutdownCountdown = "ShutdownCountdown"; const string ConfigurationManager::KeyDisableMasterRendering = "DisableRenderingOnMaster"; const string ConfigurationManager::KeyDownloadRequestURL = "DownloadRequestURL"; +const string ConfigurationManager::KeyPerSceneCache = "PerSceneCache"; const string ConfigurationManager::KeyRenderingMethod = "RenderingMethod"; const string ConfigurationManager::KeyOnScreenTextScaling = "OnScreenTextScaling"; diff --git a/src/engine/configurationmanager_doc.inl b/src/engine/configurationmanager_doc.inl index 4e06d9dcef..e53fb1b464 100644 --- a/src/engine/configurationmanager_doc.inl +++ b/src/engine/configurationmanager_doc.inl @@ -199,8 +199,8 @@ Documentation ConfigurationManager::Documentation() { new StringInListVerifier( // List taken from ScriptEngine::writeLog { "text" } - ), - "The type of logfile that will be created." + ), + "The type of logfile that will be created." }, { ConfigurationManager::PartFile, @@ -211,8 +211,8 @@ Documentation ConfigurationManager::Documentation() { } }), "Contains a log of all Lua scripts that were executed in the last " - "session.", - Optional::Yes + "session.", + Optional::Yes }, { ConfigurationManager::KeyKeyboardShortcuts, @@ -292,6 +292,15 @@ Documentation ConfigurationManager::Documentation() { "shutdown is aborted.", Optional::Yes }, + { + ConfigurationManager::KeyPerSceneCache, + new BoolVerifier, + "If this is set to 'true', the name of the scene will be appended to the " + "cache directory, thus not reusing the same directory. This is useful in " + "cases where the same instance of OpenSpace is run with multiple scenes, but " + "the caches should be retained. This value defaults to 'false'.", + Optional::Yes + }, { ConfigurationManager::KeyOnScreenTextScaling, new StringInListVerifier({ diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 03f5521b02..b8a364cb65 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -289,10 +289,32 @@ bool OpenSpaceEngine::create(int argc, char** argv, return false; } - if (!commandlineArgumentPlaceholders.cacheFolder.empty()) { + bool hasCacheCommandline = !commandlineArgumentPlaceholders.cacheFolder.empty(); + bool hasCacheConfiguration = _engine->configurationManager().hasKeyAndValue( + ConfigurationManager::KeyPerSceneCache + ); + std::string cacheFolder = absPath("${CACHE}"); + if (hasCacheCommandline) { + cacheFolder = commandlineArgumentPlaceholders.cacheFolder; + //FileSys.registerPathToken( + // "${CACHE}", + // commandlineArgumentPlaceholders.cacheFolder, + // ghoul::filesystem::FileSystem::Override::Yes + //); + } + if (hasCacheConfiguration) { + std::string scene = _engine->configurationManager().value( + ConfigurationManager::KeyConfigScene + ); + cacheFolder += "-" + ghoul::filesystem::File(scene).baseName(); + } + + if (hasCacheCommandline || hasCacheConfiguration) { + LINFO("Old cache: " << absPath("${CACHE}")); + LINFO("New cache: " << cacheFolder); FileSys.registerPathToken( "${CACHE}", - commandlineArgumentPlaceholders.cacheFolder, + cacheFolder, ghoul::filesystem::FileSystem::Override::Yes ); }