From 8a292c1645c2215bf2ff44572ba4298d258889a5 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Tue, 26 Apr 2022 14:39:00 -0400 Subject: [PATCH] Expose time interval to user in config file for sky browser topic. This will give the user control over how often data is passed. Hopefully a future proof fix for GPU crash --- modules/server/include/topics/skybrowsertopic.h | 1 + modules/server/servermodule.cpp | 10 ++++++++++ modules/server/servermodule.h | 3 +++ modules/server/src/topics/skybrowsertopic.cpp | 11 ++++++++--- openspace.cfg | 3 ++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/server/include/topics/skybrowsertopic.h b/modules/server/include/topics/skybrowsertopic.h index 3037c5cbe3..7aafc03b33 100644 --- a/modules/server/include/topics/skybrowsertopic.h +++ b/modules/server/include/topics/skybrowsertopic.h @@ -46,6 +46,7 @@ private: int _targetDataCallbackHandle = UnsetOnChangeHandle; bool _isDone = false; std::chrono::system_clock::time_point _lastUpdateTime; + std::chrono::milliseconds _skyBrowserUpdateTime = std::chrono::milliseconds(100); }; } // namespace openspace diff --git a/modules/server/servermodule.cpp b/modules/server/servermodule.cpp index 27346754c0..7b2a261638 100644 --- a/modules/server/servermodule.cpp +++ b/modules/server/servermodule.cpp @@ -72,6 +72,10 @@ ServerInterface* ServerModule::serverInterfaceByIdentifier(const std::string& id return si->get(); } +int ServerModule::skyBrowserUpdateTime() const { + return _skyBrowserUpdate; +} + void ServerModule::internalInitialize(const ghoul::Dictionary& configuration) { global::callback::preSync->emplace_back([this]() { ZoneScopedN("ServerModule") @@ -110,6 +114,12 @@ void ServerModule::internalInitialize(const ghoul::Dictionary& configuration) { _interfaces.push_back(std::move(serverInterface)); } } + // Ylva Selling, 2022-04-26 hasValue doesn't find the variable + if (configuration.hasValue("SkyBrowserUpdateTime")) { + _skyBrowserUpdate = static_cast( + configuration.value("SkyBrowserUpdateTime") + ); + } } void ServerModule::preSync() { diff --git a/modules/server/servermodule.h b/modules/server/servermodule.h index a69b92608e..c498123959 100644 --- a/modules/server/servermodule.h +++ b/modules/server/servermodule.h @@ -55,6 +55,8 @@ public: ServerInterface* serverInterfaceByIdentifier(const std::string& identifier); + int skyBrowserUpdateTime() const; + protected: void internalInitialize(const ghoul::Dictionary& configuration) override; @@ -76,6 +78,7 @@ private: std::vector _connections; std::vector> _interfaces; properties::PropertyOwner _interfaceOwner; + int _skyBrowserUpdate = 100; }; } // namespace openspace diff --git a/modules/server/src/topics/skybrowsertopic.cpp b/modules/server/src/topics/skybrowsertopic.cpp index 664aad5066..d9ae067218 100644 --- a/modules/server/src/topics/skybrowsertopic.cpp +++ b/modules/server/src/topics/skybrowsertopic.cpp @@ -25,6 +25,7 @@ #include "modules/server/include/topics/skybrowsertopic.h" #include +#include #include #include #include @@ -38,7 +39,6 @@ namespace { constexpr const char* EventKey = "event"; constexpr const char* SubscribeEvent = "start_subscription"; constexpr const char* UnsubscribeEvent = "stop_subscription"; - constexpr const std::chrono::milliseconds TimeUpdateInterval(25); } // namespace using nlohmann::json; @@ -47,7 +47,12 @@ namespace openspace { SkyBrowserTopic::SkyBrowserTopic() : _lastUpdateTime(std::chrono::system_clock::now()) -{} +{ + ServerModule* module = global::moduleEngine->module(); + if (module) { + _skyBrowserUpdateTime = std::chrono::milliseconds(module->skyBrowserUpdateTime()); + } +} SkyBrowserTopic::~SkyBrowserTopic() { if (_targetDataCallbackHandle != UnsetOnChangeHandle) { @@ -73,7 +78,7 @@ void SkyBrowserTopic::handleJson(const nlohmann::json& json) { _targetDataCallbackHandle = global::timeManager->addTimeChangeCallback([this]() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); - if (now - _lastUpdateTime > TimeUpdateInterval) { + if (now - _lastUpdateTime > _skyBrowserUpdateTime) { sendBrowserData(); _lastUpdateTime = std::chrono::system_clock::now(); } diff --git a/openspace.cfg b/openspace.cfg index f79776043e..6338b2a227 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -151,6 +151,7 @@ ModuleConfigurations = { }, Server = { AllowAddresses = { "127.0.0.1", "localhost" }, + SkyBrowserUpdateTime = 150, Interfaces = { { Type = "TcpSocket", @@ -188,7 +189,7 @@ ModuleConfigurations = { Space = { ShowExceptions = false } - -- OBS! The settings for the SkyBrowser and Exoplanets modules are + -- OBS! The settings for the SkyBrowser and Exoplanets modules are -- set in individual assets, see "data/assets/modules". Note that -- any settings addded here might be overwritten by those assets }