mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 16:35:50 +00:00
fix ExpressionFunction issue
This commit is contained in:
parent
6f287a1894
commit
f9ca8d139b
@ -12,6 +12,8 @@ import com.dfsek.terra.api.math.noise.NoiseSampler;
|
|||||||
import com.dfsek.terra.api.math.noise.samplers.noise.ExpressionFunction;
|
import com.dfsek.terra.api.math.noise.samplers.noise.ExpressionFunction;
|
||||||
import com.dfsek.terra.api.math.paralithic.BlankFunction;
|
import com.dfsek.terra.api.math.paralithic.BlankFunction;
|
||||||
import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction;
|
import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction;
|
||||||
|
import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction2;
|
||||||
|
import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction3;
|
||||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||||
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate;
|
||||||
@ -32,7 +34,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
|||||||
|
|
||||||
@Value("functions")
|
@Value("functions")
|
||||||
@Default
|
@Default
|
||||||
private Map<String, NoiseSeeded> functions = new HashMap<>();
|
private LinkedHashMap<String, NoiseSeeded> functions = new LinkedHashMap<>();
|
||||||
|
|
||||||
@Value("expressions")
|
@Value("expressions")
|
||||||
@Default
|
@Default
|
||||||
@ -41,7 +43,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
|||||||
@Override
|
@Override
|
||||||
public NoiseSampler apply(Long seed) {
|
public NoiseSampler apply(Long seed) {
|
||||||
try {
|
try {
|
||||||
Map<String, Function> noiseFunctionMap = generateFunctions();
|
Map<String, Function> noiseFunctionMap = generateFunctions(seed);
|
||||||
return new ExpressionFunction(noiseFunctionMap, equation, vars);
|
return new ExpressionFunction(noiseFunctionMap, equation, vars);
|
||||||
} catch(ParseException e) {
|
} catch(ParseException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@ -51,7 +53,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
|||||||
@Override
|
@Override
|
||||||
public boolean validate() throws ValidationException {
|
public boolean validate() throws ValidationException {
|
||||||
try {
|
try {
|
||||||
Map<String, Function> noiseFunctionMap = generateFunctions();
|
Map<String, Function> noiseFunctionMap = generateFunctions(0L);
|
||||||
new ExpressionFunction(noiseFunctionMap, equation, vars);
|
new ExpressionFunction(noiseFunctionMap, equation, vars);
|
||||||
} catch(ParseException e) {
|
} catch(ParseException e) {
|
||||||
throw new ValidationException("Errors occurred while parsing noise equation: ", e);
|
throw new ValidationException("Errors occurred while parsing noise equation: ", e);
|
||||||
@ -59,7 +61,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
|||||||
return super.validate();
|
return super.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Function> generateFunctions() throws ParseException {
|
private Map<String, Function> generateFunctions(Long seed) throws ParseException {
|
||||||
Map<String, Function> noiseFunctionMap = new HashMap<>();
|
Map<String, Function> noiseFunctionMap = new HashMap<>();
|
||||||
|
|
||||||
for(Map.Entry<String, FunctionTemplate> entry : expressions.entrySet()) {
|
for(Map.Entry<String, FunctionTemplate> entry : expressions.entrySet()) {
|
||||||
@ -69,8 +71,8 @@ public class ExpressionFunctionTemplate extends SamplerTemplate<ExpressionFuncti
|
|||||||
|
|
||||||
functions.forEach((id, function) -> {
|
functions.forEach((id, function) -> {
|
||||||
if(function.getDimensions() == 2) {
|
if(function.getDimensions() == 2) {
|
||||||
noiseFunctionMap.put(id, new BlankFunction(2));
|
noiseFunctionMap.put(id, new NoiseFunction2(function.apply(seed)));
|
||||||
} else noiseFunctionMap.put(id, new BlankFunction(3));
|
} else noiseFunctionMap.put(id, new NoiseFunction3(function.apply(seed)));
|
||||||
});
|
});
|
||||||
|
|
||||||
return noiseFunctionMap;
|
return noiseFunctionMap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user