From ff555d6f851ddcc9815d34e294f7dbf44180ac90 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 4 Nov 2013 07:37:50 +0100 Subject: [PATCH] Optimized Window::waitEvent a bit (no sleep if events are available at first try) --- src/SFML/Window/WindowImpl.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 50f55dabf..5c1dd3591 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -99,24 +99,21 @@ bool WindowImpl::popEvent(Event& event, bool block) // If the event queue is empty, let's first check if new events are available from the OS if (m_events.empty()) { - if (!block) - { - // Non-blocking mode: process events and continue - processJoystickEvents(); - processEvents(); - } - else - { - // Blocking mode: process events until one is triggered + // Get events from the system + processJoystickEvents(); + processEvents(); + // In blocking mode, we must process events until one is triggered + if (block) + { // Here we use a manual wait loop instead of the optimized // wait-event provided by the OS, so that we don't skip joystick // events (which require polling) while (m_events.empty()) { + sleep(milliseconds(10)); processJoystickEvents(); processEvents(); - sleep(milliseconds(10)); } } }