Example game loop (with fps) on rust

Hello everyone!

I wanna write new mini game on rust, but i don't know how write simple game loop with fps on rust..
working with time so hard.

Please help rewrite famous game loop from here on rust
Fix you Timestep!

Example code from article

    double t = 0.0;
double dt = 0.01;

double currentTime = hires_time_in_seconds();
double accumulator = 0.0;

State previous;
State current;

while ( !quit )
{
    double newTime = time();
    double frameTime = newTime - currentTime;
    if ( frameTime > 0.25 )
        frameTime = 0.25;
    currentTime = newTime;

    accumulator += frameTime;

    while ( accumulator >= dt )
    {
        previousState = currentState;
        integrate( currentState, t, dt );
        t += dt;
        accumulator -= dt;
    }

    const double alpha = accumulator / dt;

    State state = currentState * alpha + 
        previousState * ( 1.0 - alpha );

    render( state );
}

Thank you in advance!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.