Skip to content

Commit 67398b1

Browse files
committed
Merge branch 'develop' into filters
2 parents ad4fdff + a066ea9 commit 67398b1

File tree

18 files changed

+333
-38
lines changed

18 files changed

+333
-38
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Add JBWAPI as a dependecy
3535
<dependency>
3636
<groupId>com.github.JavaBWAPI</groupId>
3737
<artifactId>JBWAPI</artifactId>
38-
<version>0.7.1</version>
38+
<version>0.7.2</version>
3939
</dependency>
4040
```
4141

@@ -53,7 +53,7 @@ allprojects {
5353
Add JBWAPI as a dependency
5454
```
5555
dependencies {
56-
implementation 'com.github.JavaBWAPI:JBWAPI:0.7.1'
56+
implementation 'com.github.JavaBWAPI:JBWAPI:0.7.2'
5757
}
5858
```
5959

@@ -68,6 +68,11 @@ or if you already have maven installed
6868

6969
`mvn package`
7070

71+
## documentation
72+
73+
The api documentation can be found [here](https://javabwapi.github.io/JBWAPI/).
74+
7175
## tutorial
7276

7377
If you are a just starting out with bot development, it might be helpful to follow the [tutorial](https://github.com/JavaBWAPI/Java-BWAPI-Tutorial/wiki)!
78+

it/bots/SittingDuck/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>jbwapi.it</groupId>
1111
<artifactId>bots</artifactId>
12-
<version>0.7.1</version>
12+
<version>0.7.2</version>
1313
</parent>
1414

1515
<artifactId>SittingDuck</artifactId>

it/bots/jbwapibot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>jbwapi.it</groupId>
1111
<artifactId>bots</artifactId>
12-
<version>0.7.1</version>
12+
<version>0.7.2</version>
1313
</parent>
1414

1515
<artifactId>MarineHell</artifactId>

it/bots/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<groupId>jbwapi.it</groupId>
1111
<artifactId>bots</artifactId>
12-
<version>0.7.1</version>
12+
<version>0.7.2</version>
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>jbwapi</groupId>
4545
<artifactId>jbwapi</artifactId>
46-
<version>0.7.1</version>
46+
<version>0.7.2</version>
4747
</dependency>
4848
</dependencies>
4949
</project>

pom.xml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
<groupId>jbwapi</groupId>
88
<artifactId>jbwapi</artifactId>
9-
<version>0.7.1</version>
9+
<version>0.7.2</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<jmh.version>1.21</jmh.version>
1314
</properties>
1415

1516
<build>
@@ -45,6 +46,30 @@
4546
</execution>
4647
</executions>
4748
</plugin>
49+
<plugin>
50+
<groupId>org.codehaus.mojo</groupId>
51+
<artifactId>exec-maven-plugin</artifactId>
52+
<version>1.6.0</version>
53+
<executions>
54+
<execution>
55+
<id>run-benchmarks</id>
56+
<phase>integration-test</phase>
57+
<goals>
58+
<goal>exec</goal>
59+
</goals>
60+
<configuration>
61+
<classpathScope>test</classpathScope>
62+
<executable>java</executable>
63+
<arguments>
64+
<argument>-classpath</argument>
65+
<classpath/>
66+
<argument>org.openjdk.jmh.Main</argument>
67+
<argument>.*</argument>
68+
</arguments>
69+
</configuration>
70+
</execution>
71+
</executions>
72+
</plugin>
4873
</plugins>
4974
</build>
5075

@@ -86,5 +111,20 @@
86111
<version>3.12.2</version>
87112
<scope>test</scope>
88113
</dependency>
114+
115+
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh -->
116+
<dependency>
117+
<groupId>org.openjdk.jmh</groupId>
118+
<artifactId>jmh-core</artifactId>
119+
<version>${jmh.version}</version>
120+
<scope>test</scope>
121+
</dependency>
122+
123+
<dependency>
124+
<groupId>org.openjdk.jmh</groupId>
125+
<artifactId>jmh-generator-annprocess</artifactId>
126+
<version>${jmh.version}</version>
127+
<scope>test</scope>
128+
</dependency>
89129
</dependencies>
90130
</project>

src/main/java/bwapi/Client.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Client {
4545
+ 4 // LastKeepAliveTime
4646
;
4747
private static final List<Integer> SUPPORTED_BWAPI_VERSIONS = Arrays.asList(10003);
48-
private static final int MAX_COUNT = 19999;
48+
static final int MAX_COUNT = 19999;
4949

5050
private static final int maxNumGames = 8;
5151
private static final int gameTableSize = GAME_SIZE * maxNumGames;
@@ -71,6 +71,13 @@ class Client {
7171
throw new Exception("All servers busy!");
7272
}
7373

74+
/**
75+
* For test purposes only
76+
*/
77+
Client(ByteBuffer buffer) {
78+
data = new ClientData(buffer).new GameData(0);
79+
}
80+
7481
public GameData data() {
7582
return data;
7683
}

src/main/java/bwapi/Color.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ public class Color {
5454
RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, new RGBQUAD(255, 255, 255)
5555
};
5656

57-
private static boolean rgbInitialized;
5857
private static final byte[][][] closestColor = new byte[64][64][64];
58+
static {
59+
for (int r = 0; r < 64; ++r) {
60+
for (int g = 0; g < 64; ++g) {
61+
for (int b = 0; b < 64; ++b) {
62+
closestColor[r][g][b] = (byte) getBestIdFor(r << 2, g << 2, b << 2);
63+
}
64+
}
65+
}
66+
}
5967
public final int id;
6068

6169
public Color(final int r, final int g, final int b) {
@@ -92,16 +100,6 @@ private static int getBestIdFor(final int red, final int green, final int blue)
92100
}
93101

94102
private static int getRGBIndex(final int red, final int green, final int blue) {
95-
if (!rgbInitialized) {
96-
rgbInitialized = true;
97-
for (int r = 0; r < 64; ++r) {
98-
for (int g = 0; g < 64; ++g) {
99-
for (int b = 0; b < 64; ++b) {
100-
closestColor[r][g][b] = (byte) getBestIdFor(r << 2, g << 2, b << 2);
101-
}
102-
}
103-
}
104-
}
105103
return closestColor[(byte) (red >> 2)][(byte) (green >> 2)][(byte) (blue >> 2)];
106104
}
107105

src/main/java/bwapi/TechType.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ public enum TechType {
5050

5151
/// IMPLEMENTATION
5252
private static final int[] defaultOreCost = // Same as default gas cost
53-
{100, 200, 200, 100, 0, 150, 0, 200, 100, 150, 100, 100, 0, 100, 0, 200, 100, 100, 0, 200, 150, 150, 150, 0, 100, 200, 0, 200, 0, 100, 100, 100, 200};
53+
{100, 200, 200, 100, 0, 150, 0, 200, 100, 150, 100, 100, 0, 100, 0, 200, 100, 100, 0, 200, 150, 150, 150, 0,
54+
100, 200, 0, 200, 0, 100, 100, 100, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
5455
private static final int[] defaultTimeCost =
55-
{1200, 1500, 1800, 1200, 0, 1200, 0, 1200, 1800, 1500, 1200, 1200, 0, 1200, 0, 1500, 1500, 1200, 0, 1800, 1200, 1800, 1500, 0, 1200, 1200, 0, 1800, 0, 1800, 1800, 1500, 1800};
56+
{1200, 1500, 1800, 1200, 0, 1200, 0, 1200, 1800, 1500, 1200, 1200, 0, 1200, 0, 1500, 1500, 1200, 0, 1800,
57+
1200, 1800, 1500, 0, 1200, 1200, 0, 1800, 0, 1800, 1800, 1500, 1800, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58+
0, 0, 0, 0};
5659
private static final int[] defaultEnergyCost =
57-
{0, 100, 100, 0, 50, 0, 100, 75, 150, 25, 25, 0, 0, 150, 100, 150, 0, 75, 75, 75, 100, 150, 100, 0, 50, 125, 0, 150, 0, 50, 75, 100, 0, 0, 1};
60+
{0, 100, 100, 0, 50, 0, 100, 75, 150, 25, 25, 0, 0, 150, 100, 150, 0, 75, 75, 75, 100, 150, 100, 0, 50, 125,
61+
0, 150, 0, 50, 75, 100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
5862
private static final UnitType[] whatResearches = {
5963
UnitType.Terran_Academy, UnitType.Terran_Covert_Ops, UnitType.Terran_Science_Facility, UnitType.Terran_Machine_Shop,
6064
UnitType.None, UnitType.Terran_Machine_Shop, UnitType.None, UnitType.Terran_Science_Facility, UnitType.Terran_Physics_Lab,
@@ -87,7 +91,7 @@ public enum TechType {
8791
0, TARG_UNIT, TARG_BOTH, TARG_POS, TARG_BOTH, 0, TARG_UNIT, TARG_UNIT, TARG_UNIT, 0, 0, 0,
8892
TARG_UNIT, TARG_UNIT, TARG_BOTH, TARG_BOTH, TARG_UNIT, TARG_BOTH, TARG_UNIT, TARG_BOTH, TARG_UNIT,
8993
TARG_BOTH, TARG_BOTH, TARG_UNIT, TARG_UNIT, TARG_BOTH, 0, TARG_UNIT, TARG_UNIT, TARG_UNIT, TARG_UNIT,
90-
TARG_BOTH, 0, 0, TARG_BOTH, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TARG_BOTH
94+
TARG_BOTH, 0, 0, TARG_BOTH, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TARG_BOTH, 0
9195
};
9296
private static final Order[] techOrders = {
9397
Order.None, CastLockdown, CastEMPShockwave, PlaceMine, CastScannerSweep, Order.None, CastDefensiveMatrix,

src/main/java/bwapi/TextColor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static String formatText(final String text, final TextColor format) {
4848
}
4949

5050
//SINCE 4.2
51-
//C hecks if the given character is a color-changing control code.
51+
//C checks if the given character is a color-changing control code.
5252
boolean isColor() {
5353
final int c = this.id;
5454
return (2 <= c && c <= 8) || (14 <= c && c <= 17) || (21 <= c && c <= 31);

src/main/java/bwapi/WrappedBuffer.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* Wrapper around ByteBuffer that makes use of sun.misc.Unsafe if available.
1515
*/
1616
class WrappedBuffer {
17-
private static final Charset charSet = StandardCharsets.ISO_8859_1;
18-
private static final CharsetEncoder enc = charSet.newEncoder();
19-
2017
private final ByteBuffer buffer;
2118
private final long address;
2219
private final Unsafe unsafe;
@@ -72,23 +69,26 @@ void putDouble(final int offset, final double value) {
7269
}
7370

7471
String getString(final int offset, final int maxLen) {
75-
final byte[] buf = new byte[maxLen];
76-
77-
unsafe.copyMemory(null, address + offset, buf, Unsafe.ARRAY_BYTE_BASE_OFFSET, maxLen);
78-
79-
int len = 0;
80-
while (len < maxLen && buf[len] != 0) {
81-
++len;
72+
char[] buf = new char[maxLen];
73+
long pos = offset + address;
74+
for (int i = 0; i < maxLen; i++) {
75+
byte b = unsafe.getByte(pos);
76+
if (b == 0) break;
77+
buf[i] = (char) (b & 0xff);
78+
pos++;
8279
}
83-
return new String(buf, 0, len, charSet);
80+
return new String(buf, 0, (int) (pos - offset - address));
8481
}
8582

8683
void putString(final int offset, final int maxLen, final String string) {
8784
if (string.length() + 1 >= maxLen) {
8885
throw new StringIndexOutOfBoundsException();
8986
}
90-
buffer.position(offset);
91-
enc.encode(CharBuffer.wrap(string), buffer, true);
92-
buffer.put((byte) 0);
87+
long pos = offset + address;
88+
for (int i = 0; i < string.length(); i++) {
89+
unsafe.putByte(pos, (byte) string.charAt(i));
90+
pos++;
91+
}
92+
unsafe.putByte(pos, (byte) 0);
9393
}
9494
}

0 commit comments

Comments
 (0)