Well, the point is how and where do you call attachCullable(...)
I am currently working on a scene graph implementation.
As you might know, there are proposals to use several independent scene graphs to represent seperate logical relationships
My aim is to implement a generalized graph, that updates itself upon invalidation of a leaf / child. Instead of inserting all nodes into seperate graphs, I want to use the root not as sort of distributor. In the context of programming that means, I don t have to take care about inserting notes into the proper graph, I just tell the scenegraph: "here s a new object, handle it properly"
Inserting a node works like this.
root->attach( some object derived from node + interfaces);
the 'root' node is linked to the root nodes of the sub graphs
e.g.:
root->{octreeroot; lightfrustumhierarchyroot; physicworldroot;...}
The root node passes the objects down the hierarchy, where I want to decide whether the object can be attached to a node or not
e.g.:
root->octreeroot:
check if object is of type 'cullable', insert on success
root->physicworldroot:
check if object is of type physicnode, insert on success
...
Now to implement different different space partition types I could derive octree_node from a spacepartition node
class spacepartition_node : public node, public cullable;class octree_node : public spacepartition_node;class quadtree_node : public spacepartition_node;
And each object that shall be inserted into such a partitiontree has to tell whether is implements the necessary interface required by spacepartition_node;
With my previous proposal:
bool object::is_attachable_to( node& n){return (dynamic_cast<spacepartition_node*>(&n) != 0)}
Using your approach requires me to insert the nodes into each subgraph seperately, this on the one hand eleminates the need of RTTI completely, on the other hand it seperates the graphs, which is what I wanted to avoid in the first place.
Once an object is invalidated it notifies its parents, the parents try to reattach the object, on failure they either propagate it to their parents, or try to reinsert it into the subgraph through the subgraph's root node, this behaviour can be controlled via a flag set in the base class node at initialization.
This way I can keep the amount of graph traversion at a minimum even for large scenes.
I also don t have to keep track about invalidated objects, since that job was moved to the scene graph in the first place.
I am really undecided about the way to go. On the one hand the RTTI causes some overhead, on the other hand some additional work on the CPU won't hurt that much, since the 3d engine where I want to integrate it into will be fillrate limited anyways.
[Edited by - Basiror on June 8, 2007 7:08:21 AM]