@@ -76,9 +76,11 @@ Game getGame() {
7676 */
7777 void onFrame () {
7878 if (configuration .async ) {
79+ configuration .log ("Main: onFrame asynchronous start" );
7980 long startNanos = System .nanoTime ();
8081 long endNanos = startNanos + configuration .asyncFrameDurationMs * 1000000 ;
8182 if (botThread == null ) {
83+ configuration .log ("Main: Starting bot thread" );
8284 botThread = createBotThread ();
8385 botThread .setName ("JBWAPI Bot" );
8486 botThread .start ();
@@ -88,35 +90,44 @@ void onFrame() {
8890 If buffer is full, it will wait until it has capacity
8991 Wait for empty buffer OR termination condition
9092 */
93+ configuration .log ("Main: Enqueuing frame" );
9194 boolean isFrameZero = liveClientData .gameData ().getFrameCount () == 0 ;
9295 frameBuffer .enqueueFrame ();
9396 performanceMetrics .bwapiResponse .startTiming ();
9497 frameBuffer .lockSize .lock ();
9598 try {
9699 while (!frameBuffer .empty ()) {
100+ configuration .log ("Main: Waiting for empty frame buffer" );
97101
98102 // Make bot exceptions fall through to the main thread.
99103 Throwable lastThrow = getLastBotThrow ();
100104 if (lastThrow != null ) {
105+ configuration .log ("Main: Rethrowing bot throwable" );
101106 throw new RuntimeException (lastThrow );
102107 }
103108
104109 if (configuration .unlimitedFrameZero && isFrameZero ) {
110+ configuration .log ("Main: Waiting indefinitely on frame 0" );
105111 frameBuffer .conditionSize .await ();
106112 } else {
107113 long remainingNanos = endNanos - System .nanoTime ();
108114 if (remainingNanos <= 0 ) break ;
115+ configuration .log ("Main: Waiting " + remainingNanos / 1000000 + "ms for bot" );
109116 frameBuffer .conditionSize .awaitNanos (remainingNanos );
110117 }
111118 }
112119 } catch (InterruptedException ignored ) {
113120 } finally {
114121 frameBuffer .lockSize .unlock ();
115122 performanceMetrics .bwapiResponse .stopTiming ();
123+ configuration .log ("Main: onFrame asynchronous end" );
116124 }
117125 } else {
126+ configuration .log ("Main: onFrame synchronous start" );
118127 handleEvents ();
128+ configuration .log ("Main: onFrame synchronous end" );
119129 }
130+
120131 }
121132
122133 /**
@@ -139,20 +150,25 @@ Throwable getLastBotThrow() {
139150
140151 private Thread createBotThread () {
141152 return new Thread (() -> {
153+ configuration .log ("Bot: Thread started" );
142154 while ( ! gameOver ) {
155+ configuration .log ("Bot: Attempting to handle next frame" );
143156 frameBuffer .lockSize .lock ();
144157 try {
145158 while (frameBuffer .empty ()) {
159+ configuration .log ("Bot: Waiting for next frame" );
146160 performanceMetrics .botIdle .startTiming ();
147161 frameBuffer .conditionSize .awaitUninterruptibly ();
148162 }
149163 performanceMetrics .botIdle .stopTiming ();
150164 } finally {
151165 frameBuffer .lockSize .unlock ();
152166 }
167+ configuration .log ("Bot: Peeking next frame" );
153168 game .clientData ().setBuffer (frameBuffer .peek ());
154169 performanceMetrics .frameBufferSize .record (frameBuffer .framesBuffered () - 1 );
155170 try {
171+ configuration .log ("Bot: Handling frame #" + game .getFrameCount ());
156172 handleEvents ();
157173 } finally {
158174 // In the case where t
0 commit comments