fork download
  1. #include <chrono>
  2. #include <thread>
  3.  
  4. const bool force_fps_limit = true;
  5.  
  6. void calculate_next_physical_frame() {
  7. //TODO: add logic to move objects around
  8. }
  9. void display_current_frame_to_screen() {
  10. //TODO: add logic to display objects to screen
  11. }
  12.  
  13. int main() {
  14. auto current_time = std::chrono::high_resolution_clock::now();
  15. const auto physical_frame_length = std::chrono::milliseconds{1000 / 60};
  16. for (;;) {
  17. while (std::chrono::high_resolution_clock::now() - current_time > physical_frame_length) {
  18. calculate_next_physical_frame();
  19. current_time += physical_frame_length;
  20. }
  21. display_current_frame_to_screen();
  22. if (force_fps_limit) {
  23. std::this_thread::sleep_until(current_time + physical_frame_length);
  24. }
  25. }
  26. }
  27.  
Time limit exceeded #stdin #stdout 5s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty