Converts the crackable element to mutable appearances, saves 0.15 seconds of init (#73941)

## About The Pull Request

Instead of passing in an icon as a source to the alpha mask filter, we
can stick a mutable appearance in our overlays list with a render target
set, and use that render target to do our masking. Remember to use "*"
to avoid rendering the crack twice

## Why It's Good For The Game

CPU time
This commit is contained in:
LemonInTheDark
2023-03-13 16:25:40 -06:00
committed by GitHub
parent f77292d55b
commit dd419e77be
2 changed files with 27 additions and 23 deletions
+8 -8
View File
@@ -2,7 +2,7 @@
/datum/element/crackable
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
var/list/icon/crack_icons
var/list/mutable_appearance/crack_appearances
/// The level at which the object starts showing cracks, 1 being at full health and 0.5 being at half health
var/crack_integrity = 1
@@ -11,17 +11,17 @@
if(!isobj(target))
return ELEMENT_INCOMPATIBLE
src.crack_integrity = crack_integrity || src.crack_integrity
if(!crack_icons) // This is the first attachment and we need to do first time setup
crack_icons = list()
if(!crack_appearances) // This is the first attachment and we need to do first time setup
crack_appearances = list()
for(var/state in crack_states)
for(var/i in 1 to 36)
var/icon/new_crack_icon = icon(crack_icon, state)
new_crack_icon.Turn(i * 10)
crack_icons += new_crack_icon
for(var/i in 1 to 35)
var/mutable_appearance/crack = mutable_appearance(crack_icon, state)
crack.transform.Turn(i * 10)
crack_appearances += crack
RegisterSignal(target, COMSIG_ATOM_INTEGRITY_CHANGED, PROC_REF(IntegrityChanged))
/datum/element/crackable/proc/IntegrityChanged(obj/source, old_value, new_value)
SIGNAL_HANDLER
if(new_value >= source.max_integrity * crack_integrity)
return
source.AddComponent(/datum/component/cracked, crack_icons, crack_integrity)
source.AddComponent(/datum/component/cracked, crack_appearances, crack_integrity)