Improve PaddedGridDistributor Performance

This commit is contained in:
Zoe Gidiere
2025-12-10 23:17:06 -07:00
parent cf4f7822e2
commit 97b4ea6d94
2 changed files with 20 additions and 13 deletions

View File

@@ -10,7 +10,7 @@ object Versions {
const val tectonic = "4.3.1"
const val paralithic = "2.0.1"
const val strata = "1.3.2"
const val seismic = "2.5.2"
const val seismic = "2.5.4"
const val cloud = "2.0.0"

View File

@@ -2,18 +2,11 @@ package com.dfsek.terra.addons.feature.distributor.distributors;
import com.dfsek.seismic.algorithms.hashing.HashingFunctions;
import com.dfsek.seismic.math.integer.IntegerFunctions;
import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;
import com.dfsek.terra.api.structure.feature.Distributor;
public class PaddedGridDistributor implements Distributor {
private final int width;
private final int cellWidth;
private final int salt;
public PaddedGridDistributor(int width, int padding, int salt) {
@@ -27,12 +20,26 @@ public class PaddedGridDistributor implements Distributor {
int cellX = Math.floorDiv(x, cellWidth);
int cellZ = Math.floorDiv(z, cellWidth);
RandomGenerator random = RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of("Xoroshiro128PlusPlus").create(
(HashingFunctions.murmur64(IntegerFunctions.squash(cellX, cellZ)) ^ seed) + salt);
int localX = x - (cellX * cellWidth);
int localZ = z - (cellZ * cellWidth);
int pointX = random.nextInt(width) + cellX * cellWidth;
int pointZ = random.nextInt(width) + cellZ * cellWidth;
if (localX >= width || localZ >= width) {
return false;
}
return x == pointX && z == pointZ;
long hash = HashingFunctions.murmur64(IntegerFunctions.squash(cellX, cellZ)) ^ seed;
hash += salt;
hash = HashingFunctions.splitMix64(hash);
int targetX = (int) ((hash & 0x7FFFFFFFFFFFFFFFL) % width);
if (localX != targetX) {
return false;
}
hash = HashingFunctions.splitMix64(hash);
int targetZ = (int) ((hash & 0x7FFFFFFFFFFFFFFFL) % width);
return localZ == targetZ;
}
}