Kohi Game Engine
|
This file contains structures and functions specific to the event system. Events are a mechenism that allows the developer to send and recieve data at critical points in the execution of the application in a non- coupled way. For now, this follows a simple pub-sub model of event transmission. More...
#include "defines.h"
Go to the source code of this file.
Data Structures | |
struct | event_context |
Represents event contextual data to be sent along with an event code when an event is fired. It is a union that is 128 bits in size, meaning data can be mixed and matched as required by the developer. More... | |
Typedefs | |
typedef struct event_context | event_context |
Represents event contextual data to be sent along with an event code when an event is fired. It is a union that is 128 bits in size, meaning data can be mixed and matched as required by the developer. More... | |
typedef b8(* | PFN_on_event) (u16 code, void *sender, void *listener_inst, event_context data) |
A function pointer typedef which is used for event subscriptions by the subscriber. More... | |
typedef enum system_event_code | system_event_code |
System internal event codes. Application should use codes beyond 255. More... | |
Enumerations | |
enum | system_event_code { EVENT_CODE_APPLICATION_QUIT = 0x01 , EVENT_CODE_KEY_PRESSED = 0x02 , EVENT_CODE_KEY_RELEASED = 0x03 , EVENT_CODE_BUTTON_PRESSED = 0x04 , EVENT_CODE_BUTTON_RELEASED = 0x05 , EVENT_CODE_MOUSE_MOVED = 0x06 , EVENT_CODE_MOUSE_WHEEL = 0x07 , EVENT_CODE_RESIZED = 0x08 , EVENT_CODE_SET_RENDER_MODE = 0x0A , EVENT_CODE_DEBUG0 = 0x10 , EVENT_CODE_DEBUG1 = 0x11 , EVENT_CODE_DEBUG2 = 0x12 , EVENT_CODE_DEBUG3 = 0x13 , EVENT_CODE_DEBUG4 = 0x14 , EVENT_CODE_OBJECT_HOVER_ID_CHANGED = 0x15 , EVENT_CODE_DEFAULT_RENDERTARGET_REFRESH_REQUIRED = 0x16 , EVENT_CODE_KVAR_CHANGED = 0x17 , EVENT_CODE_WATCHED_FILE_WRITTEN = 0x18 , EVENT_CODE_WATCHED_FILE_DELETED = 0x19 , EVENT_CODE_MOUSE_DRAGGED = 0x20 , EVENT_CODE_MOUSE_DRAG_BEGIN = 0x21 , EVENT_CODE_MOUSE_DRAG_END = 0x22 , MAX_EVENT_CODE = 0xFF } |
System internal event codes. Application should use codes beyond 255. More... | |
Functions | |
b8 | event_system_initialize (u64 *memory_requirement, void *state, void *config) |
Initializes the event system. More... | |
void | event_system_shutdown (void *state) |
Shuts the event system down. More... | |
KAPI b8 | event_register (u16 code, void *listener, PFN_on_event on_event) |
Register to listen for when events are sent with the provided code. Events with duplicate listener/callback combos will not be registered again and will cause this to return false. More... | |
KAPI b8 | event_unregister (u16 code, void *listener, PFN_on_event on_event) |
Unregister from listening for when events are sent with the provided code. If no matching registration is found, this function returns false. More... | |
KAPI b8 | event_fire (u16 code, void *sender, event_context context) |
Fires an event to listeners of the given code. If an event handler returns true, the event is considered handled and is not passed on to any more listeners. More... | |
This file contains structures and functions specific to the event system. Events are a mechenism that allows the developer to send and recieve data at critical points in the execution of the application in a non- coupled way. For now, this follows a simple pub-sub model of event transmission.
typedef struct event_context event_context |
Represents event contextual data to be sent along with an event code when an event is fired. It is a union that is 128 bits in size, meaning data can be mixed and matched as required by the developer.
typedef b8(* PFN_on_event) (u16 code, void *sender, void *listener_inst, event_context data) |
A function pointer typedef which is used for event subscriptions by the subscriber.
code | The event code to be sent. |
sender | A pointer to the sender of the event. Can be 0. |
listener_inst | A pointer to the listener of the event. Can be 0. |
data | The event context to be passed with the fired event. |
typedef enum system_event_code system_event_code |
System internal event codes. Application should use codes beyond 255.
enum system_event_code |
System internal event codes. Application should use codes beyond 255.
KAPI b8 event_fire | ( | u16 | code, |
void * | sender, | ||
event_context | context | ||
) |
Fires an event to listeners of the given code. If an event handler returns true, the event is considered handled and is not passed on to any more listeners.
code | The event code to fire. |
sender | A pointer to the sender. Can be 0/NULL. |
data | The event data. |
KAPI b8 event_register | ( | u16 | code, |
void * | listener, | ||
PFN_on_event | on_event | ||
) |
Register to listen for when events are sent with the provided code. Events with duplicate listener/callback combos will not be registered again and will cause this to return false.
code | The event code to listen for. |
listener | A pointer to a listener instance. Can be 0/NULL. |
on_event | The callback function pointer to be invoked when the event code is fired. |
Initializes the event system.
void event_system_shutdown | ( | void * | state | ) |
Shuts the event system down.
KAPI b8 event_unregister | ( | u16 | code, |
void * | listener, | ||
PFN_on_event | on_event | ||
) |
Unregister from listening for when events are sent with the provided code. If no matching registration is found, this function returns false.
code | The event code to stop listening for. |
listener | A pointer to a listener instance. Can be 0/NULL. |
on_event | The callback function pointer to be unregistered. |