Game component structure

Get answers to all your basic programming questions. No Ogre questions, please!
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Game component structure

Post by drwbns »

Hi guys, I've been looking into how to model a good component architecture but I'm running into an indecision. I want to have different components inherit from a generic IComponent interface and then have a list of registered components available to the game engine but would it be wiser to have a global IComponent* map available with the object it belongs to or to have a IGameObject interface that contains a IComponent* list that each object inherits from? Any thoughts from design gurus here?
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Game component structure

Post by saejox »

IComponent is a good idea because you can use dynamic_cast to find it's real type.
Global map is a terrible idea. GameObject owns component why store Component pointer in a separate list.
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Game component structure

Post by drwbns »

Well, the reason why I thought about storing the ICopmponents in a seperate list is for sending event messages or possible object to object communications. Any other thoughts?
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Game component structure

Post by saejox »

If a GameObject wants to send a message to a another GameObject. This is how:
Receiver GameObject subscribes to such message, sender sends the message without knowing anything about the receiver.
How the message is handle is up to receiver. GameObject delivers the message to its components if it likes to. Gives total ownership of the components to the parent game object.
Of course receiver may send a reply message if needed. This also immediately applies to TCP/UDP communications too.

Of course you can create global lists for both Components. Lack of proper ownership will make your engine get progressively harder to manage.
That's how i designed mine anyways.
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Game component structure

Post by drwbns »

Im also wondering how and where object updates should happen and where events should be taken care of. im guessing to traverse the gameobject list and call update for each object. I guess eventhandler function should be seperate from normal update function. right?
User avatar
saejox
Goblin
Posts: 260
Joined: Tue Oct 25, 2011 1:07 am
x 36

Re: Game component structure

Post by saejox »

drwbns wrote:Im also wondering how and where object updates should happen and where events should be taken care of. im guessing to traverse the gameobject list and call update for each object. I guess eventhandler function should be seperate from normal update function. right?
Yes, no getting around that.
Alternatively, you can have multiple lists for different behavior groups. This is hard to code and easy to mess up.

I keep all in a continuous vector, and never do a id based lookup.
Nimet - Advanced Ogre3D Mesh/dotScene Viewer
asPEEK - Remote Angelscript debugger with html interface
ogreHTML - HTML5 user interfaces in Ogre
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: Game component structure

Post by drwbns »

Ok I'm going to give it a whirl and see what I come up with, thanks for the input :)