Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML CPU usage  (Read 5255 times)

0 Members and 1 Guest are viewing this topic.

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
SFML CPU usage
« 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?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
SFML CPU usage
« Reply #1 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!

vicer1234

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
SFML CPU usage
« Reply #2 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?????

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
SFML CPU usage
« Reply #3 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.
I use the latest build of SFML2

TehKyle

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML CPU usage
« Reply #4 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);

AlexM

  • Newbie
  • *
  • Posts: 18
    • View Profile
SFML CPU usage
« Reply #5 on: May 20, 2011, 05:43:54 am »
this should answer a lot of your questions


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