Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep my world data in synch in a multi-threaded game engine?

So I'm trying to create a simple multi-threaded game engine for the game I want to write. So far, everything has worked without any problems, I even know what steps I have to take to finish it.

There is only one thing I don't know (well, technically, I know a solution for it, but I'm hoping there is something more elegant and faster): Basically, I have a seperate thread for every part of my engine - Graphics, Input, Physics, Audio, etc.

The physics thread has a complete scene node structure of the world, where it simulates everything. However, I now have to get this structure over to my graphics thread, with the least overhead possible. Ideally, it should only transfer the parts which changed since the last update.

I have components in place for transfering this data, only problem is generating it.

So far, I have thought of two different approaches:

  • copy the whole structure for every update - very simple, but possibly time and memory intensife (I don't have experience with large engines - would this be viable?)
  • Keep track of which parts of the scene changed by marking the scene nodes with some flags, and then only copying over the changed parts

Approach one would copy a big amount of memory, but without much processing power, approach two would do the reverse: plenty of processing power, less memory copied.

Is there some general answer which approach would be faster in a typical gaming environment?

like image 531
Mononofu Avatar asked Oct 14 '22 16:10

Mononofu


1 Answers

No, there is not an accepted general answer, it is a current area of research in games development.

My 2 cents is the conventional wisdom - which one to use really depends on your specific use case - if your game has lots of data (ie it's very memory intensive, like most blockbuster titles), you'll probably want to just transmit changes. If your game isn't memory intensive (eg, arcade games), you can probably get away with copying the entire object.

I'd suggest implementing both and hooking up performance timers to see which works better for you; it is possible to implement an architecture which can handle both methods transparently.

like image 171
Not Sure Avatar answered Oct 20 '22 16:10

Not Sure