Quote:Original post by snk_kid
[thats abit of silly idea, constructors are mean't to setup the enviroment for the state invariant, better idea is to sperate allocation and initialization instead,
But in my method A, allocation and initialization are separate:
CObject *obj = new CObject();obj->create(...);obj->destroy(...);obj->create(...);obj->destroy(...);delete obj;
... will have the object allocated once, but used twice.
I see your idea with placement new, but quite frankly i don't like it much. It's okay for code inside a memory manager, but i want a consistant way to allocate all kind of objects in my engine, not only with the scene graph. And sometimes, some objects are just too simple to bother with a memory manager at all. Let's imagine a CTriangle class that only contains 3 vertices. Wouldn't you prefer to simply do a "new" to allocate the triangle; or would you bother calling a manager/factory in order to allocate one ?
Quote:Original post by snk_kid
this looks unmanageable especially when you some kind of memory manager that is mean't take of it.
But only specific objects really need a memory manager. What should i do for all the other "common" objects in the engine ?
Quote:Original post by snk_kid
i don't think B is to much it seems perfectly fine but i don't think Light needs to be an interface, its fine as an abstract class (meaning it could have some implementation that is common to all light types).
Agreed, i wrote "interface" but i really had an abstract class in mind.
Quote:Original post by CoffeeMug
Scene graph's job is exactly that: maintaining a graph of the scene. It is *not* instantiating objects, managing their memory, loading data from resources, etc.
That's a very interesting thought. What about this:
CObject *obj = sceneFactory->newObject();obj->create(model);scene->getRoot()->addObject(obj);
Although i'm not quite sure about the 3rd line. It would take a node of the scene graph (getRoot()) and add a child object to it. On the other hand it might also want to do some additional work on the object, that is specific to the scene manager; so this approach could also work:
scene->addObject(scene->getRoot(), obj);
Or i can also separate adding the object to the scene graph, and linking an object to a node, like:
scene->addObject(obj);scene->getRoot()->addObject(obj);
In the context of a scene graph tree, which solution do you prefer?
Quote:Original post by CoffeeMug
you'll probably need to decouple the scene graph from the renderer by adding another class in the middle.
Hum, that's going to add another layer of complexity to an engine that is already pretty complex.. i don't really like the sound of it :(
Y.