Adds funny casting to avoid pedantic ISO C warning
This commit is contained in:
parent
fd3a625249
commit
3e43c30bcb
26
src/event.c
26
src/event.c
|
@ -22,25 +22,27 @@
|
||||||
|
|
||||||
static LinkedList *callbacks = NULL;
|
static LinkedList *callbacks = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
event_register_listener(EventCallback cb)
|
event_register_listener(EventCallback cb)
|
||||||
{
|
{
|
||||||
linkedlist_append(&callbacks, cb);
|
// Cast a pointer to a pointer to avoid -wpedantic iso warning
|
||||||
|
linkedlist_append(&callbacks, *(void**)(&cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
event_clear_listeners(void)
|
event_clear_listeners(void)
|
||||||
{
|
{
|
||||||
while (callbacks)
|
while (callbacks)
|
||||||
linkedlist_pop(&callbacks);
|
linkedlist_pop(&callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
event_trigger(Event *event)
|
event_trigger(Event *event)
|
||||||
{
|
{
|
||||||
LinkedList *cbs = callbacks;
|
LinkedList *cbs = callbacks;
|
||||||
while (cbs) {
|
while (cbs) {
|
||||||
((EventCallback) cbs->data)(event);
|
// Reverse the cast from the register (-pedantic ISO warning)
|
||||||
cbs = cbs->next;
|
(*(EventCallback*)(&cbs->data))(event);
|
||||||
}
|
cbs = cbs->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
14
src/event.h
14
src/event.h
|
@ -21,18 +21,18 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
typedef enum EventType {
|
typedef enum EventType {
|
||||||
MONSTER_KILLED_EVENT
|
MONSTER_KILLED_EVENT
|
||||||
} EventType;
|
} EventType;
|
||||||
|
|
||||||
typedef struct MonsterKilledEvent {
|
typedef struct MonsterKilledEvent {
|
||||||
EventType *type;
|
EventType *type;
|
||||||
Player *player;
|
Player *player;
|
||||||
Monster *monster;
|
Monster *monster;
|
||||||
} MonsterKilledEvent;
|
} MonsterKilledEvent;
|
||||||
|
|
||||||
typedef union Event {
|
typedef union Event {
|
||||||
EventType type;
|
EventType type;
|
||||||
MonsterKilledEvent monsterKilled;
|
MonsterKilledEvent monsterKilled;
|
||||||
} Event;
|
} Event;
|
||||||
|
|
||||||
typedef void (*EventCallback)(Event*);
|
typedef void (*EventCallback)(Event*);
|
||||||
|
@ -44,4 +44,4 @@ void
|
||||||
event_clear_listeners(void);
|
event_clear_listeners(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
event_trigger(Event *event);
|
event_trigger(Event *event);
|
||||||
|
|
Loading…
Reference in New Issue