Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: WaitEvent sleeping a bit too often  (Read 1659 times)

0 Members and 1 Guest are viewing this topic.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
WaitEvent sleeping a bit too often
« on: November 03, 2013, 11:50:19 pm »
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;
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: WaitEvent sleeping a bit too often
« Reply #1 on: November 04, 2013, 07:38:56 am »
It's done.

Thanks for your help :)
Laurent Gomila - SFML developer

 

anything