mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2026-01-03 05:52:43 +00:00
lighting fixes and optimizations (#8292)
This commit is contained in:
@@ -10,6 +10,7 @@ SUBSYSTEM_DEF(lighting)
|
||||
var/static/list/sunlight_queue = list() //CHOMPEdit // List of turfs that are affected by sunlight
|
||||
var/static/list/sunlight_queue_active = list() //CHOMPEdit // List of turfs that need to have their sunlight updated
|
||||
var/list/planet_shandlers = list() //CHOMPEdit //Precomputed lighting values for tiles only affected by the sun
|
||||
var/list/z_to_pshandler = list() //CHOMPEdit
|
||||
|
||||
/datum/controller/subsystem/lighting/stat_entry(msg)
|
||||
msg = "L:[length(sources_queue)]|C:[length(corners_queue)]|O:[length(objects_queue)]"
|
||||
@@ -149,16 +150,37 @@ SUBSYSTEM_DEF(lighting)
|
||||
if (i)
|
||||
queue.Cut(1, i + 1)
|
||||
|
||||
/datum/controller/subsystem/lighting/proc/update_sunlight()
|
||||
for(var/datum/planet/planet in planet_shandlers)
|
||||
var/datum/planet_sunlight_handler/pshandler = planet_shandlers[planet]
|
||||
/datum/controller/subsystem/lighting/proc/update_sunlight(var/datum/planet_sunlight_handler/pshandler)
|
||||
if(istype(pshandler))
|
||||
pshandler.update_sun()
|
||||
sunlight_queue_active |= pshandler.shandlers
|
||||
else
|
||||
for(var/datum/planet/planet in planet_shandlers)
|
||||
var/datum/planet_sunlight_handler/planet_shandler = planet_shandlers[planet]
|
||||
planet_shandler.update_sun()
|
||||
sunlight_queue_active = sunlight_queue.Copy()
|
||||
|
||||
/datum/controller/subsystem/lighting/proc/get_pshandler(var/datum/planet/planet)
|
||||
/datum/controller/subsystem/lighting/proc/get_pshandler_planet(var/datum/planet/planet)
|
||||
if(!planet_shandlers[planet])
|
||||
planet_shandlers[planet] = new /datum/planet_sunlight_handler(planet)
|
||||
return planet_shandlers[planet]
|
||||
|
||||
//Wrapper for the list, because these type of lists are just awful to work with
|
||||
//Also takes care of initialization order issues
|
||||
/datum/controller/subsystem/lighting/proc/get_pshandler_z(var/z)
|
||||
if(z > z_to_pshandler.len)
|
||||
z_to_pshandler.len = z
|
||||
var/datum/planet_sunlight_handler/pshandler = z_to_pshandler[z]
|
||||
if(istype(pshandler))
|
||||
return pshandler
|
||||
else if(SSplanets && SSplanets.z_to_planet.len >= z && SSplanets.z_to_planet[z])
|
||||
var/datum/planet/P = SSplanets.z_to_planet[z]
|
||||
if(istype(P))
|
||||
pshandler = get_pshandler_planet(P)
|
||||
z_to_pshandler[z] = pshandler
|
||||
return pshandler
|
||||
|
||||
/datum/controller/subsystem/lighting
|
||||
//CHOMPEdit End
|
||||
|
||||
/datum/controller/subsystem/lighting/Recover()
|
||||
|
||||
@@ -108,7 +108,7 @@ SUBSYSTEM_DEF(planets)
|
||||
|
||||
var/new_color = P.sun["color"]
|
||||
P.sun_holder.update_color(new_color)
|
||||
SSlighting.update_sunlight() //CHOMPEdit
|
||||
SSlighting.update_sunlight(SSlighting.get_pshandler_planet(P)) //CHOMPEdit
|
||||
|
||||
/datum/controller/subsystem/planets/proc/updateTemp(var/datum/planet/P)
|
||||
//Set new temperatures
|
||||
|
||||
@@ -163,8 +163,17 @@
|
||||
space_tile.update_starlight()
|
||||
|
||||
//CHOMPEdit begin
|
||||
var/turf/simulated/sim_self = src
|
||||
if(lighting_object && istype(sim_self) && sim_self.shandler) //sanity check, but this should never be null for either of the switch cases (lighting_object will be null during initializations sometimes)
|
||||
switch(lighting_object.sunlight_only)
|
||||
if(SUNLIGHT_ONLY)
|
||||
vis_contents += sim_self.shandler.pshandler.vis_overhead
|
||||
if(SUNLIGHT_ONLY_SHADE)
|
||||
vis_contents += sim_self.shandler.pshandler.vis_shade
|
||||
|
||||
var/is_open = istype(new_turf,/turf/simulated/open)
|
||||
|
||||
|
||||
propogate_sunlight_changes(oldtype, old_density, new_turf)
|
||||
var/turf/simulated/cur_turf = src
|
||||
if(is_open != was_open)
|
||||
|
||||
@@ -11,6 +11,7 @@ var/static/list/fake_sunlight_zs = list()
|
||||
var/family = null //Allows multipe maps that are THEORETICALLY connected to use the same settings when not in a connected Z stack
|
||||
var/shared_settings //Automatically set if using the family var
|
||||
var/static/world_suns = list() //List of all the fake_suns in the world, used for checking for family members
|
||||
var/list/choice //CHOMPEdit
|
||||
|
||||
var/do_sun = TRUE
|
||||
var/do_weather = FALSE
|
||||
@@ -100,7 +101,7 @@ var/static/list/fake_sunlight_zs = list()
|
||||
|
||||
/obj/effect/fake_sun/LateInitialize()
|
||||
. = ..()
|
||||
var/list/choice
|
||||
//CHOMPEdit Removal
|
||||
if(family) //Allows one to make multiple fake_suns to use the same settings
|
||||
for(var/obj/effect/fake_sun/l in world_suns) //check all the suns that exist
|
||||
if(l.family == family && l.shared_settings) //do you have settings we need?
|
||||
|
||||
35
code/modules/lighting/lighting_fake_sun_zz_ch.dm
Normal file
35
code/modules/lighting/lighting_fake_sun_zz_ch.dm
Normal file
@@ -0,0 +1,35 @@
|
||||
//_zz is to change load order c:
|
||||
//Urgh, I hate lighting - Cadyn
|
||||
|
||||
/obj/effect/fake_sun
|
||||
var/advanced_lighting = FALSE
|
||||
|
||||
/obj/effect/fake_sun/Initialize()
|
||||
if(!advanced_lighting)
|
||||
return ..()
|
||||
do_sun = FALSE
|
||||
|
||||
//Copied code
|
||||
if(family) //Allows one to make multiple fake_suns to use the same settings
|
||||
for(var/obj/effect/fake_sun/l in world_suns) //check all the suns that exist
|
||||
if(l.family == family && l.shared_settings) //do you have settings we need?
|
||||
choice = l.shared_settings
|
||||
break
|
||||
if(!choice) //We didn't get anything from our family, let's pick something
|
||||
choice = pick(possible_light_setups)
|
||||
if(family) //Let's pass our settings on to our family
|
||||
shared_settings = choice
|
||||
if(choice["brightness"] <= LIGHTING_SOFT_THRESHOLD) // dark!
|
||||
return
|
||||
//Copied code end
|
||||
|
||||
var/datum/simple_sun/Ssun = new()
|
||||
Ssun.brightness = CLAMP01(choice["brightness"])
|
||||
Ssun.color = choice["color"]
|
||||
var/datum/planet_sunlight_handler/pshandler = new(Ssun)
|
||||
if(z > SSlighting.z_to_pshandler.len)
|
||||
SSlighting.z_to_pshandler.len = z
|
||||
SSlighting.z_to_pshandler[z] = pshandler
|
||||
SSlighting.update_sunlight(pshandler) //Queue an update for when it starts running
|
||||
|
||||
. = ..()
|
||||
@@ -20,19 +20,28 @@
|
||||
var/cache_b_shade = 0.0
|
||||
var/maxlum = 0.0
|
||||
var/maxlumshade = 0.0
|
||||
var/datum/sun_holder/sun
|
||||
var/datum/simple_sun/sun
|
||||
var/atom/movable/sun_vis_simple/vis_overhead
|
||||
var/atom/movable/sun_vis_simple/vis_shade
|
||||
var/list/shandlers = list()
|
||||
|
||||
/datum/planet_sunlight_handler/New(var/datum/planet/planet)
|
||||
/datum/planet_sunlight_handler/New(var/planet)
|
||||
. = ..()
|
||||
sun = planet.sun_holder
|
||||
var/datum/planet/P = planet
|
||||
var/datum/simple_sun/S = planet
|
||||
if(istype(P))
|
||||
sun = new /datum/simple_sun/planetary(P)
|
||||
|
||||
if(istype(S))
|
||||
sun = S
|
||||
|
||||
vis_overhead = new(null)
|
||||
vis_shade = new(null)
|
||||
|
||||
/datum/planet_sunlight_handler/proc/update_sun()
|
||||
var/brightness = sun.our_brightness * SSlighting.sun_mult
|
||||
var/list/color = hex2rgb(sun.our_color)
|
||||
sun.update()
|
||||
var/brightness = sun.brightness * SSlighting.sun_mult
|
||||
var/list/color = hex2rgb(sun.color)
|
||||
red = brightness * (color[1] / 255.0)
|
||||
green = brightness * (color[2] / 255.0)
|
||||
blue = brightness * (color[3] / 255.0)
|
||||
@@ -86,6 +95,8 @@
|
||||
cache_b_shade = round(blueshade * ., LIGHTING_ROUND_VALUE)
|
||||
#endif
|
||||
|
||||
|
||||
//Visuals we use to remove need to update overlays for tiles that have nothing but sunlight
|
||||
/atom/movable/sun_vis_simple
|
||||
icon = 'icons/effects/effects.dmi'
|
||||
icon_state = "white"
|
||||
@@ -93,3 +104,25 @@
|
||||
mouse_opacity = 0
|
||||
alpha = 255
|
||||
color = "#FFFFFF"
|
||||
|
||||
//A simplified datum for controlling the sun color/brightness
|
||||
//This allows for the sunlight system to be used outside of only planets
|
||||
/datum/simple_sun
|
||||
var/brightness = 1.0
|
||||
var/color = "#FFFFFF"
|
||||
|
||||
//Called from planet_sunlight_handler.update_sun()
|
||||
//Should update brightness and color values
|
||||
/datum/simple_sun/proc/update()
|
||||
return //Do nothing. This is meant to be overridden.
|
||||
|
||||
/datum/simple_sun/planetary
|
||||
var/datum/sun_holder/sun
|
||||
|
||||
/datum/simple_sun/planetary/New(var/datum/planet/planet)
|
||||
sun = planet.sun_holder
|
||||
|
||||
/datum/simple_sun/planetary/update()
|
||||
. = ..()
|
||||
brightness = sun.our_brightness
|
||||
color = sun.our_color
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
return INITIALIZE_HINT_LATELOAD
|
||||
|
||||
/turf/simulated/LateInitialize()
|
||||
if((SSplanets && SSplanets.z_to_planet.len >= z && SSplanets.z_to_planet[z]) && has_dynamic_lighting()) //ONLY FOR PLANET TILES IGNORE FAKESUN TILES
|
||||
if(((SSplanets && SSplanets.z_to_planet.len >= z && SSplanets.z_to_planet[z]) || SSlighting.get_pshandler_z(z)) && has_dynamic_lighting()) //Only for planet turfs or fakesuns that specify they want to use this system
|
||||
if(is_outdoors())
|
||||
var/turf/T = GetAbove(src)
|
||||
if(T && !istype(T,/turf/simulated/open))
|
||||
@@ -26,7 +26,7 @@
|
||||
shandler.manualInit()
|
||||
|
||||
/datum/sunlight_handler
|
||||
var/datum/sun_holder/sun
|
||||
var/datum/simple_sun/sun
|
||||
var/turf/simulated/holder
|
||||
var/datum/lighting_object/only_sun_object
|
||||
var/effect_str_r = 0
|
||||
@@ -51,13 +51,15 @@
|
||||
for(var/datum/lighting_corner/corner in corners)
|
||||
if(corner.sunlight == SUNLIGHT_NONE)
|
||||
corner.sunlight = SUNLIGHT_POSSIBLE
|
||||
if(SSplanets && SSplanets.z_to_planet.len >= holder.z && SSplanets.z_to_planet[holder.z])
|
||||
var/datum/planet/planet = SSplanets.z_to_planet[holder.z]
|
||||
pshandler = SSlighting.get_pshandler(planet)
|
||||
sun = planet.sun_holder
|
||||
if(SSlighting.get_pshandler_z(holder.z))
|
||||
pshandler = SSlighting.get_pshandler_z(holder.z)
|
||||
pshandler.shandlers += src
|
||||
sun = pshandler.sun
|
||||
sunlight_check()
|
||||
|
||||
/datum/sunlight_handler/proc/holder_change()
|
||||
holder.generate_missing_corners() //Somehow corners are self destructing under specific circumstances. Likely race conditions. This is slightly unoptimal but may be necessary.
|
||||
sunlight_check() //Also not optimal but made necessary by race conditions
|
||||
sunlight_update()
|
||||
for(var/dir in (cardinal + cornerdirs))
|
||||
var/turf/simulated/T = get_step(holder, dir)
|
||||
@@ -188,10 +190,10 @@
|
||||
sleepable_corners += corner.all_onlysun()
|
||||
|
||||
if(!sun)
|
||||
if(SSplanets && SSplanets.z_to_planet.len >= holder.z && SSplanets.z_to_planet[holder.z])
|
||||
var/datum/planet/planet = SSplanets.z_to_planet[holder.z]
|
||||
sun = planet.sun_holder
|
||||
pshandler = SSlighting.get_pshandler(planet)
|
||||
if(SSlighting.get_pshandler_z(holder.z))
|
||||
pshandler = SSlighting.get_pshandler_z(holder.z)
|
||||
pshandler.shandlers += src
|
||||
sun = pshandler.sun
|
||||
else
|
||||
return
|
||||
|
||||
@@ -222,6 +224,11 @@
|
||||
only_sun_object = null
|
||||
|
||||
if(only_sun_object)
|
||||
//Edge cases but needed to make sure that the correct overlay is used in the case that all corners switch from shade to overhead or vice versa between updates
|
||||
if(only_sun_object.sunlight_only == SUNLIGHT_ONLY_SHADE && sunlight == SUNLIGHT_OVERHEAD)
|
||||
only_sun_object.set_sunonly(SUNLIGHT_ONLY, pshandler)
|
||||
else if(only_sun_object.sunlight_only == SUNLIGHT_ONLY && sunlight == SUNLIGHT_CURRENT)
|
||||
only_sun_object.set_sunonly(SUNLIGHT_ONLY_SHADE, pshandler)
|
||||
only_sun_object.update_sun()
|
||||
|
||||
for(var/datum/lighting_corner/corner in only_sun)
|
||||
@@ -241,8 +248,8 @@
|
||||
sunlight_mult = 0.6
|
||||
if(SUNLIGHT_OVERHEAD)
|
||||
sunlight_mult = 1.0
|
||||
var/brightness = sun.our_brightness * sunlight_mult * SSlighting.sun_mult
|
||||
var/list/color = hex2rgb(sun.our_color)
|
||||
var/brightness = sun.brightness * sunlight_mult * SSlighting.sun_mult
|
||||
var/list/color = hex2rgb(sun.color)
|
||||
var/red = brightness * (color[1] / 255.0)
|
||||
var/green = brightness * (color[2] / 255.0)
|
||||
var/blue = brightness * (color[3] / 255.0)
|
||||
|
||||
@@ -225,6 +225,7 @@
|
||||
// -- Objects -- //
|
||||
/obj/effect/fake_sun/always_day
|
||||
name = "fake sun"
|
||||
advanced_lighting = TRUE
|
||||
desc = "Deletes itself, but first updates all the lighting on outdoor turfs to cool colors."
|
||||
possible_light_setups = list(
|
||||
|
||||
|
||||
@@ -2818,6 +2818,7 @@
|
||||
#include "code\modules\lighting\lighting_atom.dm"
|
||||
#include "code\modules\lighting\lighting_corner.dm"
|
||||
#include "code\modules\lighting\lighting_fake_sun_vr.dm"
|
||||
#include "code\modules\lighting\lighting_fake_sun_zz_ch.dm"
|
||||
#include "code\modules\lighting\lighting_overlay.dm"
|
||||
#include "code\modules\lighting\lighting_setup.dm"
|
||||
#include "code\modules\lighting\lighting_source.dm"
|
||||
|
||||
Reference in New Issue
Block a user