mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 10:21:11 +00:00
Implements soft lighting & adds a minor optimization to light source code.
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
|
||||
// These two lists might just be an assoc list.
|
||||
var/list/effect_str // List used to store how much we're affecting turfs.
|
||||
var/list/effect_turf // List of turfs we're affecting.
|
||||
|
||||
var/applied // Whether we have applied our light yet or not.
|
||||
|
||||
@@ -52,7 +51,6 @@
|
||||
parse_light_color()
|
||||
|
||||
effect_str = list()
|
||||
effect_turf = list()
|
||||
|
||||
update()
|
||||
|
||||
@@ -186,7 +184,7 @@
|
||||
. *= light_power; \
|
||||
. = round(., LIGHTING_ROUND_VALUE); \
|
||||
\
|
||||
effect_str += .; \
|
||||
effect_str[T] = .; \
|
||||
\
|
||||
T.lighting_overlay.update_lumcount \
|
||||
( \
|
||||
@@ -197,7 +195,7 @@
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
effect_str += 0; \
|
||||
effect_str[T] = 0; \
|
||||
} \
|
||||
\
|
||||
if(!T.affecting_lights) \
|
||||
@@ -206,12 +204,11 @@
|
||||
} \
|
||||
\
|
||||
T.affecting_lights += src; \
|
||||
effect_turf += T; \
|
||||
|
||||
// Removes a turf from effect.
|
||||
// Opposite of the above.
|
||||
|
||||
#define REMOVE_TURF(T, i) \
|
||||
#define REMOVE_TURF(T) \
|
||||
if(T.affecting_lights) \
|
||||
{ \
|
||||
T.affecting_lights -= src; \
|
||||
@@ -219,7 +216,7 @@
|
||||
\
|
||||
if(T.lighting_overlay) \
|
||||
{ \
|
||||
var/str = effect_str[i]; \
|
||||
var/str = effect_str[T]; \
|
||||
T.lighting_overlay.update_lumcount \
|
||||
( \
|
||||
-str * applied_lum_r, \
|
||||
@@ -247,14 +244,10 @@
|
||||
/datum/light_source/proc/remove_lum()
|
||||
applied = 0
|
||||
|
||||
var/i = 1
|
||||
for(var/turf/T in effect_turf)
|
||||
REMOVE_TURF(T, i)
|
||||
|
||||
i++
|
||||
for(var/turf/T in effect_str)
|
||||
REMOVE_TURF(T)
|
||||
|
||||
effect_str.Cut()
|
||||
effect_turf.Cut()
|
||||
|
||||
// Smartly updates the lighting, only removes lum from and adds lum to turfs that actually got changed.
|
||||
// This is for lights that need to reconsider due to nearby opacity changes.
|
||||
@@ -264,34 +257,27 @@
|
||||
view += T //Filter out turfs.
|
||||
|
||||
// This is the part where we calculate new turfs (if any)
|
||||
var/list/new_turfs = view - effect_turf // This will result with all the tiles that are added.
|
||||
var/list/new_turfs = view - effect_str // This will result with all the tiles that are added.
|
||||
for(var/turf/T in new_turfs)
|
||||
APPLY_TURF(T)
|
||||
|
||||
var/list/old_turfs = effect_turf - view
|
||||
var/list/old_turfs = effect_str - view
|
||||
for(var/turf/T in old_turfs)
|
||||
// Insert not-so-huge copy paste from remove_lum().
|
||||
var/idx = effect_turf.Find(T) // Get the index, luckily Find() is cheap in small lists like this. (with small I mean under a couple thousand len)
|
||||
REMOVE_TURF(T, idx)
|
||||
REMOVE_TURF(T)
|
||||
|
||||
effect_turf.Cut(idx, idx + 1)
|
||||
effect_str.Cut(idx, idx + 1)
|
||||
effect_str -= T
|
||||
|
||||
// Calculates lighting for an individual turf, used when a turf's lighting goes dynamic (construction of floors, for example.)
|
||||
// Assumes the turf is visible and such.
|
||||
// For the love of god don't call this proc when it's not needed! Lighting artifacts WILL happen!
|
||||
/datum/light_source/proc/calc_turf(var/turf/T)
|
||||
var/idx = effect_turf.Find(T)
|
||||
if(!idx)
|
||||
return // WHY.
|
||||
|
||||
if(T.lighting_overlay)
|
||||
LUM_FALLOFF(., T, source_turf)
|
||||
. *= light_power
|
||||
|
||||
. = round(., LIGHTING_ROUND_VALUE)
|
||||
|
||||
effect_str[idx] = .
|
||||
effect_str[T] = .
|
||||
// Since the applied_lum values are what are (later) removed by remove_lum.
|
||||
// Anything we apply to the lighting overlays HAS to match what remove_lum uses.
|
||||
T.lighting_overlay.update_lumcount(
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
/atom/movable/lighting_overlay
|
||||
name = ""
|
||||
mouse_opacity = 0
|
||||
anchored = 1
|
||||
anchored = TRUE
|
||||
|
||||
icon_state = "light1"
|
||||
icon = LIGHTING_ICON
|
||||
layer = LIGHTING_LAYER
|
||||
invisibility = INVISIBILITY_LIGHTING
|
||||
blend_mode = BLEND_MULTIPLY
|
||||
|
||||
color = "#000000"
|
||||
|
||||
var/lum_r
|
||||
@@ -23,6 +24,9 @@
|
||||
. = ..()
|
||||
verbs.Cut()
|
||||
|
||||
// BYOND was too stupid to realise this is constant.
|
||||
alpha = 255 - round(LIGHTING_SOFT_THRESHOLD * 255) // All overlays should start softly lit.
|
||||
|
||||
// This proc should be used to change the lumcounts of the overlay, it applies the changes and queus the overlay for updating, but only the latter if needed.
|
||||
/atom/movable/lighting_overlay/proc/update_lumcount(delta_r, delta_g, delta_b)
|
||||
if(!delta_r && !delta_g && !delta_b) //Nothing is being changed all together.
|
||||
@@ -59,22 +63,32 @@
|
||||
if(mx > 1)
|
||||
. = 1 / mx
|
||||
|
||||
// If there is any light at all, but below the soft light threshold, modify the factor so the highest lumcount is always LIGHTING_SOFT_THRESHOLD.
|
||||
else if(mx < LIGHTING_SOFT_THRESHOLD && mx > LIGHTING_ROUND_VALUE)
|
||||
. = LIGHTING_SOFT_THRESHOLD / mx
|
||||
|
||||
// Change the colour of the overlay, if we are using dynamic lighting we use animate(), else we don't.
|
||||
#if LIGHTING_TRANSITIONS == 1
|
||||
animate(src,
|
||||
color = rgb(lum_r * 255 * ., lum_g * 255 * ., lum_b * 255 * .),
|
||||
alpha = (mx ? 255 : 255 - round(LIGHTING_SOFT_THRESHOLD * 255)),
|
||||
LIGHTING_TRANSITION_SPEED
|
||||
)
|
||||
#else
|
||||
color = rgb(lum_r * 255 * ., lum_g * 255 * ., lum_b * 255 * .)
|
||||
if(mx <= LIGHTING_SOFT_THRESHOLD)
|
||||
alpha = 255 - round(LIGHTING_SOFT_THRESHOLD * 255) // BYOND I fucking hope you do this at compile time.
|
||||
|
||||
else
|
||||
alpha = 255
|
||||
#endif
|
||||
|
||||
var/turf/T = loc
|
||||
|
||||
if(istype(T)) // Incase we're not on a turf, pool ourselves, something happened.
|
||||
if(color != "#000000")
|
||||
if(max(lum_r, lum_g, lum_b) > LIGHTING_SOFT_THRESHOLD)
|
||||
luminosity = 1
|
||||
else // No light, set the turf's luminosity to 0 to remove it from view()
|
||||
else // Practically no light, disable luminosity so only people up close (or with high see_in_dark) can see this tile.
|
||||
#if LIGHTING_TRANSITIONS == 1
|
||||
spawn(LIGHTING_TRANSITION_SPEED)
|
||||
luminosity = 0
|
||||
|
||||
@@ -1223,6 +1223,8 @@ var/proccalls = 1
|
||||
#define LIGHTING_LAYER 10 // drawing layer for lighting overlays
|
||||
#define LIGHTING_ICON 'icons/effects/lighting_overlay.dmi' // icon used for lighting shading effects
|
||||
|
||||
#define LIGHTING_SOFT_THRESHOLD 0.1 // If the max of the lighting lumcounts of each spectrum drops below this, disable luminosity on the lighting overlays.
|
||||
|
||||
//Some defines to generalise colours used in lighting.
|
||||
//Important note on colors. Colors can end up significantly different from the basic html picture, especially when saturated
|
||||
#define LIGHT_COLOR_RED "#FA8282" //Warm but extremely diluted red. rgb(250, 130, 130)
|
||||
@@ -1341,4 +1343,3 @@ var/proccalls = 1
|
||||
#define MODE_CHANGELING "changeling"
|
||||
#define MODE_CULTCHAT "cultchat"
|
||||
#define MODE_ANCIENT "ancientchat"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user