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
@@ -90,4 +90,8 @@ public final class MathUtil {
return Math.sqrt(((xVal2 - xVal1) * (xVal2 - xVal1)) + ((zVal2 - zVal1) * (zVal2 - zVal1)) + ((yVal2 - yVal1) * (yVal2 - yVal1))); 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);
}
} }
@@ -43,7 +43,7 @@ public class ChunkCoordinate implements Serializable {
@Override @Override
public boolean equals(Object obj) { 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; 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; return other.getX() == x && other.getZ() == z;
} }
@@ -37,7 +37,7 @@ public class CarverCache {
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, UserDefinedCarver carver) { public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, UserDefinedCarver carver) {
synchronized(carvers) { 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(); TerraBiomeGrid grid = main.getWorld(w).getGrid();
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + carver.hashCode())))) { if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + carver.hashCode())))) {
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed()); long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
@@ -1,6 +1,7 @@
package com.dfsek.terra.generation.math; package com.dfsek.terra.generation.math;
import com.dfsek.terra.TerraWorld; 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.TerraPlugin;
import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.World;
import net.jafama.FastMath; import net.jafama.FastMath;
@@ -53,7 +54,7 @@ public class SamplerCache {
} }
public Sampler getChunk(int cx, int cz) { public Sampler getChunk(int cx, int cz) {
long key = (((long) cx) << 32) | (cz & 0xffffffffL); long key = MathUtil.squash(cx, cz);
synchronized(cache) { synchronized(cache) {
return cache.computeIfAbsent(key, k -> new Sampler(cx, cz, terraWorld.getGrid(), world, terraWorld.getConfig().getTemplate().getBaseBlend(), terraWorld.getConfig().getTemplate().getElevationBlend())); return cache.computeIfAbsent(key, k -> new Sampler(cx, cz, terraWorld.getGrid(), world, terraWorld.getConfig().getTemplate().getBaseBlend(), terraWorld.getConfig().getTemplate().getElevationBlend()));
} }
@@ -1,5 +1,6 @@
package com.dfsek.terra; package com.dfsek.terra;
import com.dfsek.terra.api.math.MathUtil;
import net.querz.mca.MCAUtil; import net.querz.mca.MCAUtil;
public final class DirectUtils { public final class DirectUtils {
@@ -12,6 +13,6 @@ public final class DirectUtils {
* @return Region IS * @return Region IS
*/ */
public static long regionID(int x, int z) { public static long regionID(int x, int z) {
return (((long) MCAUtil.chunkToRegion(x)) << 32) | (MCAUtil.chunkToRegion(z) & 0xffffffffL); return MathUtil.squash(MCAUtil.chunkToRegion(x), MCAUtil.chunkToRegion(z));
} }
} }