Cached version of icon_states() proc

This commit is contained in:
Aronai Sieyes
2020-05-06 16:05:59 -04:00
parent aaa86b1ed1
commit d172e2dd04
17 changed files with 45 additions and 26 deletions
+20 -1
View File
@@ -107,7 +107,7 @@ AngleToHue(hue)
Converts an angle to a hue in the valid range.
RotateHue(hsv, angle)
Takes an HSV or HSVA value and rotates the hue forward through red, green, and blue by an angle from 0 to 360.
(Rotating red by 60° produces yellow.) The result is another HSV or HSVA color with the same saturation and value
(Rotating red by 60 produces yellow.) The result is another HSV or HSVA color with the same saturation and value
as the original, but a different hue.
GrayScale(rgb)
Takes an RGB or RGBA color and converts it to grayscale. Returns an RGB or RGBA string.
@@ -899,6 +899,25 @@ proc/ColorTone(rgb, tone)
composite.Blend(icon(I.icon, I.icon_state, I.dir, 1), ICON_OVERLAY)
return composite
GLOBAL_LIST_EMPTY(icon_state_lists)
/proc/cached_icon_states(var/icon/I)
if(!I)
return list()
var/key = "\ref[I]"
var/returnlist = GLOB.icon_state_lists[key]
if(!returnlist)
returnlist = icon_state_lists(I)
GLOB.icon_state_lists[key] = returnlist
if((returnlist?.len == 1) && (returnlist[1] == "")) //It's some icon_state that was generated in-round probably, very likely to be reused \ref soon.
addtimer(CALLBACK(GLOBAL_PROC, .proc/expire_states_cache, key), 600, TIMER_UNIQUE)
return returnlist
/proc/expire_states_cache(var/key)
if(GLOB.icon_state_lists[key])
GLOB.icon_state_lists -= key
return TRUE
return FALSE
proc/adjust_brightness(var/color, var/value)
if (!color) return "#FFFFFF"
if (!value) return color
+1 -1
View File
@@ -94,7 +94,7 @@ proc/age2agedescription(age)
else return "unknown"
/proc/RoundHealth(health)
var/list/icon_states = icon_states(ingame_hud_med)
var/list/icon_states = cached_icon_states(ingame_hud_med)
for(var/icon_state in icon_states)
if(health >= text2num(icon_state))
return icon_state