2020-05-01 16:35:18 -04:00
|
|
|
package mindustry.async;
|
|
|
|
|
|
|
|
import arc.math.geom.*;
|
|
|
|
import mindustry.*;
|
|
|
|
import mindustry.game.*;
|
|
|
|
import mindustry.gen.*;
|
|
|
|
|
2020-05-15 19:54:04 -04:00
|
|
|
import java.util.*;
|
|
|
|
|
2020-05-01 16:35:18 -04:00
|
|
|
/** Creates quadtrees per unit team. */
|
|
|
|
public class TeamIndexProcess implements AsyncProcess{
|
2020-05-28 11:27:42 -04:00
|
|
|
private QuadTree<Unitc>[] trees = new QuadTree[Team.all.length];
|
|
|
|
private int[] counts = new int[Team.all.length];
|
2020-05-01 16:35:18 -04:00
|
|
|
|
|
|
|
public QuadTree<Unitc> tree(Team team){
|
|
|
|
if(trees[team.uid] == null) trees[team.uid] = new QuadTree<>(Vars.world.getQuadBounds(new Rect()));
|
|
|
|
|
|
|
|
return trees[team.uid];
|
|
|
|
}
|
|
|
|
|
2020-05-12 21:34:27 -04:00
|
|
|
public int count(Team team){
|
|
|
|
return counts[team.id];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateCount(Team team, int amount){
|
|
|
|
counts[team.id] += amount;
|
|
|
|
}
|
|
|
|
|
2020-05-01 16:35:18 -04:00
|
|
|
@Override
|
|
|
|
public void reset(){
|
2020-05-28 11:27:42 -04:00
|
|
|
counts = new int[Team.all.length];
|
|
|
|
trees = new QuadTree[Team.all.length];
|
2020-05-01 16:35:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void begin(){
|
|
|
|
|
2020-05-28 11:27:42 -04:00
|
|
|
for(Team team : Team.all){
|
2020-05-01 16:35:18 -04:00
|
|
|
if(trees[team.uid] != null){
|
|
|
|
trees[team.uid].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 19:54:04 -04:00
|
|
|
Arrays.fill(counts, 0);
|
2020-05-12 21:34:27 -04:00
|
|
|
|
2020-05-01 16:35:18 -04:00
|
|
|
for(Unitc unit : Groups.unit){
|
|
|
|
tree(unit.team()).insert(unit);
|
2020-05-12 21:34:27 -04:00
|
|
|
counts[unit.team().id] ++;
|
2020-05-01 16:35:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldProcess(){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|