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

ⅰ亾dé卋堺 提交于 2020-01-12 23:46:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/761990/how-do-i-keep-my-world-data-in-synch-in-a-multi-threaded-game-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!