Server crash fix / Disabled logic config sync / Faster logic parsing
This commit is contained in:
@@ -50,13 +50,11 @@ public enum LAccess{
|
||||
enabled("to"), //"to" is standard for single parameter access
|
||||
shoot("x", "y", "shoot"),
|
||||
shootp(true, "unit", "shoot"),
|
||||
configure(true, 30, "to"),
|
||||
configure(true, "to"),
|
||||
color("r", "g", "b");
|
||||
|
||||
public final String[] params;
|
||||
public final boolean isObj;
|
||||
/** Tick cooldown between invocations. */
|
||||
public float cooldown = -1;
|
||||
|
||||
public static final LAccess[]
|
||||
all = values(),
|
||||
@@ -73,9 +71,4 @@ public enum LAccess{
|
||||
isObj = obj;
|
||||
}
|
||||
|
||||
LAccess(boolean obj, float cooldown, String... params){
|
||||
this.params = params;
|
||||
this.cooldown = cooldown;
|
||||
isObj = obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import mindustry.logic.LExecutor.*;
|
||||
public class LAssembler{
|
||||
public static ObjectMap<String, Func<String[], LStatement>> customParsers = new ObjectMap<>();
|
||||
public static final int maxTokenLength = 36;
|
||||
private static final int invalidNum = Integer.MIN_VALUE;
|
||||
|
||||
private static final StringMap opNameChanges = StringMap.of(
|
||||
"atan2", "angle",
|
||||
@@ -77,23 +78,22 @@ public class LAssembler{
|
||||
//remove spaces for non-strings
|
||||
symbol = symbol.replace(' ', '_');
|
||||
|
||||
try{
|
||||
double value = parseDouble(symbol);
|
||||
if(Double.isNaN(value) || Double.isInfinite(value)) value = 0;
|
||||
double value = parseDouble(symbol);
|
||||
|
||||
if(value == invalidNum){
|
||||
return putVar(symbol).id;
|
||||
}else{
|
||||
//this creates a hidden const variable with the specified value
|
||||
return putConst("___" + value, value).id;
|
||||
}catch(NumberFormatException e){
|
||||
return putVar(symbol).id;
|
||||
}
|
||||
}
|
||||
|
||||
double parseDouble(String symbol) throws NumberFormatException{
|
||||
double parseDouble(String symbol){
|
||||
//parse hex/binary syntax
|
||||
if(symbol.startsWith("0b")) return Long.parseLong(symbol.substring(2), 2);
|
||||
if(symbol.startsWith("0x")) return Long.parseLong(symbol.substring(2), 16);
|
||||
if(symbol.startsWith("0b")) return Strings.parseLong(symbol, 2, 2, symbol.length(), invalidNum);
|
||||
if(symbol.startsWith("0x")) return Strings.parseLong(symbol, 16, 2, symbol.length(), invalidNum);
|
||||
|
||||
return Double.parseDouble(symbol);
|
||||
return Strings.parseDouble(symbol, invalidNum);
|
||||
}
|
||||
|
||||
/** Adds a constant value by name. */
|
||||
|
||||
@@ -523,7 +523,6 @@ public class LExecutor{
|
||||
public int target;
|
||||
public LAccess type = LAccess.enabled;
|
||||
public int p1, p2, p3, p4;
|
||||
public Interval timer = new Interval(1);
|
||||
|
||||
public ControlI(LAccess type, int target, int p1, int p2, int p3, int p4){
|
||||
this.type = type;
|
||||
@@ -539,7 +538,7 @@ public class LExecutor{
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
Object obj = exec.obj(target);
|
||||
if(obj instanceof Building b && b.team == exec.team && exec.linkIds.contains(b.id) && (type.cooldown <= 0 || timer.get(type.cooldown))){
|
||||
if(obj instanceof Building b && b.team == exec.team && exec.linkIds.contains(b.id)){
|
||||
if(type.isObj){
|
||||
b.control(type, exec.obj(p1), exec.num(p2), exec.num(p3), exec.num(p4));
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user