I'd like to take a minute to address some issues that I've had with such libraries, and offer some advice to anybody planning to use such a library until the issues I address are corrected in the core libraries.
#1: Numeric parsing.
Most of these libraries convert a number to text, and then copy each character individually to apply icon states to each value.
I use a different method, which is significantly faster, and frankly, much quite a lot more portable to another language.
Test method #1: (My approach)
Test1(damage)
var/digit
for(var/fac=1;fac<=damage;fac*=10)
digit = round(damage / fac) % 10
Comparison method:
Test2(damage) //taking the value as raw text
var/digit
for(var/pos=1;pos<=length(damage);pos++)
digit = copytext(damage,pos,pos+1)
Test run of 1,000,000 iterations:
Results:
Test1: 2.742 Total CPU
Test2: 4.754 Total CPU
I could go further into my approach, and the particular optimizations I have used. However, it's all quite a bit better shown than told.
I've increased some overhead slightly in handling my approach with images as opposed to overlays, however, using images allows me to cache the objects and only generate ten/eleven total objects used for the entire world's damage values.
I've also taken the liberty of switching my function over to using the new atom.color feature BYOND 500 has supplied.
#define DMG_LAYER 20
var
list/damage_numbers = newlist(/obj/damage_num{icon_state="0"},/obj/damage_num{icon_state="1"},/obj/damage_num{icon_state="2"},/obj/damage_num{icon_state="3"},
/obj/damage_num{icon_state="4"},/obj/damage_num{icon_state="5"},/obj/damage_num{icon_state="6"},/obj/damage_num{icon_state="7"},
/obj/damage_num{icon_state="8"},/obj/damage_num{icon_state="9"},/obj/damage_num{icon_state="miss"})
//only used for prototyping partial appearance data for damage numbers
obj
damage_num
icon = 'damage.dmi'
layer = FLOAT_LAYER
proc
DamageNum(damage, color=NORMAL_FONT)
var/image/gen = image(null,src,DMG_LAYER)
var/obj/place
if(isnum(damage))
var/offset = 0
var/st
//iterate through damage based on factors of 10
for(var/fac=1;fac<=damage;fac*=10)
place = damage_numbers[round(damage / fac) % 10 + 1] //grab the appearance object
place.pixel_x = -offset * 9 //set the pixel_x of the object
gen.overlays += place //add the overlay to the base object
offset++
gen.pixel_x = src.damage_offx + (offset-1)*9
else
place = damage_numbers[11] //position 11 is just the miss state
gen.overlays += place
//gen.pixel_x = src.damage_offx - 18 //ensure it is centered
gen.color = color //apply multiplicative blending
//gen.pixel_y = src.damage_offy //set the base object's pixel y
//add the base object to src overlays for 1 second
world << gen //this should probably be replaced with a more efficient qualifier
spawn(5)
del gen