From 0d7f95bf25764844f326a683aaae7ba6e554fc64 Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Thu, 24 Jun 2021 17:39:40 -0400 Subject: [PATCH] Probably fixes problems with darksight outdoors --- code/controllers/subsystems/planets.dm | 2 +- code/modules/planet/planet.dm | 5 ++-- code/modules/planet/sif.dm | 2 +- code/modules/planet/sun.dm | 32 ++++++++++++++++++++++---- code/modules/planet/virgo3b_vr.dm | 2 +- code/modules/planet/virgo4_vr.dm | 2 +- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/code/controllers/subsystems/planets.dm b/code/controllers/subsystems/planets.dm index c9a4a2db43c..16fbe59d3a6 100644 --- a/code/controllers/subsystems/planets.dm +++ b/code/controllers/subsystems/planets.dm @@ -104,7 +104,7 @@ SUBSYSTEM_DEF(planets) /datum/controller/subsystem/planets/proc/updateSunlight(var/datum/planet/P) var/new_brightness = P.sun["brightness"] - P.sun_holder.update_brightness(new_brightness) + P.sun_holder.update_brightness(new_brightness, P.planet_floors) var/new_color = P.sun["color"] P.sun_holder.update_color(new_color) diff --git a/code/modules/planet/planet.dm b/code/modules/planet/planet.dm index 293a64c9fbd..b7fd464c9d7 100644 --- a/code/modules/planet/planet.dm +++ b/code/modules/planet/planet.dm @@ -13,7 +13,7 @@ var/datum/sun_holder/sun_holder var/sun_position = 0 // 0 means midnight, 1 means noon. - var/list/sun = list("range","brightness","color") + var/list/sun = list("brightness","color") var/list/expected_z_levels = list() var/turf/unsimulated/wall/planetary/planetary_wall_type = /turf/unsimulated/wall/planetary @@ -62,8 +62,7 @@ if(weather_holder) weather_holder.process() -/datum/planet/proc/update_sun_deferred(var/new_range, var/new_brightness, var/new_color) - sun["range"] = new_range +/datum/planet/proc/update_sun_deferred(var/new_brightness, var/new_color) sun["brightness"] = new_brightness sun["color"] = new_color needs_work |= PLANET_PROCESS_SUN diff --git a/code/modules/planet/sif.dm b/code/modules/planet/sif.dm index 96cfb548ac0..af6f632bdc5 100644 --- a/code/modules/planet/sif.dm +++ b/code/modules/planet/sif.dm @@ -95,7 +95,7 @@ var/datum/planet/sif/planet_sif = null new_color = rgb(new_r, new_g, new_b) spawn(1) - update_sun_deferred(2, new_brightness, new_color) + update_sun_deferred(new_brightness, new_color) // We're gonna pretend there are 32 hours in a Sif day instead of 32.64 for the purposes of not losing sanity. We lose 38m 24s but the alternative is a path to madness. /datum/time/sif diff --git a/code/modules/planet/sun.dm b/code/modules/planet/sun.dm index 55f739d2178..d2b61a389ee 100644 --- a/code/modules/planet/sun.dm +++ b/code/modules/planet/sun.dm @@ -2,26 +2,50 @@ var/atom/movable/sun_visuals/sun = new var/datum/planet/our_planet + var/our_color = "#FFFFFF" + var/our_brightness = 1.0 + /datum/sun_holder/New(var/source) our_planet = source /datum/sun_holder/proc/update_color(new_color) - sun.color = new_color - -/datum/sun_holder/proc/update_brightness(new_brightness) - sun.alpha = round(CLAMP01(new_brightness)*255,1) + // Doesn't save much work, but might save a smidge of client work + if(our_color == new_color) + return + + // Visible change + sun.color = our_color = new_color +/datum/sun_holder/proc/update_brightness(new_brightness, list/turfs) + // Doesn't save much work, but might save a smidge of client work + if(our_brightness == new_brightness) + return + + // Store the old for math + . = our_brightness + our_brightness = new_brightness + + // Visible change + sun.alpha = round(CLAMP01(our_brightness)*255,1) + + // Update dynamic lumcount so darksight and stuff works + var/difference = . - our_brightness + for(var/turf/T as anything in turfs) + T.dynamic_lumcount -= difference + /datum/sun_holder/proc/apply_to_turf(turf/T) if(sun in T.vis_contents) warning("Was asked to add fake sun to [T.x], [T.y], [T.z] despite already having us in it's vis contents") return T.vis_contents += sun + T.dynamic_lumcount += our_brightness /datum/sun_holder/proc/remove_from_turf(turf/T) if(!(sun in T.vis_contents)) warning("Was asked to remove fake sun from [T.x], [T.y], [T.z] despite it not having us in it's vis contents") return T.vis_contents -= sun + T.dynamic_lumcount -= our_brightness /datum/sun_holder/proc/rainbow() var/end = world.time + 30 SECONDS diff --git a/code/modules/planet/virgo3b_vr.dm b/code/modules/planet/virgo3b_vr.dm index f9cc58ca0ce..2700b69805f 100644 --- a/code/modules/planet/virgo3b_vr.dm +++ b/code/modules/planet/virgo3b_vr.dm @@ -94,7 +94,7 @@ var/datum/planet/virgo3b/planet_virgo3b = null new_color = rgb(new_r, new_g, new_b) spawn(1) - update_sun_deferred(2, new_brightness, new_color) + update_sun_deferred(new_brightness, new_color) /datum/weather_holder/virgo3b diff --git a/code/modules/planet/virgo4_vr.dm b/code/modules/planet/virgo4_vr.dm index 3909b9e6cd7..6ac748f4218 100644 --- a/code/modules/planet/virgo4_vr.dm +++ b/code/modules/planet/virgo4_vr.dm @@ -92,7 +92,7 @@ var/datum/planet/virgo4/planet_virgo4 = null new_color = rgb(new_r, new_g, new_b) spawn(1) - update_sun_deferred(2, new_brightness, new_color) + update_sun_deferred(new_brightness, new_color) /datum/weather_holder/virgo4