mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-19 15:20:55 +00:00
Perf opts
This commit is contained in:
+4
-4
@@ -14,14 +14,14 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
|||||||
public class BiomeExtrusionProvider implements BiomeProvider {
|
public class BiomeExtrusionProvider implements BiomeProvider {
|
||||||
private final BiomeProvider delegate;
|
private final BiomeProvider delegate;
|
||||||
private final Set<Biome> biomes;
|
private final Set<Biome> biomes;
|
||||||
private final List<Extrusion> extrusions;
|
private final Extrusion[] extrusions;
|
||||||
private final int resolution;
|
private final int resolution;
|
||||||
|
|
||||||
public BiomeExtrusionProvider(BiomeProvider delegate, List<Extrusion> extrusions, int resolution) {
|
public BiomeExtrusionProvider(BiomeProvider delegate, List<Extrusion> extrusions, int resolution) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.biomes = delegate.stream().collect(Collectors.toSet());
|
this.biomes = delegate.stream().collect(Collectors.toSet());
|
||||||
extrusions.forEach(e -> biomes.addAll(e.getBiomes()));
|
extrusions.forEach(e -> biomes.addAll(e.getBiomes()));
|
||||||
this.extrusions = extrusions;
|
this.extrusions = extrusions.toArray(new Extrusion[0]);
|
||||||
this.resolution = resolution;
|
this.resolution = resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ public class BiomeExtrusionProvider implements BiomeProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Biome extrude(Biome original, int x, int y, int z, long seed) {
|
public Biome extrude(Biome original, int x, int y, int z, long seed) {
|
||||||
for(Extrusion extrusion : extrusions) {
|
for(int i = 0; i < extrusions.length; i++) {
|
||||||
original = extrusion.extrude(original, x, y, z, seed);
|
original = extrusions[i].extrude(original, x, y, z, seed);
|
||||||
}
|
}
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class Context {
|
|||||||
private static final AtomicInteger size = new AtomicInteger(0);
|
private static final AtomicInteger size = new AtomicInteger(0);
|
||||||
private static final Map<Class<? extends Properties>, PropertyKey<?>> properties = new HashMap<>();
|
private static final Map<Class<? extends Properties>, PropertyKey<?>> properties = new HashMap<>();
|
||||||
private final Map<Class<? extends Properties>, Properties> map = new HashMap<>();
|
private final Map<Class<? extends Properties>, Properties> map = new HashMap<>();
|
||||||
private final AtomicReference<Properties[]> list = new AtomicReference<>(new Properties[size.get()]);
|
private Properties[] list = new Properties[size.get()];
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Properties> PropertyKey<T> create(Class<T> clazz) {
|
public static <T extends Properties> PropertyKey<T> create(Class<T> clazz) {
|
||||||
@@ -38,19 +38,19 @@ public class Context {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Properties> Context put(PropertyKey<T> key, T properties) {
|
public synchronized <T extends Properties> Context put(PropertyKey<T> key, T properties) {
|
||||||
list.updateAndGet(p -> {
|
if(list.length != size.get()) {
|
||||||
if(p.length == size.get()) return p;
|
|
||||||
Properties[] p2 = new Properties[size.get()];
|
Properties[] p2 = new Properties[size.get()];
|
||||||
System.arraycopy(p, 0, p2, 0, p.length);
|
System.arraycopy(list, 0, p2, 0, list.length);
|
||||||
return p2;
|
list = p2;
|
||||||
})[key.key] = properties;
|
}
|
||||||
|
list[key.key] = properties;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Properties> T get(PropertyKey<T> key) {
|
public <T extends Properties> T get(PropertyKey<T> key) {
|
||||||
return (T) list.get()[key.key];
|
return (T) list[key.key];
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Properties> boolean has(Class<T> test) {
|
public <T extends Properties> boolean has(Class<T> test) {
|
||||||
|
|||||||
Reference in New Issue
Block a user