Game component structure
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Game component structure
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?
-
- Goblin
- Posts: 260
- Joined: Tue Oct 25, 2011 1:07 am
- x 36
Re: Game component structure
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.
Global map is a terrible idea. GameObject owns component why store Component pointer in a separate list.
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: Game component structure
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?
-
- Goblin
- Posts: 260
- Joined: Tue Oct 25, 2011 1:07 am
- x 36
Re: Game component structure
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.
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.
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: Game component structure
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?
-
- Goblin
- Posts: 260
- Joined: Tue Oct 25, 2011 1:07 am
- x 36
Re: Game component structure
Yes, no getting around that.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?
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.
-
- Orc Shaman
- Posts: 788
- Joined: Mon Jan 18, 2010 6:06 pm
- Location: Costa Mesa, California
- x 24
Re: Game component structure
Ok I'm going to give it a whirl and see what I come up with, thanks for the input 
