If this is your first game application, using multithreading to achieve your results may be more work than you should do in the first game. Synchronizing the game cycle and the rendering cycle in different streams is not an easy task.
As you correctly indicate, rendering time can greatly affect the "speed" of your game. I would suggest that you do not make your game logic dependent on a given time slice (i.e., 1/100 second). Make it dependent on the current time of the loop (well, the last time, since you don’t know how long your current frame will take to render).
Normally I would write something like below (what I wrote is strongly ):
float Frametime = 1.0f / 30.0f; while(1) { game_loop(Frametime);
Where Frametime is the calculated cycle time that the current frame has received. When you process a game loop, you use the cycle time from the previous frame (so set the initial value to something reasonable, such as 1/30 or 1/15 of a second). Starting it at the previous cycle time is close enough to get the results you need. Start the game loop using this time interval, and then draw your stuff. You may need to change the logic in the game loop in order not to assume a fixed time interval, but in general these types of corrections are quite simple.
Asynchronous game / rendering cycles may be something that you ultimately need, but this is a complex problem. It includes shooting objects objects and their corresponding data, placing these images in a buffer, and then transferring the buffer to the rendering engine. This memory buffer must be correctly partitioned around critical sections to avoid writing a game loop to it while the rendering cycle is being read from it. You will need to make sure that you copy all the relevant data to the buffer before going into the rendering cycle. In addition, you will need to write logic to stop either loops of the game or rendering, waiting for one or the other to complete.
This complexity is why I suggest writing it in a more consistent way first (unless you have experience that you could). The reason is that in doing so, the “simple” way will first make you find out how your code works, how the rendering engine works, what data the rendering engine needs, etc. Considerable knowledge of multithreading is required in the complex development of the game these days, but knowledge of how to do this requires a deep knowledge of how game systems interact with each other.
Mark source share