mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
make lighting falloff a macro and optimize turfs-in-view
Signed-off-by: Mloc <colmohici@gmail.com>
This commit is contained in:
@@ -1299,24 +1299,26 @@ var/list/WALLITEMS = list(
|
|||||||
colour += temp_col
|
colour += temp_col
|
||||||
return colour
|
return colour
|
||||||
|
|
||||||
|
var/mob/dview/dview_mob = new
|
||||||
|
|
||||||
//Version of view() which ignores darkness, because BYOND doesn't have it.
|
//Version of view() which ignores darkness, because BYOND doesn't have it.
|
||||||
/proc/dview(var/range = world.view, var/center, var/invis_flags = 0)
|
/proc/dview(var/range = world.view, var/center, var/invis_flags = 0)
|
||||||
if(!center)
|
if(!center)
|
||||||
return
|
return
|
||||||
|
|
||||||
var/global/mob/dview/DV
|
dview_mob.loc = center
|
||||||
if(!DV)
|
|
||||||
DV = new
|
|
||||||
|
|
||||||
DV.loc = center
|
dview_mob.see_invisible = invis_flags
|
||||||
|
|
||||||
DV.see_in_dark = range
|
. = view(range, dview_mob)
|
||||||
DV.see_invisible = invis_flags
|
dview_mob.loc = null
|
||||||
|
|
||||||
. = view(range, DV)
|
|
||||||
DV.loc = null
|
|
||||||
|
|
||||||
/mob/dview
|
/mob/dview
|
||||||
invisibility = 101
|
invisibility = 101
|
||||||
density = 0
|
density = 0
|
||||||
|
|
||||||
|
anchored = 1
|
||||||
|
simulated = 0
|
||||||
|
|
||||||
|
see_in_dark = 1e6
|
||||||
|
|
||||||
|
|||||||
@@ -127,32 +127,35 @@
|
|||||||
lum_g = 1
|
lum_g = 1
|
||||||
lum_b = 1
|
lum_b = 1
|
||||||
|
|
||||||
/datum/light_source/proc/falloff(atom/movable/lighting_overlay/O)
|
#if LIGHTING_FALLOFF == 1 //circular
|
||||||
#if LIGHTING_FALLOFF == 1 // circular
|
#define LUM_DISTANCE(swapvar, O, T) swapvar = (O.x - T.x)**2 + (O.y - T.y)**2 + LIGHTING_HEIGHT
|
||||||
. = (O.x - source_turf.x)**2 + (O.y - source_turf.y)**2 + LIGHTING_HEIGHT
|
#if LIGHTING_LAMBERTIAN == 1
|
||||||
|
#define LUM_ATTENUATION(swapvar) swapvar = CLAMP01((1 - CLAMP01(sqrt(swapvar) / light_range)) * (1 / sqrt(swapvar + 1)))
|
||||||
#if LIGHTING_LAMBERTIAN == 1
|
#else
|
||||||
. = CLAMP01((1 - CLAMP01(sqrt(.) / light_range)) * (1 / (sqrt(. + 1))))
|
#define LUM_ATTENUATION(swapvar) swapvar = 1 - CLAMP01(sqrt(swapvar) / light_range)
|
||||||
#else
|
|
||||||
. = 1 - CLAMP01(sqrt(.) / 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(. / light_range)) * (1 / (sqrt(.)**2 + )))
|
|
||||||
#else
|
|
||||||
. = 1 - CLAMP01(. / light_range)
|
|
||||||
#endif
|
|
||||||
#endif
|
#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()
|
/datum/light_source/proc/apply_lum()
|
||||||
applied = 1
|
applied = 1
|
||||||
if(istype(source_turf))
|
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)
|
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.
|
if(!strength) //Don't add turfs that aren't affected to the affected turfs.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -196,7 +199,7 @@
|
|||||||
//Stupid dumb copy pasta because BYOND and speed.
|
//Stupid dumb copy pasta because BYOND and speed.
|
||||||
/datum/light_source/proc/smart_vis_update()
|
/datum/light_source/proc/smart_vis_update()
|
||||||
var/list/view[0]
|
var/list/view[0]
|
||||||
for(var/turf/T in dview(light_range, source_turf, INVISIBILITY_LIGHTING))
|
FOR_DVIEW(var/turf/T, light_range, source_turf, INVISIBILITY_LIGHTING)
|
||||||
view += T //Filter out turfs.
|
view += T //Filter out turfs.
|
||||||
|
|
||||||
//This is the part where we calculate new turfs (if any)
|
//This is the part where we calculate new turfs (if any)
|
||||||
@@ -204,7 +207,9 @@
|
|||||||
for(var/turf/T in new_turfs)
|
for(var/turf/T in new_turfs)
|
||||||
//Big huge copy paste from apply_lum() incoming because screw unreadable defines and screw proc call overhead.
|
//Big huge copy paste from apply_lum() incoming because screw unreadable defines and screw proc call overhead.
|
||||||
if(T.lighting_overlay)
|
if(T.lighting_overlay)
|
||||||
. = light_power * falloff(T.lighting_overlay)
|
LUM_FALLOFF(., T, source_turf)
|
||||||
|
. *= light_power
|
||||||
|
|
||||||
if(!.) //Don't add turfs that aren't affected to the affected turfs.
|
if(!.) //Don't add turfs that aren't affected to the affected turfs.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -240,3 +245,7 @@
|
|||||||
|
|
||||||
effect_turf.Cut(idx, idx + 1)
|
effect_turf.Cut(idx, idx + 1)
|
||||||
effect_str.Cut(idx, idx + 1)
|
effect_str.Cut(idx, idx + 1)
|
||||||
|
|
||||||
|
#undef LUM_FALLOFF
|
||||||
|
#undef LUM_DISTANCE
|
||||||
|
#undef LUM_ATTENUATION
|
||||||
|
|||||||
@@ -986,3 +986,7 @@ var/list/be_special_flags = list(
|
|||||||
|
|
||||||
#define TABLE_BRITTLE_MATERIAL_MULTIPLIER 4 // Amount table damage is multiplied by if it is made of a brittle material (e.g. glass)
|
#define TABLE_BRITTLE_MATERIAL_MULTIPLIER 4 // Amount table damage is multiplied by if it is made of a brittle material (e.g. glass)
|
||||||
|
|
||||||
|
#define FOR_DVIEW(type, range, center, invis_flags) \
|
||||||
|
dview_mob.loc = center; \
|
||||||
|
dview_mob.see_invisible = invis_flags; \
|
||||||
|
for(type in view(range, dview_mob))
|
||||||
|
|||||||
Reference in New Issue
Block a user