More icon caching (#3078)

changes:

Human-type hair (facial & head), eyes, and lips are now cached in SSicon_cache.
Underwear, undershirts, and socks are now cached in SSicon_cache.
Removed forced icon regen for update_body - if this actually did anything, the cache key for these icons needs to be made more detailed.
Organs now fully use SSoverlays to apply overlays (previously they partially used it, which may have caused bugs).
A couple of hair styles (bald, shaved) are pretty common, so this should remove/reduce the overhead of constantly regenerating their icons. Also means that BST's icons only really need to be generated once.
This commit is contained in:
Lohikar
2017-07-18 04:22:01 -05:00
committed by skull132
parent 32c5c07371
commit 8fcad605ee
3 changed files with 88 additions and 39 deletions
+54 -17
View File
@@ -54,23 +54,38 @@
/obj/item/organ/external/head/get_icon()
..()
overlays.Cut()
cut_overlays()
if(!owner || !owner.species)
return
if(owner.species.has_organ["eyes"] || (owner.species.vision_organ && owner.species.has_organ[species.vision_organ]))
var/obj/item/organ/eyes/eyes = owner.internal_organs_by_name["eyes"] || owner.internal_organs_by_name[species.vision_organ]
if(eyes && species.eyes)
var/icon/eyes_icon = new/icon('icons/mob/human_face.dmi', species.eyes)
if(eyes)
eyes_icon.Blend(rgb(eyes.eye_colour[1], eyes.eye_colour[2], eyes.eye_colour[3]), ICON_ADD)
else
eyes_icon.Blend(rgb(128,0,0), ICON_ADD)
var/eyecolor
if (eyes.eye_colour)
eyecolor = rgb(eyes.eye_colour[1], eyes.eye_colour[2], eyes.eye_colour[3])
var/cache_key = "[species.eyes]_[eyecolor || "nocolor"]"
var/icon/eyes_icon = SSicon_cache.human_eye_cache[cache_key]
if (!eyes_icon)
eyes_icon = new/icon('icons/mob/human_face.dmi', species.eyes)
if(eyecolor)
eyes_icon.Blend(eyecolor, ICON_ADD)
else
eyes_icon.Blend(rgb(128,0,0), ICON_ADD)
SSicon_cache.human_eye_cache[cache_key] = eyes_icon
mob_icon.Blend(eyes_icon, ICON_OVERLAY)
overlays |= eyes_icon
add_overlay(eyes_icon)
if(owner.lip_style && (species && (species.appearance_flags & HAS_LIPS)))
var/icon/lip_icon = new/icon('icons/mob/human_face.dmi', "lips_[owner.lip_style]_s")
overlays |= lip_icon
var/icon/lip_icon = SSicon_cache.human_lip_cache["[owner.lip_style]"]
if (!lip_icon)
lip_icon = new/icon('icons/mob/human_face.dmi', "lips_[owner.lip_style]_s")
SSicon_cache.human_lip_cache["[owner.lip_style]"] = lip_icon
add_overlay(lip_icon)
mob_icon.Blend(lip_icon, ICON_OVERLAY)
for(var/M in markings)
@@ -90,18 +105,40 @@
if(owner.f_style)
var/datum/sprite_accessory/facial_hair_style = facial_hair_styles_list[owner.f_style]
if(facial_hair_style && facial_hair_style.species_allowed && (species.get_bodytype() in facial_hair_style.species_allowed))
var/icon/facial_s = new/icon("icon" = facial_hair_style.icon, "icon_state" = "[facial_hair_style.icon_state]_s")
if(facial_hair_style.do_colouration)
facial_s.Blend(rgb(owner.r_facial, owner.g_facial, owner.b_facial), ICON_ADD)
overlays |= facial_s
var/facialcolor
if (facial_hair_style.do_colouration)
facialcolor = rgb(owner.r_facial, owner.g_facial, owner.b_facial)
var/cache_key = "[facial_hair_style.icon]_[facial_hair_style.icon_state]_[facialcolor || "nocolor"]"
var/icon/facial_s = SSicon_cache.human_beard_cache[cache_key]
if (!facial_s)
facial_s = new/icon("icon" = facial_hair_style.icon, "icon_state" = "[facial_hair_style.icon_state]_s")
if(facial_hair_style.do_colouration)
facial_s.Blend(facialcolor, ICON_ADD)
SSicon_cache.human_beard_cache[cache_key] = facial_s
add_overlay(facial_s)
if(owner.h_style && !(owner.head && (owner.head.flags_inv & BLOCKHEADHAIR)))
var/datum/sprite_accessory/hair_style = hair_styles_list[owner.h_style]
if(hair_style && (species.get_bodytype() in hair_style.species_allowed))
var/icon/hair_s = new/icon("icon" = hair_style.icon, "icon_state" = "[hair_style.icon_state]_s")
if(hair_style.do_colouration && islist(h_col) && h_col.len >= 3)
hair_s.Blend(rgb(h_col[1], h_col[2], h_col[3]), ICON_ADD)
overlays |= hair_s
var/haircolor
if (hair_style.do_colouration && istype(h_col) && h_col.len >= 3)
haircolor = rgb(h_col[1], h_col[2], h_col[3])
var/cache_key = "[hair_style.icon]_[hair_style.icon_state]_[haircolor || "nocolor"]"
var/icon/hair_s = SSicon_cache.human_hair_cache[cache_key]
if (!hair_s)
hair_s = new/icon("icon" = hair_style.icon, "icon_state" = "[hair_style.icon_state]_s")
if(hair_style.do_colouration && islist(h_col) && h_col.len >= 3)
hair_s.Blend(haircolor, ICON_ADD)
SSicon_cache.human_hair_cache[cache_key] = hair_s
add_overlay(hair_s)
compile_overlays()
return mob_icon