From 66f18ffc7419b930e8fdbe1e7b6ba28884113c22 Mon Sep 17 00:00:00 2001 From: chuga-git <98280110+chuga-git@users.noreply.github.com> Date: Wed, 5 Jun 2024 22:18:48 -0500 Subject: [PATCH] Nukes reverse_direction() in favor of REVERSE_DIR define (#25550) * same taste, twice the speed * pain --- code/__DEFINES/directions.dm | 3 +++ code/__HELPERS/icon_smoothing.dm | 2 +- code/__HELPERS/unsorted.dm | 19 ------------------- code/game/machinery/doors/windowdoor.dm | 2 +- .../objects/items/weapons/tanks/jetpack.dm | 2 +- .../structures/transit_tubes/station.dm | 6 +++--- .../transit_tubes/transit_tube_pod.dm | 2 +- code/game/turfs/space/space_turf.dm | 2 +- .../vampire/vampire_powers/vampire_powers.dm | 2 +- .../modules/maze_generation/maze_generator.dm | 2 +- .../maze_generator_blockwise.dm | 2 +- code/modules/mod/mod_control.dm | 2 +- code/modules/power/generators/treadmill.dm | 2 +- code/modules/power/smes.dm | 2 +- .../surgery/organs/augments_internal.dm | 2 +- code/modules/unit_tests/map_tests.dm | 2 +- 16 files changed, 19 insertions(+), 35 deletions(-) diff --git a/code/__DEFINES/directions.dm b/code/__DEFINES/directions.dm index dfe3b2ecc78..7e4dd3c9769 100644 --- a/code/__DEFINES/directions.dm +++ b/code/__DEFINES/directions.dm @@ -28,3 +28,6 @@ #define IS_DIR_DIAGONAL(dir) (dir & (dir - 1)) /// returns TRUE if direction is cardinal and false if not #define IS_DIR_CARDINAL(dir) (!IS_DIR_DIAGONAL(dir)) + +/// Inverse direction, taking into account UP|DOWN if necessary. +#define REVERSE_DIR(dir) ( ((dir & 85) << 1) | ((dir & 170) >> 1) ) diff --git a/code/__HELPERS/icon_smoothing.dm b/code/__HELPERS/icon_smoothing.dm index affda69950a..df0fd8930d2 100644 --- a/code/__HELPERS/icon_smoothing.dm +++ b/code/__HELPERS/icon_smoothing.dm @@ -362,7 +362,7 @@ DEFINE_BITFIELD(smoothing_junction, list( icon_state = "[base_icon_state]-[smoothing_junction]-d" if(!fixed_underlay && new_junction != .) // Mutable underlays? var/junction_dir = reverse_ndir(smoothing_junction) - var/turned_adjacency = reverse_direction(junction_dir) + var/turned_adjacency = REVERSE_DIR(junction_dir) var/turf/neighbor_turf = get_step(src, turned_adjacency & (NORTH|SOUTH)) var/mutable_appearance/underlay_appearance = mutable_appearance(layer = TURF_LAYER, plane = FLOOR_PLANE) if(neighbor_turf && (!neighbor_turf.get_smooth_underlay_icon(underlay_appearance, src, turned_adjacency) || neighbor_turf.density)) //dense turfs are unwanted for underlays diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index ca7ef0c3adc..387463afa83 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1143,25 +1143,6 @@ GLOBAL_LIST_INIT(can_embed_types, typecacheof(list( if(is_type_in_typecache(W, GLOB.can_embed_types)) return TRUE -/proc/reverse_direction(dir) - switch(dir) - if(NORTH) - return SOUTH - if(NORTHEAST) - return SOUTHWEST - if(EAST) - return WEST - if(SOUTHEAST) - return NORTHWEST - if(SOUTH) - return NORTH - if(SOUTHWEST) - return NORTHEAST - if(WEST) - return EAST - if(NORTHWEST) - return SOUTHEAST - /* Checks if that loc and dir has a item on the wall */ diff --git a/code/game/machinery/doors/windowdoor.dm b/code/game/machinery/doors/windowdoor.dm index 812cd31da9f..411214d3a59 100644 --- a/code/game/machinery/doors/windowdoor.dm +++ b/code/game/machinery/doors/windowdoor.dm @@ -135,7 +135,7 @@ /obj/machinery/door/window/unrestricted_side(mob/M) var/mob_dir = get_dir(src, M) if(mob_dir == 0) // If the mob is inside the tile - mob_dir = reverse_direction(dir) // Set it to the inside direction of the windoor + mob_dir = REVERSE_DIR(dir) // Set it to the inside direction of the windoor return mob_dir & unres_sides diff --git a/code/game/objects/items/weapons/tanks/jetpack.dm b/code/game/objects/items/weapons/tanks/jetpack.dm index 865861edeb0..796ee726096 100644 --- a/code/game/objects/items/weapons/tanks/jetpack.dm +++ b/code/game/objects/items/weapons/tanks/jetpack.dm @@ -23,7 +23,7 @@ /obj/item/tank/jetpack/on_mob_move(direction, mob/user) if(on) - var/turf/T = get_step(src, reverse_direction(direction)) + var/turf/T = get_step(src, REVERSE_DIR(direction)) if(!has_gravity(T)) new /obj/effect/particle_effect/ion_trails(T, direction) diff --git a/code/game/objects/structures/transit_tubes/station.dm b/code/game/objects/structures/transit_tubes/station.dm index ddfc3b8fb64..aa3e6163f75 100644 --- a/code/game/objects/structures/transit_tubes/station.dm +++ b/code/game/objects/structures/transit_tubes/station.dm @@ -50,7 +50,7 @@ tube_dirs = list(NORTH, SOUTH) if(WEST) tube_dirs = list(NORTH, SOUTH) - boarding_dir = reverse_direction(dir) + boarding_dir = REVERSE_DIR(dir) /obj/structure/transit_tube/station/should_stop_pod(obj/structure/transit_tube_pod/pod, from_dir) for(var/atom/atom in pod.contents) @@ -209,7 +209,7 @@ /obj/structure/transit_tube/station/reverse/init_tube_dirs() tube_dirs = list(turn(dir, -90)) - boarding_dir = reverse_direction(dir) + boarding_dir = REVERSE_DIR(dir) /obj/structure/transit_tube/station/reverse/flipped icon_state = "closed_terminus1" @@ -285,7 +285,7 @@ /obj/structure/transit_tube/station/dispenser/reverse/init_tube_dirs() tube_dirs = list(turn(dir, -90)) - boarding_dir = reverse_direction(dir) + boarding_dir = REVERSE_DIR(dir) /obj/structure/transit_tube/station/dispenser/reverse/flipped icon_state = "open_terminusdispenser1" diff --git a/code/game/objects/structures/transit_tubes/transit_tube_pod.dm b/code/game/objects/structures/transit_tubes/transit_tube_pod.dm index 5238ee3c56c..4a1a1cebe74 100644 --- a/code/game/objects/structures/transit_tubes/transit_tube_pod.dm +++ b/code/game/objects/structures/transit_tubes/transit_tube_pod.dm @@ -91,7 +91,7 @@ var/move_result = move_animation(current_move_anim_mode) if(isnull(move_result)) - if(isnull(current_tube) || (!(dir in current_tube.directions()) && !(reverse_direction(dir) in current_tube.directions()))) + if(isnull(current_tube) || (!(dir in current_tube.directions()) && !(REVERSE_DIR(dir) in current_tube.directions()))) outside_tube() return PROCESS_KILL diff --git a/code/game/turfs/space/space_turf.dm b/code/game/turfs/space/space_turf.dm index 0fc08324a64..a57f48e9886 100644 --- a/code/game/turfs/space/space_turf.dm +++ b/code/game/turfs/space/space_turf.dm @@ -146,7 +146,7 @@ if(itercount > 100) stack_trace("SPACE Z-TRANSIT ERROR: [A] encountered a possible infinite loop while traveling through z-levels.") break - var/turf/target_turf = get_step(current_pull.pulledby.loc, reverse_direction(current_pull.pulledby.dir)) || current_pull.pulledby.loc + var/turf/target_turf = get_step(current_pull.pulledby.loc, REVERSE_DIR(current_pull.pulledby.dir)) || current_pull.pulledby.loc ADD_TRAIT(current_pull, TRAIT_CURRENTLY_Z_MOVING, ROUNDSTART_TRAIT) current_pull.forceMove(target_turf) REMOVE_TRAIT(current_pull, TRAIT_CURRENTLY_Z_MOVING, ROUNDSTART_TRAIT) diff --git a/code/modules/antagonists/vampire/vampire_powers/vampire_powers.dm b/code/modules/antagonists/vampire/vampire_powers/vampire_powers.dm index cf69f1e52a8..7bada89589d 100644 --- a/code/modules/antagonists/vampire/vampire_powers/vampire_powers.dm +++ b/code/modules/antagonists/vampire/vampire_powers/vampire_powers.dm @@ -248,7 +248,7 @@ // - V - Attacker facing south // - - - // Victim at 135 or more degrees of where the victim is facing. - if(attacker_dir & reverse_direction(attacker_to_victim)) + if(attacker_dir & REVERSE_DIR(attacker_to_victim)) return DEVIATION_FULL // - - - // # V # Attacker facing south diff --git a/code/modules/maze_generation/maze_generator.dm b/code/modules/maze_generation/maze_generator.dm index 447017b4aa4..7891393482f 100644 --- a/code/modules/maze_generation/maze_generator.dm +++ b/code/modules/maze_generation/maze_generator.dm @@ -120,7 +120,7 @@ // On both tiles for(var/obj/structure/window/reinforced/mazeglass/W in T3) - if(W.dir == reverse_direction(text2num(D))) + if(W.dir == REVERSE_DIR(text2num(D))) qdel(W) // Mark as visited diff --git a/code/modules/maze_generation/maze_generator_blockwise.dm b/code/modules/maze_generation/maze_generator_blockwise.dm index f6905bd1144..21d1388d8b0 100644 --- a/code/modules/maze_generation/maze_generator_blockwise.dm +++ b/code/modules/maze_generation/maze_generator_blockwise.dm @@ -68,7 +68,7 @@ var/turf/T3 = unvisited_neighbours["[D]"] // Pick random dir turf // Remove the color between the two - var/turf/T4 = get_step(T3, reverse_direction(text2num(D))) + var/turf/T4 = get_step(T3, REVERSE_DIR(text2num(D))) T4?.color = MAZEGEN_TURF_CELL // Mark as visited diff --git a/code/modules/mod/mod_control.dm b/code/modules/mod/mod_control.dm index 417af923893..22ed38ee01a 100644 --- a/code/modules/mod/mod_control.dm +++ b/code/modules/mod/mod_control.dm @@ -244,7 +244,7 @@ /obj/item/mod/control/on_mob_move(direction, mob/user) if(!jetpack_active || !isturf(user.loc)) return - var/turf/T = get_step(src, reverse_direction(direction)) + var/turf/T = get_step(src, REVERSE_DIR(direction)) if(!has_gravity(T)) new /obj/effect/particle_effect/ion_trails(T, direction) diff --git a/code/modules/power/generators/treadmill.dm b/code/modules/power/generators/treadmill.dm index f363c27f6ff..25fd175d013 100644 --- a/code/modules/power/generators/treadmill.dm +++ b/code/modules/power/generators/treadmill.dm @@ -41,7 +41,7 @@ // if 2fast, throw the person, otherwise they just slide off, if there's reasonable speed at all if(speed && A.move_resist < INFINITY) var/dist = max(throw_dist * speed / MAX_SPEED, 1) - A.throw_at(get_distant_turf(get_turf(src), reverse_direction(dir), dist), A.throw_range, A.throw_speed, src, 1) + A.throw_at(get_distant_turf(get_turf(src), REVERSE_DIR(dir), dist), A.throw_range, A.throw_speed, src, 1) /obj/machinery/power/treadmill/process() if(!anchored) diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index 63f179a18dc..844b98e2bee 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -159,7 +159,7 @@ tempDir = EAST if(NORTHWEST, SOUTHWEST) tempDir = WEST - var/turf/tempLoc = get_step(src, reverse_direction(tempDir)) + var/turf/tempLoc = get_step(src, REVERSE_DIR(tempDir)) if(isspaceturf(tempLoc)) to_chat(user, "You can't build a terminal on space.") return diff --git a/code/modules/surgery/organs/augments_internal.dm b/code/modules/surgery/organs/augments_internal.dm index 97ea59781f4..f1d635803b9 100644 --- a/code/modules/surgery/organs/augments_internal.dm +++ b/code/modules/surgery/organs/augments_internal.dm @@ -417,7 +417,7 @@ playsound(human_owner, 'sound/goonstation/items/hypo.ogg', 80, TRUE) var/obj/item/telegraph_vial = new /obj/item/qani_laaca_telegraph(get_turf(owner)) - var/turf/turf_we_throw_at = get_edge_target_turf(owner, reverse_direction(owner.dir)) + var/turf/turf_we_throw_at = get_edge_target_turf(owner, REVERSE_DIR(owner.dir)) telegraph_vial.throw_at(turf_we_throw_at, 5, 1) // Safety net in case the injection amount doesn't get reset. Apparently it happened to someone in a round. diff --git a/code/modules/unit_tests/map_tests.dm b/code/modules/unit_tests/map_tests.dm index fa8415727a7..f4e869ceef8 100644 --- a/code/modules/unit_tests/map_tests.dm +++ b/code/modules/unit_tests/map_tests.dm @@ -137,7 +137,7 @@ if(!direction) // cable direction = 0, which means its a node return TRUE var/turf/potential_cable_turf = get_step(origin_turf, direction) - var/reversed_direction = reverse_direction(direction) + var/reversed_direction = REVERSE_DIR(direction) for(var/obj/structure/cable/other_cable in potential_cable_turf.contents) if(reversed_direction == other_cable.d1 || reversed_direction == other_cable.d2) return TRUE