Jump to content

  • Log In with Google      Sign In   
  • Create Account

Please help! I have problem with FPS


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Tetriarch   Members   -  Reputation: 420

Like
0Likes
Like

Posted 12 April 2011 - 01:42 PM

Hi guys.

I am working on my game called Retro Invaders it's like Space Invaders.

And I have problem with FPS...

Well I have found some functions for FPS for example on http://www.sdltutorials.com/ and these functions are used only in movement of entities...

Well it looks well, but my computer uses during the game 100% CPU. And if I use SDL_Delay in the end of the loop, the computer uses 12-15% of CPU.

This is also well, but the game looks like it runs and halts and runs and halts.

Also surfaces are not blitted properly

My question is... any idea how to solve this problem please?



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8000

Like
0Likes
Like

Posted 12 April 2011 - 02:10 PM

Don't worry about it; all game loops use 100% CPU and this is both normal and desirable. The whole point of a game loop is that the game code can respond to input and events as fast as possible, and the only way to do that is by keeping the CPU constantly going. Start introducing delays, especially delays where there is imprecision and uncertaintly, and you lose this response.

For your specific case, check the documentation for SDL_Delay: http://sdl.beuc.net/sdl.wiki/SDL_Delay

This function waits a specified number of milliseconds before returning. It waits at least the specified time, but possible longer due to OS scheduling. The delay granularity is at least 10 ms. Some platforms have shorter clock ticks but this is the most common.


You're not sleeping for the amount of time you think you are; you're actually sleeping for an indefined and unknown-in-advance longer time, which is causing the jerky behaviour you've observed.

Use vsync if you want to block processing to a certain speed instead.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Tetriarch   Members   -  Reputation: 420

Like
0Likes
Like

Posted 12 April 2011 - 02:42 PM

Thanx, but I know a lot of games which are not using 100% of CPU and it works perfecktly... I brought my "game" to school and when I ran it a thought I will burn out that computer... Cooling was literally screaming...

I hope I said it well... (My English)

And one stupid question... what is it vsync?



#4 mhagain   Crossbones+   -  Reputation: 8000

Like
0Likes
Like

Posted 12 April 2011 - 04:40 PM

vsync: http://en.wikipedia...._tearing#V-sync

There are a few reasons why a game might not use 100% CPU.
  • Vsync as mentioned would cause each frame to block until the monitor was ready for a redraw; depending on the driver this might cause CPU usage to ease off.
  • The game might be GPU-bound rather than CPU-bound. Remember that any modern game will have at least two processors running in parallel - the GPU and the CPU. If the GPU is the bottleneck then the CPU won't be as busy.
  • You might be looking at a multicore system; with 4 cores a single threaded program will only ever show 25% usage max, for example.
Any halfway decent CPU should be able to take 100% usage by the way. Windows 95 and 98 were incapable of suspending the CPU and they certainly didn't burn out CPUs on a regular basis. Quite possible that your school's PC just needs it's fans cleaned out.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 Tetriarch   Members   -  Reputation: 420

Like
0Likes
Like

Posted 12 April 2011 - 09:26 PM

Okay so now I get It,... but how can I use vsync with SDL???




And thank you for help by the way :D






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS