Skip to content

Commit cd9d0bc

Browse files
author
Bytekeeper
committed
Added descriptions and IT
1 parent 1209976 commit cd9d0bc

File tree

7 files changed

+43
-30
lines changed

7 files changed

+43
-30
lines changed

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ before_script:
2121
- popd
2222
- "[ -f /tmp/sc-docker/starcraft.zip ] || cp sc-docker/scbw/local_docker/starcraft.zip /tmp/sc-docker/starcraft.zip"
2323
- scbw.play --install
24+
- unzip sc-docker/scbw/local_docker/starcraft.zip -d it/openbw/
25+
2426
script:
2527
- sh mvnw clean install
2628
- sh mvnw -f it/bots/pom.xml package
2729
- for bot in $(ls -d it/bots/*/); do BOTNAME=$(basename $bot); echo "Setting up $BOTNAME"; mkdir -p "$HOME/.scbw/bots/$BOTNAME/AI" "$HOME/.scbw/bots/$BOTNAME/read" "$HOME/.scbw/bots/$BOTNAME/write"; cp it/sc-docker-support/BWAPI.dll "$HOME/.scbw/bots/$BOTNAME"; cp "$bot/target/"*-with-dependencies.jar "$HOME/.scbw/bots/$BOTNAME/AI"; cp "$bot/bot.json" "$HOME/.scbw/bots/$BOTNAME"; done
28-
- scbw.play --headless --bots jbwapibot SittingDuck --timeout 180 --docker_image starcraft:game 2>&1 | grep 'Winner is BotPlayer:jbwapibot:T' || (cat $HOME/.scbw/games/*/logs_0/* && false)
30+
- scbw.play --headless --bots jbwapibot SittingDuck --timeout 180 --docker_image starcraft:game 2>&1 | grep 'Winner is BotPlayer:jbwapibot:T' || (cat $HOME/.scbw/games/*/logs_0/* && exit 1)
31+
- pushd it/openbw
32+
- chmod u+x BWAPILauncher
33+
- BWAPI_CONFIG_AUTO_MENU__RACE=Terran BWAPI_CONFIG_AUTO_MENU__MAP=~/.scbw/maps/sscai/\(3\)Neo\ Moon\ Glaive.scx ./BWAPILauncher&
34+
- BWAPI_CONFIG_AUTO_MENU__RACE=Terran BWAPI_CONFIG_AUTO_MENU__MAP=~/.scbw/maps/sscai/\(3\)Neo\ Moon\ Glaive.scx ./BWAPILauncher&
35+
- sleep 1
36+
- java -cp ../bots/SittingDuck/target/SittingDuck-*-jar-with-dependencies.jar SittingDuck &
37+
- java -jar ../bots/jbwapibot/target/MarineHell-*-jar-with-dependencies.jar | grep "Hello from JBWAPI!" || exit 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import bwapi.BWClient;
12
import bwapi.DefaultBWListener;
23

34
public class SittingDuck extends DefaultBWListener {
5+
public static void main(String[] args) {
6+
new BWClient(new SittingDuck()).startGame();
7+
}
48
}

it/openbw/BWAPILauncher

2.42 MB
Binary file not shown.

src/main/java/bwapi/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ boolean connect() {
178178
}
179179

180180
try {
181-
clientConnector.waitForServerReady();
181+
clientConnector.waitForServerData();
182182
} catch (Exception e) {
183183
System.err.println(e.getMessage());
184184
if (bwClient.getConfiguration().getDebugConnection()) {

src/main/java/bwapi/ClientConnection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.io.IOException;
44

5+
/**
6+
* Client - Server connection abstraction
7+
*/
58
interface ClientConnection {
69
void disconnect();
710

@@ -11,8 +14,6 @@ interface ClientConnection {
1114

1215
void connectSharedLock(int serverProcID) throws IOException;
1316

14-
void waitForServerReady() throws IOException;
15-
1617
void waitForServerData() throws IOException;
1718

1819
void submitClientData() throws IOException;

src/main/java/bwapi/ClientConnectionPosix.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
package bwapi;
22

33
import com.sun.jna.LastErrorException;
4+
import com.sun.jna.Library;
45
import com.sun.jna.Native;
56
import com.sun.jna.Pointer;
67
import com.sun.jna.platform.linux.Fcntl;
7-
import com.sun.jna.platform.linux.LibC;
88
import com.sun.jna.platform.linux.LibRT;
9+
import com.sun.jna.platform.unix.LibC;
910
import org.newsclub.net.unix.AFUNIXSocket;
1011
import org.newsclub.net.unix.AFUNIXSocketAddress;
1112

1213
import java.io.File;
1314
import java.io.IOException;
15+
import java.util.function.Supplier;
1416

1517
import static com.sun.jna.platform.linux.Mman.*;
1618

19+
/**
20+
* To be used with OpenBWs BWAPI including server support. At time of writing, only the following fork includes this:
21+
* https://github.com/basil-ladder/openbw
22+
*/
1723
class ClientConnectionPosix implements ClientConnection {
1824
interface LibCExt extends LibC {
1925
LibCExt INSTANCE = Native.load(LibCExt.class);
2026

2127
Pointer mmap(Pointer addr, int length, int prot, int flags, int fd, int offset) throws LastErrorException;
2228
}
2329

30+
interface PosixShm extends Library {
31+
PosixShm INSTANCE = ((Supplier<PosixShm>) (() -> {
32+
// Linux required librt to be loaded, Unix generally does not
33+
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
34+
Native.load("rt", LibRT.class);
35+
}
36+
return Native.load(PosixShm.class);
37+
})).get();
38+
39+
int shm_open(String name, int oflag, int mode);
40+
}
41+
2442
private AFUNIXSocket syncSocket = null;
2543

2644
@Override
@@ -37,7 +55,7 @@ public void disconnect() {
3755

3856
@Override
3957
public WrappedBuffer getGameTable() {
40-
int fd = LibRT.INSTANCE.shm_open("/bwapi_shared_memory_game_list", Fcntl.O_RDWR, 0);
58+
int fd = PosixShm.INSTANCE.shm_open("/bwapi_shared_memory_game_list", Fcntl.O_RDWR, 0);
4159
if (fd < 0) throw new IllegalStateException("SHM not found");
4260
Pointer gameTableView = LibCExt.INSTANCE.mmap(Pointer.NULL, GameTable.SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
4361
return new WrappedBuffer(gameTableView, GameTable.SIZE);
@@ -67,11 +85,6 @@ public void connectSharedLock(int serverProcID) {
6785
}
6886
}
6987

70-
@Override
71-
public void waitForServerReady() {
72-
// NOOP
73-
}
74-
7588
@Override
7689
public void waitForServerData() throws IOException {
7790
while ((syncSocket.getInputStream().read() != 2)) ;

src/main/java/bwapi/ClientConnectionW32.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import java.io.FileNotFoundException;
99
import java.io.IOException;
1010
import java.io.RandomAccessFile;
11-
import java.io.UncheckedIOException;
1211

12+
/**
13+
* Default Windows BWAPI pipe connection with shared memory.
14+
*/
1315
class ClientConnectionW32 implements ClientConnection {
1416
private static final int READ_WRITE = 0x1 | 0x2 | 0x4;
1517

@@ -65,29 +67,13 @@ public void connectSharedLock(int serverProcID) {
6567
}
6668
}
6769

68-
@Override
69-
public void waitForServerReady() throws IOException {
70-
byte code = 1;
71-
while (code != 2) {
72-
try {
73-
code = pipeObjectHandle.readByte();
74-
} catch (IOException e) {
75-
throw new UncheckedIOException("Unable to read pipe object.", e);
76-
}
77-
}
78-
}
79-
8070
@Override
8171
public void waitForServerData() throws IOException {
82-
byte code = 1;
83-
pipeObjectHandle.writeByte(code);
84-
while (code != 2) {
85-
code = pipeObjectHandle.readByte();
86-
}
72+
while (pipeObjectHandle.readByte() != 2) ;
8773
}
8874

8975
@Override
9076
public void submitClientData() throws IOException {
91-
// Noop
77+
pipeObjectHandle.writeByte(1);
9278
}
9379
}

0 commit comments

Comments
 (0)