From d2299f4042d6c95aef7c26756483a0ed4f7e95a2 Mon Sep 17 00:00:00 2001 From: VLLindqvist Date: Mon, 12 Jun 2023 17:56:27 +0200 Subject: [PATCH] Fix assertion error --- .../network/messagehandler.cpp | 15 +----- .../network/softwareconnection.cpp | 4 +- .../softwareintegration/session/session.cpp | 15 +----- .../softwareintegrationmodule.cpp | 53 +++++++++++++++++++ .../softwareintegrationmodule.h | 6 +++ 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/modules/softwareintegration/network/messagehandler.cpp b/modules/softwareintegration/network/messagehandler.cpp index 3201e985d0..6381725dd2 100644 --- a/modules/softwareintegration/network/messagehandler.cpp +++ b/modules/softwareintegration/network/messagehandler.cpp @@ -111,20 +111,7 @@ void checkRenderable( }; addCallback(identifier, { reanchorCallback, { storage::Key::DataPoints }, "reanchorCallback" }); - // Set large time steps for the GUI (so you for example - // can see the movement of stars at 5000 years/second) - // Values set in seconds: Real time, 5k years, - // 10k year, 50k year, 100k year, 500k year, 1M year - std::string largeTimeSteps = "{ 1.0, 157680000000.0, 315360000000.0," - " 1576800000000.0, 3153600000000.0," - " 15768000000000.0, 3153600000000.0 }"; - global::scriptEngine->queueScript( - fmt::format( - "openspace.time.setDeltaTimeSteps({});", - largeTimeSteps - ), - scripting::ScriptEngine::RemoteScripting::Yes - ); + softwareintegration::setDefaultDeltaTimeSteps(); } } diff --git a/modules/softwareintegration/network/softwareconnection.cpp b/modules/softwareintegration/network/softwareconnection.cpp index cb29b1d796..2830b2541a 100644 --- a/modules/softwareintegration/network/softwareconnection.cpp +++ b/modules/softwareintegration/network/softwareconnection.cpp @@ -534,8 +534,8 @@ IncomingMessage receiveMessageFromSoftware(std::shared_ptr c std::string type{ headerBuffer.begin() + 5, headerBuffer.begin() + 9 }; auto typeEnum = softwareintegration::simp::getMessageType(type); - // Read and convert message size: Byte 9-24 - const size_t subjectSize = std::stoll(std::string{ headerBuffer.begin() + 9, headerBuffer.begin() + 25 }); + // Read and convert message size: Byte 9-23 + const size_t subjectSize = std::stoll(std::string{ headerBuffer.begin() + 9, headerBuffer.begin() + 24 }); // Receive the message subject if (typeEnum != softwareintegration::simp::MessageType::Unknown) { diff --git a/modules/softwareintegration/session/session.cpp b/modules/softwareintegration/session/session.cpp index 247ef88d87..31392e87bd 100644 --- a/modules/softwareintegration/session/session.cpp +++ b/modules/softwareintegration/session/session.cpp @@ -141,20 +141,7 @@ bool softwareintegration::Session::loadSessionData(SoftwareIntegrationModule* mo return false; } - // Set large time steps for the GUI (so you for example - // can see the movement of stars at 5000 years/second) - // Values set in seconds: Real time, 5k years, - // 10k year, 50k year, 100k year, 500k year, 1M year - std::string largeTimeSteps = "{ 1.0, 157680000000.0, 315360000000.0," - " 1576800000000.0, 3153600000000.0," - " 15768000000000.0, 3153600000000.0 }"; - global::scriptEngine->queueScript( - fmt::format( - "openspace.time.setDeltaTimeSteps({});", - largeTimeSteps - ), - scripting::ScriptEngine::RemoteScripting::Yes - ); + softwareintegration::setDefaultDeltaTimeSteps(); return true; } diff --git a/modules/softwareintegration/softwareintegrationmodule.cpp b/modules/softwareintegration/softwareintegrationmodule.cpp index ac5995a95c..2595cb1510 100644 --- a/modules/softwareintegration/softwareintegrationmodule.cpp +++ b/modules/softwareintegration/softwareintegrationmodule.cpp @@ -134,4 +134,57 @@ scripting::LuaLibrary SoftwareIntegrationModule::luaLibrary() const { }; } +namespace softwareintegration { + +void setDefaultDeltaTimeSteps() { + // TODO: This can be set in profile for now + // // Set large time steps for the GUI (so you for example + // // can see the movement of stars at 5000 years/second) + // // Values set in seconds: Real time, 5k years, + // // 10k year, 50k year, 100k year, 500k year, 1M year + // std::vector wantedTimeSteps{ + // 1.0, 157680000000.0, 315360000000.0, + // 1576800000000.0, 3153600000000.0, + // 15768000000000.0, 3153600000000.0 + // }; + // auto timeSteps = global::timeManager->deltaTimeSteps(); + // std::sort(timeSteps.begin(), timeSteps.end()); + + // auto it = wantedTimeSteps.begin(); + // while (it != wantedTimeSteps.end()) { + // if ( + // std::find_if( + // timeSteps.begin(), + // timeSteps.end(), + // [it](double ts) { return std::abs(*it - ts) < std::numeric_limits::epsilon(); } + // ) != timeSteps.end() + // ) { + // it = wantedTimeSteps.erase(it); + // } + // else { + // ++it; + // } + // } + + // if (wantedTimeSteps.size() > 0) { + // std::string largeTimeSteps = "{ "; + // for (size_t i = 0; i < wantedTimeSteps.size(); ++i) { + // if (i != 0) { + // largeTimeSteps += ", "; + // } + // largeTimeSteps += ghoul::to_string(wantedTimeSteps[i]); + // } + // largeTimeSteps += " }"; + // global::scriptEngine->queueScript( + // fmt::format( + // "openspace.time.setDeltaTimeSteps({});", + // largeTimeSteps + // ), + // scripting::ScriptEngine::RemoteScripting::Yes + // ); + // } +} + +} // namespace softwareintegration + } // namespace openspace diff --git a/modules/softwareintegration/softwareintegrationmodule.h b/modules/softwareintegration/softwareintegrationmodule.h index 1edab78667..8876556e30 100644 --- a/modules/softwareintegration/softwareintegrationmodule.h +++ b/modules/softwareintegration/softwareintegrationmodule.h @@ -87,6 +87,12 @@ private: std::shared_ptr _networkState; }; +namespace softwareintegration { + +void setDefaultDeltaTimeSteps(); + +} // namespace softwareintegration + } // namespace openspace #include "softwareintegrationmodule.inl"