|
I do not quite understand the custom events mentioned in the user manual |
keprast
Member #16,794
January 2018
|
Hello. My English is very bad that I can not understand some of the content on the manual. Another question is: If I have a lot of rendering animation, how do I submit them to the queue. Although I try to use some machine translation, but apparently not enough. I need people to help me, can you help me? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
User events in Allegro 5 aren't too hard. First, you need an event source : ALLEGRO_EVENT_SOURCE evsrc; al_init_user_event_source(&evsrc); Then you need to register it with an event queue : al_register_event_source(event_queue , &evsrc); Then when you want to emit an event, you fill in the data fields of an ALLEGRO_EVENT and use the event source to emit that event : ALLEGRO_EVENT my_event; my_event.type = AL_ID('M' , 'I' , 'N' , 'E'); my_event.data.user1 = (intptr_t)some_data_address;/// Pass whatever custom data you want here al_emit_user_event(&evsrc , &my_event , 0); Then during your event loop, you check for events from that source : ALLEGRO_EVENT ev; al_wait_for_event(q , &ev); if (ev.source == &evsrc) { /// We got an event from our event source if (ev.type == AL_ID('M' , 'I' , 'N' , 'E')) { /// We got an event of type MINE from evsrc DoStuff(ev.data.user1); } }
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Audric
Member #907
January 2001
|
In case the Allegro functions themselves are not clear : // This allocates memory for one queue. It is empty. event_queue = al_create_event_queue();
// This tells Allegro to post keyboard events in this queue, every time the user uses the keyboard. al_register_event_source(event_queue, al_get_keyboard_event_source());
// This tells Allegro to post mouse events in this queue, every time the user uses the mouse. al_register_event_source(queue, al_get_mouse_event_source()); Generally, you want to use one queue for everything. This way, when you look in the queue, you get events in the correct order : "First the user pressed A, then he moved the mouse..." keprast said: Another question is: If I have a lot of rendering animation, how do I submit them to the queue. Normally, you separate in two functions : DRAWING When you have this separation, all the code in logic is fast. You can then use a timer event at 1/60s to run logic, and every time the event queue is empty, you can call the draw function to update the screen. |
keprast
Member #16,794
January 2018
|
THANKS! Some things make me unable to appear for some time. |
Chris Katko
Member #1,881
January 2002
|
I agree though even as a 1st language English user, that the docs are really confusing on that subject and I almost always have to re-lookup my old code, or grep though examples, to find the answer on how to do custom events, as well as "multiple events of the same time in one queue" (telling them apart). Who is up for making an Allegro 5/A.CC FAQ? If you could come up with Q's, I'll start preparing either a Wiki or YouTube walkthrough of the answers... I'm trying to get disciplined again (::boo:: health problems) and maybe forcing myself to do one a week could help me be more productive... -----sig: |
Edgar Reynaldo
Major Reynaldo
May 2007
|
There's this https://wiki.allegro.cc/index.php?title=FAQ and I thought there was another one... but no, I was thinking of something else. Alas, Tomasu is on vacation or was and doesn't have much time for the wiki anymore. I lost a bunch of pages and have been banned by his spam killers multiple times now and I lost my motivation. References
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
beoran
Member #12,636
March 2011
|
If the manual is unclear, please do make a pull request on github with a suggestion for improvement, perhaps with examples. That should be more useful than a separate FAQ. |
|