|
How do I return a boolean instead of locking up the process? |
Shadowblitz16
Member #16,818
March 2018
|
how do I return true here? 1bool window_is_running()
2{
3 if (!window_initalized) return false;
4
5 bool redraw = true;
6 ALLEGRO_EVENT event;
7
8 al_start_timer(window_timer);
9 while(1)
10 {
11 //need to return true here instead of locking up
12 al_wait_for_event(window_queue, &event);
13
14 if(event.type == ALLEGRO_EVENT_TIMER)
15 redraw = true;
16
17 else if((event.type == ALLEGRO_EVENT_KEY_DOWN) || (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE))
18 break;
19 }
20
21}
I wanted to make it so I can do.. 2window_init(256,240,60,"my title");
3while(window_is_running())
4{
5 //code here
6}
|
Peter Hull
Member #1,136
March 2001
|
Can you not 1window_init(256,240,60,"my title");
2bool window_is_running = true;
3al_start_timer(window_timer);
4while(window_is_running)
5{
6
7 bool redraw = true;
8 ALLEGRO_EVENT event;
9
10 al_wait_for_event(window_queue, &event);
11
12 if(event.type == ALLEGRO_EVENT_TIMER)
13 redraw = true;
14 else if((event.type == ALLEGRO_EVENT_KEY_DOWN) || (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE))
15 window_is_running = false;
16 //code here
17}
|
Shadowblitz16
Member #16,818
March 2018
|
why? its easy to read |
SiegeLord
Member #7,827
October 2006
|
bool window_is_running_var = true; bool window_is_running() { if (!window_initalized) return false; ALLEGRO_EVENT event; al_wait_for_event(window_queue, &event); if((event.type == ALLEGRO_EVENT_KEY_DOWN) || (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)) window_is_running_var = false; return window_is_running_var; } ? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Edgar Reynaldo
Major Reynaldo
May 2007
|
al_wait_for_event blocks until it gets an event. If you don't want to do that, use one of its cousins, al_get_next_event or al_wait_for_event_until. You could also run your window in a thread and send an event to your main loop when the window closes. The window is running until you get the close event. 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 |
|