From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Wed, 5 Feb 2025 15:22:19 +0800 Subject: [PATCH] Raytracing tracker experiment Based on the framework of EntityCulling((((((( diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java index 7eff847790394aecd058e7a61905da86163b4c6e..9099457f55a2829297ac1db8a69a98ff717d9a86 100644 --- a/net/minecraft/server/level/ChunkMap.java +++ b/net/minecraft/server/level/ChunkMap.java @@ -1208,7 +1208,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider double d1 = vec3_dx * vec3_dx + vec3_dz * vec3_dz; // Paper double d2 = d * d; // Paper start - Configurable entity tracking range by Y - boolean flag = d1 <= d2; + boolean flag = d1 <= d2 && !entity.isCulled(); // Luminol - Ray tracing entity tracker if (flag && level.paperConfig().entities.trackingRangeY.enabled) { double rangeY = level.paperConfig().entities.trackingRangeY.get(this.entity, -1); if (rangeY != -1) { diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java index ccf1914b4f48ecc0f4fe980510f42d5415ec1daa..ceca76a5791e319dd7cc4048c9860b1df065b95a 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -135,7 +135,7 @@ import net.minecraft.world.scores.ScoreHolder; import net.minecraft.world.scores.Team; import org.slf4j.Logger; -public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder, ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity, ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity { // Paper - rewrite chunk system // Paper - optimise entity tracker +public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder, ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity, ca.spottedleaf.moonrise.patches.entity_tracker.EntityTrackerEntity, dev.tr7zw.entityculling.versionless.access.Cullable { // Paper - rewrite chunk system // Paper - optimise entity tracker // Luminol - Ray tracing entity tracker // CraftBukkit start private static final int CURRENT_LEVEL = 2; @@ -6049,4 +6049,46 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess // Paper end - Expose entity id counter public boolean shouldTickHot() { return this.tickCount > 20 * 10 && this.isAlive(); } // KioCG + + private long lasttime = 0; + private boolean culled = false; + private boolean outOfCamera = false; + + @Override + public void setTimeout() { + this.lasttime = System.currentTimeMillis() + 1000; + } + + @Override + public boolean isForcedVisible() { + return this.lasttime > System.currentTimeMillis(); + } + + @Override + public void setCulled(boolean value) { + this.culled = value; + if (!value) { + setTimeout(); + } + } + + @Override + public boolean isCulled() { + if (!me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) + return false; + return this.culled; + } + + @Override + public void setOutOfCamera(boolean value) { + this.outOfCamera = value; + } + + @Override + public boolean isOutOfCamera() { + if (!me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) + return false; + return this.outOfCamera; + } + } diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java index d9cc1d7e56c37d5ce92544edc10e89dbc89dd15d..39e7689be243b9c99b507d665f6591359115287b 100644 --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java @@ -1097,6 +1097,9 @@ public class EntityType implements FeatureElement, EntityTypeT public final int passengerTickTimerId; public final int passengerInactiveTickTimerId; // Folia end - profiler + // Luminol - Raytracing entity tracker + public boolean skipRaytracningCheck = false; + // Luminol end public EntityType( EntityType.EntityFactory factory, diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java index c6252a245e9701f69db1fe167f6590095237553a..40b91234fd2e4f4f134d309590ea6b605f764e83 100644 --- a/net/minecraft/world/entity/player/Player.java +++ b/net/minecraft/world/entity/player/Player.java @@ -211,6 +211,25 @@ public abstract class Player extends LivingEntity { return (org.bukkit.craftbukkit.entity.CraftHumanEntity) super.getBukkitEntity(); } // CraftBukkit end + // Luminol start - Raytracing entity tracker + public dev.tr7zw.entityculling.CullTask cullTask; + { + if (!me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) { + this.cullTask = null; + }else { + final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance( + me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.tracingDistance, + new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level()) + ); + + this.cullTask = new dev.tr7zw.entityculling.CullTask( + culling, this, + me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.hitboxLimit, + me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.checkIntervalMs + ); + } + } + // Luminol end public Player(Level level, BlockPos pos, float yRot, GameProfile gameProfile) { super(EntityType.PLAYER, level); @@ -263,6 +282,26 @@ public abstract class Player extends LivingEntity { @Override public void tick() { + // Luminol start - Ray tracing entity tracker + if (!me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.enabled) { + if (this.cullTask != null) this.cullTask.signalStop(); + this.cullTask = null; + }else { + final com.logisticscraft.occlusionculling.OcclusionCullingInstance culling = new com.logisticscraft.occlusionculling.OcclusionCullingInstance( + me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.tracingDistance, + new dev.tr7zw.entityculling.DefaultChunkDataProvider(this.level()) + ); + + this.cullTask = new dev.tr7zw.entityculling.CullTask( + culling, this, + me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.hitboxLimit, + me.earthme.luminol.config.modules.experiment.RayTrackingEntityTrackerConfig.checkIntervalMs + ); + } + if (this.cullTask != null) this.cullTask.setup(); + if (this.cullTask != null) this.cullTask.requestCullSignal(); // Luminol - Ray tracing entity tracker + // Luminol end + this.noPhysics = this.isSpectator(); if (this.isSpectator() || this.isPassenger()) { this.setOnGround(false); @@ -1505,6 +1544,7 @@ public abstract class Player extends LivingEntity { if (this.containerMenu != null && this.hasContainerOpen()) { this.doCloseContainer(); } + if (this.cullTask != null) this.cullTask.signalStop(); // Luminol - Ray tracing entity tracker } // Folia start - region threading