Merge branch 'master' into feature/general-performance

# Conflicts:
#	apps/OpenSpace/main.cpp
#	modules/server/src/topics/timetopic.cpp
This commit is contained in:
Alexander Bock
2020-09-04 13:49:00 +02:00
18 changed files with 289 additions and 295 deletions

View File

@@ -33,7 +33,6 @@ set(HEADER_FILES
include/serverinterface.h
include/topics/authorizationtopic.h
include/topics/bouncetopic.h
include/topics/deltatimestepstopic.h
include/topics/documentationtopic.h
include/topics/flightcontrollertopic.h
include/topics/getpropertytopic.h
@@ -57,7 +56,6 @@ set(SOURCE_FILES
src/serverinterface.cpp
src/topics/authorizationtopic.cpp
src/topics/bouncetopic.cpp
src/topics/deltatimestepstopic.cpp
src/topics/documentationtopic.cpp
src/topics/flightcontrollertopic.cpp
src/topics/getpropertytopic.cpp

View File

@@ -1,57 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* 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___DELTA_TIME_STEPS_TOPIC___H__
#define __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__
#include <modules/server/include/topics/topic.h>
#include <optional>
namespace openspace {
class DeltaTimeStepsTopic : public Topic {
public:
DeltaTimeStepsTopic();
virtual ~DeltaTimeStepsTopic();
void handleJson(const nlohmann::json& json) override;
bool isDone() const override;
private:
const int UnsetOnChangeHandle = -1;
bool dataHasChanged();
void sendDeltaTimesData();
int _deltaTimeCallbackHandle = UnsetOnChangeHandle;
int _deltaTimesListCallbackHandle = UnsetOnChangeHandle;
bool _isDone = false;
std::optional<double> _lastNextDeltaTime = std::nullopt;
std::optional<double> _lastPrevDeltaTime = std::nullopt;
};
} // namespace openspace
#endif // __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__

View File

@@ -41,16 +41,21 @@ public:
private:
const int UnsetOnChangeHandle = -1;
const nlohmann::json getNextPrevDeltaTimeStepJson();
void sendCurrentTime();
void sendFullTimeData();
void sendDeltaTimeSteps();
int _timeCallbackHandle = UnsetOnChangeHandle;
int _deltaTimeCallbackHandle = UnsetOnChangeHandle;
int _deltaTimeStepsCallbackHandle = UnsetOnChangeHandle;
bool _isDone = false;
std::chrono::system_clock::time_point _lastUpdateTime;
bool _lastPauseState = false;
double _lastTargetDeltaTime = 0.0;
std::vector<double> _lastDeltaTimeSteps;
};
} // namespace openspace

View File

@@ -26,7 +26,6 @@
#include <modules/server/include/topics/authorizationtopic.h>
#include <modules/server/include/topics/bouncetopic.h>
#include <modules/server/include/topics/deltatimestepstopic.h>
#include <modules/server/include/topics/documentationtopic.h>
#include <modules/server/include/topics/flightcontrollertopic.h>
#include <modules/server/include/topics/getpropertytopic.h>
@@ -57,7 +56,6 @@ namespace {
constexpr const char* VersionTopicKey = "version";
constexpr const char* AuthenticationTopicKey = "authorize";
constexpr const char* DeltaTimeStepsTopicKey = "deltatimesteps";
constexpr const char* DocumentationTopicKey = "documentation";
constexpr const char* GetPropertyTopicKey = "get";
constexpr const char* LuaScriptTopicKey = "luascript";
@@ -97,7 +95,6 @@ Connection::Connection(std::unique_ptr<ghoul::io::Socket> s,
);
_topicFactory.registerClass<DocumentationTopic>(DocumentationTopicKey);
_topicFactory.registerClass<DeltaTimeStepsTopic>(DeltaTimeStepsTopicKey);
_topicFactory.registerClass<GetPropertyTopic>(GetPropertyTopicKey);
_topicFactory.registerClass<LuaScriptTopic>(LuaScriptTopicKey);
_topicFactory.registerClass<SessionRecordingTopic>(SessionRecordingTopicKey);
@@ -142,7 +139,7 @@ void Connection::handleMessage(const std::string& message) {
message.end(),
sanitizedString.begin(),
[](wchar_t c) {
return std::isprint(c, std::locale("")) ? c : ' ';
return std::isprint(c, std::locale("")) ? char(c) : ' ';
}
);
LERROR(fmt::format("Could not parse JSON: '{}'", sanitizedString));

View File

@@ -1,127 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* 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/deltatimestepstopic.h"
#include <modules/server/include/connection.h>
#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 {
constexpr const char* EventKey = "event";
constexpr const char* SubscribeEvent = "start_subscription";
constexpr const char* UnsubscribeEvent = "stop_subscription";
} // namespace
using nlohmann::json;
namespace openspace {
DeltaTimeStepsTopic::DeltaTimeStepsTopic() {}
DeltaTimeStepsTopic::~DeltaTimeStepsTopic() {
if (_deltaTimeCallbackHandle != UnsetOnChangeHandle) {
global::timeManager.removeDeltaTimeChangeCallback(
_deltaTimeCallbackHandle
);
}
if (_deltaTimesListCallbackHandle != UnsetOnChangeHandle) {
global::timeManager.removeDeltaTimeStepsChangeCallback(
_deltaTimesListCallbackHandle
);
}
}
bool DeltaTimeStepsTopic::isDone() const {
return _isDone;
}
bool DeltaTimeStepsTopic::dataHasChanged() {
std::optional<double> nextStep = global::timeManager.nextDeltaTimeStep();
std::optional<double> prevStep = global::timeManager.previousDeltaTimeStep();
return (nextStep != _lastNextDeltaTime || prevStep != _lastPrevDeltaTime);
}
void DeltaTimeStepsTopic::handleJson(const nlohmann::json& json) {
std::string event = json.at(EventKey).get<std::string>();
if (event == UnsubscribeEvent) {
_isDone = true;
return;
}
sendDeltaTimesData();
if (event != SubscribeEvent) {
_isDone = true;
return;
}
_deltaTimeCallbackHandle = global::timeManager.addDeltaTimeChangeCallback(
[this]() {
if (dataHasChanged()) {
sendDeltaTimesData();
}
}
);
_deltaTimesListCallbackHandle = global::timeManager.addDeltaTimeStepsChangeCallback(
[this]() {
if (dataHasChanged()) {
sendDeltaTimesData();
}
}
);
}
void DeltaTimeStepsTopic::sendDeltaTimesData() {
std::optional<double> nextStep = global::timeManager.nextDeltaTimeStep();
std::optional<double> prevStep = global::timeManager.previousDeltaTimeStep();
bool hasNext = nextStep.has_value();
bool hasPrev = prevStep.has_value();
json deltaTimesListJson = {
{ "hasNextStep", hasNext },
{ "hasPrevStep", hasPrev }
};
if (hasNext) {
deltaTimesListJson["nextStep"] = nextStep.value();
}
if (hasPrev) {
deltaTimesListJson["prevStep"] = prevStep.value();
}
_connection->sendJson(wrappedPayload(deltaTimesListJson));
_lastNextDeltaTime = nextStep;
_lastPrevDeltaTime = prevStep;
}
} // namespace openspace

View File

@@ -303,12 +303,10 @@ void FlightControllerTopic::changeFocus(const nlohmann::json& json) const {
fmt::format("Could not find {} key in JSON. JSON was:\n{}", FocusKey, j)
);
if (json.find(AimKey) == json.end()) {
const std::string j = json;
LWARNING(
fmt::format("Could not find {} key in JSON. JSON was:\n{}", AimKey, j)
);
if (json.find(AnchorKey) == json.end()) {
const std::string j = json;
LWARNING(fmt::format(
"Could not find {} key in JSON. JSON was:\n{}", AnchorKey, j
));

View File

@@ -30,7 +30,6 @@
#include <openspace/query/query.h>
#include <openspace/util/timemanager.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.h>
namespace {
constexpr const char* EventKey = "event";
@@ -54,6 +53,9 @@ TimeTopic::~TimeTopic() {
if (_deltaTimeCallbackHandle != UnsetOnChangeHandle) {
global::timeManager.removeDeltaTimeChangeCallback(_deltaTimeCallbackHandle);
}
if (_deltaTimeStepsCallbackHandle != UnsetOnChangeHandle) {
global::timeManager.removeDeltaTimeStepsChangeCallback(_deltaTimeStepsCallbackHandle);
}
}
bool TimeTopic::isDone() const {
@@ -68,6 +70,7 @@ void TimeTopic::handleJson(const nlohmann::json& json) {
}
sendFullTimeData();
sendDeltaTimeSteps();
if (event != SubscribeEvent) {
_isDone = true;
@@ -95,6 +98,37 @@ void TimeTopic::handleJson(const nlohmann::json& json) {
sendFullTimeData();
}
});
_deltaTimeStepsCallbackHandle = global::timeManager.addDeltaTimeStepsChangeCallback(
[this]() {
const std::vector<double> steps = global::timeManager.deltaTimeSteps();
if (steps != _lastDeltaTimeSteps) {
sendDeltaTimeSteps();
}
}
);
}
const json TimeTopic::getNextPrevDeltaTimeStepJson() {
const std::optional<double> nextStep = global::timeManager.nextDeltaTimeStep();
const std::optional<double> prevStep = global::timeManager.previousDeltaTimeStep();
const bool hasNext = nextStep.has_value();
const bool hasPrev = prevStep.has_value();
json nextPrevJson = {
{ "hasNextStep", hasNext },
{ "hasPrevStep", hasPrev }
};
if (hasNext) {
nextPrevJson["nextStep"] = nextStep.value();
}
if (hasPrev) {
nextPrevJson["prevStep"] = prevStep.value();
}
return nextPrevJson;
}
void TimeTopic::sendCurrentTime() {
@@ -114,17 +148,34 @@ void TimeTopic::sendFullTimeData() {
const double targetDeltaTime = global::timeManager.targetDeltaTime();
const bool isPaused = global::timeManager.isPaused();
const json timeJson = {
json timeJson = {
{ "time", currentTime },
{ "deltaTime", deltaTime},
{ "targetDeltaTime", targetDeltaTime},
{ "isPaused", isPaused },
{ "isPaused", isPaused }
};
const json nextPrevJson = getNextPrevDeltaTimeStepJson();
timeJson.insert(nextPrevJson.begin(), nextPrevJson.end());
_connection->sendJson(wrappedPayload(timeJson));
_lastUpdateTime = std::chrono::system_clock::now();
_lastPauseState = isPaused;
_lastTargetDeltaTime = targetDeltaTime;
}
void TimeTopic::sendDeltaTimeSteps() {
const std::vector<double>& steps = global::timeManager.deltaTimeSteps();
json deltaTimeStepsJson = {
{ "deltaTimeSteps", steps }
};
const json nextPrevJson = getNextPrevDeltaTimeStepJson();
deltaTimeStepsJson.insert(nextPrevJson.begin(), nextPrevJson.end());
_connection->sendJson(wrappedPayload(deltaTimeStepsJson));
_lastDeltaTimeSteps = steps;
}
} // namespace openspace