WIP
This commit is contained in:
parent
cfcf571bbd
commit
1509bf1a51
@ -7,6 +7,7 @@
|
||||
#include "interface/event.h"
|
||||
#include "interface/tcpsocket.h"
|
||||
#include "interface/packet_stream.h"
|
||||
#include "interface/magic_event.h"
|
||||
#include <Object.h>
|
||||
#include <Context.h>
|
||||
#include <Engine.h>
|
||||
@ -24,33 +25,9 @@ namespace magic = Urho3D;
|
||||
|
||||
namespace entitysync {
|
||||
|
||||
struct MagicEventHandler: public magic::Object
|
||||
{
|
||||
OBJECT(MagicEventHandler);
|
||||
|
||||
const char *MODULE = "entitysync";
|
||||
|
||||
MagicEventHandler(magic::Context *context):
|
||||
magic::Object(context)
|
||||
{
|
||||
SubscribeToEvent(magic::E_UPDATE, HANDLER(MagicEventHandler, on_update));
|
||||
SubscribeToEvent(magic::E_NODEADDED, HANDLER(MagicEventHandler, on_node_added));
|
||||
}
|
||||
|
||||
void on_update(magic::StringHash event_type, magic::VariantMap &event_data)
|
||||
{
|
||||
}
|
||||
|
||||
void on_node_added(magic::StringHash event_type, magic::VariantMap &event_data)
|
||||
{
|
||||
log_w(MODULE, "Node added");
|
||||
}
|
||||
};
|
||||
|
||||
struct Module: public interface::Module, public entitysync::Interface
|
||||
{
|
||||
interface::Server *m_server;
|
||||
magic::SharedPtr<MagicEventHandler> m_magic_event_handler;
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module("entitysync"),
|
||||
@ -71,12 +48,13 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
m_server->sub_event(this, Event::t("core:unload"));
|
||||
m_server->sub_event(this, Event::t("core:continue"));
|
||||
|
||||
/*m_server->sub_magic_event(this, magic::E_NODEADDED,
|
||||
Event::t("entitysync:node_added"));*/
|
||||
|
||||
m_server->access_scene([&](magic::Scene *scene)
|
||||
{
|
||||
magic::Context *context = scene->GetContext();
|
||||
|
||||
m_magic_event_handler = new MagicEventHandler(context);
|
||||
|
||||
/*magic::ResourceCache* cache =
|
||||
m_context->GetSubsystem<magic::ResourceCache>();
|
||||
|
||||
@ -90,9 +68,10 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
|
||||
void event(const Event::Type &type, const Event::Private *p)
|
||||
{
|
||||
EVENT_VOIDN("core:start", on_start)
|
||||
EVENT_VOIDN("core:unload", on_unload)
|
||||
EVENT_VOIDN("core:continue", on_continue)
|
||||
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)
|
||||
}
|
||||
|
||||
void on_start()
|
||||
@ -107,14 +86,7 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
{
|
||||
}
|
||||
|
||||
void on_update(magic::StringHash event_type, magic::VariantMap &event_data)
|
||||
{
|
||||
/*m_server->access_scene([&](magic::Scene *scene)
|
||||
{
|
||||
});*/
|
||||
}
|
||||
|
||||
void on_node_added(magic::StringHash event_type, magic::VariantMap &event_data)
|
||||
void on_node_added(const interface::MagicEvent &event)
|
||||
{
|
||||
log_w(MODULE, "Node added");
|
||||
/*m_server->access_scene([&](magic::Scene *scene)
|
||||
|
@ -8,6 +8,7 @@
|
||||
namespace Urho3D
|
||||
{
|
||||
class Scene;
|
||||
class StringHash;
|
||||
};
|
||||
|
||||
namespace interface
|
||||
@ -64,12 +65,15 @@ namespace interface
|
||||
|
||||
virtual void sub_event(struct Module *module, const Event::Type &type) = 0;
|
||||
virtual void emit_event(Event event) = 0;
|
||||
template<typename PrivateT>
|
||||
void emit_event(const ss_ &name, PrivateT *p){
|
||||
emit_event(std::move(Event(name, up_<Event::Private>(p))));
|
||||
template<typename TypeT, typename PrivateT>
|
||||
void emit_event(const TypeT &type, PrivateT *p){
|
||||
emit_event(std::move(Event(type, up_<Event::Private>(p))));
|
||||
}
|
||||
|
||||
virtual void access_scene(std::function<void(magic::Scene*)> cb) = 0;
|
||||
virtual void sub_magic_event(struct interface::Module *module,
|
||||
const magic::StringHash &event_type,
|
||||
const Event::Type &buildat_event_type) = 0;
|
||||
|
||||
virtual void add_socket_event(int fd, const Event::Type &event_type) = 0;
|
||||
virtual void remove_socket_event(int fd) = 0;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "interface/event.h"
|
||||
#include "interface/file_watch.h"
|
||||
#include "interface/fs.h"
|
||||
#include "interface/magic_event.h"
|
||||
//#include "interface/thread.h"
|
||||
#include "interface/mutex.h"
|
||||
#include <c55/string_util.h>
|
||||
@ -72,6 +73,34 @@ static sv_<ss_> list_includes(const ss_ &path, const sv_<ss_> &include_dirs)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*struct MagicEventHandler: public magic::Object
|
||||
{
|
||||
OBJECT(MagicEventHandler);
|
||||
|
||||
interface::Server *m_server;
|
||||
interface::Event::Type m_buildat_event_type;
|
||||
|
||||
MagicEventHandler(magic::Context *context,
|
||||
interface::Server *server,
|
||||
const magic::StringHash &eventType,
|
||||
const interface::Event::Type &buildat_event_type):
|
||||
magic::Object(context),
|
||||
m_server(server),
|
||||
m_buildat_event_type(buildat_event_type)
|
||||
{
|
||||
SubscribeToEvent(eventType, HANDLER(MagicEventHandler, on_event));
|
||||
}
|
||||
|
||||
void on_event(magic::StringHash event_type, magic::VariantMap &event_data)
|
||||
{
|
||||
auto *evreg = interface::getGlobalEventRegistry();
|
||||
log_w(MODULE, "MagicEventHandler::on_event(): %s (%zu)",
|
||||
cs(evreg->name(m_buildat_event_type)), m_buildat_event_type);
|
||||
m_server->emit_event(m_buildat_event_type, new interface::MagicEvent(
|
||||
event_type, event_data));
|
||||
}
|
||||
};*/
|
||||
|
||||
struct CState: public State, public interface::Server
|
||||
{
|
||||
struct ModuleContainer {
|
||||
@ -526,6 +555,18 @@ struct CState: public State, public interface::Server
|
||||
m_event_queue.push_back(std::move(event));
|
||||
}
|
||||
|
||||
void access_scene(std::function<void(magic::Scene*)> cb)
|
||||
{
|
||||
interface::MutexScope ms(m_magic_mutex);
|
||||
cb(m_magic_scene);
|
||||
}
|
||||
|
||||
void sub_magic_event(struct interface::Module *module,
|
||||
const magic::StringHash &eventType,
|
||||
const Event::Type &buildat_event_type)
|
||||
{
|
||||
}
|
||||
|
||||
void handle_events()
|
||||
{
|
||||
// Note: Locking m_modules_mutex here is not needed because no modules
|
||||
@ -652,12 +693,6 @@ struct CState: public State, public interface::Server
|
||||
} while(0);
|
||||
}
|
||||
|
||||
void access_scene(std::function<void(magic::Scene*)> cb)
|
||||
{
|
||||
interface::MutexScope ms(m_magic_mutex);
|
||||
cb(m_magic_scene);
|
||||
}
|
||||
|
||||
void tmp_store_data(const ss_ &name, const ss_ &data)
|
||||
{
|
||||
interface::MutexScope ms(m_tmp_data_mutex);
|
||||
|
@ -45,7 +45,6 @@ namespace server
|
||||
virtual void handle_events() = 0;
|
||||
virtual sv_<int> get_sockets() = 0;
|
||||
virtual void emit_socket_event(int fd) = 0;
|
||||
|
||||
virtual void access_scene(std::function<void(magic::Scene*)> cb) = 0;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user