Ali_RS
March 18, 2023, 6:01pm
1
Hi
It would be nice to add EntityData.removeComponents(EntityId entityId, Class<T>... types)
for ease of removing multiple components at once in Zay-ES.
Currently, I am doing something like:
Stream.of(ComponentA.class, ComponentB.class, ComponentC.class)
.forEach(component -> ed.removeComponent(eId, component));
Ali_RS
March 20, 2023, 7:34am
2
I submitted a PR
jMonkeyEngine-Contributions:master
ā Ali-RS:removecomponents
opened 07:02AM - 20 Mar 23 UTC
Solves #28
I needed to bump the language to java 8 to be able to use the "exā¦ tension/default method" feature.
@pspeed I would like to hear your opinion
pspeed
March 20, 2023, 11:18am
3
It seems fine. I havenāt really had a chance to look at it yet.
ā¦itās just a convenience method, right? (No special complications in the implementation I assume.)
Edit: just lookedā¦ I prefer not to hide code in interfaces. Itās one thing when the method does basically nothing but this is real code. Iāll keep this discussion on the PR, though. Sorry.
Ali_RS
March 20, 2023, 12:54pm
4
Applied the requested changes.
1 Like
Ali_RS
March 20, 2023, 9:43pm
5
public void removeComponents( EntityId entityId, Class<? extends EntityComponent>... types );
IDE shows an āUnchecked generics array creation for varargs parameterā hint when using ed.removeComponents().
Appears that I can not add @SafeVarargs
on interface method.
Do I need to do something about it?
pspeed
March 20, 2023, 10:26pm
6
This is a pain with generics. Isnāt there a similar setComponents() method? Does it have a similar issue or did I resolve it somehow?
Ali_RS
March 20, 2023, 10:32pm
7
It does not have this issue because it does not use generics
public void setComponents( EntityId entityId, EntityComponent... components );
pspeed
March 20, 2023, 10:35pm
8
Ah, so one approach would be just to take naked Class and cast internallyā¦ let the class cast exception bubble out.
I donāt know how I feel about that but generics leaves little good choice in this caseā¦ and at least this gets rid of the warnings for every caller.
Ali_RS
March 20, 2023, 10:52pm
9
Yeah, seems you are also doing this for other methods:
public Entity getEntity( EntityId entityId, Class... types );
public EntityId findEntity( ComponentFilter filter, Class... types );
public Set<EntityId> findEntities( ComponentFilter filter, Class... types );
public EntitySet getEntities( Class... types );
public EntitySet getEntities( ComponentFilter filter, Class... types );
public WatchedEntity watchEntity( EntityId entityId, Class... types );
Ali_RS
March 20, 2023, 11:30pm
10
Updated PR to use the naked class as you suggested and this fixed the warning.
I think it is now ready to be merged.
1 Like