From 11fbff5fbc87912d54f8f3424d199a3ef9476faf Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 16 Feb 2017 16:43:34 -0500 Subject: [PATCH] Reduce the dependency of libOpenSpace on modules - Enable module callbacks for OpenSpaceEngine - Add OpenSpaceModule function that returns a Lua library --- include/openspace/engine/openspaceengine.h | 96 +++++++- include/openspace/util/openspacemodule.h | 8 + modules/iswa/iswamodule.cpp | 13 +- modules/iswa/iswamodule.h | 2 + modules/onscreengui/include/gui.h | 1 - modules/onscreengui/onscreenguimodule.cpp | 149 +++++++++++- modules/onscreengui/onscreenguimodule.h | 6 +- modules/onscreengui/src/gui.cpp | 8 +- modules/onscreengui/src/gui_lua.inl | 6 +- src/engine/openspaceengine.cpp | 251 +++++++++------------ src/util/openspacemodule.cpp | 4 + 11 files changed, 382 insertions(+), 162 deletions(-) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index fcfc69b447..e3b823f2e5 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -92,10 +92,7 @@ public: ghoul::fontrendering::FontManager& fontManager(); DownloadManager& downloadManager(); TimeManager& timeManager(); - -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - gui::GUI& gui(); -#endif + SettingsEngine& settingsEngine(); // SGCT callbacks bool initialize(); @@ -124,6 +121,70 @@ public: void runPostInitializationScripts(const std::string& sceneDescription); + + + // This method is only to be called from Modules + + enum class CallbackOption { + Initialize = 0, // Callback for the end of the initialization + Deinitialize, // Callback for the end of the deinitialization + InitializeGL, // Callback for the end of the OpenGL initialization + DeinitializeGL, // Callback for the end of the OpenGL deinitialization + PreSync, // Callback for the end of the pre-sync function + PostSyncPreDraw, // Callback for the end of the post-sync-pre-draw function + Render, // Callback for the end of the render function + PostDraw // Callback for the end of the post-draw function + }; + + // Registers a callback for a specific CallbackOption + void registerModuleCallback(CallbackOption option, std::function function) { + switch (option) { + case CallbackOption::Initialize: + _moduleCallbacks.initialize.push_back(std::move(function)); + break; + case CallbackOption::Deinitialize: + _moduleCallbacks.deinitialize.push_back(std::move(function)); + break; + case CallbackOption::InitializeGL: + _moduleCallbacks.initializeGL.push_back(std::move(function)); + break; + case CallbackOption::DeinitializeGL: + _moduleCallbacks.deinitializeGL.push_back(std::move(function)); + break; + case CallbackOption::PreSync: + _moduleCallbacks.preSync.push_back(std::move(function)); + break; + case CallbackOption::PostSyncPreDraw: + _moduleCallbacks.postSyncPreDraw.push_back(std::move(function)); + break; + case CallbackOption::Render: + _moduleCallbacks.render.push_back(std::move(function)); + break; + case CallbackOption::PostDraw: + _moduleCallbacks.postDraw.push_back(std::move(function)); + break; + } + } + + // Registers a callback that is called when a new keyboard event is received + void registerModuleKeyboardCallback( + std::function function); + + // Registers a callback that is called when a new character event is received + void registerModuleCharCallback( + std::function function); + + // Registers a callback that is called when a new mouse button is received + void registerModuleMouseButtonCallback( + std::function function); + + // Registers a callback that is called when a new mouse movement is received + void registerModuleMousePositionCallback( + std::function function); + + // Registers a callback that is called when a scroll wheel change is received + void registerModuleMouseScrollWheelCallback(std::function function); + /** * Returns the Lua library that contains all Lua functions available to affect the * application. @@ -155,9 +216,6 @@ private: std::unique_ptr _settingsEngine; std::unique_ptr _timeManager; std::unique_ptr _downloadManager; -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - std::unique_ptr _gui; -#endif std::unique_ptr _parallelConnection; std::unique_ptr _windowWrapper; std::unique_ptr _fontManager; @@ -165,6 +223,30 @@ private: // Others std::unique_ptr _globalPropertyNamespace; + struct { + std::vector> initialize; + std::vector> deinitialize; + + std::vector> initializeGL; + std::vector> deinitializeGL; + + std::vector> preSync; + std::vector> postSyncPreDraw; + std::vector> render; + std::vector> postDraw; + + std::vector> keyboard; + std::vector> character; + + std::vector> mouseButton; + std::vector> mousePosition; + std::vector> mouseScrollWheel; + + + + + } _moduleCallbacks; + bool _isMaster; double _runTime; diff --git a/include/openspace/util/openspacemodule.h b/include/openspace/util/openspacemodule.h index a88cae8a6e..992bd8459d 100644 --- a/include/openspace/util/openspacemodule.h +++ b/include/openspace/util/openspacemodule.h @@ -28,6 +28,7 @@ #include #include +#include #include @@ -73,6 +74,13 @@ public: * \return A list of Documentation classes that are valid for this OpenSapceModule */ virtual std::vector documentations() const; + + /** + * Returns the Lua library with functions defined by this OpenSpaceModule. The default + * implementation returns an empty library. + * \return The Lua library with functions defined by this OpenSpaceModule + */ + virtual scripting::LuaLibrary luaLibrary() const; /** * Returns the minimum required OpenGL version of this OpenSpaceModule. Unless diff --git a/modules/iswa/iswamodule.cpp b/modules/iswa/iswamodule.cpp index 6c7d5e7ceb..e9c1b5004b 100644 --- a/modules/iswa/iswamodule.cpp +++ b/modules/iswa/iswamodule.cpp @@ -40,7 +40,18 @@ namespace openspace { IswaModule::IswaModule() : OpenSpaceModule("ISWA") -{} +{ + OsEng.registerModuleCallback( + OpenSpaceEngine::CallbackOption::Initialize, + [](){ + IswaManager::initialize(); + } + ); +} + +scripting::LuaLibrary IswaModule::luaLibrary() const { + return IswaManager::luaLibrary(); +} void IswaModule::internalInitialize(){ auto fRenderable = FactoryManager::ref().factory(); diff --git a/modules/iswa/iswamodule.h b/modules/iswa/iswamodule.h index e337a2facb..6b92f37634 100644 --- a/modules/iswa/iswamodule.h +++ b/modules/iswa/iswamodule.h @@ -32,6 +32,8 @@ class IswaModule : public OpenSpaceModule { public: IswaModule(); + + scripting::LuaLibrary luaLibrary() const override; protected: void internalInitialize() override; diff --git a/modules/onscreengui/include/gui.h b/modules/onscreengui/include/gui.h index 6e8e688aa1..e1b3b45484 100644 --- a/modules/onscreengui/include/gui.h +++ b/modules/onscreengui/include/gui.h @@ -44,7 +44,6 @@ namespace gui { class GUI : public GuiComponent { public: GUI(); - ~GUI(); void initialize(); void deinitialize(); diff --git a/modules/onscreengui/onscreenguimodule.cpp b/modules/onscreengui/onscreenguimodule.cpp index 88636efe39..0a42166833 100644 --- a/modules/onscreengui/onscreenguimodule.cpp +++ b/modules/onscreengui/onscreenguimodule.cpp @@ -27,13 +27,158 @@ #include #include +#include +#include +#include +#include +#include + +#include namespace openspace { +gui::GUI OnScreenGUIModule::gui; + OnScreenGUIModule::OnScreenGUIModule() : OpenSpaceModule("OnScreenGUI") { - addPropertySubOwner(OsEng.gui()); -} + addPropertySubOwner(gui); + + OsEng.registerModuleCallback( + OpenSpaceEngine::CallbackOption::Initialize, + [](){ + LDEBUGC("OnScreenGUIModule", "Initializing GUI"); + gui.initialize(); + + gui._globalProperty.setSource( + []() { + std::vector res = { + &(OsEng.settingsEngine()), + &(OsEng.interactionHandler()), + &(OsEng.renderEngine()) + }; + return res; + } + ); + + gui._screenSpaceProperty.setSource( + []() { + const auto& ssr = OsEng.renderEngine().screenSpaceRenderables(); + return std::vector(ssr.begin(), ssr.end()); + } + ); + + gui._property.setSource( + []() { + const auto& nodes = OsEng.renderEngine().scene()->allSceneGraphNodes(); + return std::vector(nodes.begin(), nodes.end()); + } + ); + } + ); + + OsEng.registerModuleCallback( + OpenSpaceEngine::CallbackOption::Deinitialize, + [](){ + LDEBUGC("OnScreenGui", "Deinitialize GUI"); + gui.deinitialize(); + } + ); + + OsEng.registerModuleCallback( + OpenSpaceEngine::CallbackOption::InitializeGL, + [](){ + LDEBUGC("OnScreenGui", "Initializing GUI OpenGL"); + gui.initializeGL(); + } + ); + + OsEng.registerModuleCallback( + OpenSpaceEngine::CallbackOption::DeinitializeGL, + [](){ + LDEBUGC("OnScreenGui", "Deinitialize GUI OpenGL"); + gui.deinitializeGL(); + } + ); + OsEng.registerModuleCallback( + OpenSpaceEngine::CallbackOption::PostSyncPreDraw, + [](){ + WindowWrapper& wrapper = OsEng.windowWrapper(); + if (OsEng.isMaster() && wrapper.isRegularRendering()) { + glm::vec2 mousePosition = wrapper.mousePosition(); + //glm::ivec2 drawBufferResolution = _windowWrapper->currentDrawBufferResolution(); + glm::ivec2 windowSize = wrapper.currentWindowSize(); + glm::ivec2 renderingSize = wrapper.currentWindowResolution(); + uint32_t mouseButtons = wrapper.mouseButtons(2); + + double dt = std::max(wrapper.averageDeltaTime(), 0.0); + + gui.startFrame( + static_cast(dt), + glm::vec2(windowSize), + wrapper.dpiScaling(), + mousePosition, + mouseButtons + ); + } + } + ); + + OsEng.registerModuleCallback( + OpenSpaceEngine::CallbackOption::PostDraw, + [](){ + WindowWrapper& wrapper = OsEng.windowWrapper(); + bool showGui = wrapper.hasGuiWindow() ? wrapper.isGuiWindow() : true; + if (OsEng.isMaster() && wrapper.isRegularRendering() && showGui) { + gui.endFrame(); + } + } + ); + + OsEng.registerModuleKeyboardCallback( + [](Key key, KeyModifier mod, KeyAction action) -> bool { + if (gui.isEnabled()) { + return gui.keyCallback(key, mod, action); + } + else { + return false; + } + } + ); + + OsEng.registerModuleCharCallback( + [](unsigned int codepoint, KeyModifier modifier) -> bool { + if (gui.isEnabled()) { + return gui.charCallback(codepoint, modifier); + } + else { + return false; + } + } + ); + + OsEng.registerModuleMouseButtonCallback( + [](MouseButton button, MouseAction action) -> bool { + if (gui.isEnabled()) { + return gui.mouseButtonCallback(button, action); + } + else { + return false; + } + } + ); + + OsEng.registerModuleMouseScrollWheelCallback( + [](double pos) -> bool { + if (gui.isEnabled()) { + return gui.mouseWheelCallback(pos); + } + else { + return false; + } + } + ); +} + } // namespace openspace diff --git a/modules/onscreengui/onscreenguimodule.h b/modules/onscreengui/onscreenguimodule.h index 80d7e76753..6576843c68 100644 --- a/modules/onscreengui/onscreenguimodule.h +++ b/modules/onscreengui/onscreenguimodule.h @@ -27,11 +27,15 @@ #include -namespace openspace { +#include +namespace openspace { + class OnScreenGUIModule : public OpenSpaceModule { public: OnScreenGUIModule(); + + static gui::GUI gui; }; } // namespace openspace diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index 874b457f46..6fa3417705 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -24,6 +24,8 @@ #include +#include + #include #include #include @@ -237,10 +239,6 @@ GUI::GUI() addPropertySubOwner(_iswa); } -GUI::~GUI() { - ImGui::Shutdown(); -} - void GUI::initialize() { std::string cachedFile = FileSys.cacheManager()->cachedFilename( configurationFile, "", ghoul::filesystem::CacheManager::Persistent::Yes @@ -322,6 +320,8 @@ void GUI::initialize() { } void GUI::deinitialize() { + ImGui::Shutdown(); + _iswa.deinitialize(); _help.deinitialize(); _performance.deinitialize(); diff --git a/modules/onscreengui/src/gui_lua.inl b/modules/onscreengui/src/gui_lua.inl index 0c20aa07bd..9155ba5d2e 100644 --- a/modules/onscreengui/src/gui_lua.inl +++ b/modules/onscreengui/src/gui_lua.inl @@ -39,7 +39,7 @@ int show(lua_State* L) { return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments); } - OsEng.gui().setEnabled(true); + OnScreenGUIModule::gui.setEnabled(true); return 0; } @@ -54,7 +54,7 @@ int hide(lua_State* L) { return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments); } - OsEng.gui().setEnabled(false); + OnScreenGUIModule::gui.setEnabled(false); return 0; } @@ -69,7 +69,7 @@ int toggle(lua_State* L) { return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments); } - OsEng.gui().setEnabled(!OsEng.gui().isEnabled()); + OnScreenGUIModule::gui.setEnabled(!OnScreenGUIModule::gui.isEnabled()); return 0; } diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 773b034e8c..65db037815 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -75,15 +75,6 @@ #include #include -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED -#include -#endif - -#ifdef OPENSPACE_MODULE_ISWA_ENABLED -#include -#include -#endif - #if defined(_MSC_VER) && defined(OPENSPACE_ENABLE_VLD) #include #endif @@ -145,9 +136,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, , _settingsEngine(new SettingsEngine) , _timeManager(new TimeManager) , _downloadManager(nullptr) -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - , _gui(new gui::GUI) -#endif , _parallelConnection(new ParallelConnection) , _windowWrapper(std::move(windowWrapper)) , _globalPropertyNamespace(new properties::PropertyOwner) @@ -189,9 +177,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, OpenSpaceEngine::~OpenSpaceEngine() { LINFO("_windowWrapper->isUsingSwapGroups(): " << _windowWrapper->isUsingSwapGroups()); LINFO("_windowWrapper->isSwapGroupMaster(): " << _windowWrapper->isSwapGroupMaster()); -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - _gui->deinitializeGL(); -#endif _interactionHandler->deinitialize(); _renderEngine->deinitialize(); @@ -208,9 +193,6 @@ OpenSpaceEngine::~OpenSpaceEngine() { _console = nullptr; _moduleEngine = nullptr; _settingsEngine = nullptr; -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - _gui = nullptr; -#endif } OpenSpaceEngine& OpenSpaceEngine::ref() { @@ -400,6 +382,14 @@ bool OpenSpaceEngine::create(int argc, char** argv, } void OpenSpaceEngine::destroy() { + for (const auto& func : _engine->_moduleCallbacks.deinitializeGL) { + func(); + } + + for (const auto& func : _engine->_moduleCallbacks.deinitialize) { + func(); + } + _engine->_moduleEngine->deinitialize(); _engine->_console->deinitialize(); @@ -471,11 +461,11 @@ bool OpenSpaceEngine::initialize() { // Register Lua script functions LDEBUG("Registering Lua libraries"); registerCoreClasses(*_scriptEngine); - -#ifdef OPENSPACE_MODULE_ISWA_ENABLED - _scriptEngine->addLibrary(IswaManager::luaLibrary()); -#endif - + + for (OpenSpaceModule* module : _moduleEngine->modules()) { + _scriptEngine->addLibrary(module->luaLibrary()); + } + // TODO: Maybe move all scenegraph and renderengine stuff to initializeGL scriptEngine().initialize(); @@ -518,6 +508,10 @@ bool OpenSpaceEngine::initialize() { _renderEngine->initialize(); _renderEngine->setGlobalBlackOutFactor(0.0); _renderEngine->startFading(1, 3.0); + + for (const auto& func : _moduleCallbacks.initialize) { + func(); + } // Run start up scripts try { @@ -527,58 +521,6 @@ bool OpenSpaceEngine::initialize() { LFATALC(e.component, e.message); } -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - LINFO("Initializing GUI"); - _gui->initialize(); - _gui->_globalProperty.setSource( - [&]() { - std::vector res = { - _settingsEngine.get(), - _interactionHandler.get(), - _renderEngine.get() - }; - return res; - } - ); - - OsEng.gui()._screenSpaceProperty.setSource( - [&]() { - const auto& ssr = renderEngine().screenSpaceRenderables(); - return std::vector(ssr.begin(), ssr.end()); - } - ); - - OsEng.gui()._property.setSource( - [&]() { - const auto& nodes = renderEngine().scene()->allSceneGraphNodes(); - return std::vector(nodes.begin(), nodes.end()); - } - ); - -#ifdef OPENSPACE_MODULE_ISWA_ENABLED - OsEng.gui()._iswa.setSource( - [&]() { - const auto& groups = IswaManager::ref().groups(); - std::vector res; - std::transform( - groups.begin(), - groups.end(), - std::back_inserter(res), - [](const auto& val) { - return val.second.get(); - } - ); - return res; - } - ); -#endif - -#endif - -#ifdef OPENSPACE_MODULE_ISWA_ENABLED - IswaManager::initialize(); -#endif - _syncEngine->addSyncables(Time::ref().getSyncables()); _syncEngine->addSyncables(_renderEngine->getSyncables()); _syncEngine->addSyncable(_scriptEngine.get()); @@ -850,15 +792,11 @@ void OpenSpaceEngine::configureLogging() { bool OpenSpaceEngine::initializeGL() { LINFO("Initializing Rendering Engine"); bool success = _renderEngine->initializeGL(); -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - LINFO("Initializing OnScreen GUI GL"); - try { - _gui->initializeGL(); + + for (const auto& func : _moduleCallbacks.initializeGL) { + func(); } - catch (const ghoul::RuntimeError& e) { - LERROR(e.what()); - } -#endif + LINFO("Finished initializing OpenGL"); // If using swapgroups, @@ -867,19 +805,19 @@ bool OpenSpaceEngine::initializeGL() { return success; } -bool OpenSpaceEngine::isMaster(){ +bool OpenSpaceEngine::isMaster() { return _isMaster; } -void OpenSpaceEngine::setMaster(bool master){ +void OpenSpaceEngine::setMaster(bool master) { _isMaster = master; } -double OpenSpaceEngine::runTime(){ +double OpenSpaceEngine::runTime() { return _runTime; } -void OpenSpaceEngine::setRunTime(double d){ +void OpenSpaceEngine::setRunTime(double d) { _runTime = d; } @@ -911,6 +849,10 @@ void OpenSpaceEngine::preSynchronization() { _parallelConnection->preSynchronization(); } + + for (const auto& func : _moduleCallbacks.preSync) { + func(); + } } void OpenSpaceEngine::postSynchronizationPreDraw() { @@ -936,26 +878,10 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { // Step the camera using the current mouse velocities which are synced //_interactionHandler->updateCamera(); -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - if (_isMaster && _windowWrapper->isRegularRendering()) { - glm::vec2 mousePosition = _windowWrapper->mousePosition(); - //glm::ivec2 drawBufferResolution = _windowWrapper->currentDrawBufferResolution(); - glm::ivec2 windowSize = _windowWrapper->currentWindowSize(); - glm::ivec2 renderingSize = _windowWrapper->currentWindowResolution(); - uint32_t mouseButtons = _windowWrapper->mouseButtons(2); - - double dt = std::max(_windowWrapper->averageDeltaTime(), 0.0); - - _gui->startFrame( - static_cast(dt), - glm::vec2(windowSize), - _windowWrapper->dpiScaling(), - mousePosition, - mouseButtons - ); + for (const auto& func : _moduleCallbacks.postSyncPreDraw) { + func(); } -#endif - + // Testing this every frame has minimal impact on the performance --- abock // Debug build: 1-2 us ; Release build: <= 1 us using ghoul::logging::LogManager; @@ -963,35 +889,42 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { int errorCounter = LogMgr.messageCounter(LogLevel::Error); int fatalCounter = LogMgr.messageCounter(LogLevel::Fatal); - if (warningCounter > 0) + if (warningCounter > 0) { LWARNINGC("Logging", "Number of Warnings raised: " << warningCounter); - if (errorCounter > 0) + } + if (errorCounter > 0) { LWARNINGC("Logging", "Number of Errors raised: " << errorCounter); - if (fatalCounter > 0) + } + if (fatalCounter > 0) { LWARNINGC("Logging", "Number of Fatals raised: " << fatalCounter); + } LogMgr.resetMessageCounters(); - } void OpenSpaceEngine::render(const glm::mat4& projectionMatrix, const glm::mat4& viewMatrix) { LTRACE("OpenSpaceEngine::render(begin)"); _renderEngine->render(projectionMatrix, viewMatrix); + + for (const auto& func : _moduleCallbacks.render) { + func(); + } + LTRACE("OpenSpaceEngine::render(end)"); } void OpenSpaceEngine::postDraw() { _renderEngine->postDraw(); + for (const auto& func : _moduleCallbacks.postDraw) { + func(); + } + bool showGui = _windowWrapper->hasGuiWindow() ? _windowWrapper->isGuiWindow() : true; if (showGui) { _renderEngine->renderScreenLog(); if (_console->isVisible()) _console->render(); -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - if (_isMaster && _windowWrapper->isRegularRendering()) - _gui->endFrame(); -#endif } if (_isInShutdownMode) { @@ -1007,14 +940,13 @@ void OpenSpaceEngine::postDraw() { void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) { if (_isMaster) { -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - if (_gui->isEnabled()) { - bool isConsumed = _gui->keyCallback(key, mod, action); - if (isConsumed) { + for (const auto& func : _moduleCallbacks.keyboard) { + bool consumed = func(key, mod, action); + if (consumed) { return; } } -#endif + if (key == _console->commandInputButton()) { if (action == KeyAction::Press) { _console->toggleMode(); @@ -1029,13 +961,13 @@ void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction actio void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier) { if (_isMaster) { -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - if (_gui->isEnabled()) { - const bool isConsumed = _gui->charCallback(codepoint, modifier); - if (isConsumed) + for (const auto& func : _moduleCallbacks.character) { + bool consumed = func(codepoint, modifier); + if (consumed) { return; + } } -#endif + if (_console->isVisible()) { _console->charCallback(codepoint, modifier); } @@ -1044,32 +976,36 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier) void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action) { if (_isMaster) { -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - if (_gui->isEnabled()) { - const bool isConsumed = _gui->mouseButtonCallback(button, action); - if (isConsumed /*&& action != MouseAction::Release*/) + for (const auto& func : _moduleCallbacks.mouseButton) { + bool consumed = func(button, action); + if (consumed) { return; + } } -#endif + _interactionHandler->mouseButtonCallback(button, action); } } void OpenSpaceEngine::mousePositionCallback(double x, double y) { if (_isMaster) { + for (const auto& func : _moduleCallbacks.mousePosition) { + func(x, y); + } + _interactionHandler->mousePositionCallback(x, y); } } void OpenSpaceEngine::mouseScrollWheelCallback(double pos) { if (_isMaster) { -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED - if (_gui->isEnabled()) { - const bool isConsumed = _gui->mouseWheelCallback(pos); - if (isConsumed) + for (const auto& func : _moduleCallbacks.mouseScrollWheel) { + bool consumed = func(pos); + if (consumed) { return; + } } -#endif + _interactionHandler->mouseScrollWheelCallback(pos); } } @@ -1088,8 +1024,9 @@ void OpenSpaceEngine::decode() { void OpenSpaceEngine::externalControlCallback(const char* receivedChars, int size, int clientId) { - if (size == 0) + if (size == 0) { return; + } _networkEngine->handleMessage(std::string(receivedChars, size)); } @@ -1144,6 +1081,37 @@ void OpenSpaceEngine::enableBarrier() { void OpenSpaceEngine::disableBarrier() { _windowWrapper->setBarrier(false); } + + +void OpenSpaceEngine::registerModuleKeyboardCallback( + std::function function) +{ + _moduleCallbacks.keyboard.push_back(std::move(function)); +} + +void OpenSpaceEngine::registerModuleCharCallback( + std::function function) +{ + _moduleCallbacks.character.push_back(std::move(function)); +} + +void OpenSpaceEngine::registerModuleMouseButtonCallback( + std::function function) +{ + _moduleCallbacks.mouseButton.push_back(std::move(function)); +} + +void OpenSpaceEngine::registerModuleMousePositionCallback( + std::function function) +{ + _moduleCallbacks.mousePosition.push_back(std::move(function)); +} + +void OpenSpaceEngine::registerModuleMouseScrollWheelCallback( + std::function function) +{ + _moduleCallbacks.mouseScrollWheel.push_back(std::move(function)); +} NetworkEngine& OpenSpaceEngine::networkEngine() { ghoul_assert(_networkEngine, "NetworkEngine must not be nullptr"); @@ -1185,13 +1153,6 @@ LuaConsole& OpenSpaceEngine::console() { return *_console; } -#ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED -gui::GUI& OpenSpaceEngine::gui() { - ghoul_assert(_gui, "GUI must not be nullptr"); - return *_gui; -} -#endif - ParallelConnection& OpenSpaceEngine::parallelConnection() { ghoul_assert(_parallelConnection, "ParallelConnection must not be nullptr"); return *_parallelConnection; @@ -1224,6 +1185,10 @@ TimeManager& OpenSpaceEngine::timeManager() { ghoul_assert(_timeManager, "Download Manager must not be nullptr"); return *_timeManager; } - + +SettingsEngine& OpenSpaceEngine::settingsEngine() { + ghoul_assert(_settingsEngine, "Settings Engine must not be nullptr"); + return *_settingsEngine; +} } // namespace openspace diff --git a/src/util/openspacemodule.cpp b/src/util/openspacemodule.cpp index 9482490ba5..fd64783648 100644 --- a/src/util/openspacemodule.cpp +++ b/src/util/openspacemodule.cpp @@ -66,6 +66,10 @@ void OpenSpaceModule::deinitialize() { std::vector OpenSpaceModule::documentations() const { return {}; } + +scripting::LuaLibrary OpenSpaceModule::luaLibrary() const { + return {}; +} ghoul::systemcapabilities::OpenGLCapabilitiesComponent::Version OpenSpaceModule::requiredOpenGLVersion() const