From 5456b5ee8539a464bc468c485ebcc4cd0e90d224 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 25 Oct 2015 13:50:39 -0500 Subject: [PATCH] Started change moving from explicit SGCT functions to wrapper class --- apps/OpenSpace/main.cpp | 4 +- include/openspace/engine/openspaceengine.h | 10 +-- .../{sgctwindow.h => sgctwindowhandler.h} | 20 +++-- .../engine/{window.h => windowhandler.h} | 21 +++++- src/CMakeLists.txt | 8 +- src/engine/openspaceengine.cpp | 41 ++++------- src/engine/sgctwindowhandler.cpp | 73 +++++++++++++++++++ src/engine/window.cpp | 0 .../{sgctwindow.cpp => windowhandler.cpp} | 0 9 files changed, 133 insertions(+), 44 deletions(-) rename include/openspace/engine/{sgctwindow.h => sgctwindowhandler.h} (80%) rename include/openspace/engine/{window.h => windowhandler.h} (81%) create mode 100644 src/engine/sgctwindowhandler.cpp delete mode 100644 src/engine/window.cpp rename src/engine/{sgctwindow.cpp => windowhandler.cpp} (100%) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 626f379290..cbac1f3d1a 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -23,7 +23,7 @@ ****************************************************************************************/ #include -#include +#include #include #include #include @@ -87,7 +87,7 @@ int main(int argc, char** argv) { std::vector sgctArguments; const bool success = openspace::OpenSpaceEngine::create( argc, argv, - new openspace::SGCTWindow, + new openspace::SGCTWindowHandler, sgctArguments ); if (!success) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index db100da693..315b92f020 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -46,7 +46,7 @@ class GUI; class RenderEngine; class SyncBuffer; class ModuleEngine; -class Window; +class WindowHandler; namespace interaction { class InteractionHandler; @@ -68,7 +68,7 @@ namespace properties { class OpenSpaceEngine { public: - static bool create(int argc, char** argv, Window* windowHandler, std::vector& sgctArguments); + static bool create(int argc, char** argv, WindowHandler* windowHandler, std::vector& sgctArguments); static void destroy(); static OpenSpaceEngine& ref(); @@ -90,7 +90,7 @@ public: ModuleEngine* moduleEngine(); network::ParallelConnection* parallelConnection(); properties::PropertyOwner* globalPropertyOwner(); - Window* windowWrapper(); + WindowHandler* windowWrapper(); gui::GUI* gui(); @@ -115,7 +115,7 @@ public: void runSettingsScripts(); private: - OpenSpaceEngine(std::string programName, Window* windowHandler); + OpenSpaceEngine(std::string programName, WindowHandler* windowHandler); ~OpenSpaceEngine(); OpenSpaceEngine(const OpenSpaceEngine& rhs) = delete; @@ -139,7 +139,7 @@ private: ModuleEngine* _moduleEngine; gui::GUI* _gui; network::ParallelConnection* _parallelConnection; - Window* _windowWrapper; + WindowHandler* _windowHandler; properties::PropertyOwner* _globalPropertyNamespace; diff --git a/include/openspace/engine/sgctwindow.h b/include/openspace/engine/sgctwindowhandler.h similarity index 80% rename from include/openspace/engine/sgctwindow.h rename to include/openspace/engine/sgctwindowhandler.h index 6d65802d21..271e689789 100644 --- a/include/openspace/engine/sgctwindow.h +++ b/include/openspace/engine/sgctwindowhandler.h @@ -22,18 +22,28 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __SGCTWINDOW_H__ -#define __SGCTWINDOW_H__ +#ifndef __SGCTWINDOWHANDLER_H__ +#define __SGCTWINDOWHANDLER_H__ -#include +#include namespace openspace { -class SGCTWindow : public Window { +class SGCTWindowHandler : public WindowHandler { public: + void setBarrier(bool enabled) override; + void clearAllWindows() override; + + double averageDeltaTime() override; + glm::vec2 mousePosition() override; + glm::ivec2 currentWindowSize() override; + glm::ivec2 currentWindowResolution() override; + + + // void forEachWindow(std::function function) override; }; } // namespace openspace -#endif // __SGCTWINDOW_H__ +#endif // __SGCTWINDOWHANDLER_H__ diff --git a/include/openspace/engine/window.h b/include/openspace/engine/windowhandler.h similarity index 81% rename from include/openspace/engine/window.h rename to include/openspace/engine/windowhandler.h index 323b9b4511..19119d8bc6 100644 --- a/include/openspace/engine/window.h +++ b/include/openspace/engine/windowhandler.h @@ -22,14 +22,29 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __WINDOW_H__ -#define __WINDOW_H__ +#ifndef __WINDOWHANDLER_H__ +#define __WINDOWHANDLER_H__ + +#include + +#include namespace openspace { -class Window { +class WindowHandler { public: + virtual void setBarrier(bool enabled) = 0; + virtual void clearAllWindows() = 0; + virtual double averageDeltaTime() = 0; + virtual glm::vec2 mousePosition() = 0; + virtual glm::ivec2 currentWindowSize() = 0; + virtual glm::ivec2 currentWindowResolution() = 0; + + + + //virtual void forEachWindow(std::function function) = 0; + }; } // namespace openspace diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 764e069b86..f4e59f7eac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,9 +33,9 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/engine/downloadmanager.cpp ${OPENSPACE_BASE_DIR}/src/engine/logfactory.cpp ${OPENSPACE_BASE_DIR}/src/engine/moduleengine.cpp - ${OPENSPACE_BASE_DIR}/src/engine/sgctwindow.cpp + ${OPENSPACE_BASE_DIR}/src/engine/sgctwindowhandler.cpp ${OPENSPACE_BASE_DIR}/src/engine/openspaceengine.cpp - ${OPENSPACE_BASE_DIR}/src/engine/window.cpp + ${OPENSPACE_BASE_DIR}/src/engine/windowhandler.cpp ${OPENSPACE_BASE_DIR}/src/interaction/controller.cpp ${OPENSPACE_BASE_DIR}/src/interaction/deviceidentifier.cpp ${OPENSPACE_BASE_DIR}/src/interaction/interactionhandler.cpp @@ -99,9 +99,9 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/engine/downloadmanager.h ${OPENSPACE_BASE_DIR}/include/openspace/engine/logfactory.h ${OPENSPACE_BASE_DIR}/include/openspace/engine/moduleengine.h - ${OPENSPACE_BASE_DIR}/include/openspace/engine/sgctwindow.h + ${OPENSPACE_BASE_DIR}/include/openspace/engine/sgctwindowhandler.h ${OPENSPACE_BASE_DIR}/include/openspace/engine/openspaceengine.h - ${OPENSPACE_BASE_DIR}/include/openspace/engine/window.h + ${OPENSPACE_BASE_DIR}/include/openspace/engine/windowhandler.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/controller.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/deviceidentifier.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/interactionhandler.h diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 859af4b274..e534d36071 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -101,7 +102,7 @@ namespace openspace { OpenSpaceEngine* OpenSpaceEngine::_engine = nullptr; -OpenSpaceEngine::OpenSpaceEngine(std::string programName, Window* windowHandler) +OpenSpaceEngine::OpenSpaceEngine(std::string programName, WindowHandler* windowHandler) : _configurationManager(new ConfigurationManager) , _interactionHandler(new interaction::InteractionHandler) , _renderEngine(new RenderEngine) @@ -112,7 +113,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, Window* windowHandler) , _moduleEngine(new ModuleEngine) , _gui(new gui::GUI) , _parallelConnection(new network::ParallelConnection) - , _windowWrapper(windowHandler) + , _windowHandler(windowHandler) , _globalPropertyNamespace(new properties::PropertyOwner) , _isMaster(false) , _runTime(0.0) @@ -132,8 +133,8 @@ OpenSpaceEngine::~OpenSpaceEngine() { delete _globalPropertyNamespace; _globalPropertyNamespace = nullptr; - delete _windowWrapper; - _windowWrapper = nullptr; + delete _windowHandler; + _windowHandler = nullptr; delete _parallelConnection; _parallelConnection = nullptr; @@ -176,7 +177,7 @@ OpenSpaceEngine& OpenSpaceEngine::ref() { bool OpenSpaceEngine::create( int argc, char** argv, - Window* windowHandler, + WindowHandler* windowHandler, std::vector& sgctArguments) { ghoul::initialize(); @@ -422,13 +423,7 @@ bool OpenSpaceEngine::isInitialized() { } void OpenSpaceEngine::clearAllWindows() { - size_t n = sgct::Engine::instance()->getNumberOfWindows(); - for (size_t i = 0; i < n; ++i) { - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - GLFWwindow* win = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle(); - glfwSwapBuffers(win); - } + _windowHandler->clearAllWindows(); } bool OpenSpaceEngine::gatherCommandlineArguments() { @@ -672,8 +667,7 @@ void OpenSpaceEngine::setRunTime(double d){ void OpenSpaceEngine::preSynchronization() { FileSys.triggerFilesystemEvents(); if (_isMaster) { - //const double dt = sgct::Engine::instance()->getDt(); - const double dt = sgct::Engine::instance()->getAvgDt(); + double dt = _windowHandler->averageDeltaTime(); Time::ref().advanceTime(dt); Time::ref().preSynchronization(); @@ -696,18 +690,15 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { if (_isMaster && _gui->isEnabled()) { - double posX, posY; - sgct::Engine::instance()->getMousePos(0, &posX, &posY); - - int x,y; - sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y); + glm::vec2 mousePosition = _windowHandler->mousePosition(); + glm::ivec2 windowResolution = _windowHandler->currentWindowResolution(); int button0 = sgct::Engine::instance()->getMouseButton(0, 0); int button1 = sgct::Engine::instance()->getMouseButton(0, 1); bool buttons[2] = { button0 != 0, button1 != 0 }; double dt = std::max(sgct::Engine::instance()->getDt(), 1.0/60.0); - _gui->startFrame(static_cast(dt), glm::vec2(glm::ivec2(x,y)), glm::vec2(posX, posY), buttons); + _gui->startFrame(static_cast(dt), glm::vec2(windowResolution), mousePosition, buttons); } } @@ -831,11 +822,11 @@ void OpenSpaceEngine::externalControlCallback(const char* receivedChars, } void OpenSpaceEngine::enableBarrier() { - sgct::SGCTWindow::setBarrier(true); + _windowHandler->setBarrier(true); } void OpenSpaceEngine::disableBarrier() { - sgct::SGCTWindow::setBarrier(false); + _windowHandler->setBarrier(false); } NetworkEngine* OpenSpaceEngine::networkEngine() { @@ -856,9 +847,9 @@ properties::PropertyOwner* OpenSpaceEngine::globalPropertyOwner() { return _globalPropertyNamespace; } -Window* OpenSpaceEngine::windowWrapper() { - ghoul_assert(_windowWrapper, "Window Wrapper"); - return _windowWrapper; +WindowHandler* OpenSpaceEngine::windowWrapper() { + ghoul_assert(_windowHandler, "Window Wrapper"); + return _windowHandler; } } // namespace openspace diff --git a/src/engine/sgctwindowhandler.cpp b/src/engine/sgctwindowhandler.cpp new file mode 100644 index 0000000000..f60af53d05 --- /dev/null +++ b/src/engine/sgctwindowhandler.cpp @@ -0,0 +1,73 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include +#include "sgct.h" + +#include + +namespace openspace { + +void SGCTWindowHandler::setBarrier(bool enabled) { + sgct::SGCTWindow::setBarrier(enabled); +} + +void SGCTWindowHandler::clearAllWindows() { + size_t n = sgct::Engine::instance()->getNumberOfWindows(); + for (size_t i = 0; i < n; ++i) { + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + GLFWwindow* win = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle(); + glfwSwapBuffers(win); + } +} + +double SGCTWindowHandler::averageDeltaTime() { + return sgct::Engine::instance()->getAvgDt(); +} + +glm::vec2 SGCTWindowHandler::mousePosition() { + double posX, posY; + sgct::Engine::instance()->getMousePos(0, &posX, &posY); + return glm::vec2(posX, posY); +} + +glm::ivec2 SGCTWindowHandler::currentWindowSize() { + return glm::ivec2(0); +} + +glm::ivec2 SGCTWindowHandler::currentWindowResolution() { + int x,y; + sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y); + return glm::ivec2(x, y); +} + +//void forEachWindow(std::function function) { +// size_t n = sgct::Engine::instance()->getNumberOfWindows(); +// for (size_t i = 0; i < n; ++i) +// function(); +//} + +} // namespace openspace + diff --git a/src/engine/window.cpp b/src/engine/window.cpp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/engine/sgctwindow.cpp b/src/engine/windowhandler.cpp similarity index 100% rename from src/engine/sgctwindow.cpp rename to src/engine/windowhandler.cpp