app.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "app.hpp"
  2. #include "saura/core/app_base/app_base.hpp"
  3. namespace saura {
  4. App::App() {
  5. is_running = true;
  6. os_ctx = std::make_unique<OS>();
  7. os_ctx->set_root_window_title(get_app_base()->get_title());
  8. server_api_ctx = std::make_shared<ServerAPI>();
  9. }
  10. App::~App() {}
  11. void App::run() {
  12. const double fps_max = 60.0;
  13. const double period_max = 1.0 / fps_max;
  14. const double perf_frequency = os_ctx->get_performance_frequency();
  15. double time = 0.0;
  16. double begin_counter = 0.0;
  17. double end_counter = 0.0;
  18. get_app_base()->start();
  19. while (is_running) {
  20. double counter_elapsed = begin_counter - end_counter;
  21. double dt = counter_elapsed / perf_frequency;
  22. double fps = perf_frequency / counter_elapsed;
  23. begin_counter = os_ctx->get_performance_counter();
  24. if (dt >= period_max) {
  25. if (dt >= 1.0) {
  26. dt = period_max;
  27. }
  28. if (!os_ctx->update_events()) {
  29. is_running = false;
  30. }
  31. os_ctx->update();
  32. os_ctx->draw_begin();
  33. get_app_base()->update(dt);
  34. os_ctx->draw_end();
  35. end_counter = begin_counter;
  36. }
  37. os_ctx->sleep(period_max);
  38. }
  39. get_app_base()->stop();
  40. }
  41. } // namespace saura