mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Optimized Window::waitEvent a bit (no sleep if events are available at first try)
This commit is contained in:
parent
f69a35e63d
commit
ff555d6f85
@ -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 the event queue is empty, let's first check if new events are available from the OS
|
||||||
if (m_events.empty())
|
if (m_events.empty())
|
||||||
{
|
{
|
||||||
if (!block)
|
// Get events from the system
|
||||||
{
|
processJoystickEvents();
|
||||||
// Non-blocking mode: process events and continue
|
processEvents();
|
||||||
processJoystickEvents();
|
|
||||||
processEvents();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Blocking mode: process events until one is triggered
|
|
||||||
|
|
||||||
|
// In blocking mode, we must process events until one is triggered
|
||||||
|
if (block)
|
||||||
|
{
|
||||||
// Here we use a manual wait loop instead of the optimized
|
// Here we use a manual wait loop instead of the optimized
|
||||||
// wait-event provided by the OS, so that we don't skip joystick
|
// wait-event provided by the OS, so that we don't skip joystick
|
||||||
// events (which require polling)
|
// events (which require polling)
|
||||||
while (m_events.empty())
|
while (m_events.empty())
|
||||||
{
|
{
|
||||||
|
sleep(milliseconds(10));
|
||||||
processJoystickEvents();
|
processJoystickEvents();
|
||||||
processEvents();
|
processEvents();
|
||||||
sleep(milliseconds(10));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user