Add events when paths are started or finished (closes #1834)

This commit is contained in:
Alexander Bock
2023-03-11 17:20:20 +01:00
parent 3f35fa992a
commit ddcbe85b51
4 changed files with 68 additions and 8 deletions

View File

@@ -77,6 +77,8 @@ struct Event {
PointSpacecraft,
RenderableEnabled,
RenderableDisabled,
CameraPathStarted,
CameraPathFinished,
Custom
};
constexpr explicit Event(Type type_) : type(type_) {}
@@ -520,6 +522,30 @@ struct EventRenderableDisabled : public Event {
const tstring node;
};
/**
* This event is created when the a camera path is started
*/
struct EventCameraPathStarted : public Event {
static constexpr Type Type = Event::Type::CameraPathStarted;
/**
* Creates an instance of an EventCameraPathStarted event.
*/
EventCameraPathStarted();
};
/**
* This event is created when the a camera path is finished
*/
struct EventCameraPathFinished : public Event {
static constexpr Type Type = Event::Type::CameraPathFinished;
/**
* Creates an instance of an EventCameraPathStarted event.
*/
EventCameraPathFinished();
};
/**
* A custom event type that can be used in a pinch when no explicit event type is
* available. This should only be used in special circumstances and it should be

View File

@@ -76,7 +76,7 @@ public:
CameraPose traversePath(double dt, float speedScale = 1.f);
/**
* Function that can be used to permaturely quit a path ,for example when skipping
* Function that can be used to permaturely quit a path, for example when skipping
* to the end
*/
void quitPath();

View File

@@ -179,11 +179,6 @@ void log(int i, const EventPointSpacecraft& e) {
));
}
void log(int i, const CustomEvent& e) {
ghoul_assert(e.type == CustomEvent::Type, "Wrong type");
LINFO(fmt::format("[{}] CustomEvent: {} ({})", i, e.subtype, e.payload));
}
void log(int i, const EventRenderableEnabled& e) {
ghoul_assert(e.type == EventRenderableEnabled::Type, "Wrong type");
LINFO(fmt::format("[{}] EventRenderableEnabled: {}", i, e.node));
@@ -194,6 +189,20 @@ void log(int i, const EventRenderableDisabled& e) {
LINFO(fmt::format("[{}] EventRenderableDisabled: {}", i, e.node));
}
void log(int i, const EventCameraPathStarted& e) {
ghoul_assert(e.type == EventCameraPathStarted::Type, "Wrong type");
LINFO(fmt::format("[{}] EventCameraPathStarted", i));
}
void log(int i, const EventCameraPathFinished& e) {
ghoul_assert(e.type == EventCameraPathFinished::Type, "Wrong type");
LINFO(fmt::format("[{}] EventCameraPathFinished", i));
}
void log(int i, const CustomEvent& e) {
ghoul_assert(e.type == CustomEvent::Type, "Wrong type");
LINFO(fmt::format("[{}] CustomEvent: {} ({})", i, e.subtype, e.payload));
}
std::string_view toString(Event::Type type) {
switch (type) {
@@ -217,6 +226,8 @@ std::string_view toString(Event::Type type) {
case Event::Type::PointSpacecraft: return "PointSpacecraft";
case Event::Type::RenderableEnabled: return "RenderableEnabled";
case Event::Type::RenderableDisabled: return "RenderableDisabled";
case Event::Type::CameraPathStarted: return "CameraPathStarted";
case Event::Type::CameraPathFinished: return "CameraPathFinished";
case Event::Type::Custom: return "Custom";
default:
throw ghoul::MissingCaseException();
@@ -281,6 +292,12 @@ Event::Type fromString(std::string_view str) {
else if (str == "RenderableDisabled") {
return Event::Type::RenderableDisabled;
}
else if (str == "CameraPathStarted") {
return Event::Type::CameraPathStarted;
}
else if (str == "CameraPathFinished") {
return Event::Type::CameraPathFinished;
}
else if (str == "Custom") {
return Event::Type::Custom;
}
@@ -534,6 +551,12 @@ void logAllEvents(const Event* e) {
case Event::Type::RenderableDisabled:
log(i, *static_cast<const EventRenderableDisabled*>(e));
break;
case Event::Type::CameraPathStarted:
log(i, *static_cast<const EventCameraPathStarted*>(e));
break;
case Event::Type::CameraPathFinished:
log(i, *static_cast<const EventCameraPathFinished*>(e));
break;
case Event::Type::Custom:
log(i, *static_cast<const CustomEvent*>(e));
break;
@@ -662,6 +685,13 @@ EventRenderableDisabled::EventRenderableDisabled(const SceneGraphNode* node_)
, node(temporaryString(node_->identifier()))
{}
EventCameraPathStarted::EventCameraPathStarted()
: Event(Type)
{}
EventCameraPathFinished::EventCameraPathFinished()
: Event(Type)
{}
CustomEvent::CustomEvent(std::string_view subtype_, std::string_view payload_)
: Event(Type)

View File

@@ -29,6 +29,7 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/events/eventengine.h>
#include <openspace/navigation/navigationhandler.h>
#include <openspace/navigation/navigationstate.h>
#include <openspace/navigation/pathnavigator.h>
@@ -47,7 +48,6 @@
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/vector_angle.hpp>
#include <vector>
#include "pathnavigator_lua.inl"
namespace {
@@ -300,7 +300,8 @@ void PathNavigator::startPath() {
return;
}
if (!global::openSpaceEngine->setMode(OpenSpaceEngine::Mode::CameraPath)) {
bool success = global::openSpaceEngine->setMode(OpenSpaceEngine::Mode::CameraPath);
if (!success) {
LERROR("Could not start camera path");
return; // couldn't switch to camera path mode
}
@@ -323,6 +324,7 @@ void PathNavigator::startPath() {
global::navigationHandler->orbitalNavigator().updateOnCameraInteraction();
global::navigationHandler->orbitalNavigator().resetVelocities();
global::eventEngine->publishEvent<events::EventCameraPathStarted>();
}
void PathNavigator::abortPath() {
@@ -453,6 +455,8 @@ void PathNavigator::handlePathEnd() {
openspace::scripting::ScriptEngine::RemoteScripting::Yes
);
}
global::eventEngine->publishEvent<events::EventCameraPathFinished>();
}
void PathNavigator::findRelevantNodes() {