mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-22 05:47:44 +03:00
Better strict equality implementation
This commit is contained in:
parent
c06146110d
commit
3cbcd779eb
@ -1326,7 +1326,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
case enabled -> enabled ? 1 : 0;
|
||||
case controlled -> this instanceof ControlBlock c ? c.isControlled() ? 1 : 0 : 0;
|
||||
case payloadCount -> getPayload() != null ? 1 : 0;
|
||||
default -> 0;
|
||||
default -> Float.NaN; //gets converted to null in logic
|
||||
};
|
||||
}
|
||||
|
||||
@ -1339,14 +1339,13 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
case payloadType -> getPayload() instanceof UnitPayload p1 ? p1.unit.type : getPayload() instanceof BuildPayload p2 ? p2.block() : null;
|
||||
default -> noSensed;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sense(Content content){
|
||||
if(content instanceof Item && items != null) return items.get((Item)content);
|
||||
if(content instanceof Liquid && liquids != null) return liquids.get((Liquid)content);
|
||||
return 0;
|
||||
if(content instanceof Item i && items != null) return items.get(i);
|
||||
if(content instanceof Liquid l && liquids != null) return liquids.get(l);
|
||||
return Float.NaN; //invalid sense
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,8 @@ public class LAssembler{
|
||||
putConst("@unit", null);
|
||||
//reference to self
|
||||
putConst("@this", null);
|
||||
//global tick
|
||||
putConst("@tick", 0);
|
||||
}
|
||||
|
||||
public static LAssembler assemble(String data, int maxInstructions){
|
||||
|
@ -36,7 +36,8 @@ public class LExecutor{
|
||||
varCounter = 0,
|
||||
varTime = 1,
|
||||
varUnit = 2,
|
||||
varThis = 3;
|
||||
varThis = 3,
|
||||
varTick = 4;
|
||||
|
||||
public static final int
|
||||
maxGraphicsBuffer = 256,
|
||||
@ -61,6 +62,7 @@ public class LExecutor{
|
||||
public void runOnce(){
|
||||
//set time
|
||||
vars[varTime].numval = Time.millis();
|
||||
vars[varTick].numval = Time.time;
|
||||
|
||||
//reset to start
|
||||
if(vars[varCounter].numval >= instructions.length || vars[varCounter].numval < 0){
|
||||
@ -784,9 +786,9 @@ public class LExecutor{
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
if(op == LogicOp.isNull){
|
||||
var v = exec.var(a);
|
||||
exec.setnum(dest, v.isobj && v.objval == null ? 1 : 0);
|
||||
if(op == LogicOp.strictEqual){
|
||||
Var v = exec.var(a), v2 = exec.var(b);
|
||||
exec.setnum(dest, v.isobj == v2.isobj && ((v.isobj && v.objval == v2.objval) || (!v.isobj && v.numval == v2.numval)) ? 1 : 0);
|
||||
}else if(op.unary){
|
||||
exec.setnum(dest, op.function1.get(exec.num(a)));
|
||||
}else{
|
||||
|
@ -19,6 +19,7 @@ public enum LogicOp{
|
||||
lessThanEq("<=", (a, b) -> a <= b ? 1 : 0),
|
||||
greaterThan(">", (a, b) -> a > b ? 1 : 0),
|
||||
greaterThanEq(">=", (a, b) -> a >= b ? 1 : 0),
|
||||
strictEqual("===", (a, b) -> 0), //this lambda is not actually used
|
||||
|
||||
shl("<<", (a, b) -> (long)a << (long)b),
|
||||
shr(">>", (a, b) -> (long)a >> (long)b),
|
||||
@ -27,7 +28,6 @@ public enum LogicOp{
|
||||
xor("xor", (a, b) -> (long)a ^ (long)b),
|
||||
not("flip", a -> ~(long)(a)),
|
||||
|
||||
isNull("isNull", v -> v == 0 ? 1 : 0), //this lambda is not actually used
|
||||
max("max", Math::max),
|
||||
min("min", Math::min),
|
||||
atan2("atan2", (x, y) -> Mathf.atan2((float)x, (float)y) * Mathf.radDeg),
|
||||
|
Loading…
Reference in New Issue
Block a user