@@ -45,15 +45,14 @@ interface MappingKernel extends Kernel32 {
4545 private static final int SUPPORTED_BWAPI_VERSION = 10003 ;
4646
4747 private ClientData clientData ;
48+ private BWClient bwClient ;
4849 private boolean connected = false ;
4950 private RandomAccessFile pipeObjectHandle = null ;
5051 private ByteBuffer gameTableFileHandle = null ;
5152 private ByteBuffer mapFileHandle = null ;
5253
53- private BWClientConfiguration configuration = new BWClientConfiguration ();
54-
55- Client (BWClientConfiguration configuration ) {
56- this .configuration = configuration ;
54+ Client (BWClient bwClient ) {
55+ this .bwClient = bwClient ;
5756 }
5857
5958 /**
@@ -83,7 +82,7 @@ void reconnect() {
8382 }
8483
8584 private void disconnect () {
86- if (configuration .debugConnection ) {
85+ if (bwClient . getConfiguration () .debugConnection ) {
8786 System .err .print ("Disconnect called by: " );
8887 System .err .println (Thread .currentThread ().getStackTrace ()[2 ]);
8988 }
@@ -134,7 +133,7 @@ boolean connect() {
134133 }
135134 catch (Exception e ) {
136135 System .err .println ("Unable to map Game table." );
137- if (configuration .debugConnection ) {
136+ if (bwClient . getConfiguration () .debugConnection ) {
138137 e .printStackTrace ();
139138 }
140139 return false ;
@@ -168,7 +167,7 @@ boolean connect() {
168167 }
169168 catch (Exception e ) {
170169 System .err .println ("Unable to open communications pipe: " + communicationPipe );
171- if (configuration .debugConnection ) {
170+ if (bwClient . getConfiguration () .debugConnection ) {
172171 e .printStackTrace ();
173172 }
174173 gameTableFileHandle = null ;
@@ -184,7 +183,7 @@ boolean connect() {
184183 }
185184 catch (Exception e ) {
186185 System .err .println ("Unable to open shared memory mapping: " + sharedMemoryName );
187- if (configuration .debugConnection ) {
186+ if (bwClient . getConfiguration () .debugConnection ) {
188187 e .printStackTrace ();
189188 }
190189 pipeObjectHandle = null ;
@@ -197,7 +196,7 @@ boolean connect() {
197196 }
198197 catch (Exception e ) {
199198 System .err .println ("Unable to map game data." );
200- if (configuration .debugConnection ) {
199+ if (bwClient . getConfiguration () .debugConnection ) {
201200 e .printStackTrace ();
202201 }
203202 return false ;
@@ -218,7 +217,7 @@ boolean connect() {
218217 }
219218 catch (Exception e ) {
220219 System .err .println ("Unable to read pipe object." );
221- if (configuration .debugConnection ) {
220+ if (bwClient . getConfiguration () .debugConnection ) {
222221 e .printStackTrace ();
223222 }
224223 disconnect ();
@@ -232,18 +231,21 @@ boolean connect() {
232231 }
233232
234233 void update () {
234+ // Indicate that we are done with the current frame
235235 byte code = 1 ;
236236 try {
237237 pipeObjectHandle .writeByte (code );
238+ bwClient .getPerformanceMetrics ().endToEndFrameDuration .stopTiming ();
238239 }
239240 catch (Exception e ) {
240241 System .err .println ("failed, disconnecting" );
241- if (configuration .debugConnection ) {
242+ if (bwClient . getConfiguration () .debugConnection ) {
242243 e .printStackTrace ();
243244 }
244245 disconnect ();
245246 return ;
246247 }
248+ // Wait for BWAPI to indicate that a new frame is ready
247249 while (code != 2 ) {
248250 try {
249251 code = pipeObjectHandle .readByte ();
@@ -257,7 +259,7 @@ void update() {
257259 }
258260 catch (Exception e ) {
259261 System .err .println ("failed, disconnecting" );
260- if (configuration .debugConnection ) {
262+ if (bwClient . getConfiguration () .debugConnection ) {
261263 e .printStackTrace ();
262264 }
263265 disconnect ();
0 commit comments