Skip to content

Commit 486bf4f

Browse files
committed
Restored existing (sync) behavior.
1 parent 0cae24e commit 486bf4f

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

src/main/java/bwapi/BWClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,28 @@ public void startGame(BWClientConfiguration configuration) {
5050
handler = new EventHandler(eventListener, client);
5151

5252
do {
53+
BotWrapper botWrapper;
5354
while (!getGame().isInGame()) {
5455
if (!client.isConnected()) {
5556
return;
5657
}
5758
client.update();
5859
}
60+
botWrapper = new BotWrapper(configuration, client.mapFile(), client.gameData(), handler);
61+
botWrapper.step();
5962
while (getGame().isInGame()) {
6063
client.update();
64+
botWrapper.step();
6165
if (!client.isConnected()) {
6266
System.out.println("Reconnecting...");
6367
client.reconnect();
6468
}
6569
}
70+
71+
// TODO: Before exiting give async bot time to complete onEnd().
72+
6673
} while (configuration.autoContinue); // lgtm [java/constant-loop-condition]
74+
75+
6776
}
6877
}

src/main/java/bwapi/BWClientConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class BWClientConfiguration {
2222
* and some tournaments enforce frame-wise time limits (at time of writing, 55ms for COG and AIIDE; 85ms for SSCAIT).
2323
*
2424
* Asynchronous mode invokes bot event handlers in a separate thread, and if all event handlers haven't returned by a specified period of time, sends an
25-
* returns control to StarCraft, allowing the game to proceed while the bot continues to run in the background. This increases the likelihood of meeting
25+
* returns control to StarCraft, allowing the game to proceed while the bot continues to step in the background. This increases the likelihood of meeting
2626
* real-time performance requirements, while not fully guaranteeing it (subject to the whims of the JVM thread scheduler), at a cost of the bot possibly
2727
* issuing commands later than intended, and a marginally larger memory footprint.
2828
*/

src/main/java/bwapi/BotWrapper.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,35 @@ of this software and associated documentation files (the "Software"), to deal
3131
* Manages invocation of bot event handlers
3232
*/
3333
public class BotWrapper {
34-
private EventHandler eventHandler;
35-
private ByteBuffer sharedMemory;
3634
private BWClientConfiguration configuration;
37-
35+
private ByteBuffer sharedMemory;
36+
private ClientData.GameData gameData;
37+
private EventHandler eventHandler;
3838
private FrameBuffer frameBuffer;
3939

40-
public BotWrapper(ByteBuffer sharedMemory, EventHandler eventHandler, BWClientConfiguration configuration) {
40+
public BotWrapper(
41+
BWClientConfiguration configuration,
42+
ByteBuffer sharedMemory,
43+
ClientData.GameData gameData,
44+
EventHandler eventHandler) {
45+
this.configuration = configuration;
4146
this.sharedMemory = sharedMemory;
47+
this.gameData = gameData;
4248
this.eventHandler = eventHandler;
43-
this.configuration = configuration;
4449

4550
if (configuration.async) {
4651
frameBuffer = new FrameBuffer(configuration.asyncFrameBufferSize);
4752
}
4853
}
4954

50-
public void run() {
55+
public void step() {
5156
if (configuration.async) {
5257
// TODO: Synchronize
5358
frameBuffer.enqueueFrame();
5459
} else {
55-
/*
5660
for (int i = 0; i < gameData.getEventCount(); i++) {
5761
eventHandler.operation(gameData.getEvents(i));
5862
}
59-
*/
6063
}
6164
}
6265
}

src/main/java/bwapi/Client.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ GameData gameData() {
7878
return gameData;
7979
}
8080

81+
ByteBuffer mapFile() {
82+
return mapFileHandle;
83+
}
84+
8185
boolean isConnected() {
8286
return connected;
8387
}

src/main/java/bwapi/Game.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ public int getAPM(final boolean includeSelects) {
22442244

22452245
/**
22462246
* Sets the number of graphical frames for every logical frame. This
2247-
* allows the game to run more logical frames per graphical frame, increasing the speed at
2247+
* allows the game to step more logical frames per graphical frame, increasing the speed at
22482248
* which the game runs.
22492249
*
22502250
* @param frameSkip Number of graphical frames per logical frame. If this value is 0 or less, then it will default to 1.

src/main/java/bwapi/Unit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ public Order getOrder() {
10191019

10201020
/**
10211021
* Retrieves the secondary Order that the unit is assigned. Secondary
1022-
* orders are run in the background as a sub-order. An example would be {@link Order#TrainFighter},
1022+
* orders are step in the background as a sub-order. An example would be {@link Order#TrainFighter},
10231023
* because a @Carrier can move and train fighters at the same time.
10241024
*
10251025
* @return The secondary {@link Order} that the unit is executing.

0 commit comments

Comments
 (0)