Files
Bubberstation/code/modules/lighting/lighting_area.dm
T
LemonInTheDark 5b4ba051a0 Builds logic that manages turfs contained inside an area (#70966)
## About The Pull Request

Area contents isn't a real list, instead it involves filtering
everything in world
This is slow, and something we should have better support for.

So instead, lets manage a list of turfs inside our area. This is simple,
since we already move turfs by area contents anyway

This should speed up the uses I've found, and opens us up to using this
pattern more often, which should make dev work easier.

By nature this is a tad fragile, so I've added a unit test to double
check my work

Rather then instantly removing turfs from the contained_turfs list, we
enter them into a list of turfs to pull out, later.
Then we just use a getter for contained_turfs rather then a var read

This means we don't need to generate a lot of usage off removing turf by
turf from space, and can instead do it only when we need to

I've added a subsystem to manage this process as well, to ensure we
don't get any out of memory errors. It goes entry by entry, ensuring we
get no overtime.
This allows me to keep things like space clean, while keeping high
amounts of usage on a sepearate subsystem when convienient

As a part of this goal of keeping space's churn as low as possible, I've
setup code to ensure we do not add turfs to areas during a z level
increment adjacent mapload. this saves a LOT of time, but is a tad
messy

I've expanded where we use contained_turfs, including into some cases
that filter for objects in areas. need to see if this is sane or not.

Builds sortedAreas on demand, caching until we mark the cache as
violated

It's faster, and it also has the same behavior

I'm not posting speed changes cause frankly they're gonna be a bit
scattered and I'm scared to.
@Mothblocks if you'd like I can look into it. I think it'll pay for
itself just off `reg_in_areas_in_z` (I looked into it. it's really hard
to tell, sometimes it's a bit slower (0.7), sometimes it's 2 seconds
(0.5 if you use the old master figure) faster. life is pain.)

## Why It's Good For The Game

Less stupid, more flexible, more speed

Co-authored-by: san7890 <the@san7890.com>
2022-11-04 20:13:54 -07:00

81 lines
2.9 KiB
Plaintext

/area
luminosity = 1
///List of mutable appearances we underlay to show light
///In the form plane offset + 1 -> appearance to use
var/list/mutable_appearance/lighting_effects = null
///Whether this area has a currently active base lighting, bool
var/area_has_base_lighting = FALSE
///alpha 0-255 of lighting_effect and thus baselighting intensity
var/base_lighting_alpha = 0
///The colour of the light acting on this area
var/base_lighting_color = COLOR_WHITE
/area/proc/set_base_lighting(new_base_lighting_color = -1, new_alpha = -1)
if(base_lighting_alpha == new_alpha && base_lighting_color == new_base_lighting_color)
return FALSE
if(new_alpha != -1)
base_lighting_alpha = new_alpha
if(new_base_lighting_color != -1)
base_lighting_color = new_base_lighting_color
update_base_lighting()
return TRUE
/area/vv_edit_var(var_name, var_value)
switch(var_name)
if(NAMEOF(src, base_lighting_color))
set_base_lighting(new_base_lighting_color = var_value)
return TRUE
if(NAMEOF(src, base_lighting_alpha))
set_base_lighting(new_alpha = var_value)
return TRUE
if(NAMEOF(src, static_lighting))
if(!static_lighting)
create_area_lighting_objects()
else
remove_area_lighting_objects()
return ..()
/area/proc/update_base_lighting()
if(!area_has_base_lighting && (!base_lighting_alpha || !base_lighting_color))
return
if(!area_has_base_lighting)
add_base_lighting()
return
remove_base_lighting()
if(base_lighting_alpha && base_lighting_color)
add_base_lighting()
/area/proc/remove_base_lighting()
var/list/z_offsets = SSmapping.z_level_to_plane_offset
for(var/turf/T as anything in get_contained_turfs())
if(z_offsets[T.z])
T.cut_overlay(lighting_effects[z_offsets[T.z] + 1])
cut_overlay(lighting_effects[1])
QDEL_LIST(lighting_effects)
area_has_base_lighting = FALSE
/area/proc/add_base_lighting()
lighting_effects = list()
for(var/offset in 0 to SSmapping.max_plane_offset)
var/mutable_appearance/lighting_effect = mutable_appearance('icons/effects/alphacolors.dmi', "white")
SET_PLANE_W_SCALAR(lighting_effect, LIGHTING_PLANE, offset)
lighting_effect.layer = LIGHTING_PRIMARY_LAYER
lighting_effect.blend_mode = BLEND_ADD
lighting_effect.alpha = base_lighting_alpha
lighting_effect.color = base_lighting_color
lighting_effect.appearance_flags = RESET_TRANSFORM | RESET_ALPHA | RESET_COLOR
lighting_effects += lighting_effect
add_overlay(lighting_effects[1])
var/list/z_offsets = SSmapping.z_level_to_plane_offset
for(var/turf/T as anything in get_contained_turfs())
T.luminosity = 1
// This outside loop is EXTREMELY hot because it's run by space tiles. Don't want no part in that
// We will only add overlays to turfs not on the first z layer, because that's a significantly lesser portion
// And we need to do them separate, or lighting will go fuckey
if(z_offsets[T.z])
T.add_overlay(lighting_effects[z_offsets[T.z] + 1])
area_has_base_lighting = TRUE