2020-05-01 16:35:18 -04:00
|
|
|
package mindustry.async;
|
|
|
|
|
|
|
|
import arc.math.geom.*;
|
|
|
|
import arc.struct.*;
|
|
|
|
import mindustry.*;
|
|
|
|
import mindustry.game.*;
|
|
|
|
import mindustry.game.Teams.*;
|
|
|
|
import mindustry.gen.*;
|
|
|
|
|
|
|
|
/** Creates quadtrees per unit team. */
|
|
|
|
public class TeamIndexProcess implements AsyncProcess{
|
|
|
|
private QuadTree<Unitc>[] trees = new QuadTree[Team.all().length];
|
|
|
|
private Array<Team> active = new Array<>();
|
2020-05-12 21:34:27 -04:00
|
|
|
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(){
|
|
|
|
active.clear();
|
2020-05-12 21:34:27 -04:00
|
|
|
counts = new int[Team.all().length];
|
2020-05-01 16:35:18 -04:00
|
|
|
trees = new QuadTree[Team.all().length];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void begin(){
|
|
|
|
for(TeamData data : Vars.state.teams.getActive()){
|
|
|
|
if(!active.contains(data.team)){
|
|
|
|
active.add(data.team);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Team team : active){
|
|
|
|
if(trees[team.uid] != null){
|
|
|
|
trees[team.uid].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 21:34:27 -04:00
|
|
|
for(Team team : active){
|
|
|
|
counts[team.id] = 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|