Pager - rvandoosselaer/Blocks GitHub Wiki
Using the Pager base class, Blocks has the ability to load and unload chunks around the player using a 3D grid. Blocks has 2 implementations of the Pager class. One for handling the meshes in the scene graph (ChunkPager) and one for handling the collision meshes in a physics space (PhysicsChunkPager).
The size of the grids that the Pager will use is set in the BlocksConfig
object:
BlocksConfig.getInstance().setGridSize(new Vec3i(5, 5, 5));
BlocksConfig.getInstance().setPhysicsGridSize(new Vec3i(3, 3, 3));
The above code will let the ChunkPager page 2 chunks around the current chunk of the player. 2 chunks to the left and right, 2 chunks to the top and bottom and 2 chunks to the front and back. Totalling to a grid of (5, 5, 5) chunks that will be loaded. Same for the PhysicsChunkPager but with a grid of (3, 3, 3) chunks.
The world location of the player should be set and updated using the setLocation(Vector3f location)
method on the Pager class. This way the Pager can calculate the current center chunk and correctly 'page' the surrounding chunks:
ChunkPagerState chunkPager = stateManager.getState(ChunkPagerState.class);
chunkPager.setLocation(new Vector3f(player.getWorldTranslation()));
The Pager uses the ChunkManager to load, generate and request chunks.
The lifecycle of a Pager is similar to that of the ChunkManager. It is good practice to handle the lifecycle in the appropriate AppState's: ChunkPagerState, PhysicsChunkPagerState.
ChunkPager
The ChunkPager 'pages' the chunks around a center location. Given the default grid size of (9, 5, 9), this means that from the center chunk, 4 chunks to the left, right, front and back and 2 chunks above and below are loaded.
PhysicsChunkPager
The PhysicsChunkPager 'pages' the collision meshes around a center location. Given the default grid size of (5, 3, 5), this means that from the center, 2 chunk meshes to the left, right, front and back and 1 chunk mesh above and below are loaded.
See javadoc