From c9a63274a855aedc436fc8fb27ac7ef98121bc48 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 1 Jun 2022 15:06:40 -0400 Subject: [PATCH 1/5] Move presync callback functionality from SkyBrowserModule to ServerModule in order to expose the functionality to other topics as well --- modules/server/servermodule.cpp | 33 +++++++++++++++++++ modules/server/servermodule.h | 9 +++++ modules/server/src/topics/skybrowsertopic.cpp | 4 +-- modules/skybrowser/skybrowsermodule.cpp | 32 ------------------ modules/skybrowser/skybrowsermodule.h | 9 ----- 5 files changed, 44 insertions(+), 43 deletions(-) diff --git a/modules/server/servermodule.cpp b/modules/server/servermodule.cpp index 734c1ce246..142cc91360 100644 --- a/modules/server/servermodule.cpp +++ b/modules/server/servermodule.cpp @@ -50,6 +50,15 @@ ServerModule::ServerModule() , _interfaceOwner({"Interfaces", "Interfaces", "Server Interfaces"}) { addPropertySubOwner(_interfaceOwner); + + global::callback::preSync->emplace_back([this]() { + // Trigger callbacks + using K = CallbackHandle; + using V = CallbackFunction; + for (const std::pair& it : _preSyncCallbacks) { + it.second(); // call function + } + }); } ServerModule::~ServerModule() { @@ -233,4 +242,28 @@ void ServerModule::consumeMessages() { } } +ServerModule::CallbackHandle ServerModule::addPreSyncCallback(CallbackFunction cb) +{ + CallbackHandle handle = _nextCallbackHandle++; + _preSyncCallbacks.emplace_back(handle, std::move(cb)); + return handle; +} + +void ServerModule::removePreSyncCallback(CallbackHandle handle) { + const auto it = std::find_if( + _preSyncCallbacks.begin(), + _preSyncCallbacks.end(), + [handle](const std::pair& cb) { + return cb.first == handle; + } + ); + + ghoul_assert( + it != _preSyncCallbacks.end(), + "handle must be a valid callback handle" + ); + + _preSyncCallbacks.erase(it); +} + } // namespace openspace diff --git a/modules/server/servermodule.h b/modules/server/servermodule.h index 05f4686681..a3f1ae9e97 100644 --- a/modules/server/servermodule.h +++ b/modules/server/servermodule.h @@ -49,6 +49,8 @@ struct Message { class ServerModule : public OpenSpaceModule { public: static constexpr const char* Name = "Server"; + using CallbackHandle = int; + using CallbackFunction = std::function; ServerModule(); virtual ~ServerModule(); @@ -57,6 +59,9 @@ public: int skyBrowserUpdateTime() const; + CallbackHandle addPreSyncCallback(CallbackFunction cb); + void removePreSyncCallback(CallbackHandle handle); + protected: void internalInitialize(const ghoul::Dictionary& configuration) override; @@ -79,6 +84,10 @@ private: std::vector> _interfaces; properties::PropertyOwner _interfaceOwner; int _skyBrowserUpdateTime = 100; + + // Callbacks for tiggering topic + int _nextCallbackHandle = 0; + std::vector> _preSyncCallbacks; }; } // namespace openspace diff --git a/modules/server/src/topics/skybrowsertopic.cpp b/modules/server/src/topics/skybrowsertopic.cpp index db375a037f..83970378a3 100644 --- a/modules/server/src/topics/skybrowsertopic.cpp +++ b/modules/server/src/topics/skybrowsertopic.cpp @@ -55,7 +55,7 @@ SkyBrowserTopic::SkyBrowserTopic() SkyBrowserTopic::~SkyBrowserTopic() { if (_targetDataCallbackHandle != UnsetOnChangeHandle) { - SkyBrowserModule* module = global::moduleEngine->module(); + ServerModule* module = global::moduleEngine->module(); if (module) { module->removePreSyncCallback(_targetDataCallbackHandle); } @@ -78,7 +78,7 @@ void SkyBrowserTopic::handleJson(const nlohmann::json& json) { return; } - SkyBrowserModule* module = global::moduleEngine->module(); + ServerModule* module = global::moduleEngine->module(); _targetDataCallbackHandle = module->addPreSyncCallback( [this]() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); diff --git a/modules/skybrowser/skybrowsermodule.cpp b/modules/skybrowser/skybrowsermodule.cpp index a3e6f05eef..5dead313c2 100644 --- a/modules/skybrowser/skybrowsermodule.cpp +++ b/modules/skybrowser/skybrowsermodule.cpp @@ -214,13 +214,6 @@ SkyBrowserModule::SkyBrowserModule() if (_cameraRotation.isAnimating() && _allowCameraRotation) { incrementallyRotateCamera(); } - - // Trigger callbacks (should maybe have a check to see if update is needed) - using K = CallbackHandle; - using V = CallbackFunction; - for (const std::pair& it : _preSyncCallbacks) { - it.second(); // call function - } }); } @@ -484,31 +477,6 @@ bool SkyBrowserModule::isSelectedPairFacingCamera() const { return found ? found->isFacingCamera() : false; } -SkyBrowserModule::CallbackHandle SkyBrowserModule::addPreSyncCallback( - CallbackFunction cb) -{ - CallbackHandle handle = _nextCallbackHandle++; - _preSyncCallbacks.emplace_back(handle, std::move(cb)); - return handle; -} - -void SkyBrowserModule::removePreSyncCallback(CallbackHandle handle) { - const auto it = std::find_if( - _preSyncCallbacks.begin(), - _preSyncCallbacks.end(), - [handle](const std::pair& cb) { - return cb.first == handle; - } - ); - - ghoul_assert( - it != _preSyncCallbacks.end(), - "handle must be a valid callback handle" - ); - - _preSyncCallbacks.erase(it); -} - std::vector SkyBrowserModule::documentations() const { return { RenderableSkyTarget::Documentation(), diff --git a/modules/skybrowser/skybrowsermodule.h b/modules/skybrowser/skybrowsermodule.h index 938ead2185..5ce75eeb65 100644 --- a/modules/skybrowser/skybrowsermodule.h +++ b/modules/skybrowser/skybrowsermodule.h @@ -47,8 +47,6 @@ struct ImageData; class SkyBrowserModule : public OpenSpaceModule { public: constexpr static const char* Name = "SkyBrowser"; - using CallbackHandle = int; - using CallbackFunction = std::function; SkyBrowserModule(); @@ -89,9 +87,6 @@ public: void loadImages(const std::string& root, const std::filesystem::path& directory); int nLoadedImages() const; - CallbackHandle addPreSyncCallback(CallbackFunction cb); - void removePreSyncCallback(CallbackHandle handle); - scripting::LuaLibrary luaLibrary() const override; std::vector documentations() const override; @@ -125,10 +120,6 @@ private: // Data handler for the image collections std::unique_ptr _dataHandler; - - // Callbacks for tiggering topic - int _nextCallbackHandle = 0; - std::vector> _preSyncCallbacks; }; } // namespace openspace From dbb3b65927397b2e58d35ff1dc359dd70cb40eca Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 1 Jun 2022 15:07:45 -0400 Subject: [PATCH 2/5] Move calculation of camera geo position from DashboardItemGlobeLocation to a function in GlobeBrowsingModule --- modules/globebrowsing/globebrowsingmodule.cpp | 40 +++++++++++++++++ modules/globebrowsing/globebrowsingmodule.h | 2 + .../src/dashboarditemglobelocation.cpp | 43 ++++--------------- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index b9074cda6b..3454f2d394 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -421,6 +421,46 @@ glm::vec3 GlobeBrowsingModule::cartesianCoordinatesFromGeo( return glm::vec3(globe.ellipsoid().cartesianPosition(pos)); } +glm::dvec3 GlobeBrowsingModule::geoPosition() const { + using namespace globebrowsing; + + const SceneGraphNode* n = global::navigationHandler->orbitalNavigator().anchorNode(); + if (!n) { + return glm::dvec3(0); + } + const RenderableGlobe* globe = dynamic_cast(n->renderable()); + if (!globe) { + return glm::dvec3(0); + } + + const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3(); + const glm::dmat4 inverseModelTransform = glm::inverse(n->modelTransform()); + const glm::dvec3 cameraPositionModelSpace = + glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0)); + const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle( + cameraPositionModelSpace + ); + + const Geodetic2 geo2 = globe->ellipsoid().cartesianToGeodetic2( + posHandle.centerToReferenceSurface + ); + + double lat = glm::degrees(geo2.lat); + double lon = glm::degrees(geo2.lon); + + double altitude = glm::length( + cameraPositionModelSpace - posHandle.centerToReferenceSurface + ); + + if (glm::length(cameraPositionModelSpace) < + glm::length(posHandle.centerToReferenceSurface)) + { + altitude = -altitude; + } + + return glm::dvec3(lat, lon, altitude); +} + void GlobeBrowsingModule::goToChunk(const globebrowsing::RenderableGlobe& globe, const globebrowsing::TileIndex& ti, glm::vec2 uv, bool doResetCameraDirection) diff --git a/modules/globebrowsing/globebrowsingmodule.h b/modules/globebrowsing/globebrowsingmodule.h index 756525843b..678558fb14 100644 --- a/modules/globebrowsing/globebrowsingmodule.h +++ b/modules/globebrowsing/globebrowsingmodule.h @@ -63,6 +63,8 @@ public: glm::vec3 cartesianCoordinatesFromGeo(const globebrowsing::RenderableGlobe& globe, double latitude, double longitude, double altitude); + glm::dvec3 geoPosition() const; + globebrowsing::cache::MemoryAwareTileCache* tileCache(); scripting::LuaLibrary luaLibrary() const override; std::vector documentations() const override; diff --git a/modules/globebrowsing/src/dashboarditemglobelocation.cpp b/modules/globebrowsing/src/dashboarditemglobelocation.cpp index 55a1e34316..4b6ab7d0ad 100644 --- a/modules/globebrowsing/src/dashboarditemglobelocation.cpp +++ b/modules/globebrowsing/src/dashboarditemglobelocation.cpp @@ -24,11 +24,13 @@ #include +#include #include #include #include #include #include +#include #include #include #include @@ -171,42 +173,13 @@ DashboardItemGlobeLocation::DashboardItemGlobeLocation( void DashboardItemGlobeLocation::render(glm::vec2& penPosition) { ZoneScoped + + GlobeBrowsingModule* module = global::moduleEngine->module(); - using namespace globebrowsing; - - const SceneGraphNode* n = global::navigationHandler->orbitalNavigator().anchorNode(); - if (!n) { - return; - } - const RenderableGlobe* globe = dynamic_cast(n->renderable()); - if (!globe) { - return; - } - - const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3(); - const glm::dmat4 inverseModelTransform = glm::inverse(n->modelTransform()); - const glm::dvec3 cameraPositionModelSpace = - glm::dvec3(inverseModelTransform * glm::dvec4(cameraPosition, 1.0)); - const SurfacePositionHandle posHandle = globe->calculateSurfacePositionHandle( - cameraPositionModelSpace - ); - - const Geodetic2 geo2 = globe->ellipsoid().cartesianToGeodetic2( - posHandle.centerToReferenceSurface - ); - - double lat = glm::degrees(geo2.lat); - double lon = glm::degrees(geo2.lon); - - double altitude = glm::length( - cameraPositionModelSpace - posHandle.centerToReferenceSurface - ); - - if (glm::length(cameraPositionModelSpace) < - glm::length(posHandle.centerToReferenceSurface)) - { - altitude = -altitude; - } + glm::dvec3 position = module->geoPosition(); + double lat = position.x; + double lon = position.y; + double altitude = position.z; std::pair dist = simplifyDistance(altitude); From 817fad60c3cb89e6c8dbfe5448c828c584de493b Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 1 Jun 2022 15:08:14 -0400 Subject: [PATCH 3/5] Add topic for geo position of camera --- modules/server/CMakeLists.txt | 2 + modules/server/include/topics/cameratopic.h | 56 +++++++++++ modules/server/src/connection.cpp | 3 + modules/server/src/topics/cameratopic.cpp | 105 ++++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 modules/server/include/topics/cameratopic.h create mode 100644 modules/server/src/topics/cameratopic.cpp diff --git a/modules/server/CMakeLists.txt b/modules/server/CMakeLists.txt index 8df2bbc669..63fb71d65a 100644 --- a/modules/server/CMakeLists.txt +++ b/modules/server/CMakeLists.txt @@ -33,6 +33,7 @@ set(HEADER_FILES include/serverinterface.h include/topics/authorizationtopic.h include/topics/bouncetopic.h + include/topics/cameratopic.h include/topics/documentationtopic.h include/topics/enginemodetopic.h include/topics/flightcontrollertopic.h @@ -58,6 +59,7 @@ set(SOURCE_FILES src/serverinterface.cpp src/topics/authorizationtopic.cpp src/topics/bouncetopic.cpp + src/topics/cameratopic.cpp src/topics/documentationtopic.cpp src/topics/enginemodetopic.cpp src/topics/flightcontrollertopic.cpp diff --git a/modules/server/include/topics/cameratopic.h b/modules/server/include/topics/cameratopic.h new file mode 100644 index 0000000000..e06778a1ea --- /dev/null +++ b/modules/server/include/topics/cameratopic.h @@ -0,0 +1,56 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * 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. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_SERVER___CAMERA_TOPIC___H__ +#define __OPENSPACE_MODULE_SERVER___CAMERA_TOPIC___H__ + +#include +#include + +namespace openspace { + +class CameraTopic : public Topic { +public: + CameraTopic(); + virtual ~CameraTopic(); + + void handleJson(const nlohmann::json& json) override; + bool isDone() const override; + +private: + const int UnsetOnChangeHandle = -1; + + void sendCameraData(); + + int _dataCallbackHandle = UnsetOnChangeHandle; + bool _isDone = false; + std::chrono::system_clock::time_point _lastUpdateTime; + glm::dvec3 _lastPosition = glm::dvec3(0); + + std::chrono::milliseconds _cameraPositionUpdateTime = std::chrono::milliseconds(100); +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_SERVER___CAMERA_TOPIC___H__ diff --git a/modules/server/src/connection.cpp b/modules/server/src/connection.cpp index 2380e2153d..a9c4bd6a8d 100644 --- a/modules/server/src/connection.cpp +++ b/modules/server/src/connection.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -71,6 +72,7 @@ namespace { constexpr const char* BounceTopicKey = "bounce"; constexpr const char* FlightControllerTopicKey = "flightcontroller"; constexpr const char* SkyBrowserKey = "skybrowser"; + constexpr const char* CameraKey = "camera"; } // namespace namespace openspace { @@ -110,6 +112,7 @@ Connection::Connection(std::unique_ptr s, std::string address _topicFactory.registerClass(FlightControllerTopicKey); _topicFactory.registerClass(VersionTopicKey); _topicFactory.registerClass(SkyBrowserKey); + _topicFactory.registerClass(CameraKey); } void Connection::handleMessage(const std::string& message) { diff --git a/modules/server/src/topics/cameratopic.cpp b/modules/server/src/topics/cameratopic.cpp new file mode 100644 index 0000000000..ab637cf780 --- /dev/null +++ b/modules/server/src/topics/cameratopic.cpp @@ -0,0 +1,105 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2022 * + * * + * 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 "modules/server/include/topics/cameratopic.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr const char* EventKey = "event"; + constexpr const char* SubscribeEvent = "start_subscription"; + constexpr const char* UnsubscribeEvent = "stop_subscription"; +} // namespace + +using nlohmann::json; + +namespace openspace { + +CameraTopic::CameraTopic() + : _lastUpdateTime(std::chrono::system_clock::now()) {} + +CameraTopic::~CameraTopic() { + if (_dataCallbackHandle != UnsetOnChangeHandle) { + ServerModule* module = global::moduleEngine->module(); + if (module) { + module->removePreSyncCallback(_dataCallbackHandle); + } + } +} + +bool CameraTopic::isDone() const { + return _isDone; +} + +void CameraTopic::handleJson(const nlohmann::json& json) { + std::string event = json.at(EventKey).get(); + if (event == UnsubscribeEvent) { + _isDone = true; + return; + } + + if (event != SubscribeEvent) { + _isDone = true; + return; + } + + ServerModule* module = global::moduleEngine->module(); + _dataCallbackHandle = module->addPreSyncCallback( + [this]() { + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + if (now - _lastUpdateTime > _cameraPositionUpdateTime) { + sendCameraData(); + _lastUpdateTime = std::chrono::system_clock::now(); + } + } + ); +} + +void CameraTopic::sendCameraData() { + using namespace openspace; + + GlobeBrowsingModule* module = global::moduleEngine->module(); + glm::dvec3 position = module->geoPosition(); + std::pair altSimplified = simplifyDistance(position.z); + + nlohmann::json jsonData = { + { "longitude", position.x }, + { "latitude", position.y}, + { "altitude", altSimplified.first }, + { "altitudeUnit", altSimplified.second} + }; + + _connection->sendJson(wrappedPayload(jsonData)); +} + +} // namespace openspace From a762f9ebc830d6f57f138c2a3afd5c3a81aa4d94 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Wed, 29 Jun 2022 07:20:00 -0400 Subject: [PATCH 4/5] Fix flipped latitude and longitude --- modules/server/src/topics/cameratopic.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/server/src/topics/cameratopic.cpp b/modules/server/src/topics/cameratopic.cpp index ab637cf780..13c8914c60 100644 --- a/modules/server/src/topics/cameratopic.cpp +++ b/modules/server/src/topics/cameratopic.cpp @@ -93,8 +93,8 @@ void CameraTopic::sendCameraData() { std::pair altSimplified = simplifyDistance(position.z); nlohmann::json jsonData = { - { "longitude", position.x }, - { "latitude", position.y}, + { "latitude", position.x}, + { "longitude", position.y }, { "altitude", altSimplified.first }, { "altitudeUnit", altSimplified.second} }; From 7ec6c247cc864087f109eab65f2e203e9128b1c0 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Thu, 21 Jul 2022 12:38:59 -0400 Subject: [PATCH 5/5] Fix comments on PR --- modules/globebrowsing/globebrowsingmodule.cpp | 4 ++-- modules/server/include/topics/cameratopic.h | 6 +++--- modules/server/servermodule.cpp | 1 + modules/server/src/topics/cameratopic.cpp | 13 +++++-------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index 3454f2d394..8ddd928cb3 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -426,11 +426,11 @@ glm::dvec3 GlobeBrowsingModule::geoPosition() const { const SceneGraphNode* n = global::navigationHandler->orbitalNavigator().anchorNode(); if (!n) { - return glm::dvec3(0); + return glm::dvec3(0.0); } const RenderableGlobe* globe = dynamic_cast(n->renderable()); if (!globe) { - return glm::dvec3(0); + return glm::dvec3(0.0); } const glm::dvec3 cameraPosition = global::navigationHandler->camera()->positionVec3(); diff --git a/modules/server/include/topics/cameratopic.h b/modules/server/include/topics/cameratopic.h index e06778a1ea..0a96378fb5 100644 --- a/modules/server/include/topics/cameratopic.h +++ b/modules/server/include/topics/cameratopic.h @@ -22,8 +22,8 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#ifndef __OPENSPACE_MODULE_SERVER___CAMERA_TOPIC___H__ -#define __OPENSPACE_MODULE_SERVER___CAMERA_TOPIC___H__ +#ifndef __OPENSPACE_MODULE_SERVER___CAMERATOPIC___H__ +#define __OPENSPACE_MODULE_SERVER___CAMERATOPIC___H__ #include #include @@ -53,4 +53,4 @@ private: } // namespace openspace -#endif // __OPENSPACE_MODULE_SERVER___CAMERA_TOPIC___H__ +#endif // __OPENSPACE_MODULE_SERVER___CAMERATOPIC___H__ diff --git a/modules/server/servermodule.cpp b/modules/server/servermodule.cpp index 142cc91360..e050d98776 100644 --- a/modules/server/servermodule.cpp +++ b/modules/server/servermodule.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include diff --git a/modules/server/src/topics/cameratopic.cpp b/modules/server/src/topics/cameratopic.cpp index 13c8914c60..cf1a7fe8df 100644 --- a/modules/server/src/topics/cameratopic.cpp +++ b/modules/server/src/topics/cameratopic.cpp @@ -46,7 +46,8 @@ using nlohmann::json; namespace openspace { CameraTopic::CameraTopic() - : _lastUpdateTime(std::chrono::system_clock::now()) {} + : _lastUpdateTime(std::chrono::system_clock::now()) +{} CameraTopic::~CameraTopic() { if (_dataCallbackHandle != UnsetOnChangeHandle) { @@ -63,10 +64,6 @@ bool CameraTopic::isDone() const { void CameraTopic::handleJson(const nlohmann::json& json) { std::string event = json.at(EventKey).get(); - if (event == UnsubscribeEvent) { - _isDone = true; - return; - } if (event != SubscribeEvent) { _isDone = true; @@ -90,13 +87,13 @@ void CameraTopic::sendCameraData() { GlobeBrowsingModule* module = global::moduleEngine->module(); glm::dvec3 position = module->geoPosition(); - std::pair altSimplified = simplifyDistance(position.z); + std::pair altSimplified = simplifyDistance(position.z); nlohmann::json jsonData = { - { "latitude", position.x}, + { "latitude", position.x }, { "longitude", position.y }, { "altitude", altSimplified.first }, - { "altitudeUnit", altSimplified.second} + { "altitudeUnit", altSimplified.second } }; _connection->sendJson(wrappedPayload(jsonData));