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

Author Topic: Event handling in multiple threads.  (Read 2334 times)

0 Members and 1 Guest are viewing this topic.

hakeris1010

  • Newbie
  • *
  • Posts: 7
    • View Profile
Event handling in multiple threads.
« on: March 15, 2015, 08:44:55 pm »
I've seen that when handling events normally in one thread my game goes to several problems: for example, if mouse is moving, the continuous key pressing is not detected. This is because all the handling is in one window class, with one sf::Event object. But how to make it happen in multiple threads, with multiple event objects, for example one thread handles keyboard, another thread mouse?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Event handling in multiple threads.
« Reply #1 on: March 16, 2015, 12:34:49 am »
You have a wrong understanding of the event system. I highly recommend you go and read the official tutorial on it (again). ;)
Multiple events, e.g. mouse moved and key pressed, generate their own event object.

If you pass the event around, SFML won't care how and where you process it.

As for multi-threading, don't do it. You need to know a lot about parallel programming in order to not make mistakes with synchronization, race conditions, etc. And then you need a lot more experience to actually gain any speed up instead of making everything slower due to over heads.
It's an advanced topic and if you barely understand C++ and have only ever heard about threads, don't use them and go read a book on parallel programming. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything