From 269dda8aff803cbae10a4b23a2e4b675243d2b63 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 24 Oct 2017 01:33:53 -0700 Subject: [PATCH] Remove runTime from OpenSpaceEngine and place in WindowWrapper instead --- apps/OpenSpace/main.cpp | 1 - include/openspace/engine/openspaceengine.h | 5 -- .../engine/wrapper/sgctwindowwrapper.h | 1 + .../openspace/engine/wrapper/windowwrapper.h | 7 +++ src/engine/openspaceengine.cpp | 55 ++++++------------- src/engine/wrapper/sgctwindowwrapper.cpp | 50 ++++++++--------- src/engine/wrapper/windowwrapper.cpp | 28 ++++++---- src/interaction/keyframenavigator.cpp | 3 +- src/network/parallelconnection.cpp | 8 +-- src/util/timemanager.cpp | 4 +- 10 files changed, 74 insertions(+), 88 deletions(-) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index b17adaa7b4..3bc0f706c2 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -313,7 +313,6 @@ void mainInitFunc() { void mainPreSyncFunc() { LTRACE("main::mainPreSyncFunc(begin)"); - OsEng.setRunTime(sgct::Engine::getTime()); OsEng.preSynchronization(); LTRACE("main::mainPreSyncFunc(end)"); } diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index ac079ad893..8d3c82269d 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -79,9 +79,6 @@ public: static OpenSpaceEngine& ref(); static bool isCreated(); - double runTime(); - void setRunTime(double t); - // callbacks void initialize(); void initializeGL(); @@ -234,8 +231,6 @@ private: std::vector> mouseScrollWheel; } _moduleCallbacks; - double _runTime; - // Structure that is responsible for the delayed shutdown of the application struct { // Whether the application is currently in shutdown mode (i.e. counting down the diff --git a/include/openspace/engine/wrapper/sgctwindowwrapper.h b/include/openspace/engine/wrapper/sgctwindowwrapper.h index 7dc3db262b..d106ce400d 100644 --- a/include/openspace/engine/wrapper/sgctwindowwrapper.h +++ b/include/openspace/engine/wrapper/sgctwindowwrapper.h @@ -49,6 +49,7 @@ public: double averageDeltaTime() const override; double deltaTime() const override; + double applicationTime() const override; glm::vec2 mousePosition() const override; uint32_t mouseButtons(int maxNumber) const override; glm::ivec2 currentWindowSize() const override; diff --git a/include/openspace/engine/wrapper/windowwrapper.h b/include/openspace/engine/wrapper/windowwrapper.h index 252eb4258a..23713c50de 100644 --- a/include/openspace/engine/wrapper/windowwrapper.h +++ b/include/openspace/engine/wrapper/windowwrapper.h @@ -106,6 +106,13 @@ public: */ virtual double deltaTime() const; + /** + * Returns the time that has passed (in seconds) since application start + * \return The time that has passed (in seconds) since application start + * @return [description] + */ + virtual double applicationTime() const; + /** * Returns the location of the mouse cursor in pixel screen coordinates. On default, * this method returns 0,0. diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index ce3cf6629c..eef2fcbd66 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -165,7 +165,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, } , _scheduledSceneSwitch(false) , _scenePath("") - , _runTime(0.0) , _shutdown({false, 0.f, 0.f}) , _isFirstRenderingFirstFrame(true) { @@ -321,23 +320,17 @@ void OpenSpaceEngine::create(int argc, char** argv, ConfigurationManager::KeyPerSceneCache ); std::string cacheFolder = absPath("${CACHE}"); - if (hasCacheCommandline) { - cacheFolder = commandlineArgumentPlaceholders.cacheFolder; - // @CLEANUP: Why is this commented out? ---abock - //FileSys.registerPathToken( - // "${CACHE}", - // commandlineArgumentPlaceholders.cacheFolder, - // ghoul::filesystem::FileSystem::Override::Yes - //); - } - if (hasCacheConfiguration) { - std::string scene = _engine->configurationManager().value( - ConfigurationManager::KeyConfigScene - ); - cacheFolder += "-" + ghoul::filesystem::File(scene).baseName(); - } - if (hasCacheCommandline || hasCacheConfiguration) { + if (hasCacheCommandline) { + cacheFolder = commandlineArgumentPlaceholders.cacheFolder; + } + if (hasCacheConfiguration) { + std::string scene = _engine->configurationManager().value( + ConfigurationManager::KeyConfigScene + ); + cacheFolder += "-" + ghoul::filesystem::File(scene).baseName(); + } + LINFO("Old cache: " << absPath("${CACHE}")); LINFO("New cache: " << cacheFolder); FileSys.registerPathToken( @@ -348,8 +341,7 @@ void OpenSpaceEngine::create(int argc, char** argv, } // Create directories that doesn't exist - auto tokens = FileSys.tokens(); - for (const std::string& token : tokens) { + for (const std::string& token : FileSys.tokens()) { if (!FileSys.directoryExists(token)) { std::string p = absPath(token); FileSys.createDirectory(p, ghoul::filesystem::FileSystem::Recursive::Yes); @@ -378,9 +370,7 @@ void OpenSpaceEngine::create(int argc, char** argv, } // Create the cachemanager - FileSys.createCacheManager( - absPath("${" + ConfigurationManager::KeyCache + "}"), CacheVersion - ); + FileSys.createCacheManager(cacheFolder, CacheVersion); // Register the provided shader directories ghoul::opengl::ShaderPreprocessor::addIncludePath(absPath("${SHADERS}")); @@ -446,7 +436,7 @@ void OpenSpaceEngine::initialize() { glbinding::Binding::useCurrentContext(); glbinding::Binding::initialize(); - // clear the screen so the user don't have to see old buffer contents from the + // clear the screen so the user doesn't have to see old buffer contents from the // graphics card LDEBUG("Clearing all Windows"); _windowWrapper->clearAllWindows(glm::vec4(0.f, 0.f, 0.f, 1.f)); @@ -912,10 +902,11 @@ void OpenSpaceEngine::initializeGL() { } LTRACE("OpenSpaceEngine::initializeGL::Console::initialize(end)"); - const std::string key = ConfigurationManager::KeyOpenGLDebugContext; - if (_configurationManager->hasKey(key)) { + if (_configurationManager->hasKey(ConfigurationManager::KeyOpenGLDebugContext)) { LTRACE("OpenSpaceEngine::initializeGL::DebugContext(begin)"); - ghoul::Dictionary dict = _configurationManager->value(key); + ghoul::Dictionary dict = _configurationManager->value( + ConfigurationManager::KeyOpenGLDebugContext + ); bool debug = dict.value(ConfigurationManager::PartActivate); // Debug output is not available before 4.3 @@ -935,7 +926,6 @@ void OpenSpaceEngine::initializeGL() { setDebugOutput(DebugOutput(debug), SynchronousOutput(synchronous)); - if (dict.hasKey(ConfigurationManager::PartFilterIdentifier)) { ghoul::Dictionary filterDict = dict.value( ConfigurationManager::PartFilterIdentifier @@ -1112,20 +1102,9 @@ void OpenSpaceEngine::initializeGL() { LINFO("Finished initializing OpenGL"); - LINFO("IsUsingSwapGroups: " << _windowWrapper->isUsingSwapGroups()); - LINFO("IsSwapGroupMaster: " << _windowWrapper->isSwapGroupMaster()); - LTRACE("OpenSpaceEngine::initializeGL(end)"); } -double OpenSpaceEngine::runTime() { - return _runTime; -} - -void OpenSpaceEngine::setRunTime(double d) { - _runTime = d; -} - void OpenSpaceEngine::preSynchronization() { LTRACE("OpenSpaceEngine::preSynchronization(begin)"); FileSys.triggerFilesystemEvents(); diff --git a/src/engine/wrapper/sgctwindowwrapper.cpp b/src/engine/wrapper/sgctwindowwrapper.cpp index dc19d46551..2d543cd25e 100644 --- a/src/engine/wrapper/sgctwindowwrapper.cpp +++ b/src/engine/wrapper/sgctwindowwrapper.cpp @@ -64,7 +64,7 @@ SGCTWindowWrapper::SGCTWindowWrapper() setEyeSeparationDistance(_eyeSeparation); }); } - + void SGCTWindowWrapper::terminate() { sgct::Engine::instance()->terminate(); } @@ -72,7 +72,7 @@ void SGCTWindowWrapper::terminate() { void SGCTWindowWrapper::setBarrier(bool enabled) { sgct::SGCTWindow::setBarrier(enabled); } - + void SGCTWindowWrapper::setSynchronization(bool enabled) { sgct_core::ClusterManager::instance()->setUseIgnoreSync(enabled); } @@ -90,7 +90,7 @@ void SGCTWindowWrapper::clearAllWindows(const glm::vec4& clearColor) { bool SGCTWindowWrapper::windowHasResized() const { return sgct::Engine::instance()->getCurrentWindowPtr()->isWindowResized(); } - + double SGCTWindowWrapper::averageDeltaTime() const { return sgct::Engine::instance()->getAvgDt(); } @@ -98,7 +98,11 @@ double SGCTWindowWrapper::averageDeltaTime() const { double SGCTWindowWrapper::deltaTime() const { return sgct::Engine::instance()->getDt(); } - + +double SGCTWindowWrapper::applicationTime() const { + return sgct::Engine::getTime(); +} + glm::vec2 SGCTWindowWrapper::mousePosition() const { int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); double posX, posY; @@ -157,7 +161,7 @@ glm::ivec2 SGCTWindowWrapper::currentDrawBufferResolution() const { } throw WindowWrapperException("No viewport available"); } - + glm::vec2 SGCTWindowWrapper::dpiScaling() const { return glm::vec2( sgct::Engine::instance()->getCurrentWindowPtr()->getXScale(), @@ -168,7 +172,7 @@ glm::vec2 SGCTWindowWrapper::dpiScaling() const { int SGCTWindowWrapper::currentNumberOfAaSamples() const { return sgct::Engine::instance()->getCurrentWindowPtr()->getNumberOfAASamples(); } - + bool SGCTWindowWrapper::isRegularRendering() const { sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr(); std::size_t nViewports = w->getNumberOfViewports(); @@ -194,7 +198,7 @@ bool SGCTWindowWrapper::isGuiWindow() const { GuiWindowTag ); } - + bool SGCTWindowWrapper::isMaster() const { return sgct::Engine::instance()->isMaster(); } @@ -206,7 +210,7 @@ bool SGCTWindowWrapper::isSwapGroupMaster() const { bool SGCTWindowWrapper::isUsingSwapGroups() const { return sgct::Engine::instance()->getCurrentWindowPtr()->isUsingSwapGroups(); } - + glm::mat4 SGCTWindowWrapper::viewProjectionMatrix() const { return sgct::Engine::instance()->getCurrentModelViewProjectionMatrix(); } @@ -214,7 +218,7 @@ glm::mat4 SGCTWindowWrapper::viewProjectionMatrix() const { glm::mat4 SGCTWindowWrapper::modelMatrix() const { return sgct::Engine::instance()->getModelMatrix(); } - + void SGCTWindowWrapper::setNearFarClippingPlane(float nearPlane, float farPlane) { sgct::Engine::instance()->setNearAndFarClippingPlanes(nearPlane, farPlane); } @@ -225,39 +229,33 @@ void SGCTWindowWrapper::setEyeSeparationDistance(float distance) { glm::ivec4 SGCTWindowWrapper::viewportPixelCoordinates() const { int x1, xSize, y1, ySize; - sgct::Engine::instance()->getCurrentWindowPtr()->getCurrentViewportPixelCoords(x1, - y1, - xSize, - ySize); + sgct::Engine::instance()->getCurrentWindowPtr()->getCurrentViewportPixelCoords( + x1, + y1, + xSize, + ySize + ); return glm::ivec4(x1, xSize, y1, ySize); } - + bool SGCTWindowWrapper::isExternalControlConnected() const { return sgct::Engine::instance()->isExternalControlConnected(); } - + void SGCTWindowWrapper::sendMessageToExternalControl(const std::vector& message) const { sgct::Engine::instance()->sendMessageToExternalControl( message.data(), static_cast(message.size()) ); } - + bool SGCTWindowWrapper::isSimpleRendering() const { return (sgct::Engine::instance()->getCurrentRenderTarget() != sgct::Engine::NonLinearBuffer); - } - + void SGCTWindowWrapper::takeScreenshot(bool applyWarping) const { sgct::SGCTSettings::instance()->setCaptureFromBackBuffer(applyWarping); sgct::Engine::instance()->takeScreenshot(); } - -//void forEachWindow(std::function function) { -// size_t n = sgct::Engine::instance()->getNumberOfWindows(); -// for (size_t i = 0; i < n; ++i) -// function(); -//} - -} // namespace openspace +} // namespace openspace diff --git a/src/engine/wrapper/windowwrapper.cpp b/src/engine/wrapper/windowwrapper.cpp index 3cb2784651..2021676076 100644 --- a/src/engine/wrapper/windowwrapper.cpp +++ b/src/engine/wrapper/windowwrapper.cpp @@ -92,19 +92,23 @@ double WindowWrapper::averageDeltaTime() const { double WindowWrapper::deltaTime() const { return 0.0; } - + +double WindowWrapper::applicationTime() const { + return 0.0; +} + glm::vec2 WindowWrapper::mousePosition() const { return glm::vec2(0.f); } - + uint32_t WindowWrapper::mouseButtons(int) const { return uint32_t(0); } - + glm::ivec2 WindowWrapper::currentWindowSize() const { return glm::ivec2(0); } - + glm::ivec2 WindowWrapper::currentWindowResolution() const { return currentWindowSize(); } @@ -153,11 +157,11 @@ glm::mat4 WindowWrapper::viewProjectionMatrix() const { glm::mat4 WindowWrapper::modelMatrix() const { return glm::mat4(1.f); } - + void WindowWrapper::setNearFarClippingPlane(float, float) {} void WindowWrapper::setEyeSeparationDistance(float) {} - + glm::ivec4 WindowWrapper::viewportPixelCoordinates() const { return glm::ivec4( 0, @@ -166,19 +170,19 @@ glm::ivec4 WindowWrapper::viewportPixelCoordinates() const { currentWindowResolution().y ); } - - + + bool WindowWrapper::isExternalControlConnected() const { return false; } - + void WindowWrapper::sendMessageToExternalControl(const std::vector&) const { } - + bool WindowWrapper::isSimpleRendering() const { return true; } - + void WindowWrapper::takeScreenshot(bool) const {} - + } // namespace openspace diff --git a/src/interaction/keyframenavigator.cpp b/src/interaction/keyframenavigator.cpp index 9d9070e609..e830925241 100644 --- a/src/interaction/keyframenavigator.cpp +++ b/src/interaction/keyframenavigator.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,7 @@ namespace openspace::interaction { void KeyframeNavigator::updateCamera(Camera& camera) { - double now = OsEng.runTime(); + double now = OsEng.windowWrapper().applicationTime(); if (_cameraPoseTimeline.nKeyframes() == 0) { return; diff --git a/src/network/parallelconnection.cpp b/src/network/parallelconnection.cpp index a5dc973343..7f0236e53c 100644 --- a/src/network/parallelconnection.cpp +++ b/src/network/parallelconnection.cpp @@ -587,7 +587,7 @@ void ParallelConnection::initializationMessageReceived(){ double ParallelConnection::calculateBufferedKeyframeTime(double originalTime) { std::lock_guard latencyLock(_latencyMutex); - double timeDiff = OsEng.runTime() - originalTime; + double timeDiff = OsEng.windowWrapper().applicationTime() - originalTime; if (_latencyDiffs.size() == 0) { _initialTimeDiff = timeDiff; } @@ -1084,7 +1084,7 @@ void ParallelConnection::preSynchronization() { if (OsEng.timeManager().time().timeJumped()) { _timeJumped = true; } - double now = OsEng.runTime(); + double now = OsEng.windowWrapper().applicationTime(); if (_lastCameraKeyframeTimestamp + _cameraKeyframeInterval < now) { sendCameraKeyframe(); @@ -1156,7 +1156,7 @@ void ParallelConnection::sendCameraKeyframe() { kf._focusNode = focusNode->name(); // Timestamp as current runtime of OpenSpace instance - kf._timestamp = OsEng.runTime(); + kf._timestamp = OsEng.windowWrapper().applicationTime(); // Create a buffer for the keyframe std::vector buffer; @@ -1180,7 +1180,7 @@ void ParallelConnection::sendTimeKeyframe() { kf._time = time.j2000Seconds(); // Timestamp as current runtime of OpenSpace instance - kf._timestamp = OsEng.runTime(); + kf._timestamp = OsEng.windowWrapper().applicationTime(); // Create a buffer for the keyframe std::vector buffer; diff --git a/src/util/timemanager.cpp b/src/util/timemanager.cpp index e8e2716e51..102a8d7fc0 100644 --- a/src/util/timemanager.cpp +++ b/src/util/timemanager.cpp @@ -23,7 +23,9 @@ ****************************************************************************************/ #include + #include +#include #include #include @@ -45,7 +47,7 @@ void TimeManager::preSynchronization(double dt) { } void TimeManager::consumeKeyframes(double dt) { - double now = OsEng.runTime(); + double now = OsEng.windowWrapper().applicationTime(); const std::deque>& keyframes = _timeline.keyframes(); auto firstFutureKeyframe = std::lower_bound(keyframes.begin(), keyframes.end(), now, &compareKeyframeTimeWithTime);