SFML community forums

Help => General => Topic started by: zyroph on August 30, 2013, 12:24:17 pm

Title: SMFL2 & CPU usage
Post by: zyroph on August 30, 2013, 12:24:17 pm
Hi all,

I'm totally new to SFML and as a first test I took that very simple program drawing a green circle as provided at the end of the install tutorial.

I'm running:
and I actually had to recompile my own version as none of the provided works for me.

However, I was very surprised to notice two performance issues:
It's really weird as I never came across such issues using other libraries, knowing the program is as simple as possible.

So any ideas? And thanx in advance...
Title: Re: SMFL2 & CPU usage
Post by: Foaly on August 30, 2013, 12:31:45 pm
Take a look at the FPS your program is running at. You'll  notice that it's ridiculously high. That is because your main loop is being executed as fast as possible and since it doesn't do much your program is running really fast. This is filling up a whole core (25%of your CPU)
So you should limit you framerate to something that is normal (like 60 FPS) or use vertical sync. This gives your program some time to sleep and doesn't waist CPU time.
Cheers
Title: Re: SMFL2 & CPU usage
Post by: zyroph on August 30, 2013, 01:04:56 pm
Wow, worked like a charm.

Hmm,... but isn't something that should be set by default in the lib? Or at least included in the tutorial program?

Anyway, cheers for one of the fastest working answer I ever got in a forum!
Title: Re: SMFL2 & CPU usage
Post by: Lo-X on August 30, 2013, 01:15:44 pm
Wow, worked like a charm.

Hmm,... but isn't something that should be set by default in the lib? Or at least included in the tutorial program?

Anyway, cheers for one of the fastest working answer I ever got in a forum!

This isn't a video game librairy but a multimedia librairy. It's the developper responsability to limit the framerate if he needs it.
Plus there's a method in sf::RenderWindow that allow you to limit the framerate or enable v-sync. But if you want more control on the framerate and how many times update and draw are executed, the best is to handle it yourself.