Merge branch 'way-zer-pr-readwrite'
This commit is contained in:
@@ -61,6 +61,8 @@ public class LExecutor{
|
|||||||
|
|
||||||
//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();
|
||||||
|
//lookup variable by name, lazy init.
|
||||||
|
protected @Nullable ObjectIntMap<String> nameMap;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
Events.on(ResetEvent.class, e -> unitTimeouts.clear());
|
Events.on(ResetEvent.class, e -> unitTimeouts.clear());
|
||||||
@@ -92,6 +94,7 @@ public class LExecutor{
|
|||||||
|
|
||||||
/** Loads with a specified assembler. Resets all variables. */
|
/** Loads with a specified assembler. Resets all variables. */
|
||||||
public void load(LAssembler builder){
|
public void load(LAssembler builder){
|
||||||
|
nameMap = null;
|
||||||
vars = builder.vars.values().toSeq().retainAll(var -> !var.constant).toArray(LVar.class);
|
vars = builder.vars.values().toSeq().retainAll(var -> !var.constant).toArray(LVar.class);
|
||||||
for(int i = 0; i < vars.length; i++){
|
for(int i = 0; i < vars.length; i++){
|
||||||
vars[i].id = i;
|
vars[i].id = i;
|
||||||
@@ -106,6 +109,17 @@ public class LExecutor{
|
|||||||
|
|
||||||
//region utility
|
//region utility
|
||||||
|
|
||||||
|
|
||||||
|
public @Nullable LVar optionalVar(String name){
|
||||||
|
if(nameMap == null){
|
||||||
|
nameMap = new ObjectIntMap<>();
|
||||||
|
for(int i = 0; i < vars.length; i++){
|
||||||
|
nameMap.put(vars[i].name, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return optionalVar(nameMap.get(name, -1));
|
||||||
|
}
|
||||||
|
|
||||||
/** @return a Var from this processor. May be null if out of bounds. */
|
/** @return a Var from this processor. May be null if out of bounds. */
|
||||||
public @Nullable LVar optionalVar(int index){
|
public @Nullable LVar optionalVar(int index){
|
||||||
return index < 0 || index >= vars.length ? null : vars[index];
|
return index < 0 || index >= vars.length ? null : vars[index];
|
||||||
@@ -227,7 +241,7 @@ public class LExecutor{
|
|||||||
outFound.setnum(0);
|
outFound.setnum(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(res != null && res.build != null &&
|
if(res != null && res.build != null &&
|
||||||
(unit.within(res.build.x, res.build.y, Math.max(unit.range(), buildingRange)) || res.build.team == exec.team)){
|
(unit.within(res.build.x, res.build.y, Math.max(unit.range(), buildingRange)) || res.build.team == exec.team)){
|
||||||
cache.build = res.build;
|
cache.build = res.build;
|
||||||
outBuild.setobj(res.build);
|
outBuild.setobj(res.build);
|
||||||
@@ -557,6 +571,13 @@ public class LExecutor{
|
|||||||
|
|
||||||
if(from instanceof MemoryBuild mem && (exec.privileged || (from.team == exec.team && !mem.block.privileged))){
|
if(from instanceof MemoryBuild mem && (exec.privileged || (from.team == exec.team && !mem.block.privileged))){
|
||||||
output.setnum(address < 0 || address >= mem.memory.length ? 0 : mem.memory[address]);
|
output.setnum(address < 0 || address >= mem.memory.length ? 0 : mem.memory[address]);
|
||||||
|
}else if(from instanceof LogicBuild logic && (exec.privileged || (from.team == exec.team && !from.block.privileged)) && position.isobj && position.objval instanceof String name){
|
||||||
|
LVar fromVar = logic.executor.optionalVar(name);
|
||||||
|
if(fromVar != null && !output.constant){
|
||||||
|
output.objval = fromVar.objval;
|
||||||
|
output.numval = fromVar.numval;
|
||||||
|
output.isobj = fromVar.isobj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -580,6 +601,13 @@ public class LExecutor{
|
|||||||
|
|
||||||
if(from instanceof MemoryBuild mem && (exec.privileged || (from.team == exec.team && !mem.block.privileged)) && address >= 0 && address < mem.memory.length){
|
if(from instanceof MemoryBuild mem && (exec.privileged || (from.team == exec.team && !mem.block.privileged)) && address >= 0 && address < mem.memory.length){
|
||||||
mem.memory[address] = value.num();
|
mem.memory[address] = value.num();
|
||||||
|
}else if(from instanceof LogicBuild logic && (exec.privileged || (from.team == exec.team && !from.block.privileged)) && position.isobj && position.objval instanceof String name){
|
||||||
|
LVar toVar = logic.executor.optionalVar(name);
|
||||||
|
if(toVar != null && !toVar.constant){
|
||||||
|
toVar.objval = value.objval;
|
||||||
|
toVar.numval = value.numval;
|
||||||
|
toVar.isobj = value.isobj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1754,29 +1754,30 @@ public class UnitType extends UnlockableContent implements Senseable{
|
|||||||
|
|
||||||
Tmp.v1.set(x, y).rotate(rot);
|
Tmp.v1.set(x, y).rotate(rot);
|
||||||
float ex = Tmp.v1.x, ey = Tmp.v1.y;
|
float ex = Tmp.v1.x, ey = Tmp.v1.y;
|
||||||
|
float rad = (radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale;
|
||||||
|
|
||||||
//engine outlines (cursed?)
|
//engine outlines (cursed?)
|
||||||
/*float z = Draw.z();
|
/*float z = Draw.z();
|
||||||
Draw.z(z - 0.0001f);
|
Draw.z(z - 0.0001f);
|
||||||
Draw.color(type.outlineColor);
|
Draw.color(type.outlineColor);
|
||||||
Fill.circle(
|
Fill.circle(
|
||||||
unit.x + ex,
|
unit.x + ex,
|
||||||
unit.y + ey,
|
unit.y + ey,
|
||||||
(type.outlineRadius * Draw.scl + radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale
|
(type.outlineRadius * Draw.scl + radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale
|
||||||
);
|
);
|
||||||
Draw.z(z);*/
|
Draw.z(z);*/
|
||||||
|
|
||||||
Draw.color(color);
|
Draw.color(color);
|
||||||
Fill.circle(
|
Fill.circle(
|
||||||
unit.x + ex,
|
unit.x + ex,
|
||||||
unit.y + ey,
|
unit.y + ey,
|
||||||
(radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale
|
rad
|
||||||
);
|
);
|
||||||
Draw.color(type.engineColorInner);
|
Draw.color(type.engineColorInner);
|
||||||
Fill.circle(
|
Fill.circle(
|
||||||
unit.x + ex - Angles.trnsx(rot + rotation, 1f),
|
unit.x + ex - Angles.trnsx(rot + rotation, rad / 4f),
|
||||||
unit.y + ey - Angles.trnsy(rot + rotation, 1f),
|
unit.y + ey - Angles.trnsy(rot + rotation, rad / 4f),
|
||||||
(radius + Mathf.absin(Time.time, 2f, radius / 4f)) / 2f * scale
|
rad / 2f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user