Skip to content

Commit 4bbef45

Browse files
committed
Merged jdk9 fixes into async branch
2 parents 30d6792 + 137254e commit 4bbef45

21 files changed

+992
-970
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ target/
88
.classpath
99
.project
1010

11+
# logging
12+
*.log

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ before_script:
1313
- git clone https://github.com/Bytekeeper/sc-docker.git
1414
- cp it/sc-docker-support/*.dockerfile sc-docker/docker/dockerfiles
1515
- pushd sc-docker
16+
- pip3 install numpy==1.16.6
1617
- python3 setup.py bdist_wheel
1718
- pip3 install dist/scbw*.whl
1819
- '[ ! -f /tmp/sc-docker/starcraft.zip ] || (cp /tmp/sc-docker/starcraft.zip scbw/local_docker && echo "Using cached starcraft.zip")'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Add JBWAPI to your dependencies in `<dependencies></dependencies>`:
3838
<dependency>
3939
<groupId>com.github.JavaBWAPI</groupId>
4040
<artifactId>JBWAPI</artifactId>
41-
<version>1.5</version>
41+
<version>1.5.1</version>
4242
</dependency>
4343
```
4444

@@ -56,7 +56,7 @@ allprojects {
5656
Add JBWAPI as a dependency:
5757
```
5858
dependencies {
59-
implementation 'com.github.JavaBWAPI:JBWAPI:1.5'
59+
implementation 'com.github.JavaBWAPI:JBWAPI:1.5.1'
6060
}
6161
```
6262

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>1.5</version>
12+
<version>1.5.1</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>1.5</version>
12+
<version>1.5.1</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>1.5</version>
12+
<version>1.5.1</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>1.5</version>
46+
<version>1.5.1</version>
4747
</dependency>
4848
</dependencies>
4949
</project>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>jbwapi</groupId>
88
<artifactId>jbwapi</artifactId>
9-
<version>1.5</version>
9+
<version>1.5.1</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/bwapi/BotWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BotWrapper {
1111
private final BWClientConfiguration configuration;
1212
private final BWEventListener eventListener;
1313
private final FrameBuffer frameBuffer;
14-
private ByteBuffer liveData;
14+
private WrappedBuffer liveData;
1515
private Game botGame;
1616
private Thread botThread;
1717
private boolean gameOver;
@@ -30,7 +30,7 @@ class BotWrapper {
3030
/**
3131
* Resets the BotWrapper for a new botGame.
3232
*/
33-
void startNewGame(ByteBuffer liveData, PerformanceMetrics performanceMetrics) {
33+
void startNewGame(WrappedBuffer liveData, PerformanceMetrics performanceMetrics) {
3434
if (configuration.getAsync()) {
3535
frameBuffer.initialize(liveData, performanceMetrics);
3636
}

src/main/java/bwapi/Client.java

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ of this software and associated documentation files (the "Software"), to deal
2525

2626
package bwapi;
2727

28-
import bwapi.ClientData.GameData;
2928
import com.sun.jna.Native;
29+
import com.sun.jna.Pointer;
3030
import com.sun.jna.platform.win32.Kernel32;
3131
import com.sun.jna.win32.W32APIOptions;
3232

3333
import java.io.RandomAccessFile;
34-
import java.nio.ByteBuffer;
35-
import java.nio.ByteOrder;
3634

3735
class Client {
3836
interface MappingKernel extends Kernel32 {
@@ -48,8 +46,8 @@ interface MappingKernel extends Kernel32 {
4846
private BWClient bwClient;
4947
private boolean connected = false;
5048
private RandomAccessFile pipeObjectHandle = null;
51-
private ByteBuffer gameTableFileHandle = null;
52-
private ByteBuffer mapFileHandle = null;
49+
private WrappedBuffer gameTableFileHandle = null;
50+
private WrappedBuffer mapFileHandle = null;
5351

5452
Client(BWClient bwClient) {
5553
this.bwClient = bwClient;
@@ -58,7 +56,7 @@ interface MappingKernel extends Kernel32 {
5856
/**
5957
* For test purposes only
6058
*/
61-
Client(ByteBuffer buffer) {
59+
Client(final WrappedBuffer buffer) {
6260
clientData = new ClientData();
6361
clientData.setBuffer(buffer);
6462
}
@@ -67,7 +65,7 @@ ClientData liveClientData() {
6765
return clientData;
6866
}
6967

70-
ByteBuffer mapFile() {
68+
WrappedBuffer mapFile() {
7169
return mapFileHandle;
7270
}
7371

@@ -90,11 +88,10 @@ private void disconnect() {
9088
return;
9189
}
9290

93-
if (pipeObjectHandle != null ) {
91+
if (pipeObjectHandle != null) {
9492
try {
9593
pipeObjectHandle.close();
96-
}
97-
catch (Exception e) {
94+
} catch (Exception e) {
9895
e.printStackTrace();
9996
}
10097
pipeObjectHandle = null;
@@ -117,21 +114,19 @@ boolean connect() {
117114

118115
// Expose the BWAPI list of games from shared memory via a ByteBuffer
119116
try {
120-
gameTableFileHandle = Kernel32.INSTANCE.MapViewOfFile(
121-
MappingKernel.INSTANCE.OpenFileMapping(READ_WRITE, false, "Local\\bwapi_shared_memory_game_list"), READ_WRITE, 0, 0, GameTable.SIZE)
122-
.getByteBuffer(0, GameTable.SIZE);
123-
gameTableFileHandle.order(ByteOrder.LITTLE_ENDIAN);
124-
}
125-
catch (Exception e) {
117+
final Pointer gameTableView = Kernel32.INSTANCE.MapViewOfFile(MappingKernel.INSTANCE
118+
.OpenFileMapping(READ_WRITE, false, "Local\\bwapi_shared_memory_game_list"), READ_WRITE,
119+
0, 0, GameTable.SIZE);
120+
gameTableFileHandle = new WrappedBuffer(gameTableView, GameTable.SIZE);
121+
} catch (Exception e) {
126122
System.err.println("Game table mapping not found.");
127123
return false;
128124
}
129125

130126
GameTable gameTable;
131127
try {
132128
gameTable = new GameTable(gameTableFileHandle);
133-
}
134-
catch (Exception e) {
129+
} catch (Exception e) {
135130
System.err.println("Unable to map Game table.");
136131
if (bwClient.getConfiguration().getDebugConnection()) {
137132
e.printStackTrace();
@@ -140,11 +135,11 @@ boolean connect() {
140135
}
141136

142137
int latest = 0;
143-
for(int i = 0; i < GameTable.MAX_GAME_INSTANCES; i++) {
138+
for (int i = 0; i < GameTable.MAX_GAME_INSTANCES; i++) {
144139
GameInstance gameInstance = gameTable.gameInstances[i];
145140
System.out.println(i + " | " + gameInstance.serverProcessID + " | " + (gameInstance.isConnected ? 1 : 0) + " | " + gameInstance.lastKeepAliveTime);
146141
if (gameInstance.serverProcessID != 0 && !gameInstance.isConnected) {
147-
if ( gameTableIndex == -1 || latest == 0 || gameInstance.lastKeepAliveTime < latest ) {
142+
if (gameTableIndex == -1 || latest == 0 || gameInstance.lastKeepAliveTime < latest) {
148143
latest = gameInstance.lastKeepAliveTime;
149144
gameTableIndex = i;
150145
}
@@ -163,9 +158,8 @@ boolean connect() {
163158
final String sharedMemoryName = "Local\\bwapi_shared_memory_" + serverProcID;
164159
final String communicationPipe = "\\\\.\\pipe\\bwapi_pipe_" + serverProcID;
165160
try {
166-
pipeObjectHandle = new RandomAccessFile(communicationPipe, "rw");
167-
}
168-
catch (Exception e) {
161+
pipeObjectHandle = new RandomAccessFile(communicationPipe, "rw");
162+
} catch (Exception e) {
169163
System.err.println("Unable to open communications pipe: " + communicationPipe);
170164
if (bwClient.getConfiguration().getDebugConnection()) {
171165
e.printStackTrace();
@@ -177,11 +171,11 @@ boolean connect() {
177171

178172
// Expose the raw game data from shared memory via a ByteBuffer
179173
try {
180-
mapFileHandle = Kernel32.INSTANCE.MapViewOfFile(MappingKernel.INSTANCE
174+
final Pointer mapFileView = Kernel32.INSTANCE.MapViewOfFile(MappingKernel.INSTANCE
181175
.OpenFileMapping(READ_WRITE, false, sharedMemoryName), READ_WRITE,
182-
0, 0, GameData.SIZE).getByteBuffer(0, GameData.SIZE);
183-
}
184-
catch (Exception e) {
176+
0, 0, ClientData.GameData.SIZE);
177+
mapFileHandle = new WrappedBuffer(mapFileView, ClientData.GameData.SIZE);
178+
} catch (Exception e) {
185179
System.err.println("Unable to open shared memory mapping: " + sharedMemoryName);
186180
if (bwClient.getConfiguration().getDebugConnection()) {
187181
e.printStackTrace();
@@ -214,8 +208,7 @@ boolean connect() {
214208
while (code != 2) {
215209
try {
216210
code = pipeObjectHandle.readByte();
217-
}
218-
catch (Exception e) {
211+
} catch (Exception e) {
219212
System.err.println("Unable to read pipe object.");
220213
if (bwClient.getConfiguration().getDebugConnection()) {
221214
e.printStackTrace();
@@ -279,6 +272,7 @@ void sendFrameReceiveFrame() {
279272
break;
280273
}
281274
}
275+
282276
metrics.getCommunicationListenToReceive().stopTiming();
283277
metrics.getCommunicationSendToReceive().stopTiming();
284278

@@ -298,8 +292,7 @@ void sendFrameReceiveFrame() {
298292
private void sleep(final int millis) {
299293
try {
300294
Thread.sleep(millis);
301-
}
302-
catch (Exception ignored) {
295+
} catch (Exception ignored) {
303296
}
304297
}
305298
}

0 commit comments

Comments
 (0)