commit
196a2bca7b
|
@ -1,7 +1,6 @@
|
|||
package amidst.fragment;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
@ -77,12 +76,7 @@ import amidst.mojangapi.world.oracle.EndIsland;
|
|||
*/
|
||||
@NotThreadSafe
|
||||
public class Fragment {
|
||||
// Every pixel in the fragment is 2^size blocks in minecraft
|
||||
private int size; //= Resolution.FRAGMENT.getStep();
|
||||
public static int SIZE = 1 << 9;
|
||||
// Resolution, same as size
|
||||
public static Resolution resolution = null;
|
||||
public Resolution localResolution = null;
|
||||
public static final int SIZE = Resolution.FRAGMENT.getStep();
|
||||
|
||||
private volatile boolean isInitialized = false;
|
||||
private volatile boolean isLoaded = false;
|
||||
|
@ -107,69 +101,16 @@ public class Fragment {
|
|||
return alpha;
|
||||
}
|
||||
|
||||
public void initBiomeData(int width, int height, Resolution resolution) {
|
||||
this.localResolution = resolution;
|
||||
public void initBiomeData(int width, int height) {
|
||||
biomeData = new short[width][height];
|
||||
}
|
||||
|
||||
@CalledOnlyBy(AmidstThread.FRAGMENT_LOADER)
|
||||
public void populateBiomeData(BiomeDataOracle biomeDataOracle) {
|
||||
if(localResolution == Resolution.WORLD) {
|
||||
biomeDataOracle.populateArray(corner, biomeData, false);
|
||||
}
|
||||
else if(localResolution == Resolution.QUARTER) {
|
||||
biomeDataOracle.populateArray(corner, biomeData, true);
|
||||
}
|
||||
else {
|
||||
int size = Resolution.QUARTER.getStepsPerFragment();
|
||||
int step = localResolution.getStep() / Resolution.QUARTER.getStep();
|
||||
short[][] tmpBiomeData = new short[size][size];
|
||||
biomeDataOracle.populateArray(corner, tmpBiomeData, true);
|
||||
for (int i = 0; i<biomeData.length; i++) {
|
||||
for (int j = 0; j<biomeData[i].length; j++) {
|
||||
// This way is faster
|
||||
//short biome = tmpBiomeData[i*step][j*step];
|
||||
// This way is more accurate: it finds the most common biome
|
||||
short biomes[] = new short[step*step];
|
||||
for (int k = 0; k<step; k++) {
|
||||
for (int l = 0; l<step; l++) {
|
||||
biomes[k*step+l] = tmpBiomeData[i*step+k][j*step+l];
|
||||
}
|
||||
}
|
||||
short biome = mostCommonFromArray(biomes);
|
||||
biomeData[i][j] = biome;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private short mostCommonFromArray(short a[]) {
|
||||
Arrays.sort(a);
|
||||
|
||||
short previous = a[0];
|
||||
short popular = a[0];
|
||||
int count = 1;
|
||||
int maxCount = 1;
|
||||
|
||||
for (int i = 1; i < a.length; i++) {
|
||||
if (a[i] == previous)
|
||||
count++;
|
||||
else {
|
||||
if (count > maxCount) {
|
||||
popular = a[i-1];
|
||||
maxCount = count;
|
||||
}
|
||||
previous = a[i];
|
||||
count = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return count > maxCount ? a[a.length-1] : popular;
|
||||
biomeDataOracle.populateArray(corner, biomeData, true);
|
||||
}
|
||||
|
||||
public short getBiomeDataAt(int x, int y) {
|
||||
//if(x==0 || y==0) return 0;
|
||||
//return (short)(((x+y)&1)+5);
|
||||
return biomeData[x][y];
|
||||
}
|
||||
|
||||
|
|
|
@ -5,22 +5,19 @@ import amidst.documentation.CalledOnlyBy;
|
|||
import amidst.documentation.Immutable;
|
||||
import amidst.fragment.Fragment;
|
||||
import amidst.mojangapi.world.coordinates.Resolution;
|
||||
import amidst.settings.Setting;
|
||||
|
||||
@Immutable
|
||||
public class BiomeDataConstructor implements FragmentConstructor {
|
||||
private final int size;
|
||||
private final Resolution resolution;
|
||||
|
||||
@CalledOnlyBy(AmidstThread.EDT)
|
||||
public BiomeDataConstructor(Resolution resolution) {
|
||||
this.size = resolution.getStepsPerFragment();
|
||||
this.resolution = resolution;
|
||||
}
|
||||
|
||||
@CalledOnlyBy(AmidstThread.EDT)
|
||||
@Override
|
||||
public void construct(Fragment fragment) {
|
||||
fragment.initBiomeData(size, size, resolution);
|
||||
fragment.initBiomeData(size, size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,11 +40,8 @@ import amidst.settings.Settings;
|
|||
@Immutable
|
||||
public class LayerBuilder {
|
||||
private final Iterable<FragmentConstructor> constructors;
|
||||
private Resolution biomeResolution;
|
||||
|
||||
public LayerBuilder() {
|
||||
this.biomeResolution = Resolution.CHUNK;
|
||||
Fragment.resolution = this.biomeResolution;
|
||||
this.constructors = createConstructors();
|
||||
}
|
||||
|
||||
|
@ -54,9 +51,9 @@ public class LayerBuilder {
|
|||
private Iterable<FragmentConstructor> createConstructors() {
|
||||
return Collections.unmodifiableList(
|
||||
Arrays.asList(
|
||||
new BiomeDataConstructor(this.biomeResolution),
|
||||
new BiomeDataConstructor(Resolution.QUARTER),
|
||||
new EndIslandsConstructor(),
|
||||
new ImageConstructor(this.biomeResolution, LayerIds.BACKGROUND),
|
||||
new ImageConstructor(Resolution.QUARTER, LayerIds.BACKGROUND),
|
||||
new ImageConstructor(Resolution.CHUNK, LayerIds.SLIME)));
|
||||
}
|
||||
|
||||
|
@ -136,7 +133,7 @@ public class LayerBuilder {
|
|||
new AlphaInitializer( declarations.get(LayerIds.ALPHA), settings.fragmentFading),
|
||||
new BiomeDataLoader( declarations.get(LayerIds.BIOME_DATA), world.getBiomeDataOracle()),
|
||||
new EndIslandsLoader( declarations.get(LayerIds.END_ISLANDS), world.getEndIslandOracle()),
|
||||
new ImageLoader( declarations.get(LayerIds.BACKGROUND), this.biomeResolution, new BackgroundColorProvider(new BiomeColorProvider(biomeSelection, settings.biomeProfileSelection), new TheEndColorProvider())),
|
||||
new ImageLoader( declarations.get(LayerIds.BACKGROUND), Resolution.QUARTER, new BackgroundColorProvider(new BiomeColorProvider(biomeSelection, settings.biomeProfileSelection), new TheEndColorProvider())),
|
||||
new ImageLoader( declarations.get(LayerIds.SLIME), Resolution.CHUNK, new SlimeColorProvider(world.getSlimeChunkOracle())),
|
||||
new WorldIconLoader<>(declarations.get(LayerIds.SPAWN), world.getSpawnProducer()),
|
||||
new WorldIconLoader<>(declarations.get(LayerIds.STRONGHOLD), world.getStrongholdProducer()),
|
||||
|
@ -162,7 +159,7 @@ public class LayerBuilder {
|
|||
// @formatter:off
|
||||
return Collections.unmodifiableList(Arrays.asList(
|
||||
new AlphaUpdater( declarations.get(LayerIds.ALPHA)),
|
||||
new ImageDrawer( declarations.get(LayerIds.BACKGROUND), this.biomeResolution, accelerationCounter),
|
||||
new ImageDrawer( declarations.get(LayerIds.BACKGROUND), Resolution.QUARTER, accelerationCounter),
|
||||
new ImageDrawer( declarations.get(LayerIds.SLIME), Resolution.CHUNK, accelerationCounter),
|
||||
new GridDrawer( declarations.get(LayerIds.GRID), zoom),
|
||||
new WorldIconDrawer(declarations.get(LayerIds.SPAWN), zoom, worldIconSelection),
|
||||
|
|
|
@ -69,8 +69,8 @@ public class CursorInformationWidget extends TextWidget {
|
|||
private String getOverworldBiomeNameAt(CoordinatesInWorld coordinates) {
|
||||
Fragment fragment = graph.getFragmentAt(coordinates);
|
||||
if (fragment != null && fragment.isLoaded()) {
|
||||
long x = coordinates.getXRelativeToFragmentAs(Fragment.resolution);
|
||||
long y = coordinates.getYRelativeToFragmentAs(Fragment.resolution);
|
||||
long x = coordinates.getXRelativeToFragmentAs(Resolution.QUARTER);
|
||||
long y = coordinates.getYRelativeToFragmentAs(Resolution.QUARTER);
|
||||
short biome = fragment.getBiomeDataAt((int) x, (int) y);
|
||||
try {
|
||||
return Biome.getByIndex(biome).getName();
|
||||
|
|
Loading…
Reference in New Issue