Page 1 of 1

A workable way to copy custom parameters?

Posted: Wed Feb 11, 2009 1:23 pm
by matches81
Hi there!

I'm currently trying to clone a hierarchy within a scene (i.e. clone a SceneNode with all children and attached objects) and I've encountered a problem: There's no sensible way to copy the custom parameters, because I don't have access to the CustomParameterMap each Renderable has.
The only "solution" I can come up with is to actually iterate over the size_t space and try to get the parameter, catching any exceptions... quite a lot of work when the number of actual parameters is probably significantly lower.
One idea would be to provide a copy of the CustomParameterMap accessible via a function (e.g. map<size_t, Vector4> Renderable::GetCustomParameterMap())... or, if that's impossible for some reason a function that returns a vector / list / whatever containing all used custom parameter indices.

anything wrong with that request?

Re: A workable way to copy custom parameters?

Posted: Wed Feb 11, 2009 6:08 pm
by _tommo_
It looks like a good request to me... anything that can be set should be "get-able".

BTW, why it is a map? map<unsigned int, something_other> isn't exactly identical to vector<something_other>? :roll:

Re: A workable way to copy custom parameters?

Posted: Thu Feb 12, 2009 1:15 am
by matches81
AFAIK it is a map because you can address these custom parameters in your materials using the index you've assigned to them.
I haven't actually looked into using them yet, I just wanted to be as thorough as possible when cloning the hierarchy and these custom parameters seemed like something I should copy.

Re: A workable way to copy custom parameters?

Posted: Thu Feb 12, 2009 5:02 pm
by nbeato
_tommo_ wrote:BTW, why it is a map? map<unsigned int, something_other> isn't exactly identical to vector<something_other>? :roll:
No it isn't identical. From a usage standpoint, the syntax is similar, that is it. My guess is that the parameters are arbitrarily assigned by the material programmer. I could make all of my parameters for a particular effect be 1000-1100 and only use 5 of the values in that range. With a vector, provided it is size 1100, traversing my 5 items will take 1100 loop iterations. With a map, it will take 5 iterations. Hence, traversing is O(max(params)) vs. O(count(params)). Space-wise, the vector require O(max(params)) storage while the map is O(count(param)) storage, so the footprint makes a difference. The vector slightly wins in random access time. A vector is O(1) while a map is O(log count(params)), which for 5 params is 3 iterations. The vector wins if your profiler tells you that random access is killing your program. Otherwise, the map makes much sense. :roll:

Re: A workable way to copy custom parameters?

Posted: Thu Feb 12, 2009 5:36 pm
by _tommo_
Yeah should've been obvious... maybe i worked too much with C arrays :lol: