Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 3:04 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Tags vs. components
PostPosted: Sun Sep 16, 2012 5:04 pm 
Offline

Joined: Sun Aug 05, 2012 3:37 pm
Posts: 23
I've got a portion of my system where a lot of entities share one aspect (health), but diverge on other things (such as: some have shields, some are bullets, some have temporary life, etc.) I've been using group tags to determine what kind of group an entity belongs in so I can take appropriate action. For example, when I have bodies collide in the physics engine, I need to determine if the related entity has shields or not, and then apply damage to that or directly to health if shields are not present.

In looking at this, I am wondering about the efficiency of using a tag versus defining an "EntityGroup"-style component that would retrieve this type of information for these entities. What's the benefit of using a tag versus using a component? I think these will accomplish the same thing, but I get the feeling the component approach will induce less overhead.

Thanks,
--tim


Top
 Profile  
 
 Post subject: Re: Tags vs. components
PostPosted: Sun Sep 16, 2012 11:43 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
You can implement tags using component and a system, no problem.


Top
 Profile  
 
 Post subject: Re: Tags vs. components
PostPosted: Mon Sep 17, 2012 5:11 pm 
Offline

Joined: Mon Sep 17, 2012 5:01 pm
Posts: 1
I have been using an entity system I built myself that is very similar to Artemis. I included a method on Entity named HasComponent(), that allows a system to query an entity to see if it has a component of a specific type. In this manner, you could them have your system process all entities with a Health component, and then query each to see if it had a Sheilds component, in this way you wouldn't need a tag at all.


Top
 Profile  
 
 Post subject: Re: Tags vs. components
PostPosted: Mon Sep 17, 2012 5:54 pm 
Offline

Joined: Sun Aug 05, 2012 3:37 pm
Posts: 23
I guess the one disadvantage to this approach is that you lose the ability to collectively retrieve a group. I have a mini-radar HUD system that gets all objects that are part of the barrier group (asteroids, etc.). If I go with a component that's a "BodyType", then I can't retrieve just the types that are barriers, or the types that are just bonus pickups.

--tim


Top
 Profile  
 
 Post subject: Re: Tags vs. components
PostPosted: Wed Sep 19, 2012 3:59 am 
Offline

Joined: Sun Aug 05, 2012 3:37 pm
Posts: 23
Artemis has something similar. If you use a component mapper, for example, you can call componentMapper.getSafe(entity). This will return a null if the entity does not have the related component.

For now, I've decided against using a component for body type. I'll revisit this in the future if I run into performance issues.

Cheers,
--tim


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 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group