Commit 3611dd05 authored by Micah's avatar Micah
Browse files

added events for when renderables are enabled/disabled that can be used to...

added events for when renderables are enabled/disabled that can be used to link renderables together
parent e6bbcbbd
Showing with 87 additions and 0 deletions
+87 -0
......@@ -35,6 +35,7 @@ namespace openspace {
class Camera;
class Layer;
class Profile;
class Renderable;
class SceneGraphNode;
class ScreenSpaceRenderable;
class Time;
......@@ -74,6 +75,8 @@ struct Event {
LayerRemoved,
SessionRecordingPlayback,
PointSpacecraft,
RenderableEnabled,
RenderableDisabled,
Custom
};
constexpr explicit Event(Type type_) : type(type_) {}
......@@ -397,6 +400,32 @@ struct EventPointSpacecraft : public Event {
const double duration;
};
/**
* This event is created whenever a renderable is enabled. By the
* time this event is signalled, the renderable has already been enabled.
*
* \param Node The identifier of the node that contains the renderable
*/
struct EventRenderableEnabled : public Event {
static const Type Type = Event::Type::RenderableEnabled;
explicit EventRenderableEnabled(const SceneGraphNode* node_);
const tstring node;
};
/**
* This event is created whenever a renderable is disabled. By the
* time this event is signalled, the renderable has already been disabled.
*
* \param Node The identifier of that node that contains the renderable
*/
struct EventRenderableDisabled : public Event {
static const Type Type = Event::Type::RenderableDisabled;
explicit EventRenderableDisabled(const SceneGraphNode* node_);
const tstring node;
};
/**
* 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
......
......@@ -184,6 +184,17 @@ void log(int i, const CustomEvent& e) {
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));
}
void log(int i, const EventRenderableDisabled& e) {
ghoul_assert(e.type == EventRenderableDisabled::Type, "Wrong type");
LINFO(fmt::format("[{}] EventRenderableDisabled: {}", i, e.node));
}
std::string_view toString(Event::Type type) {
switch (type) {
case Event::Type::SceneGraphNodeAdded: return "SceneGraphNodeAdded";
......@@ -204,6 +215,8 @@ std::string_view toString(Event::Type type) {
case Event::Type::LayerRemoved: return "LayerRemoved";
case Event::Type::SessionRecordingPlayback: return "SessionRecordingPlayback";
case Event::Type::PointSpacecraft: return "PointSpacecraft";
case Event::Type::RenderableEnabled: return "RenderableEnabled";
case Event::Type::RenderableDisabled: return "RenderableDisabled";
case Event::Type::Custom: return "Custom";
default:
throw ghoul::MissingCaseException();
......@@ -262,6 +275,12 @@ Event::Type fromString(std::string_view str) {
else if (str == "PointSpacecraft") {
return Event::Type::PointSpacecraft;
}
else if (str == "RenderableEnabled") {
return Event::Type::RenderableEnabled;
}
else if (str == "RenderableDisabled") {
return Event::Type::RenderableDisabled;
}
else if (str == "Custom") {
return Event::Type::Custom;
}
......@@ -428,6 +447,18 @@ ghoul::Dictionary toParameter(const Event& e) {
d.setValue("Dec", static_cast<const EventPointSpacecraft&>(e).dec);
d.setValue("Duration", static_cast<const EventPointSpacecraft&>(e).duration);
break;
case Event::Type::RenderableEnabled:
d.setValue(
"Node",
std::string(static_cast<const EventRenderableEnabled&>(e).node)
);
break;
case Event::Type::RenderableDisabled:
d.setValue(
"Node",
std::string(static_cast<const EventRenderableDisabled&>(e).node)
);
break;
case Event::Type::Custom:
d.setValue(
"Subtype", std::string(static_cast<const CustomEvent&>(e).subtype)
......@@ -497,6 +528,12 @@ void logAllEvents(const Event* e) {
case Event::Type::PointSpacecraft:
log(i, *static_cast<const EventPointSpacecraft*>(e));
break;
case Event::Type::RenderableEnabled:
log(i, *static_cast<const EventRenderableEnabled*>(e));
break;
case Event::Type::RenderableDisabled:
log(i, *static_cast<const EventRenderableDisabled*>(e));
break;
case Event::Type::Custom:
log(i, *static_cast<const CustomEvent*>(e));
break;
......@@ -616,6 +653,17 @@ EventPointSpacecraft::EventPointSpacecraft(double ra_, double dec_, double durat
, duration(duration_)
{}
EventRenderableEnabled::EventRenderableEnabled(const SceneGraphNode* node_)
: Event(Type)
, node(temporaryString(node_->identifier()))
{}
EventRenderableDisabled::EventRenderableDisabled(const SceneGraphNode* node_)
: Event(Type)
, node(temporaryString(node_->identifier()))
{}
CustomEvent::CustomEvent(std::string_view subtype_, std::string_view payload_)
: Event(Type)
, subtype(subtype_)
......
......@@ -27,6 +27,8 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/events/event.h>
#include <openspace/events/eventengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/memorymanager.h>
......@@ -168,6 +170,14 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary)
_enabled = p.enabled.value_or(_enabled);
addProperty(_enabled);
_enabled.onChange([this]() {
if (isEnabled()) {
global::eventEngine->publishEvent<events::EventRenderableEnabled>(_parent);
}
else {
global::eventEngine->publishEvent<events::EventRenderableDisabled>(_parent);
}
});
_opacity = p.opacity.value_or(_opacity);
// We don't add the property here as subclasses should decide on their own whether
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment