I have a basic SFML program running on my computer and it takes about 30% of CPU even when I don't input anything in the program.
Here's the code:
#include <SFML\Graphics.hpp>
void MoveView(const sf::Input *Input, sf::View &View);
void MoveShape(const sf::Input *Input, sf::Shape &Box);
int main() {
sf::RenderWindow cWin(sf::VideoMode(800, 600), "Camera test");
cWin.SetFramerateLimit(30);
sf::Event Event;
sf::Shape Box = sf::Shape::Rectangle(0.0f, 0.0f, 150.0f, 150.0f, sf::Color::Red);
Box.SetCenter(75.0f, 75.0f);
sf::View View(sf::Vector2f(400, 300), sf::Vector2f(400, 300));
while ( cWin.IsOpened() ) {
if ( cWin.GetEvent(Event) ) {
if ( Event.Type == sf::Event::Closed )
cWin.Close();
if ( cWin.GetInput().IsKeyDown(sf::Key::Escape) )
cWin.Close();
}
MoveShape(&cWin.GetInput(), Box);
MoveView(&cWin.GetInput(), View);
cWin.SetView(View);
cWin.Clear(sf::Color::White);
cWin.Draw(Box);
cWin.Display();
}
return 0;
}
void MoveView(const sf::Input *Input, sf::View &View) {
if ( Input->IsKeyDown(sf::Key::Left) )
View.Move(-20.0f, 0.0f);
else if ( Input->IsKeyDown(sf::Key::Right) )
View.Move(20.0f, 0.0f);
if ( Input->IsKeyDown(sf::Key::Up) )
View.Move(0.0f, -10.0f);
else if ( Input->IsKeyDown(sf::Key::Down) )
View.Move(0.0f, 10.0f);
}
void MoveShape(const sf::Input *Input, sf::Shape &Box) {
if ( Input->IsKeyDown(sf::Key::A) )
Box.Move(-10.0f, 0.0f);
else if ( Input->IsKeyDown(sf::Key::D) )
Box.Move(10.0f, 0.0f);
if ( Input->IsKeyDown(sf::Key::W) )
Box.Move(0.0f, -10.0f);
else if ( Input->IsKeyDown(sf::Key::S) )
Box.Move(0.0f, 10.0f);
}
Using SFML 1.6 build for VS2010. But it's the same with SFML 1.6 with VS2008 and C::B. Realese or debug, same thing.
Can anyone tell me why does this little program use so much CPU? I have a larger project, if I run that it never goes lower then 50%.
Even a basic program like displaying the window without rendering anything does take more then it should.
If I try to display more then 100x100 sf::Shape-s it takes about 20 seconds to update the frame.
Should it work that slow? :\
I tested it on other computers too and the result is the same.
Thanks in advance.