From 818ee225a5c5e74afe55ac3f9605c262e716bc51 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 21 Apr 2018 07:00:43 -0400 Subject: [PATCH] Define a Cache path on default Cleanup OpenSpaceEngine Cleanup RenderEngine * ScreenSpaceRenderables are now owned by RenderEngine, rather than being shared_ptr Cleanup LogFactory --- apps/OpenSpace/main.cpp | 1 - apps/TaskRunner/main.cpp | 4 +- include/openspace/engine/configuration.h | 4 +- include/openspace/engine/openspaceengine.h | 13 +- include/openspace/rendering/renderengine.h | 44 ++-- include/openspace/util/screenlog.h | 17 +- modules/base/dashboard/dashboarditemangle.cpp | 2 +- .../base/dashboard/dashboarditemdistance.cpp | 2 +- .../base/rendering/screenspacedashboard.cpp | 10 +- modules/imgui/src/guijoystickcomponent.cpp | 4 +- modules/iswa/util/iswamanager_lua.inl | 4 +- src/engine/configuration.cpp | 1 - src/engine/logfactory.cpp | 124 ++++----- src/engine/openspaceengine.cpp | 208 +++++++-------- src/interaction/navigationhandler_lua.inl | 4 +- src/rendering/renderengine.cpp | 241 ++++++++---------- src/rendering/renderengine_lua.inl | 27 +- src/rendering/screenspacerenderable.cpp | 3 +- src/util/screenlog.cpp | 6 +- 19 files changed, 325 insertions(+), 394 deletions(-) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 150b507a87..f66289d518 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -631,7 +631,6 @@ int main_main(int argc, char** argv) { std::pair glVersion = supportedOpenGLVersion(); // Create the OpenSpace engine and get arguments for the SGCT engine - // @CLEANUP: Replace the return valua with throwing an exception --abock std::vector sgctArguments; bool requestQuit = false; try { diff --git a/apps/TaskRunner/main.cpp b/apps/TaskRunner/main.cpp index 34219a479f..28f8cc8af1 100644 --- a/apps/TaskRunner/main.cpp +++ b/apps/TaskRunner/main.cpp @@ -61,12 +61,12 @@ namespace { void initTextureReaders() { #ifdef GHOUL_USE_DEVIL ghoul::io::TextureReader::ref().addReader( - std::make_shared() + std::make_unique() ); #endif // GHOUL_USE_DEVIL #ifdef GHOUL_USE_FREEIMAGE ghoul::io::TextureReader::ref().addReader( - std::make_shared() + std::make_unique() ); #endif // GHOUL_USE_FREEIMAGE } diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 1b2ef2760c..06916253fc 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -39,7 +39,9 @@ struct Configuration { std::string windowConfiguration = "${CONFIG}/single.xml"; std::string asset = "default"; std::vector globalCustomizationScripts; - std::map pathTokens; + std::map pathTokens = { + { "CACHE" , "CACHE = \"${BASE}/cache\"" } + }; std::map fonts; struct Logging { diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index efc6f9b511..e136e6c1b6 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -76,12 +76,12 @@ namespace scripting { struct ShutdownInformation { // Whether the application is currently in shutdown mode (i.e. counting down the // timer and closing it at '0' - bool inShutdown; + bool inShutdown = false; // Total amount of time the application will wait before actually shutting down - float waitTime; + float waitTime = 0.f; // Current state of the countdown; if it reaches '0', the application will // close - float timer; + float timer = 0.f; }; class OpenSpaceEngine { @@ -95,7 +95,7 @@ public: static OpenSpaceEngine& ref(); static bool isCreated(); - ~OpenSpaceEngine(); + ~OpenSpaceEngine() = default; // callbacks void initialize(); @@ -196,7 +196,6 @@ private: OpenSpaceEngine(std::string programName, std::unique_ptr windowWrapper); - std::unique_ptr createLoadingScreen(); void loadSingleAsset(const std::string& assetPath); void gatherCommandlineArguments(); void loadFonts(); @@ -241,7 +240,7 @@ private: properties::StringProperty sourceControlInformation; } _versionInformation; - bool _hasScheduledAssetLoading; + bool _hasScheduledAssetLoading = false; std::string _scheduledAssetPathToLoad; struct { @@ -269,7 +268,7 @@ private: // The first frame might take some more time in the update loop, so we need to know to // disable the synchronization; otherwise a hardware sync will kill us after 1 minute - bool _isFirstRenderingFirstFrame; + bool _isFirstRenderingFirstFrame = true; static OpenSpaceEngine* _engine; }; diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 5438b6d194..5520ca9e3e 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -36,7 +36,7 @@ namespace ghoul { class Dictionary; class SharedMemory; -} +} // ghoul namespace ghoul::fontrendering { class Font; } namespace ghoul::opengl { class ProgramObject; } @@ -77,8 +77,7 @@ public: Scene* scene(); void updateScene(); - Camera* camera() const; - Renderer* renderer() const; + const Renderer& renderer() const; RendererImplementation rendererImplementation() const; RaycasterManager& raycasterManager(); DeferredcasterManager& deferredcasterManager(); @@ -101,24 +100,19 @@ public: float globalBlackOutFactor(); void setGlobalBlackOutFactor(float factor); - void addScreenSpaceRenderable(std::shared_ptr s); - void removeScreenSpaceRenderable(std::shared_ptr s); + void addScreenSpaceRenderable(std::unique_ptr s); + void removeScreenSpaceRenderable(ScreenSpaceRenderable* s); void removeScreenSpaceRenderable(const std::string& name); - std::shared_ptr screenSpaceRenderable(const std::string& name); + ScreenSpaceRenderable* screenSpaceRenderable(const std::string& name); std::vector screenSpaceRenderables() const; std::unique_ptr buildRenderProgram( - std::string name, - std::string vsPath, - std::string fsPath, - const ghoul::Dictionary& dictionary = ghoul::Dictionary()); + const std::string& name, const std::string& vsPath, std::string fsPath, + ghoul::Dictionary dictionary = ghoul::Dictionary()); std::unique_ptr buildRenderProgram( - std::string name, - std::string vsPath, - std::string fsPath, - std::string csPath, - const ghoul::Dictionary& dictionary = ghoul::Dictionary()); + const std::string& name, const std::string& vsPath, std::string fsPath, + const std::string& csPath, ghoul::Dictionary dictionary = ghoul::Dictionary()); void removeRenderProgram(ghoul::opengl::ProgramObject* program); @@ -144,13 +138,13 @@ public: * Lets the renderer update the data to be brought into the rendererer programs * as a 'rendererData' variable in the dictionary. */ - void setRendererData(const ghoul::Dictionary& rendererData); + void setRendererData(ghoul::Dictionary rendererData); /** * Lets the renderer update the data to be brought into the post rendererer programs * as a 'resolveData' variable in the dictionary. */ - void setResolveData(const ghoul::Dictionary& resolveData); + void setResolveData(ghoul::Dictionary resolveData); /** * Returns the Lua library that contains all Lua functions available to affect the @@ -164,8 +158,6 @@ public: glm::ivec2 renderingResolution() const; glm::ivec2 fontResolution() const; - std::vector getSyncables(); - properties::PropertyOwner& screenSpaceOwner(); private: @@ -199,26 +191,26 @@ private: properties::BoolProperty _showCameraInfo; properties::TriggerProperty _takeScreenshot; - bool _shouldTakeScreenshot; + bool _shouldTakeScreenshot = false; properties::BoolProperty _applyWarping; properties::BoolProperty _showFrameNumber; properties::BoolProperty _disableMasterRendering; properties::BoolProperty _disableSceneTranslationOnMaster; - float _globalBlackOutFactor; - float _fadeDuration; - float _currentFadeTime; - int _fadeDirection; + float _globalBlackOutFactor = 1.f; + float _fadeDuration = 2.f; + float _currentFadeTime = 0.f; + int _fadeDirection = 0; properties::IntProperty _nAaSamples; properties::FloatProperty _hdrExposure; properties::FloatProperty _hdrBackground; properties::FloatProperty _gamma; - uint64_t _frameNumber; + uint64_t _frameNumber = 0; std::vector _programs; properties::PropertyOwner _screenSpaceOwner; - std::vector> _screenSpaceRenderables; + std::vector> _screenSpaceRenderables; std::shared_ptr _fontBig = nullptr; std::shared_ptr _fontInfo = nullptr; diff --git a/include/openspace/util/screenlog.h b/include/openspace/util/screenlog.h index 5296b42157..aed1c78dc8 100644 --- a/include/openspace/util/screenlog.h +++ b/include/openspace/util/screenlog.h @@ -70,10 +70,11 @@ public: * Constructor that creates a ScreenLog with the provided \p timeToLive, and the * minimum \p logLevel that is stored. Log message with a lower * ghoul::logging::LogLevel are automatically discarded. + * * \param timeToLive The time-to-live for the messages in this ScreenLog. Expired - * messages are removed whenever the #removeExpiredEntries method is called + * messages are removed whenever the #removeExpiredEntries method is called * \param logLevel The minimum ghoul::logging::LogLevel that messages must - * have in order to be stored in the ScreenLog + * have in order to be stored in the ScreenLog */ ScreenLog(std::chrono::seconds timeToLive, LogLevel logLevel = LogLevel::Info); @@ -85,6 +86,7 @@ public: /** * Overwritten ghoul::loggling::Log method that is called whenever a new log message * shall be stored. + * * \param level The ghoul::logging::LogLevel of the incoming log message * \param category The category of the log message * \param message The actual log message that was transmitted @@ -95,17 +97,19 @@ public: /** * This method removes all the stored LogEntry%s that have expired, calculated by * their timeStamp and the #_timeToLive value. + * * \post All entries retrieved by the #entries function have a timeStamp - * that is lower than the current time + #_timeToLive. The current time used is the - * time when this method was last called + * that is lower than the current time + #_timeToLive. The current time used is + * the time when this method was last called */ void removeExpiredEntries(); /** * Returns the list of all stored LogEntry%s. + * * \return The list of all stored LogEntry%s */ - std::vector entries() const; + const std::vector& entries() const; private: /// The list of all LogEntry%s stored by this ScreenLog @@ -118,7 +122,8 @@ private: /// The minimum LogLevel of messages LogLevel _logLevel; - /// A mutex to ensure thread-safety + /// A mutex to ensure thread-safety since the logging and the removal of expired + /// entires can occur on different threads mutable std::mutex _mutex; }; diff --git a/modules/base/dashboard/dashboarditemangle.cpp b/modules/base/dashboard/dashboarditemangle.cpp index 56843babde..a86684eddc 100644 --- a/modules/base/dashboard/dashboarditemangle.cpp +++ b/modules/base/dashboard/dashboarditemangle.cpp @@ -388,7 +388,7 @@ std::pair DashboardItemAngle::positionAndLabel( "focus" }; case Type::Camera: - return { OsEng.renderEngine().camera()->positionVec3(), "camera" }; + return { OsEng.renderEngine().scene()->camera()->positionVec3(), "camera" }; default: return { glm::dvec3(0.0), "Unknown" }; } diff --git a/modules/base/dashboard/dashboarditemdistance.cpp b/modules/base/dashboard/dashboarditemdistance.cpp index 30e4e8766f..00389c05df 100644 --- a/modules/base/dashboard/dashboarditemdistance.cpp +++ b/modules/base/dashboard/dashboarditemdistance.cpp @@ -406,7 +406,7 @@ std::pair DashboardItemDistance::positionAndLabel( "focus" }; case Type::Camera: - return { OsEng.renderEngine().camera()->positionVec3(), "camera" }; + return { OsEng.renderEngine().scene()->camera()->positionVec3(), "camera" }; default: return { glm::dvec3(0.0), "Unknown" }; } diff --git a/modules/base/rendering/screenspacedashboard.cpp b/modules/base/rendering/screenspacedashboard.cpp index 33730c82e2..b6a3ebf0f6 100644 --- a/modules/base/rendering/screenspacedashboard.cpp +++ b/modules/base/rendering/screenspacedashboard.cpp @@ -76,14 +76,13 @@ int addDashboardItemToScreenSpace(lua_State* L) { return 0; } - std::shared_ptr ssr = - OsEng.renderEngine().screenSpaceRenderable(name); + ScreenSpaceRenderable* ssr = OsEng.renderEngine().screenSpaceRenderable(name); if (!ssr) { return luaL_error(L, "Provided name is not a ScreenSpace item"); } - ScreenSpaceDashboard* dash = dynamic_cast(ssr.get()); + ScreenSpaceDashboard* dash = dynamic_cast(ssr); if (!dash) { return luaL_error( L, @@ -106,14 +105,13 @@ int removeDashboardItemsFromScreenSpace(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::removeDashboardItemsFromScreenSpace"); std::string name = ghoul::lua::checkStringAndPop(L); - std::shared_ptr ssr = - OsEng.renderEngine().screenSpaceRenderable(name); + ScreenSpaceRenderable* ssr = OsEng.renderEngine().screenSpaceRenderable(name); if (!ssr) { return luaL_error(L, "Provided name is not a ScreenSpace item"); } - ScreenSpaceDashboard* dash = dynamic_cast(ssr.get()); + ScreenSpaceDashboard* dash = dynamic_cast(ssr); if (!dash) { return luaL_error(L, "Provided name is a ScreenSpace item but not a dashboard"); } diff --git a/modules/imgui/src/guijoystickcomponent.cpp b/modules/imgui/src/guijoystickcomponent.cpp index 03c49fdbd6..999e3c6529 100644 --- a/modules/imgui/src/guijoystickcomponent.cpp +++ b/modules/imgui/src/guijoystickcomponent.cpp @@ -53,13 +53,13 @@ void GuiJoystickComponent::render() { const JoystickInputStates& states = OsEng.navigationHandler().inputState().joystickInputStates(); - for (int i = 0; i < states.size(); ++i) { + for (size_t i = 0; i < states.size(); ++i) { const JoystickInputState& state = states[i]; if (!state.isConnected) { continue; } - ImGui::Text("%s [%i]", state.name.c_str(), i); + ImGui::Text("%s [%i]", state.name.c_str(), static_cast(i)); ImGui::Text("%s", "Axes"); for (int j = 0; j < state.nAxes; ++j) { float f = state.axes[j]; diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl index deb34946a2..bfd2c37ac2 100644 --- a/modules/iswa/util/iswamanager_lua.inl +++ b/modules/iswa/util/iswamanager_lua.inl @@ -89,10 +89,10 @@ int iswa_addScreenSpaceCygnet(lua_State* L) { d.setValue("Type", "ScreenSpaceCygnet"); d.setValue("UpdateInterval", static_cast(updateInterval)); - std::shared_ptr s( + std::unique_ptr s( ScreenSpaceRenderable::createFromDictionary(d) ); - OsEng.renderEngine().addScreenSpaceRenderable(s); + OsEng.renderEngine().addScreenSpaceRenderable(std::move(s)); } return 0; } diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index f74e601bf5..eea0537f59 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -43,7 +43,6 @@ namespace { constexpr const char* KeyAsset = "Asset"; constexpr const char* KeyGlobalCustomizationScripts = "GlobalCustomizationScripts"; constexpr const char* KeyPaths = "Paths"; - constexpr const char* KeyPathsCACHE = "Paths.CACHE"; constexpr const char* KeyFonts = "Fonts"; constexpr const char* KeyLogging = "Logging"; constexpr const char* KeyLogDir = "LogDir"; diff --git a/src/engine/logfactory.cpp b/src/engine/logfactory.cpp index f5feb51d41..042fc4d66b 100644 --- a/src/engine/logfactory.cpp +++ b/src/engine/logfactory.cpp @@ -26,30 +26,29 @@ #include #include - -#include -#include #include #include #include #include +#include +#include namespace { - const char* keyType = "Type"; - const char* keyFilename = "File"; - const char* keyAppend = "Append"; - const char* keyTimeStamping = "TimeStamping"; - const char* keyDateStamping = "DateStamping"; - const char* keyCategoryStamping = "CategoryStamping"; - const char* keyLogLevelStamping = "LogLevelStamping"; - const char* keyLogLevel = "LogLevel"; + constexpr const char* KeyType = "Type"; + constexpr const char* KeyFilename = "File"; + constexpr const char* KeyAppend = "Append"; + constexpr const char* KeyTimeStamping = "TimeStamping"; + constexpr const char* KeyDateStamping = "DateStamping"; + constexpr const char* KeyCategoryStamping = "CategoryStamping"; + constexpr const char* KeyLogLevelStamping = "LogLevelStamping"; + constexpr const char* KeyLogLevel = "LogLevel"; - const char* valueHtmlLog = "html"; - const char* valueTextLog = "Text"; + constexpr const char* ValueHtmlLog = "html"; + constexpr const char* ValueTextLog = "Text"; - const char* BootstrapPath = "${WEB}/common/bootstrap.min.css"; - const char* CssPath = "${WEB}/log/style.css"; - const char* JsPath = "${WEB}/log/script.js"; + constexpr const char* BootstrapPath = "${WEB}/common/bootstrap.min.css"; + constexpr const char* CssPath = "${WEB}/log/style.css"; + constexpr const char* JsPath = "${WEB}/log/script.js"; } // namespace namespace openspace { @@ -62,50 +61,50 @@ documentation::Documentation LogFactoryDocumentation() { "core_logfactory", { { - keyType, + KeyType, new StringInListVerifier({ // List from createLog - valueTextLog, valueHtmlLog + ValueTextLog, ValueHtmlLog }), Optional::No, "The type of the new log to be generated." }, { - keyFilename, + KeyFilename, new StringVerifier, Optional::No, "The filename to which the log will be written." }, { - keyAppend, + KeyAppend, new BoolVerifier, Optional::Yes, "Determines whether the file will be cleared at startup or if the " "contents will be appended to previous runs." }, { - keyTimeStamping, + KeyTimeStamping, new BoolVerifier, Optional::Yes, "Determines whether the log entires should be stamped with the time at " "which the message was logged." }, { - keyDateStamping, + KeyDateStamping, new BoolVerifier, Optional::Yes, "Determines whether the log entries should be stamped with the date at " "which the message was logged." }, { - keyCategoryStamping, + KeyCategoryStamping, new BoolVerifier, Optional::Yes, "Determines whether the log entries should be stamped with the " "category that creates the log message." }, { - keyLogLevelStamping, + KeyLogLevelStamping, new BoolVerifier, Optional::Yes, "Determines whether the log entries should be stamped with the log level " @@ -125,33 +124,33 @@ std::unique_ptr createLog(const ghoul::Dictionary& dictiona ); // 'type' and 'filename' are required keys - std::string type = dictionary.value(keyType); - std::string filename = absPath(dictionary.value(keyFilename)); + std::string type = dictionary.value(KeyType); + std::string filename = absPath(dictionary.value(KeyFilename)); // the rest are optional bool append = true; - if (dictionary.hasKeyAndValue(keyAppend)) { - append = dictionary.value(keyAppend); + if (dictionary.hasKeyAndValue(KeyAppend)) { + append = dictionary.value(KeyAppend); } bool timeStamp = true; - if (dictionary.hasKeyAndValue(keyTimeStamping)) { - timeStamp = dictionary.value(keyTimeStamping); + if (dictionary.hasKeyAndValue(KeyTimeStamping)) { + timeStamp = dictionary.value(KeyTimeStamping); } bool dateStamp = true; - if (dictionary.hasKeyAndValue(keyDateStamping)) { - dateStamp = dictionary.value(keyDateStamping); + if (dictionary.hasKeyAndValue(KeyDateStamping)) { + dateStamp = dictionary.value(KeyDateStamping); } bool categoryStamp = true; - if (dictionary.hasKeyAndValue(keyCategoryStamping)) { - categoryStamp = dictionary.value(keyCategoryStamping); + if (dictionary.hasKeyAndValue(KeyCategoryStamping)) { + categoryStamp = dictionary.value(KeyCategoryStamping); } bool logLevelStamp = true; - if (dictionary.hasKeyAndValue(keyLogLevelStamping)) { - logLevelStamp = dictionary.value(keyLogLevelStamping); + if (dictionary.hasKeyAndValue(KeyLogLevelStamping)) { + logLevelStamp = dictionary.value(KeyLogLevelStamping); } std::string logLevel; - if (dictionary.hasKeyAndValue(keyLogLevel)) { - logLevel = dictionary.value(keyLogLevel); + if (dictionary.hasKeyAndValue(KeyLogLevel)) { + logLevel = dictionary.value(KeyLogLevel); } using Append = ghoul::logging::TextLog::Append; @@ -160,18 +159,18 @@ std::unique_ptr createLog(const ghoul::Dictionary& dictiona using CategoryStamping = ghoul::logging::Log::CategoryStamping; using LogLevelStamping = ghoul::logging::Log::LogLevelStamping; - if (type == valueHtmlLog) { + if (type == ValueHtmlLog) { std::vector cssFiles{absPath(BootstrapPath), absPath(CssPath)}; std::vector jsFiles{absPath(JsPath)}; if (logLevel.empty()) { return std::make_unique( filename, - append ? Append::Yes : Append::No, - timeStamp ? TimeStamping::Yes : TimeStamping::No, - dateStamp ? DateStamping::Yes : DateStamping::No, - categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, - logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No, + Append(append), + TimeStamping(timeStamp), + DateStamping(dateStamp), + CategoryStamping(categoryStamp), + LogLevelStamping(logLevelStamp), cssFiles, jsFiles ); @@ -179,35 +178,36 @@ std::unique_ptr createLog(const ghoul::Dictionary& dictiona else { return std::make_unique( filename, - append ? Append::Yes : Append::No, - timeStamp ? TimeStamping::Yes : TimeStamping::No, - dateStamp ? DateStamping::Yes : DateStamping::No, - categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, - logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No, - cssFiles, jsFiles, + Append(append), + TimeStamping(timeStamp), + DateStamping(dateStamp), + CategoryStamping(categoryStamp), + LogLevelStamping(logLevelStamp), + cssFiles, + jsFiles, ghoul::logging::levelFromString(logLevel) - ); + ); } } - else if (type == valueTextLog) { + else if (type == ValueTextLog) { if (logLevel.empty()) { return std::make_unique( filename, - append ? Append::Yes : Append::No, - timeStamp ? TimeStamping::Yes : TimeStamping::No, - dateStamp ? DateStamping::Yes : DateStamping::No, - categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, - logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No + Append(append), + TimeStamping(timeStamp), + DateStamping(dateStamp), + CategoryStamping(categoryStamp), + LogLevelStamping(logLevelStamp) ); } else { return std::make_unique( filename, - append ? Append::Yes : Append::No, - timeStamp ? TimeStamping::Yes : TimeStamping::No, - dateStamp ? DateStamping::Yes : DateStamping::No, - categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, - logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No, + Append(append), + TimeStamping(timeStamp), + DateStamping(dateStamp), + CategoryStamping(categoryStamp), + LogLevelStamping(logLevelStamp), ghoul::logging::levelFromString(logLevel) ); } diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 59daaf9043..2698336e56 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -39,17 +39,12 @@ #include #include #include - #include - #include #include #include #include #include -#include -#include - #include #include #include @@ -58,19 +53,18 @@ #include #include #include -#include - +#include +#include #include #include +#include #include #include #include #include #include #include - #include -#include #include #include #include @@ -80,12 +74,13 @@ #include #include #include +#include #include #include #include #include - #include +#include #if defined(_MSC_VER) && defined(OPENSPACE_ENABLE_VLD) #include @@ -100,8 +95,6 @@ #endif // __APPLE__ -#include - #include "openspaceengine_lua.inl" using namespace openspace::scripting; @@ -125,7 +118,6 @@ namespace { std::string cacheFolder; } commandlineArgumentPlaceholders; - static const openspace::properties::Property::PropertyInfo VersionInfo = { "VersionInfo", "Version Information", @@ -152,7 +144,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, : _configuration(new Configuration) , _scene(nullptr) , _dashboard(new Dashboard) - , _downloadManager(nullptr) + , _downloadManager(std::make_unique()) , _console(new LuaConsole) , _moduleEngine(new ModuleEngine) , _networkEngine(new NetworkEngine) @@ -175,10 +167,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, properties::StringProperty(VersionInfo, OPENSPACE_VERSION_STRING_FULL), properties::StringProperty(SourceControlInfo, OPENSPACE_GIT_FULL) } - , _hasScheduledAssetLoading(false) - , _scheduledAssetPathToLoad("") - , _shutdown({false, 0.f, 0.f}) - , _isFirstRenderingFirstFrame(true) { _rootPropertyOwner->addPropertySubOwner(_moduleEngine.get()); @@ -242,8 +230,6 @@ OpenSpaceEngine& OpenSpaceEngine::ref() { return *_engine; } -OpenSpaceEngine::~OpenSpaceEngine() {} - bool OpenSpaceEngine::isCreated() { return _engine != nullptr; } @@ -254,7 +240,6 @@ void OpenSpaceEngine::create(int argc, char** argv, bool& requestClose, bool consoleLog) { ghoul_assert(!_engine, "OpenSpaceEngine was already created"); - //ghoul_assert(windowWrapper != nullptr, "No Window Wrapper was provided"); requestClose = false; @@ -373,7 +358,6 @@ void OpenSpaceEngine::create(int argc, char** argv, ); } - const bool hasCacheCommandline = !commandlineArgumentPlaceholders.cacheFolder.empty(); const bool hasCacheConfig = _engine->_configuration->usePerSceneCache; std::string cacheFolder = absPath("${CACHE}"); @@ -468,14 +452,14 @@ void OpenSpaceEngine::create(int argc, char** argv, } void OpenSpaceEngine::destroy() { - if (_engine->parallelPeer().status() != - ParallelConnection::Status::Disconnected) - { + if (_engine->parallelPeer().status() != ParallelConnection::Status::Disconnected) { _engine->parallelPeer().disconnect(); } _engine->_syncEngine->removeSyncables(_engine->timeManager().getSyncables()); - _engine->_syncEngine->removeSyncables(_engine->_renderEngine->getSyncables()); + if (_engine->_scene && _engine->_scene->camera()) { + _engine->_syncEngine->removeSyncables(_engine->_scene->camera()->getSyncables()); + } _engine->_renderEngine->deinitializeGL(); @@ -505,7 +489,7 @@ void OpenSpaceEngine::initialize() { glbinding::Binding::useCurrentContext(); glbinding::Binding::initialize(); - // clear the screen so the user doesn't have to see old buffer contents from the + // clear the screen so the user doesn't have to see old buffer contents left on the // graphics card LDEBUG("Clearing all Windows"); _windowWrapper->clearAllWindows(glm::vec4(0.f, 0.f, 0.f, 1.f)); @@ -523,21 +507,10 @@ void OpenSpaceEngine::initialize() { LDEBUG("Detecting capabilities"); SysCap.detectCapabilities(); - using Verbosity = ghoul::systemcapabilities::SystemCapabilitiesComponent::Verbosity; - static const std::map VerbosityMap = { - { "None", Verbosity::None }, - { "Minimal", Verbosity::Minimal }, - { "Default", Verbosity::Default }, - { "Full", Verbosity::Full } - }; - - std::string v = _engine->_configuration->logging.capabilitiesVerbosity; - ghoul_assert( - VerbosityMap.find(v) != VerbosityMap.end(), - "Missing check for syscaps verbosity in openspace.cfg documentation" + Verbosity verbosity = ghoul::from_string( + _engine->_configuration->logging.capabilitiesVerbosity ); - Verbosity verbosity = VerbosityMap.find(v)->second; SysCap.logCapabilities(verbosity); @@ -553,9 +526,6 @@ void OpenSpaceEngine::initialize() { ); } - _downloadManager = std::make_unique(); - - // Register Lua script functions LDEBUG("Registering Lua libraries"); registerCoreClasses(*_scriptEngine); @@ -570,7 +540,6 @@ void OpenSpaceEngine::initialize() { } } - // TODO: Maybe move all scenegraph and renderengine stuff to initializeGL scriptEngine().initialize(); writeStaticDocumentation(); @@ -589,16 +558,20 @@ void OpenSpaceEngine::initialize() { _renderEngine->initialize(); - _loadingScreen = _engine->createLoadingScreen(); + _loadingScreen = std::make_unique( + LoadingScreen::ShowMessage(_configuration->loadingScreen.isShowingMessages), + LoadingScreen::ShowNodeNames(_configuration->loadingScreen.isShowingNodeNames), + LoadingScreen::ShowProgressbar(_configuration->loadingScreen.isShowingProgressbar) + ); + _loadingScreen->render(); - for (const auto& func : _moduleCallbacks.initialize) { + for (const std::function& func : _moduleCallbacks.initialize) { func(); } - std::string assetPath = _engine->_configuration->asset; _engine->_assetManager->initialize(); - scheduleLoadSingleAsset(assetPath); + scheduleLoadSingleAsset(_engine->_configuration->asset); LTRACE("OpenSpaceEngine::initialize(end)"); } @@ -608,18 +581,6 @@ void OpenSpaceEngine::scheduleLoadSingleAsset(std::string assetPath) { _scheduledAssetPathToLoad = assetPath; } -std::unique_ptr OpenSpaceEngine::createLoadingScreen() { - bool showMessage = _configuration->loadingScreen.isShowingMessages; - bool showNodeNames = _configuration->loadingScreen.isShowingNodeNames; - bool showProgressbar = _configuration->loadingScreen.isShowingProgressbar; - - return std::make_unique( - LoadingScreen::ShowMessage(showMessage), - LoadingScreen::ShowNodeNames(showNodeNames), - LoadingScreen::ShowProgressbar(showProgressbar) - ); -} - void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { LTRACE("OpenSpaceEngine::loadSingleAsset(begin)"); @@ -630,12 +591,14 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { windowWrapper().setBarrier(true); }; - if (assetPath == "") { + if (assetPath.empty()) { return; } if (_scene) { _syncEngine->removeSyncables(_timeManager->getSyncables()); - _syncEngine->removeSyncables(_renderEngine->getSyncables()); + if (_scene && _scene->camera()) { + _syncEngine->removeSyncables(_scene->camera()->getSyncables()); + } _renderEngine->setScene(nullptr); _renderEngine->setCamera(nullptr); _navigationHandler->setCamera(nullptr); @@ -643,10 +606,8 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { _rootPropertyOwner->removePropertySubOwner(_scene.get()); } - bool multiThreadedInitialization = _configuration->useMultithreadedInitialization; - std::unique_ptr sceneInitializer; - if (multiThreadedInitialization) { + if (_configuration->useMultithreadedInitialization) { unsigned int nAvailableThreads = std::thread::hardware_concurrency(); unsigned int nThreads = nAvailableThreads == 0 ? 2 : nAvailableThreads - 1; sceneInitializer = std::make_unique(nThreads); @@ -681,11 +642,11 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { _assetManager->rootAsset()->subTreeAssets(); std::unordered_set> resourceSyncs; - for (const auto& a : allAssets) { + for (const std::shared_ptr& a : allAssets) { std::vector> syncs = a->ownSynchronizations(); - for (const auto& s : syncs) { + for (const std::shared_ptr& s : syncs) { if (s->state() == ResourceSynchronization::State::Syncing) { resourceSyncs.insert(s); _loadingScreen->updateItem( @@ -722,7 +683,7 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { (*it)->name(), (*it)->name(), LoadingScreen::ItemStatus::Finished, - 1.0f + 1.f ); it = resourceSyncs.erase(it); } @@ -740,11 +701,13 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { _loadingScreen->finalize(); _renderEngine->updateScene(); - _renderEngine->setGlobalBlackOutFactor(0.0); - _renderEngine->startFading(1, 3.0); + _renderEngine->setGlobalBlackOutFactor(0.f); + _renderEngine->startFading(1, 3.f); _syncEngine->addSyncables(_timeManager->getSyncables()); - _syncEngine->addSyncables(_renderEngine->getSyncables()); + if (_scene && _scene->camera()) { + _syncEngine->addSyncables(_scene->camera()->getSyncables()); + } #ifdef __APPLE__ showTouchbar(); @@ -760,11 +723,11 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { void OpenSpaceEngine::deinitialize() { LTRACE("OpenSpaceEngine::deinitialize(begin)"); - for (const auto& func : _engine->_moduleCallbacks.deinitializeGL) { + for (const std::function& func : _engine->_moduleCallbacks.deinitializeGL) { func(); } - for (const auto& func : _engine->_moduleCallbacks.deinitialize) { + for (const std::function& func : _engine->_moduleCallbacks.deinitialize) { func(); } @@ -824,7 +787,6 @@ void OpenSpaceEngine::gatherCommandlineArguments() { } void OpenSpaceEngine::runGlobalCustomizationScripts() { - // @CLEANUP: Move this into the scene loading? ---abock LINFO("Running Global initialization scripts"); ghoul::lua::LuaState state; OsEng.scriptEngine().initializeLuaState(state); @@ -896,7 +858,7 @@ void OpenSpaceEngine::configureLogging(bool consoleLog) { using ImmediateFlush = ghoul::logging::LogManager::ImmediateFlush; LogManager::initialize( level, - immediateFlush ? ImmediateFlush::Yes : ImmediateFlush::No + ImmediateFlush(immediateFlush) ); if (consoleLog) { LogMgr.addLog(std::make_unique()); @@ -906,8 +868,15 @@ void OpenSpaceEngine::configureLogging(bool consoleLog) { try { LogMgr.addLog(createLog(log)); } - catch (const ghoul::RuntimeError& e) { - LERRORC(e.component, e.message); + catch (const documentation::SpecificationError& e) { + LERROR("Failed loading of log"); + for (const documentation::TestResult::Offense& o : e.result.offenses) { + LERRORC(o.offender, std::to_string(o.reason)); + } + for (const documentation::TestResult::Warning& w : e.result.warnings) { + LWARNINGC(w.offender, std::to_string(w.reason)); + } + throw; } } @@ -918,9 +887,7 @@ void OpenSpaceEngine::configureLogging(bool consoleLog) { #endif // WIN32 #ifndef GHOUL_LOGGING_ENABLE_TRACE - std::string logLevel = "Info"; - configurationManager().getValue(KeyLogLevel, logLevel); - LogLevel level = ghoul::logging::levelFromString(logLevel); + LogLevel level = ghoul::logging::levelFromString(_configuration->logging.level); if (level == ghoul::logging::LogLevel::Trace) { LWARNING( @@ -996,8 +963,7 @@ void OpenSpaceEngine::initializeGL() { } - for (const std::string& sev : _configuration->openGLDebugContext.severityFilters) - { + for (const std::string& sev : _configuration->openGLDebugContext.severityFilters){ setDebugMessageControl( Source::DontCare, Type::DontCare, @@ -1041,6 +1007,7 @@ void OpenSpaceEngine::initializeGL() { // state from KeyCheckOpenGLState if (_configuration->isCheckingOpenGLState) { using namespace glbinding; + // Infinite loop -- welcome to the danger zone setCallbackMaskExcept(CallbackMask::After, { "glGetError" }); setAfterCallback([](const FunctionCall& f) { @@ -1092,6 +1059,7 @@ void OpenSpaceEngine::initializeGL() { if (_configuration->isLoggingOpenGLCalls) { using namespace glbinding; + setCallbackMask(CallbackMask::After | CallbackMask::ParametersAndReturnValue); glbinding::setAfterCallback([](const glbinding::FunctionCall& call) { std::string arguments = std::accumulate( @@ -1119,7 +1087,7 @@ void OpenSpaceEngine::initializeGL() { _moduleEngine->initializeGL(); - for (const auto& func : _moduleCallbacks.initializeGL) { + for (const std::function& func : _moduleCallbacks.initializeGL) { func(); } @@ -1136,7 +1104,7 @@ void OpenSpaceEngine::preSynchronization() { perf = std::make_unique( "OpenSpaceEngine::preSynchronization", OsEng.renderEngine().performanceManager() - ); + ); } FileSys.triggerFilesystemEvents(); @@ -1145,7 +1113,7 @@ void OpenSpaceEngine::preSynchronization() { LINFO(fmt::format("Loading asset: {}", _scheduledAssetPathToLoad)); loadSingleAsset(_scheduledAssetPathToLoad); _hasScheduledAssetLoading = false; - _scheduledAssetPathToLoad = ""; + _scheduledAssetPathToLoad.clear(); } if (_isFirstRenderingFirstFrame) { @@ -1165,22 +1133,23 @@ void OpenSpaceEngine::preSynchronization() { ); for (Iter it = scheduledScripts.first; it != scheduledScripts.second; ++it) { _scriptEngine->queueScript( - *it, ScriptEngine::RemoteScripting::Yes + *it, + ScriptEngine::RemoteScripting::Yes ); } _renderEngine->updateScene(); //_navigationHandler->updateCamera(dt); - Camera* camera = _renderEngine->camera(); + Camera* camera = _scene->camera(); if (camera) { _navigationHandler->updateCamera(dt); - _renderEngine->camera()->invalidateCache(); + camera->invalidateCache(); } _parallelPeer->preSynchronization(); } - for (const auto& func : _moduleCallbacks.preSync) { + for (const std::function& func : _moduleCallbacks.preSync) { func(); } LTRACE("OpenSpaceEngine::preSynchronization(end)"); @@ -1220,10 +1189,10 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { _renderEngine->updateShaderPrograms(); if (!master) { - _renderEngine->camera()->invalidateCache(); + _scene->camera()->invalidateCache(); } - for (const auto& func : _moduleCallbacks.postSyncPreDraw) { + for (const std::function& func : _moduleCallbacks.postSyncPreDraw) { func(); } @@ -1249,8 +1218,7 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { LTRACE("OpenSpaceEngine::postSynchronizationPreDraw(end)"); } -void OpenSpaceEngine::render(const glm::mat4& sceneMatrix, - const glm::mat4& viewMatrix, +void OpenSpaceEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix) { LTRACE("OpenSpaceEngine::render(begin)"); @@ -1271,7 +1239,7 @@ void OpenSpaceEngine::render(const glm::mat4& sceneMatrix, _renderEngine->render(sceneMatrix, viewMatrix, projectionMatrix); - for (const auto& func : _moduleCallbacks.render) { + for (const std::function& func : _moduleCallbacks.render) { func(); } @@ -1297,7 +1265,7 @@ void OpenSpaceEngine::drawOverlays() { _console->render(); } - for (const auto& func : _moduleCallbacks.draw2D) { + for (const std::function& func : _moduleCallbacks.draw2D) { func(); } @@ -1317,7 +1285,7 @@ void OpenSpaceEngine::postDraw() { _renderEngine->postDraw(); - for (const auto& func : _moduleCallbacks.postDraw) { + for (const std::function& func : _moduleCallbacks.postDraw) { func(); } @@ -1326,20 +1294,20 @@ void OpenSpaceEngine::postDraw() { _isFirstRenderingFirstFrame = false; } - LTRACE("OpenSpaceEngine::postDraw(end)"); } void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) { - for (const auto& func : _moduleCallbacks.keyboard) { - const bool consumed = func(key, mod, action); - if (consumed) { + using F = std::function; + for (const F& func : _moduleCallbacks.keyboard) { + const bool isConsumed = func(key, mod, action); + if (isConsumed) { return; } } - const bool consoleConsumed = _console->keyboardCallback(key, mod, action); - if (consoleConsumed) { + const bool isConsoleConsumed = _console->keyboardCallback(key, mod, action); + if (isConsoleConsumed) { return; } @@ -1348,9 +1316,10 @@ void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction actio } void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier) { - for (const auto& func : _moduleCallbacks.character) { - bool consumed = func(codepoint, modifier); - if (consumed) { + using F = std::function; + for (const F& func : _moduleCallbacks.character) { + bool isConsumed = func(codepoint, modifier); + if (isConsumed) { return; } } @@ -1359,9 +1328,10 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier) } void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action) { - for (const auto& func : _moduleCallbacks.mouseButton) { - bool consumed = func(button, action); - if (consumed) { + using F = std::function; + for (const F& func : _moduleCallbacks.mouseButton) { + bool isConsumed = func(button, action); + if (isConsumed) { // If the mouse was released, we still want to forward it to the navigation // handler in order to reliably terminate a rotation or zoom. Accidentally // moving the cursor over a UI window is easy to miss and leads to weird @@ -1379,7 +1349,8 @@ void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action } void OpenSpaceEngine::mousePositionCallback(double x, double y) { - for (const auto& func : _moduleCallbacks.mousePosition) { + using F = std::function; + for (const F& func : _moduleCallbacks.mousePosition) { func(x, y); } @@ -1387,9 +1358,10 @@ void OpenSpaceEngine::mousePositionCallback(double x, double y) { } void OpenSpaceEngine::mouseScrollWheelCallback(double posX, double posY) { - for (const auto& func : _moduleCallbacks.mouseScrollWheel) { - bool consumed = func(posX, posY); - if (consumed) { + using F = std::function; + for (const F& func : _moduleCallbacks.mouseScrollWheel) { + bool isConsumed = func(posX, posY); + if (isConsumed) { return; } } @@ -1571,6 +1543,7 @@ void OpenSpaceEngine::registerModuleMouseScrollWheelCallback( } const Configuration& OpenSpaceEngine::configuration() const { + ghoul_assert(_configuration, "Configuration must not be nullptr"); return *_configuration; } @@ -1645,19 +1618,12 @@ interaction::KeyBindingManager& OpenSpaceEngine::keyBindingManager() { } properties::PropertyOwner& OpenSpaceEngine::rootPropertyOwner() { - ghoul_assert( - _rootPropertyOwner, - "Root Property Namespace must not be nullptr" - ); + ghoul_assert(_rootPropertyOwner, "Root Property Namespace must not be nullptr"); return *_rootPropertyOwner; } VirtualPropertyManager& OpenSpaceEngine::virtualPropertyManager() { - ghoul_assert( - _virtualPropertyManager, - "Virtual Property Manager must not be nullptr" - ); - + ghoul_assert(_virtualPropertyManager, "Virtual Property Manager must not be nullptr"); return *_virtualPropertyManager; } diff --git a/src/interaction/navigationhandler_lua.inl b/src/interaction/navigationhandler_lua.inl index 5a640be04e..ab8eccee66 100644 --- a/src/interaction/navigationhandler_lua.inl +++ b/src/interaction/navigationhandler_lua.inl @@ -184,7 +184,7 @@ int bindJoystickButton(lua_State* L) { } int clearJoystickButton(lua_State* L) { - int n = ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::bindJoystickButton"); + ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::bindJoystickButton"); int button = static_cast(lua_tonumber(L, 1)); @@ -195,7 +195,7 @@ int clearJoystickButton(lua_State* L) { } int joystickButton(lua_State* L) { - int n = ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::bindJoystickButton"); + ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::bindJoystickButton"); int button = static_cast(lua_tonumber(L, 1)); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 4b717d7c6a..bdc25c82fc 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -86,9 +86,7 @@ namespace { constexpr const char* _loggerCat = "RenderEngine"; - constexpr const char* KeyRenderingMethod = "RenderingMethod"; constexpr const std::chrono::seconds ScreenLogTimeToLive(15); - constexpr const char* DefaultRenderingMethod = "ABuffer"; constexpr const char* RenderFsPath = "${SHADERS}/render.frag"; constexpr const char* KeyFontMono = "Mono"; @@ -242,20 +240,14 @@ RenderEngine::RenderEngine() , _showVersionInfo(ShowVersionInfo, true) , _showCameraInfo(ShowCameraInfo, true) , _takeScreenshot(TakeScreenshotInfo) - , _shouldTakeScreenshot(false) , _applyWarping(ApplyWarpingInfo, false) , _showFrameNumber(ShowFrameNumberInfo, false) , _disableMasterRendering(DisableMasterInfo, false) , _disableSceneTranslationOnMaster(DisableTranslationInfo, false) - , _globalBlackOutFactor(1.f) - , _fadeDuration(2.f) - , _currentFadeTime(0.f) - , _fadeDirection(0) , _nAaSamples(AaSamplesInfo, 4, 1, 16) , _hdrExposure(HDRExposureInfo, 0.4f, 0.01f, 10.0f) , _hdrBackground(BackgroundExposureInfo, 2.8f, 0.01f, 10.0f) , _gamma(GammaInfo, 2.2f, 0.01f, 10.0f) - , _frameNumber(0) , _screenSpaceOwner({ "ScreenSpace" }) { _doPerformanceMeasurements.onChange([this](){ @@ -284,26 +276,29 @@ RenderEngine::RenderEngine() _renderer->setNAaSamples(_nAaSamples); } }); + addProperty(_nAaSamples); + _hdrExposure.onChange([this]() { if (_renderer) { _renderer->setHDRExposure(_hdrExposure); } }); + addProperty(_hdrExposure); + _hdrBackground.onChange([this]() { if (_renderer) { _renderer->setHDRBackground(_hdrBackground); } }); + addProperty(_hdrBackground); + _gamma.onChange([this]() { if (_renderer) { _renderer->setGamma(_gamma); } }); - - addProperty(_nAaSamples); - addProperty(_hdrExposure); - addProperty(_hdrBackground); addProperty(_gamma); + addProperty(_applyWarping); _takeScreenshot.onChange([this](){ @@ -324,14 +319,14 @@ void RenderEngine::setRendererFromString(const std::string& renderingMethod) { std::unique_ptr newRenderer = nullptr; switch (_rendererImplementation) { - case RendererImplementation::Framebuffer: - newRenderer = std::make_unique(); - break; - case RendererImplementation::ABuffer: - newRenderer = std::make_unique(); - break; - case RendererImplementation::Invalid: - LFATAL(fmt::format("Rendering method '{}' not available", renderingMethod)); + case RendererImplementation::Framebuffer: + newRenderer = std::make_unique(); + break; + case RendererImplementation::ABuffer: + newRenderer = std::make_unique(); + break; + case RendererImplementation::Invalid: + LFATAL(fmt::format("Rendering method '{}' not available", renderingMethod)); } setRenderer(std::move(newRenderer)); @@ -352,9 +347,11 @@ void RenderEngine::initialize() { } } - _disableMasterRendering = OsEng.configuration().isRenderingOnMasterDisabled; + // We have to perform these initializations here as the OsEng has not been initialized + // in our constructor _disableSceneTranslationOnMaster = OsEng.configuration().isSceneTranslationOnMasterDisabled; + _disableMasterRendering = OsEng.configuration().isRenderingOnMasterDisabled; _raycasterManager = std::make_unique(); _deferredcasterManager = std::make_unique(); @@ -365,30 +362,30 @@ void RenderEngine::initialize() { #ifdef GHOUL_USE_DEVIL ghoul::io::TextureReader::ref().addReader( - std::make_shared() + std::make_unique() ); #endif // GHOUL_USE_DEVIL #ifdef GHOUL_USE_FREEIMAGE ghoul::io::TextureReader::ref().addReader( - std::make_shared() + std::make_unique() ); #endif // GHOUL_USE_FREEIMAGE #ifdef GHOUL_USE_SOIL ghoul::io::TextureReader::ref().addReader( - std::make_shared() + std::make_unique() ); ghoul::io::TextureWriter::ref().addWriter( - std::make_shared() + std::make_unique() ); #endif // GHOUL_USE_SOIL #ifdef GHOUL_USE_STB_IMAGE ghoul::io::TextureReader::ref().addReader( - std::make_shared() + std::make_unique() ); #endif // GHOUL_USE_STB_IMAGE ghoul::io::TextureReader::ref().addReader( - std::make_shared() + std::make_unique() ); MissionManager::initialize(); @@ -403,26 +400,21 @@ void RenderEngine::initializeGL() { // development OsEng.windowWrapper().setNearFarClippingPlane(0.001f, 1000.f); - try { - const float fontSizeBig = 50.f; - _fontBig = OsEng.fontManager().font(KeyFontMono, fontSizeBig); - const float fontSizeTime = 15.f; - _fontDate = OsEng.fontManager().font(KeyFontMono, fontSizeTime); - const float fontSizeMono = 10.f; - _fontInfo = OsEng.fontManager().font(KeyFontMono, fontSizeMono); - const float fontSizeLight = 8.f; - _fontLog = OsEng.fontManager().font(KeyFontLight, fontSizeLight); - } catch (const ghoul::fontrendering::Font::FreeTypeException& e) { - LERROR(e.what()); - throw; - } + constexpr const float fontSizeBig = 50.f; + _fontBig = OsEng.fontManager().font(KeyFontMono, fontSizeBig); + constexpr const float fontSizeTime = 15.f; + _fontDate = OsEng.fontManager().font(KeyFontMono, fontSizeTime); + constexpr const float fontSizeMono = 10.f; + _fontInfo = OsEng.fontManager().font(KeyFontMono, fontSizeMono); + constexpr const float fontSizeLight = 8.f; + _fontLog = OsEng.fontManager().font(KeyFontLight, fontSizeLight); LINFO("Initializing Log"); std::unique_ptr log = std::make_unique(ScreenLogTimeToLive); _log = log.get(); ghoul::logging::LogManager::ref().addLog(std::move(log)); - for (std::shared_ptr& ssr : _screenSpaceRenderables) { + for (std::unique_ptr& ssr : _screenSpaceRenderables) { ssr->initializeGL(); } @@ -431,7 +423,7 @@ void RenderEngine::initializeGL() { } void RenderEngine::deinitialize() { - for (std::shared_ptr& ssr : _screenSpaceRenderables) { + for (std::unique_ptr& ssr : _screenSpaceRenderables) { ssr->deinitialize(); } @@ -439,7 +431,7 @@ void RenderEngine::deinitialize() { } void RenderEngine::deinitializeGL() { - for (std::shared_ptr& ssr : _screenSpaceRenderables) { + for (std::unique_ptr& ssr : _screenSpaceRenderables) { ssr->deinitializeGL(); } } @@ -453,7 +445,7 @@ void RenderEngine::updateScene() { const Time& currentTime = OsEng.timeManager().time(); _scene->update({ - { glm::dvec3(0), glm::dmat3(1), 1.0 }, + { glm::dvec3(0.0), glm::dmat3(11.), 1.0 }, currentTime, _performanceManager != nullptr }); @@ -490,7 +482,7 @@ void RenderEngine::updateRenderer() { } void RenderEngine::updateScreenSpaceRenderables() { - for (std::shared_ptr& ssr : _screenSpaceRenderables) { + for (std::unique_ptr& ssr : _screenSpaceRenderables) { ssr->update(); } } @@ -516,18 +508,18 @@ glm::ivec2 RenderEngine::fontResolution() const { void RenderEngine::updateFade() { // Temporary fade funtionality - const float fadedIn = 1.0; - const float fadedOut = 0.0; + constexpr const float FadedIn = 1.0; + constexpr const float FadedOut = 0.0; // Don't restart the fade if you've already done it in that direction - const bool isFadedIn = (_fadeDirection > 0 && _globalBlackOutFactor == fadedIn); - const bool isFadedOut = (_fadeDirection < 0 && _globalBlackOutFactor == fadedOut); + const bool isFadedIn = (_fadeDirection > 0 && _globalBlackOutFactor == FadedIn); + const bool isFadedOut = (_fadeDirection < 0 && _globalBlackOutFactor == FadedOut); if (isFadedIn || isFadedOut) { _fadeDirection = 0; } if (_fadeDirection != 0) { if (_currentFadeTime > _fadeDuration) { - _globalBlackOutFactor = _fadeDirection > 0 ? fadedIn : fadedOut; + _globalBlackOutFactor = _fadeDirection > 0 ? FadedIn : FadedOut; _fadeDirection = 0; } else { @@ -547,13 +539,13 @@ void RenderEngine::updateFade() { } _currentFadeTime += static_cast( OsEng.windowWrapper().averageDeltaTime() - ); + ); } } } void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMatrix, - const glm::mat4& projectionMatrix) + const glm::mat4& projectionMatrix) { LTRACE("RenderEngine::render(begin)"); WindowWrapper& wrapper = OsEng.windowWrapper(); @@ -584,7 +576,7 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat ++_frameNumber; - for (std::shared_ptr& ssr : _screenSpaceRenderables) { + for (std::unique_ptr& ssr : _screenSpaceRenderables) { if (ssr->isEnabled() && ssr->isReady()) { ssr->render(); } @@ -612,7 +604,7 @@ void RenderEngine::renderOverlays(const ShutdownInformation& info) { } void RenderEngine::renderShutdownInformation(float timer, float fullTime) { - timer = timer < 0.f ? 0.f : timer; + timer = std::max(timer, 0.f); auto size = ghoul::fontrendering::FontRenderer::defaultRenderer().boundingBox( *_fontDate, @@ -650,7 +642,7 @@ void RenderEngine::renderDashboard() { perf = std::make_unique( "Main Dashboard::render", OsEng.renderEngine().performanceManager() - ); + ); } glm::vec2 penPosition = glm::vec2( 10.f, @@ -716,12 +708,8 @@ void RenderEngine::setCamera(Camera* camera) { } } -Camera* RenderEngine::camera() const { - return _camera; -} - -Renderer* RenderEngine::renderer() const { - return _renderer.get(); +const Renderer& RenderEngine::renderer() const { + return *_renderer; } RenderEngine::RendererImplementation RenderEngine::rendererImplementation() const { @@ -743,27 +731,29 @@ void RenderEngine::startFading(int direction, float fadeDuration) { } /** -* Build a program object for rendering with the used renderer -*/ + * Build a program object for rendering with the used renderer + */ std::unique_ptr RenderEngine::buildRenderProgram( - std::string name, std::string vsPath, - std::string fsPath, const ghoul::Dictionary& data) + const std::string& name, + const std::string& vsPath, + std::string fsPath, + ghoul::Dictionary data) { - ghoul::Dictionary dict = data; + ghoul::Dictionary dict = std::move(data); // set path to the current renderer's main fragment shader dict.setValue("rendererData", _rendererData); // parameterize the main fragment shader program with specific contents. // fsPath should point to a shader file defining a Fragment getFragment() function // instead of a void main() setting glFragColor, glFragDepth, etc. - dict.setValue("fragmentPath", fsPath); + dict.setValue("fragmentPath", std::move(fsPath)); using namespace ghoul::opengl; std::unique_ptr program = ProgramObject::Build( name, vsPath, absPath(RenderFsPath), - dict + std::move(dict) ); if (program) { @@ -776,17 +766,19 @@ std::unique_ptr RenderEngine::buildRenderProgram( * Build a program object for rendering with the used renderer */ std::unique_ptr RenderEngine::buildRenderProgram( - std::string name, std::string vsPath, - std::string fsPath, std::string csPath, - const ghoul::Dictionary& data) + const std::string& name, + const std::string& vsPath, + std::string fsPath, + const std::string& csPath, + ghoul::Dictionary data) { - ghoul::Dictionary dict = data; + ghoul::Dictionary dict = std::move(data); dict.setValue("rendererData", _rendererData); // parameterize the main fragment shader program with specific contents. // fsPath should point to a shader file defining a Fragment getFragment() function // instead of a void main() setting glFragColor, glFragDepth, etc. - dict.setValue("fragmentPath", fsPath); + dict.setValue("fragmentPath", std::move(fsPath)); using namespace ghoul::opengl; std::unique_ptr program = ProgramObject::Build( @@ -794,7 +786,7 @@ std::unique_ptr RenderEngine::buildRenderProgram( vsPath, absPath(RenderFsPath), csPath, - dict + std::move(dict) ); if (program) { @@ -824,8 +816,8 @@ void RenderEngine::removeRenderProgram(ghoul::opengl::ProgramObject* program) { * Called from the renderer, whenever it needs to update * the dictionary of all rendering programs. */ -void RenderEngine::setRendererData(const ghoul::Dictionary& data) { - _rendererData = data; +void RenderEngine::setRendererData(ghoul::Dictionary data) { + _rendererData = std::move(data); for (ghoul::opengl::ProgramObject* program : _programs) { ghoul::Dictionary dict = program->dictionary(); dict.setValue("rendererData", _rendererData); @@ -838,8 +830,8 @@ void RenderEngine::setRendererData(const ghoul::Dictionary& data) { * Called from the renderer, whenever it needs to update * the dictionary of all post rendering programs. */ -void RenderEngine::setResolveData(const ghoul::Dictionary& data) { - _resolveData = data; +void RenderEngine::setResolveData(ghoul::Dictionary data) { + _resolveData = std::move(data); for (ghoul::opengl::ProgramObject* program : _programs) { ghoul::Dictionary dict = program->dictionary(); dict.setValue("resolveData", _resolveData); @@ -848,22 +840,22 @@ void RenderEngine::setResolveData(const ghoul::Dictionary& data) { } /** -* Set raycasting uniforms on the program object, and setup raycasting. -*/ + * Set raycasting uniforms on the program object, and setup raycasting. + */ void RenderEngine::preRaycast(ghoul::opengl::ProgramObject& programObject) { _renderer->preRaycast(programObject); } /** -* Tear down raycasting for the specified program object. -*/ + * Tear down raycasting for the specified program object. + */ void RenderEngine::postRaycast(ghoul::opengl::ProgramObject& programObject) { _renderer->postRaycast(programObject); } /** -* Set renderer -*/ + * Set renderer + */ void RenderEngine::setRenderer(std::unique_ptr renderer) { if (_renderer) { _renderer->deinitialize(); @@ -938,7 +930,7 @@ std::shared_ptr RenderEngine::performanceManage return _performanceManager; } -void RenderEngine::addScreenSpaceRenderable(std::shared_ptr s) { +void RenderEngine::addScreenSpaceRenderable(std::unique_ptr s) { s->initialize(); s->initializeGL(); @@ -947,41 +939,41 @@ void RenderEngine::addScreenSpaceRenderable(std::shared_ptr s) { - auto it = std::find( +void RenderEngine::removeScreenSpaceRenderable(ScreenSpaceRenderable* s) { + auto it = std::find_if( _screenSpaceRenderables.begin(), _screenSpaceRenderables.end(), - s + [s](const std::unique_ptr& r) { return r.get() == s; } ); if (it != _screenSpaceRenderables.end()) { s->deinitialize(); - _screenSpaceOwner.removePropertySubOwner(s.get()); + _screenSpaceOwner.removePropertySubOwner(s); _screenSpaceRenderables.erase(it); } } void RenderEngine::removeScreenSpaceRenderable(const std::string& name) { - std::shared_ptr s = screenSpaceRenderable(name); + ScreenSpaceRenderable* s = screenSpaceRenderable(name); if (s) { removeScreenSpaceRenderable(s); } } -std::shared_ptr RenderEngine::screenSpaceRenderable( +ScreenSpaceRenderable* RenderEngine::screenSpaceRenderable( const std::string& identifier) { auto it = std::find_if( _screenSpaceRenderables.begin(), _screenSpaceRenderables.end(), - [&identifier](const std::shared_ptr& s) { + [&identifier](const std::unique_ptr& s) { return s->identifier() == identifier; } ); if (it != _screenSpaceRenderables.end()) { - return *it; + return it->get(); } else { return nullptr; @@ -994,7 +986,7 @@ std::vector RenderEngine::screenSpaceRenderables() const _screenSpaceRenderables.begin(), _screenSpaceRenderables.end(), res.begin(), - [](std::shared_ptr p) { return p.get(); } + [](const std::unique_ptr& p) { return p.get(); } ); return res; } @@ -1020,8 +1012,8 @@ void RenderEngine::renderCameraInformation() { return; } - const glm::vec4 enabled = glm::vec4(0.2f, 0.75f, 0.2f, 1.f); - const glm::vec4 disabled = glm::vec4(0.55f, 0.2f, 0.2f, 1.f); + const glm::vec4 EnabledColor = glm::vec4(0.2f, 0.75f, 0.2f, 1.f); + const glm::vec4 DisabledColor = glm::vec4(0.55f, 0.2f, 0.2f, 1.f); using FR = ghoul::fontrendering::FontRenderer; @@ -1033,19 +1025,19 @@ void RenderEngine::renderCameraInformation() { float penPosY = fontResolution().y - rotationBox.boundingBox.y; - const float ySeparation = 5.f; - const float xSeparation = 5.f; + constexpr const float YSeparation = 5.f; + constexpr const float XSeparation = 5.f; interaction::OrbitalNavigator nav = OsEng.navigationHandler().orbitalNavigator(); FR::defaultRenderer().render( *_fontInfo, - glm::vec2(fontResolution().x - rotationBox.boundingBox.x - xSeparation, penPosY), - nav.hasRotationalFriction() ? enabled : disabled, + glm::vec2(fontResolution().x - rotationBox.boundingBox.x - XSeparation, penPosY), + nav.hasRotationalFriction() ? EnabledColor : DisabledColor, "%s", "Rotation" ); - penPosY -= rotationBox.boundingBox.y + ySeparation; + penPosY -= rotationBox.boundingBox.y + YSeparation; FR::BoundingBoxInformation zoomBox = FR::defaultRenderer().boundingBox( *_fontInfo, @@ -1055,12 +1047,12 @@ void RenderEngine::renderCameraInformation() { FR::defaultRenderer().render( *_fontInfo, - glm::vec2(fontResolution().x - zoomBox.boundingBox.x - xSeparation, penPosY), - nav.hasZoomFriction() ? enabled : disabled, + glm::vec2(fontResolution().x - zoomBox.boundingBox.x - XSeparation, penPosY), + nav.hasZoomFriction() ? EnabledColor : DisabledColor, "%s", "Zoom" ); - penPosY -= zoomBox.boundingBox.y + ySeparation; + penPosY -= zoomBox.boundingBox.y + YSeparation; FR::BoundingBoxInformation rollBox = FR::defaultRenderer().boundingBox( *_fontInfo, @@ -1070,8 +1062,8 @@ void RenderEngine::renderCameraInformation() { FR::defaultRenderer().render( *_fontInfo, - glm::vec2(fontResolution().x - rollBox.boundingBox.x - xSeparation, penPosY), - nav.hasRollFriction() ? enabled : disabled, + glm::vec2(fontResolution().x - rollBox.boundingBox.x - XSeparation, penPosY), + nav.hasRollFriction() ? EnabledColor : DisabledColor, "%s", "Roll" ); @@ -1134,15 +1126,15 @@ void RenderEngine::renderScreenLog() { _log->removeExpiredEntries(); - const int max = 10; - const int categoryLength = 20; - const int messageLength = 140; - std::chrono::seconds fade(5); + constexpr const int MaxNumberMessages = 10; + constexpr const int CategoryLength = 20; + constexpr const int MessageLength = 140; + constexpr const std::chrono::seconds FadeTime(5); - const std::vector entries = _log->entries(); + const std::vector& entries = _log->entries(); auto lastEntries = - entries.size() > max ? - std::make_pair(entries.rbegin(), entries.rbegin() + max) : + entries.size() > MaxNumberMessages ? + std::make_pair(entries.rbegin(), entries.rbegin() + MaxNumberMessages) : std::make_pair(entries.rbegin(), entries.rend()); size_t nr = 1; @@ -1152,22 +1144,22 @@ void RenderEngine::renderScreenLog() { std::chrono::duration diff = now - e->timeStamp; - float alpha = 1; - std::chrono::duration ttf = ScreenLogTimeToLive - fade; + float alpha = 1.f; + std::chrono::duration ttf = ScreenLogTimeToLive - FadeTime; if (diff > ttf) { auto d = (diff - ttf).count(); - auto t = static_cast(d) / static_cast(fade.count()); + auto t = static_cast(d) / static_cast(FadeTime.count()); float p = 0.8f - t; alpha = (p <= 0.f) ? 0.f : pow(p, 0.4f); } // Since all log entries are ordered, once one exceeds alpha, all have - if (alpha <= 0.0) { + if (alpha <= 0.f) { break; } const std::string lvl = "(" + ghoul::logging::stringFromLevel(e->level) + ")"; - const std::string& message = e->message.substr(0, messageLength); + const std::string& message = e->message.substr(0, MessageLength); nr += std::count(message.begin(), message.end(), '\n'); const glm::vec4 white(0.9f, 0.9f, 0.9f, alpha); @@ -1178,7 +1170,7 @@ void RenderEngine::renderScreenLog() { white, "%-14s %s%s", e->timeString.c_str(), - e->category.substr(0, categoryLength).c_str(), + e->category.substr(0, CategoryLength).c_str(), e->category.length() > 20 ? "..." : ""); glm::vec4 color(glm::uninitialize); @@ -1208,7 +1200,8 @@ void RenderEngine::renderScreenLog() { lvl.c_str() ); - RenderFont(*_fontLog, + RenderFont( + *_fontLog, glm::vec2(10 + 53 * _fontLog->pointSize(), _fontLog->pointSize() * nr * 2), white, "%s", @@ -1218,14 +1211,6 @@ void RenderEngine::renderScreenLog() { } } -std::vector RenderEngine::getSyncables() { - if (_camera) { - return _camera->getSyncables(); - } else { - return {}; - } -} - properties::PropertyOwner& RenderEngine::screenSpaceOwner() { return _screenSpaceOwner; } diff --git a/src/rendering/renderengine_lua.inl b/src/rendering/renderengine_lua.inl index ee437b9799..f5a3715d56 100644 --- a/src/rendering/renderengine_lua.inl +++ b/src/rendering/renderengine_lua.inl @@ -70,7 +70,8 @@ int toggleFade(lua_State* L) { int fadeIn(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::fadeIn"); - double t = luaL_checknumber(L, -1); + double t = luaL_checknumber(L, 1); + lua_pop(L, 1); OsEng.renderEngine().startFading(1, static_cast(t)); @@ -85,7 +86,8 @@ int fadeIn(lua_State* L) { int fadeOut(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::fadeOut"); - double t = luaL_checknumber(L, -1); + double t = luaL_checknumber(L, 1); + lua_pop(L, 1); OsEng.renderEngine().startFading(-1, static_cast(t)); @@ -108,10 +110,10 @@ int addScreenSpaceRenderable(lua_State* L) { return 0; } - std::shared_ptr s( + std::unique_ptr s( ScreenSpaceRenderable::createFromDictionary(d) ); - OsEng.renderEngine().addScreenSpaceRenderable(s); + OsEng.renderEngine().addScreenSpaceRenderable(std::move(s)); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); return 0; @@ -123,22 +125,7 @@ int removeScreenSpaceRenderable(lua_State* L) { using ghoul::lua::errorLocation; std::string name = ghoul::lua::checkStringAndPop(L); - - std::shared_ptr s = OsEng.renderEngine().screenSpaceRenderable( - name - ); - if (!s) { - LERRORC( - "removeScreenSpaceRenderable", - fmt::format( - "{}: Could not find ScreenSpaceRenderable '{}'", errorLocation(L), name - ) - ); - ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); - return 0; - } - - OsEng.renderEngine().removeScreenSpaceRenderable(s); + OsEng.renderEngine().removeScreenSpaceRenderable(name); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); return 0; diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index ac3f8cee77..e29fc2dd7a 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -540,7 +541,7 @@ void ScreenSpaceRenderable::draw(glm::mat4 modelTransform) { _shader->setUniform( _uniformCache.viewProj, - OsEng.renderEngine().camera()->viewProjectionMatrix() + OsEng.renderEngine().scene()->camera()->viewProjectionMatrix() ); ghoul::opengl::TextureUnit unit; diff --git a/src/util/screenlog.cpp b/src/util/screenlog.cpp index e0ce4c8e2e..b0d312d99f 100644 --- a/src/util/screenlog.cpp +++ b/src/util/screenlog.cpp @@ -40,12 +40,11 @@ ScreenLog::~ScreenLog() {} void ScreenLog::removeExpiredEntries() { std::lock_guard guard(_mutex); auto t = std::chrono::steady_clock::now(); - auto ttl = _timeToLive; auto rit = std::remove_if( _entries.begin(), _entries.end(), - [&t, &ttl](const LogEntry& e) { return (t - e.timeStamp) > ttl; } + [&t, ttl = _timeToLive](const LogEntry& e) { return (t - e.timeStamp) > ttl; } ); _entries.erase(rit, _entries.end() ); @@ -64,8 +63,7 @@ void ScreenLog::log(LogLevel level, const string& category, const string& messag } } -std::vector ScreenLog::entries() const { - std::lock_guard guard(_mutex); +const std::vector& ScreenLog::entries() const { return _entries; }