Turns lighting objects into a datum, makes all lighting be performed with an underlay. big maptick fix very good! (#58991)

credit to zewaka for the idea of using underlays

turns the lighting object movables that were unnecessary and increased maptick into a datum which then applies and removes an underlay in update(). also applies a lot of general lighting clean ups (mostly using as anything in loops and fixing single letter var names).

multiz is a little different by necessity, now only the bottom turf's lighting matters in the brightness of the top turf unlike master where the bottom turf's lighting object is hidden from the vis_contents of the top turf. there are still some kinks to iron out here though, since currently objects suspended in openspace (like tram platforms) look bad and glass floors look bad too

only thing i have left to do is make multiz work (well)

UPDATE: multiz now appears the same as far as i can tell, its possible there are other situations in which its different but datum mats work and it automatically updates if the turf below changes. now i just need to make the system less finnicky if at all possible (and possibly merge managed_turf_vis_content with managed_overlays maybe?)

new update: its basically equivalent to normal multiz as far as i can tell (visually at least, in the circumstances ive tested so far)

NEW NEW UPDATE: turfs no longer have the VIS_HIDE vis_flag and multiz works without stacking the lighting from the floor below! so this shouldnt have any overt drawbacks to master anymore

1 needless movable per tile is terrible for maptick. this is probably a larger improvement than my emissive blocker change in terms of maptick. im guessing we'd get around 0.6 average maptick per player after this where currently we get 0.85 or so

Edit: according to lemon, sybil reached 0.71 maptick per person when tm'd with this

if this is a big enough improvement i might finally be able to get rid of the Gone discord avatar
This commit is contained in:
Kylerace
2021-06-12 21:37:29 -07:00
committed by GitHub
parent 27604af0d1
commit d3a1bea859
27 changed files with 181 additions and 207 deletions

View File

@@ -71,7 +71,6 @@
/// from datum ui_act (usr, action) /// from datum ui_act (usr, action)
#define COMSIG_UI_ACT "COMSIG_UI_ACT" #define COMSIG_UI_ACT "COMSIG_UI_ACT"
/// fires on the target datum when an element is attached to it (/datum/element) /// fires on the target datum when an element is attached to it (/datum/element)
#define COMSIG_ELEMENT_ATTACH "element_attach" #define COMSIG_ELEMENT_ATTACH "element_attach"
/// fires on the target datum when an element is attached to it (/datum/element) /// fires on the target datum when an element is attached to it (/datum/element)

View File

@@ -111,7 +111,7 @@
#define FRILL_MASK_RENDER_TARGET "*FRILL_MASK_PLANE" #define FRILL_MASK_RENDER_TARGET "*FRILL_MASK_PLANE"
//---------- LIGHTING ------------- //---------- LIGHTING -------------
///Normal 1 per turf dynamic lighting objects ///Normal 1 per turf dynamic lighting underlays
#define LIGHTING_PLANE 100 #define LIGHTING_PLANE 100
#define LIGHTING_RENDER_TARGET "LIGHT_PLANE" #define LIGHTING_RENDER_TARGET "LIGHT_PLANE"

View File

@@ -149,7 +149,7 @@ DEFINE_BITFIELD(smoothing_junction, list(
return ..() return ..()
//do not use, use QUEUE_SMOOTH(atom) ///do not use, use QUEUE_SMOOTH(atom)
/atom/proc/smooth_icon() /atom/proc/smooth_icon()
smoothing_flags &= ~SMOOTH_QUEUED smoothing_flags &= ~SMOOTH_QUEUED
flags_1 |= HTML_USE_INITAL_ICON_1 flags_1 |= HTML_USE_INITAL_ICON_1
@@ -389,7 +389,6 @@ DEFINE_BITFIELD(smoothing_junction, list(
underlay_appearance.icon_state = DEFAULT_UNDERLAY_ICON_STATE underlay_appearance.icon_state = DEFAULT_UNDERLAY_ICON_STATE
underlays = list(underlay_appearance) underlays = list(underlay_appearance)
/turf/open/floor/set_smoothed_icon_state(new_junction) /turf/open/floor/set_smoothed_icon_state(new_junction)
if(broken || burnt) if(broken || burnt)
return return

View File

@@ -7,7 +7,6 @@
/mob/camera, /mob/camera,
/obj/effect, /obj/effect,
/obj/docking_port, /obj/docking_port,
/atom/movable/lighting_object,
/obj/projectile, /obj/projectile,
)) ))
var/list/processing_list = list(location) var/list/processing_list = list(location)

View File

@@ -26,9 +26,10 @@
/atom/movable/screen/plane_master/openspace/Initialize() /atom/movable/screen/plane_master/openspace/Initialize()
. = ..() . = ..()
add_filter("first_stage_openspace", 1, drop_shadow_filter(color = "#04080FAA", size = -10)) add_filter("multiz_lighting_mask", 1, alpha_mask_filter(render_source = LIGHTING_RENDER_TARGET, flags = MASK_INVERSE))
add_filter("second_stage_openspace", 2, drop_shadow_filter(color = "#04080FAA", size = -15)) add_filter("first_stage_openspace", 2, drop_shadow_filter(color = "#04080FAA", size = -10))
add_filter("third_stage_openspace", 2, drop_shadow_filter(color = "#04080FAA", size = -20)) add_filter("second_stage_openspace", 3, drop_shadow_filter(color = "#04080FAA", size = -15))
add_filter("third_stage_openspace", 4, drop_shadow_filter(color = "#04080FAA", size = -20))
///Contains just the floor ///Contains just the floor
/atom/movable/screen/plane_master/floor /atom/movable/screen/plane_master/floor

View File

@@ -72,7 +72,7 @@ SUBSYSTEM_DEF(lighting)
queue = objects_queue queue = objects_queue
for (i in 1 to length(queue)) for (i in 1 to length(queue))
var/atom/movable/lighting_object/O = queue[i] var/datum/lighting_object/O = queue[i]
if (QDELETED(O)) if (QDELETED(O))
continue continue

View File

@@ -1,3 +1,4 @@
/datum/element/turf_z_transparency /datum/element/turf_z_transparency
var/show_bottom_level = FALSE var/show_bottom_level = FALSE
@@ -19,7 +20,6 @@
ADD_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, TURF_TRAIT) ADD_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, TURF_TRAIT)
update_multiz(our_turf, TRUE, TRUE) update_multiz(our_turf, TRUE, TRUE)
/datum/element/turf_z_transparency/Detach(datum/source) /datum/element/turf_z_transparency/Detach(datum/source)
@@ -38,6 +38,7 @@
return FALSE return FALSE
if(init) if(init)
our_turf.vis_contents += below_turf our_turf.vis_contents += below_turf
if(isclosedturf(our_turf)) //Show girders below closed turfs 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) var/mutable_appearance/girder_underlay = mutable_appearance('icons/obj/structures.dmi', "girder", layer = TURF_LAYER-0.01)
girder_underlay.appearance_flags = RESET_ALPHA | RESET_COLOR girder_underlay.appearance_flags = RESET_ALPHA | RESET_COLOR
@@ -47,16 +48,20 @@
our_turf.underlays += plating_underlay our_turf.underlays += plating_underlay
return TRUE return TRUE
/datum/element/turf_z_transparency/proc/on_multiz_turf_del(turf/our_turf, turf/T, dir) /datum/element/turf_z_transparency/proc/on_multiz_turf_del(turf/our_turf, turf/below_turf, dir)
SIGNAL_HANDLER SIGNAL_HANDLER
if(dir != DOWN) if(dir != DOWN)
return return
update_multiz(our_turf) update_multiz(our_turf)
/datum/element/turf_z_transparency/proc/on_multiz_turf_new(turf/our_turf, turf/T, dir) /datum/element/turf_z_transparency/proc/on_multiz_turf_new(turf/our_turf, turf/below_turf, dir)
SIGNAL_HANDLER SIGNAL_HANDLER
if(dir != DOWN) if(dir != DOWN)
return return
update_multiz(our_turf) update_multiz(our_turf)
///Called when there is no real turf below this turf ///Called when there is no real turf below this turf

View File

@@ -6,7 +6,7 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
/turf/proc/empty(turf_type=/turf/open/space, baseturf_type, list/ignore_typecache, flags) /turf/proc/empty(turf_type=/turf/open/space, baseturf_type, list/ignore_typecache, flags)
// Remove all atoms except observers, landmarks, docking ports // Remove all atoms except observers, landmarks, docking ports
var/static/list/ignored_atoms = typecacheof(list(/mob/dead, /obj/effect/landmark, /obj/docking_port, /atom/movable/lighting_object)) var/static/list/ignored_atoms = typecacheof(list(/mob/dead, /obj/effect/landmark, /obj/docking_port))
var/list/allowed_contents = typecache_filter_list_reverse(GetAllContentsIgnoring(ignore_typecache), ignored_atoms) var/list/allowed_contents = typecache_filter_list_reverse(GetAllContentsIgnoring(ignore_typecache), ignored_atoms)
allowed_contents -= src allowed_contents -= src
for(var/i in 1 to allowed_contents.len) for(var/i in 1 to allowed_contents.len)
@@ -23,10 +23,11 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
var/obj/O var/obj/O
if(underlays.len) //we have underlays, which implies some sort of transparency, so we want to a snapshot of the previous turf as an underlay if(underlays.len) //we have underlays, which implies some sort of transparency, so we want to a snapshot of the previous turf as an underlay
O = new() O = new()
O.underlays.Add(T) O.underlays += T
T.ChangeTurf(type) T.ChangeTurf(type)
if(underlays.len) if(underlays.len)
T.underlays = O.underlays T.underlays.Cut()
T.underlays += O.underlays
if(T.icon_state != icon_state) if(T.icon_state != icon_state)
T.icon_state = icon_state T.icon_state = icon_state
if(T.icon != icon) if(T.icon != icon)
@@ -128,9 +129,11 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
lighting_build_overlay() lighting_build_overlay()
else else
lighting_clear_overlay() lighting_clear_overlay()
else if(lighting_object && !lighting_object.needs_update)
lighting_object.update()
for(var/turf/open/space/S in RANGE_TURFS(1, src)) //RANGE_TURFS is in code\__HELPERS\game.dm for(var/turf/open/space/space_tile in RANGE_TURFS(1, src))
S.update_starlight() space_tile.update_starlight()
QUEUE_SMOOTH_NEIGHBORS(src) QUEUE_SMOOTH_NEIGHBORS(src)
QUEUE_SMOOTH(src) QUEUE_SMOOTH(src)

View File

@@ -5,17 +5,16 @@ GLOBAL_DATUM_INIT(openspace_backdrop_one_for_all, /atom/movable/openspace_backdr
anchored = TRUE anchored = TRUE
icon = 'icons/turf/floors.dmi' icon = 'icons/turf/floors.dmi'
icon_state = "grey" icon_state = "grey"
plane = OPENSPACE_BACKDROP_PLANE plane = OPENSPACE_BACKDROP_PLANE
mouse_opacity = MOUSE_OPACITY_TRANSPARENT mouse_opacity = MOUSE_OPACITY_TRANSPARENT
//I don't know why the others are aligned but I shall do the same.
vis_flags = VIS_INHERIT_ID vis_flags = VIS_INHERIT_ID
/turf/open/openspace /turf/open/openspace
name = "open space" name = "open space"
desc = "Watch your step!" desc = "Watch your step!"
icon_state = "transparent" icon_state = "invisible"
baseturfs = /turf/open/openspace baseturfs = /turf/open/openspace
CanAtmosPassVertical = ATMOS_PASS_YES CanAtmosPassVertical = ATMOS_PASS_YES
baseturfs = /turf/open/openspace baseturfs = /turf/open/openspace
@@ -28,7 +27,7 @@ GLOBAL_DATUM_INIT(openspace_backdrop_one_for_all, /atom/movable/openspace_backdr
initial_gas_mix = AIRLESS_ATMOS initial_gas_mix = AIRLESS_ATMOS
/turf/open/openspace/airless/planetary /turf/open/openspace/airless/planetary
planetary_atmos = TRUE planetary_atmos = TRUE
/turf/open/openspace/Initialize() // handle plane and layer here so that they don't cover other obs/turfs in Dream Maker /turf/open/openspace/Initialize() // handle plane and layer here so that they don't cover other obs/turfs in Dream Maker
. = ..() . = ..()

View File

@@ -3,7 +3,7 @@ GLOBAL_LIST_EMPTY(station_turfs)
/// Any floor or wall. What makes up the station and the rest of the map. /// Any floor or wall. What makes up the station and the rest of the map.
/turf /turf
icon = 'icons/turf/floors.dmi' icon = 'icons/turf/floors.dmi'
vis_flags = VIS_INHERIT_ID|VIS_INHERIT_PLANE // Important for interaction with and visualization of openspace. vis_flags = VIS_INHERIT_ID | VIS_INHERIT_PLANE// Important for interaction with and visualization of openspace.
luminosity = 1 luminosity = 1
/// Turf bitflags, see code/__DEFINES/flags.dm /// Turf bitflags, see code/__DEFINES/flags.dm
var/turf_flags = NONE var/turf_flags = NONE
@@ -46,7 +46,7 @@ GLOBAL_LIST_EMPTY(station_turfs)
var/tmp/lighting_corners_initialised = FALSE var/tmp/lighting_corners_initialised = FALSE
///Our lighting object. ///Our lighting object.
var/tmp/atom/movable/lighting_object/lighting_object var/tmp/datum/lighting_object/lighting_object
///Lighting Corner datums. ///Lighting Corner datums.
var/tmp/datum/lighting_corner/lighting_corner_NE var/tmp/datum/lighting_corner/lighting_corner_NE
var/tmp/datum/lighting_corner/lighting_corner_SE var/tmp/datum/lighting_corner/lighting_corner_SE

View File

@@ -355,7 +355,6 @@ GLOBAL_LIST_EMPTY(gateway_destinations)
if(!our_destination) if(!our_destination)
return return
add_filter("portal_alpha", 1, list("type" = "alpha", "icon" = icon(alpha_icon, alpha_icon_state), "x" = 32, "y" = 32)) add_filter("portal_alpha", 1, list("type" = "alpha", "icon" = icon(alpha_icon, alpha_icon_state), "x" = 32, "y" = 32))
add_filter("portal_blur", 1, list("type" = "blur", "size" = 0.5)) add_filter("portal_blur", 1, list("type" = "blur", "size" = 0.5))
add_filter("portal_ripple", 1, list("type" = "ripple", "size" = 2, "radius" = 1, "falloff" = 1, "y" = 7)) add_filter("portal_ripple", 1, list("type" = "ripple", "size" = 2, "radius" = 1, "falloff" = 1, "y" = 7))
@@ -363,5 +362,4 @@ GLOBAL_LIST_EMPTY(gateway_destinations)
animate(get_filter("portal_ripple"), time = 1.3 SECONDS, loop = -1, easing = LINEAR_EASING, radius = 32) animate(get_filter("portal_ripple"), time = 1.3 SECONDS, loop = -1, easing = LINEAR_EASING, radius = 32)
var/turf/center_turf = our_destination.get_target_turf() var/turf/center_turf = our_destination.get_target_turf()
vis_contents += block(locate(center_turf.x - 1, center_turf.y - 1, center_turf.z), locate(center_turf.x + 1, center_turf.y + 1, center_turf.z)) vis_contents += block(locate(center_turf.x - 1, center_turf.y - 1, center_turf.z), locate(center_turf.x + 1, center_turf.y + 1, center_turf.z))

View File

@@ -25,7 +25,7 @@
//Variables declared to change how items in the launch bay are picked and launched. (Almost) all of these are changed in the ui_act proc //Variables declared to change how items in the launch bay are picked and launched. (Almost) all of these are changed in the ui_act proc
//Some effect groups are choices, while other are booleans. This is because some effects can stack, while others dont (ex: you can stack explosion and quiet, but you cant stack ordered launch and random launch) //Some effect groups are choices, while other are booleans. This is because some effects can stack, while others dont (ex: you can stack explosion and quiet, but you cant stack ordered launch and random launch)
/datum/centcom_podlauncher /datum/centcom_podlauncher
var/static/list/ignored_atoms = typecacheof(list(null, /mob/dead, /obj/effect/landmark, /obj/docking_port, /atom/movable/lighting_object, /obj/effect/particle_effect/sparks, /obj/effect/pod_landingzone, /obj/effect/hallucination/simple/supplypod_selector, /obj/effect/hallucination/simple/dropoff_location)) var/static/list/ignored_atoms = typecacheof(list(null, /mob/dead, /obj/effect/landmark, /obj/docking_port, /obj/effect/particle_effect/sparks, /obj/effect/pod_landingzone, /obj/effect/hallucination/simple/supplypod_selector, /obj/effect/hallucination/simple/dropoff_location))
var/turf/oldTurf //Keeps track of where the user was at if they use the "teleport to centcom" button, so they can go back var/turf/oldTurf //Keeps track of where the user was at if they use the "teleport to centcom" button, so they can go back
var/client/holder //client of whoever is using this datum var/client/holder //client of whoever is using this datum
var/area/centcom/supplypod/loading/bay //What bay we're using to launch shit from. var/area/centcom/supplypod/loading/bay //What bay we're using to launch shit from.

View File

@@ -1,5 +1,5 @@
/area /area
luminosity = TRUE luminosity = TRUE
var/dynamic_lighting = DYNAMIC_LIGHTING_ENABLED var/dynamic_lighting = DYNAMIC_LIGHTING_ENABLED
/area/proc/set_dynamic_lighting(new_dynamic_lighting = DYNAMIC_LIGHTING_ENABLED) /area/proc/set_dynamic_lighting(new_dynamic_lighting = DYNAMIC_LIGHTING_ENABLED)

View File

@@ -83,11 +83,8 @@
/atom/movable/Moved(atom/OldLoc, Dir) /atom/movable/Moved(atom/OldLoc, Dir)
. = ..() . = ..()
var/datum/light_source/L for (var/datum/light_source/light as anything in light_sources) // Cycle through the light sources on this atom and tell them to update.
var/thing light.source_atom.update_light()
for (thing in light_sources) // Cycle through the light sources on this atom and tell them to update.
L = thing
L.source_atom.update_light()
/atom/proc/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION) /atom/proc/flash_lighting_fx(_range = FLASH_LIGHT_RANGE, _power = FLASH_LIGHT_POWER, _color = COLOR_WHITE, _duration = FLASH_LIGHT_DURATION)

View File

@@ -2,29 +2,32 @@
// And corners get shared between multiple turfs (unless you're on the corners of the map, then 1 corner doesn't). // And corners get shared between multiple turfs (unless you're on the corners of the map, then 1 corner doesn't).
// For the record: these should never ever ever be deleted, even if the turf doesn't have dynamic lighting. // For the record: these should never ever ever be deleted, even if the turf doesn't have dynamic lighting.
/datum/lighting_corner /datum/lighting_corner
var/list/datum/light_source/affecting // Light sources affecting us. var/list/datum/light_source/affecting // Light sources affecting us.
var/x = 0 var/x = 0
var/y = 0 var/y = 0
var/turf/master_NE var/turf/master_NE
var/turf/master_SE var/turf/master_SE
var/turf/master_SW var/turf/master_SW
var/turf/master_NW var/turf/master_NW
//"raw" color values, changed by update_lumcount()
var/lum_r = 0 var/lum_r = 0
var/lum_g = 0 var/lum_g = 0
var/lum_b = 0 var/lum_b = 0
var/needs_update = FALSE //true color values, guaranteed to be between 0 and 1
var/cache_r = LIGHTING_SOFT_THRESHOLD
var/cache_g = LIGHTING_SOFT_THRESHOLD
var/cache_b = LIGHTING_SOFT_THRESHOLD
var/cache_r = LIGHTING_SOFT_THRESHOLD ///the maximum of lum_r, lum_g, and lum_b. if this is > 1 then the three cached color values are divided by this
var/cache_g = LIGHTING_SOFT_THRESHOLD var/largest_color_luminosity = 0
var/cache_b = LIGHTING_SOFT_THRESHOLD
var/cache_mx = 0 ///whether we are to be added to SSlighting's corners_queue list for an update
var/needs_update = FALSE
/datum/lighting_corner/New(turf/new_turf, diagonal) /datum/lighting_corner/New(turf/new_turf, diagonal)
. = ..() . = ..()
@@ -39,22 +42,22 @@
// My initial plan was to make this loop through a list of all the dirs (horizontal, vertical, diagonal). // My initial plan was to make this loop through a list of all the dirs (horizontal, vertical, diagonal).
// Issue being that the only way I could think of doing it was very messy, slow and honestly overengineered. // Issue being that the only way I could think of doing it was very messy, slow and honestly overengineered.
// So we'll have this hardcode instead. // So we'll have this hardcode instead.
var/turf/T var/turf/new_master_turf
// Diagonal one is easy. // Diagonal one is easy.
T = get_step(new_turf, diagonal) new_master_turf = get_step(new_turf, diagonal)
if (T) // In case we're on the map's border. if (new_master_turf) // In case we're on the map's border.
save_master(T, diagonal) save_master(new_master_turf, diagonal)
// Now the horizontal one. // Now the horizontal one.
T = get_step(new_turf, horizontal) new_master_turf = get_step(new_turf, horizontal)
if (T) // Ditto. if (new_master_turf) // Ditto.
save_master(T, ((T.x > x) ? EAST : WEST) | ((T.y > y) ? NORTH : SOUTH)) // Get the dir based on coordinates. save_master(new_master_turf, ((new_master_turf.x > x) ? EAST : WEST) | ((new_master_turf.y > y) ? NORTH : SOUTH)) // Get the dir based on coordinates.
// And finally the vertical one. // And finally the vertical one.
T = get_step(new_turf, vertical) new_master_turf = get_step(new_turf, vertical)
if (T) if (new_master_turf)
save_master(T, ((T.x > x) ? EAST : WEST) | ((T.y > y) ? NORTH : SOUTH)) // Get the dir based on coordinates. save_master(new_master_turf, ((new_master_turf.x > x) ? EAST : WEST) | ((new_master_turf.y > y) ? NORTH : SOUTH)) // Get the dir based on coordinates.
/datum/lighting_corner/proc/save_master(turf/master, dir) /datum/lighting_corner/proc/save_master(turf/master, dir)
switch (dir) switch (dir)
@@ -101,13 +104,13 @@
var/lum_r = src.lum_r var/lum_r = src.lum_r
var/lum_g = src.lum_g var/lum_g = src.lum_g
var/lum_b = src.lum_b var/lum_b = src.lum_b
var/mx = max(lum_r, lum_g, lum_b) // Scale it so one of them is the strongest lum, if it is above 1. var/largest_color_luminosity = max(lum_r, lum_g, lum_b) // Scale it so one of them is the strongest lum, if it is above 1.
. = 1 // factor . = 1 // factor
if (mx > 1) if (largest_color_luminosity > 1)
. = 1 / mx . = 1 / largest_color_luminosity
#if LIGHTING_SOFT_THRESHOLD != 0 #if LIGHTING_SOFT_THRESHOLD != 0
else if (mx < LIGHTING_SOFT_THRESHOLD) else if (largest_color_luminosity < LIGHTING_SOFT_THRESHOLD)
. = 0 // 0 means soft lighting. . = 0 // 0 means soft lighting.
cache_r = round(lum_r * ., LIGHTING_ROUND_VALUE) || LIGHTING_SOFT_THRESHOLD cache_r = round(lum_r * ., LIGHTING_ROUND_VALUE) || LIGHTING_SOFT_THRESHOLD
@@ -118,23 +121,24 @@
cache_g = round(lum_g * ., LIGHTING_ROUND_VALUE) cache_g = round(lum_g * ., LIGHTING_ROUND_VALUE)
cache_b = round(lum_b * ., LIGHTING_ROUND_VALUE) cache_b = round(lum_b * ., LIGHTING_ROUND_VALUE)
#endif #endif
cache_mx = round(mx, LIGHTING_ROUND_VALUE)
var/atom/movable/lighting_object/lighting_object = master_NE?.lighting_object src.largest_color_luminosity = round(largest_color_luminosity, LIGHTING_ROUND_VALUE)
var/datum/lighting_object/lighting_object = master_NE?.lighting_object
if (lighting_object && !lighting_object.needs_update) if (lighting_object && !lighting_object.needs_update)
lighting_object.needs_update = TRUE lighting_object.needs_update = TRUE
SSlighting.objects_queue += lighting_object SSlighting.objects_queue += lighting_object
lighting_object = master_SE?.lighting_object lighting_object = master_SE?.lighting_object
if (lighting_object && !lighting_object.needs_update) if (lighting_object && !lighting_object.needs_update)
lighting_object.needs_update = TRUE lighting_object.needs_update = TRUE
SSlighting.objects_queue += lighting_object SSlighting.objects_queue += lighting_object
lighting_object = master_SW?.lighting_object lighting_object = master_SW?.lighting_object
if (lighting_object && !lighting_object.needs_update) if (lighting_object && !lighting_object.needs_update)
lighting_object.needs_update = TRUE lighting_object.needs_update = TRUE
SSlighting.objects_queue += lighting_object SSlighting.objects_queue += lighting_object
lighting_object = master_NW?.lighting_object lighting_object = master_NW?.lighting_object
if (lighting_object && !lighting_object.needs_update) if (lighting_object && !lighting_object.needs_update)
lighting_object.needs_update = TRUE lighting_object.needs_update = TRUE

View File

@@ -1,64 +1,48 @@
/atom/movable/lighting_object /datum/lighting_object
name = "" ///the underlay we are currently applying to our turf to apply light
var/mutable_appearance/current_underlay
anchored = TRUE
icon = LIGHTING_ICON
icon_state = "transparent"
color = null //we manually set color in init instead
plane = LIGHTING_PLANE
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
invisibility = INVISIBILITY_LIGHTING
vis_flags = VIS_HIDE
///whether we are already in the SSlighting.objects_queue list
var/needs_update = FALSE var/needs_update = FALSE
var/turf/myturf
/atom/movable/lighting_object/Initialize(mapload) ///the turf that our light is applied to
var/turf/affected_turf
/datum/lighting_object/New(turf/source)
if(!isturf(source))
qdel(src, force=TRUE)
stack_trace("a lighting object was assigned to [source], a non turf! ")
return
. = ..() . = ..()
verbs.Cut()
//We avoid setting this in the base as if we do then the parent atom handling will add_atom_color it and that
//is totally unsuitable for this object, as we are always changing it's colour manually
color = LIGHTING_BASE_MATRIX
myturf = loc current_underlay = mutable_appearance(LIGHTING_ICON, "transparent", source.z, LIGHTING_PLANE, 255, RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM)
if (myturf.lighting_object)
qdel(myturf.lighting_object, force = TRUE)
myturf.lighting_object = src
myturf.luminosity = 0
for(var/turf/open/space/S in RANGE_TURFS(1, src)) //RANGE_TURFS is in code\__HELPERS\game.dm affected_turf = source
S.update_starlight() if (affected_turf.lighting_object)
qdel(affected_turf.lighting_object, force = TRUE)
stack_trace("a lighting object was assigned to a turf that already had a lighting object!")
affected_turf.lighting_object = src
affected_turf.luminosity = 0
for(var/turf/open/space/space_tile in RANGE_TURFS(1, affected_turf))
space_tile.update_starlight()
needs_update = TRUE needs_update = TRUE
SSlighting.objects_queue += src SSlighting.objects_queue += src
/atom/movable/lighting_object/Destroy(force) /datum/lighting_object/Destroy(force)
if (force) if (!force)
SSlighting.objects_queue -= src
if (loc != myturf)
var/turf/oldturf = get_turf(myturf)
var/turf/newturf = get_turf(loc)
stack_trace("A lighting object was qdeleted with a different loc then it is suppose to have ([COORD(oldturf)] -> [COORD(newturf)])")
if (isturf(myturf))
myturf.lighting_object = null
myturf.luminosity = 1
myturf = null
return ..()
else
return QDEL_HINT_LETMELIVE return QDEL_HINT_LETMELIVE
SSlighting.objects_queue -= src
if (isturf(affected_turf))
affected_turf.lighting_object = null
affected_turf.luminosity = 1
affected_turf.underlays -= current_underlay
affected_turf = null
return ..()
/atom/movable/lighting_object/proc/update() /datum/lighting_object/proc/update()
if (loc != myturf)
if (loc)
var/turf/oldturf = get_turf(myturf)
var/turf/newturf = get_turf(loc)
warning("A lighting object realised it's loc had changed in update() ([myturf]\[[myturf ? myturf.type : "null"]]([COORD(oldturf)]) -> [loc]\[[ loc ? loc.type : "null"]]([COORD(newturf)]))!")
qdel(src, TRUE)
return
// To the future coder who sees this and thinks // To the future coder who sees this and thinks
// "Why didn't he just use a loop?" // "Why didn't he just use a loop?"
@@ -68,31 +52,30 @@
// Oh it's also shorter line wise. // Oh it's also shorter line wise.
// Including with these comments. // Including with these comments.
// See LIGHTING_CORNER_DIAGONAL in lighting_corner.dm for why these values are what they are.
var/static/datum/lighting_corner/dummy/dummy_lighting_corner = new var/static/datum/lighting_corner/dummy/dummy_lighting_corner = new
var/datum/lighting_corner/cr = myturf.lighting_corner_SW || dummy_lighting_corner var/datum/lighting_corner/red_corner = affected_turf.lighting_corner_SW || dummy_lighting_corner
var/datum/lighting_corner/cg = myturf.lighting_corner_SE || dummy_lighting_corner var/datum/lighting_corner/green_corner = affected_turf.lighting_corner_SE || dummy_lighting_corner
var/datum/lighting_corner/cb = myturf.lighting_corner_NW || dummy_lighting_corner var/datum/lighting_corner/blue_corner = affected_turf.lighting_corner_NW || dummy_lighting_corner
var/datum/lighting_corner/ca = myturf.lighting_corner_NE || dummy_lighting_corner var/datum/lighting_corner/alpha_corner = affected_turf.lighting_corner_NE || dummy_lighting_corner
var/max = max(cr.cache_mx, cg.cache_mx, cb.cache_mx, ca.cache_mx) var/max = max(red_corner.largest_color_luminosity, green_corner.largest_color_luminosity, blue_corner.largest_color_luminosity, alpha_corner.largest_color_luminosity)
var/rr = cr.cache_r var/rr = red_corner.cache_r
var/rg = cr.cache_g var/rg = red_corner.cache_g
var/rb = cr.cache_b var/rb = red_corner.cache_b
var/gr = cg.cache_r var/gr = green_corner.cache_r
var/gg = cg.cache_g var/gg = green_corner.cache_g
var/gb = cg.cache_b var/gb = green_corner.cache_b
var/br = cb.cache_r var/br = blue_corner.cache_r
var/bg = cb.cache_g var/bg = blue_corner.cache_g
var/bb = cb.cache_b var/bb = blue_corner.cache_b
var/ar = ca.cache_r var/ar = alpha_corner.cache_r
var/ag = ca.cache_g var/ag = alpha_corner.cache_g
var/ab = ca.cache_b var/ab = alpha_corner.cache_b
#if LIGHTING_SOFT_THRESHOLD != 0 #if LIGHTING_SOFT_THRESHOLD != 0
var/set_luminosity = max > LIGHTING_SOFT_THRESHOLD var/set_luminosity = max > LIGHTING_SOFT_THRESHOLD
@@ -103,15 +86,20 @@
#endif #endif
if((rr & gr & br & ar) && (rg + gg + bg + ag + rb + gb + bb + ab == 8)) if((rr & gr & br & ar) && (rg + gg + bg + ag + rb + gb + bb + ab == 8))
//anything that passes the first case is very likely to pass the second, and addition is a little faster in this case //anything that passes the first case is very likely to pass the second, and addition is a little faster in this case
icon_state = "transparent" affected_turf.underlays -= current_underlay
color = null current_underlay.icon_state = "transparent"
current_underlay.color = null
affected_turf.underlays += current_underlay
else if(!set_luminosity) else if(!set_luminosity)
icon_state = "dark" affected_turf.underlays -= current_underlay
color = null current_underlay.icon_state = "dark"
current_underlay.color = null
affected_turf.underlays += current_underlay
else else
icon_state = null affected_turf.underlays -= current_underlay
color = list( current_underlay.icon_state = null
current_underlay.color = list(
rr, rg, rb, 00, rr, rg, rb, 00,
gr, gg, gb, 00, gr, gg, gb, 00,
br, bg, bb, 00, br, bg, bb, 00,
@@ -119,30 +107,6 @@
00, 00, 00, 01 00, 00, 00, 01
) )
luminosity = set_luminosity affected_turf.underlays += current_underlay
// Variety of overrides so the overlays don't get affected by weird things. affected_turf.luminosity = set_luminosity
/atom/movable/lighting_object/ex_act(severity)
return FALSE
/atom/movable/lighting_object/singularity_act()
return
/atom/movable/lighting_object/singularity_pull()
return
/atom/movable/lighting_object/blob_act()
return
/atom/movable/lighting_object/onTransitZ()
return
/atom/movable/lighting_object/wash(clean_types)
SHOULD_CALL_PARENT(FALSE) // lighting objects are dirty, confirmed
return
// Override here to prevent things accidentally moving around overlays.
/atom/movable/lighting_object/forceMove(atom/destination, no_tp=FALSE, harderforce = FALSE)
if(harderforce)
. = ..()

View File

@@ -1,3 +1,4 @@
/proc/create_all_lighting_objects() /proc/create_all_lighting_objects()
for(var/area/A in world) for(var/area/A in world)
if(!IS_DYNAMIC_LIGHTING(A)) if(!IS_DYNAMIC_LIGHTING(A))
@@ -8,6 +9,6 @@
if(!IS_DYNAMIC_LIGHTING(T)) if(!IS_DYNAMIC_LIGHTING(T))
continue continue
new/atom/movable/lighting_object(T) new/datum/lighting_object(T)
CHECK_TICK CHECK_TICK
CHECK_TICK CHECK_TICK

View File

@@ -2,14 +2,21 @@
// These are the main datums that emit light. // These are the main datums that emit light.
/datum/light_source /datum/light_source
var/atom/top_atom // The atom we're emitting light from (for example a mob if we're from a flashlight that's being held). ///The atom we're emitting light from (for example a mob if we're from a flashlight that's being held).
var/atom/source_atom // The atom that we belong to. var/atom/top_atom
///The atom that we belong to.
var/atom/source_atom
var/turf/source_turf // The turf under the above. ///The turf under the source atom.
var/turf/pixel_turf // The turf the top_atom appears to over. var/turf/source_turf
var/light_power // Intensity of the emitter light. ///The turf the top_atom appears to over.
var/light_range // The range of the emitted light. var/turf/pixel_turf
var/light_color // The colour of the light, string, decomposed by parse_light_color() ///Intensity of the emitter light.
var/light_power
/// The range of the emitted light.
var/light_range
/// The colour of the light, string, decomposed by parse_light_color()
var/light_color
// Variables for keeping track of the colour. // Variables for keeping track of the colour.
var/lum_r var/lum_r
@@ -21,11 +28,14 @@
var/tmp/applied_lum_g var/tmp/applied_lum_g
var/tmp/applied_lum_b var/tmp/applied_lum_b
var/list/datum/lighting_corner/effect_str // List used to store how much we're affecting corners. /// List used to store how much we're affecting corners.
var/list/datum/lighting_corner/effect_str
var/applied = FALSE // Whether we have applied our light yet or not. /// Whether we have applied our light yet or not.
var/applied = FALSE
var/needs_update = LIGHTING_NO_UPDATE // Whether we are queued for an update. /// whether we are to be added to SSlighting's sources_queue list for an update
var/needs_update = LIGHTING_NO_UPDATE
/datum/light_source/New(atom/owner, atom/top) /datum/light_source/New(atom/owner, atom/top)
@@ -124,8 +134,7 @@
. * applied_lum_b \ . * applied_lum_b \
); );
// This is the define used to calculate falloff. /// This is the define used to calculate falloff.
/datum/light_source/proc/remove_lum() /datum/light_source/proc/remove_lum()
applied = FALSE applied = FALSE
for (var/datum/lighting_corner/corner as anything in effect_str) for (var/datum/lighting_corner/corner as anything in effect_str)
@@ -134,14 +143,14 @@
effect_str = null effect_str = null
/datum/light_source/proc/recalc_corner(datum/lighting_corner/C) /datum/light_source/proc/recalc_corner(datum/lighting_corner/corner)
LAZYINITLIST(effect_str) LAZYINITLIST(effect_str)
if (effect_str[C]) // Already have one. if (effect_str[corner]) // Already have one.
REMOVE_CORNER(C) REMOVE_CORNER(corner)
effect_str[C] = 0 effect_str[corner] = 0
APPLY_CORNER(C) APPLY_CORNER(corner)
effect_str[C] = . effect_str[corner] = .
/datum/light_source/proc/update_corners() /datum/light_source/proc/update_corners()
@@ -178,9 +187,9 @@
pixel_turf = get_turf_pixel(top_atom) pixel_turf = get_turf_pixel(top_atom)
update = TRUE update = TRUE
else else
var/P = get_turf_pixel(top_atom) var/pixel_loc = get_turf_pixel(top_atom)
if (P != pixel_turf) if (pixel_loc != pixel_turf)
pixel_turf = P pixel_turf = pixel_loc
update = TRUE update = TRUE
if (!isturf(source_turf)) if (!isturf(source_turf))
@@ -206,7 +215,7 @@
return //nothing's changed return //nothing's changed
var/list/datum/lighting_corner/corners = list() var/list/datum/lighting_corner/corners = list()
var/list/turf/turfs = list() var/list/turf/turfs = list()
if (source_turf) if (source_turf)
var/oldlum = source_turf.luminosity var/oldlum = source_turf.luminosity
@@ -246,7 +255,7 @@
effect_str -= corner effect_str -= corner
var/list/datum/lighting_corner/gone_corners = effect_str - corners var/list/datum/lighting_corner/gone_corners = effect_str - corners
for (var/datum/lighting_corner/corner as anything in gone_corners) for (var/datum/lighting_corner/corner as anything in gone_corners)
REMOVE_CORNER(corner) REMOVE_CORNER(corner)
LAZYREMOVE(corner.affecting, src) LAZYREMOVE(corner.affecting, src)
effect_str -= gone_corners effect_str -= gone_corners

View File

@@ -7,18 +7,18 @@
/turf/proc/lighting_clear_overlay() /turf/proc/lighting_clear_overlay()
if (lighting_object) if (lighting_object)
qdel(lighting_object, TRUE) qdel(lighting_object, force=TRUE)
// Builds a lighting object for us, but only if our area is dynamic. // Builds a lighting object for us, but only if our area is dynamic.
/turf/proc/lighting_build_overlay() /turf/proc/lighting_build_overlay()
if (lighting_object) if (lighting_object)
qdel(lighting_object,force=TRUE) //Shitty fix for lighting objects persisting after death qdel(lighting_object, force=TRUE) //Shitty fix for lighting objects persisting after death
var/area/A = loc var/area/our_area = loc
if (!IS_DYNAMIC_LIGHTING(A) && !light_sources) if (!IS_DYNAMIC_LIGHTING(our_area) && !light_sources)
return return
new/atom/movable/lighting_object(src) new/datum/lighting_object(src)
// Used to get a scaled lumcount. // Used to get a scaled lumcount.
/turf/proc/get_lumcount(minlum = 0, maxlum = 1) /turf/proc/get_lumcount(minlum = 0, maxlum = 1)
@@ -39,7 +39,7 @@
L = lighting_corner_NW L = lighting_corner_NW
if (L) if (L)
totallums += L.lum_r + L.lum_b + L.lum_g totallums += L.lum_r + L.lum_b + L.lum_g
totallums /= 12 // 4 corners, each with 3 channels, get the average. totallums /= 12 // 4 corners, each with 3 channels, get the average.
@@ -57,7 +57,7 @@
if (!lighting_object) if (!lighting_object)
return FALSE return FALSE
return !(lighting_object.luminosity || dynamic_lumcount) return !(luminosity || dynamic_lumcount)
///Proc to add movable sources of opacity on the turf and let it handle lighting code. ///Proc to add movable sources of opacity on the turf and let it handle lighting code.
@@ -85,8 +85,7 @@
reconsider_lights() reconsider_lights()
return return
directional_opacity = NONE directional_opacity = NONE
for(var/am in opacity_sources) for(var/atom/movable/opacity_source as anything in opacity_sources)
var/atom/movable/opacity_source = am
if(opacity_source.flags_1 & ON_BORDER_1) if(opacity_source.flags_1 & ON_BORDER_1)
directional_opacity |= opacity_source.dir directional_opacity |= opacity_source.dir
else //If fulltile and opaque, then the whole tile blocks view, no need to continue checking. else //If fulltile and opaque, then the whole tile blocks view, no need to continue checking.
@@ -107,14 +106,14 @@
/turf/proc/generate_missing_corners() /turf/proc/generate_missing_corners()
if (!lighting_corner_NE) if (!lighting_corner_NE)
lighting_corner_NE = new/datum/lighting_corner(src, NORTH|EAST) lighting_corner_NE = new/datum/lighting_corner(src, NORTH|EAST)
if (!lighting_corner_SE) if (!lighting_corner_SE)
lighting_corner_SE = new/datum/lighting_corner(src, SOUTH|EAST) lighting_corner_SE = new/datum/lighting_corner(src, SOUTH|EAST)
if (!lighting_corner_SW) if (!lighting_corner_SW)
lighting_corner_SW = new/datum/lighting_corner(src, SOUTH|WEST) lighting_corner_SW = new/datum/lighting_corner(src, SOUTH|WEST)
if (!lighting_corner_NW) if (!lighting_corner_NW)
lighting_corner_NW = new/datum/lighting_corner(src, NORTH|WEST) lighting_corner_NW = new/datum/lighting_corner(src, NORTH|WEST)
lighting_corners_initialised = TRUE lighting_corners_initialised = TRUE

View File

@@ -207,7 +207,7 @@
// Please do not add one-off mob AIs here, but override this function for your mob // Please do not add one-off mob AIs here, but override this function for your mob
/mob/living/simple_animal/hostile/CanAttack(atom/the_target)//Can we actually attack a possible target? /mob/living/simple_animal/hostile/CanAttack(atom/the_target)//Can we actually attack a possible target?
if(isturf(the_target) || !the_target || the_target.type == /atom/movable/lighting_object) // bail out on invalids if(isturf(the_target) || !the_target) // bail out on invalids
return FALSE return FALSE
if(ismob(the_target)) //Target is in godmode, ignore it. if(ismob(the_target)) //Target is in godmode, ignore it.

View File

@@ -51,7 +51,7 @@
ADD_TRAIT(src, TRAIT_VENTCRAWLER_ALWAYS, INNATE_TRAIT) ADD_TRAIT(src, TRAIT_VENTCRAWLER_ALWAYS, INNATE_TRAIT)
/mob/living/simple_animal/hostile/asteroid/gutlunch/CanAttack(atom/the_target) // Gutlunch-specific version of CanAttack to handle stupid stat_exclusive = true crap so we don't have to do it for literally every single simple_animal/hostile except the two that spawn in lavaland /mob/living/simple_animal/hostile/asteroid/gutlunch/CanAttack(atom/the_target) // Gutlunch-specific version of CanAttack to handle stupid stat_exclusive = true crap so we don't have to do it for literally every single simple_animal/hostile except the two that spawn in lavaland
if(isturf(the_target) || !the_target || the_target.type == /atom/movable/lighting_object) // bail out on invalids if(isturf(the_target) || !the_target) // bail out on invalids
return FALSE return FALSE
if(see_invisible < the_target.invisibility)//Target's invisible to us, forget it if(see_invisible < the_target.invisibility)//Target's invisible to us, forget it

View File

@@ -70,7 +70,7 @@
ADD_TRAIT(src, TRAIT_VENTCRAWLER_ALWAYS, INNATE_TRAIT) ADD_TRAIT(src, TRAIT_VENTCRAWLER_ALWAYS, INNATE_TRAIT)
/mob/living/simple_animal/hostile/mushroom/CanAttack(atom/the_target) // Mushroom-specific version of CanAttack to handle stupid attack_same = 2 crap so we don't have to do it for literally every single simple_animal/hostile because this shit never gets spawned /mob/living/simple_animal/hostile/mushroom/CanAttack(atom/the_target) // Mushroom-specific version of CanAttack to handle stupid attack_same = 2 crap so we don't have to do it for literally every single simple_animal/hostile because this shit never gets spawned
if(!the_target || isturf(the_target) || istype(the_target, /atom/movable/lighting_object)) if(!the_target || isturf(the_target))
return FALSE return FALSE
if(see_invisible < the_target.invisibility)//Target's invisible to us, forget it if(see_invisible < the_target.invisibility)//Target's invisible to us, forget it

View File

@@ -215,7 +215,7 @@
msg = blind_message msg = blind_message
else if(T != loc && T != src) //if src is inside something and not a turf. else if(T != loc && T != src) //if src is inside something and not a turf.
msg = blind_message msg = blind_message
else if(T.lighting_object && T.lighting_object.invisibility <= M.see_invisible && T.is_softly_lit() && !in_range(T,M)) //if it is too dark, unless we're right next to them. else if(M.lighting_alpha > LIGHTING_PLANE_ALPHA_MOSTLY_INVISIBLE && T.is_softly_lit() && !in_range(T,M)) //if it is too dark, unless we're right next to them.
msg = blind_message msg = blind_message
if(!msg) if(!msg)
continue continue

View File

@@ -136,7 +136,7 @@ GLOBAL_LIST_EMPTY(conveyors_by_id)
//get the first 30 items in contents //get the first 30 items in contents
var/turf/locturf = loc var/turf/locturf = loc
var/list/items = locturf.contents - src - locturf.lighting_object var/list/items = locturf.contents - src
if(!LAZYLEN(items))//Dont do anything at all if theres nothing there but the conveyor if(!LAZYLEN(items))//Dont do anything at all if theres nothing there but the conveyor
return return
var/list/affecting var/list/affecting

View File

@@ -362,9 +362,6 @@ All ShuttleMove procs go here
/************************************Misc move procs************************************/ /************************************Misc move procs************************************/
/atom/movable/lighting_object/onShuttleMove()
return FALSE
/obj/docking_port/mobile/beforeShuttleMove(turf/newT, rotation, move_mode, obj/docking_port/mobile/moving_dock) /obj/docking_port/mobile/beforeShuttleMove(turf/newT, rotation, move_mode, obj/docking_port/mobile/moving_dock)
. = ..() . = ..()
if(moving_dock == src) if(moving_dock == src)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 KiB

After

Width:  |  Height:  |  Size: 364 KiB