Fix several hard-dels, add harddel ref tracking (#16174)

This commit is contained in:
Wildkins
2023-04-10 16:42:20 -04:00
committed by GitHub
parent e9a9bb3323
commit 3f4786ab23
30 changed files with 418 additions and 905 deletions
+53 -10
View File
@@ -447,7 +447,7 @@
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(RECURSIVE_CONTENTS_HEARING_SENSITIVE), old_target)
if(old_target.important_recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS])
GRID_CELL_REMOVE(intersecting_cell.hearing_contents, old_target.important_recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS])
GRID_CELL_REMOVE(intersecting_cell.tgt_contents, old_target.important_recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS])
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(RECURSIVE_CONTENTS_AI_TARGETS), old_target)
@@ -465,6 +465,7 @@
GRID_CELL_REMOVE(input_cell.client_contents, to_remove)
GRID_CELL_REMOVE(input_cell.hearing_contents, to_remove)
GRID_CELL_REMOVE(input_cell.tgt_contents, to_remove)
///if shit goes south, this will find hanging references for qdeleting movables inside the spatial grid
/datum/controller/subsystem/spatial_grid/proc/find_hanging_cell_refs_for_movable(atom/movable/to_remove, remove_from_cells = TRUE)
@@ -484,7 +485,7 @@
for(var/list/z_level_grid as anything in grids_by_z_level)
for(var/list/cell_row as anything in z_level_grid)
for(var/datum/spatial_grid_cell/cell as anything in cell_row)
if(to_remove in (cell.hearing_contents | cell.client_contents))
if(to_remove in (cell.hearing_contents | cell.client_contents | cell.tgt_contents))
containing_cells += cell
if(remove_from_cells)
force_remove_from_cell(to_remove, cell)
@@ -509,17 +510,21 @@
/atom/proc/find_grid_statistics_for_z_level(insert_clients = 0)
var/raw_clients = 0
var/raw_hearables = 0
var/raw_targets = 0
var/cells_with_clients = 0
var/cells_with_hearables = 0
var/cells_with_targets = 0
var/list/client_list = list()
var/list/hearable_list = list()
var/list/target_list = list()
var/total_cells = (world.maxx / SPATIAL_GRID_CELLSIZE) ** 2
var/average_clients_per_cell = 0
var/average_hearables_per_cell = 0
var/average_targets_per_cell = 0
var/hearable_min_x = (world.maxx / SPATIAL_GRID_CELLSIZE)
var/hearable_max_x = 1
@@ -533,6 +538,12 @@
var/client_min_y = (world.maxy / SPATIAL_GRID_CELLSIZE)
var/client_max_y = 1
var/target_min_x = (world.maxx / SPATIAL_GRID_CELLSIZE)
var/target_max_x = 1
var/target_min_y = (world.maxy / SPATIAL_GRID_CELLSIZE)
var/target_max_y = 1
var/list/inserted_clients = list()
if(insert_clients)
@@ -546,7 +557,7 @@
for(var/client_to_insert in 0 to insert_clients)
var/turf/random_turf = pick(turfs)
var/mob/fake_client = new()
fake_client.important_recursive_contents = list(SPATIAL_GRID_CONTENTS_TYPE_HEARING = list(fake_client), SPATIAL_GRID_CONTENTS_TYPE_CLIENTS = list(fake_client))
fake_client.important_recursive_contents = list(SPATIAL_GRID_CONTENTS_TYPE_HEARING = list(fake_client), SPATIAL_GRID_CONTENTS_TYPE_CLIENTS = list(fake_client), SPATIAL_GRID_CONTENTS_TYPE_TARGETS = list(fake_client))
fake_client.forceMove(random_turf)
inserted_clients += fake_client
@@ -555,9 +566,11 @@
for(var/datum/spatial_grid_cell/cell as anything in all_z_level_cells)
var/client_length = length(cell.client_contents)
var/hearable_length = length(cell.hearing_contents)
var/target_length = length(cell.tgt_contents)
raw_clients += client_length
raw_hearables += hearable_length
raw_targets += target_length
if(client_length)
cells_with_clients++
@@ -593,11 +606,30 @@
if(cell.cell_y > hearable_max_y)
hearable_max_y = cell.cell_y
if(target_length)
cells_with_targets++
target_list += cell.tgt_contents
if(cell.cell_x < target_min_x)
target_min_x = cell.cell_x
if(cell.cell_x > target_max_x)
target_max_x = cell.cell_x
if(cell.cell_y < target_min_y)
target_min_y = cell.cell_y
if(cell.cell_y > target_max_y)
target_max_y = cell.cell_y
var/total_client_distance = 0
var/total_hearable_distance = 0
var/total_target_distance = 0
var/average_client_distance = 0
var/average_hearable_distance = 0
var/average_target_distance = 0
for(var/hearable in hearable_list)//n^2 btw
for(var/other_hearable in hearable_list)
@@ -611,24 +643,35 @@
continue
total_client_distance += get_dist(client, other_client)
for(var/target in target_list)
for(var/other_target in target_list)
if(target == other_target)
continue
total_target_distance += get_dist(target, other_target)
if(length(hearable_list))
average_hearable_distance = total_hearable_distance / length(hearable_list)
if(length(client_list))
average_client_distance = total_client_distance / length(client_list)
if(length(target_list))
average_target_distance = total_target_distance / length(target_list)
average_clients_per_cell = raw_clients / total_cells
average_hearables_per_cell = raw_hearables / total_cells
average_targets_per_cell = raw_targets / total_cells
for(var/mob/inserted_client as anything in inserted_clients)
qdel(inserted_client)
message_admins("on z level [z] there are [raw_clients] clients ([insert_clients] of whom are fakes inserted to random station turfs) \
and [raw_hearables] hearables. all of whom are inside the bounding box given by \
clients: ([client_min_x], [client_min_y]) x ([client_max_x], [client_max_y]) \
and hearables: ([hearable_min_x], [hearable_min_y]) x ([hearable_max_x], [hearable_max_y]) \
on average there are [average_clients_per_cell] clients per cell and [average_hearables_per_cell] hearables per cell. \
[cells_with_clients] cells have clients and [cells_with_hearables] have hearables, \
the average client distance is: [average_client_distance] and the average hearable_distance is [average_hearable_distance].")
message_admins("on z level [z] there are [raw_clients] clients ([insert_clients] of whom are fakes inserted to random station turfs), \
[raw_hearables] hearables, and [raw_targets] targets. all of whom are inside the bounding box given by \
clients: ([client_min_x], [client_min_y]) x ([client_max_x], [client_max_y]), \
hearables: ([hearable_min_x], [hearable_min_y]) x ([hearable_max_x], [hearable_max_y]), \
and targets: ([target_min_x], [target_min_y]) x ([target_max_x], [target_max_y]). \
on average there are [average_clients_per_cell] clients per cell, [average_hearables_per_cell] hearables per cell, and \
[average_targets_per_cell] targets per cell. [cells_with_clients] cells have clients, [cells_with_hearables] have hearables, \
and [cells_with_targets] have targets. the average client distance is: [average_client_distance], the average hearable_distance \
is [average_hearable_distance], and the average target distance is [average_target_distance].")
#undef GRID_CELL_ADD
#undef GRID_CELL_REMOVE