ID:1894969
 
(See the best response by Ter13.)
Code:


Problem description: Hello! I was trying to create something like an "after-image" effect. When a mob is dashing, I made it so that it creates a mirror image of himself/herself with random rgb mixed into the after image's icon. The project is using pixel movements and a movement loop is being called every tick.

I tried using the image proc, and I've also tried creating an object... Both seemed to lag quite a bit since 20-30 of image/objs were being created. Is there an efficient way of accomplishing this task?

Thanks!


Show the code of what you are doing. Icon procs are likely the source of your problem.
                    var/turf/t = loc
var/image/i=image(src,t)
i.icon+=rgb(rand(250),rand(250),rand(250))
M<<i
spawn(5)
del(i)


This is being called every tick (movement loop)whenever the dashing variable is ticked on in the mob.
i.icon+=rgb(rand(250),rand(250),rand(250))

That's the source of your problem. You really don't want to be adding random colors to icons because icon modification is slow, generates resources that are NEVER garbage collected while the world is running, and they have to be sent over the network to every client that sees them.

Here's what I'd do: create a slightly transparent object where the player is standing, then set its blend mode to additive.

var/obj/o = new(loc)
o.appearance = appearance //NEW FEATURE! appearance duplicates all visual settings in one command!
o.layer -= 0.001 //make it appear a little below the player
o.mouse_opacity = 0 //make them unable to be clicked on
o.alpha = 192 //make it partially transparent
o.blend_mode = BLEND_ADD //give it a neat effect
animate(o,alpha=0,time=5) //make it fade out over 5 ticks
spawn(5)
o.loc = null
//don't call del unless you absolutely have to.
//delete it after 5 ticks


Though, I'd really suggest making this into an object:

effect
parent_type = /obj
afterimage
New(loc,atom/owner,duration=5)
appearance = owner.appearance
layer -= 0.001
alpha = 192
mouse_opacity = 0
blend_mode = BLEND_ADD
animate(src,alpha=0,time=duration)
spawn(duration)
loc = null


Now all you have to do is call:

new/effect/afterimage(loc,src)


somewhere in the proc.
In response to Ter13
Thank you very much!
I would've never known that the icon proc would be the problem without your help.
Best response
I would've never known that the icon proc would be the problem without your help.

Biggest thing I can say on the subject, is that if you are generating icons on demand, it should be avoided where at all feasible. Use atom.color and alpha and blend modes where possible.

It's fine for a limited subset of things like player customization, but ideally you don't actually want to give the player the ability to fully customize things. You lose artistic control over the way your game looks, and that gives players the ability to destroy the visual appeal of your game, thus driving away potentially interested players.

Give players the choice between a limited subset of color customization options that fit the overall palette for your world. This has the added benefit of reducing the dynamic cache size and reducing network overhead while giving the players options for customization without destroying the visual appeal of your game.

It's very rare that generating new icons at runtime will ever be necessary.