这种多线程过程生成算法有哪些潜在问题?

发布于 2024-12-12 03:13:29 字数 568 浏览 0 评论 0原文

我知道这是与游戏设计相关的,但我已阅读 StackOverflow 常见问题解答,它指出可以在此处提出软件算法问题。如果这在游戏设计上更好的话我希望有人能帮我移动它,谢谢!

我正在设计一个多线程程序地牢生成器。然而,我想知道我可能会遇到什么样的问题——我还没有找到很多清楚地显示多线程的算法。

我必须创建三个不同的对象。一个包含多个“房间”的“世界”,每个房间都将容纳潜在的“物体”。

当前的算法是这样工作的:

Step 1: Generate World
Step 2: Generate Rooms and Objects concurrently

世界包含一个房间列表和一个“可用对象列表”。房间创建方法将生成房间并将它们添加到世界的房间列表中。--对象创建过程不会以任何方式与房间过程进行通信。相反,对象创建过程将从世界的房间列表中选择随机房间并在房间中生成随机对象。

我看到的唯一问题是——如果对象创建过程过早完成。换句话说,只有房间列表中的某些房间才会在其中创建对象,因为房间创建过程晚于对象创建过程完成。

还有更多问题吗?有人对开发此类算法有任何建议或经验吗?

I know this is game design related, but I have read the StackOverflow FAQ and it states software algorithm questions can be asked here. If this is better off in game design then I hope someone can help me move it, thanks!

I am designing a multi-threaded procedural dungeon generator. However, I am wondering what kinds of problems I am likely to run into-- I haven't been able to find many algorithms that clearly showed multi-threaded in them.

I have three distinct objects which must be created. A 'World' which houses multiple 'Rooms' and each room will house potential 'Objects.'

The current algorithm works like this:

Step 1: Generate World
Step 2: Generate Rooms and Objects concurrently

The World houses a room list, and an 'available objects list.' The Room creation method will generate rooms and add them to the World's room list.-- the Object creation procedure will not communicate with the Room procedure in any way. Rather, the Object creation procedure will pick random rooms from the World's room list and generate random objects in the room.

The only problem I see with this is-- if the Object creation procedure finishes pre-maturely. In other words only some of the rooms in the room list will have objects created in them because the room creation procedure finished later than the object creation procedure.

Are there more problems, and does anyone have any advice or experience with developing such algorithms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兰花执着 2024-12-19 03:13:29

首先,您提到的问题不是真实的问题,因为您应该简单地执行 3 个步骤:

  1. 生成世界
  2. 并发生成房间
  3. 并发生成对象

按照这个顺序,确保所有房间都存在。无论如何,在性能方面,将 2+3 组合在一起并不会获得太多好处。

然而,与并发性一样,主要问题是将结果连接在一起。如果您的房间保存在列表中,则需要同步附加到该列表,这会减慢您的处理速度。一旦您开始在世界空间中实际创建房间,并且必须确保并行生成的房间不占据相同的空间(房间内的对象相同),就会出现一个更复杂的问题。

Firstly, the problem mentioned by you isn't a real one, because you should simply work with 3 steps:

  1. Generate world
  2. Generate rooms concurrently
  3. Generate objects concurrently

In that order, it is ensured that all rooms are present. And you don't gain much from keeping 2+3 together in terms of performance anyways.

However, the main problem, as typical with concurrency, is when you join your results together. If your rooms are kept in a list, then appending to that list needs to be synchronized, which slows down your processing. A much more involved problem occurs, once you start to actually create rooms in a world-space and have to ensure that rooms generated in parallel do not occupy the same space (same for objects inside a room).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文