Skip to content

Commit ea04e42

Browse files
committed
[EntityCulling] Optimize
1 parent a3267d6 commit ea04e42

File tree

1 file changed

+8
-9
lines changed
  • bukkit/version/v1_18/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling/v1_18

1 file changed

+8
-9
lines changed

bukkit/version/v1_18/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/entityculling/v1_18/RaytraceHandlerImpl.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ import org.bukkit.event.Listener
4646
import org.bukkit.event.entity.EntitySpawnEvent
4747
import org.bukkit.event.world.ChunkLoadEvent
4848
import org.incendo.cloud.annotations.Command
49-
import org.spigotmc.TrackingRange
5049
import java.util.concurrent.Executors
5150
import java.util.concurrent.atomic.AtomicInteger
52-
import kotlin.math.*
51+
import kotlin.math.abs
52+
import kotlin.math.floor
53+
import kotlin.math.sign
54+
import kotlin.math.sqrt
5355
import kotlin.time.Duration.Companion.seconds
5456

5557
class RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig, EmptyConfiguration>() {
@@ -273,7 +275,8 @@ class RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig, E
273275
fun tickPlayer(player: ServerPlayer, bukkit: Player, userCullData: UserCullData, level: ServerLevel, entities: Iterable<Entity>) {
274276
val viewDistanceSquared = (bukkit.viewDistance + 1).square() shl 8
275277

276-
val predicatedPlayerPos = if (userCullData.shouldCull && config.predicatePlayerPositon) {
278+
val shouldCull = userCullData.shouldCull
279+
val predicatedPlayerPos = if (shouldCull && config.predicatePlayerPositon) {
277280
val velocity = playerVelocityGetter.getPlayerMoveVelocity(player)
278281
if (velocity.lengthSqr() >= 0.06) { // Threshold for sprinting
279282
var x = player.x
@@ -303,17 +306,13 @@ class RaytraceHandlerImpl: RaytraceHandler<RaytraceHandlerImpl.RaytraceConfig, E
303306
// Get regions from entityLookup, then loop over each chunk to collect entities is 2x slower.
304307
for (entity in entities) {
305308
if (entity === player) continue
306-
307-
// Get tracking range for this entity type, adding extra 1 chunk to it.
308-
val typeRange = (TrackingRange.getEntityTrackingRange(entity, entity.type.clientTrackingRange() shl 4) + 16).square()
309-
val finalRange = min(typeRange, viewDistanceSquared)
310309
val dist = (player.x - entity.x).square() + (player.z - entity.z).square()
311-
if (dist > finalRange) continue
310+
if (dist > viewDistanceSquared) continue
312311

313312
tickedEntities++
314313

315314
if (
316-
!userCullData.shouldCull
315+
!shouldCull
317316
|| entity.isCurrentlyGlowing
318317
|| config.visibleEntityTypes.contains(entity.type)
319318
|| dist + (player.y - entity.y).square() <= forceVisibleDistanceSquared

0 commit comments

Comments
 (0)