@@ -50,42 +50,47 @@ public void startGame(BWClientConfiguration configuration) {
5050 client .reconnect ();
5151
5252 do {
53+ ClientData .GameData gameData = client .clientData ().gameData ();
5354 long lastUpdateTimestampMillis = 0 ;
54- System .out .println ("Client: Starting game" );
55- while (!getGame ().isInGame ()) {
56- if (!client .isConnected ()) {
55+ System .out .println ("Client: Beginning game loop" );
56+ while (!gameData .isInGame ()) {
57+ botWrapper = null ;
58+ if (client .isConnected ()) {
59+ System .out .println ("Client: Not in game; Connected." );
60+ } else {
61+ System .out .println ("Client: Not in game; Not connected." );
5762 return ;
5863 }
59- System .out .println ("Client: connected." );
6064 lastUpdateTimestampMillis = System .currentTimeMillis ();
6165 client .update ();
6266 }
63-
64- System .out .println ("Client: Creating bot wrapper" );
65- BotWrapper botWrapper = new BotWrapper (configuration , eventListener , client .mapFile ());
66-
67- while (getGame ().isInGame ()) {
68- System .out .println ("Client: Stepping bot wrapper" );
67+ while (gameData .isInGame ()) {
68+ System .out .println ("Client: In game on frame " + gameData .getFrameCount ());
69+ if (botWrapper == null ) {
70+ botWrapper = new BotWrapper (configuration , eventListener , client .mapFile ());
71+ }
6972 botWrapper .step ();
70- System .out .println ("Client: Waiting for idle bot or frame duration" );
7173
7274 // Proceed immediately once framebuffer is empty
7375 // Otherwise, wait for bot to catch up
7476 // TODO: Replace with a wait instead of a sleep
75- // TODO: Respect configuration.asyncWaitOnFrameZero
76- while ( ! botWrapper .botIdle ()) {
77- long frameDuration = System .currentTimeMillis () - lastUpdateTimestampMillis ;
78- if (frameDuration > configuration .asyncFrameDurationMillis && (client .clientData ().gameData ().getFrameCount () > 0 || ! configuration .asyncWaitOnFrameZero )) {
79- System .out .println ("Client: Exceeded frame duration while waiting for bot: " + frameDuration + "ms on frame " + client .clientData ().gameData ().getFrameCount ());
77+ while (true ) {
78+ if (botWrapper .botIdle ()) {
79+ System .out .println ("Client: Proceeding because bot is idle." );
8080 break ;
8181 }
82- try {
83- Thread .sleep (1 );
84- } catch (InterruptedException ignored ) {}
82+ long frameDurationMillis = System .currentTimeMillis () - lastUpdateTimestampMillis ;
83+ if (frameDurationMillis > configuration .asyncFrameDurationMillis && (client .clientData ().gameData ().getFrameCount () > 0 || ! configuration .asyncWaitOnFrameZero )) {
84+ System .out .println ("Client: Proceeding because frame " + botWrapper .getGame ().getFrameCount () + " lasted " + frameDurationMillis + "ms" );
85+ break ;
86+ }
87+ try { Thread .sleep (1 ); } catch (InterruptedException ignored ) {}
8588 }
8689
87- System .out .println ("Client: Ending frame. Frames buffered: " );
88- lastUpdateTimestampMillis = System .currentTimeMillis ();
90+ long currentTimeMillis = System .currentTimeMillis ();
91+ long frameDurationMillis = currentTimeMillis - lastUpdateTimestampMillis ;
92+ lastUpdateTimestampMillis = currentTimeMillis ;
93+ System .out .println ("Client: Ending frame after " + frameDurationMillis + "ms" );
8994 client .update ();
9095 if (!client .isConnected ()) {
9196 System .out .println ("Reconnecting..." );
0 commit comments