Hi all,
I've been writing a simple Space Invaders game in Allegro and managed it perfectly under Linux. It runs at a respectable pace and is fairly bug free.
When I tried to compile it under Windows however, it runs at a blinding, unplayable speed. The thing I tried first of all was to see if this problem reproduces itself under Linux, by removing the vsync() from the game loop. Nope - the game runs at exactly the same speed.
I've tried a number of solutions for controlling the speed of the game (including install_int(60,game_display); install_int(60, update_logic); ) which does absolutely nothing under Windows and SEGFAULTs under Linux.
Is Allegro Linux generally slower than the Windows version? Funny, because the opposite is true for SDL, where the Windows version is chronically slow!
I think you should look at your timer code again... I'm using windows and timers control the speed of my stuff just fine
When I tried to compile it under Windows however, it runs at a blinding, unplayable speed.
Post the smallest sample program that reproduces the behavior.
I've tried a number of solutions for controlling the speed of the game (including install_int(60,game_display); install_int(60, update_logic); ) which does absolutely nothing under Windows and SEGFAULTs under Linux.
Then you are definately doing it incorrectly. Post your code.
Is Allegro Linux generally slower than the Windows version?
No, but you do not get hardware acceleration using X11. This can reduce your framerate.
However, if you do everything in memory, then there should be no difference (actually, I remember things being a bit faster in Linux, but that was a while ago and the difference was mostly irrelevant).
Show us your code. Your timing code, for example.
in windows allegro uses directx in linux isn't such a thing.
this is why for example in my game you get only half perfomance in linux.
That's fair enough, the speed of the Linux version is fine for me anyway, although it strikes me as odd that the game always runs at the same speed whether it's chucking around 50-60 sprites or just 3. It also doesn't get affected by vsync(), as I've discovered from commenting it out in the code. Does Linux Allegro automatically vsync() regardless?
Anyway, the code, including modifications to the Windows version was thus.
| 1 | intro_sequence(); |
| 2 | |
| 3 | while(program_still_active()) |
| 4 | { |
| 5 | title_screen(); |
| 6 | predefine_variables(); |
| 7 | reset_enemies_position(); |
| 8 | reset_enemies_state(); |
| 9 | initialise_ingame_music(); |
| 10 | |
| 11 | install_int(update_logic,6); |
| 12 | install_int(game_display,6); |
| 13 | |
| 14 | while(game_still_active()) |
| 15 | { |
| 16 | //game_still_active() returns 0 based on actions within interrupts |
| 17 | }; |
| 18 | |
| 19 | remove_int(update_logic); |
| 20 | remove_int(game_display); |
| 21 | }; |
I know the code is extremely untidy and very amateurish, but then I am still quite newbie in these things.
I've tried a number of solutions for controlling the speed of the game (including install_int(60,game_display); install_int(60, update_logic); ) which does absolutely nothing under Windows and SEGFAULTs under Linux.
It would sound like you're putting a heap of coding in your timer functions and then calling them. You'll have troubles if the computer can't compute all of the calcultions in time for the function to be called again.
install_int(update_logic,6);
install_int(game_display,6);
Why do you have 2 timers? You just need 1 for the entire game!
Are the timers really running at 6 msecs = 167 per second ?
you should never, ever, EVER put anything more than just a simple interger increment or similar in your timer functions. It is not multithreading, just a function that is called on a regular basis. (which will die if you try to call it again before it is done)
So basically the best way is to use the interrupts to change a bool variable from false to true and then call update_logic()/game_display() while the variable is true, changing it to false right at the end?
No, you just increment a integer, and then follow the many examples of how to regulate the main loop execution..
So basically the best way is to use the interrupts to change a bool variable from false to true and then call update_logic()/game_display() while the variable is true, changing it to false right at the end?
Use an integer to count how many 'ticks' you have missed, and then update_logic() that many times until there are none left, then draw the game. If your update_logic is too slow and that the ticks never reach 0, then you've got a problem...
Also, you should probably have a maximum number of times the update_logic will execute before you force a redraw on the screen (in case there are say, 30 logic updates) you don't want to miss an entire second of the game - or maybe you do - it depends on the game.