CLI Improvements

This commit is contained in:
Zoe Gidiere 2024-10-11 15:16:04 -06:00
parent accc07fa07
commit 43d52e4bc1
4 changed files with 48 additions and 6 deletions

View File

@ -74,5 +74,6 @@ object Versions {
object CLI { object CLI {
const val nbt = "6.1" const val nbt = "6.1"
const val logback = "1.5.8" const val logback = "1.5.8"
const val picocli = "4.7.6"
} }
} }

View File

@ -10,6 +10,9 @@ dependencies {
shadedApi("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO) shadedApi("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO)
shadedApi("com.github.Querz", "NBT", Versions.CLI.nbt) shadedApi("com.github.Querz", "NBT", Versions.CLI.nbt)
shadedImplementation("info.picocli", "picocli", Versions.CLI.picocli)
annotationProcessor("info.picocli", "picocli-codegen", Versions.CLI.picocli)
shadedImplementation("com.google.guava", "guava", Versions.Libraries.Internal.guava) shadedImplementation("com.google.guava", "guava", Versions.Libraries.Internal.guava)
shadedImplementation("ch.qos.logback", "logback-classic", Versions.CLI.logback) shadedImplementation("ch.qos.logback", "logback-classic", Versions.CLI.logback)
@ -26,6 +29,12 @@ tasks.withType<Jar> {
} }
} }
tasks.withType<JavaCompile> {
doFirst {
options.compilerArgs.add("-Aproject=${project.group}/${project.name}")
}
}
application { application {
mainClass.set(javaMainClass) mainClass.set(javaMainClass)
} }

View File

@ -5,25 +5,48 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Callable;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent; import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
import com.dfsek.terra.api.util.vector.Vector2Int; import com.dfsek.terra.api.util.vector.Vector2Int;
import com.dfsek.terra.cli.world.CLIWorld; import com.dfsek.terra.cli.world.CLIWorld;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
public final class TerraCLI {
private static final Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class);
public static void main(String... args) { //TODO auto pull in version
@Command(name = "TerraCLI", mixinStandardHelpOptions = true, version = "6.6.0",
description = "Generates a Terra World and saves it in minecraft region format.")
public final class TerraCLI implements Callable<Integer> {
@Option(names = { "-s", "--size"}, description = "Number of regions to generate.")
private int size = 2;
@Option(names = { "-p", "--pack"}, description = "Config pack to use.")
private String pack = "OVERWORLD";
@Option(names = { "--seed"}, description = "Seed for world generation.")
private long seed = 0;
@Option(names = { "--max-height"}, description = "Maximum height of the world.")
private int maxHeight = 384;
@Option(names = { "--min-height"}, description = "Minimum height of the world.")
private int minHeight = -64;
@Override
public Integer call() throws Exception { // your business logic goes here...
Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class);
LOGGER.info("Starting Terra CLI..."); LOGGER.info("Starting Terra CLI...");
CLIPlatform platform = new CLIPlatform(); CLIPlatform platform = new CLIPlatform();
platform.getEventManager().callEvent(new PlatformInitializationEvent()); platform.getEventManager().callEvent(new PlatformInitializationEvent());
ConfigPack generate = platform.getConfigRegistry().getByID("OVERWORLD").orElseThrow(); // TODO: make this a cli argument ConfigPack generate = platform.getConfigRegistry().getByID(pack).orElseThrow();
CLIWorld world = new CLIWorld(2, 2, 384, -64, generate); CLIWorld world = new CLIWorld(size, seed, maxHeight, minHeight, generate);
world.generate(); world.generate();
@ -40,6 +63,11 @@ public final class TerraCLI {
LOGGER.info("Wrote region to file."); LOGGER.info("Wrote region to file.");
}); });
LOGGER.info("Done."); LOGGER.info("Done.");
System.exit(0); return 0;
}
public static void main(String... args) {
int exitCode = new CommandLine(new TerraCLI()).execute(args);
System.exit(exitCode);
} }
} }

View File

@ -73,6 +73,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
} }
public void generate() { public void generate() {
ArrayList<Double> CPSHistory = new ArrayList<>();
int sizeChunks = size * 32; int sizeChunks = size * 32;
List<Future<?>> futures = new ArrayList<>(); List<Future<?>> futures = new ArrayList<>();
final AtomicLong start = new AtomicLong(System.nanoTime()); final AtomicLong start = new AtomicLong(System.nanoTime());
@ -91,6 +92,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
if(num % 240 == 239) { if(num % 240 == 239) {
long time = System.nanoTime(); long time = System.nanoTime();
double cps = num / ((double) (time - start.get()) / 1000000000); double cps = num / ((double) (time - start.get()) / 1000000000);
CPSHistory.add(cps);
LOGGER.info("Generating chunk at ({}, {}), generated {} chunks at {}cps", finalX, finalZ, num, cps); LOGGER.info("Generating chunk at ({}, {}), generated {} chunks at {}cps", finalX, finalZ, num, cps);
amount.set(0); amount.set(0);
start.set(System.nanoTime()); start.set(System.nanoTime());
@ -109,6 +111,8 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
e.printStackTrace(); e.printStackTrace();
} }
} }
LOGGER.info("Average CPS: {}", CPSHistory.stream().mapToDouble(d -> d).average().orElse(0));
} }
@Override @Override