Fix Turf Transparency for MultiZ (#62875)

Fixes #62794 (Catwalk Tiles placed on the lower level of tram appear to be on the upper level)
Fixes #57654 (Open Space shading not always applied)
Fixes #53666 (When standing on a glass floor above a light on the Z level below you the light effect is rendered above the character. This makes light have ugly glows on the floors above. This also happens with grills and lattice.)

Transparent turfs, catwalks, and lighting overlays were badly broken with MultiZ issues. This fixes any transparent turf to appear and be on the same z-level if it has the turf_transparent element. Catwalks will appear and be on the same z-level as well. They were initially glitching to top z-levels causing people to walk over an illusion that caused them to fall to their deaths.

After I fixed these issues I noticed that lighting overlays were also glitching to top z-levels, which looked rather strange as there were lights in the middle of rooms and hallways with no supporting walls. Lights now appear under the transparent turfs properly.

The mapping icons for catwalks displayed the wrong icon_state so I fixed that too.

I made a big refactor for transparency and catwalks code that had to be done to get all of this to work properly.

You no longer have to be afraid of falling off of glass floors, catwalks, or transparent tiles. Also lighting overlays don't glitch through upper z-levels anymore for transparent tiles.
This commit is contained in:
Tim
2021-12-29 21:42:49 -08:00
committed by GitHub
parent 0265f334ad
commit 566b9ee1d8
6 changed files with 52 additions and 59 deletions
+15 -18
View File
@@ -1,27 +1,29 @@
/datum/element/turf_z_transparency
element_flags = ELEMENT_DETACH
var/show_bottom_level = FALSE
var/is_openspace = FALSE
///This proc sets up the signals to handle updating viscontents when turfs above/below update. Handle plane and layer here too so that they don't cover other obs/turfs in Dream Maker
/datum/element/turf_z_transparency/Attach(datum/target, show_bottom_level = TRUE)
/datum/element/turf_z_transparency/Attach(datum/target, is_openspace = FALSE)
. = ..()
if(!isturf(target))
return ELEMENT_INCOMPATIBLE
var/turf/our_turf = target
src.show_bottom_level = show_bottom_level
our_turf.plane = OPENSPACE_PLANE
our_turf.layer = OPENSPACE_LAYER
if(is_openspace)
our_turf.plane = OPENSPACE_PLANE
RegisterSignal(target, COMSIG_TURF_MULTIZ_DEL, .proc/on_multiz_turf_del)
RegisterSignal(target, COMSIG_TURF_MULTIZ_NEW, .proc/on_multiz_turf_new)
ADD_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, ELEMENT_TRAIT(type))
update_multiz(our_turf, TRUE, TRUE)
var/turf/below_turf = our_turf.below()
if(below_turf)
our_turf.vis_contents += below_turf
update_multi_z(our_turf)
/datum/element/turf_z_transparency/Detach(datum/source)
. = ..()
@@ -31,15 +33,11 @@
REMOVE_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, ELEMENT_TRAIT(type))
///Updates the viscontents or underlays below this tile.
/datum/element/turf_z_transparency/proc/update_multiz(turf/our_turf, prune_on_fail = FALSE, init = FALSE)
/datum/element/turf_z_transparency/proc/update_multi_z(turf/our_turf)
var/turf/below_turf = our_turf.below()
if(!below_turf)
our_turf.vis_contents.len = 0
if(!show_bottom_level(our_turf) && prune_on_fail) //If we cant show whats below, and we prune on fail, change the turf to plating as a fallback
our_turf.ChangeTurf(/turf/open/floor/plating, flags = CHANGETURF_INHERIT_AIR)
return FALSE
if(init)
our_turf.vis_contents += below_turf
add_baseturf_underlay(our_turf)
if(isclosedturf(our_turf)) //Show girders below closed turfs
var/mutable_appearance/girder_underlay = mutable_appearance('icons/obj/structures.dmi', "girder", layer = TURF_LAYER-0.01)
@@ -56,7 +54,7 @@
if(dir != DOWN)
return
update_multiz(our_turf)
update_multi_z(our_turf)
/datum/element/turf_z_transparency/proc/on_multiz_turf_new(turf/our_turf, turf/below_turf, dir)
SIGNAL_HANDLER
@@ -64,12 +62,12 @@
if(dir != DOWN)
return
update_multiz(our_turf)
update_multi_z(our_turf)
///Called when there is no real turf below this turf
/datum/element/turf_z_transparency/proc/show_bottom_level(turf/our_turf)
if(!show_bottom_level)
return FALSE
/datum/element/turf_z_transparency/proc/add_baseturf_underlay(turf/our_turf)
if(is_openspace) // we don't ever want our bottom turf to be openspace
our_turf.ChangeTurf(/turf/open/floor/plating, flags = CHANGETURF_INHERIT_AIR)
var/turf/path = SSmapping.level_trait(our_turf.z, ZTRAIT_BASETURF) || /turf/open/space
if(!ispath(path))
path = text2path(path)
@@ -79,4 +77,3 @@
var/mutable_appearance/underlay_appearance = mutable_appearance(initial(path.icon), initial(path.icon_state), layer = TURF_LAYER-0.02, plane = PLANE_SPACE)
underlay_appearance.appearance_flags = RESET_ALPHA | RESET_COLOR
our_turf.underlays += underlay_appearance
return TRUE
+2 -2
View File
@@ -148,7 +148,7 @@ Simple datum which is instanced once per type and is used for every object of sa
O.clawfootstep = turf_sound_override
O.heavyfootstep = turf_sound_override
if(alpha < 255)
T.AddElement(/datum/element/turf_z_transparency, TRUE)
T.AddElement(/datum/element/turf_z_transparency)
return
/datum/material/proc/get_greyscale_config_for(datum/greyscale_config/config_path)
@@ -202,7 +202,7 @@ Simple datum which is instanced once per type and is used for every object of sa
/datum/material/proc/on_removed_turf(turf/T, amount, material_flags)
if(alpha < 255)
T.RemoveElement(/datum/element/turf_z_transparency, FALSE)
T.RemoveElement(/datum/element/turf_z_transparency)
/**
* This proc is called when the mat is found in an item that's consumed by accident. see /obj/item/proc/on_accidental_consumption.
+30 -34
View File
@@ -7,47 +7,43 @@
*/
/turf/open/floor/catwalk_floor //the base type, meant to look like a maintenance panel
icon = 'icons/turf/floors/catwalk_plating.dmi'
icon_state = "maint_below"
icon_state = "maint_above"
name = "catwalk floor"
desc = "Flooring that shows its contents underneath. Engineers love it!"
baseturfs = /turf/open/floor/plating
floor_tile = /obj/item/stack/tile/catwalk_tile
layer = CATWALK_LAYER
plane = GAME_PLANE
footstep = FOOTSTEP_CATWALK
overfloor_placed = TRUE
underfloor_accessibility = UNDERFLOOR_VISIBLE
var/covered = TRUE
var/above_state = "maint_above" //Icon-state for the overlay
var/catwalk_type = "maint"
var/static/list/catwalk_underlays = list()
/turf/open/floor/catwalk_floor/Initialize(mapload)
. = ..()
update_icon(UPDATE_OVERLAYS)
GLOBAL_LIST_EMPTY(catwalk_overlay_masterlist) //Stores all the above_states for the different types of catwalk
/turf/open/floor/catwalk_floor/update_overlays()
. = ..()
if(!covered)
return //Updating the overlay with nothing actually removes it, in this case. Somehow.
if(!GLOB.catwalk_overlay_masterlist[above_state])
//Generate a new overlay and add it to the global list
var/image/catwalk_overlay = new()
catwalk_overlay.icon = icon
catwalk_overlay.icon_state = above_state
catwalk_overlay.plane = GAME_PLANE
catwalk_overlay.layer = CATWALK_LAYER
GLOB.catwalk_overlay_masterlist[above_state] = catwalk_overlay
. += GLOB.catwalk_overlay_masterlist[above_state]
if(!catwalk_underlays[catwalk_type])
var/mutable_appearance/plating_underlay = mutable_appearance(icon, "[catwalk_type]_below", TURF_LAYER)
catwalk_underlays[catwalk_type] = plating_underlay
underlays += catwalk_underlays[catwalk_type]
update_appearance()
/turf/open/floor/catwalk_floor/screwdriver_act(mob/living/user, obj/item/tool)
. = ..()
covered = !covered
if(!covered)
underfloor_accessibility = UNDERFLOOR_INTERACTABLE
layer = TURF_LAYER
plane = FLOOR_PLANE
icon_state = "[catwalk_type]_below"
else
underfloor_accessibility = UNDERFLOOR_VISIBLE
layer = CATWALK_LAYER
plane = GAME_PLANE
icon_state = "[catwalk_type]_above"
user.balloon_alert(user, "[!covered ? "cover removed" : "cover added"]")
update_icon(UPDATE_OVERLAYS)
update_appearance()
/turf/open/floor/catwalk_floor/crowbar_act(mob/user, obj/item/crowbar)
if(covered)
@@ -55,40 +51,40 @@ GLOBAL_LIST_EMPTY(catwalk_overlay_masterlist) //Stores all the above_states for
return FALSE
. = ..()
//Reskins! More fitting with most of our tiles, and appear as a radial on the base type
/turf/open/floor/catwalk_floor/iron
name = "iron plated catwalk floor"
icon_state = "iron_below"
above_state = "iron_above"
icon_state = "iron_above"
floor_tile = /obj/item/stack/tile/catwalk_tile/iron
catwalk_type = "iron"
/turf/open/floor/catwalk_floor/iron_white
name = "white plated catwalk floor"
icon_state = "whiteiron_below"
above_state = "whiteiron_above"
icon_state = "whiteiron_above"
floor_tile = /obj/item/stack/tile/catwalk_tile/iron_white
catwalk_type = "whiteiron"
/turf/open/floor/catwalk_floor/iron_dark
name = "dark plated catwalk floor"
icon_state = "darkiron_below"
above_state = "darkiron_above"
icon_state = "darkiron_above"
floor_tile = /obj/item/stack/tile/catwalk_tile/iron_dark
catwalk_type = "darkiron"
/turf/open/floor/catwalk_floor/flat_white
name = "white large plated catwalk floor"
icon_state = "flatwhite_below"
above_state = "flatwhite_above"
icon_state = "flatwhite_above"
floor_tile = /obj/item/stack/tile/catwalk_tile/flat_white
catwalk_type = "flatwhite"
/turf/open/floor/catwalk_floor/titanium
name = "titanium plated catwalk floor"
icon_state = "titanium_below"
above_state = "titanium_above"
icon_state = "titanium_above"
floor_tile = /obj/item/stack/tile/catwalk_tile/titanium
catwalk_type = "titanium"
/turf/open/floor/catwalk_floor/iron_smooth //the original green type
name = "smooth plated catwalk floor"
icon_state = "smoothiron_below"
above_state = "smoothiron_above"
icon_state = "smoothiron_above"
floor_tile = /obj/item/stack/tile/catwalk_tile/iron_smooth
catwalk_type = "smoothiron"
+1 -1
View File
@@ -25,7 +25,7 @@
/turf/open/floor/glass/LateInitialize()
. = ..()
AddElement(/datum/element/turf_z_transparency, TRUE)
AddElement(/datum/element/turf_z_transparency)
/turf/open/floor/glass/reinforced
name = "Reinforced glass floor"
+1 -1
View File
@@ -37,7 +37,7 @@ GLOBAL_DATUM_INIT(openspace_backdrop_one_for_all, /atom/movable/openspace_backdr
/turf/open/openspace/LateInitialize()
. = ..()
AddElement(/datum/element/turf_z_transparency, FALSE)
AddElement(/datum/element/turf_z_transparency, is_openspace = TRUE)
/turf/open/openspace/ChangeTurf(path, list/new_baseturfs, flags)
UnregisterSignal(src, COMSIG_ATOM_CREATED)
+3 -3
View File
@@ -129,12 +129,12 @@
var/area/local_area = get_area(src)
if(emergency_mode || (local_area?.fire))
. += mutable_appearance(overlay_icon, "[base_state]_emergency", layer, plane)
. += mutable_appearance(overlay_icon, "[base_state]_emergency")
return
if(nightshift_enabled)
. += mutable_appearance(overlay_icon, "[base_state]_nightshift", layer, plane)
. += mutable_appearance(overlay_icon, "[base_state]_nightshift")
return
. += mutable_appearance(overlay_icon, base_state, layer, plane)
. += mutable_appearance(overlay_icon, base_state)
// update the icon_state and luminosity of the light depending on its state
/obj/machinery/light/proc/update(trigger = TRUE)