#include "aorii.h" #include "async/thread_pool.h" #include "renderer/renderer_text.h" #include "window/window_manager.h" using time_type = decltype(std::chrono::high_resolution_clock::now()); std::chrono::duration delta_time = {}; time_type begin_time = {}; time_type last_time = {}; namespace aorii { bool init(const window_desc& in_main_window_desc) { spdlog::info("初始化 Aorii"); begin_time = std::chrono::high_resolution_clock::now(); if (!create_font_manager()) return false; if (!create_window_manager()) return false; const auto main_window = get_window_manager()->create_window(in_main_window_desc); if (!create_renderer()) return false; last_time = std::chrono::high_resolution_clock::now(); return true; } void destroy() { destroy_window_manager(); destroy_renderer(); destroy_font_manager(); spdlog::info("Aorii 销毁"); } void update() { thread_pool::global().process_main_thread_callbacks(); // 更新时间 const auto& current_time = std::chrono::high_resolution_clock::now(); delta_time = current_time - last_time; last_time = current_time; // 更新窗口 get_window_manager()->update(); std::this_thread::yield(); } int run(const init_info& in_init_info) { try { if (!init(in_init_info.main_window_desc)) return -1; while (!should_exit()) { update(); } destroy(); } catch (const std::exception& e) { spdlog::error("运行时异常: {}", e.what()); return -1; } catch (...) { spdlog::error("未知异常"); return -1; } return 0; } const std::chrono::duration& get_delta_time() { return delta_time; } std::chrono::duration get_total_time() { return std::chrono::high_resolution_clock::now() - begin_time; } }