Minor lighting performance tweaks (#3298)

changes:

Sunlight prebake now happens during MC Initialize instead of in the lobby.
Openturf no longer ticks in the lobby.
Openturf has been promoted to a normal SS, from SS_BACKGROUND.
Lighting no longer ticks in the lobby.
Inlined directional lighting's coordinate filter.
Directional lighting wedge caching now properly works with face-direction.
This commit is contained in:
Lohikar
2017-08-20 06:08:25 -05:00
committed by Erki
parent 1532c692aa
commit 9dd650b7a9
5 changed files with 26 additions and 44 deletions

View File

@@ -46,7 +46,7 @@
var/needs_update = LIGHTING_NO_UPDATE
/datum/light_source/New(var/atom/owner, var/atom/top)
/datum/light_source/New(atom/owner, atom/top)
source_atom = owner // Set our new owner.
LAZYADD(source_atom.light_sources, src)
@@ -102,7 +102,7 @@
}
// This proc will cause the light source to update the top atom, and add itself to the update queue.
/datum/light_source/proc/update(var/atom/new_top_atom)
/datum/light_source/proc/update(atom/new_top_atom)
// This top atom is different.
if (new_top_atom && new_top_atom != top_atom)
if(top_atom != source_atom) // Remove ourselves from the light sources of that top atom.
@@ -111,10 +111,7 @@
top_atom = new_top_atom
if (top_atom != source_atom)
if(!top_atom.light_sources)
top_atom.light_sources = list()
top_atom.light_sources += src // Add ourselves to the light sources of our new top atom.
LAZYADD(top_atom.light_sources, src) // Add ourselves to the light sources of our new top atom.
//L_PROF(source_atom, "source_update")
@@ -156,15 +153,16 @@
/datum/light_source/proc/update_angle()
var/turf/T = get_turf(top_atom)
// Don't do anything if nothing is different, trig ain't free.
if (T.x == cached_origin_x && T.y == cached_origin_y && old_direction == top_atom.dir)
return
if (istype(top_atom, /mob) && top_atom:facing_dir)
old_direction = top_atom:facing_dir
else
old_direction = top_atom.dir
// Don't do anything if nothing is different, trig ain't free.
if (T.x == cached_origin_x && T.y == cached_origin_y && old_direction == top_atom.dir)
return
var/turf/front = get_step(T, old_direction)
facing_opaque = (front && front.has_opaque_atom)
@@ -209,25 +207,11 @@
targ_sign = PSEUDO_WEDGE(limit_a_x, limit_a_y, limit_b_x, limit_b_y) > 0
#undef ARBITRARY_NUMBER
// I know this is 2D, calling it a cone anyways. Fuck the system.
// Returns true if the test point is NOT inside the cone.
// Make sure update_angle() is called first if the light's loc or dir have changed.
/datum/light_source/proc/check_light_cone(var/test_x, var/test_y)
test_x -= test_x_offset
test_y -= test_y_offset
var/at = PSEUDO_WEDGE(limit_a_x, limit_a_y, test_x, test_y)
var/tb = PSEUDO_WEDGE(test_x, test_y, limit_b_x, limit_b_y)
// if the signs of both at and tb are NOT the same, the point is NOT within the cone.
return (((at > 0) != targ_sign) || ((tb > 0) != targ_sign))
#undef POLAR_TO_CART_X
#undef POLAR_TO_CART_Y
#undef PSEUDO_WEDGE
#undef MINMAX
/datum/light_source/proc/remove_lum(var/now = FALSE)
/datum/light_source/proc/remove_lum(now = FALSE)
applied = FALSE
var/thing
@@ -245,7 +229,7 @@
effect_str = null
/datum/light_source/proc/recalc_corner(var/datum/lighting_corner/C, var/now = FALSE)
/datum/light_source/proc/recalc_corner(datum/lighting_corner/C, now = FALSE)
LAZYINITLIST(effect_str)
if (effect_str[C]) // Already have one.
REMOVE_CORNER(C,now)
@@ -329,13 +313,20 @@
var/list/Tcorners
var/Sx = source_turf.x
var/Sy = source_turf.y
var/use_reduced = (light_angle && facing_opaque)
var/actual_range = use_reduced ? light_range * LIGHTING_BLOCKED_FACTOR : light_range
var/actual_range = (light_angle && facing_opaque) ? light_range * LIGHTING_BLOCKED_FACTOR : light_range
var/test_x
var/test_y
FOR_DVIEW(T, Ceiling(actual_range), source_turf, 0)
check_t:
if (light_angle && !facing_opaque && check_light_cone(T.x, T.y))
continue
if (light_angle && !facing_opaque) // Directional lighting coordinate filter.
test_x = T.x - test_x_offset
test_y = T.y - test_y_offset
// if the signs of both of these are NOT the same, the point is NOT within the cone.
if (((PSEUDO_WEDGE(limit_a_x, limit_a_y, test_x, test_y) > 0) != targ_sign) || ((PSEUDO_WEDGE(test_x, test_y, limit_b_x, limit_b_y) > 0) != targ_sign))
continue
if (T.dynamic_lighting || T.light_sources)
Tcorners = T.corners
@@ -427,3 +418,4 @@
#undef QUEUE_UPDATE
#undef DO_UPDATE
#undef INTELLIGENT_UPDATE
#undef PSEUDO_WEDGE