| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "app_base.hpp"
- #include <memory>
- namespace saura {
- void AppBase::run() {
- os_ctx = std::make_unique<os::Context>();
- this->start();
- 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;
- while (!is_quit) {
- 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_quit = true;
- }
- os_ctx->update();
- this->update(dt);
- os_ctx->draw_begin();
- this->draw();
- os_ctx->draw_end();
- end_counter = begin_counter;
- }
- os_ctx->sleep(period_max);
- }
- this->stop();
- }
- } // namespace saura
|