default factory implementation
default factory implementation
it seems a bit backwards for the default scene node factory and the default animator factory to use the scenemanager as the real factory instead of vice-versa. i was wondering if there is a reason for this? or is the implementation planned that way just not implemented yet? there would be definate benefits of swapping the two.
looking into it deeper, i think we could leverage the new IAttributes class to shift focus of object creation to the factories. to do this, the add*() factory methods need one more parameter (defaults to null) that is a pointer to an IAttributes instance. in the scenemanager, the method turns the parameters passed into it into an IAttributes instance which in turn is then passed into the factory method. taking ISceneNodeFactory and CCubeSceneNode as an example:
becomes
the appropriate line in CDefaultSceneNodeFactory becomes:
and CSceneManager.addCubeSceneNode() becomes something like:
thoughts? potentially even a new constructor for each node that takes the manager, parent, and IAttributes.
Code: Select all
virtual ISceneNode* addSceneNode(ESCENE_NODE_TYPE type, ISceneNode* parent=0) = 0;
Code: Select all
virtual ISceneNode* addSceneNode(ESCENE_NODE_TYPE type, ISceneNode* parent=0, IAttributes* attrib=0) = 0;
Code: Select all
case ESNT_CUBE:
ISceneNode* node=CCubeSceneNode(10, parent, Manager,-1);
node->drop();
node->deserializeAttributes(attrib);
return node;
Code: Select all
if (!parent)
parent = this;
IAttributes* attrib=new IAttributes();
// set the attributes here based on the params passed in
// create the node
ISceneNode* node = getDefaultSceneNodeFactory()->addSceneNode(ESNT_CUBE,parent,attrib);
node->drop();
attrib->drop();
return node;
take it one step further... on ISceneManager implement a getSceneNodeFactory() method that takes a node type or node name, finds the first factory that can build it starting with the highest index going backwards down to the default, and returns that factory. this would allow subclassing of the default types at the rendering engine level simply by adding a new scenenodefactory that can build that type.
i love factories
i love factories