[MIRROR] Overlay lighting component (#469)

* Overlay lighting component (#52413)

Sparks no longer lag, projectile beams move super smoothly, same with mobs and whatnot. This also allows for easy expansion into directional lights, field-of-view, wee-woo rotating lights or whatever.

It does have a downside: things right-clicked or checked through the alt+click tab will show the light overlay:


This is a BYOND limitation, very well worth it IMO.

🆑
add: Smooth movable lighting system implemented. Projectiles, sparks, thrown flashlights or moving mobs with lights should be much smoother and less laggy.
balance: Light sources no longer stack in range, though they still do in intensity.
/🆑

* Overlay lighting component

Co-authored-by: Rohesie <rohesie@gmail.com>
This commit is contained in:
SkyratBot
2020-08-23 20:17:12 +02:00
committed by GitHub
co-authored by Rohesie
parent 4a51355a9e
commit 0b65cc596b
85 changed files with 1082 additions and 395 deletions
+11 -13
View File
@@ -26,7 +26,11 @@ GLOBAL_LIST_EMPTY(PDAs)
actions_types = list(/datum/action/item_action/toggle_light)
armor = list("melee" = 0, "bullet" = 0, "laser" = 0, "energy" = 0, "bomb" = 0, "bio" = 0, "rad" = 0, "fire" = 100, "acid" = 100)
resistance_flags = FIRE_PROOF | ACID_PROOF
light_system = MOVABLE_LIGHT
light_range = 2.3
light_power = 0.6
light_color = "#FFCC66"
light_on = FALSE
//Main variables
var/owner = null // String name of owner
@@ -49,8 +53,6 @@ GLOBAL_LIST_EMPTY(PDAs)
//Secondary variables
var/scanmode = PDA_SCANNER_NONE
var/fon = FALSE //Is the flashlight function on?
var/f_lum = 2.3 //Luminosity for the flashlight function
var/silent = FALSE //To beep or not to beep, that is the question
var/toff = FALSE //If TRUE, messenger disabled
var/tnote = null //Current Texts
@@ -106,8 +108,6 @@ GLOBAL_LIST_EMPTY(PDAs)
/obj/item/pda/Initialize()
. = ..()
if(fon)
set_light(f_lum)
GLOB.PDAs += src
if(default_cartridge)
@@ -175,7 +175,7 @@ GLOBAL_LIST_EMPTY(PDAs)
if(inserted_item)
overlay.icon_state = "insert_overlay"
. += new /mutable_appearance(overlay)
if(fon)
if(light_on)
overlay.icon_state = "light_overlay"
. += new /mutable_appearance(overlay)
if(pai)
@@ -311,7 +311,7 @@ GLOBAL_LIST_EMPTY(PDAs)
if (cartridge.access & CART_DRONEPHONE)
dat += "<li><a href='byond://?src=[REF(src)];choice=Drone Phone'>[PDAIMG(dronephone)]Drone Phone</a></li>"
dat += "<li><a href='byond://?src=[REF(src)];choice=3'>[PDAIMG(atmos)]Atmospheric Scan</a></li>"
dat += "<li><a href='byond://?src=[REF(src)];choice=Light'>[PDAIMG(flashlight)][fon ? "Disable" : "Enable"] Flashlight</a></li>"
dat += "<li><a href='byond://?src=[REF(src)];choice=Light'>[PDAIMG(flashlight)][light_on ? "Disable" : "Enable"] Flashlight</a></li>"
if (pai)
if(pai.loc != src)
pai = null
@@ -835,12 +835,10 @@ GLOBAL_LIST_EMPTY(PDAs)
/obj/item/pda/proc/toggle_light(mob/user)
if(issilicon(user) || !user.canUseTopic(src, BE_CLOSE))
return
if(fon)
fon = FALSE
set_light(0)
else if(f_lum)
fon = TRUE
set_light(f_lum)
if(light_on)
set_light_on(FALSE)
else if(light_range)
set_light_on(TRUE)
update_icon()
for(var/X in actions)
var/datum/action/A = X
@@ -43,7 +43,7 @@
/obj/item/pda/ai
icon = null
ttone = "data"
fon = FALSE
/obj/item/pda/ai/attack_self(mob/user)
if ((honkamt > 0) && (prob(60)))//For clown virus.
+60 -31
View File
@@ -13,9 +13,12 @@
slot_flags = ITEM_SLOT_BELT
custom_materials = list(/datum/material/iron=50, /datum/material/glass=20)
actions_types = list(/datum/action/item_action/toggle_light)
light_system = MOVABLE_LIGHT
light_range = 4
light_power = 1
light_on = FALSE
var/on = FALSE
var/brightness_on = 4 //range of light when on
var/flashlight_power = 1 //strength of the light when on
/obj/item/flashlight/Initialize()
. = ..()
@@ -23,16 +26,13 @@
on = TRUE
update_brightness()
/obj/item/flashlight/proc/update_brightness(mob/user = null)
/obj/item/flashlight/proc/update_brightness(mob/user)
if(on)
icon_state = "[initial(icon_state)]-on"
if(flashlight_power)
set_light(l_range = brightness_on, l_power = flashlight_power)
else
set_light(brightness_on)
else
icon_state = initial(icon_state)
set_light(0)
set_light_on(on)
/obj/item/flashlight/attack_self(mob/user)
on = !on
@@ -64,7 +64,7 @@
to_chat(user, "<span class='warning'>[M] doesn't have a head!</span>")
return
if(flashlight_power < 1)
if(light_power < 1)
to_chat(user, "<span class='warning'>\The [src] isn't bright enough to see anything!</span> ")
return
@@ -169,7 +169,7 @@
inhand_icon_state = ""
worn_icon_state = "pen"
flags_1 = CONDUCT_1
brightness_on = 2
light_range = 2
var/holo_cooldown = 0
/obj/item/flashlight/pen/afterattack(atom/target, mob/user, proximity_flag)
@@ -217,7 +217,7 @@
lefthand_file = 'icons/mob/inhands/equipment/security_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/security_righthand.dmi'
force = 9 // Not as good as a stun baton.
brightness_on = 5 // A little better than the standard flashlight.
light_range = 5 // A little better than the standard flashlight.
hitsound = 'sound/weapons/genhit1.ogg'
// the desk lamps are a bit special
@@ -229,7 +229,7 @@
lefthand_file = 'icons/mob/inhands/items_lefthand.dmi'
righthand_file = 'icons/mob/inhands/items_righthand.dmi'
force = 10
brightness_on = 5
light_range = 5
w_class = WEIGHT_CLASS_BULKY
flags_1 = CONDUCT_1
custom_materials = null
@@ -265,7 +265,7 @@
name = "flare"
desc = "A red Nanotrasen issued flare. There are instructions on the side, it reads 'pull cord, make light'."
w_class = WEIGHT_CLASS_SMALL
brightness_on = 7 // Pretty bright.
light_range = 7 // Pretty bright.
icon_state = "flare"
inhand_icon_state = "flare"
worn_icon_state = "flare"
@@ -335,7 +335,7 @@
name = "torch"
desc = "A torch fashioned from some leaves and a log."
w_class = WEIGHT_CLASS_BULKY
brightness_on = 4
light_range = 4
icon_state = "torch"
inhand_icon_state = "torch"
lefthand_file = 'icons/mob/inhands/items_lefthand.dmi'
@@ -351,19 +351,19 @@
lefthand_file = 'icons/mob/inhands/equipment/mining_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/mining_righthand.dmi'
desc = "A mining lantern."
brightness_on = 6 // luminosity when on
light_range = 6 // luminosity when on
/obj/item/flashlight/lantern/heirloom_moth
name = "old lantern"
desc = "An old lantern that has seen plenty of use."
brightness_on = 4
light_range = 4
/obj/item/flashlight/lantern/syndicate
name = "suspicious lantern"
desc = "A suspicious looking lantern."
icon_state = "syndilantern"
inhand_icon_state = "syndilantern"
brightness_on = 10
light_range = 10
/obj/item/flashlight/lantern/jade
name = "jade lantern"
@@ -381,7 +381,7 @@
w_class = WEIGHT_CLASS_SMALL
slot_flags = ITEM_SLOT_BELT
custom_materials = null
brightness_on = 6 //luminosity when on
light_range = 6 //luminosity when on
/obj/item/flashlight/emp
var/emp_max_charges = 4
@@ -442,7 +442,7 @@
desc = "A military-grade glowstick."
custom_price = 50
w_class = WEIGHT_CLASS_SMALL
brightness_on = 4
light_range = 4
color = LIGHT_COLOR_GREEN
icon_state = "glowstick"
inhand_icon_state = "glowstick"
@@ -450,14 +450,17 @@
grind_results = list(/datum/reagent/phenol = 15, /datum/reagent/hydrogen = 10, /datum/reagent/oxygen = 5) //Meth-in-a-stick
var/fuel = 0
/obj/item/flashlight/glowstick/Initialize()
fuel = rand(1600, 2000)
set_light_color(color)
. = ..()
return ..()
/obj/item/flashlight/glowstick/Destroy()
STOP_PROCESSING(SSobj, src)
. = ..()
return ..()
/obj/item/flashlight/glowstick/process()
fuel = max(fuel - 1, 0)
@@ -476,13 +479,13 @@
if(!fuel)
icon_state = "glowstick-empty"
cut_overlays()
set_light(0)
set_light_on(FALSE)
else if(on)
var/mutable_appearance/glowstick_overlay = mutable_appearance(icon, "glowstick-glow")
glowstick_overlay.color = color
add_overlay(glowstick_overlay)
inhand_icon_state = "glowstick-on"
set_light(brightness_on)
set_light_on(TRUE)
else
icon_state = "glowstick"
cut_overlays()
@@ -549,30 +552,56 @@
name = "disco light"
desc = "Groovy..."
icon_state = null
light_color = COLOR_WHITE
brightness_on = 0
light_range = 0
light_range = 4
light_power = 10
alpha = 0
layer = 0
on = TRUE
anchored = TRUE
var/range = null
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
///Boolean that switches when a full color flip ends, so the light can appear in all colors.
var/even_cycle = FALSE
///Base light_range that can be set on Initialize to use in smooth light range expansions and contractions.
var/base_light_range = 4
/obj/item/flashlight/spotlight/Initialize(mapload, _light_range, _light_power, _light_color)
. = ..()
if(!isnull(_light_range))
base_light_range = _light_range
set_light_range(_light_range)
if(!isnull(_light_power))
set_light_power(_light_power)
if(!isnull(_light_color))
set_light_color(_light_color)
/obj/item/flashlight/flashdark
name = "flashdark"
desc = "A strange device manufactured with mysterious elements that somehow emits darkness. Or maybe it just sucks in light? Nobody knows for sure."
icon_state = "flashdark"
inhand_icon_state = "flashdark"
brightness_on = 2.5
flashlight_power = -3
light_system = STATIC_LIGHT //The overlay light component is not yet ready to produce darkness.
light_range = 0
///Variable to preserve old lighting behavior in flashlights, to handle darkness.
var/dark_light_range = 2.5
///Variable to preserve old lighting behavior in flashlights, to handle darkness.
var/dark_light_power = -3
/obj/item/flashlight/flashdark/update_brightness(mob/user)
. = ..()
if(on)
set_light(dark_light_range, dark_light_power)
else
set_light(0)
/obj/item/flashlight/eyelight
name = "eyelight"
desc = "This shouldn't exist outside of someone's head, how are you seeing this?"
brightness_on = 15
flashlight_power = 1
light_range = 15
light_power = 1
flags_1 = CONDUCT_1
item_flags = DROPDEL
actions_types = list()