When looking through the SFML code I found it is always doing a sleep on waitEvent when the SFML queue is empty, even if process(Joystick)Events can get fresh events from the OS at first try.
Wouldn't it be better to restructure this code from WindowImpl.cpp
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
// 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())
{
processJoystickEvents();
processEvents();
sleep(milliseconds(10));
}
}
}
// Pop the first event of the queue, if it is not empty
if (!m_events.empty())
{
event = m_events.front();
m_events.pop();
return true;
}
return false;
}
a bit, to get this where it does a first try always?
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())
{
processJoystickEvents();
processEvents();
if (!block)
{
// Non-blocking mode: stop if no events found
if (m_events.empty())
return false;
}
else
{
// Blocking mode: process events until one is triggered
// 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();
}
}
}
// Pop the first event of the queue
event = m_events.front();
m_events.pop();
return true;
}