优化高密度二进制空间划分为网格 [英] Optimal High-Density Binary Space Partition for Grids

查看:234
本文介绍了优化高密度二进制空间划分为网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个游戏,人物走动的实时随机生成的地图(因为它的发现。)这就引出了一个有趣的数据结构的问题。地图被生成,因为它涉及到视图中,在字符周围的圆(大概20-60瓦),以便在有数据时,它是非常密集,并且所有在一个网格。哪里有没有数据,不过,有可能是巨大的,ungenerated空间。字符可以走在一个巨大的圆圈,例如,创建围绕空旷的空间瓷砖环。

I'm writing a game in which a character moves around on a randomly generated map in real time (as it's revealed.) This leads me an interesting data structures problem. The map is generated as it comes into view, in a circle around the character (probably 20-60 tiles) so where there is data, it is very dense, and all in a grid. Where there's not data, though, there could be huge, ungenerated spaces. The character could walk in a huge circle, for example, creating a ring of tiles around vast empty space.

一个简单的矩阵将造成不必要的开销,大量的,浪费了大量的空间。典型的BSP,不过,看起来他们会导致由于数据的密集,网格状的性质巨大的性能下降。

A simple matrix would create massive amounts of unneeded overhead, and waste a lot of space. Typical BSPs, though, seem like they would cause a huge performance drop because of the dense, grid-like nature of the data.

你有什么建议怎么样?矩阵 - 四叉树 - ?两者的某种混合

What do you suggest? Matrixes - quadtrees - some hybrid of the two?

推荐答案

我一直在处理这个在过去的一个月,而且都拿出了什么,我相信这是一个相当不错的解决方案。这不是一样快,一个纯粹的基体,但有被无限扩展

I've been tackling this for the past month, and have come up with what I believe is a fairly good solution. It's not as fast as a pure matrix, but has the benefit of being infinitely extensible (within the limits of an int.)

基本上,这是它构建起就是一个二进制空间分割(而不是向下,像一个四叉树)。如果你写一个点的当前分配矩阵空间之外,它会产生一个较大的节点,并展开。如果大多数节点的子节点分配矩阵,将它们聚集到自身,并删除它们的引用。这意味着,更明确定义的边界使用,更好的性能你得到的,作为更这种结构的作用就像一个矩阵

Basically, it's a binary space partition which builds upwards (instead of downwards, like a quadtree.) If you write to a point outside of the currently allocated matrix space, it generates a larger node and expands. If a majority of a node's children nodes are allocated matrices, it will aggregate them into itself and remove their references. This means that the more well-defined boundaries you use, the better performance you get, as the more this structure acts like a matrix.

我已经张贴了我的code ,并会尝试写一些排序演示的未来,并移动到一个更好的托管网站。

I've posted my code here, and will try and write some sort of demo in the future, and move to a better hosting site.

不要犹豫,让我知道你在想什么,或者,如果您有任何问题了。

Don't hesitate to let me know what you think, or if you have any questions about it.

这篇关于优化高密度二进制空间划分为网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆