Implements a configurable sun for a sunlight effect using the lighting engine.
Abuses Z-lights to illuminate Zs in a semi-realistic way.

Kinda slow at setting state, but state changes shouldn't lag & are rare.

Also adds the ability to create lights that ignore visibility when calculating range, causing them to shine through objects/walls.
This commit is contained in:
Lohikar
2017-05-31 11:43:18 +03:00
committed by skull132
parent 1db5663128
commit 90b6691c8f
14 changed files with 336 additions and 66 deletions
+2 -46
View File
@@ -65,7 +65,7 @@
update()
L_PROF(source_atom, "source_new")
L_PROF(source_atom, "source_new([type])")
return ..()
@@ -147,42 +147,6 @@
else
lum_u = 0
// Macro that applies light to a new corner.
// It is a macro in the interest of speed, yet not having to copy paste it.
// If you're wondering what's with the backslashes, the backslashes cause BYOND to not automatically end the line.
// As such this all gets counted as a single line.
// The braces and semicolons are there to be able to do this on a single line.
#define APPLY_CORNER_XY(C,now,Tx,Ty) \
. = LUM_FALLOFF_XY(C.x, C.y, Tx, Ty); \
\
. *= light_power; \
var/OLD = effect_str[C]; \
\
effect_str[C] = .; \
\
C.update_lumcount \
( \
(. * lum_r) - (OLD * applied_lum_r), \
(. * lum_g) - (OLD * applied_lum_g), \
(. * lum_b) - (OLD * applied_lum_b), \
(. * lum_u) - (OLD * applied_lum_u), \
now \
);
#define APPLY_CORNER(C,now) APPLY_CORNER_XY(C,now,source_turf.x,source_turf.y)
// I don't need to explain what this does, do I?
#define REMOVE_CORNER(C,now) \
. = -effect_str[C]; \
C.update_lumcount \
( \
. * applied_lum_r, \
. * applied_lum_g, \
. * applied_lum_b, \
. * applied_lum_u, \
now \
);
#define POLAR_TO_CART_X(R,T) ((R) * cos(T))
#define POLAR_TO_CART_Y(R,T) ((R) * sin(T))
#define PSEUDO_WEDGE(A_X,A_Y,B_X,B_Y) ((A_X)*(B_Y) - (A_Y)*(B_X))
@@ -267,10 +231,6 @@
#undef PSEUDO_WEDGE
#undef MINMAX
// This is the define used to calculate falloff.
#define LUM_FALLOFF(C, T) (1 - CLAMP01(sqrt((C.x - T.x) ** 2 + (C.y - T.y) ** 2 + LIGHTING_HEIGHT) / max(1, light_range)))
#define LUM_FALLOFF_XY(Cx,Cy,Tx,Ty) (1 - CLAMP01(sqrt(((Cx) - (Tx)) ** 2 + ((Cy) - (Ty)) ** 2 + LIGHTING_HEIGHT) / max(1, light_range)))
/datum/light_source/proc/remove_lum(var/now = FALSE)
applied = FALSE
@@ -298,6 +258,7 @@
APPLY_CORNER(C,now)
UNSETEMPTY(effect_str)
// If you update this, update the equivalent proc in lighting_source_novis.dm.
/datum/light_source/proc/update_corners(now = FALSE)
var/update = FALSE
@@ -449,8 +410,3 @@
#undef QUEUE_UPDATE
#undef DO_UPDATE
#undef INTELLIGENT_UPDATE
#undef LUM_FALLOFF
#undef LUM_FALLOFF_XY
#undef REMOVE_CORNER
#undef APPLY_CORNER
#undef APPLY_CORNER_XY