commit 1d33cd7e80b54a3d0d5bfba2aad863e399f4dfa3 parent cc4f59342fa0f4597b4bb59333509c0e9012d0f3 Author: Michael Savage <mikejsavage@gmail.com> Date: Fri Jul 14 00:14:17 +0300 Cap frame time at 1/20th of a second Diffstat:
main.cc | | | 7 | +++++-- |
diff --git a/main.cc b/main.cc @@ -61,9 +61,12 @@ int main( int argc, char ** argv ) { double last_xpos, last_ypos; glfwGetCursorPos( window, &last_xpos, &last_ypos ); + double game_time = 0; + while( !glfwWindowShouldClose( window ) ) { const double current_frame_time = glfwGetTime(); - const float dt = float( current_frame_time - last_frame_time ); + const float dt = min( 1.0f / 20.0f, float( current_frame_time - last_frame_time ) ); + game_time += dt; if( glfwGetKey( window, GLFW_KEY_Q ) == GLFW_PRESS || glfwGetKey( window, GLFW_KEY_ESCAPE ) == GLFW_PRESS ) { break; @@ -103,7 +106,7 @@ int main( int argc, char ** argv ) { hotload_shaders(); } - game_frame( &state, &mem, &input, current_frame_time, dt ); + game_frame( &state, &mem, &input, game_time, dt ); glfwSwapBuffers( window ); glfwPollEvents();