I'm making a game with the SFML libraries and i'm using it's RenderWindow class to capture the player's keystrokes. However, I believe it is what is eating up CPU while my program is running.
For example, the following code, when in the while loop, uses my entire core.
1 2 3 4 5 6 7 8 9
App->Display();
while (1)
{
if (App->GetEvent(Event))
{
if(Event.Key.Code == sf::Key::Escape)
{break;}
}
}
I was considering putting a pause in between capturing keystrokes, but i'm afraid that i may miss input that way. Does anyone know a way where i can accurately record keystrokes while still remaining conservative in my CPU usage?
I have zero experience with SFML, but judging from the documentation and examples I've had a look at, your game loop is a little screwy.
RenderWindow::Display() renders the window to screen, this should be the last instruction in your main loop!
RenderWindow::GetEvent(sf::Event) called in a loop to process all available events, as cire has above.
RenderWindow::SetFramerateLimit(int) limiting the framerate will reduce cpu usage.
Throwing it all together, you should have main loop that looks similar to this:-
http://redkiing.wordpress.com/2009/08/20/your-first-sfml-game-part-ii-the-board/
You might consider moving on to SFML 2.0 as well. I don't believe 1.6 will be supported once 2.0 is "officially" released and it has quite a few design issues that are dealt with better in 2.0