This commit is contained in:
Anuken
2020-06-08 17:19:47 -04:00
parent 87ab895253
commit 8ea28e1ced
147 changed files with 438 additions and 437 deletions

View File

@@ -11,20 +11,20 @@ import static mindustry.Vars.world;
public class Astar{
public static final DistanceHeuristic manhattan = (x1, y1, x2, y2) -> Math.abs(x1 - x2) + Math.abs(y1 - y2);
private static final Array<Tile> out = new Array<>();
private static final Seq<Tile> out = new Seq<>();
private static final PQueue<Tile> queue = new PQueue<>(200 * 200 / 4, (a, b) -> 0);
private static final IntFloatMap costs = new IntFloatMap();
private static byte[][] rotations;
public static Array<Tile> pathfind(Tile from, Tile to, TileHueristic th, Boolf<Tile> passable){
public static Seq<Tile> pathfind(Tile from, Tile to, TileHueristic th, Boolf<Tile> passable){
return pathfind(from.x, from.y, to.x, to.y, th, manhattan, passable);
}
public static Array<Tile> pathfind(int startX, int startY, int endX, int endY, TileHueristic th, Boolf<Tile> passable){
public static Seq<Tile> pathfind(int startX, int startY, int endX, int endY, TileHueristic th, Boolf<Tile> passable){
return pathfind(startX, startY, endX, endY, th, manhattan, passable);
}
public static Array<Tile> pathfind(int startX, int startY, int endX, int endY, TileHueristic th, DistanceHeuristic dh, Boolf<Tile> passable){
public static Seq<Tile> pathfind(int startX, int startY, int endX, int endY, TileHueristic th, DistanceHeuristic dh, Boolf<Tile> passable){
Tiles tiles = world.tiles;
Tile start = tiles.getn(startX, startY);

View File

@@ -54,7 +54,7 @@ public class BaseAI{
int wx = (int)(core.tileX() + Tmp.v1.x), wy = (int)(core.tileY() + Tmp.v1.y);
Tile tile = world.tiles.getc(wx, wy);
Array<BasePart> parts = null;
Seq<BasePart> parts = null;
//pick a completely random base part, and place it a random location
//((yes, very intelligent))

View File

@@ -19,12 +19,12 @@ import java.io.*;
import static mindustry.Vars.tilesize;
public class BaseRegistry{
public Array<BasePart> cores = new Array<>();
public Array<BasePart> parts = new Array<>();
public ObjectMap<Content, Array<BasePart>> reqParts = new ObjectMap<>();
public Seq<BasePart> cores = new Seq<>();
public Seq<BasePart> parts = new Seq<>();
public ObjectMap<Content, Seq<BasePart>> reqParts = new ObjectMap<>();
public Array<BasePart> forResource(Content item){
return reqParts.get(item, Array::new);
public Seq<BasePart> forResource(Content item){
return reqParts.get(item, Seq::new);
}
public void load(){
@@ -85,7 +85,7 @@ public class BaseRegistry{
part.centerY = part.schematic.height/2;
}
if(part.required != null) reqParts.get(part.required, Array::new).add(part);
if(part.required != null) reqParts.get(part.required, Seq::new).add(part);
}catch(IOException e){
throw new RuntimeException(e);

View File

@@ -38,7 +38,7 @@ public class BlockIndexer{
/** All ores available on this map. */
private ObjectSet<Item> allOres = new ObjectSet<>();
/** Stores teams that are present here as tiles. */
private Array<Team> activeTeams = new Array<>();
private Seq<Team> activeTeams = new Seq<>();
/** Maps teams to a map of flagged tiles by flag. */
private TileArray[][] flagMap = new TileArray[Team.all.length][BlockFlag.all.length];
/** Max units by team. */
@@ -48,7 +48,7 @@ public class BlockIndexer{
/** Empty set used for returning. */
private TileArray emptySet = new TileArray();
/** Array used for returning and reusing. */
private Array<Tile> returnArray = new Array<>();
private Seq<Tile> returnArray = new Seq<>();
public BlockIndexer(){
Events.on(TileChangeEvent.class, event -> {
@@ -196,7 +196,7 @@ public class BlockIndexer{
}
/** Get all enemy blocks with a flag. */
public Array<Tile> getEnemy(Team team, BlockFlag type){
public Seq<Tile> getEnemy(Team team, BlockFlag type){
returnArray.clear();
for(Team enemy : team.enemies()){
if(state.teams.isActive(enemy)){
@@ -446,7 +446,7 @@ public class BlockIndexer{
}
public static class TileArray implements Iterable<Tile>{
private Array<Tile> tiles = new Array<>(false, 16);
private Seq<Tile> tiles = new Seq<>(false, 16);
private IntSet contained = new IntSet();
public void add(Tile tile){

View File

@@ -26,7 +26,7 @@ public class Pathfinder implements Runnable{
/** tile data, see PathTileStruct */
private int[][] tiles;
/** unordered array of path data for iteration only. DO NOT iterate or access this in the main thread. */
private Array<Flowfield> threadList = new Array<>(), mainList = new Array<>();
private Seq<Flowfield> threadList = new Seq<>(), mainList = new Seq<>();
/** Maps team ID and target to to a flowfield.*/
private ObjectMap<PathTarget, Flowfield>[] fieldMap = new ObjectMap[Team.all.length];
/** Used field maps. */
@@ -37,7 +37,7 @@ public class Pathfinder implements Runnable{
private ObjectMap<Position, PathTarget> targetCache = new ObjectMap<>();
/** Current pathfinding thread */
private @Nullable Thread thread;
private IntArray tmpArray = new IntArray();
private IntSeq tmpArray = new IntSeq();
public Pathfinder(){
Events.on(WorldLoadEvent.class, event -> {
@@ -48,8 +48,8 @@ public class Pathfinder implements Runnable{
fieldMap = new ObjectMap[Team.all.length];
fieldMapUsed = new ObjectSet[Team.all.length];
targetCache = new ObjectMap<>();
threadList = new Array<>();
mainList = new Array<>();
threadList = new Seq<>();
mainList = new Seq<>();
for(Tile tile : world.tiles){
tiles[tile.x][tile.y] = packTile(tile);
@@ -189,7 +189,7 @@ public class Pathfinder implements Runnable{
//if this combination is not found, create it on request
if(fieldMapUsed[team.uid].add(target)){
//grab targets since this is run on main thread
IntArray targets = target.getPositions(team, new IntArray());
IntSeq targets = target.getPositions(team, new IntSeq());
queue.post(() -> createPath(team, target, targets));
}
return tile;
@@ -293,14 +293,14 @@ public class Pathfinder implements Runnable{
}
private void preloadPath(Team team, PathTarget target){
updateFrontier(createPath(team, target, target.getPositions(team, new IntArray())), -1);
updateFrontier(createPath(team, target, target.getPositions(team, new IntSeq())), -1);
}
/**
* Created a new flowfield that aims to get to a certain target for a certain team.
* Pathfinding thread only.
*/
private Flowfield createPath(Team team, PathTarget target, IntArray targets){
private Flowfield createPath(Team team, PathTarget target, IntSeq targets){
Flowfield path = new Flowfield(team, target, world.width(), world.height());
path.lastUpdateTime = Time.millis();
@@ -391,14 +391,14 @@ public class Pathfinder implements Runnable{
public static final FlagTarget[] all = values();
private final Cons2<Team, IntArray> targeter;
private final Cons2<Team, IntSeq> targeter;
FlagTarget(Cons2<Team, IntArray> targeter){
FlagTarget(Cons2<Team, IntSeq> targeter){
this.targeter = targeter;
}
@Override
public IntArray getPositions(Team team, IntArray out){
public IntSeq getPositions(Team team, IntSeq out){
targeter.get(team, out);
return out;
}
@@ -417,7 +417,7 @@ public class Pathfinder implements Runnable{
}
@Override
public IntArray getPositions(Team team, IntArray out){
public IntSeq getPositions(Team team, IntSeq out){
out.add(Point2.pack(world.toTile(position.getX()), world.toTile(position.getY())));
return out;
}
@@ -430,7 +430,7 @@ public class Pathfinder implements Runnable{
public interface PathTarget{
/** Gets targets to pathfind towards. This must run on the main thread. */
IntArray getPositions(Team team, IntArray out);
IntSeq getPositions(Team team, IntSeq out);
/** Refresh rate in milliseconds. Return any number <= 0 to disable. */
int refreshRate();
}
@@ -448,7 +448,7 @@ public class Pathfinder implements Runnable{
/** search frontier, these are Pos objects */
final IntQueue frontier = new IntQueue();
/** all target positions; these positions have a cost of 0, and must be synchronized on! */
final IntArray targets = new IntArray();
final IntSeq targets = new IntSeq();
/** current search ID */
int search = 1;
/** last updated time */

View File

@@ -17,7 +17,7 @@ import static mindustry.Vars.*;
public class WaveSpawner{
private static final float margin = 40f, coreMargin = tilesize * 3; //how far away from the edge flying units spawn
private Array<Tile> spawns = new Array<>();
private Seq<Tile> spawns = new Seq<>();
private boolean spawning = false;
public WaveSpawner(){
@@ -28,7 +28,7 @@ public class WaveSpawner{
return spawns.size;
}
public Array<Tile> getSpawns(){
public Seq<Tile> getSpawns(){
return spawns;
}

View File

@@ -7,7 +7,7 @@ import arc.struct.*;
* {@code BoundedSlotAssignmentStrategy} is an abstract implementation of {@link SlotAssignmentStrategy} that supports roles.
* Generally speaking, there are hard and soft roles. Hard roles cannot be broken, soft roles can.
* <p>
* This abstract class provides an implementation of the {@link #calculateNumberOfSlots(Array) calculateNumberOfSlots} method that
* This abstract class provides an implementation of the {@link #calculateNumberOfSlots(Seq) calculateNumberOfSlots} method that
* is more general (and costly) than the simplified implementation in {@link FreeSlotAssignmentStrategy}. It scans the assignment
* list to find the number of filled slots, which is the highest slot number in the assignments.
* @author davebaol
@@ -15,10 +15,10 @@ import arc.struct.*;
public abstract class BoundedSlotAssignmentStrategy implements SlotAssignmentStrategy{
@Override
public abstract void updateSlotAssignments(Array<SlotAssignment> assignments);
public abstract void updateSlotAssignments(Seq<SlotAssignment> assignments);
@Override
public int calculateNumberOfSlots(Array<SlotAssignment> assignments){
public int calculateNumberOfSlots(Seq<SlotAssignment> assignments){
// Find the number of filled slots: it will be the
// highest slot number in the assignments
int filledSlots = -1;
@@ -32,7 +32,7 @@ public abstract class BoundedSlotAssignmentStrategy implements SlotAssignmentStr
}
@Override
public void removeSlotAssignment(Array<SlotAssignment> assignments, int index){
public void removeSlotAssignment(Seq<SlotAssignment> assignments, int index){
int sn = assignments.get(index).slotNumber;
for(int i = 0; i < assignments.size; i++){
SlotAssignment sa = assignments.get(i);

View File

@@ -13,8 +13,8 @@ public class DistanceAssignmentStrategy implements SlotAssignmentStrategy{
}
@Override
public void updateSlotAssignments(Array<SlotAssignment> assignments){
IntArray slots = IntArray.range(0, assignments.size);
public void updateSlotAssignments(Seq<SlotAssignment> assignments){
IntSeq slots = IntSeq.range(0, assignments.size);
for(SlotAssignment slot : assignments){
int mindex = 0;
@@ -35,12 +35,12 @@ public class DistanceAssignmentStrategy implements SlotAssignmentStrategy{
}
@Override
public int calculateNumberOfSlots(Array<SlotAssignment> assignments){
public int calculateNumberOfSlots(Seq<SlotAssignment> assignments){
return assignments.size;
}
@Override
public void removeSlotAssignment(Array<SlotAssignment> assignments, int index){
public void removeSlotAssignment(Seq<SlotAssignment> assignments, int index){
assignments.remove(index);
}

View File

@@ -19,7 +19,7 @@ import arc.struct.*;
public class Formation{
/** A list of slots assignments. */
public Array<SlotAssignment> slotAssignments;
public Seq<SlotAssignment> slotAssignments;
/** The anchor point of this formation. */
public Vec3 anchor;
@@ -74,7 +74,7 @@ public class Formation{
this.slotAssignmentStrategy = slotAssignmentStrategy;
this.motionModerator = motionModerator;
this.slotAssignments = new Array<>();
this.slotAssignments = new Seq<>();
this.driftOffset = new Vec3();
this.positionOffset = new Vec2(anchor.x, anchor.y).cpy();
}

View File

@@ -25,7 +25,7 @@ public abstract class FormationMotionModerator{
* @param pattern the pattern
* @return the given location for chaining.
*/
public Vec3 calculateDriftOffset(Vec3 centerOfMass, Array<SlotAssignment> slotAssignments, FormationPattern pattern){
public Vec3 calculateDriftOffset(Vec3 centerOfMass, Seq<SlotAssignment> slotAssignments, FormationPattern pattern){
// Clear the center of mass
centerOfMass.x = centerOfMass.y = 0;
float centerOfMassOrientation = 0;

View File

@@ -13,7 +13,7 @@ import arc.struct.*;
public class FreeSlotAssignmentStrategy implements SlotAssignmentStrategy{
@Override
public void updateSlotAssignments(Array<SlotAssignment> assignments){
public void updateSlotAssignments(Seq<SlotAssignment> assignments){
// A very simple assignment algorithm: we simply go through
// each assignment in the list and assign sequential slot numbers
for(int i = 0; i < assignments.size; i++)
@@ -21,12 +21,12 @@ public class FreeSlotAssignmentStrategy implements SlotAssignmentStrategy{
}
@Override
public int calculateNumberOfSlots(Array<SlotAssignment> assignments){
public int calculateNumberOfSlots(Seq<SlotAssignment> assignments){
return assignments.size;
}
@Override
public void removeSlotAssignment(Array<SlotAssignment> assignments, int index){
public void removeSlotAssignment(Seq<SlotAssignment> assignments, int index){
assignments.remove(index);
}

View File

@@ -9,12 +9,12 @@ import arc.struct.*;
public interface SlotAssignmentStrategy{
/** Updates the assignment of members to slots */
void updateSlotAssignments(Array<SlotAssignment> assignments);
void updateSlotAssignments(Seq<SlotAssignment> assignments);
/** Calculates the number of slots from the assignment data. */
int calculateNumberOfSlots(Array<SlotAssignment> assignments);
int calculateNumberOfSlots(Seq<SlotAssignment> assignments);
/** Removes the slot assignment at the specified index. */
void removeSlotAssignment(Array<SlotAssignment> assignments, int index);
void removeSlotAssignment(Seq<SlotAssignment> assignments, int index);
}

View File

@@ -27,7 +27,7 @@ import arc.util.*;
public class SoftRoleSlotAssignmentStrategy extends BoundedSlotAssignmentStrategy{
protected SlotCostProvider slotCostProvider;
protected float costThreshold;
private BooleanArray filledSlots;
private BoolSeq filledSlots;
/**
* Creates a {@code SoftRoleSlotAssignmentStrategy} with the given slot cost provider and no cost threshold.
@@ -46,14 +46,14 @@ public class SoftRoleSlotAssignmentStrategy extends BoundedSlotAssignmentStrateg
this.slotCostProvider = slotCostProvider;
this.costThreshold = costThreshold;
this.filledSlots = new BooleanArray();
this.filledSlots = new BoolSeq();
}
@Override
public void updateSlotAssignments(Array<SlotAssignment> assignments){
public void updateSlotAssignments(Seq<SlotAssignment> assignments){
// Holds a list of member and slot data for each member.
Array<MemberAndSlots> memberData = new Array<>();
Seq<MemberAndSlots> memberData = new Seq<>();
// Compile the member data
int numberOfAssignments = assignments.size;
@@ -146,12 +146,12 @@ public class SoftRoleSlotAssignmentStrategy extends BoundedSlotAssignmentStrateg
static class MemberAndSlots implements Comparable<MemberAndSlots>{
FormationMember member;
float assignmentEase;
Array<CostAndSlot> costAndSlots;
Seq<CostAndSlot> costAndSlots;
public MemberAndSlots(FormationMember member){
this.member = member;
this.assignmentEase = 0f;
this.costAndSlots = new Array<>();
this.costAndSlots = new Seq<>();
}
@Override