lighting fixes and optimizations (#8292)

This commit is contained in:
Cadyn
2024-04-22 23:13:25 -07:00
committed by GitHub
parent e694b1aea7
commit e1bffd71be
9 changed files with 133 additions and 24 deletions

View File

@@ -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 = sunlight_queue.Copy()
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()

View File

@@ -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