/
SilovAndrey
/
easel_examples
Обзор
Документация
Войти
/
SilovAndrey
/
easel_examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
print_elapsed.cpp
58 строк
1 KB
Andrey HomePC
Add easel_examples v0.1.0 with shapes, space, paths examples
10 июл 2026, 10:34
10 июл 2026, 10:34
8ecc405
Код
Авторство
О чём код?
module; #include <string> #include <iostream> module App; using namespace easel; extern float elapsed_; template <int n> struct exp_moving_average { static constexpr float b = 2.0f / (n + 1); static constexpr float b_ = 1.0f - b; exp_moving_average(float y_ = 0.0f) : y(y_) {} float operator()(float s) { return y = b * s + b_ * y; } float y = 0.0f; }; void print_elapsed(canvas& cnv, point br, color bkd, color c) { // static font open_sans = font_descr{"Open Sans", 12}; // static auto metrics = open_sans.metrics(); // static auto height = metrics.ascent + metrics.leading + metrics.descent; static exp_moving_average<256> ma; static int refresh = 0; static std::string fps_str; auto ave = ma(elapsed_); if (++refresh == 30) { refresh = 0; fps_str = std::to_string(1/ave) + " fps"; } std::cout<<"print_elapsed "<<fps_str<<std::endl; // auto width = open_sans.measure_text(fps_str); // cnv.fill_style(bkd); // cnv.add_rect({br.x - (width + 4), br.y - height, br.x, br.y}); // cnv.fill(); // cnv.fill_style(c); // cnv.font(open_sans); // cnv.text_align(cnv.right | cnv.bottom); // cnv.fill_text(fps_str, {br.x-2, br.y}); }