MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ signal()

void MayaFlux::Vruta::WindowEventSource::signal ( Core::WindowEvent  event)

Enqueue a window event and resume matching waiters.

Parameters
eventEvent produced by the window backend.

Updates input state caches before dispatching.

Definition at line 7 of file WindowEventSource.cpp.

8{
9 if (auto* kd = std::get_if<Core::WindowEvent::KeyData>(&event.data)) {
10 if (event.type == Core::WindowEventType::KEY_PRESSED) {
11 m_key_states[kd->key] = true;
12 } else if (event.type == Core::WindowEventType::KEY_RELEASED) {
13 m_key_states[kd->key] = false;
14 }
15 }
16
17 if (auto* bd = std::get_if<Core::WindowEvent::MouseButtonData>(&event.data)) {
19 m_button_states[bd->button] = true;
20 } else if (event.type == Core::WindowEventType::MOUSE_BUTTON_RELEASED) {
21 m_button_states[bd->button] = false;
22 }
23 }
24
25 if (auto* pd = std::get_if<Core::WindowEvent::MousePosData>(&event.data)) {
26 m_mouse_x = pd->x;
27 m_mouse_y = pd->y;
28 }
29
30 const size_t resumed_before = m_resumed;
32 dispatch(&event);
34 if (m_resumed == resumed_before) {
35 m_pending_events.push_back(event);
36 auto& held = m_pending_counts[static_cast<uint8_t>(event.type)];
37 if (++held > k_max_pending_events) {
38 auto oldest = std::ranges::find(m_pending_events, event.type, &Core::WindowEvent::type);
39 m_pending_events.erase(oldest);
40 --held;
41 }
42 }
43
44 if (m_signal_depth != 0 || m_deferred_actions.empty())
45 return;
46
47 std::vector<std::function<void()>> deferred_actions;
48 deferred_actions.swap(m_deferred_actions);
49 for (auto& action : deferred_actions)
50 action();
51}
void dispatch(const void *event)
Iterates the waiter list, passing the type-erased signal to each.
std::unordered_map< int16_t, bool > m_key_states
std::vector< std::function< void()> > m_deferred_actions
std::deque< Core::WindowEvent > m_pending_events
std::unordered_map< int, bool > m_button_states
std::array< size_t, 256 > m_pending_counts
static constexpr size_t k_max_pending_events
Most events of one type held for a later awaiter before the oldest of that type is dropped.

References MayaFlux::Core::WindowEvent::data, MayaFlux::Vruta::EventSource::dispatch(), k_max_pending_events, MayaFlux::Core::KEY_PRESSED, MayaFlux::Core::KEY_RELEASED, m_button_states, m_deferred_actions, m_key_states, m_mouse_x, m_mouse_y, m_pending_counts, m_pending_events, m_resumed, m_signal_depth, MayaFlux::Core::MOUSE_BUTTON_PRESSED, MayaFlux::Core::MOUSE_BUTTON_RELEASED, and MayaFlux::Core::WindowEvent::type.

+ Here is the call graph for this function: