xy 坐标系需要可调整大小的数据类型
我正在编写一个程序来修改简单 3D 游戏地图的选定块 (我的世界)。该地图理论上非常大,因此加载整个地图地图是不可能的。我只想加载每个 16x16 大小的块一次,并将这些块保留在内存中,以便我需要再次修改它。我需要一个数据结构来以 (x,y) 坐标方式将这些部分存储在内存中,同时能够根据需要调整该数据结构的大小并保持其有序,以便我可以找到特定的块。 我不知道可以使用什么数据结构来满足我的要求。我希望有人可以提出一些建议。我正在用 c# 编码。
I am coding a program to modify select chunks of a simple 3d game map (minecraft). The map can be theoretically very large so loading the entire map is out of the question. I want to only load each 16x16 sized chunk once and have those chunks in memory should I need to modify it again. I need a data structure to store these portions in memory in an (x,y) coordinate fashion while being able to resize this data structure as needed and keep it orderly so I can find specific chunks.
I am at a loss on what data structure I could use to meet my requirements. I am hoping someone could make some suggestions. I am coding in c#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用顶级
Map
数据结构,该结构具有基于坐标
的索引器。接下来添加一个Chunk
数据结构,它就像一个微型地图。在 Map 索引器的访问器中,检查是否加载了包含坐标的块,如果没有则加载它。然后将Map
索引器委托给Chunk
索引器。Map
可以使用Dictionary
跟踪加载了哪些块。最后,您需要根据策略卸载块,例如最近最少使用的策略。有了这个基础设施,您就可以将
Map
用作虚拟的无限平面。这里有一些(未经测试的)伪代码可以帮助您入门:
I recommend a top level
Map
data structure that has an indexer based on aCoordinate
. Next add aChunk
data structure which is like a miniature map. In the accessors for theMap
indexer, check whether the chunk that contains the coordinate is loaded and if not load it. Then delegate theMap
indexer to theChunk
indexer. TheMap
can keep track of which chunks are loaded using aDictionary
. Finally, you need to unload chunks based on a strategy, e.g. least recently used.With this infrastructure in place you can then use the
Map
as a virtual infinite plane.Here's some (untested) pseudo-code to get you started: