我正在学习 C++ 的响应式,我正在寻找一些指导。我创建了一个函数来等待事件然后返回它。我想捕捉反应式异步发生的所有事件并在它们发生时处理它们。这是我到目前为止所拥有的:
int Engine::Initialize()
{
al_init();
display = al_create_display(1200, 800);
eventQueue = al_create_event_queue();
al_install_mouse();
al_install_keyboard();
al_register_event_source(eventQueue, al_get_keyboard_event_source());
al_register_event_source(eventQueue, al_get_mouse_event_source());
//test: wait for 2 events to happen
auto events = rxcpp::observable<>::create([](rxcpp::subscriber<ALLEGRO_EVENT> e)
{
e.on_next(WaitForEvent);
e.on_next(WaitForEvent);
e.on_completed();
});
events.subscribe([](ALLEGRO_EVENT e)
{
printf("We have an Event: %d \n", e.type);
},
[]()
{
printf("Done\n");
});
return 0;
}
ALLEGRO_EVENT Engine::WaitForEvent()
{
ALLEGRO_EVENT event;
al_wait_for_event(eventQueue, &event);
return event;
}
我似乎得到了错误:没有函数模板实例 "rxcpp::observable::create" 与参数列表匹配。我是否需要制作自己的模板或其他东西才能观察到 ALLEGRO_EVENT?