al_init_user_event_source(3alleg5)

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

πŸ’– al_init_user_event_source β€” Allegro 5 API πŸ’–

okay bestie, welcome to the Allegro 5 API page for al_init_user_event_source, and yes we're doing this together, grab a snack πŸ“


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

void al_init_user_event_source(ALLEGRO_EVENT_SOURCE *src)

🌸 DESCRIPTION 🌸

So like, this function initialises an event source for emitting user events. That's the whole job. The way it works is: the space for the event source has to already be allocated β€” like, you gotta have that memory ready before you call this, she does not do it for you, no cap. πŸ™ˆ

One possible way of creating custom event sources is to derive other structures with ALLEGRO_EVENT_SOURCE at the head, like:

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;
}

And the advantage here, the little slay of it all, is that the THING pointer will be the same as the ALLEGRO_EVENT_SOURCE pointer πŸ‘‘. Like they're the same address, they're matching, it's giving destiny fr fr. So events emitted by the event source will have the event source pointer as the source field, and from that you can get a pointer to a THING by a simple cast β€” after making sure you checked the event is of the correct type first, obviously, do not skip that step babe πŸ’….

However β€” and this is important β€” it is only one technique, and you are not obliged to use it. It's an option, not a rule. Live your truth. πŸ¦‹

Also, big heads up: the user event source will never be destroyed automatically. Never ever. Not on its own, not when you look away, not ever. You must destroy it manually with al_destroy_user_event_source(3alleg5). Don't leave her hanging, that's so not main character energy 😭


🌈 SEE ALSO 🌈


Allegro reference manual ✨ that's the vibe, that's the source, that's the al_init_user_event_source(3alleg5) footer energy β€” this page came straight out of the Allegro reference manual and it's dated like the iconic classic it is. mwah, go init your event sources bestie πŸ’–πŸŽ€πŸ§š

πŸ“¦ where this page comes from