app_base.cpp 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "app_base.hpp"
  2. #include <memory>
  3. namespace saura {
  4. void AppBase::run() {
  5. os_ctx = std::make_unique<os::Context>();
  6. this->start();
  7. const double fps_max = 60.0;
  8. const double period_max = 1.0 / fps_max;
  9. const double perf_frequency = os_ctx->get_performance_frequency();
  10. double time = 0.0;
  11. double begin_counter = 0.0;
  12. double end_counter = 0.0;
  13. while (!is_quit) {
  14. double counter_elapsed = begin_counter - end_counter;
  15. double dt = counter_elapsed / perf_frequency;
  16. double fps = perf_frequency / counter_elapsed;
  17. begin_counter = os_ctx->get_performance_counter();
  18. if (dt >= period_max) {
  19. if (dt >= 1.0) {
  20. dt = period_max;
  21. }
  22. if (!os_ctx->update_events()) {
  23. is_quit = true;
  24. }
  25. os_ctx->update();
  26. this->update(dt);
  27. os_ctx->draw_begin();
  28. this->draw();
  29. os_ctx->draw_end();
  30. end_counter = begin_counter;
  31. }
  32. os_ctx->sleep(period_max);
  33. }
  34. this->stop();
  35. }
  36. } // namespace saura