Make setmarker ignor null values, remove redundant marker control operations

This commit is contained in:
ApsZoldat
2023-12-04 22:39:32 +03:00
parent 90e40af8c1
commit cf02b0f36d
5 changed files with 198 additions and 131 deletions
+2 -3
View File
@@ -2303,7 +2303,7 @@ lst.setprop = Sets a property of a unit or building.
lst.effect = Create a particle effect. lst.effect = Create a particle effect.
lst.sync = Sync a variable across the network.\nLimited to 20 times a second per variable. lst.sync = Sync a variable across the network.\nLimited to 20 times a second per variable.
lst.makemarker = Create a new logic marker in the world.\nAn ID to identify this marker must be provided.\nMarkers currently limited to 20,000 per world. lst.makemarker = Create a new logic marker in the world.\nAn ID to identify this marker must be provided.\nMarkers currently limited to 20,000 per world.
lst.setmarker = Set a property for a marker.\nThe ID used must be the same as in the Make Marker instruction. lst.setmarker = Set a property for a marker.\nThe ID used must be the same as in the Make Marker instruction.\n[accent]null []values are being ignored instead of converting to 0.
logic.nounitbuild = [red]Unit building logic is not allowed here. logic.nounitbuild = [red]Unit building logic is not allowed here.
@@ -2458,6 +2458,5 @@ lenum.within = Check if unit is near a position.
lenum.boost = Start/stop boosting. lenum.boost = Start/stop boosting.
lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nSecond and third arguments are additional suffixes added using "-" separator.\nIf additional arguments are not strings, nothing is added to first string. lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nSecond and third arguments are additional suffixes added using "-" separator.\nIf additional arguments are not strings, nothing is added to first string.
lenum.texturewidth = Width of texture in tiles. Zero value scales marker width to original texture's size. lenum.texturesize = Size of texture in tiles. Zero value scales marker width to original texture's size.
lenum.textureheight = Height of texture in tiles. Zero value scales marker height to original texture's size.
lenum.autoscale = Whether to scale marker corresponding to player's zoom level. lenum.autoscale = Whether to scale marker corresponding to player's zoom level.
+103 -43
View File
@@ -630,8 +630,9 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public void added(){} public void added(){}
/** Remove any UI elements, if necessary. */ /** Remove any UI elements, if necessary. */
public void removed(){} public void removed(){}
/** Control marker with world processor code*/ /** Control marker with world processor code. Ignores NaN (null) values. */
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(Double.isNaN(p1)) return;
switch(type){ switch(type){
case visibility -> hidden = Mathf.equal((float)p1, 0f); case visibility -> hidden = Mathf.equal((float)p1, 0f);
case drawLayer -> drawLayer = (float)p1; case drawLayer -> drawLayer = (float)p1;
@@ -757,24 +758,41 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(!Double.isNaN(p1)){
switch(type){ switch(type){
case x -> pos.x = (float)p1 * tilesize; case pos -> pos.x = (float)p1 * tilesize;
case y -> pos.y = (float)p1 * tilesize;
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
case fontSize -> fontSize = (float)p1; case fontSize -> fontSize = (float)p1;
case textHeight -> textHeight = (float)p1; case textHeight -> textHeight = (float)p1;
case labelFlags -> { case labelFlags -> {
flags = (!Mathf.equal((float)p1, 0f) ? WorldLabel.flagBackground : 0); if(!Mathf.equal((float)p1, 0f)){
if(!Mathf.equal((float)p2, 0f)) flags |= WorldLabel.flagOutline; flags |= WorldLabel.flagBackground;
}else{
flags &= ~WorldLabel.flagBackground;
}
} }
case radius -> radius = (float)p1; case radius -> radius = (float)p1;
case rotation -> rotation = (float)p1; case rotation -> rotation = (float)p1;
case shapeSides -> sides = (int)p1;
case color -> color.set(Tmp.c1.fromDouble(p1)); case color -> color.set(Tmp.c1.fromDouble(p1));
case shape -> sides = (int)p1;
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
} }
if(!Double.isNaN(p2)){
switch(type){
case pos -> pos.y = (float)p2 * tilesize;
case labelFlags -> {
if(!Mathf.equal((float)p2, 0f)){
flags |= WorldLabel.flagOutline;
}else{
flags &= ~WorldLabel.flagOutline;
}
}
default -> super.control(type, p1, p2, p3);
}
}
}
@Override @Override
public void setText(String text, boolean fetch){ public void setText(String text, boolean fetch){
this.text = text; this.text = text;
@@ -828,16 +846,24 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(!Double.isNaN(p1)){
switch(type){ switch(type){
case x -> pos.x = (int)p1; case pos -> pos.x = (int)p1;
case y -> pos.y = (int)p1;
case pos -> pos.set((int)p1, (int)p2);
case radius -> radius = (float)p1; case radius -> radius = (float)p1;
case stroke -> stroke = (float)p1; case stroke -> stroke = (float)p1;
case color -> color.set(Tmp.c1.fromDouble(p1)); case color -> color.set(Tmp.c1.fromDouble(p1));
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
} }
if(!Double.isNaN(p2)){
if(type == LMarkerControl.pos){
pos.y = (int)p2;
}else{
super.control(type, p1, p2, p3);
}
}
}
} }
/** Displays a shape with an outline and color. */ /** Displays a shape with an outline and color. */
@@ -916,25 +942,34 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(!Double.isNaN(p1)){
switch(type){ switch(type){
case x -> pos.x = (float)p1 * tilesize; case pos -> pos.x = (float)p1 * tilesize;
case y -> pos.y = (float)p1 * tilesize;
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
case radius -> radius = (float)p1; case radius -> radius = (float)p1;
case rotation -> rotation = (float)p1;
case stroke -> stroke = (float)p1; case stroke -> stroke = (float)p1;
case shapeSides -> sides = (int)p1; case rotation -> rotation = (float)p1;
case shapeFill -> fill = !Mathf.equal((float)p1, 0f);
case shapeOutline -> outline = !Mathf.equal((float)p1, 0f);
case shape -> {
sides = (int)p1;
fill = !Mathf.equal((float)p2, 0f);
outline = !Mathf.equal((float)p3, 0f);
}
case color -> color.set(Tmp.c1.fromDouble(p1)); case color -> color.set(Tmp.c1.fromDouble(p1));
case shape -> sides = (int)p1;
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
} }
if(!Double.isNaN(p2)){
switch(type){
case pos -> pos.y = (float)p2 * tilesize;
case shape -> fill = !Mathf.equal((float)p2, 0f);
default -> super.control(type, p1, p2, p3);
}
}
if(!Double.isNaN(p3)){
if(type == LMarkerControl.shape){
outline = !Mathf.equal((float)p3, 0f);
}else{
super.control(type, p1, p2, p3);
}
}
}
} }
/** Displays text at a location. */ /** Displays text at a location. */
@@ -994,19 +1029,36 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(!Double.isNaN(p1)){
switch(type){ switch(type){
case x -> pos.x = (float)p1 * tilesize; case pos -> pos.x = (float)p1 * tilesize;
case y -> pos.y = (float)p1 * tilesize;
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
case fontSize -> fontSize = (float)p1; case fontSize -> fontSize = (float)p1;
case labelFlags -> { case labelFlags -> {
flags = (!Mathf.equal((float)p1, 0f) ? WorldLabel.flagBackground : 0); if(!Mathf.equal((float)p1, 0f)){
if(!Mathf.equal((float)p2, 0f)) flags |= WorldLabel.flagOutline; flags |= WorldLabel.flagBackground;
}else{
flags &= ~WorldLabel.flagBackground;
}
} }
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
} }
if(!Double.isNaN(p2)){
switch(type){
case pos -> pos.y = (float)p2 * tilesize;
case labelFlags -> {
if(!Mathf.equal((float)p2, 0f)){
flags |= WorldLabel.flagOutline;
}else{
flags &= ~WorldLabel.flagOutline;
}
}
default -> super.control(type, p1, p2, p3);
}
}
}
@Override @Override
public void setText(String text, boolean fetch){ public void setText(String text, boolean fetch){
this.text = text; this.text = text;
@@ -1073,19 +1125,24 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(!Double.isNaN(p1)){
switch(type){ switch(type){
case x -> pos1.x = (float)p1 * tilesize; case pos -> pos1.x = (float)p1 * tilesize;
case y -> pos1.y = (float)p1 * tilesize; case endPos -> pos2.x = (float)p1 * tilesize;
case pos -> pos1.set((float)p1 * tilesize, (float)p2 * tilesize);
case endX -> pos2.x = (float)p1 * tilesize;
case endY -> pos2.y = (float)p1 * tilesize;
case endPos -> pos2.set((float)p1 * tilesize, (float)p2 * tilesize);
case stroke -> stroke = (float)p1; case stroke -> stroke = (float)p1;
case shapeOutline -> outline = !Mathf.equal((float)p1, 0f);
case color -> color.set(Tmp.c1.fromDouble(p1)); case color -> color.set(Tmp.c1.fromDouble(p1));
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
} }
if(!Double.isNaN(p2)){
switch(type){
case pos -> pos1.y = (float)p2 * tilesize;
case endPos -> pos2.y = (float)p2 * tilesize;
default -> super.control(type, p1, p2, p3);
}
}
}
} }
/** Displays a texture with specified name. */ /** Displays a texture with specified name. */
@@ -1106,22 +1163,25 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(!Double.isNaN(p1)){
switch(type){ switch(type){
case x -> pos.x = (float)p1 * tilesize; case pos -> pos.x = (float)p1 * tilesize;
case y -> pos.y = (float)p1 * tilesize;
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
case rotation -> rotation = (float)p1; case rotation -> rotation = (float)p1;
case textureWidth -> width = (float)p1 * tilesize; case textureSize -> width = (float)p1 * tilesize;
case textureHeight -> height = (float)p1 * tilesize;
case textureSize -> {
width = (float)p1 * tilesize;
height = (float)p2 * tilesize;
}
case color -> color.set(Tmp.c1.fromDouble(p1)); case color -> color.set(Tmp.c1.fromDouble(p1));
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
} }
if(!Double.isNaN(p2)){
switch(type){
case pos -> pos.y = (float)p2 * tilesize;
case textureSize -> height = (float)p2 * tilesize;
default -> super.control(type, p1, p2, p3);
}
}
}
@Override @Override
public void draw(){ public void draw(){
if(hidden || textureName.isEmpty() || minimap) return; if(hidden || textureName.isEmpty() || minimap) return;
+31 -14
View File
@@ -157,18 +157,29 @@ public class LExecutor{
return v.isobj ? v.objval != null : Math.abs(v.numval) >= 0.00001; return v.isobj ? v.objval != null : Math.abs(v.numval) >= 0.00001;
} }
public double num(int index){ @Nullable
public double num(int index, boolean nullToNan){
Var v = var(index); Var v = var(index);
return v.isobj ? v.objval != null ? 1 : 0 : invalid(v.numval) ? 0 : v.numval; return v.isobj ? v.objval != null ? 1 : nullToNan ? Double.NaN : 0: invalid(v.numval) ? 0 : v.numval;
}
public double num(int index){
return num(index, false);
}
@Nullable
public float numf(int index, boolean nullToNan){
Var v = var(index);
return v.isobj ? v.objval != null ? 1 : nullToNan ? Float.NaN : 0: invalid(v.numval) ? 0 : (float)v.numval;
} }
public float numf(int index){ public float numf(int index){
Var v = var(index); return numf(index, false);
return v.isobj ? v.objval != null ? 1 : 0 : invalid(v.numval) ? 0 : (float)v.numval;
} }
@Nullable
public int numi(int index){ public int numi(int index){
return (int)num(index); return (int)num(index, true);
} }
public void setbool(int index, boolean value){ public void setbool(int index, boolean value){
@@ -584,7 +595,8 @@ public class LExecutor{
} }
} }
} }
default -> {} default -> {
}
} }
} }
} }
@@ -605,7 +617,8 @@ public class LExecutor{
this.p4 = p4; this.p4 = p4;
} }
ControlI(){} ControlI(){
}
@Override @Override
public void run(LExecutor exec){ public void run(LExecutor exec){
@@ -852,7 +865,8 @@ public class LExecutor{
this.to = to; this.to = to;
} }
SetI(){} SetI(){
}
@Override @Override
public void run(LExecutor exec){ public void run(LExecutor exec){
@@ -884,7 +898,8 @@ public class LExecutor{
this.dest = dest; this.dest = dest;
} }
OpI(){} OpI(){
}
@Override @Override
public void run(LExecutor exec){ public void run(LExecutor exec){
@@ -919,7 +934,8 @@ public class LExecutor{
public static class NoopI implements LInstruction{ public static class NoopI implements LInstruction{
@Override @Override
public void run(LExecutor exec){} public void run(LExecutor exec){
}
} }
public static class DrawI implements LInstruction{ public static class DrawI implements LInstruction{
@@ -1061,7 +1077,8 @@ public class LExecutor{
this.value = value; this.value = value;
} }
PrintI(){} PrintI(){
}
@Override @Override
public void run(LExecutor exec){ public void run(LExecutor exec){
@@ -1904,7 +1921,7 @@ public class LExecutor{
} }
public static class SetMarkerI implements LInstruction{ public static class SetMarkerI implements LInstruction{
public LMarkerControl type = LMarkerControl.x; public LMarkerControl type = LMarkerControl.pos;
public int id, p1, p2, p3; public int id, p1, p2, p3;
public SetMarkerI(LMarkerControl type, int id, int p1, int p2, int p3){ public SetMarkerI(LMarkerControl type, int id, int p1, int p2, int p3){
@@ -1939,7 +1956,7 @@ public class LExecutor{
marker.setTexture(res.toString()); marker.setTexture(res.toString());
} }
}else{ }else{
marker.control(type, exec.num(p1), exec.num(p2), exec.num(p3)); marker.control(type, exec.num(p1, true), exec.num(p2, true), exec.num(p3, true));
} }
} }
} }
@@ -1971,7 +1988,7 @@ public class LExecutor{
int mid = exec.numi(id); int mid = exec.numi(id);
if(exec.bool(replace) || !state.markers.containsKey(mid)){ if(exec.bool(replace) || !state.markers.containsKey(mid)){
var marker = cons.get(); var marker = cons.get();
marker.control(LMarkerControl.pos, exec.num(x), exec.num(y), 0); marker.control(LMarkerControl.pos, exec.num(x, true), exec.num(y, true), 0);
state.markers.put(mid, marker); state.markers.put(mid, marker);
} }
} }
@@ -5,20 +5,13 @@ public enum LMarkerControl{
visibility("true/false"), visibility("true/false"),
minimap("true/false"), minimap("true/false"),
autoscale("true/false"), autoscale("true/false"),
x("x"),
y("y"),
pos("x", "y"), pos("x", "y"),
endX("x"),
endY("y"),
endPos("x", "y"), endPos("x", "y"),
drawLayer("layer"), drawLayer("layer"),
color("color"), color("color"),
radius("radius"), radius("radius"),
stroke("stroke"), stroke("stroke"),
rotation("rotation"), rotation("rotation"),
shapeSides("sides"),
shapeFill("true/false"),
shapeOutline("true/false"),
shape("sides", "fill", "outline"), shape("sides", "fill", "outline"),
text("text"), text("text"),
flushText, flushText,
@@ -26,8 +19,6 @@ public enum LMarkerControl{
textHeight("height"), textHeight("height"),
labelFlags("background", "outline"), labelFlags("background", "outline"),
texture("name", "-", "-"), texture("name", "-", "-"),
textureWidth("width"),
textureHeight("height"),
textureSize("width", "height"); textureSize("width", "height");
public final String[] params; public final String[] params;
+1 -1
View File
@@ -1945,7 +1945,7 @@ public class LStatements{
@RegisterStatement("setmarker") @RegisterStatement("setmarker")
public static class SetMarkerStatement extends LStatement{ public static class SetMarkerStatement extends LStatement{
public LMarkerControl type = LMarkerControl.x; public LMarkerControl type = LMarkerControl.pos;
public String id = "0", p1 = "0", p2 = "0", p3 = "0"; public String id = "0", p1 = "0", p2 = "0", p3 = "0";
@Override @Override