However, I'm using this for a map saving library, so it basically gets called for every object in the world. Every object is checked, it loops through each of the variables that the object says it wants to keep track of, checks if those variables have changed, and then records which ones have changed. I imagine this gets pretty cumbersome when there are a lot of items to check.
Any suggestions on how to do this extra-quick? Here's what I'm using at the moment:
mydatum/proc/BuildSavedVarsData(atom/A)
// Get the list of saved vars, and if there aren't any then return null.
var/saved_vars = SavedVars(A)
if(!saved_vars)
return null
// Find out which vars out of the provided list have changed from their default value.
var/list/changed_vars = list()
for(var/v in params2list(saved_vars))
if(A.vars[v] != initial(A.vars[v]) && issaved(A.vars[v]))
changed_vars[v] = A.vars[v]
// If there are changed vars to save...
if(changed_vars.len)
var/params = list2params(changed_vars)
//return params
return params
// If no changed vars to save were found, return null.
return null
I've thought about perhaps having each object in the game record its default values for its saved variables list, then store them in another params set, just to save some processing time during the map saving, but that would likely just transfer the delay to the start of the program, and it would probably take up quite a bit of memory, too.
Personally I'd say doing things this way is just too inefficient.
You're probably better off using a proc to make any var changes to things that you want saved, and have that proc flag when the var has been changed.
I.E:
And just look through the savedvars list to check to see if they were changed or not.