Skip to main content
GameDev.net gamedev.net
🔒 Locked

A scenemanager's objects not soaked in Render-stuff

Started by Mercenarey Jul 25, 2010 at 9:40 AM 3 replies 1.5k views
Original Post
Mercenarey
Mercenarey
Let us start with a diagram of the structure, so you know what the hell I am talking about:
scenemanager_structure.jpg



I have designed a SceneManager, that I use for my world. It is divided into quadrants, which each hold the objects belonging there. When I want a list of visible objects, I call a GetVisibleObjects()-method, which takes the "seeing" camera as argument, and which returns a list of visible objects.

So far, all I have used the scenemanager for, has been for rendering. And therefore, the objects I have been storing, had rendering in some form (a Render()-method) attached to them. I knew when I designed my RenderObject, that it would give problems conceptually, because the RenderObject derived from a more basic object, and I was forced to derive again from it with classes, for which rendering was irrelevant.

My problem now is, that I want to use the SceneManager for more. For example, I could imagine integrating it with a collision system (or rather, let it become a collision system as well).

Now I have this stupid render-class stuck in the middle of my object-hierarchy, and all it is good for, is rendering, and it is not directly relevant to other objects, that have to derive from it, to participate in the SceneManager, and that irks me. For instance, in my structure, StaticCollisionObject now derives from RenderObject, and that is an eye sore to me.
Also, on the server-side, I don't need rendering at all, meaning RenderObject becomes completely obsolete here.

But then I have thought about the alternatives. If I return a list of BaseObjects, how will I be able to get to rendering in any form? I came up with different solutions:

- virtual bool BaseObject::Render() = 0;
By moving this method from RenderObject to BaseObject, I would maybe be able to get rid of the RenderObject (at least at a so low level as I have it now).
But it is ugly to have it at that level. I would prefer to have methods only directly relevant to each object.

- virtual bool BaseObject::RegisterInformation(ENUM informationnature=RENDERING) = 0; This will call the virtual method until it hits the object that acknowledges RENDERING, and this object will place itself in a singleton register as itself (RenderObject), and from there, the caller can retrieve the list of that specific object.
But it will mean, that through the ENUM informationnature, render-information will again have leaked through. Also I don't like the elaborate registering system.

- put an object's render-information (BaseObjectGraphics, this class would need a link to the BaseObject) in a seperate table, retrieve all the visible objects from SceneManager, and thereafter retrieve the corresponding render-information from the table with the BaseObject::GetID().
It is a possibility. The object will be completely fragmented.

- leave it as it is.

--------------

Right now I am leaning towards either keeping the information seperately in another table and linking through ID or leaving as it is.

--------------

Have any of you encountered this problem? And what was your solution to keep the objects logically intact, and to avoid superflouous classes/methods?
Quote: CalvinI am only polite because I don't know enough foul language Quote: <span st
Scourage
Scourage
So from your description, you're problem is using inheritance to add a capability vs using composition.

A good article on composition vs inheritance is: http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

Cheers,

Bob

[size="3"]Halfway down the trail to Hell...
Mercenarey
Mercenarey
Sorry for the late reply from me.
After a week or so with no reply, I gave up on this thread.

Yes, sadly I have to admit, that what you pointed out was exactly my problem :)

I created a new structure like this:
new structure


Here BaseCollisionObject will have to replicate what is needed of the Base-/MoveObject interfaces. In return I get a completely independent CollisionObject, that can take the place of the old RenderObject.
Quote: CalvinI am only polite because I don't know enough foul language Quote: <span st
LorenzoGatti
LorenzoGatti
Quote:
Original post by Mercenarey
Sorry for the late reply from me.
After a week or so with no reply, I gave up on this thread.

Yes, sadly I have to admit, that what you pointed out was exactly my problem :)

I created a new structure like this:
new structure


Here BaseCollisionObject will have to replicate what is needed of the Base-/MoveObject interfaces. In return I get a completely independent CollisionObject, that can take the place of the old RenderObject.

Do you mean that some CollisionObjects aren't MoveObjects and some MoveObjects aren't CollisionObjects? Which ones? why do you think separating these classes is important? What is BaseCollisionObject, and why is it a base class of both important classes? What is poor lonely BaseObject used for? How can a CollisionObject class be similar to a RenderObject class?

I think a composition-based approach would get rid of most of these questions: objects of a single class would own appropriate components or not, without spurious dependencies between unrelated classes.
Omae Wa Mou Shindeiru
Mercenarey
Mercenarey
I made a BaseCollisionObject because I want it to be a base for both 2D and 3D collision.
Im developing an RTS atm, and the world is rendered in 3D, while the collision system will run in 2D.

So instead of CollisionObject it will be Collision2DObject and Collision3DObject.

Also, I wished to isolate the duplication of MoveObject's interface in the BaseClass.

A MoveObject does not necessarily have to be in the collisionsystem. It can be a light or a camera.

Notice that BaseCollisionObject is *not* a base class of MoveObject. The diamond symbolizes an aggregation, not inheritance.
Quote: CalvinI am only polite because I don't know enough foul language Quote: <span st

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.