From 150aab353012350559e6c25513eaf082b0d7ebf7 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 15 Mar 2021 17:13:27 -0400 Subject: [PATCH] Server crash fix / Disabled logic config sync / Faster logic parsing --- .../mindustry/entities/comp/BuildingComp.java | 12 ++++++------ core/src/mindustry/logic/LAccess.java | 9 +-------- core/src/mindustry/logic/LAssembler.java | 18 +++++++++--------- core/src/mindustry/logic/LExecutor.java | 3 +-- .../world/blocks/power/PowerNode.java | 12 ++++++------ gradle.properties | 2 +- 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 694611fed3..dd5fa7c335 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -33,6 +33,7 @@ import mindustry.world.*; import mindustry.world.blocks.ConstructBlock.*; import mindustry.world.blocks.*; import mindustry.world.blocks.environment.*; +import mindustry.world.blocks.logic.LogicBlock.*; import mindustry.world.blocks.payloads.*; import mindustry.world.blocks.power.*; import mindustry.world.consumers.*; @@ -940,7 +941,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, /** Called when arbitrary configuration is applied to a tile. */ public void configured(@Nullable Unit builder, @Nullable Object value){ //null is of type void.class; anonymous classes use their superclass. - Class type = value == null ? void.class : value.getClass().isAnonymousClass() || value.getClass().getSimpleName().startsWith("adapter") ? value.getClass().getSuperclass() : value.getClass(); + Class type = value == null ? void.class : value.getClass().isAnonymousClass() ? value.getClass().getSuperclass() : value.getClass(); if(value instanceof Item) type = Item.class; if(value instanceof Block) type = Block.class; @@ -1360,12 +1361,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, @Override public void control(LAccess type, Object p1, double p2, double p3, double p4){ - //don't execute configure instructions as the client - if(type == LAccess.configure && block.logicConfigurable && !net.client()){ + //don't execute configure instructions that copy logic building configures; this can cause extreme lag + if(type == LAccess.configure && block.logicConfigurable && !(p1 instanceof LogicBuild)){ //change config only if it's new - Object prev = senseObject(LAccess.config); - if(prev != p1){ - configureAny(p1); + if(senseObject(LAccess.config) != p1){ + configured(null, p1); } } } diff --git a/core/src/mindustry/logic/LAccess.java b/core/src/mindustry/logic/LAccess.java index dad09faf56..4f4517498a 100644 --- a/core/src/mindustry/logic/LAccess.java +++ b/core/src/mindustry/logic/LAccess.java @@ -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; - } } diff --git a/core/src/mindustry/logic/LAssembler.java b/core/src/mindustry/logic/LAssembler.java index dfd64e9c44..662f3ad186 100644 --- a/core/src/mindustry/logic/LAssembler.java +++ b/core/src/mindustry/logic/LAssembler.java @@ -10,6 +10,7 @@ import mindustry.logic.LExecutor.*; public class LAssembler{ public static ObjectMap> 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. */ diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index c52e30dbda..db6ebf12a7 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -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{ diff --git a/core/src/mindustry/world/blocks/power/PowerNode.java b/core/src/mindustry/world/blocks/power/PowerNode.java index 73c9017bc8..476511e4a1 100644 --- a/core/src/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/mindustry/world/blocks/power/PowerNode.java @@ -143,7 +143,7 @@ public class PowerNode extends PowerBlock{ Draw.color(Pal.placing); Drawf.circles(x * tilesize + offset, y * tilesize + offset, laserRange * tilesize); - getPotentialLinks(tile, other -> { + getPotentialLinks(tile, player.team(), other -> { Draw.color(laserColor1, Renderer.laserOpacity * 0.5f); drawLaser(tile.team(), x * tilesize + offset, y * tilesize + offset, other.x, other.y, size, other.block.size); @@ -193,10 +193,10 @@ public class PowerNode extends PowerBlock{ return Intersector.overlaps(Tmp.cr1.set(src.worldx() + offset, src.worldy() + offset, laserRange * tilesize), Tmp.r1.setSize(size * tilesize).setCenter(other.worldx() + offset, other.worldy() + offset)); } - protected void getPotentialLinks(Tile tile, Cons others){ + protected void getPotentialLinks(Tile tile, Team team, Cons others){ Boolf valid = other -> other != null && other.tile() != tile && other.power != null && (other.block.outputsPower || other.block.consumesPower || other.block instanceof PowerNode) && - overlaps(tile.x * tilesize + offset, tile.y * tilesize + offset, other.tile(), laserRange * tilesize) && other.team == player.team() && + overlaps(tile.x * tilesize + offset, tile.y * tilesize + offset, other.tile(), laserRange * tilesize) && other.team == team && !graphs.contains(other.power.graph) && !PowerNode.insulated(tile, other.tile) && !(other instanceof PowerNodeBuild obuild && obuild.power.links.size >= ((PowerNode)obuild.block).maxNodes) && @@ -211,7 +211,7 @@ public class PowerNode extends PowerBlock{ //add conducting graphs to prevent double link for(var p : Edges.getEdges(size)){ Tile other = tile.nearby(p); - if(other != null && other.team() == player.team() && other.build != null && other.build.power != null){ + if(other != null && other.team() == team && other.build != null && other.build.power != null){ graphs.add(other.build.power.graph); } } @@ -351,7 +351,7 @@ public class PowerNode extends PowerBlock{ public void placed(){ if(net.client()) return; - getPotentialLinks(tile, other -> { + getPotentialLinks(tile, team, other -> { if(!power.links.contains(other.pos())){ configureAny(other.pos()); } @@ -382,7 +382,7 @@ public class PowerNode extends PowerBlock{ if(this == other){ if(other.power.links.size == 0){ int[] total = {0}; - getPotentialLinks(tile, link -> { + getPotentialLinks(tile, team, link -> { if(!insulated(this, link) && total[0]++ < maxNodes){ configure(link.pos()); } diff --git a/gradle.properties b/gradle.properties index 2108e6d452..9c3c5a3de4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=50fe096a7d26e76abc9be1ee5b18172d18e1b930 +archash=f57850f3e251bf14804cbbea536a9f01cf61c22d