|
event queue never empty |
William Labbett
Member #4,486
March 2004
|
I spent a while getting the formatting correct but when I paste it here it goes wrong and when I paste into Notepad it goes wrong. Anyway, the code below doesn't work because al_is_event_queue_empty() always returns 0 so the drawing never happens. This was working a few days ago. I added a bit of code and nw it's broken. I'v got no clue as to why the queue is never empty. Any ideas ? Using Win7. 1
2
3int main()
4{
5
6 OneRun OneRunObject = OneRun();
7
8 if( OneRunObject.InitOkay() == false)
9 {
10 game_log(MAIN_LOG, "Problem initialising game.\n");
11 pause_and_quit
12 }
13
14
15
16 Menu MainMenu("main_menu_bitmap_list.txt", "game_data/menu_bitmaps");
17
18 Menu *CurrentMenu;
19
20 int cm_id = MAIN_MENU; /* current menu identifier */
21
22 bool need_redraw = false;
23 bool hold_on_key_down_events = false;
24 bool close_menu = false;
25
26 int time;
27
28 int update_done = 0;
29
30 int time_of_key_down;
31
32 while( OneRunObject.ClearUpAndQuit() == false)
33 {
34 switch(cm_id)
35 {
36 case MAIN_MENU:
37 CurrentMenu = &MainMenu;
38 break;
39 }
40
41 al_wait_for_event(OneRunObject.q, &OneRunObject.event);
42 switch(OneRunObject.event.type)
43 {
44 case ALLEGRO_EVENT_DISPLAY_CLOSE:
45 pf("display close.\n");
46
47 OneRunObject.SetClearUpAndQuitFlag();
48 CurrentMenu->SetNeedToActFlag();
49 break;
50 case ALLEGRO_EVENT_KEY_DOWN:
51
52 printf("key down.\n");
53
54 if(hold_on_key_down_events == false)
55 {
56 OneRunObject.SetKeyState(ALLEGRO_EVENT_KEY_DOWN);
57 }
58
59 break;
60 case ALLEGRO_EVENT_KEY_UP:
61 printf("key up.\n");
62 OneRunObject.SetKeyState(ALLEGRO_EVENT_KEY_UP);
63 break;
64 case ALLEGRO_EVENT_TIMER:
65 pf("timer tick\n");
66 need_redraw = true;
67
68 if(hold_on_key_down_events == false)
69 {
70 update_done = CurrentMenu->Update(OneRunObject.key_states);
71 }
72
73 if(update_done == 1 && hold_on_key_down_events == false) /* key down processed */
74 {
75 hold_on_key_down_events = true;
76 time_of_key_down = al_get_timer_count(OneRunObject.timer);
77 }
78 else if(update_done == 2) /* Enter key pressed. */
79 {
80 if(cm_id == MAIN_MENU)
81 {
82 switch(CurrentMenu->OptionSelected())
83 {
84 case 0: /* Play. */
85 OneRunObject.time_to_play = true;
86 break;
87 case 1:
88 cm_id = CONTROL_OPTIONS;
89 close_menu = true;
90 CurrentMenu->SetCloseTime(al_get_timer_count(OneRunObject.timer));
91 break;
92
93 }
94 }
95
96
97 }
98
99 if(hold_on_key_down_events == true && al_get_timer_count(OneRunObject.timer) >= time_of_key_down + 20)
100 {
101 hold_on_key_down_events = false;
102 }
103
104 break;
105 default:
106 pf("some other event.\n\n");
107 break;
108
109 } /* switch(OneRunObject.event.type) */
110
111
112 pf("need redraw = %s empty = %d", need_redraw ? "TRUE" : "FALSE", (int) al_is_event_queue_empty(OneRunObject.q));
113
114 if(need_redraw == true && al_is_event_queue_empty(OneRunObject.q))
115 {
116 printf("calling\n");
117 CurrentMenu->DrawMenu(close_menu, al_get_timer_count(OneRunObject.timer));
118 }
119
120 pf("\n");
121
122
123 if(OneRunObject.time_to_play == true)
124 {
125 /* if a loaded game was chosen, it should already be loaded */
126
127 printf("start game here.\n");
128 pause_and_quit(1);
129 }
130
131
132 al_flip_display();
133
134 pf("flushing.\n");
135 fflush(stdout);
136
137 }
138
139
140
141 game_log(MAIN_LOG, "End of program. Returning 0.\n");
142 return 0;
143}
|
weapon_S
Member #7,859
October 2006
|
Quote: I added a bit of code and now it's broken. While I read, I'll ask: what code? |
William Labbett
Member #4,486
March 2004
|
I changed a line to CurrentMenu->DrawMenu(close_menu, al_get_timer_count(OneRunObject.timer)); It was CurrentMenu->DrawMenu(); Also I started using the monolith file but I switched back to seperate archives to see if the monolith was the cause but it turned out it wasn't.
|
weapon_S
Member #7,859
October 2006
|
You are sure it runs, except for the redraw? I.e. it closes immediately when you tell it too? If a lot of events stack up, it won't close immediately. You changed the timing code? Maybe you forgot to register the timer event source. BTW Is that a single-case switch-statement |
Elias
Member #358
May 2000
|
Don't call al_flip_display() if you aren't drawing. It takes a long time but your current code only handles one event per al_flip_display call which inevitably leads to the queue never being empty. Also, about formatting, don't use any tabs (or alternatively, only tabs, but that's bound to go wrong in some places) then line up { and } with spaces and use a constant indentation. The way you have it right now makes it very hard to read. -- |
William Labbett
Member #4,486
March 2004
|
weapon_S said: "pf" pfff... When you suffer from newb blues as badly as me, and you've typed printf() so many times, using function name macros like pf was one the things I've learned that been a relief. Thanks both of you for the advice. I'm going to sort out that thing with the two strings. That'll make life a bit easier. Also, thanks Elias. My program works lovely now. Very grateful for the guidance. /off to kettle for tea
|
weapon_S
Member #7,859
October 2006
|
I see only 1 al_flip_display, and it only gets called when want_redraw == true |
William Labbett
Member #4,486
March 2004
|
it's the dreadful indentation that makes it look like that
|
bamccaig
Member #7,536
July 2006
|
Elias said: Also, about formatting, don't use any tabs (or alternatively, only tabs, but that's bound to go wrong in some places) then line up { and } with spaces and use a constant indentation. The way you have it right now makes it very hard to read. ^ This. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
BAF
Member #2,981
December 2002
|
Elias said: Also, about formatting, don't use any tabs (or alternatively, only tabs, but that's bound to go wrong in some places) then line up { and } with spaces and use a constant indentation. The way you have it right now makes it very hard to read. FFS, do NOT indent with spaces. That's what tabs are for, and they're infinitely more flexible. If you need to line things up (like code that bleeds onto another line), tab it in to the same level, then use spaces. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Never, never, ever mix spaces with tabs. Pick one, and stick with it. 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 |
bamccaig
Member #7,536
July 2006
|
BAF said: If you need to line things up (like code that bleeds onto another line), tab it in to the same level, then use spaces. That is fine in theory, but in practice it's very difficult to maintain. It's easy for you, or somebody else on the team, to mix up the tabs or spaces accidentally. Being whitespace, you won't notice. Using spaces is just much easier, especially with a mediocre or better editor that can expand them automatically for you. There's never guess work. It just works. There's absolutely no practical difference for me. I hit the tab key (or >>) to indent, the shift-tab combo (or <<) to un-indent, and there's no visible difference. As for the actual indentation step size, you can pretty easily write a program (or editor extension or whatever) to automatically convert between them if you care, but 4-spaces should be a happy medium for everybody. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
BAF
Member #2,981
December 2002
|
Quote: As for the actual indentation step size, you can pretty easily write a program (or editor extension or whatever) to automatically convert between them if you care, but 4-spaces should be a happy medium for everybody. Or you can, you know, just use tabs and configure your editor to have how many ever spaces you want. I don't understand why people think spaces are for indentation, and then come up with all these crazy workarounds to make it sound so usable. |
bamccaig
Member #7,536
July 2006
|
Don't knock it until you've tried it. It's clear that you haven't. At least, not with a useful editor (hint: Visual Studio's editor is not useful). -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|