|
al_wait_for_event Issue (Code execution stuck) |
MarcMDE
Member #16,639
February 2017
|
Hello! Would really aprecciate some help with this, I am so annoyed. Thanks!!! |
Eric Johnson
Member #14,841
January 2013
|
Nothing immediately jumps out at me, so I'm not too sure what the problem is. One thing I would suggest is changing if (draw) to if (draw && al_is_event_queue_empty(event_queue)) though. Edit I can't compile this without all the files. Could you provide GameUtils.h and Game.h, along with its corresponding source files?
|
Elias
Member #358
May 2000
|
I didn't look at anything else but you clearly don't want this as 1 / 60 will be identical to 0 in C++: al_create_timer(1 / 60); -- |
Chris Katko
Member #1,881
January 2002
|
And to clarify that a little bit. 1 / 60 = 0 because 1 and 60 are both integers. You'd need 1.0 / 60.0 or 1F / 60F to tell the compiler to treat those constants as floating point numbers. Sidenote: You might be able to get away with only one of them having .0, but I never tested that and I'm not sure the automatic type promotion rules of C++. If you start the left-side with 1.0 and then divide by 60 (no decimal point), I would imagine it'd be promoted to float. But you might as well leave all of the constants with decimals to clarify you intend the number to be a float, to any human reader. Likewise, I wonder what happens if you start with an integer, and then divide by a floating point constant ala (1 / 60.0). -----sig: |
Eric Johnson
Member #14,841
January 2013
|
Curious... Let me try that... Okay, here's what I got: 1
2#include <iostream>
3
4using std::cout;
5
6int main(void) {
7
8 cout << 1 / 60 << "\n";
9 cout << 1.0 / 60 << "\n";
10 cout << 1 / 60.0 << "\n";
11 cout << 1.0 / 60.0 << "\n";
12
13 return 0;
14}
Result: So it seems that so long as one of them is a float, the whole thing is treated as a float. I used g++ to compile, by the way. g++ --version
|
MarcMDE
Member #16,639
February 2017
|
Wohaaa, what a mistake... The problem was the al_create_timer. Thanks you all for the answer.
Eric Johnson said: One thing I would suggest is changing if (draw) to if (draw && al_is_event_queue_empty(event_queue)) though. Not getting why do we need to check if the queue is empty at all. I mean, I understand it, but I'm not understanding it as much as I would. I commented it when I was trying to solve the problem mentioned. Thanks you all again! |
Elias
Member #358
May 2000
|
If you don't have the al_is_event_queue_empty() but are receiving more than 60 events per second (easy with mouse/joystick events), you would delay your input more and more. You always draw 60 times per second then handle a single event afterwards. The check just makes sure to always handle all events before drawing the next time. -- |
Neil Roy
Member #2,229
April 2002
|
Eric Johnson said:
Result: So it seems that so long as one of them is a float, the whole thing is treated as a float. I used g++ to compile, by the way. A C book I was reading said the following; “Any operation between two values in C is performed as a floating-point operation if either value is a floating-point variable or constant.” When you have two integers, it is treated as an integer operation and the decimal value is simply dropped with no rounding. You could have also done something like: 60 / 1f or 60f / 1 etc. --- |
|