EventHandler
This package allows to create new events and trigger them at desired times. The Gamestate package already uses it.
Warning
The EventHandler requires some basic understanding of the PermMem. The documentation can be found here.
Dependencies
Initialization
Initialize with LeGo_EventHandler
flag.
Implementation
Functions
Event_Create
Creates a new event and returns a handle to it.
The function returns a new PermMem handle to an event.
Event_Delete
Alias to PermMem delete
. Cleans up the handle.
var int event
Handle returned fromEvent_Create
Event_Empty
Checks whether the event is "empty", i.e. nothing will happen after its execution.
var int event
Handle returned fromEvent_Create
Return value
The function returns TRUE
if event is empty, FALSE
is returned otherwise.
Event_Has
Checks if function
is added to the event.
var int event
Handle returned fromEvent_Create
var func function
Checked function
Return value
The function returns TRUE
if function is added, FALSE
is returned otherwise.
Event_Add
Adds an event handler function. The handler is called after running Event_Execute
.
var int event
Handle returned fromEvent_Create
var func function
Function to be added
Event_AddOnce
Event_Add
but checks if the handler function is already added, to prevent duplicates.
var int event
Handle returned fromEvent_Create
var func function
Function to be added
Event_Remove
Removes the event handler function
from the event.
var int event
Handle returned fromEvent_Create
var func function
Function to be removed
Event_Execute
Core of the package. Calls all functions registered via Event_Add
and Event_AddOnce
.
var int event
Handle returned fromEvent_Create
var int data
Int parameter passed to all executed functions
Ptr functions
Tip
The pointer functions are used internally by the previous functions. If you created an event with Event_Create
use functions without Ptr
in the name, but if you created event with EventPtr_Create
use only Ptr
functions. The normal user will probably never need the pointer versions, however the choice, which one to use is yours.
EventPtr_Create
Creates a new event and returns a pointer to it.
The function returns a new PermMem pointer to an event.
EventPtr_Delete
Alias to PermMem free
. Cleans up the pointer.
var int eventPtr
Pointer returned fromEventPtr_Create
EventPtr_Empty
Checks whether the event is "empty", i.e. nothing will happen after its execution.
var int eventPtr
Pointer returned fromEventPtr_Create
Return value
The function returns TRUE
if empty, FALSE
is returned otherwise.
EventPtr_Has
Checks if function
is added to an event.
var int eventPtr
Pointer returned fromEventPtr_Create
var func function
Checked function
Return value
The function returns TRUE
if function is added, FALSE
is returned otherwise.
EventPtr_HasI
EventPtr_Has
but with function ID instead of pointer. Used mainly internally.
var int eventPtr
Pointer returned fromEventPtr_Create
var int id
ID of checked function
Return value
The function returns TRUE
if function is added, FALSE
is returned otherwise.
EventPtr_Add
Adds an event handler function. The handler is called after running EventPtr_Execute
.
var int eventPtr
Pointer returned fromEventPtr_Create
var func function
Function to be added
EventPtr_AddI
EventPtr_Add
but with function ID instead of pointer. Used mainly internally.
var int eventPtr
Pointer returned fromEventPtr_Create
var int id
ID of function to be added
EventPtr_AddOnce
Event_Add
but checks if function is already added, to prevent duplicates.
var int eventPtr
Pointer returned fromEventPtr_Create
var func function
Function to be added
EventPtr_AddOnceI
EventPtr_AddI
but checks if function is already added, to prevent duplicates.
var int eventPtr
Pointer returned fromEventPtr_Create
var int id
ID of function to be added
EventPtr_Remove
Removes a function from the event's call list.
var int eventPtr
Pointer returned fromEventPtr_Create
var func function
Function to be removed
EventPtr_RemoveI
EventPtr_Remove
but with function ID instead of pointer. Used mainly internally.
var int eventPtr
Pointer returned fromEventPtr_Create
var int id
ID of function to be removed
EventPtr_Execute
Core of the package. Calls all functions registered via EventPtr_Add
and EventPtr_AddOnce
.
var int eventPtr
Pointer returned fromEventPtr_Create
var int data
Int parameter passed to all executed functions
Examples
Note
This article has no built-in examples, but the best way to understand how EventHandler works is reading source code of the Gamestate package.