Closed appgurueu closed 10 months ago
I know we discussed on the issue, but still wanted to ask:
(The idea is clever, btw. Just seems easy to accidentally break in the future.)
Tested, works.
Do we need to keep the insert order?
I'm not sure. I can imagine keeping the insertion order to be useful, for example when scene nodes need to be drawn in a particular order due to depth sorting. I don't know whether our current implementation relies on this however, since entities, particles, and mapblocks are all depth-sorted by Minetest.
If not, can we perf-compare this with just using an unordered_set (assuming children are unique)?
We probably could, but I'm not sure an unordered set is a good idea.
Pros:
Cons:
rehash
, but you'd have to be careful to do that at the right time to not wreck performance).Just seems easy to accidentally break in the future.
As said on the issue, I believe this is well encapsulated by the add / remove child methods of ISceneNode
. If you want further encapsulation, I can stick Children
and ChildIterator
in their own tiny "class" and make them private
, only allowing access through methods which ensure consistency (though I feel that would be overengineered).
I also don't expect this (the children management in particular) to be touched often, looking at the history.
An attempt at fixing #274, briefly tested with Shadow Forest, but not profiled.
This relies on two invariants in
removeChild
:You can experimentally verify that these seem to hold by replacing the body of
removeChild
with the less efficient:The
assert
s should not be tripped.