mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-12 19:22:56 +00:00
[MIRROR] Micro-opt lighting (#9268)
Co-authored-by: ShadowLarkens <shadowlarkens@gmail.com> Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
@@ -111,28 +111,44 @@
|
||||
// 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.
|
||||
|
||||
// /tg/ falloff alg
|
||||
#define LUM_FALLOFF(C, T) (1 - CLAMP01(sqrt((C.x - T.x) ** 2 + (C.y - T.y) ** 2 + LIGHTING_HEIGHT) / max(1, light_range)))
|
||||
// This exists so we can cache the vars used in this macro, and save MASSIVE time :)
|
||||
// Most of this is saving off datum var accesses, tho some of it does actually cache computation
|
||||
// You will NEED to call this before you call APPLY_CORNER
|
||||
#define SETUP_CORNERS_CACHE(lighting_source) \
|
||||
var/_turf_x = lighting_source.pixel_turf.x; \
|
||||
var/_turf_y = lighting_source.pixel_turf.y; \
|
||||
var/_range_divisor = max(1, lighting_source.light_range); \
|
||||
var/_light_power = lighting_source.light_power; \
|
||||
var/_applied_lum_r = lighting_source.applied_lum_r; \
|
||||
var/_applied_lum_g = lighting_source.applied_lum_g; \
|
||||
var/_applied_lum_b = lighting_source.applied_lum_b; \
|
||||
var/_lum_r = lighting_source.lum_r; \
|
||||
var/_lum_g = lighting_source.lum_g; \
|
||||
var/_lum_b = lighting_source.lum_b; \
|
||||
|
||||
// Bay/Polaris falloff alg
|
||||
//#define LUM_FALLOFF(C, T)(1 - CLAMP01(((C.x - T.x) ** 2 +(C.y - T.y) ** 2 + LIGHTING_HEIGHT) ** 0.6 / max(1, light_range)))
|
||||
#define SETUP_CORNERS_REMOVAL_CACHE(lighting_source) \
|
||||
var/_applied_lum_r = lighting_source.applied_lum_r; \
|
||||
var/_applied_lum_g = lighting_source.applied_lum_g; \
|
||||
var/_applied_lum_b = lighting_source.applied_lum_b;
|
||||
|
||||
#define LUM_FALLOFF(C) (1 - CLAMP01(sqrt((C.x - _turf_x) ** 2 + (C.y - _turf_y) ** 2 + LIGHTING_HEIGHT) / _range_divisor))
|
||||
|
||||
#define APPLY_CORNER(C) \
|
||||
. = LUM_FALLOFF(C, pixel_turf); \
|
||||
. *= light_power; \
|
||||
. = LUM_FALLOFF(C); \
|
||||
. *= _light_power; \
|
||||
var/OLD = 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_r) - (OLD * _applied_lum_r), \
|
||||
(. * _lum_g) - (OLD * _applied_lum_g), \
|
||||
(. * _lum_b) - (OLD * _applied_lum_b) \
|
||||
); \
|
||||
|
||||
//CHOMPEdit Begin
|
||||
#define APPLY_CORNER_NEW(C) \
|
||||
. = LUM_FALLOFF(C, pixel_turf); \
|
||||
. *= light_power; \
|
||||
. = LUM_FALLOFF(C); \
|
||||
. *= _light_power; \
|
||||
var/OLD = effect_str[C]; \
|
||||
if (. != 0){ \
|
||||
LAZYADD(C.affecting, src); \
|
||||
@@ -140,21 +156,22 @@
|
||||
} \
|
||||
C.update_lumcount \
|
||||
( \
|
||||
(. * lum_r) - (OLD * applied_lum_r), \
|
||||
(. * lum_g) - (OLD * applied_lum_g), \
|
||||
(. * lum_b) - (OLD * applied_lum_b) \
|
||||
(. * _lum_r) - (OLD * _applied_lum_r), \
|
||||
(. * _lum_g) - (OLD * _applied_lum_g), \
|
||||
(. * _lum_b) - (OLD * _applied_lum_b) \
|
||||
); \
|
||||
//CHOMPEdit End
|
||||
#define REMOVE_CORNER(C) \
|
||||
. = -effect_str[C]; \
|
||||
C.update_lumcount \
|
||||
( \
|
||||
. * applied_lum_r, \
|
||||
. * applied_lum_g, \
|
||||
. * applied_lum_b \
|
||||
. * _applied_lum_r, \
|
||||
. * _applied_lum_g, \
|
||||
. * _applied_lum_b \
|
||||
);
|
||||
|
||||
/datum/light_source/proc/remove_lum()
|
||||
SETUP_CORNERS_REMOVAL_CACHE(src)
|
||||
applied = FALSE
|
||||
for (var/datum/lighting_corner/corner as anything in effect_str)
|
||||
LAZYREMOVE(corner.affecting, src) //CHOMPEdit
|
||||
@@ -163,6 +180,7 @@
|
||||
effect_str = null
|
||||
|
||||
/datum/light_source/proc/recalc_corner(datum/lighting_corner/corner)
|
||||
SETUP_CORNERS_CACHE(src)
|
||||
LAZYINITLIST(effect_str)
|
||||
if (effect_str[corner]) // Already have one.
|
||||
REMOVE_CORNER(corner)
|
||||
@@ -174,6 +192,24 @@
|
||||
/datum/light_source/proc/get_turfs_in_range()
|
||||
return view(CEILING(light_range, 1), source_turf)
|
||||
|
||||
// Keep in mind. Lighting corners accept the bottom left (northwest) set of cords to them as input
|
||||
//CHOMPEdit Start Dynamic light
|
||||
#define GENERATE_MISSING_CORNERS(gen_for) \
|
||||
if (!gen_for.lighting_corner_NE) { \
|
||||
gen_for.lighting_corner_NE = new /datum/lighting_corner(gen_for.x, gen_for.y, gen_for.z, gen_for.has_dynamic_lighting()); \
|
||||
} \
|
||||
if (!gen_for.lighting_corner_SE) { \
|
||||
gen_for.lighting_corner_SE = new /datum/lighting_corner(gen_for.x, gen_for.y - 1, gen_for.z, gen_for.has_dynamic_lighting()); \
|
||||
} \
|
||||
if (!gen_for.lighting_corner_SW) { \
|
||||
gen_for.lighting_corner_SW = new /datum/lighting_corner(gen_for.x - 1, gen_for.y - 1, gen_for.z, gen_for.has_dynamic_lighting()); \
|
||||
} \
|
||||
if (!gen_for.lighting_corner_NW) { \
|
||||
gen_for.lighting_corner_NW = new /datum/lighting_corner(gen_for.x - 1, gen_for.y, gen_for.z, gen_for.has_dynamic_lighting()); \
|
||||
} \
|
||||
gen_for.lighting_corners_initialised = TRUE;
|
||||
//CHOMPEdit End
|
||||
|
||||
/datum/light_source/proc/update_corners()
|
||||
var/update = FALSE
|
||||
var/atom/source_atom = src.source_atom
|
||||
@@ -236,24 +272,27 @@
|
||||
return //nothing's changed
|
||||
|
||||
var/list/datum/lighting_corner/corners = list()
|
||||
var/list/turf/turfs = list()
|
||||
|
||||
if (source_turf)
|
||||
var/oldlum = source_turf.luminosity
|
||||
source_turf.luminosity = CEILING(light_range, 1)
|
||||
for(var/turf/T in get_turfs_in_range())
|
||||
if(!IS_OPAQUE_TURF(T))
|
||||
if (!T.lighting_corners_initialised)
|
||||
T.generate_missing_corners()
|
||||
corners[T.lighting_corner_NE] = 0
|
||||
corners[T.lighting_corner_SE] = 0
|
||||
corners[T.lighting_corner_SW] = 0
|
||||
corners[T.lighting_corner_NW] = 0
|
||||
turfs += T
|
||||
if(IS_OPAQUE_TURF(T))
|
||||
continue
|
||||
if (!T.lighting_corners_initialised)
|
||||
GENERATE_MISSING_CORNERS(T)
|
||||
|
||||
corners[T.lighting_corner_NE] = 0
|
||||
corners[T.lighting_corner_SE] = 0
|
||||
corners[T.lighting_corner_SW] = 0
|
||||
corners[T.lighting_corner_NW] = 0
|
||||
source_turf.luminosity = oldlum
|
||||
|
||||
var/list/datum/lighting_corner/new_corners = (corners - effect_str)
|
||||
LAZYINITLIST(effect_str)
|
||||
SETUP_CORNERS_CACHE(src)
|
||||
|
||||
var/list/datum/lighting_corner/new_corners = (corners - src.effect_str)
|
||||
LAZYINITLIST(src.effect_str)
|
||||
var/list/effect_str = src.effect_str
|
||||
if (needs_update == LIGHTING_VIS_UPDATE)
|
||||
for (var/datum/lighting_corner/corner in new_corners) //CHOMPEdit
|
||||
//CHOMPEdit Begin
|
||||
@@ -267,8 +306,8 @@
|
||||
|
||||
for (var/datum/lighting_corner/corner in corners - new_corners) // Existing corners //CHOMPEdit
|
||||
//CHOMPEdit Begin
|
||||
. = LUM_FALLOFF(corner, pixel_turf);
|
||||
. *= light_power;
|
||||
. = LUM_FALLOFF(corner);
|
||||
. *= _light_power;
|
||||
var/OLD = effect_str[corner];
|
||||
if (. != 0)
|
||||
effect_str[corner] = .
|
||||
@@ -277,9 +316,9 @@
|
||||
effect_str -= corner
|
||||
corner.update_lumcount \
|
||||
( \
|
||||
(. * lum_r) - (OLD * applied_lum_r), \
|
||||
(. * lum_g) - (OLD * applied_lum_g), \
|
||||
(. * lum_b) - (OLD * applied_lum_b) \
|
||||
(. * _lum_r) - (OLD * _applied_lum_r), \
|
||||
(. * _lum_g) - (OLD * _applied_lum_g), \
|
||||
(. * _lum_b) - (OLD * _applied_lum_b) \
|
||||
);
|
||||
//CHOMPEdit End
|
||||
|
||||
@@ -293,9 +332,11 @@
|
||||
applied_lum_g = lum_g
|
||||
applied_lum_b = lum_b
|
||||
|
||||
UNSETEMPTY(effect_str)
|
||||
UNSETEMPTY(src.effect_str)
|
||||
|
||||
#undef EFFECT_UPDATE
|
||||
#undef LUM_FALLOFF
|
||||
#undef REMOVE_CORNER
|
||||
#undef APPLY_CORNER
|
||||
#undef SETUP_CORNERS_REMOVAL_CACHE
|
||||
#undef SETUP_CORNERS_CACHE
|
||||
|
||||
Reference in New Issue
Block a user