mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-20 04:37:31 +07:00
Cleanup, optimization
This commit is contained in:
50
core/src/mindustry/async/TeamIndexProcess.java
Normal file
50
core/src/mindustry/async/TeamIndexProcess.java
Normal file
@ -0,0 +1,50 @@
|
||||
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<>();
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(){
|
||||
active.clear();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
for(Unitc unit : Groups.unit){
|
||||
tree(unit.team()).insert(unit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcess(){
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user