Skip to content

Commit 5c2212d

Browse files
committed
merge develop
2 parents bc54ecd + a066ea9 commit 5c2212d

File tree

18 files changed

+333
-39
lines changed

18 files changed

+333
-39
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 & 2 deletions
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>
@@ -50,12 +51,35 @@
5051
<artifactId>maven-site-plugin</artifactId>
5152
<version>3.7.1</version>
5253
</plugin>
53-
5454
<plugin>
5555
<groupId>org.apache.maven.plugins</groupId>
5656
<artifactId>maven-project-info-reports-plugin</artifactId>
5757
<version>3.0.0</version>
5858
</plugin>
59+
<plugin>
60+
<groupId>org.codehaus.mojo</groupId>
61+
<artifactId>exec-maven-plugin</artifactId>
62+
<version>1.6.0</version>
63+
<executions>
64+
<execution>
65+
<id>run-benchmarks</id>
66+
<phase>integration-test</phase>
67+
<goals>
68+
<goal>exec</goal>
69+
</goals>
70+
<configuration>
71+
<classpathScope>test</classpathScope>
72+
<executable>java</executable>
73+
<arguments>
74+
<argument>-classpath</argument>
75+
<classpath/>
76+
<argument>org.openjdk.jmh.Main</argument>
77+
<argument>.*</argument>
78+
</arguments>
79+
</configuration>
80+
</execution>
81+
</executions>
82+
</plugin>
5983
</plugins>
6084
</build>
6185

@@ -111,5 +135,20 @@
111135
<version>3.12.2</version>
112136
<scope>test</scope>
113137
</dependency>
138+
139+
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh -->
140+
<dependency>
141+
<groupId>org.openjdk.jmh</groupId>
142+
<artifactId>jmh-core</artifactId>
143+
<version>${jmh.version}</version>
144+
<scope>test</scope>
145+
</dependency>
146+
147+
<dependency>
148+
<groupId>org.openjdk.jmh</groupId>
149+
<artifactId>jmh-generator-annprocess</artifactId>
150+
<version>${jmh.version}</version>
151+
<scope>test</scope>
152+
</dependency>
114153
</dependencies>
115154
</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
@@ -62,8 +62,16 @@ public class Color {
6262
RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, new RGBQUAD(255, 255, 255)
6363
};
6464

65-
private static boolean rgbInitialized;
6665
private static final byte[][][] closestColor = new byte[64][64][64];
66+
static {
67+
for (int r = 0; r < 64; ++r) {
68+
for (int g = 0; g < 64; ++g) {
69+
for (int b = 0; b < 64; ++b) {
70+
closestColor[r][g][b] = (byte) getBestIdFor(r << 2, g << 2, b << 2);
71+
}
72+
}
73+
}
74+
}
6775
public final int id;
6876

6977
/**
@@ -115,16 +123,6 @@ private static int getBestIdFor(final int red, final int green, final int blue)
115123
}
116124

117125
private static int getRGBIndex(final int red, final int green, final int blue) {
118-
if (!rgbInitialized) {
119-
rgbInitialized = true;
120-
for (int r = 0; r < 64; ++r) {
121-
for (int g = 0; g < 64; ++g) {
122-
for (int b = 0; b < 64; ++b) {
123-
closestColor[r][g][b] = (byte) getBestIdFor(r << 2, g << 2, b << 2);
124-
}
125-
}
126-
}
127-
}
128126
return closestColor[(byte) (red >> 2)][(byte) (green >> 2)][(byte) (blue >> 2)];
129127
}
130128

src/main/java/bwapi/TechType.java

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

5555
/// IMPLEMENTATION
5656
private static final int[] defaultOreCost = // Same as default gas cost
57-
{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};
57+
{100, 200, 200, 100, 0, 150, 0, 200, 100, 150, 100, 100, 0, 100, 0, 200, 100, 100, 0, 200, 150, 150, 150, 0,
58+
100, 200, 0, 200, 0, 100, 100, 100, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
5859
private static final int[] defaultTimeCost =
59-
{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};
60+
{1200, 1500, 1800, 1200, 0, 1200, 0, 1200, 1800, 1500, 1200, 1200, 0, 1200, 0, 1500, 1500, 1200, 0, 1800,
61+
1200, 1800, 1500, 0, 1200, 1200, 0, 1800, 0, 1800, 1800, 1500, 1800, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62+
0, 0, 0, 0};
6063
private static final int[] defaultEnergyCost =
61-
{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};
64+
{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,
65+
0, 150, 0, 50, 75, 100, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
6266
private static final UnitType[] whatResearches = {
6367
UnitType.Terran_Academy, UnitType.Terran_Covert_Ops, UnitType.Terran_Science_Facility, UnitType.Terran_Machine_Shop,
6468
UnitType.None, UnitType.Terran_Machine_Shop, UnitType.None, UnitType.Terran_Science_Facility, UnitType.Terran_Physics_Lab,
@@ -91,7 +95,7 @@ public enum TechType {
9195
0, TARG_UNIT, TARG_BOTH, TARG_POS, TARG_BOTH, 0, TARG_UNIT, TARG_UNIT, TARG_UNIT, 0, 0, 0,
9296
TARG_UNIT, TARG_UNIT, TARG_BOTH, TARG_BOTH, TARG_UNIT, TARG_BOTH, TARG_UNIT, TARG_BOTH, TARG_UNIT,
9397
TARG_BOTH, TARG_BOTH, TARG_UNIT, TARG_UNIT, TARG_BOTH, 0, TARG_UNIT, TARG_UNIT, TARG_UNIT, TARG_UNIT,
94-
TARG_BOTH, 0, 0, TARG_BOTH, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TARG_BOTH
98+
TARG_BOTH, 0, 0, TARG_BOTH, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TARG_BOTH, 0
9599
};
96100
private static final Order[] techOrders = {
97101
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)