server/state, builtin/entitysync: Tracking of node and component changes works
This commit is contained in:
parent
fa261d74d9
commit
a2d430d35f
@ -50,6 +50,12 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
|
||||
m_server->sub_magic_event(this, magic::E_NODEADDED,
|
||||
Event::t("entitysync:node_added"));
|
||||
m_server->sub_magic_event(this, magic::E_NODEREMOVED,
|
||||
Event::t("entitysync:node_removed"));
|
||||
m_server->sub_magic_event(this, magic::E_COMPONENTADDED,
|
||||
Event::t("entitysync:component_added"));
|
||||
m_server->sub_magic_event(this, magic::E_COMPONENTREMOVED,
|
||||
Event::t("entitysync:component_removed"));
|
||||
|
||||
m_server->access_scene([&](magic::Scene *scene)
|
||||
{
|
||||
@ -71,7 +77,14 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
EVENT_VOIDN("core:start", on_start)
|
||||
EVENT_VOIDN("core:unload", on_unload)
|
||||
EVENT_VOIDN("core:continue", on_continue)
|
||||
EVENT_TYPEN("entitysync:node_added", on_node_added, interface::MagicEvent)
|
||||
EVENT_TYPEN("entitysync:node_added",
|
||||
on_node_added, interface::MagicEvent)
|
||||
EVENT_TYPEN("entitysync:node_removed",
|
||||
on_node_removed, interface::MagicEvent)
|
||||
EVENT_TYPEN("entitysync:component_added",
|
||||
on_component_added, interface::MagicEvent)
|
||||
EVENT_TYPEN("entitysync:component_removed",
|
||||
on_component_removed, interface::MagicEvent)
|
||||
}
|
||||
|
||||
void on_start()
|
||||
@ -88,10 +101,26 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
|
||||
void on_node_added(const interface::MagicEvent &event)
|
||||
{
|
||||
log_w(MODULE, "Node added");
|
||||
/*m_server->access_scene([&](magic::Scene *scene)
|
||||
{
|
||||
});*/
|
||||
magic::VariantMap event_data = event.magic_data;
|
||||
log_w(MODULE, "Node added: %i", event_data["NodeID"].GetInt());
|
||||
}
|
||||
|
||||
void on_node_removed(const interface::MagicEvent &event)
|
||||
{
|
||||
magic::VariantMap event_data = event.magic_data;
|
||||
log_w(MODULE, "Node removed: %i", event_data["NodeID"].GetInt());
|
||||
}
|
||||
|
||||
void on_component_added(const interface::MagicEvent &event)
|
||||
{
|
||||
magic::VariantMap event_data = event.magic_data;
|
||||
log_w(MODULE, "Component added: %i", event_data["ComponentID"].GetInt());
|
||||
}
|
||||
|
||||
void on_component_removed(const interface::MagicEvent &event)
|
||||
{
|
||||
magic::VariantMap event_data = event.magic_data;
|
||||
log_w(MODULE, "Component removed: %i", event_data["ComponentID"].GetInt());
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
@ -16,10 +16,10 @@ namespace interface
|
||||
namespace magic = Urho3D;
|
||||
|
||||
struct MagicEvent: public interface::Event::Private {
|
||||
magic::StringHash event_type;
|
||||
magic::VariantMap event_data;
|
||||
MagicEvent(magic::StringHash event_type, const magic::VariantMap &event_data):
|
||||
event_type(event_type), event_data(event_data){}
|
||||
magic::StringHash magic_type;
|
||||
magic::VariantMap magic_data;
|
||||
MagicEvent(magic::StringHash magic_type, const magic::VariantMap &magic_data):
|
||||
magic_type(magic_type), magic_data(magic_data){}
|
||||
};
|
||||
}
|
||||
// vim: set noet ts=4 sw=4:
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include <Context.h>
|
||||
#include <Engine.h>
|
||||
#include <Scene.h>
|
||||
#include <SceneEvents.h>
|
||||
#include <Component.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
@ -98,6 +100,30 @@ struct MagicEventHandler: public magic::Object
|
||||
log_d(MODULE, "MagicEventHandler::on_event(): %s (%zu)",
|
||||
cs(evreg->name(m_buildat_event_type)), m_buildat_event_type);
|
||||
}
|
||||
// Convert pointers to IDs because the event will be queued for later
|
||||
// handling and pointers may become invalid
|
||||
if(event_type == magic::E_NODEADDED ||
|
||||
event_type == magic::E_NODEREMOVED){
|
||||
magic::Node *parent = static_cast<magic::Node*>(
|
||||
event_data["Parent"].Get<void*>());
|
||||
event_data["ParentID"] = parent->GetID();
|
||||
event_data.Erase("Parent");
|
||||
magic::Node *node = static_cast<magic::Node*>(
|
||||
event_data["Node"].Get<void*>());
|
||||
event_data["NodeID"] = node->GetID();
|
||||
event_data.Erase("Node");
|
||||
}
|
||||
if(event_type == magic::E_COMPONENTADDED ||
|
||||
event_type == magic::E_COMPONENTREMOVED){
|
||||
magic::Node *node = static_cast<magic::Node*>(
|
||||
event_data["Node"].Get<void*>());
|
||||
event_data["NodeID"] = node->GetID();
|
||||
event_data.Erase("Node");
|
||||
magic::Component *c = static_cast<magic::Component*>(
|
||||
event_data["Component"].Get<void*>());
|
||||
event_data["ComponentID"] = c->GetID();
|
||||
event_data.Erase("Component");
|
||||
}
|
||||
m_server->emit_event(m_buildat_event_type, new interface::MagicEvent(
|
||||
event_type, event_data));
|
||||
}
|
||||
@ -571,7 +597,7 @@ struct CState: public State, public interface::Server
|
||||
{
|
||||
{
|
||||
interface::MutexScope ms(m_magic_mutex);
|
||||
m_magic_event_handlers[event_type] = new MagicEventHandler(
|
||||
m_magic_event_handlers[buildat_event_type] = new MagicEventHandler(
|
||||
m_magic_context, this, event_type, buildat_event_type);
|
||||
}
|
||||
sub_event(module, buildat_event_type);
|
||||
|
Loading…
x
Reference in New Issue
Block a user