Chunk
The chunk interface helps you to create you own chunk based systems with high performance.
Important: If you are looking for a ready to use "get the nearest point in range" system, please use the PointInRange
module.
Example: consider all entered locations
If the player steps into that location the
on_enter
callback is called.If the player leaves that location the
on_leave
callback is called.If there are more than one location at the same coordinates (or overlapping radius) all callbacks of the related locations are called (see
chunk_api.setModeAllEntered()
).
Example: Only nearest location
Like the example before but only that location nearest to the player will be called ( see
chunk_api.setModeOnlyEnteredNearest()
).
Public interface methods (NssLibsChunksApi
)
NssLibsChunksApi
).create()
.create()
Creates a chunk grid and return its api NssLibsChunkApi
.
Note: Be careful with grids, the more grids there are, the more performance it will need.
.clear()
.clear()
Clear all chunk grids of the resource.
Returns NssLibsChunksApi
.
Public methods of NssLibsChunkApi
NssLibsChunkApi
.setSize(size_in_meters)
.setSize(size_in_meters)
Sets the grid size in meters.
size_in_meters
(number) - The size of the grid in meters. The default is 5.
Returns NssLibsChunkApi
.
.setMonitoringInterval(interval_in_ms)
.setMonitoringInterval(interval_in_ms)
Sets the monitoring interval in milliseconds.
interval_in_ms
(number) - The interval in milliseconds. The default is1000
.0
means each frame.
Returns NssLibsChunkApi
.
.setModeAllEntered()
.setModeAllEntered()
All locations entered by the player will be called. E.g. you have two locations near besides to each other all locations will be called if the player steps into both location radius.
Returns NssLibsChunkApi
.
.setModeOnlyEnteredNearest()
.setModeOnlyEnteredNearest()
Only the location nearest to the player will be called. E.g. you have two locations near besides to each other the nearest one will be called if the player steps into both location radius.
Returns NssLibsChunkApi
.
.add(x, y, z, radius, on_enter_cb, on_leave_cb)
.add(x, y, z, radius, on_enter_cb, on_leave_cb)
Adds a location to the chunk grid.
x
(number) - The x coordinate of the location.y
(number) - The y coordinate of the location.z
(number) - The z coordinate of the location.radius
(number) - The radius of the location.on_enter_cb
(function(location_id
string)) - The callback function which is called if the player steps into the location.on_leave_cb
(function(location_id
string)) - The callback function which is called if the player steps out of the location or on nearest mode if another location is nearer.
Returns NssLibsChunkItemApi
.
.remove(location_id)
.remove(location_id)
Removes a location from the chunk grid.
location_id
(string) - The location id which was returned by theadd
method.
Returns NssLibsChunkApi
.
.reset()
.reset()
Clears (removes) all locations from the chunk grid.
Returns NssLibsChunkApi
.
Public methods of NssLibsChunkItemApi
NssLibsChunkItemApi
.getId()
.getId()
Returns the location id.
.remove()
.remove()
Remove the location from the chunk grid.
Returns nothing.
Dev notes
Currently, nothing ;)
Last updated