SFML community forums
Help => General => Topic started by: Makuto on March 03, 2011, 03:39:32 am
-
Why is my simple program taking up 100% of my CPU? My code is from the documentation files (the first example).
-
Because you tell it to take 100% CPU. Well, in fact you don't tell it to not take 100% CPU ;)
Simply use SetFramerateLimit, UseVerticalSync or Sleep to slow down your program and let the CPU do something else.
-
What would you suggest I limit the frame rate to?
-
Use vertical synchronization, it will give better visual results because the framerate will be synchronized with the monitor's refresh rate.
-
Is that in the documentation? I'm assuming it is. Thanks for the help.
-
It is, all functions are documented. I don't know if it's in the tutorials.
-
I used the UseVerticalSync and the program looks really good now, but it still takes up 100%. Should I also limit the framerate?
-
Really? It shouldn't. Try SetFramerateLimit (without UseVerticalSync), and if it still doesn't work then you probably have a problem.
-
It's working now. Thanks for all of the help!
-
I have the same problem but it isn't working for me...
I'm using Ubuntu 10.10.
App.UseVerticalSync (true);
or
App.UseVerticalSync (false);
App.SetFramerateLimit (0x20);
both limit the rate, but the CPU satys at 100%
-
I got rid of this problem a while ago. Limiting the frame rate seems to limit the CPU. I think your hardware might be affecting yours. Mine only runs like 10% now.
-
wurd.... hopefully in 2.0 it will be fixed :S
-
VSync seems to not work with all drivers. I had this problem once on my laptop with an ATI Radeon HD blah-blah-something. SetFramerateLimit() should work in any case.
-
Nope! I tried
App.UseVerticalSync (false);
App.SetFramerateLimit (0x20);
this
App.UseVerticalSync (true);
App.SetFramerateLimit (0x20);
this
App.SetFramerateLimit (0x20);
and this
App.UseVerticalSync (true);
on 2 differant computers, and it still maxed out the CPU at 100%
-
My code is from the documentation files (the first example)
Which one?
-
I fixed this problem a while ago, but it came up again in a different form with different source code. The window source is below:
sf::RenderWindow App(sf::VideoMode(800, 600), "Dodger");
App.UseVerticalSync(useVertSync);
App.SetFramerateLimit(frameLimit);
use vert sync is true and framelimit is set to 45. The program runs on an average amount of CPU, but it acts like a program running on 100% CPU (mouse flickers, disappears when you don't move it, boxes appear by mouse, etc.). This started occurring all-of-the-sudden. All of the images move quickly and at a normal pace.
-
my code isn't from the tut, it's my own
-
Mine is now too, but the problem arised after. To tell you the truth, I only said that I was using the tutorial code so I wouldn't have to post mine, cause I'm lazy... :)
-
I just stopped thinking about this problem for a while.. but this morning it was really bugging me.. SO! I tried several things... and...
sf::Sleep(0.01);
Doesn't seem to have any effect on speed AND the CPU goes to 0%! :D
w00t!
-
I just stopped thinking about this problem for a while.. but this morning it was really bugging me.. SO! I tried several things... and...
sf::Sleep(0.01);
Doesn't seem to have any effect on speed AND the CPU goes to 0%! :D
w00t!
Or you could look at the second post in this thread. Your technique is equivalent to SetFramerateLimit(100);
The 100 comes from 1/0.01.
-
No I tried that, it didn't work either.. I think it might be a hardware problem
-
No I tried that, it didn't work either.. I think it might be a hardware problem
I doubt it. I'm 99% sure that SetFramerateLimit uses sf::Sleep (although I haven't checked, to be honest).
-
I don't think so... when i do
App.SetFramerateLimit (0x30);
For instance.. it does nothing to my CPU.. but when i do
sf::Sleep(0.01);
it lowers it to 0! it's wacked.
-
I don't think so... when i do
App.SetFramerateLimit (0x30);
For instance.. it does nothing to my CPU.. but when i do
sf::Sleep(0.01);
it lowers it to 0! it's wacked.
Why are you using hexadecimal in SetFramerateLimit?
Also, I was correct. This is how SFML handles FramerateLimit:
if (myFramerateLimit > 0)
{
float remainingTime = 1.f / myFramerateLimit - myClock.GetElapsedTime();
if (remainingTime > 0)
Sleep(remainingTime);
}
In other words, using SetFramerateLimit has the exact same effect as your Sleep method.
-
i use hex because i believe it compiles faster.. dunno i guess i just like it :D
weiiiirdd... oh well as long as both of them work in the same way it doesn't matter i guess lol