What does WorldView do?

AlbireoX

Unsuccessful Javascript Evangelist
Contributor
Logistics
At first, I thought it was a view of the world and all of your currently loaded chunks. But it seems that new ones are created in updateChunksInProximity() in a for loop?

What are the purposes of WorldView, Region3i, and World/ChunkProvider?
 

Immortius

Lead Software Architect
Contributor
Architecture
GUI
I did actually answer that first question in IRC, I guess you missed it?

A World View provides direct access to a sub-section of the world in the form of a rectangle of adjacent chunks. A very typical view is a chunk and all its adjacent chunks, but it can be as large or small as is necessary (within reason). The view can be given an offset, so that rather than having systems worried about the absolute position of the blocks it can use relative positions - very useful during the generation phases. Methods are also provided for locking and checking all the chunks involved in the view. It is potentially more efficient than going through the world for each block change because the chunks are in an array rather than a hashmap. The world view takes care of bound checks and such too.

Specifically for something like ChunkTessellation, you need both the chunk and the surrounding chunks to create the chunk's mesh (for testing adjacent blocks and gathering light information), so a view of both the target chunk and the surrounds is used.

Region3i is basically an integer version of an AABB. It denotes a 3D rectangular area in terms of a min and max Vector3i, provides some methods about checking what is in and out of the area, iterating over the contents and so forth. It is one of those generally handy math classes. I use it a lot because

Code:
for (Vector3i position : Region3i.createMinMax(Vector3i.zero(), new Vector3i(15,15,15))) {
    // do something...
}
Is a lot clearer than a three loops over X, Y and Z. (Can be read as "for each position in the region (0,0,0) -> (15,15,15)")

ChunkProvider manages the actual chunks, WorldProvider is an interface for working with the world as a whole, which is built over a ChunkProvider. Most game logic should work with the WorldProvider. At the moment we have a LocalChunkProvider implementation, in the future there will be a RemoteChunkProvider implementation for multiplayer. LocalChunkProvider deals mostly with loading and unloading/caching/saving chunks as they move in and out of relevance, which is based on the position of the player(s).
 

AlbireoX

Unsuccessful Javascript Evangelist
Contributor
Logistics
I did actually answer that first question in IRC, I guess you missed it?
Unfortunately, I did not. I probably logged off or something. If I didn't, I'm blind. Sorry :/

Thank you for the useful information. Perhaps WorldView should be renamed to SurroundingChunks or ChunkGroup or ChunkRegion.
 

Immortius

Lead Software Architect
Contributor
Architecture
GUI
Maybe ChunkView or ChunkSubview. I think View describes nicely what it does - it doesn't own the chunks or control them, just presents a view over the top of them (similar to Boost's multidimensional array views). World might be a little strong, I agree.
 
Top