Paul Sinnett | 17 Oct 2006 07:08
Picon

Re: strategies/patterns for composition

On Mon, 2006-10-16 at 17:30 -0700, Jamie Fristrom wrote:
> So - we've all heard "inheritance bad, composition good" - what I'd
> like to know is what are people's favorite strategies for composition,
> in particular with game entities/actors/pawns (or whatever your engine
> calls them)? 

Jamie,

Have you read Mick West's Inner Product column "Evolve your hierarchy"
in the March 2006 issue of Game Developer? It's more an overview of the
subject than a specific implementation recipe but it might illuminate
some areas.

I suggested using such a system on a recent project but initially there
was a lot of resistance. Later, we adopted components for collision and
AI which worked fairly well. I expect some of those team members will
expand on that in future projects.

The way we implemented it was the table / database approach you
outlined. For example, objects that needed collision had a collision
object. But when they were created, the collision object was added to a
collision world. So rather than having a single collection of all
objects in the game we had a collection for each behavioural aspect. The
main loop wasn't a sequence of loops through a master entity list, but a
single loop through a sequence of component specific lists. That way we
didn't have to query because the list itself was the cached result set.

It wasn't really as neat as that since it evolved as we went along - but
that was what it was evolving into as far as I can tell. We actually had
collision pointers in the entity too although we didn't really need them
as it turned out.

_______________________________________________
sweng-gamedev mailing list
sweng-gamedev <at> lists.midnightryder.com
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com


Gmane