Sign in to follow this  
tetriarch

Please help! I have problem with FPS

Recommended Posts

tetriarch    851
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?

Share this post


Link to post
Share on other sites
mhagain    13430
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: [url="http://sdl.beuc.net/sdl.wiki/SDL_Delay"]http://sdl.beuc.net/sdl.wiki/SDL_Delay[/url]

[quote]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.[/quote]

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.

Share this post


Link to post
Share on other sites
tetriarch    851
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?

Share this post


Link to post
Share on other sites
mhagain    13430
vsync: [url="http://en.wikipedia.org/wiki/Screen_tearing#V-sync"]http://en.wikipedia...._tearing#V-sync[/url]

There are a few reasons why a game might not use 100% CPU.
[list][*]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.[/list]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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this