2020-08-23 10:14:04 -04:00
|
|
|
package mindustry.logic;
|
|
|
|
|
|
|
|
import arc.math.*;
|
2020-10-05 15:42:37 -04:00
|
|
|
import arc.util.*;
|
2020-08-23 10:14:04 -04:00
|
|
|
|
|
|
|
public enum LogicOp{
|
|
|
|
add("+", (a, b) -> a + b),
|
|
|
|
sub("-", (a, b) -> a - b),
|
|
|
|
mul("*", (a, b) -> a * b),
|
|
|
|
div("/", (a, b) -> a / b),
|
2020-09-17 17:46:45 +01:00
|
|
|
idiv("//", (a, b) -> Math.floor(a / b)),
|
2020-08-23 10:14:04 -04:00
|
|
|
mod("%", (a, b) -> a % b),
|
2020-11-12 18:46:20 -05:00
|
|
|
pow("^", Math::pow),
|
|
|
|
|
2020-10-05 15:42:37 -04:00
|
|
|
equal("==", (a, b) -> Math.abs(a - b) < 0.000001 ? 1 : 0, (a, b) -> Structs.eq(a, b) ? 1 : 0),
|
|
|
|
notEqual("not", (a, b) -> Math.abs(a - b) < 0.000001 ? 0 : 1, (a, b) -> !Structs.eq(a, b) ? 1 : 0),
|
2020-11-12 18:46:20 -05:00
|
|
|
land("and", (a, b) -> a != 0 && b != 0 ? 1 : 0),
|
2020-08-23 10:14:04 -04:00
|
|
|
lessThan("<", (a, b) -> a < b ? 1 : 0),
|
|
|
|
lessThanEq("<=", (a, b) -> a <= b ? 1 : 0),
|
|
|
|
greaterThan(">", (a, b) -> a > b ? 1 : 0),
|
|
|
|
greaterThanEq(">=", (a, b) -> a >= b ? 1 : 0),
|
2020-11-12 18:46:20 -05:00
|
|
|
|
2020-09-16 18:38:23 -04:00
|
|
|
shl("<<", (a, b) -> (long)a << (long)b),
|
|
|
|
shr(">>", (a, b) -> (long)a >> (long)b),
|
2020-09-10 18:14:03 -05:00
|
|
|
or("or", (a, b) -> (long)a | (long)b),
|
2020-11-12 18:46:20 -05:00
|
|
|
and("b-and", (a, b) -> (long)a & (long)b),
|
2020-09-10 18:14:03 -05:00
|
|
|
xor("xor", (a, b) -> (long)a ^ (long)b),
|
2020-11-12 18:46:20 -05:00
|
|
|
not("flip", a -> ~(long)(a)),
|
|
|
|
|
2021-02-08 12:48:39 -05:00
|
|
|
isNull("isNull", v -> v == 0 ? 1 : 0), //this lambda is not actually used
|
2020-08-23 10:14:04 -04:00
|
|
|
max("max", Math::max),
|
|
|
|
min("min", Math::min),
|
|
|
|
atan2("atan2", (x, y) -> Mathf.atan2((float)x, (float)y) * Mathf.radDeg),
|
|
|
|
dst("dst", (x, y) -> Mathf.dst((float)x, (float)y)),
|
2020-09-10 16:45:48 -04:00
|
|
|
noise("noise", LExecutor.noise::rawNoise2D),
|
2020-08-23 11:30:56 -04:00
|
|
|
abs("abs", a -> Math.abs(a)),
|
2020-08-23 10:14:04 -04:00
|
|
|
log("log", Math::log),
|
|
|
|
log10("log10", Math::log10),
|
|
|
|
sin("sin", d -> Math.sin(d * 0.017453292519943295D)),
|
|
|
|
cos("cos", d -> Math.cos(d * 0.017453292519943295D)),
|
|
|
|
tan("tan", d -> Math.tan(d * 0.017453292519943295D)),
|
|
|
|
floor("floor", Math::floor),
|
|
|
|
ceil("ceil", Math::ceil),
|
|
|
|
sqrt("sqrt", Math::sqrt),
|
2020-11-01 19:35:22 +00:00
|
|
|
rand("rand", d -> Mathf.rand.nextDouble() * d);
|
2020-08-23 10:14:04 -04:00
|
|
|
|
|
|
|
public static final LogicOp[] all = values();
|
|
|
|
|
2020-09-09 19:02:40 -04:00
|
|
|
public final OpObjLambda2 objFunction2;
|
2020-08-23 10:14:04 -04:00
|
|
|
public final OpLambda2 function2;
|
|
|
|
public final OpLambda1 function1;
|
|
|
|
public final boolean unary;
|
|
|
|
public final String symbol;
|
|
|
|
|
|
|
|
LogicOp(String symbol, OpLambda2 function){
|
2020-09-09 19:02:40 -04:00
|
|
|
this(symbol, function, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
LogicOp(String symbol, OpLambda2 function, OpObjLambda2 objFunction){
|
2020-08-23 10:14:04 -04:00
|
|
|
this.symbol = symbol;
|
|
|
|
this.function2 = function;
|
|
|
|
this.function1 = null;
|
|
|
|
this.unary = false;
|
2020-09-09 19:02:40 -04:00
|
|
|
this.objFunction2 = objFunction;
|
2020-08-23 10:14:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
LogicOp(String symbol, OpLambda1 function){
|
|
|
|
this.symbol = symbol;
|
|
|
|
this.function1 = function;
|
|
|
|
this.function2 = null;
|
|
|
|
this.unary = true;
|
2020-09-09 19:02:40 -04:00
|
|
|
this.objFunction2 = null;
|
2020-08-23 10:14:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString(){
|
|
|
|
return symbol;
|
|
|
|
}
|
|
|
|
|
2020-09-09 19:02:40 -04:00
|
|
|
interface OpObjLambda2{
|
|
|
|
double get(Object a, Object b);
|
|
|
|
}
|
|
|
|
|
2020-08-23 10:14:04 -04:00
|
|
|
interface OpLambda2{
|
|
|
|
double get(double a, double b);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface OpLambda1{
|
|
|
|
double get(double a);
|
|
|
|
}
|
|
|
|
}
|