Skip to content

Commit

Permalink
Bunch of improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Feb 4, 2016
1 parent d54e3e4 commit 9c026fa
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 154 deletions.
17 changes: 8 additions & 9 deletions readme.md
Expand Up @@ -9,17 +9,20 @@ There are 2 main reasons I'm making this:
1. I wanted to be able to check one or more existing seeds for resoureces and/or make maps of those resources.
2. I wanted to make a non-spoiling way to select a good seed. (aka be sure it has some decent resources within a reasonable radius of spawn, without knowing where to go look)

This program spits out json files, which can then be analyzed by hand or by an external program.
I'm now working on some JavaScript (NodeJS) program to present the results and allow for custom filtering.

License
-------

© 2015 - Dries007

Unless otherwise specified per file, or per package via the package-info.java file.

This program conains code from the [Terrafirmacraft mod](https://github.com/Deadrik/TFCraft), hence the GPL license.
This program contains code from the [Terrafirmacraft mod](https://github.com/Deadrik/TFCraft), hence the GPL license.

Done/Todo
----
---------

- [x] Make maps per layer + combined
- [x] Multithreading
Expand All @@ -33,10 +36,6 @@ Done/Todo
- [x] pH
- [x] Drainage
- [x] Add Gradle file and use it for dependecies
- [ ] Seed rating system
- [ ] Requirements
- [ ] Instant rejections
- [ ] Score system
- [ ] Add "hardcoded" tree generation
- [ ] Crops
- [ ] Animals
- [ ] Add "hardcoded" tree generation (nearly impossible)
- [ ] Crops (nearly impossible)
- [ ] Animals (nearly impossible)
43 changes: 22 additions & 21 deletions src/main/java/net/dries007/tfc/seedmaker/CommandLineInterface.java
Expand Up @@ -14,29 +14,32 @@
*/
public class CommandLineInterface implements Runnable
{
@Parameter(names = {"-taw", "--trees-above-water"}, description = "Count trees in water biomes")
private boolean treesAboveWater = false;
@Parameter(names = {"-T", "--trees-above-water"}, description = "Count trees in water biomes")
public boolean treesAboveWater = false;

@Parameter(names = {"-riw", "--rocks-in-water"}, description = "Count the rock layers in water biomes")
private boolean rocksInWater = false;
@Parameter(names = {"-R", "--rocks-in-water"}, description = "Count the rock layers in water biomes")
public boolean rocksInWater = false;

@Parameter(names = {"-t", "--threads"}, description = "Amount of threads used, by defauld amound of CPU cores available")
private int threads = Runtime.getRuntime().availableProcessors();
@Parameter(names = {"-t", "--threads"}, description = "Amount of threads used, by default amount of CPU cores available")
public int threads = Runtime.getRuntime().availableProcessors();

@Parameter(names = {"-r", "--radius"}, description = "Radius in blocks")
private int radius = 1024 * 5;
public int radius = 1024 * 5;

@Parameter(names = {"-c", "--chunksize"}, description = "Size per 'chunk'")
private int chunkSize = 128;
public int chunkSize = 128;

@Parameter(names = {"-s", "--seed", "--seeds"}, description = "The seeds to use, if none provided one random seed is chosen per thread")
private List<String> seeds = new ArrayList<>();
@Parameter(names = {"-s", "--seed", "--seeds"}, description = "The seeds to use, if none provided one random seed is chosen per thread. Comma separated list of strings")
public List<String> seeds = new ArrayList<>();

@Parameter(names = {"-n", "-count", "-target"}, description = "The amount of seeds to try and find")
private int targetCount = 10;
@Parameter(names = {"-n", "-count", "-target"}, description = "The amount of seeds to try and find. Only used when no seeds are given. If -1, the program will run forever")
public int targetCount = 10;

@Parameter(names = {"-m", "--map"}, description = "Save the map to <seed>.png")
private boolean map = false;
@Parameter(names = {"-m", "--map", "--maps"}, description = "Possible maps: Combined, Rock_Top, Rock_Middle, Rock_Bottom, Tree_0, Tree_1, Tree_2, EVT, Rain, Stability, PH, Drainage. You can also specify Rocks or Trees or All")
public List<String> maps = new ArrayList<>();

@Parameter(names = {"-?", "--help"}, help = true, description = "Display command line interface parameters")
public boolean help;

@Override
public void run()
Expand All @@ -49,14 +52,14 @@ public void run()
System.out.println("- chunkSize: " + chunkSize);
System.out.println("- seeds: " + seeds);
System.out.println("- targetCount: " + targetCount);
System.out.println("- map: " + map);
System.out.println("- maps: " + maps);

final JsonArray rootArray = new JsonArray();
Thread[] threadAray = new Thread[threads];
if (!seeds.isEmpty())
{
final ConcurrentLinkedQueue<WorldGen> queue = new ConcurrentLinkedQueue<>();
for (String seed : seeds) queue.add(new WorldGen(seed, treesAboveWater, rocksInWater, radius, chunkSize, map));
for (String seed : seeds) queue.add(new WorldGen(seed, treesAboveWater, rocksInWater, radius, chunkSize, maps));

for (int i = 0; i < threads; i++)
{
Expand Down Expand Up @@ -88,14 +91,12 @@ public void run()
@Override
public void run()
{
while (goodCount.get() < targetCount)
while (targetCount < 0 || goodCount.get() < targetCount)
{
WorldGen worldGen = new WorldGen(null, treesAboveWater, rocksInWater, radius, chunkSize, map);
WorldGen worldGen = new WorldGen(null, treesAboveWater, rocksInWater, radius, chunkSize, maps);
worldGen.run();

// worldGen.evaluate();
// if (Helper.evaluate(worldGen))
goodCount.decrementAndGet();
goodCount.incrementAndGet();
rootArray.add(worldGen.toJson());
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/net/dries007/tfc/seedmaker/Main.java
Expand Up @@ -2,17 +2,13 @@

import com.beust.jcommander.JCommander;

import java.awt.*;

public class Main
{
public static void main(String[] args)
{
if (args.length > 0 || GraphicsEnvironment.isHeadless())
{
CommandLineInterface cli = new CommandLineInterface();
new JCommander(cli, args);
cli.run();
}
CommandLineInterface cli = new CommandLineInterface();
JCommander jc = new JCommander(cli, args);
if (cli.help || args.length == 0) jc.usage();
else cli.run();
}
}
30 changes: 0 additions & 30 deletions src/main/java/net/dries007/tfc/seedmaker/Test.java

This file was deleted.

28 changes: 8 additions & 20 deletions src/main/java/net/dries007/tfc/seedmaker/util/Helper.java
Expand Up @@ -4,15 +4,11 @@
import ar.com.hjg.pngj.PngWriter;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

/**
Expand All @@ -37,25 +33,17 @@ public static long parseSeed(String seedString)
}
}

public static <T extends Comparable<? super T>> JsonElement toSortedJson(Set<T> set)
public static <K, V> JsonElement toJson(Map<K, V> biomeMap)
{
JsonArray array = new JsonArray();
List<T> list = new ArrayList<>();
list.addAll(set);
Collections.sort(list);
for (T e : list) array.add(e.toString());
return array;
JsonObject object = new JsonObject();
for (Map.Entry<K, V> e : biomeMap.entrySet()) object.addProperty(e.getKey().toString(), e.getValue().toString());
return object;
}

public static PngWriter[] prepareGraphics(String[] filenames, int size, File folder)
public static PngWriter[] prepareGraphics(String[] filenames, int size, File folder, boolean[] maps)
{
PngWriter[] out = new PngWriter[filenames.length];
for (int i = 0; i < out.length; i++) out[i] = new PngWriter(new File(folder, filenames[i] + ".png"), new ImageInfo(size, size, 8, false), true);
for (int i = 0; i < out.length; i++) if (maps[i]) out[i] = new PngWriter(new File(folder, filenames[i] + ".png"), new ImageInfo(size, size, 8, false), true);
return out;
}

public static void finishGraphics(PngWriter[] writers) throws IOException
{
for (PngWriter writer : writers) writer.close();
}
}

0 comments on commit 9c026fa

Please sign in to comment.