Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am currently familiarizing myself with the entity component paradigm.

For an example, take a collision system, that detects if entities collide and if they do let them explode.

So the collision system has to test collision based on the position component and then set the state of those entities to exploding.

But what if the "effect" (setting the state to exploding) is different for different entities? For example, a ship fades out while for an asteroid a particle system must be created. Since entities and components are only data, this must happen in some system.

The collision system could do it, but then it must switch over the entity type, which in my opinion is a cumbersome and difficult to extend solution.

So how do I trigger "entity type dependend" updates on an entity?

share|improve this question
    
You might wanna see a concrete example like this code.google.com/p/gamadu-starwarrior/source/browse/src/com/… which was implmented using Artemis Entity System gamadu.com/artemis/tutorial.html –  XiaoChuan Yu Nov 22 '12 at 0:31

1 Answer 1

up vote 6 down vote accepted

First things first, I would use an event-driven system rather than one based on states. Setting a state to "exploding" is clunky and rather useless, since an explosion is a one-time event.

Secondly, you can make use of what I like to call behaviour components. These components are programmed to react to certain events, like "exploded". Adding these components to an entity allows you to easily change how the entity responds to events. In this case, you could create a FadesOutBehaviour component that can be customized to different event types, fade times, etc. Then, whenever an entity with that component is blown up, it will fade out. The same goes for a SpawnsParticlesBehaviour component.

What I would really do in this case is give entities components that would fit in "real life". For example, I would forgo creating components to enable fading or particle spawning and instead use components like FuelTank (I can't think of one that would work for a spaceship fading; that doesn't even make sense :P). An entity containing FuelTank is susceptible to catching on fire, exploding, and at the same time can keep track of how much fuel it has left. The kinds of data a FuelTank would store would include capacity, damage, name of the mesh it is linked to inside the model, etc. Structuring entities like this makes more sense to me.

share|improve this answer
    
So these components have the logic to fade themselves out or there's a FadesOutSystem to do that? –  Luke B. Nov 22 '12 at 0:25
    
Whichever one you like. The way I explain with FuelTank is better suited to a components-as-data approach. –  Boreal Nov 22 '12 at 0:44
    
Ok, an entity containing a FuelTank is catching fire when destroyed. How and by whom is this decided and the "fire" created? Does the collision system have to test if an destroyed entity contains a fuel tank? –  Nathan Nov 22 '12 at 6:46
1  
This is how I would implement the FuelTank behaviours: You have a system that manages the various damages game objects can receive. The system monitors collision events between projectiles and the game objects; the collision subsystem is only responsible for broadcasting collision events. When the damage system receives an entity-entity collision event, it checks if one of the entities has a Projectile component and the other has a FuelTank. If so, the FuelTank is damaged, possibly creating a fire particle system or an explosion. The damage system could also monitor vehicle damage, etc. –  Boreal Nov 23 '12 at 0:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.