Skip to content

Commit

Permalink
Remove distinction between populators and samplers
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Jul 6, 2018
1 parent 00e8463 commit d415403
Show file tree
Hide file tree
Showing 58 changed files with 753 additions and 685 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Terrarium
Terrarium is a mod generates the real world in Minecraft. It is a rewrite of my previous mod, [Earth](https://github.com/gegy1000/Earth).
Terrarium is a mod generates the real world in Minecraft. It is a rewrite of [Earth](https://github.com/gegy1000/Earth).

![Himalayas](https://i.imgur.com/OGzQoFq.jpg)
_Himalayas, as generated by Terrarium (rendered by Chunky)_
Expand All @@ -10,9 +10,9 @@ Terrarium implements a new world type for this generation. The generation can be
Data tiles are downloaded from the various sources as you explore them, so lag may occur when new tiles are being loaded. Once they have been downloaded, however, these tiles are cached locally to be used again later.

To navigate to a real location, you can make use of the `geotp` command.
This command allows navigation to a real place on earth.
This command allows navigation to any real place on earth.

It can be used with latitude / longitude coordinates:
It can be used with latitude & longitude coordinates:
- `/geotp 27.987746 86.924812`

Or it can be used with a place name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.gegy1000.earth.server.world.cover.EarthCoverContext;
import net.gegy1000.earth.server.world.cover.EarthCoverTypes;
import net.gegy1000.earth.server.world.pipeline.composer.DebugSignDecorationComposer;
import net.gegy1000.earth.server.world.pipeline.populator.DebugCoverRegionPopulator;
import net.gegy1000.earth.server.world.pipeline.layer.DebugCoverPopulator;
import net.gegy1000.terrarium.server.world.TerrariumGeneratorInitializer;
import net.gegy1000.terrarium.server.world.TerrariumWorldType;
import net.gegy1000.terrarium.server.world.coordinate.Coordinate;
Expand All @@ -24,8 +24,8 @@
import net.gegy1000.terrarium.server.world.pipeline.composer.surface.BedrockSurfaceComposer;
import net.gegy1000.terrarium.server.world.pipeline.composer.surface.CoverSurfaceComposer;
import net.gegy1000.terrarium.server.world.pipeline.composer.surface.HeightmapSurfaceComposer;
import net.gegy1000.terrarium.server.world.pipeline.populator.ConstantByteRegionPopulator;
import net.gegy1000.terrarium.server.world.pipeline.populator.ConstantShortRegionPopulator;
import net.gegy1000.terrarium.server.world.pipeline.layer.ConstantByteProducer;
import net.gegy1000.terrarium.server.world.pipeline.layer.ConstantShortProducer;
import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
Expand Down Expand Up @@ -98,9 +98,9 @@ private List<ConstructedCover<?>> buildCoverTypes(CoordinateState zoneGeoCoordin
@Override
public TerrariumDataProvider buildDataProvider() {
return TerrariumDataProvider.builder()
.withComponent(RegionComponentType.HEIGHT, new ConstantShortRegionPopulator((short) 62))
.withComponent(RegionComponentType.SLOPE, new ConstantByteRegionPopulator((byte) 0))
.withComponent(RegionComponentType.COVER, new DebugCoverRegionPopulator())
.withComponent(RegionComponentType.HEIGHT, new ConstantShortProducer((short) 62))
.withComponent(RegionComponentType.SLOPE, new ConstantByteProducer((byte) 0))
.withComponent(RegionComponentType.COVER, new DebugCoverPopulator())
.build();
}
}
Expand Down
93 changes: 54 additions & 39 deletions src/main/java/net/gegy1000/earth/server/world/EarthWorldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
import net.gegy1000.earth.server.world.cover.EarthCoverContext;
import net.gegy1000.earth.server.world.cover.EarthCoverTypes;
import net.gegy1000.earth.server.world.pipeline.EarthComponentTypes;
import net.gegy1000.earth.server.world.pipeline.adapter.OceanDepthCorrectionAdapter;
import net.gegy1000.earth.server.world.pipeline.adapter.OsmCoastlineAdapter;
import net.gegy1000.earth.server.world.pipeline.adapter.WaterFlattenAdapter;
import net.gegy1000.earth.server.world.pipeline.composer.BoulderDecorationComposer;
import net.gegy1000.earth.server.world.pipeline.populator.OsmRegionPopulator;
import net.gegy1000.earth.server.world.pipeline.sampler.OsmSampler;
import net.gegy1000.earth.server.world.pipeline.layer.OsmPopulatorLayer;
import net.gegy1000.earth.server.world.pipeline.layer.OsmSampleLayer;
import net.gegy1000.earth.server.world.pipeline.source.GlobcoverSource;
import net.gegy1000.earth.server.world.pipeline.source.SrtmHeightSource;
import net.gegy1000.earth.server.world.pipeline.source.osm.OverpassSource;
import net.gegy1000.earth.server.world.pipeline.source.tile.OsmTile;
import net.gegy1000.terrarium.server.capability.TerrariumWorldData;
import net.gegy1000.terrarium.server.util.Interpolation;
import net.gegy1000.terrarium.server.world.TerrariumGeneratorInitializer;
Expand All @@ -36,9 +34,12 @@
import net.gegy1000.terrarium.server.world.generator.customization.widget.InversePropertyConverter;
import net.gegy1000.terrarium.server.world.generator.customization.widget.SliderWidget;
import net.gegy1000.terrarium.server.world.generator.customization.widget.ToggleWidget;
import net.gegy1000.terrarium.server.world.pipeline.DataLayer;
import net.gegy1000.terrarium.server.world.pipeline.DataLayerProducer;
import net.gegy1000.terrarium.server.world.pipeline.DataSource;
import net.gegy1000.terrarium.server.world.pipeline.MergeDataLayer;
import net.gegy1000.terrarium.server.world.pipeline.TerrariumDataProvider;
import net.gegy1000.terrarium.server.world.pipeline.adapter.BeachAdapter;
import net.gegy1000.terrarium.server.world.pipeline.adapter.HeightNoiseAdapter;
import net.gegy1000.terrarium.server.world.pipeline.adapter.HeightTransformAdapter;
import net.gegy1000.terrarium.server.world.pipeline.component.RegionComponentType;
import net.gegy1000.terrarium.server.world.pipeline.composer.biome.CoverBiomeComposer;
Expand All @@ -47,12 +48,15 @@
import net.gegy1000.terrarium.server.world.pipeline.composer.surface.CoverSurfaceComposer;
import net.gegy1000.terrarium.server.world.pipeline.composer.surface.HeightmapSurfaceComposer;
import net.gegy1000.terrarium.server.world.pipeline.composer.surface.OceanFillSurfaceComposer;
import net.gegy1000.terrarium.server.world.pipeline.populator.ScaledByteRegionPopulator;
import net.gegy1000.terrarium.server.world.pipeline.populator.ScaledCoverRegionPopulator;
import net.gegy1000.terrarium.server.world.pipeline.populator.ScaledShortRegionPopulator;
import net.gegy1000.terrarium.server.world.pipeline.sampler.CoverTileSampler;
import net.gegy1000.terrarium.server.world.pipeline.sampler.ShortTileSampler;
import net.gegy1000.terrarium.server.world.pipeline.sampler.SlopeTileSampler;
import net.gegy1000.terrarium.server.world.pipeline.layer.CoverTileSampleLayer;
import net.gegy1000.terrarium.server.world.pipeline.layer.ScaledByteLayer;
import net.gegy1000.terrarium.server.world.pipeline.layer.ScaledCoverLayer;
import net.gegy1000.terrarium.server.world.pipeline.layer.ScaledShortLayer;
import net.gegy1000.terrarium.server.world.pipeline.layer.ShortTileSampleLayer;
import net.gegy1000.terrarium.server.world.pipeline.layer.SlopeProducerLayer;
import net.gegy1000.terrarium.server.world.pipeline.source.tile.ByteRasterTile;
import net.gegy1000.terrarium.server.world.pipeline.source.tile.CoverRasterTile;
import net.gegy1000.terrarium.server.world.pipeline.source.tile.ShortRasterTile;
import net.minecraft.client.gui.GuiCreateWorld;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.init.Blocks;
Expand Down Expand Up @@ -186,64 +190,75 @@ private List<ConstructedCover<?>> constructCoverTypes() {
public TerrariumDataProvider buildDataProvider() {
int heightOrigin = this.properties.getInteger(HEIGHT_ORIGIN);
SrtmHeightSource heightSource = new SrtmHeightSource(this.srtmRaster, "srtm_heights");
DataLayerProducer<ShortRasterTile> heightSampler = DataSource.from(new ShortTileSampleLayer(heightSource));
return TerrariumDataProvider.builder()
.withComponent(RegionComponentType.HEIGHT, this.createHeightPopulator(heightSource))
.withComponent(RegionComponentType.SLOPE, this.createSlopePopulator(heightSource))
.withComponent(RegionComponentType.HEIGHT, this.createHeightProducer(heightSampler))
.withComponent(RegionComponentType.SLOPE, this.createSlopePopulator(heightSampler))
.withComponent(RegionComponentType.COVER, this.createCoverPopulator())
.withComponent(EarthComponentTypes.OSM, this.createOsmPopulator())
.withAdapter(new OsmCoastlineAdapter(RegionComponentType.HEIGHT, RegionComponentType.COVER, EarthComponentTypes.OSM, this.earthCoordinates))
.withAdapter(new HeightNoiseAdapter(this.world, RegionComponentType.HEIGHT, 2, 0.08, this.properties.getDouble(NOISE_SCALE)))
// .withAdapter(new OsmCoastlineAdapter(RegionComponentType.HEIGHT, RegionComponentType.COVER, EarthComponentTypes.OSM, this.earthCoordinates))
// .withAdapter(new HeightNoiseAdapter(this.world, RegionComponentType.HEIGHT, 2, 0.08, this.properties.getDouble(NOISE_SCALE)))
.withAdapter(new HeightTransformAdapter(RegionComponentType.HEIGHT, this.properties.getDouble(HEIGHT_SCALE) * this.worldScale, heightOrigin))
.withAdapter(new OceanDepthCorrectionAdapter(RegionComponentType.HEIGHT, this.properties.getInteger(OCEAN_DEPTH)))
// .withAdapter(new OceanDepthCorrectionAdapter(RegionComponentType.HEIGHT, this.properties.getInteger(OCEAN_DEPTH)))
.withAdapter(new BeachAdapter(this.world, RegionComponentType.COVER, this.properties.getInteger(BEACH_SIZE), EarthCoverTypes.WATER, EarthCoverTypes.BEACH))
.withAdapter(new WaterFlattenAdapter(RegionComponentType.HEIGHT, RegionComponentType.COVER, 15, EarthCoverTypes.WATER))
// .withAdapter(new WaterFlattenAdapter(RegionComponentType.HEIGHT, RegionComponentType.COVER, 15, EarthCoverTypes.WATER))
.build();
}

private ScaledShortRegionPopulator createHeightPopulator(SrtmHeightSource heightSource) {
private DataLayerProducer<ShortRasterTile> createHeightProducer(DataLayerProducer<ShortRasterTile> heightSampler) {
Interpolation.Method interpolationMethod = this.selectInterpolationMethod(this.properties);
ShortTileSampler heightSampler = new ShortTileSampler(heightSource);
return new ScaledShortRegionPopulator(heightSampler, this.srtmRaster, interpolationMethod);
return DataLayer.of(new ScaledShortLayer(this.srtmRaster, interpolationMethod), heightSampler);
}

private ScaledByteRegionPopulator createSlopePopulator(SrtmHeightSource heightSource) {
SlopeTileSampler slopeSampler = new SlopeTileSampler(heightSource);
return new ScaledByteRegionPopulator(slopeSampler, this.srtmRaster, Interpolation.Method.LINEAR);
private DataLayerProducer<ByteRasterTile> createSlopePopulator(DataLayerProducer<ShortRasterTile> heightSampler) {
DataLayerProducer<ByteRasterTile> layer = DataLayer.of(new SlopeProducerLayer(), heightSampler);
layer = DataLayer.of(new ScaledByteLayer(this.srtmRaster, Interpolation.Method.LINEAR), layer);
return layer;
}

private ScaledCoverRegionPopulator createCoverPopulator() {
private DataLayerProducer<CoverRasterTile> createCoverPopulator() {
GlobcoverSource globcoverSource = new GlobcoverSource(this.globcoverRaster, "globcover");
CoverTileSampler coverSampler = new CoverTileSampler(globcoverSource);
return new ScaledCoverRegionPopulator(coverSampler, this.globcoverRaster);
DataLayerProducer<CoverRasterTile> layer = DataSource.from(new CoverTileSampleLayer(globcoverSource));
layer = DataLayer.of(new ScaledCoverLayer(this.globcoverRaster), layer);
return layer;
}

private OsmRegionPopulator createOsmPopulator() {
OverpassSource outlineSource = new OverpassSource(
private DataLayerProducer<OsmTile> createOsmPopulator() {
List<OverpassSource> sources = new ArrayList<>();
sources.add(new OverpassSource(
this.earthCoordinates,
0.3,
"osm/outline",
new ResourceLocation(TerrariumEarth.MODID, "query/outline_overpass_query.oql"),
1
);
OverpassSource generalSource = new OverpassSource(
));
sources.add(new OverpassSource(
this.earthCoordinates,
0.1,
"osm/general",
new ResourceLocation(TerrariumEarth.MODID, "query/general_overpass_query.oql"),
2
);
OverpassSource detailSource = new OverpassSource(
));
sources.add(new OverpassSource(
this.earthCoordinates,
0.05,
"osm/detailed",
new ResourceLocation(TerrariumEarth.MODID, "query/detail_overpass_query.oql"),
2
);
return new OsmRegionPopulator(
new OsmSampler(outlineSource, this.earthCoordinates),
new OsmSampler(generalSource, this.earthCoordinates),
new OsmSampler(detailSource, this.earthCoordinates)
);
));

List<DataLayerProducer<OsmTile>> samplers = sources.stream()
.filter(OverpassSource::shouldSample)
.map(overpassSource -> new OsmSampleLayer(overpassSource, this.earthCoordinates))
.collect(Collectors.toList());

if (!samplers.isEmpty()) {
DataLayerProducer<OsmTile> layer = MergeDataLayer.from(samplers);
layer = DataLayer.of(new OsmPopulatorLayer(), layer);
return layer;
}

return DataSource.from(view -> new OsmTile());
}

private Interpolation.Method selectInterpolationMethod(PropertyContainer properties) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.gegy1000.earth.server.world.coordinate;

import net.gegy1000.earth.server.world.pipeline.populator.DebugMap;
import net.gegy1000.earth.server.world.pipeline.layer.DebugMap;
import net.gegy1000.terrarium.server.world.coordinate.CoordinateState;
import net.minecraft.util.math.MathHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.gegy1000.earth.server.world.pipeline.source.tile.OsmTile;
import net.gegy1000.terrarium.server.world.pipeline.component.RegionComponentType;
import net.gegy1000.terrarium.server.world.pipeline.source.tile.ByteRasterTile;

public class EarthComponentTypes {
public static final RegionComponentType<OsmTile> OSM = new RegionComponentType<OsmTile>(OsmTile.class) {
Expand All @@ -10,4 +11,11 @@ public OsmTile createDefaultData(int width, int height) {
return new OsmTile();
}
};

public static final RegionComponentType<ByteRasterTile> WATER = new RegionComponentType<ByteRasterTile>(ByteRasterTile.class) {
@Override
public ByteRasterTile createDefaultData(int width, int height) {
return new ByteRasterTile(new byte[width * height], width, height);
}
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.gegy1000.earth.server.world.pipeline.composer;

import net.gegy1000.earth.server.world.pipeline.populator.DebugMap;
import net.gegy1000.earth.server.world.pipeline.layer.DebugMap;
import net.gegy1000.terrarium.server.world.pipeline.component.RegionComponentType;
import net.gegy1000.terrarium.server.world.pipeline.composer.decoration.DecorationComposer;
import net.gegy1000.terrarium.server.world.pipeline.source.tile.ShortRasterTile;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.gegy1000.earth.server.world.pipeline.layer;

import net.gegy1000.terrarium.server.world.pipeline.DataLayerProducer;
import net.gegy1000.terrarium.server.world.pipeline.DataView;
import net.gegy1000.terrarium.server.world.pipeline.source.tile.CoverRasterTile;

public class DebugCoverPopulator implements DataLayerProducer<CoverRasterTile> {
@Override
public CoverRasterTile apply(DataView view) {
CoverRasterTile result = new CoverRasterTile(view);
int viewX = view.getX();
int viewY = view.getY();
for (int localZ = 0; localZ < view.getHeight(); localZ++) {
for (int localX = 0; localX < view.getWidth(); localX++) {
result.set(localX, localZ, DebugMap.getCover(localX + viewX, localZ + viewY).getCoverType());
}
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.gegy1000.earth.server.world.pipeline.populator;
package net.gegy1000.earth.server.world.pipeline.layer;

import com.google.common.base.CaseFormat;
import net.gegy1000.earth.server.world.cover.EarthCoverTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.gegy1000.earth.server.world.pipeline.layer;

import net.gegy1000.earth.server.world.pipeline.source.tile.OsmTile;
import net.gegy1000.terrarium.server.world.pipeline.DataLayerProcessor;
import net.gegy1000.terrarium.server.world.pipeline.DataView;

public class OsmPopulatorLayer implements DataLayerProcessor<OsmTile, OsmTile> {
@Override
public OsmTile apply(DataView view, OsmTile parent, DataView parentView) {
return parent;
}

@Override
public DataView getParentView(DataView view) {
return view.grow(8, 8, 8, 8);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.gegy1000.earth.server.world.pipeline.sampler;
package net.gegy1000.earth.server.world.pipeline.layer;

import de.topobyte.osm4j.core.model.iface.OsmNode;
import de.topobyte.osm4j.core.model.iface.OsmWay;
Expand All @@ -7,25 +7,25 @@
import net.gegy1000.earth.server.world.pipeline.source.tile.OsmTile;
import net.gegy1000.terrarium.server.world.coordinate.Coordinate;
import net.gegy1000.terrarium.server.world.coordinate.CoordinateState;
import net.gegy1000.terrarium.server.world.generator.customization.GenerationSettings;
import net.gegy1000.terrarium.server.world.pipeline.sampler.DataSampler;
import net.gegy1000.terrarium.server.world.pipeline.DataLayerProducer;
import net.gegy1000.terrarium.server.world.pipeline.DataView;
import net.gegy1000.terrarium.server.world.pipeline.source.DataTilePos;
import net.gegy1000.terrarium.server.world.pipeline.source.TiledDataSource;
import net.minecraft.util.math.MathHelper;

public class OsmSampler implements DataSampler<OsmTile> {
public class OsmSampleLayer implements DataLayerProducer<OsmTile> {
private final TiledDataSource<OsmTile> overpassSource;
private final CoordinateState coordinateState;

public OsmSampler(TiledDataSource<OsmTile> overpassSource, CoordinateState coordinateState) {
public OsmSampleLayer(TiledDataSource<OsmTile> overpassSource, CoordinateState coordinateState) {
this.overpassSource = overpassSource;
this.coordinateState = coordinateState;
}

@Override
public OsmTile sample(GenerationSettings settings, int x, int z, int width, int height) {
DataTilePos blockMinTilePos = this.getTilePos(Coordinate.fromBlock(x, z));
DataTilePos blockMaxTilePos = this.getTilePos(Coordinate.fromBlock(x + width, z + height));
public OsmTile apply(DataView view) {
DataTilePos blockMinTilePos = this.getTilePos(view.getMinCoordinate());
DataTilePos blockMaxTilePos = this.getTilePos(view.getMaxCoordinate());

DataTilePos minTilePos = DataTilePos.min(blockMinTilePos, blockMaxTilePos);
DataTilePos maxTilePos = DataTilePos.max(blockMinTilePos, blockMaxTilePos);
Expand All @@ -46,16 +46,6 @@ public OsmTile sample(GenerationSettings settings, int x, int z, int width, int
return new OsmTile(nodes, ways);
}

@Override
public boolean shouldSample() {
return this.overpassSource.shouldSample();
}

@Override
public Class<OsmTile> getSamplerType() {
return OsmTile.class;
}

private DataTilePos getTilePos(Coordinate coordinate) {
coordinate = coordinate.to(this.coordinateState);

Expand Down
Loading

0 comments on commit d415403

Please sign in to comment.