Skip to content

Commit

Permalink
foliage density in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valoeghese committed Dec 17, 2021
1 parent 7685c08 commit 5bc1085
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/main/java/tk/valoeghese/fc0/world/gen/ecozone/EcoZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import tk.valoeghese.fc0.world.gen.generator.GeneratorSettings;
import tk.valoeghese.fc0.world.gen.generator.NoneGeneratorSettings;
import tk.valoeghese.fc0.world.gen.generator.ScatteredOreGenerator;
import tk.valoeghese.fc0.world.gen.generator.TreeGenerator;
import tk.valoeghese.fc0.world.gen.generator.TreeGeneratorSettings;
import tk.valoeghese.fc0.world.tile.Tile;

import java.util.ArrayList;
Expand All @@ -31,9 +33,14 @@ protected EcoZone(String name, Tile surface, Tile beach) {
public final byte beach;
private List<Pair<Generator, GeneratorSettings>> generators = new ArrayList<>();
private boolean cold = false;
private int treesPerChunk; // trees per chunk, for the debug view.

public <T extends GeneratorSettings> void addGenerator(Generator<T> generator, T settings) {
this.generators.add(new Pair<>(generator, settings));

if (generator instanceof TreeGenerator) {
this.treesPerChunk += ((TreeGeneratorSettings) settings).getBaseTreeCount();
}
}

protected void cold() {
Expand All @@ -48,6 +55,13 @@ public boolean isCold() {
return this.cold;
}

/**
* @return the average foliage density. Used in the terrain-test debugger.
*/
public int getAverageFoliageDensity() {
return this.treesPerChunk;
}

@Override
public String toString() {
return "ecozone." + this.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public TreeGeneratorSettings(int baseTreeCount, float treeCountVariation, int ba
private final int baseTreeHeight;
private final int potentialHeightIncrease;

public int getBaseTreeCount() {
return this.baseTreeCount;
}

@Override
public int getCount(GenWorld world, Random rand, int startX, int startZ) {
return this.baseTreeCount + (int) (this.treeCountVariation * world.sampleNoise(startX / 64.0, startZ / 64.0));
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/tk/valoeghese/fc0/world/gen/TerrainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import test.Dummy2fc;
import test.PanelTest;
import tk.valoeghese.fc0.util.maths.MathsUtils;
import tk.valoeghese.fc0.util.maths.Vec2f;
import tk.valoeghese.fc0.util.maths.Vec2i;
import tk.valoeghese.fc0.world.gen.ecozone.EcoZone;
Expand Down Expand Up @@ -69,7 +70,7 @@ protected int getColour(int x, int z) { // TODO kingdom widget thing when in cit
} else {
// cold or not
if (zone.isCold()) height *= 1.2f;
return Color.getHSBColor(0.37f, zone.isCold() ? 0.12f : 0.69f, height > 1.0f ? 1.0f : height).getRGB();
return Color.getHSBColor(MathsUtils.clampMap(zone.getAverageFoliageDensity(), 0, 10, 0.3f, 0.44f), zone.isCold() ? (0.12f + 0.04f * zone.getAverageFoliageDensity()) : 0.69f, height > 1.0f ? 1.0f : height).getRGB();
}
} else {
height = (height / 128f) + 0.2f;
Expand Down

0 comments on commit 5bc1085

Please sign in to comment.