This commit is contained in:
Anuken
2020-09-16 14:53:44 -04:00
parent 0847fc9f09
commit 5c98512e4f
10 changed files with 39 additions and 57 deletions

View File

@@ -33,7 +33,7 @@ public class BlockIndexer{
/** Maps each team ID to a quarant. A quadrant is a grid of bits, where each bit is set if and only if there is a block of that team in that quadrant. */
private GridBits[] structQuadrants;
/** Stores all damaged tile entities by team. */
private BuildingArray[] damagedTiles = new BuildingArray[Team.all.length];
private ObjectSet<Building>[] damagedTiles = new ObjectSet[Team.all.length];
/** All ores available on this map. */
private ObjectSet<Item> allOres = new ObjectSet<>();
/** Stores teams that are present here as tiles. */
@@ -70,7 +70,7 @@ public class BlockIndexer{
Events.on(WorldLoadEvent.class, event -> {
scanOres.clear();
scanOres.addAll(Item.getAllOres());
damagedTiles = new BuildingArray[Team.all.length];
damagedTiles = new ObjectSet[Team.all.length];
flagMap = new TileArray[Team.all.length][BlockFlag.all.length];
unitCaps = new int[Team.all.length];
activeTeams = new Seq<>(Team.class);
@@ -139,14 +139,14 @@ public class BlockIndexer{
}
/** Returns all damaged tiles by team. */
public BuildingArray getDamaged(Team team){
returnArray.clear();
public ObjectSet<Building> getDamaged(Team team){
breturnArray.clear();
if(damagedTiles[team.id] == null){
damagedTiles[team.id] = new BuildingArray();
damagedTiles[team.id] = new ObjectSet<>();
}
BuildingArray set = damagedTiles[team.id];
ObjectSet<Building> set = damagedTiles[team.id];
for(Building build : set){
if((!build.isValid() || build.team != team || !build.damaged()) || build.block instanceof ConstructBlock){
breturnArray.add(build);
@@ -214,7 +214,7 @@ public class BlockIndexer{
public void notifyTileDamaged(Building entity){
if(damagedTiles[entity.team.id] == null){
damagedTiles[entity.team.id] = new BuildingArray();
damagedTiles[entity.team.id] = new ObjectSet<Building>();
}
damagedTiles[entity.team.id].add(entity);
@@ -476,35 +476,4 @@ public class BlockIndexer{
return tiles.iterator();
}
}
//TODO copy-pasted code, generics would be nice here
public static class BuildingArray implements Iterable<Building>{
private Seq<Building> tiles = new Seq<>(false, 16);
private IntSet contained = new IntSet();
public void add(Building tile){
if(contained.add(tile.pos())){
tiles.add(tile);
}
}
public void remove(Building tile){
if(contained.remove(tile.pos())){
tiles.remove(tile);
}
}
public int size(){
return tiles.size;
}
public Building first(){
return tiles.first();
}
@Override
public Iterator<Building> iterator(){
return tiles.iterator();
}
}
}