Skip to content

Commit

Permalink
Merge pull request #4756 from out-of-phaze/fix/lighting-dupe
Browse files Browse the repository at this point in the history
Fix lighting overlays being created multiple times per turf
  • Loading branch information
MistakeNot4892 authored Jan 20, 2025
2 parents 33074a8 + 62472e1 commit d4847b8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 52 deletions.
10 changes: 9 additions & 1 deletion code/controllers/subsystems/ambience.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ SUBSYSTEM_DEF(ambience)
/// Whether this turf has been queued for an ambient lighting update.
var/ambience_queued = FALSE

/turf/proc/shows_outdoor_ambience()
return is_outside()

// Starlight can't be blocked by stuff above a space turf.
// TODO: decide if open sky deserves the same treatment
/turf/space/shows_outdoor_ambience()
return TRUE

/turf/proc/update_ambient_light_from_z_or_area()

// If we're not outside, we don't show ambient light.
clear_ambient_light() // TODO: fix the delta issues resulting in burn-in so this can be run only when needed

var/ambient_light_modifier
// If we're indoors because of our area, OR we're outdoors and not exposed to the weather, get interior ambience.
var/outsideness = is_outside()
var/outsideness = shows_outdoor_ambience()
if((!outsideness && is_outside == OUTSIDE_AREA) || (outsideness && get_weather_exposure() != WEATHER_EXPOSED))
var/area/A = get_area(src)
if(isnull(A?.interior_ambient_light_modifier))
Expand Down
27 changes: 6 additions & 21 deletions code/controllers/subsystems/lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ SUBSYSTEM_DEF(lighting)

// Generate overlays.
for (var/zlevel = 1 to world.maxz)
overlaycount += InitializeZlev(zlevel)
var/datum/level_data/level = SSmapping.levels_by_z[zlevel]
for (var/turf/tile as anything in block(1, 1, zlevel, level.level_max_width, level.level_max_height)) // include TRANSITIONEDGE turfs
if (TURF_IS_DYNAMICALLY_LIT_UNSAFE(tile))
tile.lighting_build_overlay()
overlaycount++
CHECK_TICK

admin_notice(SPAN_DANGER("Created [overlaycount] lighting overlays in [(REALTIMEOFDAY - starttime)/10] seconds."), R_DEBUG)

Expand All @@ -71,26 +76,6 @@ SUBSYSTEM_DEF(lighting)

..()

/datum/controller/subsystem/lighting/proc/InitializeZlev(zlev)
for (var/thing in Z_ALL_TURFS(zlev))
var/turf/T = thing
if (TURF_IS_DYNAMICALLY_LIT_UNSAFE(T) && !T.lighting_overlay) // Can't assume that one hasn't already been created on bay/neb.
new /atom/movable/lighting_overlay(T)
. += 1
if (T.ambient_light)
T.generate_missing_corners() // Forcibly generate corners.

CHECK_TICK

// It's safe to pass a list of non-turfs to this list - it'll only check turfs.
/datum/controller/subsystem/lighting/proc/InitializeTurfs(list/targets)
for (var/turf/T in (targets || world))
if (TURF_IS_DYNAMICALLY_LIT_UNSAFE(T))
T.lighting_build_overlay()

// If this isn't here, BYOND will set-background us.
CHECK_TICK

/datum/controller/subsystem/lighting/fire(resumed = FALSE, no_mc_tick = FALSE)
if (!resumed)
processed_lights = 0
Expand Down
2 changes: 1 addition & 1 deletion code/game/turfs/turf_changing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
if ((old_opacity != opacity) || (tidlu != old_dynamic_lighting) || force_lighting_update)
reconsider_lights()

if (tidlu != old_dynamic_lighting)
if (tidlu != old_dynamic_lighting && SSlighting.initialized) // don't fuck with lighting before lighting flush
if (tidlu)
lighting_build_overlay()
else
Expand Down
29 changes: 9 additions & 20 deletions code/modules/lighting/lighting_turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,17 @@
return

// Unlit turfs will have corners if they have a lit neighbor -- don't generate corners for them, but do update them if they're there.
// if (!corners)
// var/force_build_corners = FALSE
// for (var/turf/T as anything in RANGE_TURFS(src, 1))
// if (TURF_IS_DYNAMICALLY_LIT_UNSAFE(T))
// force_build_corners = TRUE
// break

// if (force_build_corners || TURF_IS_DYNAMICALLY_LIT_UNSAFE(src))
// generate_missing_corners()
// else
// return

// still inefficient :(
if(!corners || !lighting_corners_initialised)
/* Commented out pending working out why this doesn't work properly on Neb.
if(TURF_IS_DYNAMICALLY_LIT_UNSAFE(src))
if (!corners)
var/force_build_corners = FALSE
for (var/turf/T as anything in RANGE_TURFS(src, 1))
if (TURF_IS_DYNAMICALLY_LIT_UNSAFE(T))
force_build_corners = TRUE
break

if (force_build_corners || TURF_IS_DYNAMICALLY_LIT_UNSAFE(src))
generate_missing_corners()
else
return
*/
generate_missing_corners()

// This list can contain nulls on things like space turfs -- they only have their neighbors' corners.
for (var/datum/lighting_corner/C in corners)
Expand Down Expand Up @@ -126,8 +116,7 @@
// Builds a lighting overlay for us, but only if our area is dynamic.
/turf/proc/lighting_build_overlay(now = FALSE)
if (lighting_overlay)
return // shrug
// CRASH("Attempted to create lighting_overlay on tile that already had one.")
CRASH("Attempted to create lighting_overlay on tile that already had one.")

if (TURF_IS_DYNAMICALLY_LIT_UNSAFE(src))
if (!lighting_corners_initialised || !corners)
Expand Down
4 changes: 0 additions & 4 deletions code/modules/maps/_map_template.dm
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@
for(var/z_index = bounds[MAP_MINZ] to bounds[MAP_MAXZ])
var/datum/level_data/level = SSmapping.levels_by_z[z_index]
level.after_template_load(src)
if(SSlighting.initialized)
SSlighting.InitializeZlev(z_index)
Master.StopLoadingMap()
log_game("Z-level [name] loaded at [x],[y],[world.maxz]")
loaded++
Expand Down Expand Up @@ -225,8 +223,6 @@
init_atoms(atoms_to_initialise)
init_shuttles(shuttle_state, map_hash, initialized_areas_by_type)
after_load()
if (SSlighting.initialized)
SSlighting.InitializeTurfs(atoms_to_initialise) // Hopefully no turfs get placed on new coords by SSatoms.
Master.StopLoadingMap()

log_game("[name] loaded at at [T.x],[T.y],[T.z]")
Expand Down
2 changes: 0 additions & 2 deletions code/modules/maps/reader.dm
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ var/global/dmm_suite/preloader/_preloader = new
maxx = max(maxx, xcrd)
++xcrd
--ycrd
if (zexpansion && SSlighting.initialized)
SSlighting.InitializeZlev(zcrd)

bounds[MAP_MAXX] = clamp(max(bounds[MAP_MAXX], cropMap ? min(maxx, world.maxx) : maxx), x_lower, x_upper)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@

//Run the finishing touch on all loaded levels
for(var/datum/level_data/LD in new_level_data)
LD.after_template_load(src)
if(SSlighting.initialized)
SSlighting.InitializeZlev(LD.level_z)
//This is done in parent if we have mappaths, so skip it unless we don't have any
if(!length(mappaths))
LD.after_template_load(src)
log_game("Z-level '[LD.name]'(planetoid:'[name]') loaded at [LD.level_z]")
loaded++
return WORLD_CENTER_TURF(world.maxz)
Expand Down

0 comments on commit d4847b8

Please sign in to comment.