multithreading - Thoughts about rendering loop strategies -


I know that hundreds of variations of these ideas have been posted on the whole net. However, I do not know anything that describes my exact problem, so I hope you can help me see the light.

I am currently using OpenGL in Java with 2D game development. The language and graphics library used is not relevant to my question, though it has a more general character.

I am trying to design a general-purpose game loop which can be used for more or less, any game that has a modest heavy graphics (mostly bitmap texture) and possibly heavy game logic (AI, collision detection, etc.).

Actually I expect to keep the list of items / arrays / buffers

1) Updated a thread for updates (for updates) (Status, velocity, and other game updates) and rendering (texture / frames in updated status) rendering

I have tried a sequential solution and only one thread (good By the way two, when user input is counted), left using.

  • Calculate the changes and update the buffer object
  • Make the backbuffer the texture in the updated state
  • Bring back the backbuffer

    Apparently very good computing time is wasting on the Hell Swap buffers hardware, which demands a more efficient solution

    2) One for updates Thread, one for the rendering

    By dividing the program an updated thread and one To synchronize Ndering thread and shared buffer reaches I should be able to make a pretty steady framerate. Synchronizing access to shared buffers can be completed in many ways, but all of them have one thing in common. They restrict all thread concurrency, although this can be a fair trade, I am thinking that synchronization is necessary.

    3) Similar to 2, but without synchronization

    I understand that many problems that may be due to the negligent implementation of the concurrent thread. Producers / consumers, readers / writers and similar situations have potential deadlock. However, I do not understand that if the following criteria are met then I need to ensure the synchronization of the shared data (and they should be):

    • Render threads only Shared buffer can read
    • Update thread can read from both, and write shared buffer (hence it is only 'Author')
    • Never share buffer Will not be empty or complete, while the game is running
    • Thread Never sleep
    • Rendering should not be 100% accurate If some shared objects have not yet been updated, they are not updated if they are behind an object-step (like some 10-20 milliseconds) other objects. can be done.

      -

      So ... is there a clear point I am missing here? Why do I need to get this setup synchronized?

      • Cache thresholds that are causing problems when not synchronized properly?
      • Or can the data be damaged in any way if the writing thread gets interrupted at unfortunate times?
      • Or is there any common problem with my proposed Stagejee is it worthless?

        Any thoughts, comments or suggestions are most welcome or if this particular question has already been addressed elsewhere, then I would appreciate a reference.

        The unstructured approach will work right for you; If I double this stock Intel hardware 1 I still do not use it.

        The reason is that uncensored concurrency almost never works reliably, according to the processor, when there is a store and load between the main ram and the cache. It can erase almost any uninitialized protocol. However, as you say, if no visualization can ever change suddenly in your application, then there is no possibility of paying any attention; All data will go to RAM and the second thread will appear sooner or later.

        Although you have no guarantees when it will happen and in which the sequence, which leaves you with the theoretical probability of a mixture, weirdly after frames (suddenly or later of the visible or its light)

        Based on your programming language and its memory model (C ++ 11+++ I think?) You are likely to find light synchronization primitives whose favorable side effects find appropriate memory constraints, whose Impact will be negligible on display. This is what I would recommend as a starting point. Extreme performance optimization (which can be safe) should be the last step of optimizing your engine.


        1 ) I do not think it is documented anywhere and I do not like to trust it. You can still read the readings, so this is not a help in your scenario.

Comments