mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
lighting fixes and optimizations (#8292)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user