mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-08 04:31:08 -06:00
Send topic on presync instead of from itmemanager (closes #2037)
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/properties/property.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/util/timemanager.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
namespace {
|
||||
@@ -56,7 +55,8 @@ SkyBrowserTopic::SkyBrowserTopic()
|
||||
|
||||
SkyBrowserTopic::~SkyBrowserTopic() {
|
||||
if (_targetDataCallbackHandle != UnsetOnChangeHandle) {
|
||||
global::timeManager->removeTimeChangeCallback(_targetDataCallbackHandle);
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
module->removePreSyncCallback(_targetDataCallbackHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,13 +76,14 @@ void SkyBrowserTopic::handleJson(const nlohmann::json& json) {
|
||||
return;
|
||||
}
|
||||
|
||||
_targetDataCallbackHandle = global::timeManager->addTimeChangeCallback([this]() {
|
||||
SkyBrowserModule* module = global::moduleEngine->module<SkyBrowserModule>();
|
||||
_targetDataCallbackHandle = module->addPreSyncCallback([this]() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
if (now - _lastUpdateTime > _skyBrowserUpdateTime) {
|
||||
sendBrowserData();
|
||||
_lastUpdateTime = std::chrono::system_clock::now();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void SkyBrowserTopic::sendBrowserData() {
|
||||
|
||||
@@ -154,6 +154,13 @@ 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<K, V>& it : _preSyncCallbacks) {
|
||||
it.second(); // call function
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -397,6 +404,31 @@ 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<CallbackHandle, CallbackFunction>& cb) {
|
||||
return cb.first == handle;
|
||||
}
|
||||
);
|
||||
|
||||
ghoul_assert(
|
||||
it != _preSyncCallbacks.end(),
|
||||
"handle must be a valid callback handle"
|
||||
);
|
||||
|
||||
_preSyncCallbacks.erase(it);
|
||||
}
|
||||
|
||||
scripting::LuaLibrary SkyBrowserModule::luaLibrary() const {
|
||||
return {
|
||||
"skybrowser",
|
||||
|
||||
@@ -52,6 +52,8 @@ enum class MouseInteraction {
|
||||
class SkyBrowserModule : public OpenSpaceModule {
|
||||
public:
|
||||
constexpr static const char* Name = "SkyBrowser";
|
||||
using CallbackHandle = int;
|
||||
using CallbackFunction = std::function<void()>;
|
||||
|
||||
SkyBrowserModule();
|
||||
|
||||
@@ -90,6 +92,9 @@ 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<documentation::Documentation> documentations() const override;
|
||||
|
||||
@@ -125,6 +130,10 @@ private:
|
||||
|
||||
// Data handler for the image collections
|
||||
std::unique_ptr<WwtDataHandler> _dataHandler;
|
||||
|
||||
// Callbacks for tiggering topic
|
||||
int _nextCallbackHandle = 0;
|
||||
std::vector<std::pair<CallbackHandle, CallbackFunction>> _preSyncCallbacks;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user