mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
revert some stuff
This commit is contained in:
@@ -6,7 +6,7 @@ import java.io.IOException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class RegionGenerator {
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
public static void main(String[] args) throws IOException {
|
||||
long seed;
|
||||
if(args.length == 1) seed = Long.parseLong(args[0]);
|
||||
else seed = ThreadLocalRandom.current().nextLong();
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Counter {
|
||||
private final AtomicInteger integer = new AtomicInteger();
|
||||
private final Consumer<Integer> update;
|
||||
|
||||
public Counter(Consumer<Integer> update) {
|
||||
this.update = update;
|
||||
}
|
||||
|
||||
public void add() {
|
||||
update.accept(integer.addAndGet(1));
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.DirectUtils;
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.platform.DirectChunkData;
|
||||
import com.dfsek.terra.platform.DirectWorld;
|
||||
import com.dfsek.terra.region.Generator;
|
||||
import net.querz.mca.MCAUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.RecursiveAction;
|
||||
|
||||
public class GenerationWorker extends RecursiveAction {
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final DirectWorld world;
|
||||
private final Generator generator;
|
||||
private final Counter counter;
|
||||
|
||||
public GenerationWorker(int x, int z, DirectWorld world, Generator generator, Counter counter) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.world = world;
|
||||
this.generator = generator;
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void compute() {
|
||||
for(int cx = x * 32; cx < x * 32 + 32; cx++) {
|
||||
for(int cz = z * 32; cz <= z * 32 + 32; cz++) {
|
||||
DirectChunkData chunkData = (DirectChunkData) world.getChunkAt(cx, cz);
|
||||
generator.getGenerator().generateChunkData(world, null, cx, cz, chunkData);
|
||||
|
||||
generator.getCavePopulator().populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
generator.getStructurePopulator().populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
generator.getOrePopulator().populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
generator.getFloraPopulator().populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
generator.getTreePopulator().populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
|
||||
counter.add();
|
||||
}
|
||||
}
|
||||
long regionID = DirectUtils.regionID(x, z);
|
||||
try {
|
||||
File file = new File("region", MCAUtil.createNameFromRegionLocation(x, z));
|
||||
file.getParentFile().mkdirs();
|
||||
MCAUtil.write(world.getFiles().get(regionID), file);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
world.getFiles().remove(regionID);
|
||||
System.out.println("Saved region [" + x + "," + z + "]. " + world.getFiles().size() + " regions remain loaded.");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.dfsek.terra.region;
|
||||
|
||||
import com.dfsek.terra.StandalonePlugin;
|
||||
import com.dfsek.terra.api.util.GlueList;
|
||||
import com.dfsek.terra.async.Counter;
|
||||
import com.dfsek.terra.async.GenerationWorker;
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.generation.MasterChunkGenerator;
|
||||
import com.dfsek.terra.generation.math.SamplerCache;
|
||||
import com.dfsek.terra.platform.DirectChunkData;
|
||||
import com.dfsek.terra.platform.DirectWorld;
|
||||
import com.dfsek.terra.platform.GenWrapper;
|
||||
import com.dfsek.terra.population.CavePopulator;
|
||||
@@ -18,10 +18,7 @@ import net.querz.mca.MCAUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class Generator {
|
||||
private final long seed;
|
||||
@@ -52,34 +49,33 @@ public class Generator {
|
||||
GenWrapper wrapper = new GenWrapper(generator);
|
||||
DirectWorld world = new DirectWorld(seed, wrapper);
|
||||
|
||||
AtomicLong l = new AtomicLong(System.nanoTime());
|
||||
long l = System.nanoTime();
|
||||
int count = 0;
|
||||
|
||||
Counter counter = new Counter((id) -> {
|
||||
if(id % 200 == 0) {
|
||||
long c = System.nanoTime();
|
||||
for(int cx = -rad; cx <= rad; cx++) {
|
||||
for(int cz = -rad; cz <= rad; cz++) {
|
||||
DirectChunkData chunkData = (DirectChunkData) world.getChunkAt(cx, cz);
|
||||
generator.generateChunkData(world, null, cx, cz, chunkData);
|
||||
|
||||
long diff = c - l.get();
|
||||
cavePopulator.populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
structurePopulator.populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
orePopulator.populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
floraPopulator.populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
treePopulator.populate(world, new FastRandom(MathUtil.getCarverChunkSeed(cx, cz, world.getSeed())), chunkData);
|
||||
count++;
|
||||
|
||||
double ms = (double) diff / 1000000;
|
||||
if(count % 200 == 0) {
|
||||
long n = System.nanoTime();
|
||||
|
||||
System.out.println("[" + Thread.currentThread().getName() + "] Generated " + id + " chunks. " + (200d / ms) * 1000 + " cps. " + world.getFiles().size() + " Regions loaded.");
|
||||
l.set(System.nanoTime());
|
||||
}
|
||||
});
|
||||
System.out.println("Generated " + count + " chunks. " + 200 / ((double) (n - l) / 1000000) * 1000 + "cps.");
|
||||
|
||||
l = System.nanoTime();
|
||||
|
||||
List<GenerationWorker> workers = new GlueList<>();
|
||||
|
||||
|
||||
for(int x = -rad / 32; x <= rad / 32; x++) {
|
||||
for(int z = -rad / 32; z <= rad / 32; z++) {
|
||||
workers.add(new GenerationWorker(x, z, world, this, counter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ForkJoinTask.invokeAll(workers);
|
||||
|
||||
|
||||
System.out.println("Saving...");
|
||||
|
||||
@@ -93,34 +89,6 @@ public class Generator {
|
||||
MCAUtil.write(entry.getValue(), file);
|
||||
}
|
||||
|
||||
System.out.println("Done in " + (System.nanoTime() - l.get()) / 1000000000 + "s");
|
||||
}
|
||||
|
||||
public StructurePopulator getStructurePopulator() {
|
||||
return structurePopulator;
|
||||
}
|
||||
|
||||
public OrePopulator getOrePopulator() {
|
||||
return orePopulator;
|
||||
}
|
||||
|
||||
public CavePopulator getCavePopulator() {
|
||||
return cavePopulator;
|
||||
}
|
||||
|
||||
public TreePopulator getTreePopulator() {
|
||||
return treePopulator;
|
||||
}
|
||||
|
||||
public FloraPopulator getFloraPopulator() {
|
||||
return floraPopulator;
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
public MasterChunkGenerator getGenerator() {
|
||||
return generator;
|
||||
System.out.println("Done in " + (System.nanoTime() - l) / 1000000000 + "s");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user