Group collisions
This commit is contained in:
@@ -56,10 +56,10 @@ public class Annotations{
|
||||
}
|
||||
|
||||
/** Creates a group that only examines entities that have all the components listed. */
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface GroupDef{
|
||||
Class[] value();
|
||||
Class[] collide() default {};
|
||||
boolean spatial() default false;
|
||||
boolean mapping() default false;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class EntityProcess extends BaseProcessor{
|
||||
ObjectMap<Svar, String> varInitializers = new ObjectMap<>();
|
||||
ObjectMap<Smethod, String> methodBlocks = new ObjectMap<>();
|
||||
ObjectSet<String> imports = new ObjectSet<>();
|
||||
Array<Smethod> allGroups = new Array<>();
|
||||
Array<Selement> allGroups = new Array<>();
|
||||
Array<Selement> allDefs = new Array<>();
|
||||
Array<Stype> allInterfaces = new Array<>();
|
||||
|
||||
@@ -45,7 +45,7 @@ public class EntityProcess extends BaseProcessor{
|
||||
|
||||
@Override
|
||||
public void process(RoundEnvironment env) throws Exception{
|
||||
allGroups.addAll(methods(GroupDef.class));
|
||||
allGroups.addAll(elements(GroupDef.class));
|
||||
allDefs.addAll(elements(EntityDef.class));
|
||||
allInterfaces.addAll(types(EntityInterface.class));
|
||||
|
||||
@@ -169,17 +169,18 @@ public class EntityProcess extends BaseProcessor{
|
||||
}else if(round == 2){ //round 2: get component classes and generate interfaces for them
|
||||
|
||||
//parse groups
|
||||
for(Smethod group : allGroups){
|
||||
for(Selement<?> group : allGroups){
|
||||
GroupDef an = group.annotation(GroupDef.class);
|
||||
Array<Stype> types = types(an, GroupDef::value).map(this::interfaceToComp);;
|
||||
groupDefs.add(new GroupDefinition(group.name(), ClassName.bestGuess(packageName + "." + interfaceName(types.first())), types, an.spatial(), an.mapping()));
|
||||
Array<Stype> types = types(an, GroupDef::value).map(this::interfaceToComp);
|
||||
Array<Stype> collides = types(an, GroupDef::collide);
|
||||
groupDefs.add(new GroupDefinition(group.name(), ClassName.bestGuess(packageName + "." + interfaceName(types.first())), types, an.spatial(), an.mapping(), collides));
|
||||
}
|
||||
|
||||
//add special generated groups
|
||||
for(DrawLayer layer : DrawLayer.values()){
|
||||
String name = "DrawLayer" + Strings.capitalize(layer.name()) + "c";
|
||||
//create group definition with no components directly
|
||||
GroupDefinition def = new GroupDefinition(layer.name(), ClassName.bestGuess(packageName + "." + name), Array.with(), false, false);
|
||||
GroupDefinition def = new GroupDefinition(layer.name(), ClassName.bestGuess(packageName + "." + name), Array.with(), false, false, new Array<>(0));
|
||||
//add manual inclusions of entities to be added to this group
|
||||
def.manualInclusions.addAll(allDefs.select(s -> allComponents(s).contains(comp -> comp.interfaces().contains(in -> in.name().equals(name)))));
|
||||
groupDefs.add(def);
|
||||
@@ -420,6 +421,12 @@ public class EntityProcess extends BaseProcessor{
|
||||
|
||||
groupUpdate.addStatement("all.update()");
|
||||
|
||||
for(GroupDefinition group : groupDefs){
|
||||
for(Stype collide : group.collides){
|
||||
groupUpdate.addStatement("$L.collide($L)", group.name, collide.name());
|
||||
}
|
||||
}
|
||||
|
||||
for(DrawLayer layer : DrawLayer.values()){
|
||||
MethodSpec.Builder groupDraw = MethodSpec.methodBuilder("draw" + Strings.capitalize(layer.name()))
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
@@ -673,15 +680,17 @@ public class EntityProcess extends BaseProcessor{
|
||||
final String name;
|
||||
final ClassName baseType;
|
||||
final Array<Stype> components;
|
||||
final Array<Stype> collides;
|
||||
final boolean spatial, mapping;
|
||||
final ObjectSet<Selement> manualInclusions = new ObjectSet<>();
|
||||
|
||||
public GroupDefinition(String name, ClassName bestType, Array<Stype> components, boolean spatial, boolean mapping){
|
||||
public GroupDefinition(String name, ClassName bestType, Array<Stype> components, boolean spatial, boolean mapping, Array<Stype> collides){
|
||||
this.baseType = bestType;
|
||||
this.components = components;
|
||||
this.name = name;
|
||||
this.spatial = spatial;
|
||||
this.mapping = mapping;
|
||||
this.collides = collides;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,27 +6,32 @@ import mindustry.gen.*;
|
||||
class AllDefs{
|
||||
|
||||
@GroupDef(Entityc.class)
|
||||
void all(){
|
||||
class all{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(Playerc.class)
|
||||
void player(){
|
||||
class player{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Bulletc.class, spatial = true, collide = {unit.class})
|
||||
class bullet{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Unitc.class, spatial = true)
|
||||
void unit(){
|
||||
class unit{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(Tilec.class)
|
||||
void tile(){
|
||||
class tile{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(Syncc.class)
|
||||
void sync(){
|
||||
class sync{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
|
||||
array.sort(comp);
|
||||
}
|
||||
|
||||
public void collide(EntityGroup<? extends Hitboxc> other){
|
||||
collisions.collideGroups((EntityGroup<? extends Hitboxc>)this, other);
|
||||
}
|
||||
|
||||
public void updatePhysics(){
|
||||
collisions.updatePhysics((EntityGroup<? extends Hitboxc>)this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user