Per-unit cap (still broken)

This commit is contained in:
Anuken
2020-07-21 15:43:02 -04:00
parent 4ef0143928
commit 5c9e005397
20 changed files with 3758 additions and 1996 deletions

View File

@ -4,6 +4,7 @@ import arc.math.geom.*;
import mindustry.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.type.*;
import java.util.*;
@ -11,6 +12,7 @@ import java.util.*;
public class TeamIndexProcess implements AsyncProcess{
private QuadTree<Unit>[] trees = new QuadTree[Team.all.length];
private int[] counts = new int[Team.all.length];
private int[][] typeCounts = new int[Team.all.length][0];
public QuadTree<Unit> tree(Team team){
if(trees[team.id] == null) trees[team.id] = new QuadTree<>(Vars.world.getQuadBounds(new Rect()));
@ -22,8 +24,18 @@ public class TeamIndexProcess implements AsyncProcess{
return counts[team.id];
}
public void updateCount(Team team, int amount){
public int countType(Team team, UnitType type){
return typeCounts[team.id].length < type.id ? 0 : typeCounts[team.id][type.id];
}
public void updateCount(Team team, UnitType type, int amount){
int tid = type.id;
counts[team.id] += amount;
if(typeCounts[team.id].length < tid){
typeCounts[team.id] = new int[Vars.content.units().size];
}
typeCounts[team.id][tid] += amount;
}
@Override
@ -39,13 +51,16 @@ public class TeamIndexProcess implements AsyncProcess{
if(trees[team.id] != null){
trees[team.id].clear();
}
Arrays.fill(typeCounts[team.id], 0);
}
Arrays.fill(counts, 0);
for(Unit unit : Groups.unit){
tree(unit.team).insert(unit);
counts[unit.team.id] ++;
updateCount(unit.team, unit.type(), 1);
}
}