Skip to content

Commit

Permalink
refactor: remove from all block proc all locate procs (#5208)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeebBeebBoob authored Jun 19, 2024
1 parent d26c0bd commit 5c5a581
Show file tree
Hide file tree
Showing 20 changed files with 32 additions and 39 deletions.
12 changes: 6 additions & 6 deletions code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@

#define RECT_TURFS(H_RADIUS, V_RADIUS, CENTER) \
block( \
locate(max(CENTER.x-(H_RADIUS),1), max(CENTER.y-(V_RADIUS),1), CENTER.z), \
locate(min(CENTER.x+(H_RADIUS),world.maxx), min(CENTER.y+(V_RADIUS),world.maxy), CENTER.z) \
max(CENTER.x - (H_RADIUS), 1), max(CENTER.y - (V_RADIUS), 1), CENTER.z, \
min(CENTER.x + (H_RADIUS), world.maxx), min(CENTER.y + (V_RADIUS), world.maxy), CENTER.z \
)

/// Returns the turfs on the edge of a square with CENTER in the middle and with the given RADIUS. If used near the edge of the map, will still work fine.
// order of the additions: top edge + bottom edge + left edge + right edge
#define RANGE_EDGE_TURFS(RADIUS, CENTER)\
(CENTER.y + RADIUS < world.maxy ? block(locate(max(CENTER.x - RADIUS, 1), min(CENTER.y + RADIUS, world.maxy), CENTER.z), locate(min(CENTER.x + RADIUS, world.maxx), min(CENTER.y + RADIUS, world.maxy), CENTER.z)) : list()) +\
(CENTER.y - RADIUS > 1 ? block(locate(max(CENTER.x - RADIUS, 1), max(CENTER.y - RADIUS, 1), CENTER.z), locate(min(CENTER.x + RADIUS, world.maxx), max(CENTER.y - RADIUS, 1), CENTER.z)) : list()) +\
(CENTER.x - RADIUS > 1 ? block(locate(max(CENTER.x - RADIUS, 1), min(CENTER.y + RADIUS - 1, world.maxy), CENTER.z), locate(max(CENTER.x - RADIUS, 1), max(CENTER.y - RADIUS + 1, 1), CENTER.z)) : list()) +\
(CENTER.x + RADIUS < world.maxx ? block(locate(min(CENTER.x + RADIUS, world.maxx), min(CENTER.y + RADIUS - 1, world.maxy), CENTER.z), locate(min(CENTER.x + RADIUS, world.maxx), max(CENTER.y - RADIUS + 1, 1), CENTER.z)) : list())
(CENTER.y + RADIUS < world.maxy ? block(max(CENTER.x - RADIUS, 1), min(CENTER.y + RADIUS, world.maxy), CENTER.z, min(CENTER.x + RADIUS, world.maxx), min(CENTER.y + RADIUS, world.maxy), CENTER.z) : list()) +\
(CENTER.y - RADIUS > 1 ? block(max(CENTER.x - RADIUS, 1), max(CENTER.y - RADIUS, 1), CENTER.z, min(CENTER.x + RADIUS, world.maxx), max(CENTER.y - RADIUS, 1), CENTER.z) : list()) +\
(CENTER.x - RADIUS > 1 ? block(max(CENTER.x - RADIUS, 1), min(CENTER.y + RADIUS - 1, world.maxy), CENTER.z, max(CENTER.x - RADIUS, 1), max(CENTER.y - RADIUS + 1, 1), CENTER.z) : list()) +\
(CENTER.x + RADIUS < world.maxx ? block(min(CENTER.x + RADIUS, world.maxx), min(CENTER.y + RADIUS - 1, world.maxy), CENTER.z, min(CENTER.x + RADIUS, world.maxx), max(CENTER.y - RADIUS + 1, 1), CENTER.z) : list())


#define FOR_DVIEW(type, range, center, invis_flags) \
Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/icon_smoothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
//Icon smoothing helpers

/proc/smooth_zlevel(var/zlevel, now = FALSE)
var/list/away_turfs = block(locate(1, 1, zlevel), locate(world.maxx, world.maxy, zlevel))
var/list/away_turfs = block(1, 1, zlevel, world.maxx, world.maxy, zlevel)
for(var/V in away_turfs)
var/turf/T = V
if(T.smooth)
Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Turf and target are seperate in case you want to teleport some distance from a t
var/turf/center = locate((destination.x+xoffset),(destination.y+yoffset),location.z)//So now, find the new center.

//Now to find a box from center location and make that our destination.
for(var/turf/T in block(locate(center.x+b1xerror,center.y+b1yerror,location.z), locate(center.x+b2xerror,center.y+b2yerror,location.z) ))
for(var/turf/T in block(center.x+b1xerror,center.y+b1yerror,location.z, center.x+b2xerror,center.y+b2yerror,location.z) )
if(density&&T.density) continue//If density was specified.
if(T.x>world.maxx || T.x<1) continue//Don't want them to teleport off the map.
if(T.y>world.maxy || T.y<1) continue
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/air.dm
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ SUBSYSTEM_DEF(air)


/datum/controller/subsystem/air/proc/setup_allturfs()
var/list/turfs_to_init = block(locate(1, 1, 1), locate(world.maxx, world.maxy, world.maxz))
var/list/turfs_to_init = block(1, 1, 1, world.maxx, world.maxy, world.maxz)
// Clear active turfs - faster than removing every single turf in the world
// one-by-one, and Initialize_Atmos only ever adds `src` back in.
active_turfs.Cut()
Expand Down
3 changes: 1 addition & 2 deletions code/datums/helper_datums/map_template.dm
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@

var/max_x = min_x + width-1
var/max_y = min_y + height-1
placement = locate(max(min_x,1), max(min_y,1), placement.z)
return block(placement, locate(min(max_x, world.maxx), min(max_y, world.maxy), placement.z))
return block(max(min_x,1), max(min_y,1), placement.z, min(max_x, world.maxx), min(max_y, world.maxy), placement.z)

/datum/map_template/proc/fits_in_map_bounds(turf/T, centered = 0)
var/turf/placement = T
Expand Down
2 changes: 1 addition & 1 deletion code/datums/mapgen/LavalandGenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
//time for noise
var/node_gen = rustg_cnoise_generate("[initial_basalt_chance]", "[basalt_smoothing_interations]", "[basalt_birth_limit]", "[basalt_death_limit]", "[size_x + 1]", "[size_y + 1]")
var/node_gen2 = rustg_cnoise_generate("[initial_granite_chance]", "[granite_smoothing_interations]", "[granite_birth_limit]", "[granite_death_limit]", "[size_x + 1]", "[size_y + 1]")
var/list/changing_turfs = block(locate(picked_turf.x - round(size_x/2),picked_turf.y - round(size_y/2),picked_turf.z),locate(picked_turf.x + round(size_x/2),picked_turf.y + round(size_y/2),picked_turf.z))
var/list/changing_turfs = block(picked_turf.x - round(size_x/2),picked_turf.y - round(size_y/2),picked_turf.z, picked_turf.x + round(size_x/2),picked_turf.y + round(size_y/2),picked_turf.z)
for(var/turf/T in changing_turfs) //shitcode
if(!ismineralturf(T))
continue
Expand Down
8 changes: 3 additions & 5 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,9 @@
if(is_multi_tile && isturf(destination))
var/list/new_locs = block(
destination,
locate(
min(world.maxx, destination.x + ROUND_UP(bound_width / 32)),
min(world.maxy, destination.y + ROUND_UP(bound_height / 32)),
destination.z
)
min(world.maxx, destination.x + ROUND_UP(bound_width / 32)),
min(world.maxy, destination.y + ROUND_UP(bound_height / 32)),
destination.z
)
if(old_area && old_area != destarea)
old_area.Exited(src, movement_dir)
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/blob/blob_report.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


/datum/station_state/proc/count()
for(var/turf/T in block(locate(1,1,1), locate(world.maxx,world.maxy,1)))
for(var/turf/T in block(1,1,1, world.maxx,world.maxy,1))

if(isfloorturf(T))
if(!(T:burnt))
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/blob/powers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
/mob/camera/blob/proc/rally_spores(var/turf/T)
to_chat(src, "You rally your spores.")

var/list/surrounding_turfs = block(locate(T.x - 1, T.y - 1, T.z), locate(T.x + 1, T.y + 1, T.z))
var/list/surrounding_turfs = block(T.x - 1, T.y - 1, T.z, T.x + 1, T.y + 1, T.z)
if(!surrounding_turfs.len)
return

Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/steal_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ GLOBAL_LIST_INIT(ungibbable_items_types, get_ungibbable_items_types())
. = list()

var/list/stations_z = levels_by_trait(STATION_LEVEL)
var/list/station_turfs = block(locate(1, 1, stations_z[1]), locate(world.maxx, world.maxy, stations_z[length(stations_z)]))
var/list/station_turfs = block(1, 1, stations_z[1], world.maxx, world.maxy, stations_z[length(stations_z)])

for(var/turf/turf_check in station_turfs)
if(ispath(typepath, /mob/living))
Expand Down
2 changes: 1 addition & 1 deletion code/game/turfs/simulated/river.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/datum/river_spawner/proc/generate(nodes = 4, min_x = RIVER_MIN_X, min_y = RIVER_MIN_Y, max_x = RIVER_MAX_X, max_y = RIVER_MAX_Y)
var/list/river_nodes = list()
var/num_spawned = 0
var/list/possible_locs = block(locate(min_x, min_y, target_z), locate(max_x, max_y, target_z))
var/list/possible_locs = block(min_x, min_y, target_z, max_x, max_y, target_z)
while(num_spawned < nodes && possible_locs.len)
var/turf/T = pick(possible_locs)
var/area/A = get_area(T)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/awaymissions/maploader/reader.dm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ GLOBAL_DATUM_INIT(_preloader, /datum/dmm_suite/preloader, new())
CRASH("Bad Map bounds in [fname], Min x: [bounds[MAP_MINX]], Min y: [bounds[MAP_MINY]], Min z: [bounds[MAP_MINZ]], Max x: [bounds[MAP_MAXX]], Max y: [bounds[MAP_MAXY]], Max z: [bounds[MAP_MAXZ]]")
else
if(!measureOnly)
for(var/t in block(locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]), locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ])))
for(var/t in block(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ], bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ]))
var/turf/T = t
// we do this after we load everything in. if we don't; we'll have weird atmos bugs regarding atmos adjacent turfs
T.AfterChange(TRUE, keep_cabling = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/awaymissions/zlevel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GLOBAL_LIST_INIT(potentialRandomZlevels, generateMapList(filename = "config/away
/proc/empty_rect(low_x,low_y, hi_x,hi_y, z)
var/timer = start_watch()
log_debug("Emptying region: ([low_x], [low_y]) to ([hi_x], [hi_y]) on z '[z]'")
empty_region(block(locate(low_x, low_y, z), locate(hi_x, hi_y, z)))
empty_region(block(low_x, low_y, z, hi_x, hi_y, z))
log_debug("Took [stop_watch(timer)]s")


Expand Down
2 changes: 1 addition & 1 deletion code/modules/events/wormholes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if(!length(stations_z))
return

var/list/station_turfs = block(locate(1, 1, stations_z[1]), locate(world.maxx, world.maxy, stations_z[length(stations_z)]))
var/list/station_turfs = block(1, 1, stations_z[1], world.maxx, world.maxy, stations_z[length(stations_z)])
for(var/turf/simulated/floor/new_turf in station_turfs)
pick_turfs |= new_turf

Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/silicon/ai/freelook/chunk.dm
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
cameras["[z_level]"] = local_cameras

var/image/mirror_from = GLOB.cameranet.obscured_images[GET_Z_PLANE_OFFSET(z_level) + 1]
for(var/turf/lad as anything in block(locate(max(x, 1), max(y, 1), z_level), locate(min(x + CHUNK_SIZE - 1, world.maxx), min(y + CHUNK_SIZE - 1, world.maxy), z_level)))
for(var/turf/lad as anything in block(max(x, 1), max(y, 1), z_level, min(x + CHUNK_SIZE - 1, world.maxx), min(y + CHUNK_SIZE - 1, world.maxy), z_level))
var/image/our_image = new /image(mirror_from)
our_image.loc = lad
turfs[lad] = our_image
Expand Down
2 changes: 1 addition & 1 deletion code/modules/power/gravitygenerator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ GLOBAL_LIST_EMPTY(gravity_generators) // We will keep track of this by adding ne
/obj/machinery/gravity_generator/main/proc/setup_parts()
var/turf/our_turf = get_turf(src)
// 9x9 block obtained from the bottom middle of the block
var/list/spawn_turfs = block(locate(our_turf.x - 1, our_turf.y + 2, our_turf.z), locate(our_turf.x + 1, our_turf.y, our_turf.z))
var/list/spawn_turfs = block(our_turf.x - 1, our_turf.y + 2, our_turf.z, our_turf.x + 1, our_turf.y, our_turf.z)
var/count = 10
for(var/turf/part_turf as anything in spawn_turfs)
count--
Expand Down
8 changes: 2 additions & 6 deletions code/modules/shuttle/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@
//returns turfs within our projected rectangle in no particular order
/obj/docking_port/proc/return_turfs()
var/list/L = return_coords()
var/turf/T0 = locate(L[1], L[2], z)
var/turf/T1 = locate(L[3], L[4], z)
return block(T0, T1)
return block(L[1], L[2], z, L[3], L[4], z)

//returns turfs within our projected rectangle in a specific order.
//this ensures that turfs are copied over in the same order, regardless of any rotation
Expand Down Expand Up @@ -133,9 +131,7 @@
/obj/docking_port/proc/highlight(_color)
SET_PLANE_IMPLICIT(src, GHOST_PLANE)
var/list/L = return_coords()
var/turf/T0 = locate(L[1],L[2],z)
var/turf/T1 = locate(L[3],L[4],z)
for(var/turf/T in block(T0,T1))
for(var/turf/T in block(L[1], L[2], z, L[3], L[4], z))
T.color = _color
T.maptext = null
if(_color)
Expand Down
10 changes: 5 additions & 5 deletions code/modules/space_management/space_level.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@
/datum/space_level/proc/build_space_destination_arrays()
// We skip `add_to_transit` here because we want to skip the checks in order to save time
// Bottom border
for(var/turf/space/S in block(locate(1,1,zpos),locate(world.maxx,TRANSITION_BORDER_SOUTH,zpos)))
for(var/turf/space/S in block(1,1,zpos, world.maxx,TRANSITION_BORDER_SOUTH,zpos))
transit_south |= S

// Top border
for(var/turf/space/S in block(locate(1,world.maxy,zpos),locate(world.maxx,TRANSITION_BORDER_NORTH,zpos)))
for(var/turf/space/S in block(1,world.maxy,zpos, world.maxx,TRANSITION_BORDER_NORTH,zpos))
transit_north |= S

// Left border
for(var/turf/space/S in block(locate(1,TRANSITION_BORDER_SOUTH + 1,zpos),locate(TRANSITION_BORDER_WEST,TRANSITION_BORDER_NORTH - 1,zpos)))
for(var/turf/space/S in block(1,TRANSITION_BORDER_SOUTH + 1,zpos, TRANSITION_BORDER_WEST,TRANSITION_BORDER_NORTH - 1,zpos))
transit_west |= S

// Right border
for(var/turf/space/S in block(locate(TRANSITION_BORDER_EAST,TRANSITION_BORDER_SOUTH + 1,zpos),locate(world.maxx,TRANSITION_BORDER_NORTH - 1,zpos)))
for(var/turf/space/S in block(TRANSITION_BORDER_EAST,TRANSITION_BORDER_SOUTH + 1,zpos, world.maxx,TRANSITION_BORDER_NORTH - 1,zpos))
transit_east |= S

/datum/space_level/proc/add_to_transit(turf/space/S)
Expand Down Expand Up @@ -118,7 +118,7 @@


/datum/space_level/proc/get_turfs()
return block(locate(1, 1, zpos), locate(world.maxx, world.maxy, zpos))
return block(1, 1, zpos, world.maxx, world.maxy, zpos)

/datum/space_level/proc/set_linkage(transition_type)
if(linkage == transition_type)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/station_goals/bsa.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
x_min = x + BSA_SIZE_BACK
x_max = x - BSA_SIZE_FRONT

for(var/turf/T in block(locate(x_min,y-1,z),locate(x_max,y+1,z)))
for(var/turf/T in block(x_min,y-1,z, x_max,y+1,z))
if(T.density || isspaceturf(T))
return FALSE
return TRUE
Expand Down
2 changes: 1 addition & 1 deletion code/modules/unit_tests/test_runner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
test_logs[I] = list()
durations[I] = 0

for(var/turf/T in block(locate(1, 1, z_level), locate(world.maxx, world.maxy, z_level)))
for(var/turf/T in block(1, 1, z_level, world.maxx, world.maxy, z_level))
for(var/datum/map_per_tile_test/test in tests)
if(test.failure_count < MAX_MAP_TEST_FAILURE_COUNT)
var/duration = REALTIMEOFDAY
Expand Down

0 comments on commit 5c5a581

Please sign in to comment.