SubChunks

object SubChunks

This class uses the mesh method to divide the space to optimize collision detection by reducing the number of calculations, but the worst-case time complexity of the algorithm when all objects are in dense space is still O(n^2 - n), which is same as the traversal algorithm.

A mesh in the mesh method is called Chunk/SubChunk here.

The implementation builds a two-dimensional array to store all the entities there (actually the UUID of the entity) and represent the mesh that divides the space, and within each logical frame, update the mesh in which the entities are located. Each time when an entity is processing collide testing, only those that are in the same meshes where it is located, might be more than one mesh, as the entity are detected, reducing the number of collision checks.

The default meshing number is 12*14, you can use the provided functions to automatically mesh, or set the number of divisions on the x-axis and y-axis yourself.

Author

KKoishi_

Functions

Link copied to clipboard

Adjust the SubChunks according to the specified width and height.

Link copied to clipboard

Returns if an entity which has the given UUID is in the SubChunks where the player located in.

Link copied to clipboard
fun modifySubChunk(widthAmount: Int, heightAmount: Int)
Link copied to clipboard
fun refresh()
Link copied to clipboard

When debug mode on, will render the meshes.

Link copied to clipboard

Set the baseSubChunkLength to the given value.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Reindex the space.