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 个解决方案
#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.
我的2美分是传统的智慧 - 使用哪一个真正取决于你的具体用例 - 如果你的游戏有很多数据(即它的内存密集,就像大多数重磅炸弹的标题一样),你可能只想传输变化。如果你的游戏不是内存密集型游戏(例如街机游戏),你可能会抄袭整个对象。
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.
我建议实现这两个并连接性能计时器,看看哪个更适合你;可以实现一种可以透明地处理这两种方法的体系结构。
#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.
我的2美分是传统的智慧 - 使用哪一个真正取决于你的具体用例 - 如果你的游戏有很多数据(即它的内存密集,就像大多数重磅炸弹的标题一样),你可能只想传输变化。如果你的游戏不是内存密集型游戏(例如街机游戏),你可能会抄袭整个对象。
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.
我建议实现这两个并连接性能计时器,看看哪个更适合你;可以实现一种可以透明地处理这两种方法的体系结构。