AL_INIT_USER_EVENT_SOURCE(3)
π NAME π
okay so bestie, this is al_init_user_event_source(3) from the Library Functions Manual β the Allegro 5 API function that sets up an event source for emitting user events β¨
β¨ SYNOPSIS β¨
#include <allegro5/allegro.h>
void al_init_user_event_source(ALLEGRO_EVENT_SOURCE *src)
π¦ DESCRIPTION π¦
So what this icon does is initialise an event source for emitting user events. That's the whole vibe. But hear me out: the space for the event source must already have been allocated before you call this. She is not out here doing your malloc for you, bestie β she just initialises what's already there π
One possible way of creating custom event sources is to derive other structures with ALLEGRO_EVENT_SOURCE at the head, e.g.:
typedef struct THING THING;
struct THING {
ALLEGRO_EVENT_SOURCE event_source;
int field1;
int field2;
/* etc. */
};
THING *create_thing(void)
{
THING *thing = malloc(sizeof(THING));
if (thing) {
al_init_user_event_source(&thing->event_source);
thing->field1 = 0;
thing->field2 = 0;
}
return thing;
}
The advantage here is that the THING pointer will be the same as the ALLEGRO_EVENT_SOURCE pointer. Events emitted by the event source will have the event source pointer as the source field, from which you can get a pointer to a THING by a simple cast (after you make sure to check that the event is of the correct type). It's giving pointer math but make it cute π
However, it is only one technique and you are not obliged to use it. No pressure, bestie β do what works for your code π«Ά
β οΈ real talk: the user event source will never be destroyed automatically. You must destroy it manually with al_destroy_user_event_source(3). Don't leave her hanging, okay? π
π SEE ALSO π
byeee bestie π«Ά this has been the Allegro reference manual (source/version vibes: iconic; date: not listed in this footer, so she's a mystery π) β now go init that event source and slay β¨π
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms