Skip to content

Commit

Permalink
Implements Cardinal Smoothing Support, Misc Smoothing Cleanup (tgstat…
Browse files Browse the repository at this point in the history
…ion#84402)

## About The Pull Request

[Implements a new cardinal only bitmask smoothing
mode](tgstation@d565564)

The icon cutter supports generating cardinal only dmis, we should
support using them.

This is fairly trivial, just involves skipping a step to handle
diagonals.

While I'm here, makes adding new smoothing modes easier by creating a
"using smoothing" group define

[Removes undef for smoothing
junctions](tgstation@4c0a4d6)

It is useful to be able to reference these in the general codebase, they
should not be considered scoped to just icon smoothing

[Fixes a copypasta issue breaking burn states for asteroid
snow](tgstation@a41b31d)

[Removes SMOOTH_BROKEN_TURF and
SMOOTH_BURNT_TURF](tgstation@8a9a340)

Bitflags should not be this specific, this should be a var on
/turf/open, so that's what I'm making it.

## Why It's Good For The Game

Upstreams a bit of wallening work, cleans up the codebase some

## Changelog
:cl:
fix: Some varieties of snow now visually melt properly again when burned
/:cl:
  • Loading branch information
LemonInTheDark authored Jul 1, 2024
1 parent afa0b00 commit 7d1e9e1
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 51 deletions.
26 changes: 14 additions & 12 deletions code/__DEFINES/icon_smoothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@
#define SMOOTH_CORNERS (1<<0)
/// Smoothing system in where adjacencies are calculated and used to select a pre-baked icon_state, encoded by bitmasking.
#define SMOOTH_BITMASK (1<<1)
/// Limits SMOOTH_BITMASK to only cardinal directions, for use with cardinal smoothing
#define SMOOTH_BITMASK_CARDINALS (1<<2)
/// Atom has diagonal corners, with underlays under them.
#define SMOOTH_DIAGONAL_CORNERS (1<<2)
#define SMOOTH_DIAGONAL_CORNERS (1<<3)
/// Atom will smooth with the borders of the map.
#define SMOOTH_BORDER (1<<3)
#define SMOOTH_BORDER (1<<4)
/// Atom is currently queued to smooth.
#define SMOOTH_QUEUED (1<<4)
#define SMOOTH_QUEUED (1<<5)
/// Smooths with objects, and will thus need to scan turfs for contents.
#define SMOOTH_OBJ (1<<5)
#define SMOOTH_OBJ (1<<6)
/// Uses directional object smoothing, so we care not only about something being on the right turf, but also its direction
/// Changes the meaning of smoothing_junction, instead of representing the directions we are smoothing in
/// it represents the sides of our directional border object that have a neighbor
/// Is incompatible with SMOOTH_CORNERS because border objects don't have corners
#define SMOOTH_BORDER_OBJECT (1<<6)
/// Has a smooth broken sprite, used to decide whether to apply an offset to the broken overlay or not. For /turf/open only.
#define SMOOTH_BROKEN_TURF (1<<7)
/// Has a smooth burnt sprite, used to decide whether to apply an offset to the burnt overlay or not. For /turf/open only.
#define SMOOTH_BURNT_TURF (1<<8)
#define SMOOTH_BORDER_OBJECT (1<<7)

#define USES_SMOOTHING (SMOOTH_CORNERS|SMOOTH_BITMASK|SMOOTH_BITMASK_CARDINALS)

DEFINE_BITFIELD(smoothing_flags, list(
"SMOOTH_CORNERS" = SMOOTH_CORNERS,
"SMOOTH_BITMASK" = SMOOTH_BITMASK,
"SMOOTH_BITMASK_CARDINALS" = SMOOTH_BITMASK_CARDINALS,
"SMOOTH_DIAGONAL_CORNERS" = SMOOTH_DIAGONAL_CORNERS,
"SMOOTH_BORDER" = SMOOTH_BORDER,
"SMOOTH_QUEUED" = SMOOTH_QUEUED,
"SMOOTH_OBJ" = SMOOTH_OBJ,
"SMOOTH_BORDER_OBJECT" = SMOOTH_BORDER_OBJECT,
"SMOOTH_BROKEN_TURF" = SMOOTH_BROKEN_TURF,
"SMOOTH_BURNT_TURF" = SMOOTH_BURNT_TURF,
))

/// Components of a smoothing junction
Expand All @@ -44,6 +43,9 @@ DEFINE_BITFIELD(smoothing_flags, list(
#define SOUTHWEST_JUNCTION (1<<6)
#define NORTHWEST_JUNCTION (1<<7)

#define CARDINAL_SMOOTHING_JUNCTIONS (NORTH_JUNCTION|SOUTH_JUNCTION|EAST_JUNCTION|WEST_JUNCTION)
#define ALL_SMOOTHING_JUNCTIONS (NORTH_JUNCTION|SOUTH_JUNCTION|EAST_JUNCTION|WEST_JUNCTION|NORTHEAST_JUNCTION|SOUTHEAST_JUNCTION|SOUTHWEST_JUNCTION|NORTHWEST_JUNCTION)

DEFINE_BITFIELD(smoothing_junction, list(
"NORTH_JUNCTION" = NORTH_JUNCTION,
"SOUTH_JUNCTION" = SOUTH_JUNCTION,
Expand All @@ -57,7 +59,7 @@ DEFINE_BITFIELD(smoothing_junction, list(

/*smoothing macros*/

#define QUEUE_SMOOTH(thing_to_queue) if(thing_to_queue.smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK)) {SSicon_smooth.add_to_queue(thing_to_queue)}
#define QUEUE_SMOOTH(thing_to_queue) if(thing_to_queue.smoothing_flags & USES_SMOOTHING) {SSicon_smooth.add_to_queue(thing_to_queue)}

#define QUEUE_SMOOTH_NEIGHBORS(thing_to_queue) for(var/atom/atom_neighbor as anything in orange(1, thing_to_queue)) {QUEUE_SMOOTH(atom_neighbor)}

Expand Down
17 changes: 4 additions & 13 deletions code/__HELPERS/icon_smoothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ xxx xxx xxx
corners_diagonal_smooth(calculate_adjacencies())
else
corners_cardinal_smooth(calculate_adjacencies())
else if(smoothing_flags & SMOOTH_BITMASK)
else if(smoothing_flags & (SMOOTH_BITMASK|SMOOTH_BITMASK_CARDINALS))
bitmask_smooth()
else
CRASH("smooth_icon called for [src] with smoothing_flags == [smoothing_flags]")
Expand Down Expand Up @@ -430,7 +430,7 @@ xxx xxx xxx
SET_ADJ_IN_DIR(WEST, WEST)

// If there's nothing going on already
if(!(new_junction & (NORTH|SOUTH)) || !(new_junction & (EAST|WEST)))
if(smoothing_flags & SMOOTH_BITMASK_CARDINALS || !(new_junction & (NORTH|SOUTH)) || !(new_junction & (EAST|WEST)))
set_smoothed_icon_state(new_junction)
return

Expand Down Expand Up @@ -518,13 +518,13 @@ xxx xxx xxx
/proc/smooth_zlevel(zlevel, now = FALSE)
var/list/away_turfs = Z_TURFS(zlevel)
for(var/turf/turf_to_smooth as anything in away_turfs)
if(turf_to_smooth.smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(turf_to_smooth.smoothing_flags & USES_SMOOTHING)
if(now)
turf_to_smooth.smooth_icon()
else
QUEUE_SMOOTH(turf_to_smooth)
for(var/atom/movable/movable_to_smooth as anything in turf_to_smooth)
if(movable_to_smooth.smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(movable_to_smooth.smoothing_flags & USES_SMOOTHING)
if(now)
movable_to_smooth.smooth_icon()
else
Expand Down Expand Up @@ -655,15 +655,6 @@ xxx xxx xxx
smoothing_groups = null
canSmoothWith = null

#undef NORTH_JUNCTION
#undef SOUTH_JUNCTION
#undef EAST_JUNCTION
#undef WEST_JUNCTION
#undef NORTHEAST_JUNCTION
#undef NORTHWEST_JUNCTION
#undef SOUTHEAST_JUNCTION
#undef SOUTHWEST_JUNCTION

#undef NO_ADJ_FOUND
#undef ADJ_FOUND
#undef NULLTURF_BORDER
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/effects/decals/cleanable/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
if(T.tiled_dirt)
smoothing_flags = SMOOTH_BITMASK
QUEUE_SMOOTH(src)
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)

/obj/effect/decal/cleanable/dirt/Destroy()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)
return ..()

Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/structures.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/obj/structure/Initialize(mapload)
. = ..()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH(src)
QUEUE_SMOOTH_NEIGHBORS(src)
if(smoothing_flags & SMOOTH_CORNERS)
Expand All @@ -28,7 +28,7 @@

/obj/structure/Destroy(force)
GLOB.cameranet.updateVisibility(src)
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)
return ..()

Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/structures/grille.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
return

. = ..()
if((updates & UPDATE_SMOOTHING) && (smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK)))
if((updates & UPDATE_SMOOTHING) && (smoothing_flags & USES_SMOOTHING))
QUEUE_SMOOTH(src)

/obj/structure/grille/update_icon_state()
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/structures/mineral_doors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@

/obj/structure/mineral_door/paperframe/Initialize(mapload)
. = ..()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)

/obj/structure/mineral_door/paperframe/examine(mob/user)
Expand Down Expand Up @@ -333,6 +333,6 @@
return ..()

/obj/structure/mineral_door/paperframe/Destroy()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)
return ..()
2 changes: 1 addition & 1 deletion code/game/objects/structures/tables_racks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

/obj/structure/table/update_icon(updates=ALL)
. = ..()
if((updates & UPDATE_SMOOTHING) && (smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK)))
if((updates & UPDATE_SMOOTHING) && (smoothing_flags & USES_SMOOTHING))
QUEUE_SMOOTH(src)
QUEUE_SMOOTH_NEIGHBORS(src)

Expand Down
6 changes: 3 additions & 3 deletions code/game/objects/structures/window.dm
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@
//This proc is used to update the icons of nearby windows.
/obj/structure/window/proc/update_nearby_icons()
update_appearance()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)

//merges adjacent full-tile windows into one
Expand All @@ -402,7 +402,7 @@
if(QDELETED(src) || !fulltile)
return

if((updates & UPDATE_SMOOTHING) && (smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK)))
if((updates & UPDATE_SMOOTHING) && (smoothing_flags & USES_SMOOTHING))
QUEUE_SMOOTH(src)

var/ratio = atom_integrity / max_integrity
Expand Down Expand Up @@ -901,7 +901,7 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/structure/window/reinforced/tinted/frosted/spaw

/obj/structure/window/paperframe/update_icon(updates=ALL)
. = ..()
if((updates & UPDATE_SMOOTHING) && (smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK)))
if((updates & UPDATE_SMOOTHING) && (smoothing_flags & USES_SMOOTHING))
QUEUE_SMOOTH(src)

/obj/structure/window/paperframe/update_overlays()
Expand Down
8 changes: 6 additions & 2 deletions code/game/turfs/open/_open.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
/// Determines the type of damage overlay that will be used for the tile
var/damaged_dmi = null
var/broken = FALSE
/// Are broken overlays smoothed? if they are we have to change a little bit about how we render them
var/smooth_broken = FALSE
var/burnt = FALSE
/// Are burnt overlays smoothed? if they are we have to change a little bit about how we render them
var/smooth_burnt = FALSE


/// Returns a list of every turf state considered "broken".
Expand Down Expand Up @@ -47,7 +51,7 @@
if(broken)
var/mutable_appearance/broken_appearance = mutable_appearance(damaged_dmi, pick(broken_states()))

if(smoothing_flags && !(smoothing_flags & SMOOTH_BROKEN_TURF))
if(smoothing_flags && !smooth_broken)
var/matrix/translation = new
translation.Translate(-LARGE_TURF_SMOOTHING_X_OFFSET, -LARGE_TURF_SMOOTHING_Y_OFFSET)
broken_appearance.transform = translation
Expand All @@ -62,7 +66,7 @@
else
burnt_appearance = mutable_appearance(damaged_dmi, pick(broken_states()))

if(smoothing_flags && !(smoothing_flags & SMOOTH_BURNT_TURF))
if(smoothing_flags && !smooth_burnt)
var/matrix/translation = new
translation.Translate(-LARGE_TURF_SMOOTHING_X_OFFSET, -LARGE_TURF_SMOOTHING_Y_OFFSET)
burnt_appearance.transform = translation
Expand Down
2 changes: 1 addition & 1 deletion code/game/turfs/open/asteroid.dm
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ GLOBAL_LIST_EMPTY(dug_up_basalt)
return TRUE
return FALSE

/turf/open/misc/grass/burnt_states()
/turf/open/misc/asteroid/snow/burnt_states()
return list("snow_dug")

/turf/open/misc/asteroid/snow/icemoon
Expand Down
4 changes: 2 additions & 2 deletions code/game/turfs/open/floor/fancy_floor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@
if(!. || !(updates & UPDATE_SMOOTHING))
return
if(!broken && !burnt)
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH(src)
else
make_plating()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)

/turf/open/floor/carpet/lone
Expand Down
8 changes: 5 additions & 3 deletions code/game/turfs/open/grass.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
barefootstep = FOOTSTEP_GRASS
clawfootstep = FOOTSTEP_GRASS
heavyfootstep = FOOTSTEP_GENERIC_HEAVY
smoothing_flags = SMOOTH_BITMASK | SMOOTH_BROKEN_TURF | SMOOTH_BURNT_TURF
smoothing_flags = SMOOTH_BITMASK
smoothing_groups = SMOOTH_GROUP_TURF_OPEN + SMOOTH_GROUP_FLOOR_GRASS
canSmoothWith = SMOOTH_GROUP_FLOOR_GRASS + SMOOTH_GROUP_CLOSED_TURFS
smooth_broken = TRUE
smooth_burnt = TRUE
layer = HIGH_TURF_LAYER
rust_resistance = RUST_RESISTANCE_ORGANIC
damaged_dmi = 'icons/turf/floors/grass_damaged.dmi'
Expand All @@ -24,13 +26,13 @@
var/base_burnt_icon_state = "grass_damaged"

/turf/open/misc/grass/broken_states()
if (!smoothing_junction || !(smoothing_flags & SMOOTH_BROKEN_TURF))
if (!smoothing_junction || !smooth_broken)
return list("[base_broken_icon_state]-255")

return list("[base_broken_icon_state]-[smoothing_junction]")

/turf/open/misc/grass/burnt_states()
if (!smoothing_junction || !(smoothing_flags & SMOOTH_BURNT_TURF))
if (!smoothing_junction || !smooth_burnt)
return list("[base_burnt_icon_state]-255")

return list("[base_burnt_icon_state]-[smoothing_junction]")
Expand Down
2 changes: 1 addition & 1 deletion code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ GLOBAL_LIST_EMPTY(station_turfs)

SETUP_SMOOTHING()

if (smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if (smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH(src)

for(var/atom/movable/content as anything in src)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/holodeck/turfs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@

/turf/open/floor/holofloor/carpet/update_icon(updates=ALL)
. = ..()
if((updates & UPDATE_SMOOTHING) && overfloor_placed && smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if((updates & UPDATE_SMOOTHING) && overfloor_placed && smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH(src)

/turf/open/floor/holofloor/wood
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,12 @@ Difficulty: Hard

/obj/effect/temp_visual/hierophant/wall/Initialize(mapload, new_caster)
. = ..()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)
QUEUE_SMOOTH(src)

/obj/effect/temp_visual/hierophant/wall/Destroy()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)
return ..()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,12 @@ While using this makes the system rely on OnFire, it still gives options for tim

/obj/effect/temp_visual/elite_tumor_wall/Initialize(mapload, new_caster)
. = ..()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)
QUEUE_SMOOTH(src)

/obj/effect/temp_visual/elite_tumor_wall/Destroy()
if(smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH_NEIGHBORS(src)
return ..()

Expand Down
2 changes: 1 addition & 1 deletion code/modules/shuttle/shuttle_rotate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If ever any of these procs are useful for non-shuttles, rename it to proc/rotate
setDir(angle2dir(rotation+dir2angle(dir)))

//resmooth if need be.
if(params & ROTATE_SMOOTH && smoothing_flags & (SMOOTH_CORNERS|SMOOTH_BITMASK))
if(params & ROTATE_SMOOTH && smoothing_flags & USES_SMOOTHING)
QUEUE_SMOOTH(src)

//rotate the pixel offsets too.
Expand Down

0 comments on commit 7d1e9e1

Please sign in to comment.