Tramway SDK
Public Types | Static Public Member Functions | Public Attributes | List of all members
tram::Event Struct Reference

Event data. More...

#include <framework/event.h>

Public Types

enum  Type : event_t {
  NONE , KEYPRESS , KEYDOWN , KEYUP ,
  KEYCHAR , CURSORPOS , FRAME , TICK ,
  SELECTED , LOOK_AT , LAST_EVENT
}
 

Static Public Member Functions

static event_t Register (const char *name)
 Registers a new event type. More...
 
static event_t GetType (name_t name)
 Returns the event_t associated with a given name. More...
 
static name_t GetName (event_t type)
 Returns the name that was associated with a given event_t. More...
 
static event_t GetLast ()
 Returns the last event_t plus one. More...
 
static void Post (const Event &event)
 Adds an event to the event queue. More...
 
static void Dispatch ()
 Dispatches events from the event queue. More...
 
static listener_t AddListener (event_t type, EntityComponent *component)
 Registers a listener. More...
 
static listener_t AddListener (event_t type, Entity *entity)
 Registers a listener. More...
 
static listener_t AddListener (event_t type, void *data, void(*handler)(Event &event, void *data))
 Registers a listener. More...
 
static listener_t AddListener (event_t type, void(*handler)(Event &event))
 Registers a listener. More...
 
static void RemoveListener (listener_t listener_id)
 Deregisters a listener. More...
 
static void * AllocateData (size_t ammount)
 Allocates space for event data. More...
 
template<typename T >
static T * AllocateData ()
 
template<typename T >
static T * AllocateData (const T &data)
 

Public Attributes

event_t type
 Type of the event. More...
 
event_t subtype
 Arbitrary event subtype. More...
 
id_t poster
 
union {
   void *   data = nullptr
 
   int32_t   data_int
 
   value_t *   data_value
 
}; 
 

Detailed Description

Event data.

Fill in the struct fields and then use Event::Post() to send it out to listeners.

Member Enumeration Documentation

◆ Type

Enumerator
NONE 
KEYPRESS 
KEYDOWN 
KEYUP 
KEYCHAR 
CURSORPOS 
FRAME 
TICK 
SELECTED 
LOOK_AT 
LAST_EVENT 

Member Function Documentation

◆ AddListener() [1/4]

listener_t tram::Event::AddListener ( event_t  type,
Entity entity 
)
static

Registers a listener.

◆ AddListener() [2/4]

listener_t tram::Event::AddListener ( event_t  type,
EntityComponent component 
)
static

Registers a listener.

◆ AddListener() [3/4]

listener_t tram::Event::AddListener ( event_t  type,
void *  data,
void(*)(Event &event, void *data handler 
)
static

Registers a listener.

◆ AddListener() [4/4]

listener_t tram::Event::AddListener ( event_t  type,
void(*)(Event &event)  handler 
)
static

Registers a listener.

◆ AllocateData() [1/3]

template<typename T >
static T * tram::Event::AllocateData ( )
inlinestatic

◆ AllocateData() [2/3]

template<typename T >
static T * tram::Event::AllocateData ( const T &  data)
inlinestatic

◆ AllocateData() [3/3]

void * tram::Event::AllocateData ( size_t  ammount)
static

Allocates space for event data.

This allocation is useful for storing the additional data (Event::data pointer), for events, since all allocated space will be cleared once all events have been dispatched.

Note
Only store POD data types in the allocated memory. Either that, or prepare for memory leaks. Altough an IDE might complain that a value_t is not POD, you can ignore the warning. Overwriting a value_t shouldn't cause memory leaks.

◆ Dispatch()

void tram::Event::Dispatch ( )
static

Dispatches events from the event queue.

◆ GetLast()

event_t tram::Event::GetLast ( )
static

Returns the last event_t plus one.

Useful for iterating over all registered events, i.e. in a while (++event < Event::GetLast()); or a similar loop.

◆ GetName()

name_t tram::Event::GetName ( event_t  type)
static

Returns the name that was associated with a given event_t.

◆ GetType()

event_t tram::Event::GetType ( name_t  name)
static

Returns the event_t associated with a given name.

◆ Post()

void tram::Event::Post ( const Event event)
static

Adds an event to the event queue.

◆ Register()

event_t tram::Event::Register ( const char *  name)
static

Registers a new event type.

◆ RemoveListener()

void tram::Event::RemoveListener ( listener_t  listener_id)
static

Deregisters a listener.

Member Data Documentation

◆ 

union { ... } tram::Event::@38

◆ data

tram::Event::data = nullptr

Pointer to arbitrary data.

Can be set to a nullptr. Some event types have specific data, e.g. structs or other types that they need their data pointers to be pointing to. For your own event types, you can use this pointer for whatever purpose you want. If uncertain, set this to a nullptr.

◆ data_int

tram::Event::data_int

Arbitrary data integer.

◆ data_value

tram::Event::data_value

◆ poster

id_t tram::Event::poster

◆ subtype

tram::Event::subtype

Arbitrary event subtype.

Some event types have subtypes with specific semantics, but if you create your own event types, you can use the subtype field for anything.

◆ type

tram::Event::type

Type of the event.


The documentation for this struct was generated from the following files: