diff --git a/src/main/java/tesseract/api/gt/GTController.java b/src/main/java/tesseract/api/gt/GTController.java index 7c9da1a2..9971e627 100644 --- a/src/main/java/tesseract/api/gt/GTController.java +++ b/src/main/java/tesseract/api/gt/GTController.java @@ -12,7 +12,6 @@ import tesseract.util.Node; import tesseract.util.Pos; -import java.util.Comparator; import java.util.List; /** @@ -46,8 +45,11 @@ public GTController(int dim) { */ @Override public void change() { + //noinspection StatementWithEmptyBody + while(!changeInternal()); // not sure how many times we may break the network while changing it + } + private boolean changeInternal(){ data.clear(); - for (Long2ObjectMap.Entry> e : group.getNodes().long2ObjectEntrySet()) { long pos = e.getLongKey(); IGTNode producer = e.getValue().value(); @@ -60,7 +62,8 @@ public void change() { long side = position.offset(direction).asLong(); if (group.getNodes().containsKey(side)) { - onCheck(producer, consumers, null, pos,side); + if (!onCheck(producer, consumers, null, pos,side)) + return false; } else { Grid grid = group.getGridAt(side, direction); if (grid != null) { @@ -68,7 +71,8 @@ public void change() { if (!path.isEmpty()) { Node target = path.target(); assert target != null; - onCheck(producer, consumers, path,pos, target.asLong()); + if (!onCheck(producer, consumers, path,pos, target.asLong())) + return false; } } } @@ -89,6 +93,7 @@ public void change() { for (List consumers : data.values()) { consumers.sort(GTConsumer.COMPARATOR); } + return true; } /** @@ -122,11 +127,11 @@ private void onMerge(IGTNode producer, List consumers) { * @param consumerPos The position of the consumer. * @param producerPos The position of the producer. */ - private void onCheck(IGTNode producer, List consumers, Path path, long producerPos, long consumerPos) { + private boolean onCheck(IGTNode producer, List consumers, Path path, long producerPos, long consumerPos) { Cache nodee = group.getNodes().get(consumerPos); if (nodee == null) { System.out.println("Error in onCheck, null cache."); - return; + return false; } IGTNode node = nodee.value(); Pos pos = new Pos(consumerPos).sub(new Pos(producerPos)); @@ -136,15 +141,17 @@ private void onCheck(IGTNode producer, List consumers, Path