From 65a7b7764ea5a5f67afc19d19070aa8e9cbbd7e6 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Mon, 2 Oct 2017 20:24:24 -0500 Subject: Rebase to latest experimental head --- .../java/gregtech/common/GT_Worldgenerator.java | 41 +++++++++++++++++----- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Worldgenerator.java') diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index 9d68b13f40..d69cf5c9c7 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -15,6 +15,9 @@ import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.ChunkProviderEnd; import net.minecraft.world.gen.ChunkProviderHell; +import static gregtech.api.enums.GT_Values.D1; +import static gregtech.api.enums.GT_Values.oreveinPercentage; +import static gregtech.api.enums.GT_Values.debugWorldGen; import java.util.ArrayList; import java.util.List; @@ -49,7 +52,7 @@ public class GT_Worldgenerator //gcMaxSize = GregTech_API.sWorldgenFile.get("gcasteroids", "GCAsteroidMaxSize", 400); //mGCAsteroidProbability = GregTech_API.sWorldgenFile.get("gcasteroids", "GCAsteroidProbability", 300); GameRegistry.registerWorldGenerator(this, 1073741823); - if (D1) { + if (debugWorldGen) { GT_Log.out.println( "GT_Worldgenerator created" ); @@ -60,14 +63,14 @@ public class GT_Worldgenerator synchronized (listLock) { this.mList.add(new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, ((aChunkGenerator instanceof ChunkProviderEnd)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.sky) ? 1 : ((aChunkGenerator instanceof ChunkProviderHell)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.hell) ? -1 : 0, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); - if (D1) {GT_Log.out.println("ADD WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size());} + if (debugWorldGen) {GT_Log.out.println("ADD WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size());} } if (!this.mIsGenerating) { this.mIsGenerating = true; int mList_sS=this.mList.size(); for (int i = 0; i < mList_sS; i++) { WorldGenContainer toRun = (WorldGenContainer) this.mList.get(0); - if (D1) {GT_Log.out.println("RUN WorldGen chunk x:" + toRun.mX/16 + " z:" + toRun.mZ/16 + " SIZE: " + this.mList.size());} + if (debugWorldGen) {GT_Log.out.println("RUN WorldGen chunk x:" + toRun.mX/16 + " z:" + toRun.mZ/16 + " SIZE: " + this.mList.size());} synchronized (listLock) { this.mList.remove(0); @@ -110,10 +113,12 @@ public class GT_Worldgenerator public void run() { if ((Math.abs(this.mX / 16) % 3 == 1) && (Math.abs(this.mZ / 16) % 3 == 1)) { - if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { + int oreveinRNG = this.mRandom.nextInt(100); + if (( oreveinRNG < oreveinPercentage) && (GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { boolean temp = true; int tRandomWeight; - for (int i = 0; (i < 256) && (temp); i++) { + int i; + for (i = 0; (i < 256) && (temp); i++) { tRandomWeight = this.mRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight); for (GT_Worldgen tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight; @@ -131,13 +136,33 @@ public class GT_Worldgenerator } if (D1 & temp) { GT_Log.out.println( - "No Orevein Selected!" + + "No orevein selected!" + " @ dim="+ this.mDimensionType+ " chunkX="+ this.mX + " chunkZ="+ this.mZ ); - } + } else if (D1) + { + GT_Log.out.println( + "Orevein took " + i + " attempts to find" + ); + } + + }else + { + if((oreveinRNG >= oreveinPercentage) && (D1)) + { + GT_Log.out.println( + "Skipped orevein in this 3x3 chunk!" + + " @ dim="+ this.mDimensionType+ + " chunkX="+ this.mX + + " chunkZ="+ this.mZ + + " RNG=" + oreveinRNG + + " %=" + oreveinPercentage + ); + } } + int i = 0; for (int tX = this.mX - 16; i < 3; tX += 16) { int j = 0; @@ -162,7 +187,7 @@ public class GT_Worldgenerator { if (D1) { GT_Log.out.println( - "Chunk Skipped, not 3x3 center" + + "Skipped chunk, not 3x3 center" + " @ dim="+this.mDimensionType+ " chunkX="+this.mX+ " chunkZ="+this.mZ -- cgit From 8c867332c01b823293006ea5fa9f91fe79d55008 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Sat, 16 Sep 2017 13:15:51 -0500 Subject: Missed a execCount. Modified output to print dimension name instead of dimension number, since TF and others reuse dim 0. --- src/main/java/gregtech/common/GT_Worldgenerator.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Worldgenerator.java') diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index d69cf5c9c7..a99da09916 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -112,10 +112,12 @@ public class GT_Worldgenerator } public void run() { + String tDimensionName = this.mWorld.provider.getDimensionName(); if ((Math.abs(this.mX / 16) % 3 == 1) && (Math.abs(this.mZ / 16) % 3 == 1)) { int oreveinRNG = this.mRandom.nextInt(100); if (( oreveinRNG < oreveinPercentage) && (GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { boolean temp = true; + int tRandomWeight; int i; for (i = 0; (i < 256) && (temp); i++) { @@ -139,12 +141,15 @@ public class GT_Worldgenerator "No orevein selected!" + " @ dim="+ this.mDimensionType+ " chunkX="+ this.mX + - " chunkZ="+ this.mZ + " chunkZ="+ this.mZ + + " dimensionName=" + tDimensionName ); } else if (D1) { GT_Log.out.println( - "Orevein took " + i + " attempts to find" + "Orevein took " + i + + " attempts to find" + + " dimensionName=" + tDimensionName ); } @@ -158,7 +163,8 @@ public class GT_Worldgenerator " chunkX="+ this.mX + " chunkZ="+ this.mZ + " RNG=" + oreveinRNG + - " %=" + oreveinPercentage + " %=" + oreveinPercentage+ + " dimensionName=" + tDimensionName ); } } @@ -190,7 +196,8 @@ public class GT_Worldgenerator "Skipped chunk, not 3x3 center" + " @ dim="+this.mDimensionType+ " chunkX="+this.mX+ - " chunkZ="+this.mZ + " chunkZ="+this.mZ+ + " dimensionName=" + tDimensionName ); } } -- cgit From 94b24d92e0b533e0631c70748c32a0b5719bfb68 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Mon, 2 Oct 2017 20:04:20 -0500 Subject: Add variable to configure number of attempts before giving up, default to 64. Set default orevein fill rate to 75% --- src/main/java/gregtech/common/GT_Worldgenerator.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Worldgenerator.java') diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index a99da09916..47990cae64 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -18,6 +18,8 @@ import net.minecraft.world.gen.ChunkProviderHell; import static gregtech.api.enums.GT_Values.D1; import static gregtech.api.enums.GT_Values.oreveinPercentage; import static gregtech.api.enums.GT_Values.debugWorldGen; +import static gregtech.api.enums.GT_Values.debugOrevein; +import static gregtech.api.enums.GT_Values.oreveinAttempts; import java.util.ArrayList; import java.util.List; @@ -120,7 +122,7 @@ public class GT_Worldgenerator int tRandomWeight; int i; - for (i = 0; (i < 256) && (temp); i++) { + for (i = 0; (i < oreveinAttempts) && (temp); i++) { tRandomWeight = this.mRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight); for (GT_Worldgen tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight; @@ -136,15 +138,15 @@ public class GT_Worldgenerator } } } - if (D1 & temp) { + if (debugOrevein & temp) { GT_Log.out.println( "No orevein selected!" + - " @ dim="+ this.mDimensionType+ " chunkX="+ this.mX + " chunkZ="+ this.mZ + + " oreveinAttemps=" + oreveinAttempts + " dimensionName=" + tDimensionName ); - } else if (D1) + } else if (debugOrevein) { GT_Log.out.println( "Orevein took " + i + @@ -155,11 +157,10 @@ public class GT_Worldgenerator }else { - if((oreveinRNG >= oreveinPercentage) && (D1)) + if((oreveinRNG >= oreveinPercentage) && (debugOrevein)) { GT_Log.out.println( "Skipped orevein in this 3x3 chunk!" + - " @ dim="+ this.mDimensionType+ " chunkX="+ this.mX + " chunkZ="+ this.mZ + " RNG=" + oreveinRNG + @@ -191,7 +192,7 @@ public class GT_Worldgenerator } else { - if (D1) { + if (debugOrevein) { GT_Log.out.println( "Skipped chunk, not 3x3 center" + " @ dim="+this.mDimensionType+ @@ -214,7 +215,7 @@ public class GT_Worldgenerator if ((GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { boolean temp = true; int tRandomWeight; - for (int i = 0; (i < 256) && (temp); i++) { + for (int i = 0; (i < oreveinAttempts) && (temp); i++) { tRandomWeight = aRandom.nextInt(GT_Worldgen_GT_Ore_Layer.sWeight); for (GT_Worldgen_GT_Ore_Layer tWorldGen : GT_Worldgen_GT_Ore_Layer.sList) { tRandomWeight -= ((GT_Worldgen_GT_Ore_Layer) tWorldGen).mWeight; -- cgit From 29d2846c40e9f69374f2b0c2701c11073ec7e287 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Tue, 17 Oct 2017 02:23:08 -0500 Subject: Preserve debug messages and bugfix for deep dark doing multiple worldgens on a single chunk. --- .../java/gregtech/common/GT_Worldgenerator.java | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Worldgenerator.java') diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index 47990cae64..8ccce145ed 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -24,6 +24,7 @@ import static gregtech.api.enums.GT_Values.oreveinAttempts; import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.HashSet; import static gregtech.api.enums.GT_Values.D1; @@ -39,6 +40,7 @@ public class GT_Worldgenerator //private static int gcMaxSize = 400; private static boolean endAsteroids = true; public List mList = new ArrayList(); + public HashSet ProcChunks = new HashSet(); public boolean mIsGenerating = false; public static final Object listLock = new Object(); //private static boolean gcAsteroids = true; @@ -64,15 +66,21 @@ public class GT_Worldgenerator public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { synchronized (listLock) { - this.mList.add(new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, ((aChunkGenerator instanceof ChunkProviderEnd)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.sky) ? 1 : ((aChunkGenerator instanceof ChunkProviderHell)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.hell) ? -1 : 0, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); - if (debugWorldGen) {GT_Log.out.println("ADD WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size());} + if (!this.ProcChunks.contains( ((long)aX << 32) | ((long)(aZ) & 0x00000000ffffffffL)) ) { + this.ProcChunks.add( ((long)aX << 32) | ((long)(aZ) & 0x00000000ffffffffL)); + this.mList.add(new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, ((aChunkGenerator instanceof ChunkProviderEnd)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.sky) ? 1 : ((aChunkGenerator instanceof ChunkProviderHell)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.hell) ? -1 : 0, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); + if (debugWorldGen) {GT_Log.out.println("ADD WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size());} + } else { + if (debugWorldGen) {GT_Log.out.println("DUP WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size() + " ProcChunks.size(): " + ProcChunks.size() ); } + } } if (!this.mIsGenerating) { this.mIsGenerating = true; int mList_sS=this.mList.size(); for (int i = 0; i < mList_sS; i++) { WorldGenContainer toRun = (WorldGenContainer) this.mList.get(0); - if (debugWorldGen) {GT_Log.out.println("RUN WorldGen chunk x:" + toRun.mX/16 + " z:" + toRun.mZ/16 + " SIZE: " + this.mList.size());} + if (debugWorldGen) {GT_Log.out.println("RUN WorldGen chunk x:" + toRun.mX/16 + " z:" + toRun.mZ/16 + " SIZE: " + this.mList.size() + " i: " + i );} + this.ProcChunks.remove( ((long)(toRun.mX/16) << 32) | ((long)(toRun.mZ/16) & 0x00000000ffffffffL)); synchronized (listLock) { this.mList.remove(0); @@ -114,7 +122,9 @@ public class GT_Worldgenerator } public void run() { - String tDimensionName = this.mWorld.provider.getDimensionName(); + String tDimensionName = ""; + if (debugOrevein) { tDimensionName = this.mWorld.provider.getDimensionName(); } + long startTime = System.nanoTime(); if ((Math.abs(this.mX / 16) % 3 == 1) && (Math.abs(this.mZ / 16) % 3 == 1)) { int oreveinRNG = this.mRandom.nextInt(100); if (( oreveinRNG < oreveinPercentage) && (GT_Worldgen_GT_Ore_Layer.sWeight > 0) && (GT_Worldgen_GT_Ore_Layer.sList.size() > 0)) { @@ -313,6 +323,14 @@ public class GT_Worldgenerator if (tChunk != null) { tChunk.isModified = true; } + long endTime = System.nanoTime(); + long duration = (endTime - startTime); + if (debugWorldGen) { + GT_Log.out.println( + "Oregen took " + duration + + " nanoseconds" + ); + } } } } -- cgit From df14479aacd21fd5c8029be15082ea19d3c18c9c Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Tue, 17 Oct 2017 03:03:25 -0500 Subject: Revert threadsafe code back to lossy code. Chunks will get skipped with this, but at least the worldgen won't lag. --- .../java/gregtech/common/GT_Worldgenerator.java | 29 ++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'src/main/java/gregtech/common/GT_Worldgenerator.java') diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index 8ccce145ed..f42bc4ef1b 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -63,34 +63,27 @@ public class GT_Worldgenerator } } + public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) { - synchronized (listLock) - { - if (!this.ProcChunks.contains( ((long)aX << 32) | ((long)(aZ) & 0x00000000ffffffffL)) ) { - this.ProcChunks.add( ((long)aX << 32) | ((long)(aZ) & 0x00000000ffffffffL)); - this.mList.add(new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, ((aChunkGenerator instanceof ChunkProviderEnd)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.sky) ? 1 : ((aChunkGenerator instanceof ChunkProviderHell)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.hell) ? -1 : 0, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); - if (debugWorldGen) {GT_Log.out.println("ADD WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size());} - } else { - if (debugWorldGen) {GT_Log.out.println("DUP WorldGen chunk x:" + aX + " z:" + aZ + " SIZE: " + this.mList.size() + " ProcChunks.size(): " + ProcChunks.size() ); } - } - } + this.mList.add(new WorldGenContainer(new XSTR(aRandom.nextInt()), aX * 16, aZ * 16, ((aChunkGenerator instanceof ChunkProviderEnd)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.sky) ? 1 : ((aChunkGenerator instanceof ChunkProviderHell)) || (aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8) == BiomeGenBase.hell) ? -1 : 0, aWorld, aChunkGenerator, aChunkProvider, aWorld.getBiomeGenForCoords(aX * 16 + 8, aZ * 16 + 8).biomeName)); if (!this.mIsGenerating) { this.mIsGenerating = true; int mList_sS=this.mList.size(); for (int i = 0; i < mList_sS; i++) { - WorldGenContainer toRun = (WorldGenContainer) this.mList.get(0); - if (debugWorldGen) {GT_Log.out.println("RUN WorldGen chunk x:" + toRun.mX/16 + " z:" + toRun.mZ/16 + " SIZE: " + this.mList.size() + " i: " + i );} - this.ProcChunks.remove( ((long)(toRun.mX/16) << 32) | ((long)(toRun.mZ/16) & 0x00000000ffffffffL)); - synchronized (listLock) - { - this.mList.remove(0); - } - toRun.run(); + ((Runnable) this.mList.get(i)).run(); } + if (debugWorldGen) { + GT_Log.out.println( + "Tossing " + (this.mList.size() - mList_sS) + + " chunks!" + ); + } + this.mList.clear(); this.mIsGenerating = false; } } + //public synchronized void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkProvider aChunkGenerator, IChunkProvider aChunkProvider) {//TODO CHECK??? // int tempDimensionId = aWorld.provider.dimensionId; // if (tempDimensionId != -1 && tempDimensionId != 1 && !aChunkGenerator.getClass().getName().contains("galacticraft")) { -- cgit