Game Engine Threading Model

I am interested in threading into a small engine that I work on in my spare time, but I'm curious what works best. I'm interested in the recommended way to synchronize the physics stream with the rest of the engine, similar to ThisGuy . I work with the Bullet Physics SDK, which already uses the method of copying the data that he described, but I was interested, as soon as the bullet goes through one simulation, then synchronizes the data with other streams, will it lead to something like vertical synchronization, where is the rendering stream, halfway through the processing data, suddenly starting to use a new and different set of information?

Is this what the viewer will be able to notice? What if some kind of explosion appears with an object that must be destroyed?

If this is a problem, then the best way to solve it?

Block a physical stream so that it cannot do anything until the rendering stream (and basically every other stream) passes through its frame? It seems that it would lose processor time. Or the preferred triple buffer method, copy physics data to second place, continue physical modeling, and then copy this data to the rendering stream after it's ready?

What approaches do you recommend?

+4
source share
1 answer

The simplest and probably most commonly used option is to physically launch, visualize, ai, ... the threads in parallel and synchronize them after each of them has finished with the / timestep frame. This is not the fastest solution, but one with the least problems. Writing data to the rendering stream when it starts leads to massive synchronization problems (for example, you must block each vector / matrix when it is updated). For parallelization efficiency to be effective, you must minimize the amount of data to synchronize, for example. just write data to the render stream that you can visualize.

When you don’t synchronize after each frame, you can probably get the effect that physics / ai uses the entire processor power of 60 frames per second, while rendering only 10 frames per second, which in most cases is not , What would you like.

Double buffering will also improve performance, but you still need to synchronize your threads. The problem is ai and a physical or similar stream, as they may require changes to the same data.

+2
source

Source: https://habr.com/ru/post/1313604/


All Articles