ID:1215665
 
Keywords: icon, overlays
(See the best response by Ter13.)
Code:
mob/proc
Load_Overlays()
var/L[0]
var/obj/h1
var/h2
var/h3
var/h4
var/h8
var/h5
var/h9
var/v1='Vaimask.dmi'
var/v2='Vaimask2.dmi'
var/v3='Vaimask3.dmi'
src.overlays=0
src.underlays=0
if(src.race=="Hollow")
if(src.hollowtype == "strong")
src.overlays += /obj/nstrong1
src.overlays += /obj/nstrong2
src.overlays += /obj/nstrong3
src.overlays += /obj/nstrong4
if(src.hollowtype == "meno")
src.icon='blank.dmi'
src.overlays += /obj/Menos/m1
src.overlays += /obj/Menos/m2
src.overlays += /obj/Menos/m3
src.overlays += /obj/Menos/m4
src.overlays += /obj/Menos/m5
src.overlays += /obj/Menos/m6
src.overlays += /obj/Menos/m7
src.overlays += /obj/Menos/m8
if(src.hollowtype == "adjucha")
src.icon = 'blank.dmi'
src.overlays += /obj/Adjucha/a1
src.overlays += /obj/Adjucha/a2
src.overlays += /obj/Adjucha/a3
src.overlays += /obj/Adjucha/b1
src.overlays += /obj/Adjucha/b2
src.overlays += /obj/Adjucha/b3
src.overlays += /obj/Adjucha/c1
src.overlays += /obj/Adjucha/c2
src.overlays += /obj/Adjucha/c3
src.overlays += /obj/Adjucha/d1
src.overlays += /obj/Adjucha/d2
src.overlays += /obj/Adjucha/d3
src.overlays += /obj/Adjucha/e1
src.overlays += /obj/Adjucha/e2
src.overlays += /obj/Adjucha/e3
src.overlays += /obj/Adjucha/f1
src.overlays += /obj/Adjucha/f2
src.overlays += /obj/Adjucha/f3
return
if(src.pants)
h2='BleachPants.dmi'
if(src.shirt)
h5='BleachShirt.dmi'
if(src.shoes)
h8='Bleachshoes.dmi'
if(src.jacket)
h9='Jacket.dmi'
switch(src.hair_type)
if(1)
h1='hair1.dmi'
if(2)
h1='hair2.dmi'
if(3)
h1='hair3.dmi'
if(4)
h1='hair4.dmi'
if(5)
h1='hair5.dmi'
if(17)
h1='hair1.dmi'
switch(src.arrancarmask)
if(1)
h3='arrancar1.dmi'
if(2)
h3='arrancar2.dmi'
if(3)
h3='arrancar3.dmi'

if(h1)
h1+=rgb(src.hair_red,src.hair_green,src.hair_blue)
var/obj/j1=new/obj
j1.pixel_y=3
if(src.hair_type==5)j1.pixel_y=5
j1.icon=h1
j1.layer=MOB_LAYER+2

L+= j1
if(src.ressurection&&src.ressurectiontype=="Skeleton"||src.ressurection&&src.ressurectiontype=="Del Toro")
L-=j1
if(src.trans)
L+=/obj/ssj1
spawn(2)
del j1
if(h3)
if(!src.ressurection)
var/obj/j3=new/obj
j3.pixel_y=1
j3.icon=h3
j3.layer=MOB_LAYER+3
L+= j3
if(src.arrancarmask==1)
var/obj/j3s=new/obj
j3s.pixel_y=8
j3s.icon='arrancar1.1.dmi'
j3s.layer=MOB_LAYER+3
L+= j3s
spawn(2)
del j3s
spawn(2)
del j3
if(src.maskon&&src.maskuses>9)
v1+=rgb(src.vstripe_red,src.vstripe_green,src.vstripe_blue)
v2+=rgb(src.vmask_red,src.vmask_green,src.vmask_blue)
v3+=rgb(src.veye_red,src.veye_green,src.veye_blue)
var/obj/j1=new/obj
j1.icon='Vaimask4.dmi'
j1.overlays+=v1
j1.overlays+=v2
j1.overlays+=v3
j1.layer=MOB_LAYER+2

L+= j1
spawn(2)
del j1
if(h4&&src.maskon&&src.maskuses<=9)
var/obj/j2=new/obj
j2.pixel_y=3
//j2.icon='Vaizardmaskhalf.dmi'
j2.layer=MOB_LAYER+3
L+= j2
spawn(2)
del j2
if(special)L+=special
if(undershirt) L+=undershirt
if(h2)
h2+=rgb(src.pants_red,src.pants_green,src.pants_blue)
L+=h2
if(h5)
h5+=rgb(src.shirt_red,src.shirt_green,src.shirt_blue)
L+=h5
if(h8)
h8+=rgb(src.shoes_red,src.shoes_green,src.shoes_blue)
L+=h8
if(h9)
//h9+=rgb(src.jacket_red,src.jacket_green,src.jacket_blue)
var/obj/j2=new/obj
j2.pixel_y=3
j2.icon='Jacket.dmi'
j2.icon+=rgb(src.jacket_red,src.jacket_green,src.jacket_blue)
j2.layer=MOB_LAYER+5
L+= j2
spawn(2)
del j2
//continues like that for awhile


Problem description:

I use a Load_Overlay() proc to give the players/npcs all the right overlays. The icon/proc/RscFile and mob/proc/Load_Overlays are taking up the most CPU. Is there something wrong with the codes?
            v1+=rgb(src.vstripe_red,src.vstripe_green,src.vstripe_blue)
v2+=rgb(src.vmask_red,src.vmask_green,src.vmask_blue)
v3+=rgb(src.veye_red,src.veye_green,src.veye_blue)


        if(h2)
h2+=rgb(src.pants_red,src.pants_green,src.pants_blue)
L+=h2
if(h5)
h5+=rgb(src.shirt_red,src.shirt_green,src.shirt_blue)
L+=h5
if(h8)
h8+=rgb(src.shoes_red,src.shoes_green,src.shoes_blue)
L+=h8
if(h9)
...
j2.icon+=rgb(src.jacket_red,src.jacket_green,src.jacket_blue)


There's your problem. Bleding is slow, especially without a caching to back this stuff up. I suggest you start storing values to be reused later or disable this feature all together and provide a limited number of colors. No one will be able to tell the difference between Ultramarine and Duke Blue in your game.
Are you recommending that I make a select few colors and put it in .dmi file?
Creating new objects and icons in byond is among the more intense of the built-in operations. What you are doing is ugly, but I wouldn't say it's wrong.

Also, why are you deleting j2? It's not inside of spawn(), so the deletion is immediate.
In response to Ter13
Ter13 wrote:
Creating new objects and icons in byond is among the more intense of the built-in operations. What you are doing is ugly, but I wouldn't say it's wrong.

Also, why are you deleting j2? It's not inside of spawn(), so the deletion is immediate.

Since my base is kinda tall, when I iconned the hair (and other stuff) it didn't fit to base perfectly so I did a little pixel offset by creating a new obj. Is that wrong?
Best response
No, it's not wrong really, but deleting the obj limits your ability to manipulate that overlay, and just adds unnecessary overhead to your function. For the most part, it's best to let the garbage collector handle object cleanup except in the case of circular references.
var/list/L=new
L+=typesof(/obj/hair)
for(var/y in L)
if(length(typesof(y))>1)
L.Remove(y)
var/x1=pick(L)
src.hair_type=x1
src.overlays+=x1

I created different colored hair for icons, will this lower the RscFile proc for when npcs randomly generate hair instead of them randonmly blending?