drastically optimise terrascript scoping

This commit is contained in:
dfsek
2022-02-16 15:55:46 -07:00
parent aa39dc4b81
commit a02847e3ed
39 changed files with 226 additions and 289 deletions

View File

@@ -7,16 +7,14 @@
package com.dfsek.terra.addon.terrascript.check;
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
import net.jafama.FastMath;
import java.util.Map;
import com.dfsek.terra.addons.chunkgenerator.generation.NoiseChunkGenerator3D;
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.SamplerProvider;
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
import com.dfsek.terra.addons.terrascript.parser.lang.variables.Variable;
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
import com.dfsek.terra.api.util.RotationUtil;
@@ -39,19 +37,19 @@ public class CheckFunction implements Function<String> {
@Override
public String apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
public String apply(ImplementationArguments implementationArguments, Scope scope) {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = Vector2.of(x.apply(implementationArguments, variableMap).doubleValue(),
z.apply(implementationArguments, variableMap).doubleValue());
Vector2 xz = Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
z.apply(implementationArguments, scope).doubleValue());
RotationUtil.rotateVector(xz, arguments.getRotation());
Vector3 location = arguments.getOrigin().toVector3Mutable().add(
Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(),
Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).doubleValue(),
FastMath.roundToInt(xz.getZ()))).immutable();
return apply(location, arguments.getWorld());