Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/mindustry/logic/LExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void runOnce(){
public void load(LAssembler builder){
stop = false;
nameMap = null;
vars = builder.vars.values().toSeq().retainAll(var -> !var.constant).toArray(LVar.class);
vars = builder.vars.values().toSeq().retainAll(var -> !var.constant || var.name.charAt(0) != '_' && var.name.charAt(0) != '@').toArray(LVar.class);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to add only the constants representing the linked variables here, to keep the array small. Before, all constants were excluded. Now I'm excluding the constants representing mlog literals (triple underscore) and builtin variables (@this, @links, etc.). What remains should be the constants representing linked blocks.

I could include the builtins as well, and they would be remotely readable, but the only really useful one is @links, and since links can't be read remotely anyway, its utility is limited. I'd probably add them in #11838.

for(int i = 0; i < vars.length; i++){
vars[i].id = i;
}
Expand Down
14 changes: 11 additions & 3 deletions core/src/mindustry/world/blocks/logic/LogicBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,24 @@ public LogicBlock(String name){
int x = lbuild.tileX(), y = lbuild.tileY();
int oldSize = entity.links.size;

entity.links.removeAll(l -> world.build(l.x, l.y) == lbuild);
entity.links.removeAll(l -> {
boolean remove = world.build(l.x, l.y) == lbuild;
if(remove) l.trySet(entity.executor, null);
return remove;
});

if(oldSize > entity.links.size){ //check whether any were removed
//re-enable the target when unlinking
if(lbuild.block.autoResetEnabled && lbuild.lastDisabler == entity){
lbuild.enabled = true;
}
}else{
entity.links.add(new LogicLink(x, y, entity.findLinkName(lbuild.block), true));
LogicLink link = new LogicLink(x, y, entity.findLinkName(lbuild.block), true);
link.trySet(entity.executor, lbuild);
entity.links.add(link);
}

entity.updateCode(entity.code, true, null);
entity.updateLinks();
});
}

Expand Down Expand Up @@ -575,6 +581,8 @@ public void updateTile(){
}

public void updateLinks(){
if(linksVar == null) return; //no valid code compiled yet

int valids = links.count(l -> l.valid);
executor.links = new Building[valids];
executor.linkIds.clear();
Expand Down
Loading