Please help! I have problem with FPS

Started by
3 comments, last by tetriarch 13 years ago
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?

Advertisement
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.[/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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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?

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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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




And thank you for help by the way :D

This topic is closed to new replies.

Advertisement