20 class Application:
public fabric::async::async_bus_t {
23 : stop_application_listener_(on_event([&](
const StopApplicationEvent&) -> fabric::task<> {
24 if (this->window_map_.empty()) {
25 this->emit<fabric::async::StopBusEvent>();
27 this->stop_application_flag_.test_and_set();
28 this->stop_application_flag_.notify_all();
31 ZoneScopedN(
"Application{}");
32 using namespace std::chrono_literals;
33 LOG::print{INFO}(
"Initializing application...");
36 ->schedule([] -> fabric::task<> {
37 tracy::SetThreadNameWithHint(
"Application", 1);
38 ZoneScopedN(
"Application Init");
40 if (not SDL_Init(SDL_INIT_VIDEO)) {
41 SDL_Log(
"Couldn't initialize SDL: %s", SDL_GetError());
42 LOG::print{ERROR}(
"Couldn't initialize SDL3: {}", SDL_GetError());
44 LOG::print{INFO}(
"SDL3 initialized.");
49 get_executor()->schedule([&] -> fabric::task<> {
59 LOG::print{INFO}(
"Application initialized...");
64 ZoneScopedN(
"~Application");
69 static Application instance;
73 template <
typename... Args>
75 ZoneScopedN(
"Application:run_async");
77 [=](Args... argss) -> fabric::task<
decltype(fun(std::forward<Args>(argss)...))> {
78 ZoneScopedN(
"Application:run_async:()");
79 co_return fun(std::forward<Args>(argss)...);
81 std::forward<Args>(args)...
85 template <
typename... Args>
86 static auto run(
auto&& fun, Args&&... args) {
87 ZoneScopedN(
"Application:run");
88 return run_async(fun, std::forward<Args>(args)...).get();
91 template <
typename... Args>
92 static auto schedule(
auto&& fun, Args&&... args) {
93 ZoneScopedN(
"Application:run_async");
97 template <
typename... Args>
98 static auto schedule(fabric::tasks::time_point tp,
auto&& fun, Args&&... args) {
99 ZoneScopedN(
"Application:run_async");
103 template <
typename... Args>
104 static auto schedule(fabric::tasks::duration duration,
auto&& fun, Args&&... args) {
105 ZoneScopedN(
"Application:run_async");
110 ZoneScopedN(
"Application:register_window");
113 LOG::print{INFO}(
"Window registered ID={}", id);
116 ZoneScopedN(
"Application:unregister_window");
118 std::scoped_lock lk{instance.window_map_mtx_};
119 instance.window_map_.erase(
id);
120 if (instance.window_map_.empty() and instance.stop_application_flag_.test()) {
121 instance.stop_application_flag_.clear();
122 instance.emit<fabric::async::StopBusEvent>();
124 LOG::print{INFO}(
"Window unregistered ID={}", id);
132 TracyLockable(std::mutex, window_map_mtx_);
133 std::map<std::size_t, fabric::async::async_bus_t*> window_map_{};
134 fabric::async::listener<StopApplicationEvent> stop_application_listener_;
135 std::atomic_flag stop_application_flag_{
false};