Learning about components, and I encountered this concept of a ‘dirty node’. Basically, a scene node stores its position relative to the root scene node (aka the ‘world transform’ of the scene node), and when its local position (relative to its parent scene node) changes, the world transform is no longer accurate. That inaccuracy means the scene node is ‘dirty’, and it gets ‘cleaned’ by updating the stored world transform with Node::UpdateWorldTransform()
.
Components, which are attached to nodes, have the option (i.e. the implementer of a Component has the option) to respond to a node being made dirty, with the virtual function Component::OnMarkedDirty()
. However, the calls to OnMarkedDirty()
in Node.cpp seem inconsistent. There are only three calls:
- in
Node::AddListener()
, when a component is added as a listener to a node then if the node is dirtyOnMarkedDirty()
will be called right away; supposedly the whole point of components ‘listening’ to arbitrary nodes is for being able to respond when those nodes become dirty (or enabled/disabled) - that idea is backed up by the second call, in
Node::MarkDirty()
(name is self-explanatory), where all of the node’s listener components callOnMarkedDirty()
- the third call, however… is in
Node::AddComponent(...)
; but nowhere do I see a component being added as a listener to the node that owns it
Note: yes, nodes both own components, and have a list of other (owned and unowned) components called ‘listeners’. Separate lists
So, why is OnMarkedDirty()
called in AddComponent()
, if a component doesn’t listen to its own node unless explicitly told to?