Zay-ES questions

Hi,

2 questions about Zay-ES :

  • Why do we need to add the class requested by a filter in the class list (getEntities method)?

Why can’t we do it automatically…saying if i request for entities which have a position component i’ll need it…we must add it anyway for now.

Or let the user decide by adding it or not…saying i need only entities in this area but i don’t mind the area component here…less data to transfer.

  • And second question, i have an area component (my world is split into multiples zones) and, for example, if i want only NPC entities which are in a particular area? I’ve seen multiple filters is prepared in the lib but no way for using it, planned?
@haze said: Hi,

2 questions about Zay-ES :

  • Why do we need to add the class requested by a filter in the class list (getEntities method)?

Why can’t we do it automatically…saying if i request for entities which have a position component i’ll need it…we must add it anyway for now.

Or let the user decide by adding it or not…saying i need only entities in this area but i don’t mind the area component here…less data to transfer.

If the filter requires component X then you need to request component X or there will be nothing to filter on. I could include it by default but I wanted to user to be clear that they are requesting the components… it’s also easier for the calling code to ask for it then it is for me to pull it out (especially if I someday support multiple filters as planned).

@haze said: - And second question, i have an area component (my world is split into multiples zones) and, for example, if i want only NPC entities which are in a particular area? I've seen multiple filters is prepared in the lib but no way for using it, planned?

You can make your own filters. Though there may not be a reason to in this case as often the field filter is just fine if you structure your component(s) properly.

I would need more information to answer better. But for example, in Mythruna I have a zoneId field as part of the Position component. Since in my case zones are calculated directly based on position it is easy to just make it a part of the position field. When I want entities in a given zone then I need only search for entities with a Position component that has that particular zone ID as a field value.

@pspeed said: If the filter requires component X then you need to request component X or there will be nothing to filter on. I could include it by default but I wanted to user to be clear that they are requesting the components... it's also easier for the calling code to ask for it then it is for me to pull it out (especially if I someday support multiple filters as planned).

Ok, so it’s a misconception if i have a entityType component (PLAYER, NPC, etc…) and request somewhere for the Position component for only players? I just need position, no entityType…i know i’ll get only players entities cause of the filter…i will receive the entityType for all the players, a lot of useless data…

@pspeed said:

You can make your own filters. Though there may not be a reason to in this case as often the field filter is just fine if you structure your component(s) properly.

I would need more information to answer better. But for example, in Mythruna I have a zoneId field as part of the Position component. Since in my case zones are calculated directly based on position it is easy to just make it a part of the position field. When I want entities in a given zone then I need only search for entities with a Position component that has that particular zone ID as a field value.

Hummm, yes, not a bad idea, i could go for a ZoneName field in the position component.
In fact, i have a state which keep in memory a list of all players, npcs, pets, etc… and i have separated them by areas, so i can iterate only for npcs in a particular area…something like Map<Zone, Map<EntityType, EntitySet>> if it’s more clear.

@haze said: Ok, so it's a misconception if i have a entityType component (PLAYER, NPC, etc...) and request somewhere for the Position component for only players? I just need position, no entityType...i know i'll get only players entities cause of the filter...i will receive the entityType for all the players, a lot of useless data...

I think it’s the opposite. If you need entity type for your filter then you need to specify it in the list of components you need. That way you won’t be surprised that it is in your Entity. It needs to be in the entity or the filter won’t work.

As I said, I could have automatically put it in the entity but
a) I kind of wanted the caller to be aware explicitly of what they were asking for,
b) this way the only difference between a filtered and unfiltered call for the same entity set is just the filter,
c) you can change/add/remove the filter for an entity set later and the caller should be aware that it can only filter what’s been requested, and finally
d) it’s not so much trouble for the user to specify it.