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

Author Topic: Rendering thread and game logic  (Read 2741 times)

0 Members and 1 Guest are viewing this topic.

homar

  • Newbie
  • *
  • Posts: 7
    • View Profile
Rendering thread and game logic
« on: January 02, 2014, 04:45:53 pm »
I am trying to wrap my head around working with multiple threads. In one of the tutorials (http://www.sfml-dev.org/tutorials/2.0/window-opengl.php) it states that a typical configuration is to handle the window and its events in the main thread with the rendering is performed in another thread. In this configuration, where would the game logic go?

If the game logic is in the rendering thread then I can't see there being much of a performance benefit over having a single thread. The main thread would be doing very little.

On the other hand, if the game logic is in the main thread then the game entities would need to be shared across both threads so that they can be updated in the main thread and rendered in the rendering thread. This is susceptible to race conditions and so each game entity would need a mutex.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Rendering thread and game logic
« Reply #1 on: January 02, 2014, 05:34:29 pm »
In general don't use threads, especially if you've no idea how to do proper synchronization etc, etc.
Parallel programming is one of the harder topics and especially since C++ itself only comes with a limited amount of out-of-the-box tools.

Unless you're on a very large project, the time you'll need to invest in learning proper multithreading and maintaining that code base is way larger than the gain you'll get from it. Multiple threads doesn't automatically mean double the processing time, it's often even the other way around, due to bad synchronization or other challenges. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

homar

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Rendering thread and game logic
« Reply #2 on: January 02, 2014, 05:40:38 pm »
Unfortunately, as this is for a university project, the project brief states that I am required to use multiple threads.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Rendering thread and game logic
« Reply #3 on: January 02, 2014, 06:44:28 pm »
Unfortunately, as this is for a university project, the project brief states that I am required to use multiple threads.
Well one can use multiple threads in many ways. Do they actually specify how to use them, or just "use threads!!!!11"? ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

homar

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Rendering thread and game logic
« Reply #4 on: January 02, 2014, 10:56:20 pm »
It just specifies that I should use multiple threads with message passing for communication between threads. There is no requirement for how I should separate the game into multiple threads.

Daddi

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
    • http://foxdev.de/
    • Email
Re: Rendering thread and game logic
« Reply #5 on: January 03, 2014, 12:45:23 am »
Is building a game a requirement too? If not, you should try something else with multithreaded architecture :D

 

anything