mirror of
https://github.com/Citadel-Station-13/Citadel-Station-13-RP.git
synced 2026-08-27 17:57:05 +01:00
fast turf reservation lookups & aligned spatial grid lookups (#6532)
# why? non-player facing we're going to need fast lookups for "is this thing in range of this other thing" at some point, for things like telecomms this current solution consumes about 16KB per reservation level we also add the capability to use spatial grids to quickly get atoms on a level. spatial grids are also at 16KB per grid, per world level all in all worth it in my opinion.
This commit is contained in:
@@ -9,8 +9,6 @@
|
||||
registered_type = /datum/component/spatial_grid
|
||||
/// target spatial grid
|
||||
var/datum/spatial_grid/grid
|
||||
/// target grid resolution
|
||||
var/grid_resolution
|
||||
/// target grid width
|
||||
var/grid_width
|
||||
/// last grid index
|
||||
@@ -24,7 +22,6 @@
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
src.grid = grid
|
||||
src.grid_resolution = grid.resolution
|
||||
src.grid_width = grid.width
|
||||
|
||||
/datum/component/spatial_grid/RegisterWithParent()
|
||||
@@ -43,7 +40,7 @@
|
||||
RegisterSignal(root, COMSIG_MOVABLE_MOVED, PROC_REF(update))
|
||||
root = root.loc
|
||||
if(isturf(root))
|
||||
var/idx = ceil(root.x / grid_resolution) + grid_width * floor(root.y / grid_resolution)
|
||||
var/idx = ceil(root.x / TURF_CHUNK_RESOLUTION) + grid_width * (ceil(root.y / TURF_CHUNK_RESOLUTION) - 1)
|
||||
grid.direct_insert(parent, root.z, idx)
|
||||
current_index = idx
|
||||
|
||||
@@ -61,7 +58,7 @@
|
||||
return
|
||||
// turf --> turf, try to do an optimized, lazy update
|
||||
if(isturf(oldloc) && isturf(newloc) && (oldloc.z == newloc.z))
|
||||
var/new_index = ceil(newloc.x / grid_resolution) + grid_width * floor(newloc.y / grid_resolution)
|
||||
var/new_index = ceil(newloc.x / TURF_CHUNK_RESOLUTION) + grid_width * (ceil(newloc.y / TURF_CHUNK_RESOLUTION) - 1)
|
||||
var/z = oldloc.z
|
||||
if(new_index != current_index)
|
||||
grid.direct_remove(parent, z, current_index)
|
||||
|
||||
Reference in New Issue
Block a user