ID:2141773
 
(See the best response by Lummox JR.)
I'm storing a list of images so I can reuse them and don't have to recreate images to reduce lag/rending time. I'm wondering whats the best way to pull any image out of the list. I've tried var/image/img=imageresource[1] but it seems the list doesn't resize/reorganize fast enough for this to be viable, perhaps var/image/img=imageresource[imageresource.len]? or is var/image/img=locate(/image) in imageresource the best solution?
Code:
var/list/imageresource=new
proc
RecycleImage(var/image/img,time=0)
set waitfor=FALSE
sleep(time)
img.transform=null
img.pixel_x=null
img.pixel_y=null
img.color=null
img.loc=null
imageresource+=img
FindImage()
var/image/img=locate(/image) in imageresource//This part in particular is what I'm asking about
if(img)
imageresource-=img
return img
else return new/image


Problem description:

Best response
I'd pull from the end of the list for sure.

Also since speed is a concern for you, I would suggest using mutable appearances to reset your image instead of setting each var individually. You could keep a single mutable appearance and use it for all resets.
Alright thx for the input. I'm slightly unfamiliar with mutable appearances, are you suggesting I just set the img.appearance to null or that of an image that is unmodified?
So the newer code works much better.

proc
RecycleImage(var/image/img,time=0)
set waitfor=FALSE
sleep(time)
img.appearance=null
imageresource+=img
FindImage(icon,icon_state)
if(imageresource.len)
var/image/img=imageresource[imageresource.len]
img.icon=icon
img.icon_state=icon_state
imageresource.len--
return img
else return new/image(icon,,icon_state)

One small question on efficiency again.
See imageresource.len--, do you think thats a better approach than imageresource-=img, or is it practically doing the same thing.
I think reducing len is the better approach. While list removal starts at the last element, so -=img would be pretty fast, it's simpler and more direct just to reduce the length.

For mutable appearances, I'm thinking something like this:

var/mutable_appearance/nullimage

proc/RecycleImage(image/img, time=0)
set waitfor = 0
sleep(time)
if(!nullimage) nullimage = new(/image)
img.appearance = nullimage
img.loc = null
imageresource += img
are mutable appearance types only in the beta?
Yes, they're new to 511. You could simply use regular appearances, which would be about the same.

var/image/nullimage

proc/RecycleImage(image/img, time=0)
set waitfor = 0
sleep(time)
if(!nullimage) nullimage = new
img.appearance = nullimage.appearance
img.loc = null
imageresource += img
Very nice. And thx a lot :D