Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be64def

Browse files
committed
Logic filter cleanup
1 parent 304b62f commit be64def

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

core/src/mindustry/logic/LExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class LExecutor{
6060
public @Nullable LogicBuild build;
6161
public IntSet linkIds = new IntSet();
6262
public Team team = Team.derelict;
63-
public boolean privileged = false, isFilter = false;
63+
public boolean privileged = false;
6464

6565
//yes, this is a minor memory leak, but it's probably not significant enough to matter
6666
protected static IntFloatMap unitTimeouts = new IntFloatMap();

core/src/mindustry/maps/filters/LogicFilter.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mindustry.maps.filters;
22

33
import arc.scene.ui.layout.*;
4+
import mindustry.*;
45
import mindustry.gen.*;
56
import mindustry.logic.*;
67
import mindustry.maps.filters.FilterOption.*;
@@ -40,8 +41,19 @@ public void build(Table table){
4041
public void apply(Tiles tiles, GenerateInput in){
4142
executor = new LExecutor();
4243
executor.privileged = true;
43-
executor.isFilter = true;
44-
configure(code);
44+
45+
try{
46+
//assembler has no variables, all the standard ones are null
47+
executor.load(LAssembler.assemble(code, true));
48+
}catch(Throwable ignored){
49+
//if loading code
50+
return;
51+
}
52+
53+
//this updates map width/height global variables
54+
logicVars.update();
55+
56+
//NOTE: all tile operations will call setNet for tiles, but that should have no overhead during world loading
4557

4658
//limited run
4759
for(int i = 1; i < maxInstructionsExecution; i++){
@@ -59,24 +71,4 @@ public char icon(){
5971
public boolean isPost(){
6072
return true;
6173
}
62-
63-
void configure(String code){
64-
try{
65-
//create assembler to store extra variables
66-
LAssembler asm = LAssembler.assemble(code, true);
67-
68-
asm.putConst("@mapw", world.width());
69-
asm.putConst("@maph", world.height());
70-
asm.putConst("@links", executor.links.length);
71-
asm.putConst("@ipt", 1);
72-
73-
asm.putConst("@thisx", 0);
74-
asm.putConst("@thisy", 0);
75-
76-
executor.load(asm);
77-
}catch(Exception e){
78-
//handle malformed code and replace it with nothing
79-
executor.load(LAssembler.assemble(code = "", true));
80-
}
81-
}
8274
}

0 commit comments

Comments
 (0)