Cache upstream

But i do ¬ like how this turned out, so reverting :(
This commit is contained in:
Patrick 'Quezler' Mounier
2020-02-07 10:59:45 +01:00
parent 9abb08152b
commit 908018b97c

View File

@@ -26,6 +26,8 @@ import static mindustry.Vars.*;
public class CraterConveyor extends Block implements Autotiler{
private TextureRegion[] regions = new TextureRegion[8];
private Tile upstream;
public float speed = 0f;
public CraterConveyor(String name){
@@ -145,6 +147,8 @@ public class CraterConveyor extends Block implements Autotiler{
entity.blendbit1 = bits[0];
entity.blendsclx = bits[1];
entity.blendscly = bits[2];
upstream(tile);
}
@Override
@@ -256,6 +260,7 @@ public class CraterConveyor extends Block implements Autotiler{
int blendbit1, blendbit2;
int blendsclx, blendscly;
int[] upstream = new int[3];
int from = Pos.invalid;
float reload;
@@ -276,37 +281,43 @@ public class CraterConveyor extends Block implements Autotiler{
}
}
private void upstream(Tile tile, Cons<Tile> cons){
private void upstream(Tile tile){
CraterConveyorEntity entity = tile.ent();
if( entity.blendbit1 == 0 // 1 input from the back, 0 from the sides
|| entity.blendbit1 == 2 // 1 input from the back, 1 from the sides
|| entity.blendbit1 == 3 // 1 input from the back, 2 from the sides
) cons.get(tile.back());
) entity.upstream[0] = tile.back().pos(); else entity.upstream[0] = Pos.invalid;
if( entity.blendbit1 == 3 // 1 input from the back, 2 from the sides
|| entity.blendbit1 == 4 // 0 input from the back, 2 from the sides
||(entity.blendbit1 == 1 && entity.blendscly == -1) // side is open
||(entity.blendbit1 == 2 && entity.blendscly == +1) // side is open
) cons.get(tile.right());
) entity.upstream[1] = tile.right().pos(); else entity.upstream[1] = Pos.invalid;
if( entity.blendbit1 == 3 // 1 input from the back, 2 from the sides
|| entity.blendbit1 == 4 // 0 input from the back, 2 from the sides
||(entity.blendbit1 == 1 && entity.blendscly == +1) // side is open
||(entity.blendbit1 == 2 && entity.blendscly == -1) // side is open
) cons.get(tile.left());
) entity.upstream[2] = tile.left().pos(); else entity.upstream[2] = Pos.invalid;
}
// ▲ | ▼ fixme: refactor
// awaken inputting conveyors
private void bump(Tile tile){
upstream(tile, t -> {
if(t != null && t.entity != null && t.entity.isSleeping() && t.entity.items.total() > 0){
t.entity.noSleep();
bump(t);
CraterConveyorEntity entity = tile.ent();
for(int i = 0; i < 3; i++){
if(entity.upstream[i] == Pos.invalid) continue;
upstream = world.tile(entity.upstream[i]);
if(upstream != null && upstream.entity != null && upstream.entity.isSleeping() && upstream.entity.items.total() > 0){
upstream.entity.noSleep();
bump(upstream);
}
});
}
}
public boolean shouldLaunch(Tile tile){