This commit is contained in:
dfsek
2021-01-09 02:58:02 -07:00
parent 141b4f86ae
commit 9310114c0e
5 changed files with 10 additions and 4 deletions

View File

@@ -90,4 +90,8 @@ public final class MathUtil {
return Math.sqrt(((xVal2 - xVal1) * (xVal2 - xVal1)) + ((zVal2 - zVal1) * (zVal2 - zVal1)) + ((yVal2 - yVal1) * (yVal2 - yVal1)));
}
public static long squash(int first, int last) {
return (((long) first) << 32) | (last & 0xffffffffL);
}
}

View File

@@ -43,7 +43,7 @@ public class ChunkCoordinate implements Serializable {
@Override
public boolean equals(Object obj) {
if(!(obj instanceof com.dfsek.terra.api.world.generation.population.ChunkCoordinate)) return false;
if(!(obj instanceof ChunkCoordinate)) return false;
com.dfsek.terra.api.world.generation.population.ChunkCoordinate other = (com.dfsek.terra.api.world.generation.population.ChunkCoordinate) obj;
return other.getX() == x && other.getZ() == z;
}

View File

@@ -37,7 +37,7 @@ public class CarverCache {
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, UserDefinedCarver carver) {
synchronized(carvers) {
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL), key -> {
return carvers.computeIfAbsent(MathUtil.squash(chunkX, chunkZ), key -> {
TerraBiomeGrid grid = main.getWorld(w).getGrid();
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + carver.hashCode())))) {
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());

View File

@@ -1,6 +1,7 @@
package com.dfsek.terra.generation.math;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.math.MathUtil;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.world.World;
import net.jafama.FastMath;
@@ -53,7 +54,7 @@ public class SamplerCache {
}
public Sampler getChunk(int cx, int cz) {
long key = (((long) cx) << 32) | (cz & 0xffffffffL);
long key = MathUtil.squash(cx, cz);
synchronized(cache) {
return cache.computeIfAbsent(key, k -> new Sampler(cx, cz, terraWorld.getGrid(), world, terraWorld.getConfig().getTemplate().getBaseBlend(), terraWorld.getConfig().getTemplate().getElevationBlend()));
}