mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
Planetary Lighting Optimization Attempt
Changes how lighting is applied to the Surface. The current method works by making every tile glow in a specific color and intensity. The issue is that when it is time to change the color/intensity, it can take the light controller a considerable amount of time for it to update every tile (estimated to be around 14,000 tiles), which can take a minute or two for the lighting controller to finish. New method is to have a special light source for the surface, with different properties to the 'regular' light source that most things use for making light. The special version doesn't care about line of sight or lighting falloff. This special light source is applied to a series of invisible 'sun' objects that get generated as the planetary controller gets created. When the lights need to change, the lighting controller has to change a much smaller group of objects instead of literally every outdoor tile.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
var/datum/light_source/light
|
||||
var/list/light_sources
|
||||
var/light_datum_type = /datum/light_source
|
||||
|
||||
// Nonsensical value for l_color default, so we can detect if it gets set to null.
|
||||
#define NONSENSICAL_VALUE -99999
|
||||
@@ -41,7 +42,7 @@
|
||||
if(light)
|
||||
light.update(.)
|
||||
else
|
||||
light = new /datum/light_source(src, .)
|
||||
light = new light_datum_type(src, .)
|
||||
|
||||
/atom/New()
|
||||
. = ..()
|
||||
@@ -109,3 +110,19 @@
|
||||
/obj/item/dropped()
|
||||
. = ..()
|
||||
update_light()
|
||||
|
||||
/obj/effect/sun
|
||||
name = "sun"
|
||||
desc ="SUNTHESUNTHESUNTHESUNTHE"
|
||||
icon = 'icons/effects/effects.dmi'
|
||||
icon_state = "sun"
|
||||
invisibility = 100
|
||||
anchored = TRUE
|
||||
light_datum_type = /datum/light_source/sun
|
||||
light_color = "#FFFFFF"
|
||||
light_range = 65
|
||||
|
||||
/obj/effect/sun/Destroy(force = FALSE)
|
||||
if(!force)
|
||||
return QDEL_HINT_LETMELIVE
|
||||
return ..()
|
||||
@@ -284,6 +284,106 @@
|
||||
C.affecting -= src
|
||||
effect_str -= C
|
||||
|
||||
#define APPLY_CORNER_NO_FALLOFF(C) \
|
||||
. = 1; \
|
||||
. *= light_power; \
|
||||
\
|
||||
effect_str[C] = .; \
|
||||
\
|
||||
C.update_lumcount \
|
||||
( \
|
||||
. * applied_lum_r, \
|
||||
. * applied_lum_g, \
|
||||
. * applied_lum_b \
|
||||
);
|
||||
|
||||
// Special snowflake subtype used to light the Surface.
|
||||
// The big differences is that this ignores FOV calculations (and as such doesn't use DVIEW) and instead applies it to all
|
||||
// 'outdoor' turfs within range.
|
||||
// Another difference is it has no falloff, meaning that it creates a big flat square instead of a circle that gets darker towards the edges.
|
||||
/datum/light_source/sun
|
||||
|
||||
/datum/light_source/sun/recalc_corner(var/datum/lighting_corner/C)
|
||||
if(effect_str.Find(C)) // Already have one.
|
||||
REMOVE_CORNER(C)
|
||||
|
||||
APPLY_CORNER_NO_FALLOFF(C)
|
||||
|
||||
/datum/light_source/sun/apply_lum()
|
||||
var/static/update_gen = 1
|
||||
applied = 1
|
||||
|
||||
// Keep track of the last applied lum values so that the lighting can be reversed
|
||||
applied_lum_r = lum_r
|
||||
applied_lum_g = lum_g
|
||||
applied_lum_b = lum_b
|
||||
|
||||
for(var/thing in RANGE_TURFS(light_range, source_turf) )
|
||||
var/turf/T = thing
|
||||
if(!T.lighting_corners_initialised)
|
||||
T.generate_missing_corners()
|
||||
|
||||
if(!T.outdoors)
|
||||
continue
|
||||
|
||||
for(var/datum/lighting_corner/C in T.get_corners())
|
||||
if(C.update_gen == update_gen)
|
||||
continue
|
||||
|
||||
C.update_gen = update_gen
|
||||
C.affecting += src
|
||||
|
||||
if(!C.active)
|
||||
effect_str[C] = 0
|
||||
continue
|
||||
|
||||
APPLY_CORNER_NO_FALLOFF(C)
|
||||
|
||||
if(!T.affecting_lights)
|
||||
T.affecting_lights = list()
|
||||
|
||||
T.affecting_lights += src
|
||||
affecting_turfs += T
|
||||
|
||||
update_gen++
|
||||
|
||||
/datum/light_source/sun/smart_vis_update()
|
||||
var/list/datum/lighting_corner/corners = list()
|
||||
var/list/turf/turfs = list()
|
||||
|
||||
for(var/thing in RANGE_TURFS(light_range, source_turf) )
|
||||
var/turf/T = thing
|
||||
if(!T.lighting_corners_initialised)
|
||||
T.generate_missing_corners()
|
||||
corners |= T.get_corners()
|
||||
turfs += T
|
||||
|
||||
var/list/L = turfs - affecting_turfs // New turfs, add us to the affecting lights of them.
|
||||
affecting_turfs += L
|
||||
for(var/turf/T in L)
|
||||
if(!T.affecting_lights)
|
||||
T.affecting_lights = list(src)
|
||||
else
|
||||
T.affecting_lights += src
|
||||
|
||||
L = affecting_turfs - turfs // Now-gone turfs, remove us from the affecting lights.
|
||||
affecting_turfs -= L
|
||||
for(var/turf/T in L)
|
||||
T.affecting_lights -= src
|
||||
|
||||
for(var/datum/lighting_corner/C in corners - effect_str) // New corners
|
||||
C.affecting += src
|
||||
if(!C.active)
|
||||
effect_str[C] = 0
|
||||
continue
|
||||
|
||||
APPLY_CORNER_NO_FALLOFF(C)
|
||||
|
||||
for(var/datum/lighting_corner/C in effect_str - corners) // Old, now gone, corners.
|
||||
REMOVE_CORNER(C)
|
||||
C.affecting -= src
|
||||
effect_str -= C
|
||||
|
||||
#undef effect_update
|
||||
#undef LUM_FALLOFF
|
||||
#undef REMOVE_CORNER
|
||||
|
||||
Reference in New Issue
Block a user