al_emit_user_event(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– al_emit_user_event πŸ’–

okay bestie, welcome to the Allegro 5 API corner of the manual, where we're talking about al_emit_user_event β€” the function that lets you yeet your own custom events into the wild. it's giving "main character sends a message to the group chat" energy and honestly? obsessed. πŸ¦‹


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

bool al_emit_user_event(ALLEGRO_EVENT_SOURCE *src,
   ALLEGRO_EVENT *event, void (*dtor)(ALLEGRO_USER_EVENT *))

🌸 DESCRIPTION 🌸

so like, this is the moment. you take an event source and you emit an event from a user event source. slay. but no cap, there's a prerequisite: that event source has to have been initialised first with al_init_user_event_source(3alleg5). can't skip that step, bestie, it's the vibe check. πŸ’…

it returns false if the event source isn't registered with any queues β€” which lowkey means the event wouldn't have been delivered into any queues at all. so a false here is the universe telling you "nobody was listening, girl." 😭

heads up: events are copied in and out of event queues. so the second this function returns, the memory that event points to may be freed or reused. also, some fields of the event you passed in may get modified by the function itself. so like... don't go clinging to that pointer afterwards, it's not yours anymore. πŸ™ˆ

now, the reference counting part β€” this is where it gets ✨iconic✨:

once the reference count drops to zero, dtor gets called with a copy of the event as an argument. it should free the resources associated with the event β€” but not the event itself, because it's just a copy, bestie. not the whole thing. just a copy. πŸŽ€

if dtor is NULL then reference counting will not be performed. and here's a lil fun fact: it's safe, but unnecessary, to call al_unref_user_event(3alleg5) on non-reference counted user events. so like, no harm no foul, but also why would you. 🧚

and finally β€” plot twist β€” you can use al_emit_user_event to emit both user and non-user events from your user event source. rainbow of possibilities. 🌈

⚠️ but be careful: emitting input events will not update the corresponding input device states. for example, you may emit an event of type ALLEGRO_EVENT_KEY_DOWN(3alleg5), but it will not update the ALLEGRO_KEYBOARD_STATE(3alleg5) returned by al_get_keyboard_state(3alleg5). the keyboard state does not know. the keyboard state did not receive your memo. do not trust it. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie β€” you ate. this was the Allegro reference manual talking about al_emit_user_event(3alleg5), and like every good group chat, it's over way too soon. go emit something iconic. periodt. πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from