Skip to content

Commit

Permalink
respect function loading order
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsek committed Feb 6, 2021
1 parent 4aebb83 commit 76eb0f3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder;
import com.dfsek.terra.biome.pipeline.stages.ExpanderStage;
import com.dfsek.terra.biome.pipeline.stages.MutatorStage;
import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
import com.dfsek.terra.config.loaders.MaterialSetLoader;
import com.dfsek.terra.config.loaders.ProbabilityCollectionLoader;
import com.dfsek.terra.config.loaders.RangeLoader;
Expand Down Expand Up @@ -45,6 +46,8 @@
import com.dfsek.terra.world.population.items.ores.OreHolder;
import com.dfsek.terra.world.population.items.tree.TreeLayer;

import java.util.LinkedHashMap;

public class GenericLoaders implements LoaderRegistrar {
private final TerraPlugin main;

Expand Down Expand Up @@ -79,6 +82,7 @@ public void register(TypeRegistry registry) {
.registerLoader(BorderMutatorTemplate.class, BorderMutatorTemplate::new)
.registerLoader(BorderListMutatorTemplate.class, BorderListMutatorTemplate::new)
.registerLoader(FunctionTemplate.class, FunctionTemplate::new)
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader())
.registerLoader(ImageSampler.Channel.class, (t, object, cf) -> ImageSampler.Channel.valueOf((String) object))
.registerLoader(ExpanderStage.Type.class, (t, object, cf) -> ExpanderStage.Type.valueOf((String) object))
.registerLoader(MutatorStage.Type.class, (t, object, cf) -> MutatorStage.Type.valueOf((String) object))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.dfsek.terra.config.templates.BiomeTemplate;
import parsii.eval.Scope;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class BiomeFactory implements TerraFactory<BiomeTemplate, TerraBiome> {
Expand All @@ -27,7 +27,7 @@ public UserDefinedBiome build(BiomeTemplate template, TerraPlugin main) {
generatorBuilder.setCarvingEquation(template.getCarvingEquation());
generatorBuilder.setNoiseBuilderMap(pack.getTemplate().getNoiseBuilderMap());

Map<String, FunctionTemplate> functions = new HashMap<>(pack.getTemplate().getFunctions());
Map<String, FunctionTemplate> functions = new LinkedHashMap<>(pack.getTemplate().getFunctions()); // linked map to preserve order.
functions.putAll(template.getFunctions());
generatorBuilder.setFunctionTemplateMap(functions);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dfsek.terra.config.loaders;

import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
import java.util.Map;

public class LinkedHashMapLoader implements TypeLoader<LinkedHashMap<Object, Object>> {
@Override
public LinkedHashMap<Object, Object> load(Type t, Object c, ConfigLoader loader) throws LoadException {
Map<String, Object> config = (Map<String, Object>) c;
LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
if(t instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) t;
Type key = pType.getActualTypeArguments()[0];
Type value = pType.getActualTypeArguments()[1];
for(Map.Entry<String, Object> entry : config.entrySet()) {
map.put(loader.loadType(key, entry.getKey()), loader.loadType(value, entry.getValue()));
}
} else throw new LoadException("Unable to load config");

return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@SuppressWarnings({"unused", "FieldMayBeFinal"})
Expand All @@ -24,7 +25,7 @@ public class ConfigPackTemplate implements ConfigTemplate {

@Value("functions")
@Default
private Map<String, FunctionTemplate> functions = new HashMap<>();
private LinkedHashMap<String, FunctionTemplate> functions = new LinkedHashMap<>();

@Value("structures.locatable")
@Default
Expand All @@ -34,22 +35,6 @@ public class ConfigPackTemplate implements ConfigTemplate {
@Default
private int elevationBlend = 4;

@Value("erode.enable")
@Default
private boolean erode = false;

@Value("erode.frequency")
@Default
private double erodeFreq = 0.001D;

@Value("erode.threshold")
@Default
private double erodeThresh = 0.0015D;

@Value("erode.octaves")
@Default
private int erodeOctaves = 5;

@Value("vanilla.mobs")
@Default
private boolean vanillaMobs = true;
Expand Down Expand Up @@ -129,22 +114,6 @@ public Map<String, Double> getVariables() {
return variables;
}

public boolean isErode() {
return erode;
}

public double getErodeFreq() {
return erodeFreq;
}

public double getErodeThresh() {
return erodeThresh;
}

public int getErodeOctaves() {
return erodeOctaves;
}

public int getElevationBlend() {
return elevationBlend;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import parsii.tokenizer.ParseException;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -57,7 +58,7 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Value("functions")
@Default
@Abstractable
private Map<String, FunctionTemplate> functions = new HashMap<>();
private LinkedHashMap<String, FunctionTemplate> functions = new LinkedHashMap<>();

@Value("carving.equation")
@Abstractable
Expand Down Expand Up @@ -342,7 +343,7 @@ public boolean validate() throws ValidationException {

pack.getTemplate().getNoiseBuilderMap().forEach((id, builder) -> tester.registerFunction(id, new BlankFunction(builder.getDimensions()))); // Register dummy functions

Map<String, FunctionTemplate> testFunctions = new HashMap<>(pack.getTemplate().getFunctions());
Map<String, FunctionTemplate> testFunctions = new LinkedHashMap<>(pack.getTemplate().getFunctions());
testFunctions.putAll(functions);
for(Map.Entry<String, FunctionTemplate> entry : testFunctions.entrySet()) {
String id = entry.getKey();
Expand Down
4 changes: 2 additions & 2 deletions platforms/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ val testWithPaper = task<JavaExec>(name = "testWithPaper") {
"-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32", "-XX:+PerfDisableSharedMem",
"-XX:MaxTenuringThreshold=1", "-Dusing.aikars.flags=https://mcflags.emc.gs",
"-Daikars.new.flags=true", "-DIReallyKnowWhatIAmDoingISwear")
maxHeapSize = "2G"
minHeapSize = "2G"
maxHeapSize = "4G"
minHeapSize = "4G"
//args = listOf("nogui")
workingDir = file("${testDir}/")
classpath = files("${testDir}/paper.jar")
Expand Down

0 comments on commit 76eb0f3

Please sign in to comment.