37
37
import net .minecraft .client .renderer .entity .state .EntityRenderState ;
38
38
import net .minecraft .client .resources .model .ModelBakery ;
39
39
import net .minecraft .core .BlockPos ;
40
- import net .minecraft .core .SectionPos ;
41
40
import net .minecraft .server .level .BlockDestructionProgress ;
42
41
import net .minecraft .util .Mth ;
43
42
import net .minecraft .util .profiling .Profiler ;
@@ -210,7 +209,7 @@ public void setupTerrain(Camera camera,
210
209
this .lastCameraYaw = yaw ;
211
210
212
211
if (cameraLocationChanged || fogDistanceChanged || cameraAngleChanged || cameraProjectionChanged ) {
213
- this .renderSectionManager .markGraphDirty ();
212
+ this .renderSectionManager .notifyChangedCamera ();
214
213
}
215
214
216
215
this .lastFogParameters = fogParameters ;
@@ -227,16 +226,14 @@ public void setupTerrain(Camera camera,
227
226
int maxChunkUpdates = updateChunksImmediately ? this .renderDistance : 1 ;
228
227
229
228
for (int i = 0 ; i < maxChunkUpdates ; i ++) {
230
- if (this .renderSectionManager .needsUpdate ()) {
231
- profiler .popPush ("chunk_render_lists" );
229
+ profiler .popPush ("chunk_render_lists" );
232
230
233
- this .renderSectionManager .update (camera , viewport , fogParameters , spectator );
234
- }
231
+ this .renderSectionManager .updateRenderLists (camera , viewport , fogParameters , spectator , updateChunksImmediately );
235
232
236
233
profiler .popPush ("chunk_update" );
237
234
238
235
this .renderSectionManager .cleanupAndFlip ();
239
- this .renderSectionManager .updateChunks (updateChunksImmediately );
236
+ this .renderSectionManager .updateChunks (viewport , updateChunksImmediately );
240
237
241
238
profiler .popPush ("chunk_upload" );
242
239
@@ -356,9 +353,8 @@ private void renderBlockEntities(PoseStack matrices,
356
353
357
354
while (renderSectionIterator .hasNext ()) {
358
355
var renderSectionId = renderSectionIterator .nextByteAsInt ();
359
- var renderSection = renderRegion .getSection (renderSectionId );
360
356
361
- var blockEntities = renderSection .getCulledBlockEntities ();
357
+ var blockEntities = renderRegion .getCulledBlockEntities (renderSectionId );
362
358
363
359
if (blockEntities == null ) {
364
360
continue ;
@@ -383,7 +379,7 @@ private void renderGlobalBlockEntities(PoseStack matrices,
383
379
LocalPlayer player ,
384
380
LocalBooleanRef isGlowing ) {
385
381
for (var renderSection : this .renderSectionManager .getSectionsWithGlobalEntities ()) {
386
- var blockEntities = renderSection .getGlobalBlockEntities ();
382
+ var blockEntities = renderSection .getRegion (). getGlobalBlockEntities (renderSection . getSectionIndex () );
387
383
388
384
if (blockEntities == null ) {
389
385
continue ;
@@ -457,9 +453,7 @@ public void iterateVisibleBlockEntities(Consumer<BlockEntity> blockEntityConsume
457
453
458
454
while (renderSectionIterator .hasNext ()) {
459
455
var renderSectionId = renderSectionIterator .nextByteAsInt ();
460
- var renderSection = renderRegion .getSection (renderSectionId );
461
-
462
- var blockEntities = renderSection .getCulledBlockEntities ();
456
+ var blockEntities = renderRegion .getCulledBlockEntities (renderSectionId );
463
457
464
458
if (blockEntities == null ) {
465
459
continue ;
@@ -472,7 +466,7 @@ public void iterateVisibleBlockEntities(Consumer<BlockEntity> blockEntityConsume
472
466
}
473
467
474
468
for (var renderSection : this .renderSectionManager .getSectionsWithGlobalEntities ()) {
475
- var blockEntities = renderSection .getGlobalBlockEntities ();
469
+ var blockEntities = renderSection .getRegion (). getGlobalBlockEntities (renderSection . getSectionIndex () );
476
470
477
471
if (blockEntities == null ) {
478
472
continue ;
@@ -485,10 +479,13 @@ public void iterateVisibleBlockEntities(Consumer<BlockEntity> blockEntityConsume
485
479
}
486
480
487
481
// the volume of a section multiplied by the number of sections to be checked at most
488
- private static final double MAX_ENTITY_CHECK_VOLUME = 16 * 16 * 16 * 15 ;
482
+ private static final double MAX_ENTITY_CHECK_VOLUME = 16 * 16 * 16 * 50 ;
489
483
490
484
/**
491
485
* Returns whether the entity intersects with any visible chunks in the graph.
486
+ *
487
+ * Note that this method assumes the entity is within the frustum. It does not perform a frustum check.
488
+ *
492
489
* @return True if the entity is visible, otherwise false
493
490
*/
494
491
public <T extends Entity , S extends EntityRenderState > boolean isEntityVisible (EntityRenderer <T , S > renderer , T entity ) {
@@ -506,7 +503,7 @@ public <T extends Entity, S extends EntityRenderState> boolean isEntityVisible(E
506
503
// bail on very large entities to avoid checking many sections
507
504
double entityVolume = (bb .maxX - bb .minX ) * (bb .maxY - bb .minY ) * (bb .maxZ - bb .minZ );
508
505
if (entityVolume > MAX_ENTITY_CHECK_VOLUME ) {
509
- // TODO: do a frustum check instead, even large entities aren't visible if they're outside the frustum
506
+ // large entities are only frustum tested, their sections are not checked for visibility
510
507
return true ;
511
508
}
512
509
@@ -520,48 +517,28 @@ public boolean isBoxVisible(double x1, double y1, double z1, double x2, double y
520
517
return true ;
521
518
}
522
519
523
- int minX = SectionPos .posToSectionCoord (x1 - 0.5D );
524
- int minY = SectionPos .posToSectionCoord (y1 - 0.5D );
525
- int minZ = SectionPos .posToSectionCoord (z1 - 0.5D );
526
-
527
- int maxX = SectionPos .posToSectionCoord (x2 + 0.5D );
528
- int maxY = SectionPos .posToSectionCoord (y2 + 0.5D );
529
- int maxZ = SectionPos .posToSectionCoord (z2 + 0.5D );
530
-
531
- for (int x = minX ; x <= maxX ; x ++) {
532
- for (int z = minZ ; z <= maxZ ; z ++) {
533
- for (int y = minY ; y <= maxY ; y ++) {
534
- if (this .renderSectionManager .isSectionVisible (x , y , z )) {
535
- return true ;
536
- }
537
- }
538
- }
539
- }
540
-
541
- return false ;
520
+ return this .renderSectionManager .isBoxVisible (x1 , y1 , z1 , x2 , y2 , z2 );
542
521
}
543
522
544
523
public String getChunksDebugString () {
545
- // C: visible/total D: distance
546
- // TODO: add dirty and queued counts
547
- return String .format ("C: %d/%d D: %d" , this .renderSectionManager .getVisibleChunkCount (), this .renderSectionManager .getTotalSections (), this .renderDistance );
524
+ return this .renderSectionManager .getChunksDebugString ();
548
525
}
549
526
550
527
/**
551
528
* Schedules chunk rebuilds for all chunks in the specified block region.
552
529
*/
553
- public void scheduleRebuildForBlockArea (int minX , int minY , int minZ , int maxX , int maxY , int maxZ , boolean important ) {
554
- this .scheduleRebuildForChunks (minX >> 4 , minY >> 4 , minZ >> 4 , maxX >> 4 , maxY >> 4 , maxZ >> 4 , important );
530
+ public void scheduleRebuildForBlockArea (int minX , int minY , int minZ , int maxX , int maxY , int maxZ , boolean playerChanged ) {
531
+ this .scheduleRebuildForChunks (minX >> 4 , minY >> 4 , minZ >> 4 , maxX >> 4 , maxY >> 4 , maxZ >> 4 , playerChanged );
555
532
}
556
533
557
534
/**
558
535
* Schedules chunk rebuilds for all chunks in the specified chunk region.
559
536
*/
560
- public void scheduleRebuildForChunks (int minX , int minY , int minZ , int maxX , int maxY , int maxZ , boolean important ) {
537
+ public void scheduleRebuildForChunks (int minX , int minY , int minZ , int maxX , int maxY , int maxZ , boolean playerChanged ) {
561
538
for (int chunkX = minX ; chunkX <= maxX ; chunkX ++) {
562
539
for (int chunkY = minY ; chunkY <= maxY ; chunkY ++) {
563
540
for (int chunkZ = minZ ; chunkZ <= maxZ ; chunkZ ++) {
564
- this .scheduleRebuildForChunk (chunkX , chunkY , chunkZ , important );
541
+ this .scheduleRebuildForChunk (chunkX , chunkY , chunkZ , playerChanged );
565
542
}
566
543
}
567
544
}
@@ -570,8 +547,8 @@ public void scheduleRebuildForChunks(int minX, int minY, int minZ, int maxX, int
570
547
/**
571
548
* Schedules a chunk rebuild for the render belonging to the given chunk section position.
572
549
*/
573
- public void scheduleRebuildForChunk (int x , int y , int z , boolean important ) {
574
- this .renderSectionManager .scheduleRebuild (x , y , z , important );
550
+ public void scheduleRebuildForChunk (int x , int y , int z , boolean playerChanged ) {
551
+ this .renderSectionManager .scheduleRebuild (x , y , z , playerChanged );
575
552
}
576
553
577
554
public Collection <String > getDebugStrings () {
0 commit comments