Thank you Laurent and FRex, i fixed timestep in my game, and now it works exactly how i wanted. The same speed with different frame rates, clear code, no bugs like objects falling through the floor or disappearing when i move the window, also clear physics, no matter if the frame rate is 5 or 500 FPS. Here's the source code of my game object:
Game::Game(void)
: window(sf::VideoMode(window_size_x, window_size_y), "Ambient"),
view(sf::FloatRect(0, 0, float(window_size_x), float(window_size_y))),
updateFPS(1000),
dt(1.0f / updateFPS),
elapsedTime(0.0f),
accumulator(0.0f),
currentTime(clock.getElapsedTime().asMilliseconds())
{
init();
}
And game run() function:
void Game::run()
{
while (window.isOpen())
{
/* Events */
EventHandling();
/* Timestep */
newTime = clock.getElapsedTime().asMilliseconds();
frameTime = static_cast<float> (newTime - currentTime) / 1000.0f;
if (frameTime > 0.25f) frameTime = 0.25f;
currentTime = newTime;
accumulator += frameTime;
while (accumulator >= dt)
{
elapsedTime += dt;
accumulator -= dt;
/* Game Logic Update */
GameLogicUpdate();
}
/* View */
View();
/* Draw */
Draw();
}
}
Problem solved.