Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » My game runs faster in Windows

Credits go to Kris Asick for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
My game runs faster in Windows
James Stanley
Member #7,275
May 2006
avatar

I have timers (they don't seem to do anything), and I just compiled my game in Windows and it runs way too fast. Changing the speed of the timer doesn't seem to do anything in Linux and I haven't tried on Windows. Any ideas?

EDIT:
Timers do affect speed on Windows

jamal
Member #3,326
March 2003
avatar

Quote:

Changing the speed of the timer doesn't seem to do anything in Linux and I haven't tried on Windows.

it should. Can you post your code ?

Steve Terry
Member #1,989
March 2002
avatar

Some friggin code or something please?

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

James Stanley
Member #7,275
May 2006
avatar

I just did a little more testing, and it seems that changing the timer speed does affect it after a point.

volatile int counter = 0;

LOCK_VARIABLE(counter);
LOCK_FUNCTION(timer);
install_int_ex(timer, MSEC_TO_TIMER(1));

while(1) {
  if(counter >= 1) {
    //Main loop
  }
  //Drawing
}

EDIT:
Code change...

jamal
Member #3,326
March 2003
avatar

volatile int counter = 0;

LOCK_VARIABLE(counter);
LOCK_FUNCTION(timer);
install_int_ex(timer, MSEC_TO_TIMER(1));

while(1) {
  while(counter >= 1) {
    counter--;
    //Main loop
  }
  //Drawing
}

James Stanley
Member #7,275
May 2006
avatar

Forgot to mention, there is already a counter = 0 in the main loop. Sorry.

EDIT:
Anyway, I can remove the bit about timers on Linux and it still runs the same speed.

EDIT2:
I must go now. I may be back tomorrow. Thanks.

Steve Terry
Member #1,989
March 2002
avatar

You should have it as a while loop. Never set it to 0 manually or you will effectively bipass the timer.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

James Stanley
Member #7,275
May 2006
avatar

What? How would that bypass the timer?

gnolam
Member #2,030
March 2002
avatar

Quote:

Forgot to mention, there is already a counter = 0 in the main loop. Sorry.

How about you post all relevant code then? :P

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

Kris Asick
Member #1,424
July 2001

It almost looks as though your counter is based on 1 ms increments. That alone could be the source of your problems. Running your game at an internal framerate of 1000 FPS is going to cause speed variations you never considered.

I'm also going to assume you are running a fixed time engine instead of a real time engine. In that case, the speed difference you are experiencing has to do with one of your computers/OSes being less able to keep up with a 1 ms timer than the other.

Instead of MSEC_TO_TIMER(1) try BPS_TO_TIMER(30) to do a 30 ticks per second timer, and then alter all your code to move at that rate. That should take care of your speed issues. (Provided both computers/OSes you are running this game on can handle 30 ticks per second of your game.)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

James Stanley
Member #7,275
May 2006
avatar

Gnolam, seeing as it worked on one computer, I assumed that was all the relevant code ;)

Kris, thanks. I'll try that.

EDIT:
That works perfectly on the Linux one, and I'll try Windows when I get to school.

BAF
Member #2,981
December 2002
avatar

I usually run 60 hz timer logic myself.

gnolam
Member #2,030
March 2002
avatar

Quote:

Gnolam, seeing as it worked on one computer, I assumed that was all the relevant code ;)

::)
And you don't think that code that directly affects your timing is relevant? Are you trolling or just stupid?

Kris: 30 FPS is way too little.

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

Kris Asick
Member #1,424
July 2001

Quote:

Kris: 30 FPS is way too little.

But low enough to know if that was the problem or not upon implementing it! ;)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

piccolo
Member #3,163
January 2003
avatar

hey every one.

should i put a timer on the server of my mmrpg?

i have one on the client because i want the clients to run at the same speed.
but i was thinking that i should let the sever run as fast as it can right.

edit:
that goes for the networking part of the client as well.

should i dived to the networking from the logic so the networking can run as fast as it can?

wow
-------------------------------
i am who you are not am i

Hard Rock
Member #1,547
September 2001
avatar

Yes you definitely want the server using up all available resources so it is at no less then 100% cpu usage at all times. End Sarcasm

Server is much more important then the client, as if someone decides to hack your client and your server doesn't follow logic speed, then they can use that to a pretty massive advantage. The client should be restricted as well, but the server is what synchronizes play between clients, not the other way around (this is in a client/server setup, p2p behaves differently).

Secondly, though I'm sure a server might be able to take it, it's probably not in your best interest to have a server running as fast as it can when the cpu usage can be best used for other things (like resting, as cooling can be an issue in a tightly packed server environment).

The same goes for network traffic for obvious reasons.(I hope).

But now that I've said that, next time you may want to start a separate thread and not hijack someone else's.

_________________________________________________
Hard Rock
[ Stars Dev Company ][ Twitter ][Global Warming: ARA My TINS 07 Entry][Pong Ultra Website][GifAllegS Ver 1.07]
"Well there's also coolwebsearch but we'll let that be an IE exclusive feature" - arielb on the New Browser Plugins "What's better, HTML or Variables?"

James Stanley
Member #7,275
May 2006
avatar

Thanks. The 30 BPS thing worked. I guess it was because one computer was fast enough to keep up but the other not.

BAF
Member #2,981
December 2002
avatar

30 BPS will be too slow for you. I'd go for at least 60.

James Stanley
Member #7,275
May 2006
avatar

The maximum it will run at on my computer is 35 (on the windows computers it is about 250), so I just use 30 and double the speeds so that it runs as if it is 60 :P

X-G
Member #856
December 2000
avatar

Yes, who cares about those people who might have better computers than you and might want to run the game without stutter? Shame on them for even suggesting it! ::)

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

kentl
Member #2,905
November 2002

Could anyone explain to me why you need more frames than 30 per second? Seeing as motion pictures are typically shot at 25 frames per second and it's good enough for them.

X-G
Member #856
December 2000
avatar

Because of the presence of motion blur, which mitigates the stuttering effect. Computer games generally don't simulate motion blur, which means you need much higher framerates to avoid choppiness.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

kentl
Member #2,905
November 2002

Are there any research for how high framerate you need that you know of?

imaxcs
Member #4,036
November 2003

I read somewhere that 50fps is about the amount the eyes/brain can cope with. More is (in terms of visible aspects) unnecessary...

kentl
Member #2,905
November 2002

I've heard that less than 75Hz isn't good for the brain and can cause head aches and epilepsy attacks. When I worked as a system administrator I always set the update frequency to the highest possible. At the same time older PAL televisions only has 50Hz.

 1   2 


Go to: