Slick Forums

Discuss the Slick 2D Library
It is currently Wed Oct 16, 2019 11:58 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Component inheritance
PostPosted: Sun Nov 03, 2013 10:45 am 
Offline

Joined: Mon Oct 28, 2013 10:41 am
Posts: 4
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.


Top
 Profile  
 
PostPosted: Sun Nov 03, 2013 4:52 pm 
Offline

Joined: Sun Jun 03, 2012 9:21 pm
Posts: 49
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).

_________________
agrotera: bytecode-weaving antiboilerplate lib for artemis. | artemis-odb: bugfixing and performance optimized fork.


Top
 Profile  
 
PostPosted: Sun Nov 03, 2013 9:06 pm 
Offline

Joined: Mon Oct 28, 2013 10:41 am
Posts: 4
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.


Top
 Profile  
 
PostPosted: Tue Nov 05, 2013 11:56 am 
Offline

Joined: Sun Jun 03, 2012 9:21 pm
Posts: 49
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.

_________________
agrotera: bytecode-weaving antiboilerplate lib for artemis. | artemis-odb: bugfixing and performance optimized fork.


Top
 Profile  
 
PostPosted: Tue Nov 05, 2013 9:02 pm 
Offline

Joined: Mon Oct 28, 2013 10:41 am
Posts: 4
That makes sense, thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group