| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #include "app.hpp"
- #include "saura/core/app_base/app_base.hpp"
- namespace saura {
- App::App() {
- is_running = true;
- os_ctx = std::make_unique<OS>();
- os_ctx->set_root_window_title(get_app_base()->get_title());
- server_api_ctx = std::make_shared<ServerAPI>();
- }
- App::~App() {}
- void App::run() {
- const double fps_max = 60.0;
- const double period_max = 1.0 / fps_max;
- const double perf_frequency = os_ctx->get_performance_frequency();
- double time = 0.0;
- double begin_counter = 0.0;
- double end_counter = 0.0;
- get_app_base()->start();
- while (is_running) {
- double counter_elapsed = begin_counter - end_counter;
- double dt = counter_elapsed / perf_frequency;
- double fps = perf_frequency / counter_elapsed;
- begin_counter = os_ctx->get_performance_counter();
- if (dt >= period_max) {
- if (dt >= 1.0) {
- dt = period_max;
- }
- if (!os_ctx->update_events()) {
- is_running = false;
- }
- os_ctx->update();
- os_ctx->draw_begin();
- get_app_base()->update(dt);
- os_ctx->draw_end();
- end_counter = begin_counter;
- }
- os_ctx->sleep(period_max);
- }
- get_app_base()->stop();
- }
- } // namespace saura
|