Skip to content

Commit df5af39

Browse files
committed
wip changes
1 parent e22d4cb commit df5af39

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

core/src/mindustry/world/blocks/storage/Unloader.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public class UnloaderBuild extends Building{
9393
public Item sortItem = null;
9494
public ContainerStat dumpingFrom, dumpingTo;
9595
public final Seq<ContainerStat> possibleBlocks = new Seq<>(ContainerStat.class);
96+
public final BoolSeq itemCanUnload = new BoolSeq(allItems != null ? allItems.length : 16);
97+
public final BoolSeq itemCanReceived = new BoolSeq(allItems != null ? allItems.length : 16);
9698

9799
protected final Comparator<ContainerStat> comparator = (x, y) -> {
98100
//sort so it gives priority for blocks that can only either receive or give (not both), and then by load, and then by last use
@@ -165,10 +167,39 @@ public void updateTile(){
165167
if(sortItem != null){
166168
if(isPossibleItem(sortItem)) item = sortItem;
167169
}else{
170+
int len = allItems.length;
171+
var pbi = possibleBlocks.items;
172+
int pbs = possibleBlocks.size;
173+
174+
Arrays.fill(itemCanUnload.items, false);
175+
Arrays.fill(itemCanReceived.items, false);
176+
177+
for(int i = 0; i < pbs; i++){
178+
var pb = pbi[i];
179+
var other = pb.building;
180+
181+
for(int j = 0; j < len; j++){
182+
var it = allItems[j];
183+
184+
//items that have stock in at least one neighbour
185+
if(other.canUnload() && other.items != null && other.items.has(it)){
186+
itemCanUnload.items[j] = true;
187+
}
188+
//items that at least one neighbour will accept
189+
if(pb.notStorage && other.acceptItem(this, it)){
190+
itemCanReceived.items[j] = true;
191+
}
192+
}
193+
}
194+
168195
//selects the next item for nulloaders
169196
//inspired of nextIndex() but for all "proximity" (possibleBlocks) at once, and also way more powerful
170-
for(int i = 0, l = allItems.length; i < l; i++){
171-
int id = (rotations + i + 1) % l;
197+
for(int i = 0; i < len; i++){
198+
int id = (rotations + i + 1) % len;
199+
200+
//isPossibleItem() is expensive, avoid calls whenever possible
201+
if(!itemCanUnload.items[id] || !itemCanReceived.items[id]) continue;
202+
172203
var possibleItem = allItems[id];
173204

174205
if(isPossibleItem(possibleItem)){

0 commit comments

Comments
 (0)