I am working on a java LWJGL game based on minecraft. I am working on the terrain management which is hard because the world can expand as you explore. How would you manage the terrain if it is stored in chunk objects and you needed to know which chunk to remove from the render list, which to add, and which to generate based on player's xyz position?
Asked
Active
Viewed 4,439 times
0
-
Which part of it is causing you problems? As it is, the question seems to be far too broad. – biziclop Jul 07 '12 at 16:27
-
The Part that stumps me is how to store the chunks in a way that you can easily tell whether they are rendered, and remove them if you are far away or add them if you are close. This is hard to do as you can't really use an array for an infinite world and Arraylist is hard to find out which chunk in the index goes to which xyz position. – Mad3ngineer Jul 07 '12 at 16:51
-
I come back now that I figured it out... The reason I was stumped was that I was so worried about the performance. – Mad3ngineer Oct 20 '12 at 19:33
1 Answers
3
I work with high resolution medical voxel data and use an octree to store it in an efficient way.
You cannot really use an octree because you want dynamically expanding terrain (an octree is extremly fast when it comes to lookups, but very slow on building/extending).
I suggest you try to use a HashMap, if you provide a good hash function for Vector3 the lookup time will be nearly the same for any amount of chunks (theoretically O(1), but that's just the best case ... ).
You can then remove all map entries that are out of sight by iterating through the map keys.(this could be done on a secondary thread that handles all loading/unloading).
Hope this helps,
~ Loki

Loki
- 46
- 2
-
2I've found that the best way is to split each world section up so that one chunk has an array of `16x16x16` blocks, then a region has an array of `16x16x16` chunks, then the world can have an array of `117188x1x117188` regions for a total of `30000128` blocks in each compass direction(similar to minecraft). The game I'm working on has slightly different array sizes, but the concept is the same. – Brian_Entei Sep 24 '15 at 16:38
-
And when I say array I mean something like `Block[][][] blocks = new Block[16][16][16];`, NOT a hashmap or arraylist; as I have tried those and they seem to be far slower than a traditional 3 dimensional array. – Brian_Entei Sep 24 '15 at 16:39