Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7c564fb
I must not lag. Lag is the server-killer.
JohnWildkins Sep 30, 2025
47a1a20
Lag is the little-death that brings total obliteration.
JohnWildkins Sep 30, 2025
0d1003b
Merge branch 'master' of https://github.com/Aurorastation/Aurora.3 in…
JohnWildkins Sep 30, 2025
921c360
I will face the lag. I will permit it to pass over me and through me.
JohnWildkins Sep 30, 2025
5803794
And when it has gone past, I will turn the profiler to see its path.
JohnWildkins Sep 30, 2025
f85e85c
Where the lag has gone there will be nothing.
JohnWildkins Sep 30, 2025
8221b32
Only I will remain.
JohnWildkins Sep 30, 2025
f91794e
This wise man observed that performance is a tool of maintainers.
JohnWildkins Oct 1, 2025
ae9eea6
But the pursuit of performance is the way to slavery.
JohnWildkins Oct 1, 2025
1f23076
Performance is a constant race between invention and catastrophe.
JohnWildkins Oct 1, 2025
e659bc8
Documentation helps but it's never enough. You must also commit.
JohnWildkins Oct 1, 2025
a806844
A reference followed precisely to its end leads precisely nowhere.
JohnWildkins Oct 1, 2025
7932312
Coding foolishness is ultimately suicidal. They believe that by riski…
JohnWildkins Oct 1, 2025
e0e353d
el bruh
liermattia Oct 2, 2025
3e919ae
s
liermattia Oct 2, 2025
ae08514
They have the contributor mentality, that false sense of freedom from…
JohnWildkins Oct 2, 2025
94c59ca
el bruh 2
liermattia Oct 2, 2025
49b5817
I'm mister lag catcher, Maintainer Gang ref snatcher
JohnWildkins Oct 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/byond.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
env:
MACRO_COUNT: 0
GENDER_COUNT: 6
TO_WORLD_COUNT: 179
TO_WORLD_COUNT: 178

#These variables are filled from dependencies.sh inside the steps, DO NOT SET THEM HERE
BYOND_MAJOR: ""
Expand Down
1 change: 1 addition & 0 deletions aurorastation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,7 @@
#include "code\modules\hydroponics\spreading\spreading.dm"
#include "code\modules\hydroponics\spreading\spreading_growth.dm"
#include "code\modules\hydroponics\spreading\spreading_response.dm"
#include "code\modules\hydroponics\trays\_defines.dm"
#include "code\modules\hydroponics\trays\tray.dm"
#include "code\modules\hydroponics\trays\tray_process.dm"
#include "code\modules\hydroponics\trays\tray_reagents.dm"
Expand Down
7 changes: 5 additions & 2 deletions code/__DEFINES/spatial_gridmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#define SPATIAL_GRID_CONTENTS_TYPE_CLIENTS RECURSIVE_CONTENTS_CLIENT_MOBS
///all atmos machines are stored in this channel (I'm sorry kyler)
#define SPATIAL_GRID_CONTENTS_TYPE_ATMOS "spatial_grid_contents_type_atmos"
/// everything that can be targeted
#define SPATIAL_GRID_CONTENTS_TYPE_TARGETS RECURSIVE_CONTENTS_AI_TARGETS

#define ALL_CONTENTS_OF_CELL(cell) (cell.hearing_contents | cell.client_contents | cell.atmos_contents)
#define ALL_CONTENTS_OF_CELL(cell) (cell.hearing_contents | cell.client_contents | cell.atmos_contents | cell.target_contents)

///whether movable is itself or containing something which should be in one of the spatial grid channels.
#define HAS_SPATIAL_GRID_CONTENTS(movable) (movable.spatial_grid_key)
Expand Down Expand Up @@ -52,4 +54,5 @@
#define GRID_CELL_REMOVE_ALL(cell, movable) \
GRID_CELL_REMOVE(cell.hearing_contents, movable) \
GRID_CELL_REMOVE(cell.client_contents, movable) \
GRID_CELL_REMOVE(cell.atmos_contents, movable)
GRID_CELL_REMOVE(cell.atmos_contents, movable) \
GRID_CELL_REMOVE(cell.target_contents, movable)
92 changes: 84 additions & 8 deletions code/controllers/subsystems/spatial_gridmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
var/list/client_contents
///every atmos machine inside this cell
var/list/atmos_contents
///every valid ai turret target inside this cell
var/list/target_contents

/datum/spatial_grid_cell/New(cell_x, cell_y, cell_z)
. = ..()
Expand All @@ -43,6 +45,7 @@
hearing_contents = dummy_list
client_contents = dummy_list
atmos_contents = dummy_list
target_contents = dummy_list

/datum/spatial_grid_cell/Destroy(force)
if(force)//the response to someone trying to qdel this is a right proper fuck you
Expand Down Expand Up @@ -85,7 +88,7 @@ SUBSYSTEM_DEF(spatial_grid)
///list of the spatial_grid_cell datums per z level, arranged in the order of y index then x index
var/list/grids_by_z_level = list()
///everything that spawns before us is added to this list until we initialize
var/list/waiting_to_add_by_type = list(SPATIAL_GRID_CONTENTS_TYPE_HEARING = list(), SPATIAL_GRID_CONTENTS_TYPE_CLIENTS = list(), SPATIAL_GRID_CONTENTS_TYPE_ATMOS = list())
var/list/waiting_to_add_by_type = list(SPATIAL_GRID_CONTENTS_TYPE_HEARING = list(), SPATIAL_GRID_CONTENTS_TYPE_CLIENTS = list(), SPATIAL_GRID_CONTENTS_TYPE_ATMOS = list(), SPATIAL_GRID_CONTENTS_TYPE_TARGETS = list())
///associative list of the form: movable.spatial_grid_key (string) -> inner list of spatial grid types for that key.
///inner lists contain contents channel types such as SPATIAL_GRID_CONTENTS_TYPE_HEARING etc.
///we use this to make adding to a cell static cost, and to save on memory
Expand Down Expand Up @@ -257,6 +260,12 @@ SUBSYSTEM_DEF(spatial_grid)
for(var/x_index in BOUNDING_BOX_MIN(center_x) to BOUNDING_BOX_MAX(center_x, cells_on_x_axis))
. += grid_level[row][x_index].atmos_contents

if(SPATIAL_GRID_CONTENTS_TYPE_TARGETS)
for(var/row in BOUNDING_BOX_MIN(center_y) to BOUNDING_BOX_MAX(center_y, cells_on_y_axis))
for(var/x_index in BOUNDING_BOX_MIN(center_x) to BOUNDING_BOX_MAX(center_x, cells_on_x_axis))

. += grid_level[row][x_index].target_contents

return .

///get the grid cell encomapassing targets coordinates
Expand Down Expand Up @@ -378,6 +387,11 @@ SUBSYSTEM_DEF(spatial_grid)
GRID_CELL_SET(intersecting_cell.hearing_contents, new_target.important_recursive_contents[SPATIAL_GRID_CONTENTS_TYPE_HEARING])
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_ENTERED(SPATIAL_GRID_CONTENTS_TYPE_HEARING), new_target_contents[SPATIAL_GRID_CONTENTS_TYPE_HEARING])

if(SPATIAL_GRID_CONTENTS_TYPE_TARGETS)
var/list/new_target_contents = new_target.important_recursive_contents
GRID_CELL_SET(intersecting_cell.target_contents, new_target.important_recursive_contents[SPATIAL_GRID_CONTENTS_TYPE_TARGETS])
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_ENTERED(SPATIAL_GRID_CONTENTS_TYPE_TARGETS), new_target_contents[SPATIAL_GRID_CONTENTS_TYPE_TARGETS])

if(SPATIAL_GRID_CONTENTS_TYPE_ATMOS)
GRID_CELL_SET(intersecting_cell.atmos_contents, new_target)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_ENTERED(SPATIAL_GRID_CONTENTS_TYPE_ATMOS), new_target)
Expand Down Expand Up @@ -408,6 +422,11 @@ SUBSYSTEM_DEF(spatial_grid)
GRID_CELL_SET(intersecting_cell.hearing_contents, new_target.important_recursive_contents[SPATIAL_GRID_CONTENTS_TYPE_HEARING])
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_ENTERED(SPATIAL_GRID_CONTENTS_TYPE_HEARING), new_target_contents[SPATIAL_GRID_CONTENTS_TYPE_HEARING])

if(SPATIAL_GRID_CONTENTS_TYPE_TARGETS)
var/list/new_target_contents = new_target.important_recursive_contents
GRID_CELL_SET(intersecting_cell.target_contents, new_target.important_recursive_contents[SPATIAL_GRID_CONTENTS_TYPE_TARGETS])
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_ENTERED(SPATIAL_GRID_CONTENTS_TYPE_TARGETS), new_target_contents[SPATIAL_GRID_CONTENTS_TYPE_TARGETS])

if(SPATIAL_GRID_CONTENTS_TYPE_ATMOS)
GRID_CELL_SET(intersecting_cell.atmos_contents, new_target)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_ENTERED(SPATIAL_GRID_CONTENTS_TYPE_ATMOS), new_target)
Expand Down Expand Up @@ -447,6 +466,11 @@ SUBSYSTEM_DEF(spatial_grid)
GRID_CELL_REMOVE(intersecting_cell.hearing_contents, old_target_contents)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(type), old_target_contents)

if(SPATIAL_GRID_CONTENTS_TYPE_TARGETS)
var/list/old_target_contents = old_target.important_recursive_contents?[type] || old_target
GRID_CELL_REMOVE(intersecting_cell.target_contents, old_target_contents)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(type), old_target_contents)

if(SPATIAL_GRID_CONTENTS_TYPE_ATMOS)
GRID_CELL_REMOVE(intersecting_cell.atmos_contents, old_target)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(type), old_target)
Expand Down Expand Up @@ -479,6 +503,11 @@ SUBSYSTEM_DEF(spatial_grid)
GRID_CELL_REMOVE(intersecting_cell.hearing_contents, old_target_contents)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(exclusive_type), old_target_contents)

if(SPATIAL_GRID_CONTENTS_TYPE_TARGETS)
var/list/old_target_contents = old_target.important_recursive_contents?[exclusive_type] || old_target
GRID_CELL_REMOVE(intersecting_cell.target_contents, old_target_contents)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(exclusive_type), old_target_contents)

if(SPATIAL_GRID_CONTENTS_TYPE_ATMOS)
GRID_CELL_REMOVE(intersecting_cell.atmos_contents, old_target)
SEND_SIGNAL(intersecting_cell, SPATIAL_GRID_CELL_EXITED(exclusive_type), old_target)
Expand Down Expand Up @@ -521,6 +550,12 @@ SUBSYSTEM_DEF(spatial_grid)
if(movable_to_check in cell.hearing_contents)
contents = "hearing"

if(movable_to_check in cell.target_contents)
if(length(contents) > 0)
contents = "[contents], target"
else
contents = "target"

if(movable_to_check in cell.client_contents)
if(length(contents) > 0)
contents = "[contents], client"
Expand Down Expand Up @@ -566,7 +601,7 @@ SUBSYSTEM_DEF(spatial_grid)
remove_from_pre_init_queue(to_remove)//the spatial grid doesnt exist yet, so just take it out of the queue
return

#ifdef UNIT_TESTS
#ifdef UNIT_TEST
if(untracked_movable_error(to_remove))
find_hanging_cell_refs_for_movable(to_remove, remove_from_cells=FALSE) //dont remove from cells because we should be able to see 2 errors
return
Expand Down Expand Up @@ -604,7 +639,7 @@ SUBSYSTEM_DEF(spatial_grid)
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 | cell.atmos_contents))
if(to_remove in (cell.hearing_contents | cell.client_contents | cell.atmos_contents | cell.target_contents))
containing_cells += cell
if(remove_from_cells)
force_remove_from_cell(to_remove, cell)
Expand Down Expand Up @@ -677,14 +712,17 @@ SUBSYSTEM_DEF(spatial_grid)
var/raw_clients = 0
var/raw_hearables = 0
var/raw_atmos = 0
var/raw_targets = 0

var/cells_with_clients = 0
var/cells_with_hearables = 0
var/cells_with_atmos = 0
var/cells_with_targets = 0

var/list/client_list = list()
var/list/hearable_list = list()
var/list/atmos_list = list()
var/list/target_list = list()

var/x_cell_count = world.maxx / SPATIAL_GRID_CELLSIZE
var/y_cell_count = world.maxy / SPATIAL_GRID_CELLSIZE
Expand All @@ -694,6 +732,7 @@ SUBSYSTEM_DEF(spatial_grid)
var/average_clients_per_cell = 0
var/average_hearables_per_cell = 0
var/average_atmos_mech_per_call = 0
var/average_targets_per_cell

var/hearable_min_x = x_cell_count
var/hearable_max_x = 1
Expand All @@ -707,6 +746,12 @@ SUBSYSTEM_DEF(spatial_grid)
var/client_min_y = y_cell_count
var/client_max_y = 1

var/target_min_x = x_cell_count
var/target_max_x = 1

var/target_min_y = y_cell_count
var/target_max_y = 1

var/atmos_min_x = x_cell_count
var/atmos_max_x = 1

Expand All @@ -727,7 +772,7 @@ SUBSYSTEM_DEF(spatial_grid)
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

Expand All @@ -737,10 +782,12 @@ SUBSYSTEM_DEF(spatial_grid)
var/client_length = length(cell.client_contents)
var/hearable_length = length(cell.hearing_contents)
var/atmos_length = length(cell.atmos_contents)
var/target_length = length(cell.target_contents)

raw_clients += client_length
raw_hearables += hearable_length
raw_atmos += atmos_length
raw_targets += target_length

if(client_length)
cells_with_clients++
Expand Down Expand Up @@ -776,6 +823,23 @@ SUBSYSTEM_DEF(spatial_grid)
if(cell.cell_y > hearable_max_y)
hearable_max_y = cell.cell_y

if(target_length)
cells_with_targets++

target_list += cell.target_contents

if(cell.cell_x < hearable_min_x)
target_min_x = cell.cell_x

if(cell.cell_x > hearable_max_x)
target_max_x = cell.cell_x

if(cell.cell_y < hearable_min_y)
target_min_y = cell.cell_y

if(cell.cell_y > hearable_max_y)
target_max_y = cell.cell_y

if(raw_atmos)
cells_with_atmos++

Expand All @@ -796,10 +860,12 @@ SUBSYSTEM_DEF(spatial_grid)
var/total_client_distance = 0
var/total_hearable_distance = 0
var/total_atmos_distance = 0
var/total_target_distance = 0

var/average_client_distance = 0
var/average_hearable_distance = 0
var/average_atmos_distance = 0
var/average_target_distance = 0

for(var/hearable in hearable_list)//n^2 btw
for(var/other_hearable in hearable_list)
Expand All @@ -813,6 +879,12 @@ SUBSYSTEM_DEF(spatial_grid)
continue
total_client_distance += get_dist(client, other_client)

for(var/target in target_list)//n^2 btw
for(var/other_target in target_list)
if(target == other_target)
continue
total_target_distance += get_dist(target, other_target)

for(var/atmos in atmos_list)//n^2 btw
for(var/other_atmos in atmos_list)
if(atmos == other_atmos)
Expand All @@ -825,24 +897,28 @@ SUBSYSTEM_DEF(spatial_grid)
average_client_distance = total_client_distance / length(client_list)
if(length(atmos_list))
average_atmos_distance = total_atmos_distance / length(atmos_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_atmos_mech_per_call = raw_atmos / 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)\
, [raw_hearables] hearables, and [raw_atmos] atmos machines. all of whom are inside the bounding box given by \
, [raw_hearables] hearables, [raw_targets] targets, and [raw_atmos] atmos machines. 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]) \
targets: ([target_min_x], [target_min_y] x [target_max_x], [target_max_y]) \
and atmos machines: ([atmos_min_x], [atmos_min_y]) x ([atmos_max_x], [atmos_max_y]), \
on average there are [average_clients_per_cell] clients per cell, [average_hearables_per_cell] hearables per cell, \
and [average_atmos_mech_per_call] per cell, \
[cells_with_clients] cells have clients, [cells_with_hearables] have hearables, and [cells_with_atmos] have atmos machines \
[average_targets_per_cell] targets per cell, and [average_atmos_mech_per_call] atmos machines per cell, \
[cells_with_clients] cells have clients, [cells_with_hearables] have hearables, [cells_with_targets] have targets, and [cells_with_atmos] have atmos machines \
the average client distance is: [average_client_distance], the average hearable_distance is [average_hearable_distance], \
and the average atmos distance is [average_atmos_distance] ")
the average target distance is [average_target_distance], and the average atmos distance is [average_atmos_distance] ")

#undef BOUNDING_BOX_MAX
#undef BOUNDING_BOX_MIN
Expand Down
34 changes: 19 additions & 15 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@
LAZYINITLIST(recursive_contents[channel])
recursive_contents[channel] -= gone.important_recursive_contents[channel]
switch(channel)
if(RECURSIVE_CONTENTS_CLIENT_MOBS, RECURSIVE_CONTENTS_HEARING_SENSITIVE)
if(RECURSIVE_CONTENTS_CLIENT_MOBS, RECURSIVE_CONTENTS_HEARING_SENSITIVE,RECURSIVE_CONTENTS_AI_TARGETS)
if(!length(recursive_contents[channel]))
// This relies on a nice property of the linked recursive and gridmap types
// They're defined in relation to each other, so they have the same value
Expand All @@ -601,7 +601,7 @@
var/list/recursive_contents = location.important_recursive_contents // blue hedgehog velocity
LAZYINITLIST(recursive_contents[channel])
switch(channel)
if(RECURSIVE_CONTENTS_CLIENT_MOBS, RECURSIVE_CONTENTS_HEARING_SENSITIVE)
if(RECURSIVE_CONTENTS_CLIENT_MOBS, RECURSIVE_CONTENTS_HEARING_SENSITIVE,RECURSIVE_CONTENTS_AI_TARGETS)
if(!length(recursive_contents[channel]))
SSspatial_grid.add_grid_awareness(location, channel)
recursive_contents[channel] |= arrived.important_recursive_contents[channel]
Expand Down Expand Up @@ -701,25 +701,29 @@
// This proc adds atom/movables to the AI targetable list, i.e. things that the AI (turrets, hostile animals) will attempt to target
/atom/movable/proc/add_to_target_grid()
for (var/atom/movable/location as anything in get_nested_locs(src) + src)
LAZYADDASSOCLIST(location.important_recursive_contents, RECURSIVE_CONTENTS_AI_TARGETS, src)
LAZYINITLIST(location.important_recursive_contents)
var/list/recursive_contents = location.important_recursive_contents
if(!length(recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS]))
SSspatial_grid.add_grid_awareness(location, SPATIAL_GRID_CONTENTS_TYPE_TARGETS)
LAZYINITLIST(recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS])
recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS] |= src

var/turf/our_turf = get_turf(src)
if(our_turf && SSspatial_grid.initialized)
SSspatial_grid.add_grid_awareness(src, RECURSIVE_CONTENTS_AI_TARGETS)
SSspatial_grid.add_grid_membership(src, our_turf, RECURSIVE_CONTENTS_AI_TARGETS)

else if(our_turf && !SSspatial_grid.initialized)//SSspatial_grid isnt init'd yet, add ourselves to the queue
SSspatial_grid.enter_pre_init_queue(src, RECURSIVE_CONTENTS_AI_TARGETS)
SSspatial_grid.add_grid_membership(src, our_turf, SPATIAL_GRID_CONTENTS_TYPE_TARGETS)

/atom/movable/proc/clear_from_target_grid()
var/turf/our_turf = get_turf(src)
if(our_turf && SSspatial_grid.initialized)
SSspatial_grid.exit_cell(src, our_turf, RECURSIVE_CONTENTS_AI_TARGETS)
else if(our_turf && !SSspatial_grid.initialized)
SSspatial_grid.remove_from_pre_init_queue(src, RECURSIVE_CONTENTS_AI_TARGETS)
SSspatial_grid.remove_grid_membership(src, our_turf, SPATIAL_GRID_CONTENTS_TYPE_TARGETS)

for(var/atom/movable/location as anything in get_nested_locs(src) + src)
LAZYREMOVEASSOC(location.important_recursive_contents, RECURSIVE_CONTENTS_AI_TARGETS, src)
for(var/atom/movable/movable_loc as anything in get_nested_locs(src) + src)
LAZYINITLIST(movable_loc.important_recursive_contents)
var/list/recursive_contents = movable_loc.important_recursive_contents // blue hedgehog velocity
LAZYINITLIST(recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS])
recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS] -= src
if(!length(recursive_contents[RECURSIVE_CONTENTS_AI_TARGETS]))
SSspatial_grid.remove_grid_awareness(movable_loc, SPATIAL_GRID_CONTENTS_TYPE_TARGETS)
ASSOC_UNSETEMPTY(recursive_contents, RECURSIVE_CONTENTS_AI_TARGETS)
UNSETEMPTY(movable_loc.important_recursive_contents)

/atom/movable/proc/do_simple_ranged_interaction(var/mob/user)
return FALSE
Expand Down
Loading
Loading