mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
Merge pull request #455 from pumken/seasoned-samplers-2
Add salted version of sampler functions in EXPRESSION samplers
This commit is contained in:
commit
8cf766e77b
@ -11,6 +11,8 @@ import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.paralithic.defined.UserDefinedFunction;
|
||||
import com.dfsek.terra.addons.noise.paralithic.noise.NoiseFunction2;
|
||||
import com.dfsek.terra.addons.noise.paralithic.noise.NoiseFunction3;
|
||||
import com.dfsek.terra.addons.noise.paralithic.noise.SaltedNoiseFunction2;
|
||||
import com.dfsek.terra.addons.noise.paralithic.noise.SaltedNoiseFunction3;
|
||||
|
||||
|
||||
public class FunctionUtil {
|
||||
@ -23,10 +25,15 @@ public class FunctionUtil {
|
||||
for(Map.Entry<String, FunctionTemplate> entry : functions.entrySet()) {
|
||||
functionMap.put(entry.getKey(), UserDefinedFunction.newInstance(entry.getValue()));
|
||||
}
|
||||
samplers.forEach((id, sampler) -> functionMap.put(id,
|
||||
sampler.getDimensions() == 2 ?
|
||||
new NoiseFunction2(sampler.getSampler()) :
|
||||
new NoiseFunction3(sampler.getSampler())));
|
||||
samplers.forEach((id, sampler) -> {
|
||||
if(sampler.getDimensions() == 2) {
|
||||
functionMap.put(id, new NoiseFunction2(sampler.getSampler()));
|
||||
functionMap.put(id + "Salted", new SaltedNoiseFunction2(sampler.getSampler()));
|
||||
} else {
|
||||
functionMap.put(id, new NoiseFunction3(sampler.getSampler()));
|
||||
functionMap.put(id + "Salted", new SaltedNoiseFunction3(sampler.getSampler()));
|
||||
}
|
||||
});
|
||||
return functionMap;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.dfsek.terra.addons.noise.paralithic.noise;
|
||||
|
||||
import com.dfsek.paralithic.functions.dynamic.Context;
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
import com.dfsek.paralithic.node.Statefulness;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class SaltedNoiseFunction2 implements DynamicFunction {
|
||||
private final NoiseSampler gen;
|
||||
|
||||
public SaltedNoiseFunction2(NoiseSampler gen) {
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(double... args) {
|
||||
throw new UnsupportedOperationException("Cannot evaluate seeded function without seed context.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(Context context, double... args) {
|
||||
return gen.noise(((SeedContext) context).getSeed() + (long) args[2], args[0], args[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArgNumber() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Statefulness statefulness() {
|
||||
return Statefulness.CONTEXTUAL;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.dfsek.terra.addons.noise.paralithic.noise;
|
||||
|
||||
import com.dfsek.paralithic.functions.dynamic.Context;
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
import com.dfsek.paralithic.node.Statefulness;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class SaltedNoiseFunction3 implements DynamicFunction {
|
||||
private final NoiseSampler gen;
|
||||
|
||||
public SaltedNoiseFunction3(NoiseSampler gen) {
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(double... args) {
|
||||
throw new UnsupportedOperationException("Cannot evaluate seeded function without seed context.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(Context context, double... args) {
|
||||
return gen.noise(((SeedContext) context).getSeed() + (long) args[3], args[0], args[1], args[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArgNumber() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Statefulness statefulness() {
|
||||
return Statefulness.CONTEXTUAL;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user