mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-12 08:48:09 +07:00
Logic filter cleanup
This commit is contained in:
@ -60,7 +60,7 @@ public class LExecutor{
|
|||||||
public @Nullable LogicBuild build;
|
public @Nullable LogicBuild build;
|
||||||
public IntSet linkIds = new IntSet();
|
public IntSet linkIds = new IntSet();
|
||||||
public Team team = Team.derelict;
|
public Team team = Team.derelict;
|
||||||
public boolean privileged = false, isFilter = false;
|
public boolean privileged = false;
|
||||||
|
|
||||||
//yes, this is a minor memory leak, but it's probably not significant enough to matter
|
//yes, this is a minor memory leak, but it's probably not significant enough to matter
|
||||||
protected static IntFloatMap unitTimeouts = new IntFloatMap();
|
protected static IntFloatMap unitTimeouts = new IntFloatMap();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package mindustry.maps.filters;
|
package mindustry.maps.filters;
|
||||||
|
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
|
import mindustry.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.logic.*;
|
import mindustry.logic.*;
|
||||||
import mindustry.maps.filters.FilterOption.*;
|
import mindustry.maps.filters.FilterOption.*;
|
||||||
@ -40,8 +41,19 @@ public class LogicFilter extends GenerateFilter{
|
|||||||
public void apply(Tiles tiles, GenerateInput in){
|
public void apply(Tiles tiles, GenerateInput in){
|
||||||
executor = new LExecutor();
|
executor = new LExecutor();
|
||||||
executor.privileged = true;
|
executor.privileged = true;
|
||||||
executor.isFilter = true;
|
|
||||||
configure(code);
|
try{
|
||||||
|
//assembler has no variables, all the standard ones are null
|
||||||
|
executor.load(LAssembler.assemble(code, true));
|
||||||
|
}catch(Throwable ignored){
|
||||||
|
//if loading code
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//this updates map width/height global variables
|
||||||
|
logicVars.update();
|
||||||
|
|
||||||
|
//NOTE: all tile operations will call setNet for tiles, but that should have no overhead during world loading
|
||||||
|
|
||||||
//limited run
|
//limited run
|
||||||
for(int i = 1; i < maxInstructionsExecution; i++){
|
for(int i = 1; i < maxInstructionsExecution; i++){
|
||||||
@ -59,24 +71,4 @@ public class LogicFilter extends GenerateFilter{
|
|||||||
public boolean isPost(){
|
public boolean isPost(){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure(String code){
|
|
||||||
try{
|
|
||||||
//create assembler to store extra variables
|
|
||||||
LAssembler asm = LAssembler.assemble(code, true);
|
|
||||||
|
|
||||||
asm.putConst("@mapw", world.width());
|
|
||||||
asm.putConst("@maph", world.height());
|
|
||||||
asm.putConst("@links", executor.links.length);
|
|
||||||
asm.putConst("@ipt", 1);
|
|
||||||
|
|
||||||
asm.putConst("@thisx", 0);
|
|
||||||
asm.putConst("@thisy", 0);
|
|
||||||
|
|
||||||
executor.load(asm);
|
|
||||||
}catch(Exception e){
|
|
||||||
//handle malformed code and replace it with nothing
|
|
||||||
executor.load(LAssembler.assemble(code = "", true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user