mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
synchronize maps
This commit is contained in:
parent
d327909389
commit
764344b4ef
@ -5,11 +5,12 @@ import com.dfsek.terra.generation.config.NoiseBuilder;
|
|||||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||||
import parsii.eval.Scope;
|
import parsii.eval.Scope;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GeneratorBuilder {
|
public class GeneratorBuilder {
|
||||||
private final Map<Long, WorldGenerator> gens = new HashMap<>();
|
private final Map<Long, WorldGenerator> gens = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
|
||||||
private String noiseEquation;
|
private String noiseEquation;
|
||||||
|
|
||||||
@ -35,7 +36,9 @@ public class GeneratorBuilder {
|
|||||||
|
|
||||||
|
|
||||||
public WorldGenerator build(long seed) {
|
public WorldGenerator build(long seed) {
|
||||||
return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, interpolateElevation, noise2d, base, biomeNoise.build((int) seed)));
|
synchronized(gens) {
|
||||||
|
return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, interpolateElevation, noise2d, base, biomeNoise.build((int) seed)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBiomeNoise(NoiseBuilder biomeNoise) {
|
public void setBiomeNoise(NoiseBuilder biomeNoise) {
|
||||||
|
@ -10,6 +10,7 @@ import com.google.common.cache.LoadingCache;
|
|||||||
import net.jafama.FastMath;
|
import net.jafama.FastMath;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -18,16 +19,20 @@ public class SamplerCache {
|
|||||||
private final TerraPlugin main;
|
private final TerraPlugin main;
|
||||||
|
|
||||||
public SamplerCache(TerraPlugin main) {
|
public SamplerCache(TerraPlugin main) {
|
||||||
containerMap = new HashMap<>();
|
containerMap = Collections.synchronizedMap(new HashMap<>());
|
||||||
this.main = main;
|
this.main = main;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sampler get(World world, int x, int z) {
|
public Sampler get(World world, int x, int z) {
|
||||||
return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).get(x, z);
|
synchronized(containerMap) {
|
||||||
|
return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).get(x, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sampler getChunk(World world, int chunkX, int chunkZ) {
|
public Sampler getChunk(World world, int chunkX, int chunkZ) {
|
||||||
return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).getChunk(chunkX, chunkZ);
|
synchronized(containerMap) {
|
||||||
|
return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).getChunk(chunkX, chunkZ);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user