|
Generating timer event |
APrince
Member #12,698
March 2011
|
Hi, I wanted to know, whether there's a way to generate timer event on my own. The thing is that I have something like: while (ti->run){ al_wait_for_event(queue, &ev); if (ti->run/* && (!*(ti->suspended))*/){ if (ti->updater->update()) *(ti->refresh) = true; } } This code runs in separate thread. Now when I need to close the application, I just set ti->run to false and wait for the thread to exit (actually it is Win32 thread, I do not use allegro wrapper for this one, but I don't think that matters). The point is, that in the worst case I have to wait for the whole timer interval till the thread closes (because of it waiting for the event). So after setting ti->run from sepparate thread, I would also like to escape the al_wait_for_event (by generating the event on my own for example...). Now I suppose I could create my own event type (somehow - I know Allegro supports it but I haven't found out any tutorial on that...), but I really do not want to compliate things, so fireing the timer event on my own would suffice. Thanks |
SiegeLord
Member #7,827
October 2006
|
I doubt Allegro provides such a feature. I'd just use a user event, they are easy enough (see ex_user_events for more ideas). Just create your own source, register it and fire off a user event: 1ALLEGRO_EVENT_SOURCE my_source;
2al_init_user_event_source(&my_source);
3
4ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
5al_register_event_source(queue, &my_source);
6
7#define EVENT_QUIT ALLEGRO_GET_EVENT_TYPE('q', 'u', 'i', 't')
8
9ALLEGRO_EVENT my_event;
10my_event.user.type = EVENT_QUIT;
11al_emit_user_event(&my_source, &my_event, 0);
12
13ALLEGRO_EVENT event;
14al_wait_for_event(queue, &event);
15
16al_destroy_user_event_source(&my_source);
"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
APrince
Member #12,698
March 2011
|
OK, I'll try that out... //edit: Works perfectly! |
|