From c615675dabb7bef0787f37eba683f39bc0c55eac Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 2 Oct 2023 08:30:04 +0200 Subject: [PATCH] [MIRROR] Pulls over some changes I made on wallening [MDB IGNORE] (#24062) * Pulls over some changes I made on wallening (#78690) ## About The Pull Request Uses junctions for smoothing, rather then base dirs Also adds a macro/vars for setting base_pixel_z/w, suprise tool which will help us later * Pulls over some changes I made on wallening --------- Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> --- code/__DEFINES/icon_smoothing.dm | 21 ++++++ code/__DEFINES/visual_helpers.dm | 10 +++ code/__HELPERS/icon_smoothing.dm | 75 +++++++++++-------- code/game/atoms.dm | 5 ++ .../industrial_lift/tram/tram_windows.dm | 5 +- 5 files changed, 82 insertions(+), 34 deletions(-) diff --git a/code/__DEFINES/icon_smoothing.dm b/code/__DEFINES/icon_smoothing.dm index bc3c2011ae2..830daef563d 100644 --- a/code/__DEFINES/icon_smoothing.dm +++ b/code/__DEFINES/icon_smoothing.dm @@ -27,6 +27,27 @@ DEFINE_BITFIELD(smoothing_flags, list( "SMOOTH_BORDER_OBJECT" = SMOOTH_BORDER_OBJECT, )) +/// Components of a smoothing junction +/// Redefinitions of the diagonal directions so they can be stored in one var without conflicts +#define NORTH_JUNCTION NORTH //(1<<0) +#define SOUTH_JUNCTION SOUTH //(1<<1) +#define EAST_JUNCTION EAST //(1<<2) +#define WEST_JUNCTION WEST //(1<<3) +#define NORTHEAST_JUNCTION (1<<4) +#define SOUTHEAST_JUNCTION (1<<5) +#define SOUTHWEST_JUNCTION (1<<6) +#define NORTHWEST_JUNCTION (1<<7) + +DEFINE_BITFIELD(smoothing_junction, list( + "NORTH_JUNCTION" = NORTH_JUNCTION, + "SOUTH_JUNCTION" = SOUTH_JUNCTION, + "EAST_JUNCTION" = EAST_JUNCTION, + "WEST_JUNCTION" = WEST_JUNCTION, + "NORTHEAST_JUNCTION" = NORTHEAST_JUNCTION, + "SOUTHEAST_JUNCTION" = SOUTHEAST_JUNCTION, + "SOUTHWEST_JUNCTION" = SOUTHWEST_JUNCTION, + "NORTHWEST_JUNCTION" = NORTHWEST_JUNCTION, +)) /*smoothing macros*/ diff --git a/code/__DEFINES/visual_helpers.dm b/code/__DEFINES/visual_helpers.dm index 204cc8ba03a..bb54c5d6b0b 100644 --- a/code/__DEFINES/visual_helpers.dm +++ b/code/__DEFINES/visual_helpers.dm @@ -11,5 +11,15 @@ base_pixel_x = x; \ base_pixel_y = y; +#define SET_BASE_VISUAL_PIXEL(w, z) \ + pixel_w = w; \ + base_pixel_w = w; \ + pixel_z = z; \ + base_pixel_z = z; + +#define _SET_BASE_PIXEL_VISUAL_NO_OFFSET(w, z) \ + base_pixel_z = w; \ + base_pixel_z = z; + /// Much like [SET_BASE_PIXEL], except it will not effect pixel offsets in mapping programs #define SET_BASE_PIXEL_NOMAP(x, y) MAP_SWITCH(SET_BASE_PIXEL(x, y), _SET_BASE_PIXEL_NO_OFFSET(x, y)) diff --git a/code/__HELPERS/icon_smoothing.dm b/code/__HELPERS/icon_smoothing.dm index 5f92c67a6fc..6a1cfd6191a 100644 --- a/code/__HELPERS/icon_smoothing.dm +++ b/code/__HELPERS/icon_smoothing.dm @@ -24,27 +24,6 @@ To see an example of a diagonal wall, see '/turf/closed/wall/mineral/titanium' and its subtypes. */ -//Redefinitions of the diagonal directions so they can be stored in one var without conflicts -#define NORTH_JUNCTION NORTH //(1<<0) -#define SOUTH_JUNCTION SOUTH //(1<<1) -#define EAST_JUNCTION EAST //(1<<2) -#define WEST_JUNCTION WEST //(1<<3) -#define NORTHEAST_JUNCTION (1<<4) -#define SOUTHEAST_JUNCTION (1<<5) -#define SOUTHWEST_JUNCTION (1<<6) -#define NORTHWEST_JUNCTION (1<<7) - -DEFINE_BITFIELD(smoothing_junction, list( - "NORTH_JUNCTION" = NORTH_JUNCTION, - "SOUTH_JUNCTION" = SOUTH_JUNCTION, - "EAST_JUNCTION" = EAST_JUNCTION, - "WEST_JUNCTION" = WEST_JUNCTION, - "NORTHEAST_JUNCTION" = NORTHEAST_JUNCTION, - "SOUTHEAST_JUNCTION" = SOUTHEAST_JUNCTION, - "SOUTHWEST_JUNCTION" = SOUTHWEST_JUNCTION, - "NORTHWEST_JUNCTION" = NORTHWEST_JUNCTION, -)) - #define NO_ADJ_FOUND 0 #define ADJ_FOUND 1 #define NULLTURF_BORDER 2 @@ -55,13 +34,13 @@ GLOBAL_LIST_INIT(adjacent_direction_lookup, generate_adjacent_directions()) * Each 3x3 grid is a tile, with each X representing a direction a border object could be in IN said grid * Directions marked with A are acceptable smoothing targets, M is the example direction * The example given here is of a northfacing border object -xxx xxx xxx xxx AxA xxx -xxx xAx xxx +xxx AxA xxx +xxx AxA xxx -xAx xMx xAx +AAA MMM AAA +xxx AxA xxx xxx AxA xxx -xxx xxx xxx xxx xxx xxx xxx xxx xxx @@ -96,21 +75,20 @@ xxx xxx xxx // We'll do the two dirs to our left and right // They connect.. "below" us and on their side if(connectable_dir == NONE) - smoothable_dirs[left] = opposite | left - smoothable_dirs[right] = opposite | right + smoothable_dirs[left] = dir_to_junction(opposite | left) + smoothable_dirs[right] = dir_to_junction(opposite | right) // If it's to our right or left we'll include just the dir matching ours // Left edge touches only our left side, and so on else if (connectable_dir == left) smoothable_dirs[dir] = left else if (connectable_dir == right) smoothable_dirs[dir] = right - // If it's straight on we'll include all cardinals but us, since all 3 bits would touch us - // Turf opposite gets just our dir as the connection, the other two get our dir + theirs - // Since they touch the edges + // If it's straight on we'll include our direction as a link + // Then include the two edges on the other side as diagonals else if(connectable_dir == dir) smoothable_dirs[opposite] = dir - smoothable_dirs[left] = dir | left - smoothable_dirs[right] = dir | right + smoothable_dirs[left] = dir_to_junction(dir | left) + smoothable_dirs[right] = dir_to_junction(dir | right) // otherwise, go HOME, I don't want to encode anything for you else continue @@ -594,6 +572,39 @@ xxx xxx xxx add_overlay(new_overlays) +/// Takes a direction, turns it into all the junctions that contain it +/proc/dir_to_all_junctions(dir) + var/handback = NONE + if(dir & NORTH) + handback |= NORTH_JUNCTION | NORTHEAST_JUNCTION | NORTHWEST_JUNCTION + if(dir & SOUTH) + handback |= SOUTH_JUNCTION | SOUTHEAST_JUNCTION | SOUTHWEST_JUNCTION + if(dir & EAST) + handback |= EAST_JUNCTION | SOUTHEAST_JUNCTION | NORTHEAST_JUNCTION + if(dir & WEST) + handback |= WEST_JUNCTION | NORTHWEST_JUNCTION | SOUTHWEST_JUNCTION + return handback + +/proc/dir_to_junction(dir) + switch(dir) + if(NORTH) + return NORTH_JUNCTION + if(SOUTH) + return SOUTH_JUNCTION + if(WEST) + return WEST_JUNCTION + if(EAST) + return EAST_JUNCTION + if(NORTHWEST) + return NORTHWEST_JUNCTION + if(NORTHEAST) + return NORTHEAST_JUNCTION + if(SOUTHEAST) + return SOUTHEAST_JUNCTION + if(SOUTHWEST) + return SOUTHWEST_JUNCTION + else + return NONE /proc/reverse_ndir(ndir) switch(ndir) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index ed2ecb0cfca..c2c67edf097 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -129,6 +129,11 @@ var/base_pixel_x = 0 ///Default pixel y shifting for the atom's icon. var/base_pixel_y = 0 + // Use SET_BASE_VISUAL_PIXEL(x, y) to set these in typepath definitions, it'll handle pixel_w and z for you + ///Default pixel w shifting for the atom's icon. + var/base_pixel_w = 0 + ///Default pixel z shifting for the atom's icon. + var/base_pixel_z = 0 ///Used for changing icon states for different base sprites. var/base_icon_state diff --git a/code/modules/industrial_lift/tram/tram_windows.dm b/code/modules/industrial_lift/tram/tram_windows.dm index 1a98a56a0ba..55ec5aa283f 100644 --- a/code/modules/industrial_lift/tram/tram_windows.dm +++ b/code/modules/industrial_lift/tram/tram_windows.dm @@ -36,8 +36,9 @@ if(fulltile) return ..() smoothing_junction = new_junction - var/smooth_left = (smoothing_junction & turn(dir, 90)) - var/smooth_right = (smoothing_junction & turn(dir, -90)) + var/go_off = reverse_ndir(smoothing_junction) + var/smooth_left = (go_off & turn(dir, 90)) + var/smooth_right = (go_off & turn(dir, -90)) if(smooth_left && smooth_right) icon_state = "tram_mid" else if (smooth_left)