Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anuken
2020-08-08 14:14:43 -04:00
11 changed files with 47 additions and 48 deletions

View File

@@ -40,20 +40,20 @@ In general, if you are using IntelliJ, you should be warned about platform incom
#### Use `arc` collections and classes when possible. #### Use `arc` collections and classes when possible.
Instead of using `java.util.List`, `java.util.HashMap`, and other standard Java collections, use `Array`, `ObjectMap` and other equivalents from `arc.struct`. Instead of using `java.util.List`, `java.util.HashMap`, and other standard Java collections, use `Seq`, `ObjectMap` and other equivalents from `arc.struct`.
Why? Because that's what the rest of the codebase uses, and the standard collections have a lot of cruft and usability issues associated with them. Why? Because that's what the rest of the codebase uses, and the standard collections have a lot of cruft and usability issues associated with them.
In the rare case that concurrency is required, you may use the standard Java classes for that purpose (e.g. `CopyOnWriteArrayList`). In the rare case that concurrency is required, you may use the standard Java classes for that purpose (e.g. `CopyOnWriteArrayList`).
What you'll usually need to change: What you'll usually need to change:
- `HashSet` -> `ObjectSet` - `HashSet` -> `ObjectSet`
- `HashMap` -> `ObjectMap` - `HashMap` -> `ObjectMap`
- `List` / `ArrayList` / `Stack` -> `Array` - `List` / `ArrayList` / `Stack` -> `Seq`
- `java.util.Queue` -> `arc.struct.Queue` - `java.util.Queue` -> `arc.struct.Queue`
- *Many others* - *Many others*
#### Avoid boxed types (Integer, Boolean) #### Avoid boxed types (Integer, Boolean)
Never create variables or collections with boxed types `Array<Integer>` or `ObjectMap<Integer, ...>`. Use the collections specialized for this task, e.g. `IntArray` and `IntMap`. Never create variables or collections with boxed types `Seq<Integer>` or `ObjectMap<Integer, ...>`. Use the collections specialized for this task, e.g. `IntSeq` and `IntMap`.
#### Do not allocate anything if possible. #### Do not allocate anything if possible.

View File

@@ -94,24 +94,24 @@ public class Conveyor extends Block implements Autotiler{
public class ConveyorEntity extends Building{ public class ConveyorEntity extends Building{
//parallel array data //parallel array data
Item[] ids = new Item[capacity]; public Item[] ids = new Item[capacity];
float[] xs = new float[capacity]; public float[] xs = new float[capacity];
float[] ys = new float[capacity]; public float[] ys = new float[capacity];
//amount of items, always < capacity //amount of items, always < capacity
int len = 0; public int len = 0;
//next entity //next entity
@Nullable Building next; public @Nullable Building next;
@Nullable ConveyorEntity nextc; public @Nullable ConveyorEntity nextc;
//whether the next conveyor's rotation == tile rotation //whether the next conveyor's rotation == tile rotation
boolean aligned; public boolean aligned;
int lastInserted, mid; public int lastInserted, mid;
float minitem = 1; public float minitem = 1;
int blendbits, blending; public int blendbits, blending;
int blendsclx, blendscly; public int blendsclx, blendscly;
float clogHeat = 0f; public float clogHeat = 0f;
@Override @Override
public void draw(){ public void draw(){
@@ -350,7 +350,7 @@ public class Conveyor extends Block implements Autotiler{
} }
final void add(int o){ public final void add(int o){
for(int i = Math.max(o + 1, len); i > o; i--){ for(int i = Math.max(o + 1, len); i > o; i--){
ids[i] = ids[i - 1]; ids[i] = ids[i - 1];
xs[i] = xs[i - 1]; xs[i] = xs[i - 1];
@@ -360,7 +360,7 @@ public class Conveyor extends Block implements Autotiler{
len++; len++;
} }
final void remove(int o){ public final void remove(int o){
for(int i = o; i < len - 1; i++){ for(int i = o; i < len - 1; i++){
ids[i] = ids[i + 1]; ids[i] = ids[i + 1];
xs[i] = xs[i + 1]; xs[i] = xs[i + 1];

View File

@@ -357,7 +357,7 @@ public class ItemBridge extends Block{
return liquids.get(liquid) + amount < liquidCapacity && (liquids.current() == liquid || liquids.get(liquids.current()) < 0.2f); return liquids.get(liquid) + amount < liquidCapacity && (liquids.current() == liquid || liquids.get(liquids.current()) < 0.2f);
} }
private boolean linked(Building source){ protected boolean linked(Building source){
return source instanceof ItemBridgeEntity && linkValid(source.tile(), tile) && ((ItemBridgeEntity)source).link == pos(); return source instanceof ItemBridgeEntity && linkValid(source.tile(), tile) && ((ItemBridgeEntity)source).link == pos();
} }

View File

@@ -27,7 +27,7 @@ public class Junction extends Block{
} }
public class JunctionEntity extends Building{ public class JunctionEntity extends Building{
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity); public DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity);
@Override @Override
public int acceptStack(Item item, int amount, Teamc source){ public int acceptStack(Item item, int amount, Teamc source){

View File

@@ -86,13 +86,13 @@ public class MassDriver extends Block{
} }
public class MassDriverEntity extends Building{ public class MassDriverEntity extends Building{
int link = -1; public int link = -1;
float rotation = 90; public float rotation = 90;
float reload = 0f; public float reload = 0f;
DriverState state = DriverState.idle; public DriverState state = DriverState.idle;
OrderedSet<Tile> waitingShooters = new OrderedSet<>(); public OrderedSet<Tile> waitingShooters = new OrderedSet<>();
Tile currentShooter(){ public Tile currentShooter(){
return waitingShooters.isEmpty() ? null : waitingShooters.first(); return waitingShooters.isEmpty() ? null : waitingShooters.first();
} }
@@ -322,7 +322,7 @@ public class MassDriver extends Block{
} }
} }
enum DriverState{ public enum DriverState{
idle, //nothing is shooting at this mass driver and it does not have any target idle, //nothing is shooting at this mass driver and it does not have any target
accepting, //currently getting shot at, unload items accepting, //currently getting shot at, unload items
shooting, shooting,

View File

@@ -31,9 +31,9 @@ public class OverflowGate extends Block{
} }
public class OverflowGateEntity extends Building{ public class OverflowGateEntity extends Building{
Item lastItem; public Item lastItem;
Tile lastInput; public Tile lastInput;
float time; public float time;
@Override @Override
public int acceptStack(Item item, int amount, Teamc source){ public int acceptStack(Item item, int amount, Teamc source){

View File

@@ -241,15 +241,14 @@ public class PayloadConveyor extends Block{
} }
} }
boolean blends(int direction){ protected boolean blends(int direction){
if(direction == rotation){ if(direction == rotation){
return !blocked || next != null; return !blocked || next != null;
}else{
return PayloadAcceptor.blends(this, direction);
} }
return PayloadAcceptor.blends(this, direction);
} }
TextureRegion clipRegion(Rect bounds, Rect sprite, TextureRegion region){ protected TextureRegion clipRegion(Rect bounds, Rect sprite, TextureRegion region){
Rect over = Tmp.r3; Rect over = Tmp.r3;
boolean overlaps = Intersector.intersectRectangles(bounds, sprite, over); boolean overlaps = Intersector.intersectRectangles(bounds, sprite, over);
@@ -273,11 +272,11 @@ public class PayloadConveyor extends Block{
return out; return out;
} }
int curStep(){ public int curStep(){
return (int)((Time.time()) / moveTime); return (int)((Time.time()) / moveTime);
} }
float fract(){ public float fract(){
return interp.apply(progress / moveTime); return interp.apply(progress / moveTime);
} }
} }

View File

@@ -20,9 +20,9 @@ public class Router extends Block{
} }
public class RouterEntity extends Building{ public class RouterEntity extends Building{
Item lastItem; public Item lastItem;
Tile lastInput; public Tile lastInput;
float time; public float time;
@Override @Override
public void updateTile(){ public void updateTile(){
@@ -70,7 +70,7 @@ public class Router extends Block{
return result; return result;
} }
Building getTileTarget(Item item, Tile from, boolean set){ public Building getTileTarget(Item item, Tile from, boolean set){
int counter = rotation; int counter = rotation;
for(int i = 0; i < proximity.size; i++){ for(int i = 0; i < proximity.size; i++){
Building other = proximity.get((i + counter) % proximity.size); Building other = proximity.get((i + counter) % proximity.size);

View File

@@ -48,7 +48,7 @@ public class Sorter extends Block{
} }
public class SorterEntity extends Building{ public class SorterEntity extends Building{
@Nullable Item sortItem; public @Nullable Item sortItem;
@Override @Override
public void configured(Player player, Object value){ public void configured(Player player, Object value){
@@ -86,12 +86,12 @@ public class Sorter extends Block{
to.handleItem(this, item); to.handleItem(this, item);
} }
boolean isSame(Building other){ public boolean isSame(Building other){
//uncomment code below to prevent sorter/gate chaining // comment code below to allow sorter/gate chaining
return other != null && (other.block() instanceof Sorter || other.block() instanceof OverflowGate); return other != null && (other.block() instanceof Sorter || other.block() instanceof OverflowGate);
} }
Building getTileTarget(Item item, Building source, boolean flip){ public Building getTileTarget(Item item, Building source, boolean flip){
int dir = source.relativeTo(tile.x, tile.y); int dir = source.relativeTo(tile.x, tile.y);
if(dir == -1) return null; if(dir == -1) return null;
Building to; Building to;

View File

@@ -219,12 +219,12 @@ public class StackConveyor extends Block implements Autotiler{
return false; // has no moving parts; return false; // has no moving parts;
} }
private void poofIn(){ protected void poofIn(){
link = tile.pos(); link = tile.pos();
Fx.plasticburn.at(this); Fx.plasticburn.at(this);
} }
private void poofOut(){ protected void poofOut(){
Fx.plasticburn.at(this); Fx.plasticburn.at(this);
link = -1; link = -1;
} }