Skip to content

Commit

Permalink
Performance optimizations and version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Dioswilson committed Jan 24, 2024
1 parent e6c39d5 commit 536e6e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'com.dioswilson'
version '1.2.1'
version '1.2.2'

repositories {
mavenCentral()
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/com/dioswilson/WitchSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,28 @@ public void print() {

public void initialize() {

CopyableRandom rand = new CopyableRandom(seed);
rand.advanceSeed(4);
for (int i = 0; i <= this.maxAdvancers; i++) {
this.advancers = 0;
Arrays.fill(this.finalHeightMap, 0);
this.positions.clear();
this.blocksToFill.clear();
calculateRandomChunkPositionsFull(4 + i);
calculateRandomChunkPositionsFull(4 + i, rand.getCurrentSeed());
rand.nextInt();
}

}

private void calculateRandomChunkPositionsFull(int calls) {
private void calculateRandomChunkPositionsFull(int calls, long initialSeed) {
int validChunks = 0;
HashMap<Long, Integer> differentSeeds = new HashMap<>(); //TODO: naming
HashMap<Long, Integer> differentSeedsTemp = new HashMap<>();

CopyableRandom initRand = new CopyableRandom(seed);
for (int i = 0; i < calls; i++) {
initRand.nextInt();
}
differentSeeds.put(initRand.getCurrentSeed(), 1);
// CopyableRandom initRand = new CopyableRandom(seed);
// initRand.advanceSeed(calls);

differentSeeds.put(initialSeed, 1);

int i = 0;
int extraCalls = 0;
Expand Down Expand Up @@ -176,9 +178,7 @@ private void calculateRandomChunkPositionsFull(int calls) {
CopyableRandom rand = new CopyableRandom(seed);
rand.setCurrentSeed(specificSeed);

for (int i1 = 0; i1 < extraCalls; i1++) {
rand.nextInt();
}
rand.advanceSeed(extraCalls);

BlockPos blockpos = getRandomChunkPosition(rand, chunk.getX(), chunk.getZ(), height);
int staticY = blockpos.getY();
Expand Down Expand Up @@ -417,9 +417,8 @@ public void getBlocksPositions(int calls, int playerX, int playerZ) {
HashMap<Long, Integer> differentSeedsTemp = new HashMap<>();

CopyableRandom initRand = new CopyableRandom(seed);
for (int i = 0; i < calls; i++) {
initRand.nextInt();
}
initRand.advanceSeed(calls);

differentSeeds.put(initRand.getCurrentSeed(), 1);

Set<BlockPos> positionsTemp = new HashSet<>();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/dioswilson/utils/CopyableRandom.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ public CopyableRandom copy() {
return new CopyableRandom((seed.get() ^ multiplier) & mask);
}

public void advanceSeed(int advancers) {
for (int i = 0; i < advancers; i++) {
next(48);
}
}
}

0 comments on commit 536e6e2

Please sign in to comment.