@@ -48,7 +48,7 @@ public void processQueue(World world, Channel channel, PlayerSession session, lo
4848 int chunkQueueSize = this .configFacade .get ().chunkQueueSize ();
4949
5050 do {
51- this .drainReadyEntries (world , channel , session );
51+ session . chunkQueue (). removeIf ( entry -> this .checkQueueEntry (world , channel , session , entry ) );
5252
5353 if (session .chunkQueue ().size () >= chunkQueueSize ) {
5454 break ;
@@ -69,8 +69,6 @@ public void processQueue(World world, Channel channel, PlayerSession session, lo
6969 break ;
7070 }
7171 } while (System .nanoTime () < deadlineNanos );
72-
73- this .drainReadyEntries (world , channel , session );
7472 }
7573
7674 public void sendUnload (Channel channel , PlayerSession session , long chunkKey ) {
@@ -131,38 +129,28 @@ private CompletableFuture<ByteBuf> buildChunk(
131129 .exceptionally (throwable -> null );
132130 }
133131
134- private void drainReadyEntries (World world , Channel channel , PlayerSession session ) {
135- if (session .chunkQueue ().isEmpty ()) {
136- return ;
132+ private boolean checkQueueEntry (World world , Channel channel , PlayerSession session , ChunkSendQueueEntry entry ) {
133+ CompletableFuture <ByteBuf > buildFuture = entry .buildFuture ();
134+ if (!buildFuture .isDone ()) {
135+ return false ;
137136 }
138- int checks = session .chunkQueue ().size ();
139- for (int i = 0 ; i < checks ; i ++) {
140- ChunkSendQueueEntry entry = session .chunkQueue ().pollFirst ();
141- if (entry == null ) {
142- break ;
143- }
144- CompletableFuture <ByteBuf > buildFuture = entry .buildFuture ();
145- if (!buildFuture .isDone ()) {
146- session .chunkQueue ().addLast (entry );
147- continue ;
148- }
149- if (buildFuture .isCompletedExceptionally ()) {
150- session .onChunkBuildFailed (entry .chunkKey ());
151- entry .releaseFuture ();
152- continue ;
153- }
154- ByteBuf payload = buildFuture .getNow (null );
155- if (payload == null ) {
156- session .onChunkBuildFailed (entry .chunkKey ());
157- entry .releaseFuture ();
158- continue ;
159- }
160- ByteBuf toSend = payload .retainedDuplicate ();
161- if (!this .trySend (channel , session , world .getUID (), session .epoch (), toSend , entry .chunkKey ())) {
162- session .onChunkBuildFailed (entry .chunkKey ());
163- }
137+ if (buildFuture .isCompletedExceptionally ()) {
138+ session .onChunkBuildFailed (entry .chunkKey ());
164139 entry .releaseFuture ();
140+ return true ;
141+ }
142+ ByteBuf payload = buildFuture .getNow (null );
143+ if (payload == null ) {
144+ session .onChunkBuildFailed (entry .chunkKey ());
145+ entry .releaseFuture ();
146+ return true ;
147+ }
148+ ByteBuf toSend = payload .retainedDuplicate ();
149+ if (!this .trySend (channel , session , world .getUID (), session .epoch (), toSend , entry .chunkKey ())) {
150+ session .onChunkBuildFailed (entry .chunkKey ());
165151 }
152+ entry .releaseFuture ();
153+ return true ;
166154 }
167155
168156 private boolean trySend (
0 commit comments