Frustum filtering tracker

This commit is contained in:
2026-07-16 23:09:01 +08:00
parent dcbf2e541c
commit 1c5998411d
3 changed files with 359 additions and 0 deletions
@@ -0,0 +1,59 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NanaChiyo0721 <nanachiyo0721@163.com>
Date: Thu, 16 Jul 2026 23:04:23 +0800
Subject: [PATCH] Frustum filtering tracker
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index 849ad46b2941ebba91b428846b3b20d11ee5e1c9..3291d17bc176b306a792a1ca59254615b188ee9e 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -932,6 +932,7 @@ public class ChunkMap extends SimpleRegionStorage implements ChunkHolder.PlayerP
public void move(final ServerPlayer player) {
// Paper - optimise entity tracker
+ if (player.culling != null) player.culling.updateFrustum(); // Shiroha - Frustum filtering tracker
SectionPos oldSection = player.getLastSectionPos();
SectionPos newSection = SectionPos.of(player);
//boolean wasIgnored = this.playerMap.ignored(player); // Folia - region threading
@@ -1054,6 +1055,11 @@ public class ChunkMap extends SimpleRegionStorage implements ChunkHolder.PlayerP
final ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup entityLookup = (ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup)((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getEntityLookup();;
final ca.spottedleaf.moonrise.common.misc.NearbyPlayers nearbyPlayers = this.level.moonrise$getNearbyPlayers(); // Folia - region threading
+ // Shiroha start - Frustum filtering tracker
+ for (var player : worldData.getLocalPlayers()) {
+ if (player.culling != null) player.culling.updateFrustum();
+ }
+ // Shiroha end - Frustum filtering tracker
final ca.spottedleaf.moonrise.common.list.ReferenceList<net.minecraft.world.entity.Entity> trackerEntities = worldData.trackerEntities; // Folia - region threading
final Entity[] trackerEntitiesRaw = trackerEntities.getRawDataUnchecked();
for (int i = 0, len = totalEntities = trackerEntities.size(); i < len; ++i) { // Folia - region threading
@@ -1371,6 +1377,15 @@ public class ChunkMap extends SimpleRegionStorage implements ChunkHolder.PlayerP
if (visibleToPlayer && (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(player) || !player.getBukkitEntity().canSee(this.entity.getBukkitEntity()))) { // Paper - only consider hits // Folia - region threading
visibleToPlayer = false;
}
+ // Shiroha start - Frustum filtering tracker
+ if (player.culling != null) {
+ player.culling.far((float) Math.sqrt(distanceSquared));
+
+ if (visibleToPlayer && !player.isSpectator() && distanceSquared > ((int)io.nanachiyo0721.shiroha.config.modules.optimizations.FrustumFilteringTrackerConfig.minForceVisibleDistance ^ 2)) {
+ visibleToPlayer = player.culling.isVisibleFor(this.entity.getBoundingBox());
+ }
+ }
+ // Shiroha end - Frustum filtering tracker
// CraftBukkit end
if (visibleToPlayer) {
if (this.seenBy.add(player.connection)) {
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
index e5e5e1da691dc71dc806d3b039ff02b1fa50eacf..81c5a042b288fb1208bd71239b16f65dd63e69d6 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -186,6 +186,8 @@ public abstract class Player extends Avatar implements ContainerUser {
}
// CraftBukkit end
+ public io.nanachiyo0721.shiroha.utils.Culling culling = io.nanachiyo0721.shiroha.utils.Culling.newDefault(this); // Shiroha - Frustum filtering tracker
+
public Player(final Level level, final GameProfile gameProfile) {
super(EntityTypes.PLAYER, level);
this.setUUID(gameProfile.id());