LWJGL
May 25, 2013, 17:50:34 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: How would you manage chunks in an infinitely expandable voxel based world?  (Read 2401 times)
dangerdoc
Regular nerd
**
Posts: 71


Thats right... Nikola Tesla


« on: July 06, 2012, 11:35:55 »

Hello,
I am making a voxel based 3-D game that can be infinitely generated in all directions using procedural terrain generation. I am having a hard time managing the world in a way that it has these requirements:

*It can be updated each frame quickly
*It can remove unused chunks
*It can find out whether or not a chunk is rendered and add it if it isn't


Any ideas?
The ideas I have tried aren't very sound, and they will not work with several features. I have a chunk class that stores the block data, and a ChunkManager class that loads and unloads the chunks using arraylist. How would you make them index-able so you can find whether chunk (x, y, z) is loaded? If I went through the arraylist each frame and checked the coordinates of the chunk to figure out which need to be loaded and removed, it would probably run slowly.

I am stumped, and I can't find any code that shows ways to do this in an infinitely expandable world (Yes, its based on exploring). Any help will be appreciated! Smiley

dangerdoc
Logged

“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla
CodeBunny
Nerdus Imperius
*****
Posts: 561



WWW
« Reply #1 on: July 06, 2012, 18:54:52 »

In all honesty, the StackExchange sites (StackOverflow, GameDev, etc.) are a better place for this. This is a very heavy-duty question.
Logged
dangerdoc
Regular nerd
**
Posts: 71


Thats right... Nikola Tesla


« Reply #2 on: July 07, 2012, 08:13:53 »

Ok, Thanks CodeBunny! Ill go ask there (If it doesn't ask for too much personal information lol). Also, the question is still open if someone has an answer!  Wink

Edit: Done!!  Cheesy

http://stackoverflow.com/questions/11376201/chunk-management-in-a-voxel-based-game
Logged

“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla
Fool Running
Nerdus Imperius
*****
Posts: 742


« Reply #3 on: July 09, 2012, 06:06:46 »

I would create some kind of hash code based on the x,y,z location so that you can just look it up in a HashTable. Otherwise (since the world in infinite and the values can get too large to create unique hashes), you could create some kind of tree structure (where the root is the whole world, then under that you have the world divided into smaller chunks, then smaller chunks, etc) all sorted in such a way that a search would be fast.
Logged

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option Grin
CodeBunny
Nerdus Imperius
*****
Posts: 561



WWW
« Reply #4 on: July 09, 2012, 07:55:03 »

Would it be possible to do a variant of that? Use the tree structure to organize saved chunk files, but while in game, use a 6-axial linked structure? Effectively, the player is "in" a given chunk, and that chunk is linked to all adjacent ones. As new chunks need to be loaded, the tree structure is called upon to determine the correct ones.

You'd need to do fewer lookups, and it you could use it to get rid of the "far lands" problem in chunk-based games.
Logged
dangerdoc
Regular nerd
**
Posts: 71


Thats right... Nikola Tesla


« Reply #5 on: August 18, 2012, 09:04:45 »

Okay, I have come up with a theory on how it might work.

Every frame, the main class would call chunkmanager, which tells each chunk to render itself via mesh object. Tells which chunks have been edited (ie, build/destroy), and adds them to the loadmesh queue. Loads one chunk from each queue. If it has been X frames, ask each chunk if it is outside of the boundaries for a chunk to be rendered. If a chunk is too far away from the player, add it to the remove queue. Check the players location, transfer that to chunk coordinates, and check if the chunks around the player are loaded. If they are not loaded, add them to the load queue.

Is that feasible? Or would you spread out the update more instead of doing it in one frame? Thanks! I also will be storing the chunks in bigger chunks.
Logged

“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla
basil
Regular nerd
**
Posts: 60



« Reply #6 on: September 01, 2012, 14:47:31 »

you can get a working thing with that idea. a http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html would be enough to start.

but loki's answer on http://stackoverflow.com/questions/11376201/chunk-management-in-a-voxel-based-game is actualy pretty right.
Logged
dangerdoc
Regular nerd
**
Posts: 71


Thats right... Nikola Tesla


« Reply #7 on: September 20, 2012, 12:46:15 »

Thanks basil. That library looks good for this.
Logged

“We build but to tear down. Most of our work and resource is squandered. Our onward march is marked by devastation. Everywhere there is an appalling loss of time, effort and life. A cheerless view, but true.” - Nikola Tesla
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!