/** * Gets an array of landscapes that can be used to fade between one landscape type and the other. Contains the first and last landscape (or only * one element if the landscape is the same. * <p> * Returns null if there is no way the landscapes can be faded. * * @param l1 * @param l2 * @return */ public ELandscapeType[] getLandscapesBetween(ELandscapeType l1, ELandscapeType l2) { ELandscapeType[] buffered = fadeLandscapesBuffer[l1.ordinal()][l2.ordinal()]; if (buffered == null) { computeLandscapesFrom(l1); buffered = fadeLandscapesBuffer[l1.ordinal()][l2.ordinal()]; // int length = buffered.length; // ELandscapeType[] reverse = new ELandscapeType[length]; // for (int i = 0; i < length; i++) { // reverse[i] = buffered[length - 1 - i]; // } // fadeLandscapesBuffer[l2.ordinal()][l1.ordinal()] = reverse; } return buffered; }
private void computeLandscapesFrom(ELandscapeType l1) { System.out.println("Starting to compute fades from " + l1.toString()); ELandscapeType[][] ways = fadeLandscapesBuffer[l1.ordinal()]; ways[l1.ordinal()] = new ELandscapeType[] { l1 }; boolean foundnew = true; while (foundnew) { foundnew = false; for (FadableLandscapes f : allowed) { int ordinal1 = f.getL1().ordinal(); int ordinal2 = f.getL2().ordinal(); if (ways[ordinal1] == null && ways[ordinal2] != null) { ways[ordinal1] = add(ways[ordinal2], f.getL1()); foundnew = true; } if (ways[ordinal2] == null && ways[ordinal1] != null) { ways[ordinal2] = add(ways[ordinal1], f.getL2()); foundnew = true; } } } }
stream.writeByte(data.getLandscape(x, y).ordinal());