SFML community forums

Help => General => Topic started by: vicer1234 on May 19, 2011, 07:05:40 pm

Title: SFML CPU usage
Post by: vicer1234 on May 19, 2011, 07:05:40 pm
Hi,
         I am just running a simple code:

Code: [Select]

int main(int argc, char* argv[])
{
sf::RenderWindow Game(sf::VideoMode(800, 600, 32), "Box2d");
while(Game.IsOpened())
{
while(Game.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
Game.Close();
}

Game.Clear(sf::Color(127, 149, 237));
Game.Display();

}
}



when i check the CPU usage in task manager it is around 45-50%.
Why so much high percentage usage, am i doing something wrong?
Title: SFML CPU usage
Post by: Grimshaw on May 19, 2011, 08:04:48 pm
There is a loop there, which goes on infinitely.

That means the CPU will process that loop as fast as it can. If you have a dualcore cpu, the 50% stands for one of cores processing at full speed.

I believe this is common in Real time applications!
Title: SFML CPU usage
Post by: vicer1234 on May 19, 2011, 11:53:37 pm
Quote from: "DevilWithin"
There is a loop there, which goes on infinitely.

That means the CPU will process that loop as fast as it can. If you have a dualcore cpu, the 50% stands for one of cores processing at full speed.

I believe this is common in Real time applications!



Hi,
 That means in a GameLoop, which also runs infinitely, the CPU percentage will be high. When the game loads and does complex process like physics etc the CPU will increase further?????
Title: SFML CPU usage
Post by: OniLinkPlus on May 20, 2011, 12:43:32 am
Quote from: "vicer1234"
Quote from: "DevilWithin"
There is a loop there, which goes on infinitely.

That means the CPU will process that loop as fast as it can. If you have a dualcore cpu, the 50% stands for one of cores processing at full speed.

I believe this is common in Real time applications!



Hi,
 That means in a GameLoop, which also runs infinitely, the CPU percentage will be high. When the game loads and does complex process like physics etc the CPU will increase further?????
No, it will stay the same, but the framerate will decrease. Limit the framerate (there's a function to do that) to reduce the cpu usage. You'll find that it should be using less than 1% of your cpu for this particular program.
Title: SFML CPU usage
Post by: TehKyle on May 20, 2011, 02:53:54 am
It is using high cpu because you didn't put any fps limit.
http://www.bit-tech.net/news/gaming/2010/08/03/starcraft-2-doesn-t-limit-framerates/1 should be relevant

You can easily fix this issue by putting this code
Game.SetFramerateLimit(60);
Title: SFML CPU usage
Post by: AlexM on May 20, 2011, 05:43:54 am
this should answer a lot of your questions


http://dewitters.koonsolo.com/gameloop.html