From c3825cc81efd48f69dc18ccfc08bfb363085bea0 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 31 Aug 2017 11:37:22 -0400 Subject: [PATCH] Only display commit hash text overlay if there is information available Add version and commit information into a global property --- include/openspace/engine/openspaceengine.h | 6 +++++ src/engine/openspaceengine.cpp | 23 ++++++++++++++++++ src/rendering/renderengine.cpp | 28 +++++++++++++--------- support/cmake/openspace_header.template | 1 + 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index f5f77fcdea..ac079ad893 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_CORE___OPENSPACEENGINE___H__ #define __OPENSPACE_CORE___OPENSPACEENGINE___H__ +#include #include #include @@ -204,6 +205,11 @@ private: // Others std::unique_ptr _globalPropertyNamespace; + + struct { + properties::StringProperty versionString; + properties::StringProperty sourceControlInformation; + } _versionInformation; bool _scheduledSceneSwitch; std::string _scenePath; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 7e817d875e..4036be12df 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -112,6 +112,19 @@ namespace { std::string sceneName; std::string cacheFolder; } commandlineArgumentPlaceholders; + + + static const openspace::properties::Property::PropertyInfo VersionInfo = { + "VersionInfo", + "Version Information", + "This value contains the full string identifying this OpenSpace Version" + }; + + static const openspace::properties::Property::PropertyInfo SourceControlInfo = { + "SCMInfo", + "Source Control Management Information", + "This value contains information from the SCM, such as commit hash and branch" + }; } // namespace namespace openspace { @@ -145,6 +158,10 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, , _scriptScheduler(new scripting::ScriptScheduler) , _virtualPropertyManager(new VirtualPropertyManager) , _globalPropertyNamespace(new properties::PropertyOwner({ "" })) + , _versionInformation{ + properties::StringProperty(VersionInfo, OPENSPACE_VERSION_STRING_FULL), + properties::StringProperty(SourceControlInfo, OPENSPACE_GIT_FULL) + } , _scheduledSceneSwitch(false) , _scenePath("") , _runTime(0.0) @@ -161,6 +178,12 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, _globalPropertyNamespace->addPropertySubOwner(_parallelConnection.get()); _globalPropertyNamespace->addPropertySubOwner(_console.get()); + + _versionInformation.versionString.setReadOnly(true); + _globalPropertyNamespace->addProperty(_versionInformation.versionString); + _versionInformation.sourceControlInformation.setReadOnly(true); + _globalPropertyNamespace->addProperty(_versionInformation.sourceControlInformation); + FactoryManager::initialize(); FactoryManager::ref().addFactory( std::make_unique>(), diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index e10b9bacdf..d148c10959 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -1331,17 +1331,23 @@ void RenderEngine::renderVersionInformation() { OPENSPACE_VERSION_STRING_FULL ); - FR::defaultRenderer().render( - *_fontInfo, - glm::vec2( - fontResolution().x - commitBox.boundingBox.x - 10.f, - versionBox.boundingBox.y + 5.f - ), - glm::vec4(0.5, 0.5, 0.5, 1.f), - "%s@%s", - OPENSPACE_GIT_BRANCH, - OPENSPACE_GIT_COMMIT - ); + // If a developer hasn't placed the Git command in the path, this variable will be + // empty + if (!std::string(OPENSPACE_GIT_COMMIT).empty()) { + // We check OPENSPACE_GIT_COMMIT but puse OPENSPACE_GIT_FULL on purpose since + // OPENSPACE_GIT_FULL will never be empty (always will contain at least @, but + // checking for that is a bit brittle) + FR::defaultRenderer().render( + *_fontInfo, + glm::vec2( + fontResolution().x - commitBox.boundingBox.x - 10.f, + versionBox.boundingBox.y + 5.f + ), + glm::vec4(0.5, 0.5, 0.5, 1.f), + "%s", + OPENSPACE_GIT_FULL + ); + } } void RenderEngine::renderScreenLog() { diff --git a/support/cmake/openspace_header.template b/support/cmake/openspace_header.template index b728054104..c02e41e71b 100644 --- a/support/cmake/openspace_header.template +++ b/support/cmake/openspace_header.template @@ -41,6 +41,7 @@ constexpr const char* OPENSPACE_VERSION_STRING_FULL = "@OPENSPACE_VERSION_MAJOR@ constexpr const char* OPENSPACE_GIT_BRANCH = "@OPENSPACE_GIT_BRANCH@"; constexpr const char* OPENSPACE_GIT_COMMIT = "@OPENSPACE_GIT_COMMIT@"; +constexpr const char* OPENSPACE_GIT_FULL = "@OPENSPACE_GIT_BRANCH@@@OPENSPACE_GIT_COMMIT@"; } // namespace openspace