mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-19 02:54:41 +01:00
Resolves merge conflicts
This commit is contained in:
@@ -11,13 +11,16 @@
|
||||
var/lum_g
|
||||
var/lum_b
|
||||
|
||||
var/list/effect_r
|
||||
var/list/effect_g
|
||||
var/list/effect_b
|
||||
var/tmp/old_lum_r
|
||||
var/tmp/old_lum_g
|
||||
var/tmp/old_lum_b
|
||||
|
||||
var/list/effect_str
|
||||
var/list/effect_turf
|
||||
|
||||
var/applied
|
||||
|
||||
var/vis_update //Whetever we should smartly recalculate visibility. and then only update tiles that became (in) visible to us
|
||||
var/needs_update
|
||||
var/destroyed
|
||||
var/force_update
|
||||
@@ -38,9 +41,7 @@
|
||||
|
||||
parse_light_color()
|
||||
|
||||
effect_r = list()
|
||||
effect_g = list()
|
||||
effect_b = list()
|
||||
effect_str = list()
|
||||
effect_turf = list()
|
||||
|
||||
update()
|
||||
@@ -71,6 +72,13 @@
|
||||
needs_update = 1
|
||||
lighting_update_lights += src
|
||||
|
||||
/datum/light_source/proc/vis_update()
|
||||
if(!needs_update)
|
||||
needs_update = 1
|
||||
lighting_update_lights += src
|
||||
|
||||
vis_update = 1
|
||||
|
||||
/datum/light_source/proc/check()
|
||||
if(!source_atom || !light_range || !light_power)
|
||||
destroy()
|
||||
@@ -96,14 +104,19 @@
|
||||
light_range = source_atom.light_range
|
||||
. = 1
|
||||
|
||||
if(light_range && light_power && !applied)
|
||||
. = 1
|
||||
|
||||
if(. || source_atom.light_color != light_color)//Save the old lumcounts if we need to update, if the colour changed DO IT BEFORE we parse the colour and LOSE the old lumcounts!
|
||||
old_lum_r = lum_r
|
||||
old_lum_g = lum_g
|
||||
old_lum_b = lum_b
|
||||
|
||||
if(source_atom.light_color != light_color)
|
||||
light_color = source_atom.light_color
|
||||
parse_light_color()
|
||||
. = 1
|
||||
|
||||
if(light_range && light_power && !applied)
|
||||
. = 1
|
||||
|
||||
/datum/light_source/proc/parse_light_color()
|
||||
if(light_color)
|
||||
lum_r = GetRedPart(light_color) / 255
|
||||
@@ -114,49 +127,50 @@
|
||||
lum_g = 1
|
||||
lum_b = 1
|
||||
|
||||
/datum/light_source/proc/falloff(atom/movable/lighting_overlay/O)
|
||||
#if LIGHTING_FALLOFF == 1 // circular
|
||||
. = (O.x - source_turf.x)**2 + (O.y - source_turf.y)**2 + LIGHTING_HEIGHT
|
||||
|
||||
#if LIGHTING_LAMBERTIAN == 1
|
||||
. = CLAMP01((1 - CLAMP01(sqrt(.) / max(1,light_range))) * (1 / (sqrt(. + 1))))
|
||||
#else
|
||||
. = 1 - CLAMP01(sqrt(.) / max(1,light_range))
|
||||
#endif
|
||||
|
||||
#elif LIGHTING_FALLOFF == 2 // square
|
||||
. = abs(O.x - source_turf.x) + abs(O.y - source_turf.y) + LIGHTING_HEIGHT
|
||||
|
||||
#if LIGHTING_LAMBERTIAN == 1
|
||||
. = CLAMP01((1 - CLAMP01(. / max(1,light_range))) * (1 / (sqrt(.)**2 + )))
|
||||
#else
|
||||
. = 1 - CLAMP01(. / max(1,light_range))
|
||||
#endif
|
||||
#if LIGHTING_FALLOFF == 1 //circular
|
||||
#define LUM_DISTANCE(swapvar, O, T) swapvar = (O.x - T.x)**2 + (O.y - T.y)**2 + LIGHTING_HEIGHT
|
||||
#if LIGHTING_LAMBERTIAN == 1
|
||||
#define LUM_ATTENUATION(swapvar) swapvar = CLAMP01((1 - CLAMP01(sqrt(swapvar) / light_range)) * (1 / sqrt(swapvar + 1)))
|
||||
#else
|
||||
#define LUM_ATTENUATION(swapvar) swapvar = 1 - CLAMP01(sqrt(swapvar) / light_range)
|
||||
#endif
|
||||
#elif LIGHTING_FALLOFF == 2 //square
|
||||
#define LUM_DISTANCE(swapvar, O, T) swapvar = abs(O.x - T.x) + abs(O.y - T.y) + LIGHTING_HEIGHT
|
||||
#if LIGHTING_LAMBERTIAN == 1
|
||||
#define LUM_ATTENUATION(swapvar) swapvar = CLAMP01((1 - CLAMP01(swapvar / light_range)) * (1 / sqrt(swapvar**2 + 1)))
|
||||
#else
|
||||
#define LUM_ATTENUATION(swapvar) swapvar = CLAMP01(swapvar / light_range)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define LUM_FALLOFF(swapvar, O, T) \
|
||||
LUM_DISTANCE(swapvar, O, T); \
|
||||
LUM_ATTENUATION(swapvar);
|
||||
|
||||
/datum/light_source/proc/apply_lum()
|
||||
applied = 1
|
||||
if(istype(source_turf))
|
||||
for(var/turf/T in dview(light_range, source_turf, INVISIBILITY_LIGHTING))
|
||||
FOR_DVIEW(var/turf/T, light_range, source_turf, INVISIBILITY_LIGHTING)
|
||||
if(T.lighting_overlay)
|
||||
var/strength = light_power * falloff(T.lighting_overlay)
|
||||
var/strength
|
||||
LUM_FALLOFF(strength, T, source_turf)
|
||||
strength *= light_power
|
||||
|
||||
if(!strength) //Don't add turfs that aren't affected to the affected turfs.
|
||||
continue
|
||||
|
||||
effect_r += round(lum_r * strength, LIGHTING_ROUND_VALUE)
|
||||
effect_g += round(lum_g * strength, LIGHTING_ROUND_VALUE)
|
||||
effect_b += round(lum_b * strength, LIGHTING_ROUND_VALUE)
|
||||
strength = round(strength, LIGHTING_ROUND_VALUE) //Screw sinking points.
|
||||
|
||||
effect_str += strength
|
||||
|
||||
T.lighting_overlay.update_lumcount(
|
||||
round(lum_r * strength, LIGHTING_ROUND_VALUE),
|
||||
round(lum_g * strength, LIGHTING_ROUND_VALUE),
|
||||
round(lum_b * strength, LIGHTING_ROUND_VALUE)
|
||||
lum_r * strength,
|
||||
lum_g * strength,
|
||||
lum_b * strength
|
||||
)
|
||||
|
||||
else
|
||||
effect_r += 0
|
||||
effect_g += 0
|
||||
effect_b += 0
|
||||
effect_str += 0
|
||||
|
||||
if(!T.affecting_lights)
|
||||
T.affecting_lights = list()
|
||||
@@ -172,11 +186,66 @@
|
||||
T.affecting_lights -= src
|
||||
|
||||
if(T.lighting_overlay)
|
||||
T.lighting_overlay.update_lumcount(-effect_r[i], -effect_g[i], -effect_b[i])
|
||||
var/str = effect_str[i]
|
||||
T.lighting_overlay.update_lumcount(-str * old_lum_r, -str * old_lum_g, -str * old_lum_b)
|
||||
|
||||
i++
|
||||
|
||||
effect_r.Cut()
|
||||
effect_g.Cut()
|
||||
effect_b.Cut()
|
||||
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.
|
||||
//Stupid dumb copy pasta because BYOND and speed.
|
||||
/datum/light_source/proc/smart_vis_update()
|
||||
var/list/view[0]
|
||||
FOR_DVIEW(var/turf/T, light_range, source_turf, INVISIBILITY_LIGHTING)
|
||||
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.
|
||||
for(var/turf/T in new_turfs)
|
||||
//Big huge copy paste from apply_lum() incoming because screw unreadable defines and screw proc call overhead.
|
||||
if(T.lighting_overlay)
|
||||
LUM_FALLOFF(., T, source_turf)
|
||||
. *= light_power
|
||||
|
||||
if(!.) //Don't add turfs that aren't affected to the affected turfs.
|
||||
continue
|
||||
|
||||
. = round(., LIGHTING_ROUND_VALUE)
|
||||
|
||||
effect_str += .
|
||||
|
||||
T.lighting_overlay.update_lumcount(
|
||||
lum_r * .,
|
||||
lum_g * .,
|
||||
lum_b * .
|
||||
)
|
||||
|
||||
else
|
||||
effect_str += 0
|
||||
|
||||
if(!T.affecting_lights)
|
||||
T.affecting_lights = list()
|
||||
|
||||
T.affecting_lights += src
|
||||
effect_turf += T
|
||||
|
||||
var/list/old_turfs = effect_turf - 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)
|
||||
if(T.affecting_lights)
|
||||
T.affecting_lights -= src
|
||||
|
||||
if(T.lighting_overlay)
|
||||
var/str = effect_str[idx]
|
||||
T.lighting_overlay.update_lumcount(-str * lum_r, -str * lum_g, -str * lum_b)
|
||||
|
||||
effect_turf.Cut(idx, idx + 1)
|
||||
effect_str.Cut(idx, idx + 1)
|
||||
|
||||
#undef LUM_FALLOFF
|
||||
#undef LUM_DISTANCE
|
||||
#undef LUM_ATTENUATION
|
||||
@@ -7,7 +7,6 @@
|
||||
icon = LIGHTING_ICON
|
||||
layer = LIGHTING_LAYER
|
||||
invisibility = INVISIBILITY_LIGHTING
|
||||
blend_mode = BLEND_MULTIPLY
|
||||
color = "#000000"
|
||||
icon_state = "light1"
|
||||
|
||||
@@ -62,34 +61,33 @@
|
||||
lighting_update_overlays += src
|
||||
|
||||
/atom/movable/lighting_overlay/proc/update_overlay()
|
||||
var/mx = max(lum_r, lum_g, lum_b)
|
||||
. = 1 // factor
|
||||
if(mx > 1)
|
||||
. = 1/mx
|
||||
#if LIGHTING_TRANSITIONS == 1
|
||||
animate(src,
|
||||
color = rgb(lum_r * 255 * ., lum_g * 255 * ., lum_b * 255 * .),
|
||||
LIGHTING_TRANSITION_SPEED
|
||||
)
|
||||
#else
|
||||
color = rgb(lum_r * 255 * ., lum_g * 255 * ., lum_b * 255 * .)
|
||||
#endif
|
||||
|
||||
var/turf/T = loc
|
||||
|
||||
if(istype(T)) //Incase we're not on a turf, pool ourselves, something happened.
|
||||
if(color != "#000000")
|
||||
T.luminosity = 1
|
||||
else //No light, set the turf's luminosity to 0 to remove it from view()
|
||||
#if LIGHTING_TRANSITIONS == 1
|
||||
spawn(LIGHTING_TRANSITION_SPEED)
|
||||
if(lum_r == lum_g && lum_r == lum_b) //greyscale
|
||||
blend_mode = BLEND_OVERLAY
|
||||
if(lum_r <= 0)
|
||||
T.luminosity = 0
|
||||
color = "#000000"
|
||||
alpha = 255
|
||||
else
|
||||
T.luminosity = 1
|
||||
color = "#000000"
|
||||
alpha = (1 - min(lum_r, 1)) * 255
|
||||
else
|
||||
alpha = 255
|
||||
var/mx = max(lum_r, lum_g, lum_b)
|
||||
. = 1 // factor
|
||||
if(mx > 1)
|
||||
. = 1/mx
|
||||
blend_mode = BLEND_MULTIPLY
|
||||
color = rgb(lum_r * 255 * ., lum_g * 255 * ., lum_b * 255 * .)
|
||||
if(color != "#000000")
|
||||
T.luminosity = 1
|
||||
else //No light, set the turf's luminosity to 0 to remove it from view()
|
||||
T.luminosity = 0
|
||||
#else
|
||||
T.luminosity = 0
|
||||
#endif
|
||||
|
||||
else
|
||||
warning("A lighting overlay realised it's loc was NOT a turf (actual loc: [loc], [loc.type]) in update_overlay() and got qdel'd!")
|
||||
warning("A lighting overlay realised its loc was NOT a turf (actual loc: [loc][loc ? ", " + loc.type : ""]) in update_overlay() and got qdel'ed!")
|
||||
qdel(src)
|
||||
|
||||
/atom/movable/lighting_overlay/singularity_act()
|
||||
@@ -104,9 +102,5 @@
|
||||
var/turf/T = loc
|
||||
if(istype(T))
|
||||
T.lighting_overlay = null
|
||||
for(var/datum/light_source/D in T.affecting_lights) //Remove references to us on the light sources affecting us.
|
||||
D.effect_r -= src
|
||||
D.effect_g -= src
|
||||
D.effect_b -= src
|
||||
|
||||
return ..()
|
||||
@@ -5,25 +5,31 @@
|
||||
/datum/controller/process/lighting/doWork()
|
||||
var/list/lighting_update_lights_old = lighting_update_lights //We use a different list so any additions to the update lists during a delay from scheck() don't cause things to be cut from the list without being updated.
|
||||
last_light_count = lighting_update_lights.len
|
||||
lighting_update_lights = null //Nulling it first because of http://www.byond.com/forum/?post=1854520
|
||||
lighting_update_lights = list()
|
||||
|
||||
for(var/datum/light_source/L in lighting_update_lights_old)
|
||||
if(L.needs_update)
|
||||
if(L.destroyed || L.check() || L.force_update)
|
||||
L.remove_lum()
|
||||
if(!L.destroyed) L.apply_lum()
|
||||
L.force_update = 0
|
||||
L.needs_update = 0
|
||||
if(L.destroyed || L.check() || L.force_update)
|
||||
L.remove_lum()
|
||||
if(!L.destroyed)
|
||||
L.apply_lum()
|
||||
|
||||
else if(L.vis_update) //We smartly update only tiles that became (in) visible to use.
|
||||
L.smart_vis_update()
|
||||
|
||||
L.vis_update = 0
|
||||
L.force_update = 0
|
||||
L.needs_update = 0
|
||||
|
||||
scheck()
|
||||
|
||||
var/list/lighting_update_overlays_old = lighting_update_overlays //Same as above.
|
||||
last_overlay_count = lighting_update_overlays.len
|
||||
lighting_update_overlays = null //Same as above
|
||||
lighting_update_overlays = list()
|
||||
|
||||
for(var/atom/movable/lighting_overlay/O in lighting_update_overlays_old)
|
||||
if(O.needs_update)
|
||||
O.update_overlay()
|
||||
O.needs_update = 0
|
||||
O.update_overlay()
|
||||
O.needs_update = 0
|
||||
|
||||
scheck()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
/turf/proc/reconsider_lights()
|
||||
for(var/datum/light_source/L in affecting_lights)
|
||||
L.force_update()
|
||||
L.vis_update()
|
||||
|
||||
/turf/proc/lighting_clear_overlays()
|
||||
if(lighting_overlay)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#undef LIGHTING_FALLOFF
|
||||
#undef LIGHTING_LAMBERTIAN
|
||||
#undef LIGHTING_HEIGHT
|
||||
#undef LIGHTING_TRANSITIONS
|
||||
|
||||
#undef LIGHTING_RESOLUTION
|
||||
#undef LIGHTING_LAYER
|
||||
|
||||
Reference in New Issue
Block a user