Home Game Development c++ – How would I’m going about fixing my variable fee SDL timestep?

c++ – How would I’m going about fixing my variable fee SDL timestep?

0
c++ – How would I’m going about fixing my variable fee SDL timestep?

[ad_1]

I my gameloop goes round 10x sooner than what it needs to be and I do not know tips on how to repair it.

I attempted a number of totally different different variable fee timesteps however none appear to be as efficient as this one.

int important(int argc, char* args[])
{
    Uint32 t = 0;
    Uint32 dt = 10000 / 60.0;

    Uint32 currentTime = SDL_GetTicks();

    sport = new Renderer();

    game->init("window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);

    whereas(game->operating()){
        
        Uint32 newTime = SDL_GetTicks();
        Uint32 frameTime = newTime - currentTime;
        currentTime = newTime;

        whereas(frameTime > 0.0)
        {
            float deltaTime = std::min(frameTime, dt);
            game->handleEvents();
            game->replace(deltaTime/1000);
            frameTime -= deltaTime;
            t += deltaTime;
            
            t += dt;
        }
        game->render();
    }

    game->clear();

    return 0;
}

Whenever I name

g.rework.place.x+=1/60.0;

within the render operate, I count on it to maneuver 1 pixel each 1 second however it strikes technique to quick.
Does anybody know the way I can gradual this down or what I’m doing incorrect?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here