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

Author Topic: [SOLVED]Listenning event within a thread  (Read 1248 times)

0 Members and 1 Guest are viewing this topic.

schizo-boy

  • Newbie
  • *
  • Posts: 11
    • View Profile
[SOLVED]Listenning event within a thread
« on: July 06, 2013, 02:52:18 pm »
Hello,

My colleague and I are developing an network based application but we did not manage to put the keyboard listening event into an SFML thread.

We would like the listening events to be non blocking:

Our application must have 2 infinite loops allowing us to :
1. Listen to the network requests. ( synchronized sockets)
2. Listen to the keyboard events.

All we've manage to do so fare when putting the listening events in a thread is either a segmentation fault or the application would simply ignore those events.

So our question is :

How can we create a non blocking keyboard listening event?

An other thing would be how could we avoid being in the pollEvent loop all the time :
while (renderWindow.isOpen())
    {
        sf::Event event;
        while (renderWindow.pollEvent(event))
        {
           //handle events
        }
    }
 

when we are trying to actions which are not related to events?

Thanks

PS: If a solution existe using the SFML network module we are not allowed to use it and we have to use the Posix sockets.
« Last Edit: July 07, 2013, 03:12:57 pm by schizo-boy »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Listenning event within a thread
« Reply #1 on: July 06, 2013, 06:13:40 pm »
Quote
All we've manage to do so fare when putting the listening events in a thread is either a segmentation fault or the application would simply ignore those events.
It is clearly written in the tutorial that on some OSes you can't handle events in a thread (OS X), or handle them in another thread that the one where the window was created (Windows).

Quote
An other thing would be how could we avoid being in the pollEvent loop all the tim
You're not in the event loop all the time, once there is no more events to process you exit the loop.
Laurent Gomila - SFML developer

schizo-boy

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Listenning event within a thread
« Reply #2 on: July 07, 2013, 03:12:33 pm »
Thanks for the reply!

We've managed to find an alternative solution  :)