dispatcher: uses type_id_v rather than a family
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#define CR_HOST
|
||||
|
||||
#include <cr.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/utility.hpp>
|
||||
#include <entt/signal/dispatcher.hpp>
|
||||
#include "types.h"
|
||||
|
||||
struct listener {
|
||||
void on(event ev) { value = ev.payload; }
|
||||
void on(message msg) { value = msg.payload; }
|
||||
int value{};
|
||||
};
|
||||
|
||||
TEST(Lib, Dispatcher) {
|
||||
entt::dispatcher dispatcher;
|
||||
listener listener;
|
||||
|
||||
dispatcher.sink<event>().connect<entt::overload<void(event)>(&listener::on)>(listener);
|
||||
dispatcher.sink<message>().connect<entt::overload<void(message)>(&listener::on)>(listener);
|
||||
dispatcher.trigger<event>(3);
|
||||
|
||||
ASSERT_EQ(listener.value, 3);
|
||||
|
||||
cr_plugin ctx;
|
||||
ctx.userdata = &dispatcher;
|
||||
cr_plugin_load(ctx, PLUGIN);
|
||||
cr_plugin_update(ctx);
|
||||
|
||||
ASSERT_EQ(listener.value, 42);
|
||||
|
||||
cr_plugin_close(ctx);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <cr.h>
|
||||
#include <entt/signal/dispatcher.hpp>
|
||||
#include "types.h"
|
||||
|
||||
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
|
||||
switch (operation) {
|
||||
case CR_STEP:
|
||||
static_cast<entt::dispatcher *>(ctx->userdata)->trigger<message>(42);
|
||||
break;
|
||||
case CR_LOAD:
|
||||
case CR_UNLOAD:
|
||||
case CR_CLOSE:
|
||||
// nothing to do here, this is only a test.
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef ENTT_PLUGIN_DISPATCHER_TYPES_H
|
||||
#define ENTT_PLUGIN_DISPATCHER_TYPES_H
|
||||
|
||||
struct message {
|
||||
int payload;
|
||||
};
|
||||
|
||||
struct event {
|
||||
int payload;
|
||||
};
|
||||
|
||||
#endif // ENTT_PLUGIN_DISPATCHER_TYPES_H
|
||||
|
||||
Reference in New Issue
Block a user