Skip to content

Commit 97b6f5d

Browse files
author
Jasper Geurtz
committed
Auto-generate AsyncClientData via DumpToClient, remove SyncClientData, and reuse constants in FrameBuffer
1 parent 4218268 commit 97b6f5d

10 files changed

Lines changed: 395 additions & 356 deletions

File tree

‎src/main/java/bwapi/AsyncClientData.java‎

Lines changed: 108 additions & 161 deletions
Large diffs are not rendered by default.

‎src/main/java/bwapi/BotWrapper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BotWrapper {
2121
*/
2222
void startNewGame(WrappedBuffer liveData, PerformanceMetrics performanceMetrics) {
2323
this.performanceMetrics = performanceMetrics;
24-
botGame = new Game(new SyncClientData());
24+
botGame = new Game();
2525
botGame.setConfiguration(configuration);
2626
botGame.botClientData().setBuffer(liveData);
2727
gameOver = false;

‎src/main/java/bwapi/BotWrapperAsync.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Manages invocation of bot event handlers
77
*/
88
class BotWrapperAsync extends BotWrapper {
9-
private final ClientData liveClientData = new SyncClientData();
9+
private final ClientData liveClientData = new ClientData();
1010
private final FrameBuffer frameBuffer;
1111
private WrappedBuffer liveData;
1212
private Thread botThread;

‎src/main/java/bwapi/Client.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Client {
4545
* For test purposes only
4646
*/
4747
Client(final WrappedBuffer buffer) {
48-
clientData = new SyncClientData();
48+
clientData = new ClientData();
4949
clientData.setBuffer(buffer);
5050
clientConnector = null;
5151
}
@@ -145,7 +145,7 @@ boolean connect() {
145145
return false;
146146
}
147147
try {
148-
clientData = new SyncClientData();
148+
clientData = new ClientData();
149149
clientData.setBuffer(mapShm);
150150
} catch (Exception e) {
151151
System.err.println("Unable to map game data.");

‎src/main/java/bwapi/ClientData.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void setExtra(int value) {
7575
}
7676
class GameData {
7777
static final int SIZE = 33017048;
78-
private int myOffset;
78+
protected int myOffset;
7979
GameData(int myOffset) {
8080
this.myOffset = myOffset;
8181
}

‎src/main/java/bwapi/FrameBuffer.java‎

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,7 @@
1111
* Circular buffer of game states.
1212
*/
1313
class FrameBuffer {
14-
static final int STATICTILES_START = 3447004; // getGroundHeight, isWalkable, isBuildable
15-
static final int STATICTILES_END = 4823260;
16-
static final int REGION_START = 5085404; // getMapTileRegionId, ..., getRegions
17-
static final int REGION_END = 10586480;
18-
static final int STRINGSSHAPES_START = 10962632; // getStringCount, ... getShapes
19-
static final int STRINGSHAPES_END = 32242636;
20-
static final int UNITFINDER_START = 32962644;
21-
22-
static final int DYNAMIC_SLICE1_SIZE = STATICTILES_START; // 3447004
23-
static final int DYNAMIC_SLICE2_SIZE = REGION_START - STATICTILES_END; // 262144
24-
static final int DYNAMIC_SLICE3_SIZE = STRINGSSHAPES_START - REGION_END; // 376152
25-
static final int DYNAMIC_SLICE4_SIZE = UNITFINDER_START - STRINGSHAPES_END; // 720008
26-
27-
static final int DEST_SLICE1_OFFSET = 0;
28-
static final int DEST_SLICE2_OFFSET = DYNAMIC_SLICE1_SIZE; // 3447004
29-
static final int DEST_SLICE3_OFFSET = DEST_SLICE2_OFFSET + DYNAMIC_SLICE2_SIZE; // 3709148
30-
static final int DEST_SLICE4_OFFSET = DEST_SLICE3_OFFSET + DYNAMIC_SLICE3_SIZE; // 4085300
31-
32-
static final int BUFFER_SIZE = DEST_SLICE4_OFFSET + DYNAMIC_SLICE4_SIZE; // 4805308
14+
static final int BUFFER_SIZE = AsyncClientData.BUFFER_SIZE;
3315
private static final Unsafe unsafe = UnsafeTools.getUnsafe();
3416

3517
private WrappedBuffer liveData;
@@ -170,9 +152,9 @@ void dequeue() {
170152
}
171153

172154
void copyBuffer(WrappedBuffer source, WrappedBuffer destination) {
173-
unsafe.copyMemory(source.getAddress() + 0, destination.getAddress() + DEST_SLICE1_OFFSET, DYNAMIC_SLICE1_SIZE);
174-
unsafe.copyMemory(source.getAddress() + STATICTILES_END, destination.getAddress() + DEST_SLICE2_OFFSET, DYNAMIC_SLICE2_SIZE);
175-
unsafe.copyMemory(source.getAddress() + REGION_END, destination.getAddress() + DEST_SLICE3_OFFSET, DYNAMIC_SLICE3_SIZE);
176-
unsafe.copyMemory(source.getAddress() + STRINGSHAPES_END, destination.getAddress() + DEST_SLICE4_OFFSET, DYNAMIC_SLICE4_SIZE);
155+
unsafe.copyMemory(source.getAddress() + 0, destination.getAddress() + AsyncClientData.DEST_SLICE1_OFFSET, AsyncClientData.DYNAMIC_SLICE1_SIZE);
156+
unsafe.copyMemory(source.getAddress() + AsyncClientData.STATICTILES_END, destination.getAddress() + AsyncClientData.DEST_SLICE2_OFFSET, AsyncClientData.DYNAMIC_SLICE2_SIZE);
157+
unsafe.copyMemory(source.getAddress() + AsyncClientData.REGION_END, destination.getAddress() + AsyncClientData.DEST_SLICE3_OFFSET, AsyncClientData.DYNAMIC_SLICE3_SIZE);
158+
unsafe.copyMemory(source.getAddress() + AsyncClientData.STRINGSHAPES_END, destination.getAddress() + AsyncClientData.DEST_SLICE4_OFFSET, AsyncClientData.DYNAMIC_SLICE4_SIZE);
177159
}
178160
}

‎src/main/java/bwapi/Game.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public final class Game {
106106
final SideEffectQueue sideEffects = new SideEffectQueue();
107107

108108
Game() {
109-
this(new SyncClientData());
109+
this(new ClientData());
110110
}
111111

112112
Game(ClientData clientData) {

‎src/main/java/bwapi/SyncClientData.java‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)