mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-26 06:22:17 -08:00
Prevent concurrent modification in BlockIndexer#eachBlock
This commit is contained in:
parent
37d7b3d7fb
commit
5b2dc021a6
2 changed files with 26 additions and 12 deletions
|
|
@ -211,13 +211,12 @@ public class BlockIndexer{
|
|||
}
|
||||
|
||||
public boolean eachBlock(@Nullable Team team, float wx, float wy, float range, Boolf<Building> pred, Cons<Building> cons){
|
||||
returnBool = false;
|
||||
breturnArray.clear();
|
||||
|
||||
if(team == null){
|
||||
allBuildings(wx, wy, range, b -> {
|
||||
if(pred.get(b)){
|
||||
returnBool = true;
|
||||
cons.get(b);
|
||||
breturnArray.add(b);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
|
|
@ -225,13 +224,20 @@ public class BlockIndexer{
|
|||
if(buildings == null) return false;
|
||||
buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> {
|
||||
if(b.within(wx, wy, range + b.hitSize() / 2f) && pred.get(b)){
|
||||
returnBool = true;
|
||||
cons.get(b);
|
||||
breturnArray.add(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return returnBool;
|
||||
int size = breturnArray.size;
|
||||
var items = breturnArray.items;
|
||||
for(int i = 0; i < size; i++){
|
||||
cons.get(items[i]);
|
||||
items[i] = null;
|
||||
}
|
||||
breturnArray.size = 0;
|
||||
|
||||
return size > 0;
|
||||
}
|
||||
|
||||
/** Get all enemy blocks with a flag. */
|
||||
|
|
@ -274,16 +280,24 @@ public class BlockIndexer{
|
|||
}
|
||||
|
||||
public void allBuildings(float x, float y, float range, Cons<Building> cons){
|
||||
breturnArray.clear();
|
||||
for(int i = 0; i < activeTeams.size; i++){
|
||||
Team team = activeTeams.items[i];
|
||||
var buildings = team.data().buildings;
|
||||
if(buildings == null) continue;
|
||||
buildings.intersect(x - range, y - range, range*2f, range*2f, b -> {
|
||||
if(b.within(x, y, range + b.hitSize()/2f)){
|
||||
cons.get(b);
|
||||
}
|
||||
});
|
||||
buildings.intersect(x - range, y - range, range*2f, range*2f, breturnArray);
|
||||
}
|
||||
|
||||
var items = breturnArray.items;
|
||||
int size = breturnArray.size;
|
||||
for(int i = 0; i < size; i++){
|
||||
var b = items[i];
|
||||
if(b.within(x, y, range + b.hitSize()/2f)){
|
||||
cons.get(b);
|
||||
}
|
||||
items[i] = null;
|
||||
}
|
||||
breturnArray.size = 0;
|
||||
}
|
||||
|
||||
public Building findEnemyTile(@Nullable Team team, float x, float y, float range, Boolf<Building> pred){
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ kapt.include.compile.classpath=false
|
|||
kotlin.stdlib.default.dependency=false
|
||||
#needed for android compilation
|
||||
android.useAndroidX=true
|
||||
archash=58cab1a87e1ed024a0044c4639594dc22088c87e
|
||||
archash=65939d39bd6b20ddcfa85cb76cb1ceb815d91aec
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue