Hello everybody.
I need some help with timestep. I tried a lot of methods to implement correct time step, but i none of them helped.
If i use setFrameLimit(60) my game will stutter hard.
If i use VSync - then game use 90% of CPU, but there is no stuttering.
Also, i tried to use this code: (it is from SFML's wiki)
sf::Clock frameClock;
sf::Clock updateClock;
sf::Int32 nextUpdate = updateClock.getElapsedTime().asMilliseconds();
float updateRate(1.0f / 20.f);
float maxUpdates = 1;
window.setFramerateLimit(60);
while (window.isOpen())
{
sf::Int32 updateTime = updateClock.getElapsedTime().asMilliseconds();
Uint32 updates = 0;
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
SceneManager::instance().input(event);
}
while((updateTime - nextUpdate) >= updateRate && updates++ < maxUpdates)
{
SceneManager::instance().updateFixed(sf::seconds(updateRate));
nextUpdate += updateRate;
}
SceneManager::instance().update(frameClock.restart());
window.clear();
SceneManager::instance().draw(window);
window.display();
}
Looks better than just setFrameLimit() but there is still some stuttering, even when i use * dt.asSeconds() when moving.
Need some help with it, i will be glad to see your implementation of timestep.
Thanks/