ID:132644
 
In my games I use a base icon and then swap out all its colors to represent different teams or different areas of the map. The problem is that using SwapColor() to change multiple colors creates a large number of unused icons in the cache. I am running into problems in Regressia as new icon operations fail when the single-session cache becomes too large. What I would like would be some way to call a single proc to make all my palette changes at once:

var/list/color_changes = list(
"#fff" = "#000",
"#f00" = "#00f",
"#0f0" = "#f00",
"#00f" = "#0f0",
"#000" = "#fff",
)
var/icon/I = yada_yada_yada
I.SwapPalette(color_changes)

// or

var/list/original_palette = list("#fff", "#f00", "#0f0", "#00f", "#000")
var/list/new_palette = list("#000", "#00f", "#f00", "#0f0", "#fff")
var/icon/I = yada_yada_yada
I.SwapPalette(original_palette, new_palette)
I've had a few cache problems with SwapColor() myself.

In Decadence I use a base torso icon. This torso is used to create two icons, one for red team and the other for blue team. These icons are created when the world starts. Sometimes when people log in it will seem like the created icon is incomplete. It will be the correct color, but it'll just point south with no other frames of animation.

Removing and reapplying the same torso icon seems to fix the problem.
Calling SwapColor() multiple times should not impact the cache size because an icon should only be stored in the cache once it's committed to a cache file--that is, if you use fcopy_rsc() or assign it to an atom.icon, or if you do some other operation that implicitly calls fcopy_rsc(). However I do see that your swapping might be problematic because one thing SwapColor() doesn't do is account for cases where you might want to change A to B and B to C without changing A to C. It might be interesting to support a variant of SwapColor() that uses lists instead of single colors, though since we don't use palettes internally I can't say it'd be fast.

Lummox JR