Updated core and fixed generator bug

This commit is contained in:
tom lee
2022-01-05 19:18:52 +08:00
parent 965c19d426
commit f4c1f1bcd7
3 changed files with 90 additions and 40 deletions
@@ -26,6 +26,7 @@ import com.seibel.lod.common.wrappers.worldGeneration.WorldGenerationStep.Steps;
import com.seibel.lod.core.api.ClientApi;
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
import com.seibel.lod.core.enums.config.DistanceGenerationMode;
import com.seibel.lod.core.enums.config.GenerationPriority;
import com.seibel.lod.core.objects.PosToGenerateContainer;
import com.seibel.lod.core.objects.lod.LodDimension;
import com.seibel.lod.core.util.LevelPosUtil;
@@ -70,7 +71,10 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra
DistanceGenerationMode mode = CONFIG.client().worldGenerator().getDistanceGenerationMode();
numberOfGenerationPoints = CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads();
GenerationPriority priority = CONFIG.client().worldGenerator().getGenerationPriority();
if (priority == GenerationPriority.AUTO)
priority = MC.hasSinglePlayerServer() ? GenerationPriority.FAR_FIRST : GenerationPriority.NEAR_FIRST;
generationGroup.updateAllFutures();
if (mode == DistanceGenerationMode.NONE || !MC.hasSinglePlayerServer())
return;
@@ -95,9 +99,6 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra
// We are checking one FarPos, and one NearPos per iterations. This ensure we
// aren't just
// always picking one or the other.
int nearCount = posToGenerate.getNumberOfNearPos();
int farCount = posToGenerate.getNumberOfFarPos();
int maxIteration = Math.max(nearCount, farCount);
Steps targetStep;
switch (mode) {
case NONE:
@@ -121,41 +122,87 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra
assert false;
return;
}
for (int i = 0; i < maxIteration; i++) {
// We have nearPos to go though
if (i < nearCount && posToGenerate.getNthDetail(i, true) != 0) {
positionGoneThough++;
// TODO: Add comment here on why theres a '-1'.
// Not sure what's happening here. This is copied from previous codes.
byte detailLevel = (byte) (posToGenerate.getNthDetail(i, true) - 1);
int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, true));
int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, true));
int genSize = detailLevel > LodUtil.CHUNK_DETAIL_LEVEL ? 0 : generationGroupSize;
if (generationGroup.tryAddPoint(chunkX, chunkZ, genSize, targetStep)) {
toGenerate--;
if (priority == GenerationPriority.FAR_FIRST) {
int nearCount = posToGenerate.getNumberOfNearPos();
int farCount = posToGenerate.getNumberOfFarPos();
int maxIteration = Math.max(nearCount, farCount);
for (int i = 0; i < maxIteration; i++) {
// We have nearPos to go though
if (i < nearCount && posToGenerate.getNthDetail(i, true) != 0) {
positionGoneThough++;
// TODO: Add comment here on why theres a '-1'.
// Not sure what's happening here. This is copied from previous codes.
byte detailLevel = (byte) (posToGenerate.getNthDetail(i, true) - 1);
int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, true));
int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, true));
int genSize = detailLevel > LodUtil.CHUNK_DETAIL_LEVEL ? 0 : generationGroupSize;
if (generationGroup.tryAddPoint(chunkX, chunkZ, genSize, targetStep)) {
toGenerate--;
}
}
// We have farPos to go though
if (i < farCount && posToGenerate.getNthDetail(i, false) != 0) {
positionGoneThough++;
// TODO: Add comment here on why theres a '-1'.
// Not sure what's happening here. This is copied from previous codes.
byte detailLevel = (byte) (posToGenerate.getNthDetail(i, false) - 1);
int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, false));
int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, false));
if (generationGroup.tryAddPoint(chunkX, chunkZ, generationGroupSizeFar, targetStep)) {
toGenerate--;
}
}
if (toGenerate <= 0)
break;
}
} else {
int nearCount = posToGenerate.getNumberOfNearPos();
for (int i = 0; i < nearCount; i++) {
// We have nearPos to go though
if (posToGenerate.getNthDetail(i, true) != 0) {
positionGoneThough++;
// TODO: Add comment here on why theres a '-1'.
// Not sure what's happening here. This is copied from previous codes.
byte detailLevel = (byte) (posToGenerate.getNthDetail(i, true) - 1);
int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, true));
int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, true));
int genSize = detailLevel > LodUtil.CHUNK_DETAIL_LEVEL ? 0 : generationGroupSize;
if (generationGroup.tryAddPoint(chunkX, chunkZ, genSize, targetStep)) {
ClientApi.LOGGER.info("Added one NEAR event: "+genSize+"("+detailLevel+")");
toGenerate--;
}
if (toGenerate <= 0)
break;
}
}
//if (toGenerate <= 0)
// break;
// We have farPos to go though
if (i < farCount && posToGenerate.getNthDetail(i, false) != 0) {
positionGoneThough++;
// TODO: Add comment here on why theres a '-1'.
// Not sure what's happening here. This is copied from previous codes.
byte detailLevel = (byte) (posToGenerate.getNthDetail(i, false) - 1);
int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, false));
int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, false));
if (generationGroup.tryAddPoint(chunkX, chunkZ, generationGroupSizeFar, targetStep)) {
toGenerate--;
// Only do far gen if toGenerate is non 0 and that we have requested all samples we can get.
if (toGenerate > 0 && estimatedSampleNeeded > posToGenerate.getNumberOfPos()) {
int farCount = posToGenerate.getNumberOfFarPos();
for (int i = 0; i < farCount; i++) {
// We have farPos to go though
if (posToGenerate.getNthDetail(i, false) != 0) {
positionGoneThough++;
// TODO: Add comment here on why theres a '-1'.
// Not sure what's happening here. This is copied from previous codes.
byte detailLevel = (byte) (posToGenerate.getNthDetail(i, false) - 1);
int chunkX = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosX(i, false));
int chunkZ = LevelPosUtil.getChunkPos(detailLevel, posToGenerate.getNthPosZ(i, false));
if (generationGroup.tryAddPoint(chunkX, chunkZ, generationGroupSizeFar, targetStep)) {
ClientApi.LOGGER.info("Added one FAR event: 0");
toGenerate--;
}
}
if (toGenerate <= 0)
break;
}
}
if (toGenerate <= 0)
break;
}
//Enable this for logging
//Enable this for logging
if (targetToGenerate != toGenerate) {
if (toGenerate <= 0) {
ClientApi.LOGGER.info(
@@ -175,7 +222,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra
// Ensure wee don't go to basically infinity
if (estimatedSampleNeeded > 32768)
estimatedSampleNeeded = 32768;
//System.out.println("WorldGenerator: Increasing estimatedSampleNeeeded to " + estimatedSampleNeeded);
System.out.println("WorldGenerator: Increasing estimatedSampleNeeeded to " + estimatedSampleNeeded);
} else if (toGenerate <= 0 && positionGoneThough * 1.5 < posToGenerate.getNumberOfPos()) {
// We haven't gone though half of them and it's already enough.
@@ -184,7 +231,7 @@ public class ExperimentalGenerator extends AbstractExperimentalWorldGeneratorWra
// Ensure we don't go to near zero.
if (estimatedSampleNeeded < 4)
estimatedSampleNeeded = 4;
//System.out.println("WorldGenerator: Decreasing estimatedSampleNeeeded to " + estimatedSampleNeeded);
System.out.println("WorldGenerator: Decreasing estimatedSampleNeeeded to " + estimatedSampleNeeded);
}
}
@@ -355,8 +355,11 @@ public final class WorldGenerationStep {
}
public final boolean tooClose(int cx, int cz, int cr) {
int dist = Math.min(Math.abs(cx - pos.x), Math.abs(cz - pos.z));
return dist < range + cr;
int distX = Math.abs(cx - pos.x);
int distZ = Math.abs(cz - pos.z);
int minRange = cr+range+1; //Need one to account for the center
minRange += 3 + 3; // Account for required empty chunks
return distX < minRange && distZ < minRange;
}
public final void refreshTimeout() {
@@ -434,7 +437,7 @@ public final class WorldGenerationStep {
}
public final void generateLodFromList(GenerationEvent event) {
// System.out.println("Started event: "+event);
if (event.range!=0) System.out.println("Started event: "+event);
event.pEvent.beginNano = System.nanoTime();
GridList<ChunkAccess> referencedChunks;
DistanceGenerationMode generationMode;
+1 -1
Submodule core updated: 4bf004ae6b...e71660eb41