mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Merge pull request #1289 from TrueFuFLeaderG/adventure
threaded WaveFunctionCollapse
This commit is contained in:
@@ -18,6 +18,7 @@ import forge.adventure.util.Config;
|
||||
import forge.adventure.util.Paths;
|
||||
import forge.adventure.util.SaveFileContent;
|
||||
import forge.adventure.util.SaveFileData;
|
||||
import forge.util.ThreadUtil;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.*;
|
||||
@@ -278,7 +279,7 @@ private void clearTerrain(int x,int y,int size)
|
||||
private long measureGenerationTime(String msg,long lastTime)
|
||||
{
|
||||
long currentTime = System.currentTimeMillis();
|
||||
//System.out.print("\n"+msg+" :\t\t"+((currentTime-lastTime)/1000f)+" s");
|
||||
System.out.print("\n"+msg+" :\t\t"+((currentTime-lastTime)/1000f)+" s");
|
||||
return currentTime;
|
||||
}
|
||||
public World generateNew(long seed) {
|
||||
@@ -288,8 +289,10 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
|
||||
loadWorldData();
|
||||
|
||||
if(seed==0) { seed=random.nextLong(); }
|
||||
this.seed=seed;
|
||||
if (seed == 0) {
|
||||
seed = random.nextLong();
|
||||
}
|
||||
this.seed = seed;
|
||||
random.setSeed(seed);
|
||||
OpenSimplexNoise noise = new OpenSimplexNoise(seed);
|
||||
|
||||
@@ -298,7 +301,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
height = data.height;
|
||||
//save at all data
|
||||
biomeMap = new long[width][height];
|
||||
terrainMap= new int[width][height];
|
||||
terrainMap = new int[width][height];
|
||||
Pixmap pix = new Pixmap(width, height, Pixmap.Format.RGBA8888);
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
@@ -312,7 +315,28 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
pix.fill();
|
||||
|
||||
int biomeIndex = -1;
|
||||
currentTime=measureGenerationTime("loading data",currentTime);
|
||||
currentTime = measureGenerationTime("loading data", currentTime);
|
||||
HashMap<BiomeStructureData, BiomeStructure> structureDataMap = new HashMap<>();
|
||||
|
||||
|
||||
for (BiomeData biome : data.GetBiomes()) {
|
||||
if (biome.structures != null) {
|
||||
int biomeWidth = (int) Math.round(biome.width * (double) width);
|
||||
int biomeHeight = (int) Math.round(biome.height * (double) height);
|
||||
for (BiomeStructureData data : biome.structures) {
|
||||
long localSeed=seed;
|
||||
ThreadUtil.getServicePool().submit(() -> {
|
||||
long threadStartTime = System.currentTimeMillis();
|
||||
BiomeStructure structure = new BiomeStructure(data, localSeed, biomeWidth, biomeHeight);
|
||||
structure.initialize();
|
||||
structureDataMap.put(data, structure);
|
||||
measureGenerationTime("wavefunctioncollapse " + data.sourcePath, threadStartTime);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (BiomeData biome : data.GetBiomes()) {
|
||||
|
||||
biomeIndex++;
|
||||
@@ -331,7 +355,6 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
endX = width;
|
||||
endY = height;
|
||||
}
|
||||
HashMap<BiomeStructureData,BiomeStructure> structureDataMap=new HashMap<>();
|
||||
for (int x = beginX; x < endX; x++) {
|
||||
for (int y = beginY; y < endY; y++) {
|
||||
//value 0-1 based on noise
|
||||
@@ -370,19 +393,15 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
{
|
||||
for(BiomeStructureData data:biome.structures)
|
||||
{
|
||||
while(!structureDataMap.containsKey(data)) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
BiomeStructure structure;
|
||||
if(!structureDataMap.containsKey(data))
|
||||
{
|
||||
structure=new BiomeStructure(data,seed,biomeWidth,biomeHeight);
|
||||
structure.initialize();
|
||||
structureDataMap.put(data,structure);
|
||||
currentTime=measureGenerationTime("wavefunctioncollapse "+data.sourcePath,currentTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
structure=structureDataMap.get(data);
|
||||
}
|
||||
BiomeStructure structure=structureDataMap.get(data);
|
||||
int structureXStart= x-(biomeXStart - biomeWidth / 2)-(int) ((data.x*biomeWidth)-(data.width*biomeWidth/2));
|
||||
int structureYStart= y-(biomeYStart - biomeHeight / 2)- (int) ((data.y*biomeHeight)-(data.height*biomeHeight/2));
|
||||
|
||||
@@ -406,6 +425,7 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
currentTime=measureGenerationTime("biomes in total",currentTime);
|
||||
|
||||
mapPoiIds = new PointOfInterestMap(getChunkSize(), data.tileSize, data.width / getChunkSize(),data.height / getChunkSize());
|
||||
List<PointOfInterest> towns = new ArrayList<>();
|
||||
@@ -679,8 +699,10 @@ private long measureGenerationTime(String msg,long lastTime)
|
||||
}
|
||||
biomeImage = pix;
|
||||
measureGenerationTime("sprites",currentTime);
|
||||
//System.out.print("\nGenerating world took :\t\t"+((System.currentTimeMillis()-startTime)/1000f)+" s");
|
||||
System.out.print("\nGenerating world took :\t\t"+((System.currentTimeMillis()-startTime)/1000f)+" s\n");
|
||||
WorldStage.getInstance().clearCache();
|
||||
ThreadUtil.getServicePool().shutdownNow();
|
||||
ThreadUtil.refreshServicePool();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user