Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro Linux slower than Allegro Windows?

This thread is locked; no one can reply to it. rss feed Print
Allegro Linux slower than Allegro Windows?
jamyskis
Member #6,557
November 2005
avatar

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!

__________________________________________________________________
In a world without fences and walls, who needs Windows and Gates?
http://www.jamyskis.net

BrknPhoenix
Member #7,304
June 2006

I think you should look at your timer code again... I'm using windows and timers control the speed of my stuff just fine ???

Evert
Member #794
November 2000
avatar

Quote:

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.

Quote:

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.

Quote:

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).

gnolam
Member #2,030
March 2002
avatar

Show us your code. Your timing code, for example.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Frank Drebin
Member #2,987
December 2002
avatar

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.

jamyskis
Member #6,557
November 2005
avatar

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.

__________________________________________________________________
In a world without fences and walls, who needs Windows and Gates?
http://www.jamyskis.net

Archon
Member #4,195
January 2004
avatar

Quote:

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.

Quote:

install_int(update_logic,6);
install_int(game_display,6);

Why do you have 2 timers? You just need 1 for the entire game!

hazul
Member #4,338
February 2004
avatar

Are the timers really running at 6 msecs = 167 per second ?

* * * * *
"Multiplayer is actually the best way of not programming a good AI" -ReyBrujo

Jonatan Hedborg
Member #4,886
July 2004
avatar

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)

-------
Sweden: Free from the shackles of Democracy since 2008-06-18!

jamyskis
Member #6,557
November 2005
avatar

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?

__________________________________________________________________
In a world without fences and walls, who needs Windows and Gates?
http://www.jamyskis.net

Thomas Fjellstrom
Member #476
June 2000
avatar

No, you just increment a integer, and then follow the many examples of how to regulate the main loop execution..

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Archon
Member #4,195
January 2004
avatar

Quote:

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.

Go to: