Moved spawner to OnGameUpdate hook

This commit is contained in:
KiritoDv
2024-12-28 01:31:13 -06:00
committed by Lywx
parent 4dd2eb6eb6
commit 7cfa58117d
5 changed files with 58 additions and 18 deletions
+11 -3
View File
@@ -5,6 +5,7 @@
#include <stddef.h>
typedef uint16_t EventID;
typedef uint32_t ListenerID;
typedef enum {
EVENT_TYPE_PRE,
@@ -23,6 +24,11 @@ typedef struct {
typedef void (*EventCallback)(IEvent*);
typedef struct {
EventPriority priority;
EventCallback function;
} EventListener;
// ID Type
// 000000000000000 0
#define EVENT_ID(id, type) ((id << 1) | type)
@@ -34,12 +40,14 @@ typedef void (*EventCallback)(IEvent*);
class EventSystem {
public:
static EventSystem* Instance;
size_t RegisterListener(EventID id, EventPriority priority, EventCallback callback);
ListenerID RegisterListener(EventID id, EventCallback callback, EventPriority priority = EVENT_PRIORITY_NORMAL);
void UnregisterListener(EventID ev, ListenerID id);
void CallEvent(EventID id, IEvent* event);
private:
std::array<std::vector<EventCallback>, 0xFFFF> mEventListeners;
std::array<std::vector<EventListener>, 0xFFFF> mEventListeners;
};
#else
extern size_t EventSystem_RegisterListener(EventID id, EventPriority priority, EventCallback callback);
extern ListenerID EventSystem_RegisterListener(EventID id, EventCallback callback, EventPriority priority);
extern void EventSystem_UnregisterListener(EventID ev, ListenerID id);
extern void EventSystem_CallEvent(EventID id, void* event);
#endif