From 5f629e2aca9c26aac986b0cd85ad1a3a26560ea4 Mon Sep 17 00:00:00 2001 From: Leshana Date: Tue, 11 Apr 2017 22:23:16 -0400 Subject: [PATCH] Optimizes lighting overlays for slow clients. Ports https://github.com/tgstation/tgstation/pull/25778 and https://github.com/tgstation/tgstation/pull/25861 * Instead of using color matrix for all overlays, fully dark and fully light use static black and transparant icon states without color matrix. * Also implements LIGHTING_ROUND_VALUE so that lighting values actually will reach 0 or 1. --- code/__defines/lighting.dm | 4 +- code/modules/lighting/lighting_corner.dm | 18 +++++--- code/modules/lighting/lighting_overlay.dm | 50 +++++++++++++++++++--- icons/effects/lighting_overlay.dmi | Bin 0 -> 1882 bytes 4 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 icons/effects/lighting_overlay.dmi diff --git a/code/__defines/lighting.dm b/code/__defines/lighting.dm index 58f2e96b145..0b581cf7801 100644 --- a/code/__defines/lighting.dm +++ b/code/__defines/lighting.dm @@ -10,9 +10,9 @@ #define LIGHTING_HEIGHT 1 // height off the ground of light sources on the pseudo-z-axis, you should probably leave this alone #define LIGHTING_LAYER 10 // drawing layer for lighting overlays -#define LIGHTING_ICON 'icons/effects/lighting_overlay.png' // icon used for lighting shading effects +#define LIGHTING_ICON 'icons/effects/lighting_overlay.dmi' // icon used for lighting shading effects -#define LIGHTING_ROUND_VALUE (1 / 128) //Value used to round lumcounts, values smaller than 1/255 don't matter (if they do, thanks sinking points), greater values will make lighting less precise, but in turn increase performance, VERY SLIGHTLY. +#define LIGHTING_ROUND_VALUE (1 / 64) //Value used to round lumcounts, values smaller than 1/69 don't matter (if they do, thanks sinking points), greater values will make lighting less precise, but in turn increase performance, VERY SLIGHTLY. #define LIGHTING_SOFT_THRESHOLD 0.05 // If the max of the lighting lumcounts of each spectrum drops below this, disable luminosity on the lighting overlays. diff --git a/code/modules/lighting/lighting_corner.dm b/code/modules/lighting/lighting_corner.dm index 907e7aab8b5..63ce1232535 100644 --- a/code/modules/lighting/lighting_corner.dm +++ b/code/modules/lighting/lighting_corner.dm @@ -98,20 +98,28 @@ lighting_update_corners += src /datum/lighting_corner/proc/update_overlays() - // Cache these values a head of time so 4 individual lighting overlays don't all calculate them individually. + var/lum_r = src.lum_r + var/lum_g = src.lum_g + var/lum_b = src.lum_b var/mx = max(lum_r, lum_g, lum_b) // Scale it so 1 is the strongest lum, if it is above 1. . = 1 // factor if (mx > 1) . = 1 / mx + #if LIGHTING_SOFT_THRESHOLD != 0 else if (mx < LIGHTING_SOFT_THRESHOLD) . = 0 // 0 means soft lighting. - cache_r = lum_r * . || LIGHTING_SOFT_THRESHOLD - cache_g = lum_g * . || LIGHTING_SOFT_THRESHOLD - cache_b = lum_b * . || LIGHTING_SOFT_THRESHOLD - cache_mx = mx + cache_r = round(lum_r * ., LIGHTING_ROUND_VALUE) || LIGHTING_SOFT_THRESHOLD + cache_g = round(lum_g * ., LIGHTING_ROUND_VALUE) || LIGHTING_SOFT_THRESHOLD + cache_b = round(lum_b * ., LIGHTING_ROUND_VALUE) || LIGHTING_SOFT_THRESHOLD + #else + cache_r = round(lum_r * ., LIGHTING_ROUND_VALUE) + cache_g = round(lum_g * ., LIGHTING_ROUND_VALUE) + cache_b = round(lum_b * ., LIGHTING_ROUND_VALUE) + #endif + cache_mx = round(mx, LIGHTING_ROUND_VALUE) for (var/TT in masters) var/turf/T = TT diff --git a/code/modules/lighting/lighting_overlay.dm b/code/modules/lighting/lighting_overlay.dm index 4679d1fafc1..559e3a87f8f 100644 --- a/code/modules/lighting/lighting_overlay.dm +++ b/code/modules/lighting/lighting_overlay.dm @@ -59,16 +59,52 @@ var/max = max(cr.cache_mx, cg.cache_mx, cb.cache_mx, ca.cache_mx) - color = list( - cr.cache_r, cr.cache_g, cr.cache_b, 0, - cg.cache_r, cg.cache_g, cg.cache_b, 0, - cb.cache_r, cb.cache_g, cb.cache_b, 0, - ca.cache_r, ca.cache_g, ca.cache_b, 0, - 0, 0, 0, 1 + var/rr = cr.cache_r + var/rg = cr.cache_g + var/rb = cr.cache_b + + var/gr = cg.cache_r + var/gg = cg.cache_g + var/gb = cg.cache_b + + var/br = cb.cache_r + var/bg = cb.cache_g + var/bb = cb.cache_b + + var/ar = ca.cache_r + var/ag = ca.cache_g + var/ab = ca.cache_b + + #if LIGHTING_SOFT_THRESHOLD != 0 + var/set_luminosity = max > LIGHTING_SOFT_THRESHOLD + #else + // Because of floating points, it won't even be a flat 0. + // This number is mostly arbitrary. + var/set_luminosity = max > 1e-6 + #endif + + if((rr & gr & br & ar) && (rg + gg + bg + ag + rb + gb + bb + ab == 8)) + //anything that passes the first case is very likely to pass the second, and addition is a little faster in this case + icon_state = "transparent" + color = null + else if(!set_luminosity) + icon_state = "dark" + color = null + else + icon_state = null + color = list( + rr, rg, rb, 00, + gr, gg, gb, 00, + br, bg, bb, 00, + ar, ag, ab, 00, + 00, 00, 00, 01 ) - luminosity = max > LIGHTING_SOFT_THRESHOLD + luminosity = set_luminosity +// Variety of overrides so the overlays don't get affected by weird things. +/atom/movable/lighting_overlay/ex_act() + return /atom/movable/lighting_overlay/singularity_act() return diff --git a/icons/effects/lighting_overlay.dmi b/icons/effects/lighting_overlay.dmi new file mode 100644 index 0000000000000000000000000000000000000000..51985c0c981c5bdb3dd57606b733474016ca5c5d GIT binary patch literal 1882 zcmb7_`#;l*AICqt$QWYCWUdbh6Pux}IHo2vw~X8`8A4h^n24EMN1|_$)%JDNBvS5< zaa1GQiR02a5_O7CE)_YuX~!)cjrYniW5&mU2aJ<^Et^}O+N7h4+S##Ry?+#2M++d%H1eVzAXMfH+!z- z5>XUFz47AKcIjE2I_q@Y9=m1s|oogTItkX(FuuZ#2(x|k~~hm7LL6V^m{F! zSpYp9yVoQF*o6ROodF`41O}>0M!``DLuxitXS*b~)Gona!H*M1`Re@9+7*;22&4kx zp#90O-qJv*v~44AqiwvoC-kRW!_Oaq66+5($AY2pT*A=aV|VKStb2akX28Yg!1#W^ z6H@UKC6W)5V&!F@y?}LCW*Mo5eHjs zSt7@|iG54I6RXj4=zS&gXtQD8LFS+a*2ugK>^Cjq90kNQC_RUVgKnZBy`%3R8~0g? z8DiSBrT8k{N^JT_LJ}t;YP}z*fco}oa)p<0sx7?{qMCe}F$9U3Uh1e7Qk$viM@oH) z>(F&*zh+O!oYFBlfzZfW5#eNriy7ut+t5utA=vAretuL& zp%oFykk7Pa9bh#(xofDelAyQ{bR~v?sl@w*Jl8x*IPF}*UEw%ZdC3&o9Ayd7Q5$7d zCeFv>snA=<`4LrVZn(R1h6_UxD9+r@R-f|p{3?`&~;Z->)+q;ut<+`AJ z%-HULw5EM?D8FEh1SL9<96V**0hoQHdD6-5oJJL{73)g{{I~MABHk{erL;HVb9Q<{UtR~Y0O~MgxbW_kC#T&08)TKbfq+8X2Uyq@}1$C zx9@E8g91bU6BXE}(B^S?)?IYn!<~jr8_Do*pq5(>HtX`R%j4fRLCp@9H za6WIeDG(hNz2(Q|Tjnk=&*M&hyD@-=C=e9n1ihw+Gw*zEh6~dF+r9rxmhwI5XvV!Z literal 0 HcmV?d00001