Slick Forums
http://slick.ninjacave.com/forum/

Component inheritance
http://slick.ninjacave.com/forum/viewtopic.php?f=28&t=6782
Page 1 of 1

Author:  hefty [ Sun Nov 03, 2013 10:45 am ]
Post subject:  Component inheritance

So, I've made an abstract class Projectile, with a concrete subclass Bullet.
Projectile extends the Component class.

In my system I've defined
Code:
@Mapper ComponentMapper<Projectile>  pm;


where I use it normally
Code:
final Projectile p = pm.get(e);


However, "p" is null! If I replace Projectile with Bullet, it works fine, but that is not really convenient.
What would be the cause of this, and how would I go about fixing it?

I use the latest trunk of artemis-odb.

Author:  junkdog [ Sun Nov 03, 2013 4:52 pm ]
Post subject:  Re: Component inheritance

Artemis - and Entity-Systems in general - don't have any notion of polymorphic components.

Components are mapped according to the index reported by ComponentType, which in turn is used for mapping component types to entities (componentBits field in Entity) and by the ComponentManager for tracking all component instances.

Conceptually, artemis provides a slot for each component type for every entity. When a component is inserted into an entity, it positions itself in the slot designated for that component (which is why an entity can only have one component per type).

So, when you add a Bullet to the entity, it's inserted into the Bullet slot - whereas the ComponentMapper goes looking for the component in the Projectile slot.

Why do you need to extend Projectile in the first place? Either make Projectile a concrete component or remove it altogether (but I'm guessing there's a reason why it's there).

Author:  hefty [ Sun Nov 03, 2013 9:06 pm ]
Post subject:  Re: Component inheritance

Well, it's not a problem. I was just wondering why that is, and you've answered the question to my satisfaction.
I'm in a midst of converting from hierarchy based entity design to ECS, so I'm not thinking with ECS fully yet.

I have some properties like base damage that I've put in the top class Projectile before. But I'm now redesigning the classes so that I will have a single component that holds the aforementioned properties.
Hopefully, I'm heading toward the right direction.

Author:  junkdog [ Tue Nov 05, 2013 11:56 am ]
Post subject:  Re: Component inheritance

Not sure if it helps, but on some theoretical level, an entity is a Thing made up of properties(/components) intrinsic to the world. As a rule of thumb (my thumb, at least), if something is a concrete thing, it's an entity. Position, Damage and so forth are properties used for describing Things.

You could model the Bullet as follows:
- Collidible
- HitPoints (when it collides, subtract health from the bullet, so that it too "dies")./
- Damage (inflict this on collision, if the other entity has HitPoints, in your Collision system or such)
- Position
- Velocity
- HasOwner (don't want it to collide with your avatar/ship)
- SpriteReference
- Size

So, none of the entities would need an actual Projectile component. In practice however, it sometimes makes sense though.

Author:  hefty [ Tue Nov 05, 2013 9:02 pm ]
Post subject:  Re: Component inheritance

That makes sense, thanks!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/