Skip to content

Commit aacde75

Browse files
committed
fix draw bugs
1 parent 8fff919 commit aacde75

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/main/java/JavaBWAPIBackend/Client.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ public Command(int type, int value1, int value2) {
4444
}
4545

4646
public static class Shape {
47-
final int type, coordType, x1, y1, x2, y2, extra1, extra2, color, isSolid;
47+
final int type, coordType, x1, y1, x2, y2, extra1, extra2, color;
48+
final byte isSolid;
4849

49-
public Shape(int type, int coordType, int x1, int y1, int x2, int y2, int extra1, int extra2, int color, int isSolid) {
50+
public Shape(int type, int coordType, int x1, int y1, int x2, int y2, int extra1, int extra2, int color, boolean isSolid) {
5051
this.type = type;
5152
this.coordType = coordType;
5253
this.x1 = x1;
@@ -56,7 +57,7 @@ public Shape(int type, int coordType, int x1, int y1, int x2, int y2, int extra1
5657
this.extra1 = extra1;
5758
this.extra2 = extra2;
5859
this.color = color;
59-
this.isSolid = isSolid;
60+
this.isSolid = (byte)(isSolid ? 1 : 0);
6061
}
6162
private static final int SIZE = 40;
6263
}
@@ -460,7 +461,8 @@ public void addShape(Shape shape) {
460461
sharedMemory.putInt(ShapeOffset + at * Shape.SIZE + 24, shape.y2);
461462
sharedMemory.putInt(ShapeOffset + at * Shape.SIZE + 28, shape.extra1);
462463
sharedMemory.putInt(ShapeOffset + at * Shape.SIZE + 32, shape.extra2);
463-
sharedMemory.putInt(ShapeOffset + at * Shape.SIZE + 36, shape.isSolid);
464+
sharedMemory.putInt(ShapeOffset + at * Shape.SIZE + 36, shape.color);
465+
sharedMemory.put(ShapeOffset + at * Shape.SIZE + 40, shape.isSolid);
464466
sharedMemory.putInt(ShapeOffset, at + 1);
465467
}
466468

src/main/java/bwapi/Game.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void addCommand(final int type, final int value1, final int value2) {
111111
gameData.addCommand(new Client.Command(type, value1, value2));
112112
}
113113

114-
void addShape(final int type, final int coordType, final int x1, final int y1, final int x2, final int y2, final int extra1, final int extra2, final int color, final int isSolid) {
114+
void addShape(final int type, final int coordType, final int x1, final int y1, final int x2, final int y2, final int extra1, final int extra2, final int color, final boolean isSolid) {
115115
gameData.addShape(new Client.Shape(type, coordType, x1, y1, x2, y2, extra1, extra2, color, isSolid));
116116
}
117117

@@ -689,7 +689,7 @@ public Set<Player> observers() {
689689
//if someone implements the textSize stuff, replace TextSize.Default with getTextSize
690690
public void drawText(final Coordinate ctype, final int x, final int y, final String cstr_format) {
691691
final int stringId = gameData.addString(cstr_format);
692-
addShape(Shape.Text.value, ctype.value, x, y, 0,0, stringId, TextSize.Default.value,0,0);
692+
addShape(Shape.Text.value, ctype.value, x, y, 0,0, stringId, TextSize.Default.value,0,false);
693693
}
694694

695695

@@ -724,7 +724,7 @@ public void drawBox(final Coordinate ctype, final int left, final int top, final
724724
}
725725

726726
public void drawBox(final Coordinate ctype, final int left, final int top, final int right, final int bottom, final Color color, final boolean isSolid) {
727-
addShape(ctype.value, Shape.Box.value, left, top, right, bottom, 0,0, color.id, isSolid ? 1 : 0);
727+
addShape(Shape.Box.value, ctype.value, left, top, right, bottom, 0,0, color.id, isSolid);
728728
}
729729

730730
public void drawBoxMap(int left, int top, int right, int bottom, Color color) {
@@ -775,13 +775,12 @@ public void drawBoxScreen(Position leftTop, Position rightBottom, Color color, b
775775
drawBox(Coordinate.Screen, leftTop.x, leftTop.y, rightBottom.x, rightBottom.y, color, isSolid);
776776
}
777777

778-
779778
public void drawTriangle(Coordinate ctype, int ax, int ay, int bx, int by, int cx, int cy, Color color) {
780779
drawTriangle(ctype, ax, ay, bx, by, cx, cy, color, false);
781780
}
782781

783782
public void drawTriangle(Coordinate ctype, int ax, int ay, int bx, int by, int cx, int cy, Color color, boolean isSolid) {
784-
addShape(ctype.value, Shape.Triangle.value, ax, ay, bx, by, cx, cy, color.id, isSolid ? 1 : 0);
783+
addShape(Shape.Triangle.value, ctype.value, ax, ay, bx, by, cx, cy, color.id, isSolid);
785784
}
786785

787786
public void drawTriangleMap(int ax, int ay, int bx, int by, int cx, int cy, Color color) {
@@ -833,13 +832,12 @@ public void drawTriangleScreen(Position a, Position b, Position c, Color color,
833832
drawTriangle(Coordinate.Screen, a.x, a.y, b.x, b.y, c.x, c.y, color, isSolid);
834833
}
835834

836-
837835
public void drawCircle(Coordinate ctype, int x, int y, int radius, Color color) {
838836
drawCircle(ctype, x, y, radius, color, false);
839837
}
840838

841839
public void drawCircle(Coordinate ctype, int x, int y, int radius, Color color, boolean isSolid) {
842-
addShape(Shape.Circle.value, ctype.value, x ,y,0,0, radius,0, color.id, isSolid ? 1 : 0);
840+
addShape(Shape.Circle.value, ctype.value, x ,y,0,0, radius,0, color.id, isSolid);
843841
}
844842

845843
public void drawCircleMap(int x, int y, int radius, Color color) {
@@ -890,13 +888,12 @@ public void drawCircleScreen(Position p, int radius, Color color, boolean isSoli
890888
drawCircle(Coordinate.Screen, p.x, p.y, radius, color, isSolid);
891889
}
892890

893-
894891
public void drawEllipse(Coordinate ctype, int x, int y, int xrad, int yrad, Color color) {
895892
drawEllipse(ctype,x, y, xrad, yrad, color, false);
896893
}
897894

898895
public void drawEllipse(Coordinate ctype, int x, int y, int xrad, int yrad, Color color, boolean isSolid) {
899-
addShape(Shape.Ellipse.value, ctype.value, x, y,0,0, xrad, yrad, color.id, isSolid ? 1 : 0);
896+
addShape(Shape.Ellipse.value, ctype.value, x, y, 0, 0, xrad, yrad, color.id, isSolid);
900897
}
901898

902899
public void drawEllipseMap(int x, int y, int xrad, int yrad, Color color) {
@@ -948,7 +945,7 @@ public void drawEllipseScreen(Position p, int xrad, int yrad, Color color, boole
948945
}
949946

950947
public void drawDot(Coordinate ctype, int x, int y, Color color) {
951-
addShape(Shape.Dot.value, ctype.value, x, y, 0, 0, 0, 0, color.id, 0);
948+
addShape(Shape.Dot.value, ctype.value, x, y, 0, 0, 0, 0, color.id, false);
952949
}
953950

954951
public void drawDotMap(int x, int y, Color color) {
@@ -976,7 +973,7 @@ public void drawDotScreen(Position p, Color color) {
976973
}
977974

978975
public void drawLine(Coordinate ctype, int x1, int y1, int x2, int y2, Color color) {
979-
addShape(Shape.Line.value, ctype.value, x1, y1, x2, y2, 0, 0, color.id, 0);
976+
addShape(Shape.Line.value, ctype.value, x1, y1, x2, y2, 0, 0, color.id, false);
980977
}
981978

982979
public void drawLineMap(int x1, int y1, int x2, int y2, Color color) {

src/test/java/game/DrawTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import bwapi.BWClient;
44
import bwapi.DefaultBWListener;
55
import bwapi.Game;
6+
import bwapi.point.Position;
67
import bwapi.values.Color;
78

89
class DrawTest extends DefaultBWListener {
@@ -21,10 +22,16 @@ public void onStart() {
2122

2223
@Override
2324
public void onFrame() {
24-
Color color = Color.Purple;
25-
26-
game.drawCircleScreen(200, 200, 10, color);
2725
game.drawTextScreen(50, 50, "frame: " + game.getFrameCount());
26+
27+
28+
game.drawCircleScreen(200, 110, 80, Color.Purple, true);
29+
game.drawCircleScreen(350, 110, 80, Color.Purple, true);
30+
31+
game.drawTriangleScreen(143, 167,407, 167, 275, 350, Color.Purple, true);
32+
33+
game.drawBoxScreen(200, 110, 350, 210, Color.Purple, true);
34+
2835
}
2936

3037
public static void main(String[] args) {

0 commit comments

Comments
 (0)