From 58b953a3fcd99480b51e7979ce7c07f7bcefe401 Mon Sep 17 00:00:00 2001 From: Lohikar Date: Sat, 20 May 2017 06:24:04 -0500 Subject: [PATCH] Cross-Z Lighting (#2281) This PR edits the lighting engine's turf selection algorithm to also include turfs below openturf tiles, allowing for cross-Z lighting. changes: Lights now will now shine down Z-levels when they light up an open turf. Commented-out openturf starlight pending making it not pummel SSlighting. Openspace overlays are now only queued if they are not already in the queue. Lighting overlays will now also update their associated openturf overlay on update if they have one. Removed an old unused message from the asteroid generation subsystem. --- baystation12.dme | 1 - code/__defines/subsystem-priority.dm | 6 +-- .../subsystems/initialization/asteroid.dm | 7 +-- code/controllers/subsystems/openturf.dm | 21 +++------ code/modules/lighting/lighting_overlay.dm | 3 ++ code/modules/lighting/lighting_source.dm | 6 +++ code/modules/multiz/openspace.dm | 47 ++++++++++++++++++- code/modules/multiz/openspace_overlay.dm | 43 ----------------- html/changelogs/lohikar-zlights.yml | 4 ++ 9 files changed, 70 insertions(+), 68 deletions(-) delete mode 100644 code/modules/multiz/openspace_overlay.dm create mode 100644 html/changelogs/lohikar-zlights.yml diff --git a/baystation12.dme b/baystation12.dme index 1042c11fd38..c202e8d62a2 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -1693,7 +1693,6 @@ #include "code\modules\multiz\basic.dm" #include "code\modules\multiz\movement.dm" #include "code\modules\multiz\openspace.dm" -#include "code\modules\multiz\openspace_overlay.dm" #include "code\modules\multiz\pipes.dm" #include "code\modules\multiz\structures.dm" #include "code\modules\multiz\turf.dm" diff --git a/code/__defines/subsystem-priority.dm b/code/__defines/subsystem-priority.dm index 0ee077a7922..a54ffbdb8fc 100644 --- a/code/__defines/subsystem-priority.dm +++ b/code/__defines/subsystem-priority.dm @@ -14,9 +14,9 @@ #define SS_INIT_SMOOTHING 6 // Object icon smoothing. Creates overlays. #define SS_INIT_ICON_UPDATE 5 // Icon update queue flush. Should run before overlays. #define SS_INIT_OVERLAY 4 // Overlay flush. -#define SS_INIT_OPENTURF 3 // Openturf flush. Should run after SSoverlay & SSicon_smooth so it copies the smoothed sprites. Causes lighting updates if starlight is enabled. -#define SS_INIT_MISC 2 // Subsystems without an explicitly set initialization order start here. -#define SS_INIT_LIGHTING 1 // Generation of lighting overlays and pre-bake. +#define SS_INIT_MISC 3 // Subsystems without an explicitly set initialization order start here. +#define SS_INIT_LIGHTING 2 // Generation of lighting overlays and pre-bake. +#define SS_INIT_OPENTURF 1 // Openturf flush. Should run after SSoverlay & SSicon_smooth so it copies the smoothed sprites. Causes lighting updates if starlight is enabled. #define SS_INIT_LOBBY 0 // Lobby timer starts here. // Something to remember when setting priorities: SS_TICKER runs before Normal, which runs before SS_BACKGROUND. diff --git a/code/controllers/subsystems/initialization/asteroid.dm b/code/controllers/subsystems/initialization/asteroid.dm index 317c6a89028..5c9419e8c7b 100644 --- a/code/controllers/subsystems/initialization/asteroid.dm +++ b/code/controllers/subsystems/initialization/asteroid.dm @@ -6,7 +6,7 @@ /datum/controller/subsystem/asteroid/Initialize(timeofday) if(config.generate_asteroid) // These values determine the specific area that the map is applied to. - // If you do not use the official Baycode moonbase map, you will need to change them. + // Create the chasms. new /datum/random_map/automata/cave_system/chasms(null,0,0,3,255,255) new /datum/random_map/automata/cave_system(null,0,0,3,255,255) @@ -15,12 +15,9 @@ new /datum/random_map/automata/cave_system/chasms(null,0,0,5,255,255) new /datum/random_map/automata/cave_system/high_yield(null,0,0,5,255,255) new /datum/random_map/automata/cave_system/chasms/surface(null,0,0,6,255,255) + // Create the deep mining ore distribution map. new /datum/random_map/noise/ore(null, 0, 0, 5, 64, 64) new /datum/random_map/noise/ore(null, 0, 0, 4, 64, 64) new /datum/random_map/noise/ore(null, 0, 0, 3, 64, 64) - var/counting_result = "Total number of chasms: [SSopenturf.openspace_turfs.len]" - admin_notice(span("danger", counting_result)) - game_log("ASGEN", counting_result) - ..() diff --git a/code/controllers/subsystems/openturf.dm b/code/controllers/subsystems/openturf.dm index 1715bf8c5ad..87ae3c72455 100644 --- a/code/controllers/subsystems/openturf.dm +++ b/code/controllers/subsystems/openturf.dm @@ -97,18 +97,12 @@ // Handle space parallax & starlight. if (T.is_above_space()) T.plane = PLANE_SPACE_BACKGROUND - if (config.starlight) - for (var/thing in RANGE_TURFS(1, T)) - var/turf/RT = thing - if (!RT.dynamic_lighting || istype(RT, /turf/simulated/open)) - continue - - T.set_light(config.starlight, 0.5) - break + /*if (config.starlight) // Openturf starlight is broken. SSlighting and SSopenturf will fight if this is un-commented-out. Maybe someone will fix it someday. + T.set_light(config.starlight, 0.5)*/ else T.plane = OPENTURF_MAX_PLANE - depth - if (config.starlight && T.light_range != 0) - T.set_light(0) + /*if (config.starlight && T.light_range != 0) + T.set_light(0)*/ // Add everything below us to the update queue. for (var/thing in T.below) @@ -167,11 +161,10 @@ OO.dir = OO.associated_atom.dir OO.appearance = OO.associated_atom OO.plane = OPENTURF_MAX_PLANE - OO.depth + OO.queued = FALSE - // Something's above us, queue it. - var/turf/oo_loc = OO.loc - if (istype(oo_loc.above)) - oo_loc.above.update_icon() + if (OO.bound_overlay) // If we have a bound overlay, queue it too. + OO.update_oo() if (no_mc_tick) CHECK_TICK diff --git a/code/modules/lighting/lighting_overlay.dm b/code/modules/lighting/lighting_overlay.dm index b96e61615d8..286eb34ab89 100644 --- a/code/modules/lighting/lighting_overlay.dm +++ b/code/modules/lighting/lighting_overlay.dm @@ -119,6 +119,9 @@ ) #endif + if (bound_overlay) + update_oo() + // Variety of overrides so the overlays don't get affected by weird things. /atom/movable/lighting_overlay/ex_act(severity) diff --git a/code/modules/lighting/lighting_source.dm b/code/modules/lighting/lighting_source.dm index d36f70ef995..3844f7cda7d 100644 --- a/code/modules/lighting/lighting_source.dm +++ b/code/modules/lighting/lighting_source.dm @@ -371,6 +371,7 @@ var/Sy = source_turf.y FOR_DVIEW(T, Ceiling(light_range), source_turf, 0) + check_t: if (light_angle && check_light_cone(T.x, T.y)) continue @@ -379,6 +380,11 @@ corners[C] = 0 turfs += T + + if (istype(T, /turf/simulated/open) && T:below) + T = T:below // Consider the turf below us as well. (Z-lights) + goto check_t + END_FOR_DVIEW LAZYINITLIST(affecting_turfs) diff --git a/code/modules/multiz/openspace.dm b/code/modules/multiz/openspace.dm index e2d09915466..ccfc2127751 100644 --- a/code/modules/multiz/openspace.dm +++ b/code/modules/multiz/openspace.dm @@ -49,7 +49,7 @@ return // check_existence returns TRUE if the overlay is valid. - if (bound_overlay.check_existence()) + if (bound_overlay.check_existence() && !bound_overlay.queued) SSopenturf.queued_overlays += bound_overlay /atom/movable/proc/get_above_oo() @@ -105,4 +105,47 @@ return ..() -// /atom/movable/openspace/overlay is in openspace_overlay.dm +// The visual representation of an atom under an openspace turf. +/atom/movable/openspace/overlay + plane = OPENTURF_MAX_PLANE + var/atom/movable/associated_atom + var/depth + var/queued = FALSE + +/atom/movable/openspace/overlay/New() + SSopenturf.openspace_overlays += src + +/atom/movable/openspace/overlay/Destroy() + SSopenturf.openspace_overlays -= src + + if (associated_atom) + associated_atom.bound_overlay = null + associated_atom = null + + return ..() + +/atom/movable/openspace/overlay/attackby(obj/item/W, mob/user) + user << span("notice", "\The [src] is too far away.") + +/atom/movable/openspace/overlay/attack_hand(mob/user as mob) + user << span("notice", "You cannot reach \the [src] from here.") + +/atom/movable/openspace/overlay/attack_generic(mob/user as mob) + user << span("notice", "You cannot reach \the [src] from here.") + +/atom/movable/openspace/overlay/forceMove(atom/dest) + . = ..() + check_existence() + +/atom/movable/openspace/overlay/Move() + . = ..() + check_existence() + +// Checks if we've moved off of an openturf. +// Returns TRUE if we're continuing to exist, FALSE if we're deleting ourselves. +/atom/movable/openspace/overlay/proc/check_existence() + if (!istype(loc, /turf/simulated/open)) + qdel(src) + return FALSE + else + return TRUE diff --git a/code/modules/multiz/openspace_overlay.dm b/code/modules/multiz/openspace_overlay.dm deleted file mode 100644 index abbacc12a1f..00000000000 --- a/code/modules/multiz/openspace_overlay.dm +++ /dev/null @@ -1,43 +0,0 @@ -// The visual representation of an atom under an openspace turf. -/atom/movable/openspace/overlay - plane = OPENTURF_MAX_PLANE - var/atom/movable/associated_atom - var/depth - -/atom/movable/openspace/overlay/New() - SSopenturf.openspace_overlays += src - -/atom/movable/openspace/overlay/Destroy() - SSopenturf.openspace_overlays -= src - - if (associated_atom) - associated_atom.bound_overlay = null - associated_atom = null - - return ..() - -/atom/movable/openspace/overlay/attackby(obj/item/W, mob/user) - user << span("notice", "\The [src] is too far away.") - -/atom/movable/openspace/overlay/attack_hand(mob/user as mob) - user << span("notice", "You cannot reach \the [src] from here.") - -/atom/movable/openspace/overlay/attack_generic(mob/user as mob) - user << span("notice", "You cannot reach \the [src] from here.") - -/atom/movable/openspace/overlay/forceMove(atom/dest) - . = ..() - check_existence() - -/atom/movable/openspace/overlay/Move() - . = ..() - check_existence() - -// Checks if we've moved off of an openturf. -// Returns TRUE if we're continuing to exist, FALSE if we're deleting ourselves. -/atom/movable/openspace/overlay/proc/check_existence() - if (!istype(loc, /turf/simulated/open)) - qdel(src) - return FALSE - else - return TRUE diff --git a/html/changelogs/lohikar-zlights.yml b/html/changelogs/lohikar-zlights.yml new file mode 100644 index 00000000000..0bf551d79be --- /dev/null +++ b/html/changelogs/lohikar-zlights.yml @@ -0,0 +1,4 @@ +author: Lohikar +delete-after: True +changes: + - tweak: "Lights will now shine through Z-holes (openturfs)."