Skip to content

Commit

Permalink
Converts most other usages of block() to x/y/z format (#89290)
Browse files Browse the repository at this point in the history
## About The Pull Request

The sequel to tgstation/tgstation#89234

> someone should do the rest at some point

guess what, I'm that someone :3

## Why It's Good For The Game

Same reasoning as the previous PR:

> less cluttered code is nice, and it should in theory be more optimized
as we avoid the need to run min, max, and locate.

## Changelog

No user-facing changes
  • Loading branch information
Absolucy authored and Iajret committed Feb 19, 2025
1 parent afe0403 commit f0b5266
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 90 deletions.
20 changes: 12 additions & 8 deletions code/controllers/subsystem/explosions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -651,23 +651,27 @@ ADMIN_VERB(check_bomb_impacts, R_DEBUG, "Check Bomb Impact", "See what the effec
// top left to one before top right
if(highest_y <= max_y)
candidates += block(
locate(max(lowest_x, 1), highest_y, our_z),
locate(min(highest_x - 1, max_x), highest_y, our_z))
lowest_x, highest_y, our_z,
highest_x - 1, highest_y, our_z
)
// top right to one before bottom right
if(highest_x <= max_x)
candidates += block(
locate(highest_x, min(highest_y, max_y), our_z),
locate(highest_x, max(lowest_y + 1, 1), our_z))
highest_x, highest_y, our_z,
highest_x, lowest_y + 1, our_z
)
// bottom right to one before bottom left
if(lowest_y >= 1)
candidates += block(
locate(min(highest_x, max_x), lowest_y, our_z),
locate(max(lowest_x + 1, 1), lowest_y, our_z))
highest_x, lowest_y, our_z,
lowest_x + 1, lowest_y, our_z
)
// bottom left to one before top left
if(lowest_x >= 1)
candidates += block(
locate(lowest_x, max(lowest_y, 1), our_z),
locate(lowest_x, min(highest_y - 1, max_y), our_z))
lowest_x, lowest_y, our_z,
lowest_x, highest_y - 1, our_z
)

if(!do_directional)
outlist += candidates
Expand Down
11 changes: 6 additions & 5 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,11 @@ ADMIN_VERB(load_away_mission, R_FUN, "Load Away Mission", "Load a specific away
if(!level_trait(z,ZTRAIT_RESERVED))
clearing_reserved_turfs = FALSE
CRASH("Invalid z level prepared for reservations.")
var/turf/A = get_turf(locate(SHUTTLE_TRANSIT_BORDER,SHUTTLE_TRANSIT_BORDER,z))
var/turf/B = get_turf(locate(world.maxx - SHUTTLE_TRANSIT_BORDER,world.maxy - SHUTTLE_TRANSIT_BORDER,z))
var/block = block(A, B)
for(var/turf/T as anything in block)
var/list/reserved_block = block(
SHUTTLE_TRANSIT_BORDER, SHUTTLE_TRANSIT_BORDER, z,
world.maxx - SHUTTLE_TRANSIT_BORDER, world.maxy - SHUTTLE_TRANSIT_BORDER, z
)
for(var/turf/T as anything in reserved_block)
// No need to empty() these, because they just got created and are already /turf/open/space/basic.
T.turf_flags = UNUSED_RESERVATION_TURF
T.blocks_air = TRUE
Expand All @@ -666,7 +667,7 @@ ADMIN_VERB(load_away_mission, R_FUN, "Load Away Mission", "Load a specific away
if(SSatoms.initialized)
SSatoms.InitializeAtoms(Z_TURFS(z))

unused_turfs["[z]"] = block
unused_turfs["[z]"] = reserved_block
reservation_ready["[z]"] = TRUE
clearing_reserved_turfs = FALSE

Expand Down
7 changes: 4 additions & 3 deletions code/datums/elements/mirage_border.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
var/x = target_turf.x
var/y = target_turf.y
var/z = clamp(target_turf.z, 1, world.maxz)
var/turf/southwest = locate(clamp(x - (direction & WEST ? range : 0), 1, world.maxx), clamp(y - (direction & SOUTH ? range : 0), 1, world.maxy), z)
var/turf/northeast = locate(clamp(x + (direction & EAST ? range : 0), 1, world.maxx), clamp(y + (direction & NORTH ? range : 0), 1, world.maxy), z)
holder.vis_contents += block(southwest, northeast)
holder.vis_contents += block(
x - (direction & WEST ? range : 0), y - (direction & SOUTH ? range : 0), z,
x + (direction & EAST ? range : 0), y + (direction & NORTH ? range : 0), z
)
if(direction & SOUTH)
holder.pixel_y -= ICON_SIZE_Y * range
if(direction & WEST)
Expand Down
4 changes: 2 additions & 2 deletions code/datums/shuttles/_shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
. = ..()
if(!.)
return
var/list/turfs = block( locate(.[MAP_MINX], .[MAP_MINY], .[MAP_MINZ]),
locate(.[MAP_MAXX], .[MAP_MAXY], .[MAP_MAXZ]))
var/list/turfs = block( .[MAP_MINX], .[MAP_MINY], .[MAP_MINZ],
.[MAP_MAXX], .[MAP_MAXY], .[MAP_MAXZ])
for(var/i in 1 to turfs.len)
var/turf/place = turfs[i]
if(isspaceturf(place)) // This assumes all shuttles are loaded in a single spot then moved to their real destination.
Expand Down
22 changes: 10 additions & 12 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,12 @@

var/list/new_locs
if(is_multi_tile_object && isturf(newloc))
var/dx = newloc.x
var/dy = newloc.y
var/dz = newloc.z
new_locs = block(
newloc,
locate(
min(world.maxx, newloc.x + CEILING(bound_width / 32, 1)),
min(world.maxy, newloc.y + CEILING(bound_height / 32, 1)),
newloc.z
)
dx, dy, dz,
dx + ceil(bound_width / 32), dy + ceil(bound_height / 32), dz
) // If this is a multi-tile object then we need to predict the new locs and check if they allow our entrance.
for(var/atom/entering_loc as anything in new_locs)
if(!entering_loc.Enter(src))
Expand Down Expand Up @@ -1164,13 +1163,12 @@
return FALSE

if(is_multi_tile && isturf(destination))
var/dx = destination.x
var/dy = destination.y
var/dz = destination.z
var/list/new_locs = block(
destination,
locate(
min(world.maxx, destination.x + ROUND_UP(bound_width / ICON_SIZE_X)),
min(world.maxy, destination.y + ROUND_UP(bound_height / ICON_SIZE_Y)),
destination.z
)
dx, dy, dz,
dx + ROUND_UP(bound_width / ICON_SIZE_X), dy + ROUND_UP(bound_height / ICON_SIZE_Y), dz
)
if(old_area && old_area != destarea)
old_area.Exited(src, movement_dir)
Expand Down
10 changes: 6 additions & 4 deletions code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ GLOBAL_PROTECT(tracy_init_reason)
LISTASSERTLEN(global_area.turfs_by_zlevel, map_load_z_cutoff, list())
for (var/zlevel in 1 to map_load_z_cutoff)
var/list/to_add = block(
locate(old_max + 1, 1, zlevel),
locate(maxx, maxy, zlevel))
old_max + 1, 1, zlevel,
maxx, maxy, zlevel
)

global_area.turfs_by_zlevel[zlevel] += to_add

Expand All @@ -474,8 +475,9 @@ GLOBAL_PROTECT(tracy_init_reason)
LISTASSERTLEN(global_area.turfs_by_zlevel, map_load_z_cutoff, list())
for (var/zlevel in 1 to map_load_z_cutoff)
var/list/to_add = block(
locate(1, old_maxy + 1, 1),
locate(maxx, maxy, map_load_z_cutoff))
1, old_maxy + 1, 1,
maxx, maxy, map_load_z_cutoff
)
global_area.turfs_by_zlevel[zlevel] += to_add

/world/proc/incrementMaxZ()
Expand Down
12 changes: 2 additions & 10 deletions code/modules/capture_the_flag/ctf_map_loading.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ GLOBAL_DATUM(ctf_spawner, /obj/effect/landmark/ctf)
/obj/effect/landmark/ctf/Destroy()
if(map_bounds)
for(var/turf/ctf_turf in block(
locate(
map_bounds[MAP_MINX],
map_bounds[MAP_MINY],
map_bounds[MAP_MINZ],
),
locate(
map_bounds[MAP_MAXX],
map_bounds[MAP_MAXY],
map_bounds[MAP_MAXZ],
)
map_bounds[MAP_MINX], map_bounds[MAP_MINY], map_bounds[MAP_MINZ],
map_bounds[MAP_MAXX], map_bounds[MAP_MAXY], map_bounds[MAP_MAXZ]
))
ctf_turf.empty()
GLOB.ctf_spawner = null
Expand Down
30 changes: 7 additions & 23 deletions code/modules/mapping/map_template.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,9 @@
var/list/area/areas = list()

var/list/turfs = block(
locate(
bounds[MAP_MINX],
bounds[MAP_MINY],
bounds[MAP_MINZ]
),
locate(
bounds[MAP_MAXX],
bounds[MAP_MAXY],
bounds[MAP_MAXZ]
)
)
bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ],
bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ]
)
for(var/turf/current_turf as anything in turfs)
var/area/current_turfs_area = current_turf.loc
areas |= current_turfs_area
Expand Down Expand Up @@ -114,17 +106,9 @@

//calculate all turfs inside the border
var/list/template_and_bordering_turfs = block(
locate(
max(bounds[MAP_MINX]-1, 1),
max(bounds[MAP_MINY]-1, 1),
bounds[MAP_MINZ]
),
locate(
min(bounds[MAP_MAXX]+1, world.maxx),
min(bounds[MAP_MAXY]+1, world.maxy),
bounds[MAP_MAXZ]
)
)
bounds[MAP_MINX]-1, bounds[MAP_MINY]-1, bounds[MAP_MINZ],
bounds[MAP_MAXX]+1, bounds[MAP_MAXY]+1, bounds[MAP_MAXZ]
)
for(var/turf/affected_turf as anything in template_and_bordering_turfs)
affected_turf.air_update_turf(TRUE, TRUE)
affected_turf.levelupdate()
Expand Down Expand Up @@ -231,7 +215,7 @@
var/turf/corner = locate(placement.x - round(width/2), placement.y - round(height/2), placement.z)
if(corner)
placement = corner
return block(placement, locate(placement.x+width-1, placement.y+height-1, placement.z))
return block(placement.x, placement.y, placement.z, placement.x+width-1, placement.y+height-1, placement.z)

/// Takes in a type path, locates an instance of that type in the cached map, and calculates its offset from the origin of the map, returns this offset in the form list(x, y).
/datum/map_template/proc/discover_offset(obj/marker)
Expand Down
5 changes: 3 additions & 2 deletions code/modules/mapping/reader.dm
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@

if(!no_changeturf)
var/list/turfs = block(
locate(bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ]),
locate(bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ]))
bounds[MAP_MINX], bounds[MAP_MINY], bounds[MAP_MINZ],
bounds[MAP_MAXX], bounds[MAP_MAXY], bounds[MAP_MAXZ]
)
for(var/turf/T as anything in turfs)
//we do this after we load everything in. if we don't, we'll have weird atmos bugs regarding atmos adjacent turfs
T.AfterChange(CHANGETURF_IGNORE_AIR)
Expand Down
7 changes: 4 additions & 3 deletions code/modules/mapping/space_management/space_transition.dm
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@
continue
var/zlevelnumber = level.z_value
for(var/side in 1 to 4)
var/turf/beginning = locate(x_pos_beginning[side], y_pos_beginning[side], zlevelnumber)
var/turf/ending = locate(x_pos_ending[side], y_pos_ending[side], zlevelnumber)
var/list/turfblock = block(beginning, ending)
var/list/turfblock = block(
x_pos_beginning[side], y_pos_beginning[side], zlevelnumber,
x_pos_ending[side], y_pos_ending[side], zlevelnumber
)
var/dirside = 2**(side-1)
var/x_target = x_pos_transition[side] == 1 ? 0 : x_pos_transition[side]
var/y_target = y_pos_transition[side] == 1 ? 0 : y_pos_transition[side]
Expand Down
5 changes: 3 additions & 2 deletions code/modules/procedural_mapping/mapGenerators/repair.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
require_area_resort()

var/list/generation_turfs = block(
locate(bounds[MAP_MINX], bounds[MAP_MINY], SSmapping.station_start),
locate(bounds[MAP_MAXX], bounds[MAP_MAXY], z_offset - 1))
bounds[MAP_MINX], bounds[MAP_MINY], SSmapping.station_start,
bounds[MAP_MAXX], bounds[MAP_MAXY], z_offset - 1
)
for(var/turf/gen_turf as anything in generation_turfs)
atoms += gen_turf
for(var/atom in gen_turf)
Expand Down
19 changes: 9 additions & 10 deletions code/modules/shuttle/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@

///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)
var/list/coords = return_coords()
return block(
coords[1], coords[2], z,
coords[3], coords[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
/obj/docking_port/proc/return_ordered_turfs(_x, _y, _z, _dir)
Expand Down Expand Up @@ -147,17 +148,15 @@
/obj/docking_port/proc/highlight(_color = "#f00")
SetInvisibility(INVISIBILITY_NONE)
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))
var/list/coords = return_coords()
for(var/turf/T in block(coords[1], coords[2], z, coords[3], coords[4], z))
T.color = _color
LAZYINITLIST(T.atom_colours)
T.maptext = null
if(_color)
var/turf/T = locate(L[1], L[2], z)
var/turf/T = locate(coords[1], coords[2], z)
T.color = "#0f0"
T = locate(L[3], L[4], z)
T = locate(coords[3], coords[4], z)
T.color = "#00f"

#endif
Expand Down
13 changes: 7 additions & 6 deletions code/modules/transport/transport_module.dm
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,16 @@
var/x_offset = ROUND_UP(bound_width / ICON_SIZE_X) - 1 //how many tiles our horizontally farthest edge is from us
var/y_offset = ROUND_UP(bound_height / ICON_SIZE_Y) - 1 //how many tiles our vertically farthest edge is from us

var/destination_x = destination.x
var/destination_y = destination.y
var/destination_z = destination.z
//the x coordinate of the edge furthest from our future destination, which would be our right hand side
var/back_edge_x = destination.x + x_offset//if we arent multitile this should just be destination.x
var/upper_edge_y = destination.y + y_offset

var/turf/upper_right_corner = locate(min(world.maxx, back_edge_x), min(world.maxy, upper_edge_y), destination.z)
var/back_edge_x = destination_x + x_offset//if we arent multitile this should just be destination.x
var/upper_edge_y = destination_y + y_offset

var/list/dest_locs = block(
destination,
upper_right_corner
destination_x, destination_y, destination_z,
back_edge_x, upper_edge_y, destination_z
)

var/list/entering_locs = dest_locs - locs
Expand Down

0 comments on commit f0b5266

Please sign in to comment.