Reduced garbage allocation

This commit is contained in:
Anuken 2020-06-29 15:58:48 -04:00
parent d58e3ac235
commit bf5dd7386e
6 changed files with 24 additions and 22 deletions

View File

@ -221,8 +221,7 @@ public class BlockIndexer{
}
public Building findEnemyTile(Team team, float x, float y, float range, Boolf<Building> pred){
for(Team enemy : activeTeams){
if(!team.isEnemy(enemy)) continue;
for(Team enemy : team.enemies()){
Building entity = indexer.findTile(enemy, x, y, range, pred, true);
if(entity != null){

View File

@ -27,7 +27,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
@Override
public void getCollisions(Cons<QuadTree> consumer){
for(Team team : state.teams.enemiesOf(team)){
for(Team team : team.enemies()){
consumer.get(teamIndex.tree(team));
}
}

View File

@ -80,7 +80,7 @@ public class Team implements Comparable<Team>{
return state.rules.teams.get(this);
}
public Seq<Team> enemies(){
public Team[] enemies(){
return state.teams.enemiesOf(this);
}

View File

@ -4,7 +4,6 @@ import arc.func.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.ai.*;
import mindustry.gen.*;
import mindustry.world.blocks.storage.CoreBlock.*;
@ -23,13 +22,9 @@ public class Teams{
}
public @Nullable CoreEntity closestEnemyCore(float x, float y, Team team){
for(TeamData data : active){
if(areEnemies(team, data.team)){
CoreEntity tile = Geometry.findClosest(x, y, data.cores);
if(tile != null){
return tile;
}
}
for(Team enemy : team.enemies()){
CoreEntity tile = Geometry.findClosest(x, y, enemy.cores());
if(tile != null) return tile;
}
return null;
}
@ -38,7 +33,7 @@ public class Teams{
return Geometry.findClosest(x, y, get(team).cores);
}
public Seq<Team> enemiesOf(Team team){
public Team[] enemiesOf(Team team){
return get(team).enemies;
}
@ -67,10 +62,10 @@ public class Teams{
/** Returns team data by type. */
public TeamData get(Team team){
if(map[Pack.u(team.id)] == null){
map[Pack.u(team.id)] = new TeamData(team);
if(map[team.uid] == null){
map[team.uid] = new TeamData(team);
}
return map[Pack.u(team.id)];
return map[team.uid];
}
public Seq<CoreEntity> playerCores(){
@ -135,20 +130,23 @@ public class Teams{
}
for(TeamData data : active){
data.enemies.clear();
Seq<Team> enemies = new Seq<>();
for(TeamData other : active){
if(areEnemies(data.team, other.team)){
data.enemies.add(other.team);
enemies.add(other.team);
}
}
data.enemies = enemies.toArray(Team.class);
}
}
public class TeamData{
public final Seq<CoreEntity> cores = new Seq<>();
public final Seq<Team> enemies = new Seq<>();
public final Team team;
public final BaseAI ai;
public Team[] enemies = {};
public Queue<BlockPlan> blocks = new Queue<>();
public TeamData(Team team){

View File

@ -21,7 +21,7 @@ public class Universe{
private int turn;
private float turnCounter;
private Schematic lastLoadout = Loadouts.basicShard;
private Schematic lastLoadout;
private Seq<ItemStack> lastLaunchResources = new Seq<>();
public Universe(){
@ -94,6 +94,7 @@ public class Universe{
}
public Schematic getLastLoadout(){
if(lastLoadout == null) lastLoadout = Loadouts.basicShard;
return lastLoadout;
}

View File

@ -49,8 +49,12 @@ public class DesktopInput extends InputHandler{
@Override
public void buildUI(Group group){
group.fill(t -> {
t.bottom().update(() -> t.getColor().a = Mathf.lerpDelta(t.getColor().a, player.builder().isBuilding() ? 1f : 0f, 0.15f));
t.visible(() -> Core.settings.getBool("hints") && selectRequests.isEmpty());
t.bottom();
t.visible(() -> {
t.getColor().a = Mathf.lerpDelta(t.getColor().a, player.builder().isBuilding() ? 1f : 0f, 0.15f);
return Core.settings.getBool("hints") && selectRequests.isEmpty() && t.getColor().a > 0.01f;
});
t.touchable(() -> t.getColor().a < 0.1f ? Touchable.disabled : Touchable.childrenOnly);
t.table(Styles.black6, b -> {
b.defaults().left();