163 lines
9.0 KiB
C
163 lines
9.0 KiB
C
#pragma once
|
|
|
|
#include <event/event_bus.h>
|
|
|
|
#define E2D_EVENT_BUS_NAME_(n) n##_Bus
|
|
|
|
/**
|
|
* @brief 声明事件总线
|
|
*/
|
|
#define DECLARE_EVENT_BUS(BusName) \
|
|
struct BusName##_Bus { \
|
|
static constexpr const char *NAME = #BusName; \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明无参数事件
|
|
*/
|
|
#define DECLARE_EVENT_0(EventName, BusName) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName)> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit() { ::extra2d::event::broadcast<EventName>(); } \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明单参数事件
|
|
*/
|
|
#define DECLARE_EVENT_1(EventName, BusName, Arg0) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0) { \
|
|
::extra2d::event::broadcast<EventName>(arg0); \
|
|
} \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明双参数事件
|
|
*/
|
|
#define DECLARE_EVENT_2(EventName, BusName, Arg0, Arg1) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0, \
|
|
Arg1> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0, Arg1 arg1) { \
|
|
::extra2d::event::broadcast<EventName>(arg0, arg1); \
|
|
} \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明三参数事件
|
|
*/
|
|
#define DECLARE_EVENT_3(EventName, BusName, Arg0, Arg1, Arg2) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0, Arg1, \
|
|
Arg2> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0, Arg1 arg1, Arg2 arg2) { \
|
|
::extra2d::event::broadcast<EventName>(arg0, arg1, arg2); \
|
|
} \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明四参数事件
|
|
*/
|
|
#define DECLARE_EVENT_4(EventName, BusName, Arg0, Arg1, Arg2, Arg3) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0, Arg1, \
|
|
Arg2, Arg3> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0, Arg1 arg1, Arg2 arg2, Arg3 arg3) { \
|
|
::extra2d::event::broadcast<EventName>(arg0, arg1, arg2, arg3); \
|
|
} \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明五参数事件
|
|
*/
|
|
#define DECLARE_EVENT_5(EventName, BusName, Arg0, Arg1, Arg2, Arg3, Arg4) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0, Arg1, \
|
|
Arg2, Arg3, Arg4> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) { \
|
|
::extra2d::event::broadcast<EventName>(arg0, arg1, arg2, arg3, arg4); \
|
|
} \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明六参数事件
|
|
*/
|
|
#define DECLARE_EVENT_6(EventName, BusName, Arg0, Arg1, Arg2, Arg3, Arg4, \
|
|
Arg5) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0, Arg1, \
|
|
Arg2, Arg3, Arg4, Arg5> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, \
|
|
Arg5 arg5) { \
|
|
::extra2d::event::broadcast<EventName>(arg0, arg1, arg2, arg3, arg4, \
|
|
arg5); \
|
|
} \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明七参数事件
|
|
*/
|
|
#define DECLARE_EVENT_7(EventName, BusName, Arg0, Arg1, Arg2, Arg3, Arg4, \
|
|
Arg5, Arg6) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0, Arg1, \
|
|
Arg2, Arg3, Arg4, Arg5, Arg6> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, \
|
|
Arg5 arg5, Arg6 arg6) { \
|
|
::extra2d::event::broadcast<EventName>(arg0, arg1, arg2, arg3, arg4, \
|
|
arg5, arg6); \
|
|
} \
|
|
};
|
|
|
|
/**
|
|
* @brief 声明八参数事件
|
|
*/
|
|
#define DECLARE_EVENT_8(EventName, BusName, Arg0, Arg1, Arg2, Arg3, Arg4, \
|
|
Arg5, Arg6, Arg7) \
|
|
struct EventName \
|
|
: ::extra2d::event::EventTrait<E2D_EVENT_BUS_NAME_(BusName), Arg0, Arg1, \
|
|
Arg2, Arg3, Arg4, Arg5, Arg6, Arg7> { \
|
|
using Listener = ::extra2d::event::Listener<EventName>; \
|
|
static constexpr const char *NAME = #EventName; \
|
|
static constexpr const char *BUS_NAME = \
|
|
E2D_EVENT_BUS_NAME_(BusName)::NAME; \
|
|
static void emit(Arg0 arg0, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, \
|
|
Arg5 arg5, Arg6 arg6, Arg7 arg7) { \
|
|
::extra2d::event::broadcast<EventName>(arg0, arg1, arg2, arg3, arg4, \
|
|
arg5, arg6, arg7); \
|
|
} \
|
|
};
|