- Description
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- getComponentType()
- clear()
- tick(Player, PlayerRef, TransformComponent, float, CommandBuffer)
- isLoaded(long)
- isLoaded(int, int, int)
- removeForReload(long)
- removeForReload(int, int, int)
- shouldBeVisible(long)
- shouldBeVisible(int, int, int)
- getChunkVisibility(long)
- getSectionVisibility(int, int, int)
- getMaxSectionsPerSecond()
- setMaxSectionsPerSecond(int)
- setDefaultMaxSectionsPerSecond(PlayerRef)
- getMaxSectionsPerTick()
- setMaxSectionsPerTick(int)
- getMinLoadedRadius()
- setMinLoadedRadius(int)
- getMaxHotLoadedRadius()
- setMaxHotLoadedRadius(int)
- getLoadedSectionsCount()
- forEachLoadedSection(TriIntConsumer)
- getLoadingSectionsCount()
- getLoadedChunksDebug()
- setReadyForChunks(boolean)
- isReadyForChunks()
- copyFrom(ChunkTracker)
- tryLoadColumnAsync(ChunkStore, PlayerRef, long, TransformComponent, ComponentAccessor)
- tryLoadSectionAsync(ChunkStore, PlayerRef, int, int, int, TransformComponent, ComponentAccessor)
- clone()
- calculateSectionPriority(int, int, int)
- calculateColumnPriority(int, int)
Class ChunkTracker
- All Implemented Interfaces:
Component<EntityStore>, Cloneable
Chunk sending is rate limited to prevent sending unnecessary chunks when the player is moving.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAn enum that represents the visibility state of a chunk. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum Ys per batchedSetAbsentChunkspacket.static final longThe maximum failure backoff time in nanoseconds.static final intThe maximum hot loaded chunks radius.static final intstatic final intstatic final intstatic final intstatic final intstatic final intMaximum ints per batchedUnloadChunkspacket.static final MetricsRegistry<ChunkTracker> The metrics registry for the chunk tracker.static final intThe minimum loaded chunks radius.Fields inherited from interface Component
EMPTY_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionEmpty Constructor for aChunkTrackerinstance.ChunkTracker(Supplier<SphereOffsets> sphereOffsetsSupplier) Constructor accepting the max viewSphereOffsetssupplier, so callers (notably tests) can build aChunkTrackerwithout depending on the server singleton. -
Method Summary
Modifier and TypeMethodDescriptionfloatcalculateColumnPriority(int x, int z) floatcalculateSectionPriority(int x, int y, int z) voidclear()Called to clear all loaded and loading chunks without sending unload packets.clone()voidcopyFrom(ChunkTracker chunkTracker) Called to copy the state from anotherChunkTrackerinstance.voidforEachLoadedSection(TriIntConsumer consumer) Visits each section the client has received from this tracker, callingconsumer.accept(x, y, z)once per section under the tracker's read lock.getChunkVisibility(long indexChunk) Fetches the visibility state of a chunk column using a flat 2D disc test around the player.static ComponentType<EntityStore, ChunkTracker> Formats a debug string containing tracker state and two top-down grids: loaded section counts per column and hot section counts per column.intReturns the number of sections loaded by the player that owns this tracker.intReturns the number of sections being loaded by the player that owns this tracker.intintintintgetSectionVisibility(int x, int y, int z) Fetches the visibility state of a chunk section.booleanisLoaded(int x, int y, int z) booleanisLoaded(long indexChunk) Determines whether the given chunk is loaded.booleanvoidremoveForReload(int x, int y, int z) voidremoveForReload(long chunkIndex) Deprecated, for removal: This API element is subject to removal in a future version.voidsetDefaultMaxSectionsPerSecond(PlayerRef playerRef) Called to set the default maximum sections per second based on the player connection type.voidsetMaxHotLoadedRadius(int maxHotLoadedRadius) Called to set the maximum hot loaded chunks radius.voidsetMaxSectionsPerSecond(int maxSectionsPerSecond) Called to set the maximum sections per second allowed to be sent to the player.voidsetMaxSectionsPerTick(int maxSectionsPerTick) Called to set the maximum sections per tick allowed to be sent to the player.voidsetMinLoadedRadius(int minLoadedRadius) Called to set the minimum loaded chunks radius.voidsetReadyForChunks(boolean readyForChunks) Called to set whether the chunk tracker is ready to send chunks.booleanshouldBeVisible(int x, int y, int z) Determines whether the given section coordinates should be visible from the player's current position, using the same sphere predicate that drives section load/unload.booleanshouldBeVisible(long chunkCoordinates) Determines whether the given chunk coordinates should be visible.voidtick(Player playerComponent, PlayerRef playerRefComponent, TransformComponent transformComponent, float dt, CommandBuffer<EntityStore> commandBuffer) Called to tick the chunk tracker component for the given player entity.voidtryLoadColumnAsync(ChunkStore chunkStore, PlayerRef playerRefComponent, long chunkIndex, TransformComponent transformComponent, ComponentAccessor<EntityStore> componentAccessor) Called to try and load a chunk asynchronously for the given player.voidtryLoadSectionAsync(ChunkStore chunkStore, PlayerRef playerRefComponent, int x, int y, int z, TransformComponent transformComponent, ComponentAccessor<EntityStore> componentAccessor) Called to try and load a section asynchronously for the given player.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Component
cloneSerializable
-
Field Details
-
METRICS_REGISTRY
The metrics registry for the chunk tracker. -
MAX_SECTIONS_PER_SECOND_LOCAL
public static final int MAX_SECTIONS_PER_SECOND_LOCAL- See Also:
-
MAX_SECTIONS_PER_SECOND_LAN
public static final int MAX_SECTIONS_PER_SECOND_LAN- See Also:
-
MAX_SECTIONS_PER_SECOND
public static final int MAX_SECTIONS_PER_SECOND- See Also:
-
MAX_SECTIONS_PER_TICK
public static final int MAX_SECTIONS_PER_TICK- See Also:
-
MAX_UNLOAD_SECTION_INTS
public static final int MAX_UNLOAD_SECTION_INTSMaximum ints per batchedUnloadChunkspacket. A large move (or teleport) can unload far more than one packet should carry, soflushUnloads(PlayerRef)slices the scratch buffers into packets of at most these many ints. Must match theMaxLengthon the packet'sSections/Columnsfields and stay a multiple of the entry stride (3 for sections, 2 for columns).- See Also:
-
MAX_UNLOAD_COLUMN_INTS
public static final int MAX_UNLOAD_COLUMN_INTS- See Also:
-
MAX_ABSENT_Y_INTS
public static final int MAX_ABSENT_Y_INTSMaximum Ys per batchedSetAbsentChunkspacket. Must match theMaxLengthonSetAbsentChunks.Ys;flushPendingAbsent(PlayerRef)slices a column's pending list into packets of at most this many so a tall cubic column can't produce an over-long packet.- See Also:
-
MIN_LOADED_RADIUS
public static final int MIN_LOADED_RADIUSThe minimum loaded chunks radius.- See Also:
-
MAX_HOT_LOADED_RADIUS
public static final int MAX_HOT_LOADED_RADIUSThe maximum hot loaded chunks radius.- See Also:
-
MAX_FAILURE_BACKOFF_NANOS
public static final long MAX_FAILURE_BACKOFF_NANOSThe maximum failure backoff time in nanoseconds.
-
-
Constructor Details
-
ChunkTracker
public ChunkTracker()Empty Constructor for aChunkTrackerinstance. Reads the max view offsets from the live server config. -
ChunkTracker
Constructor accepting the max viewSphereOffsetssupplier, so callers (notably tests) can build aChunkTrackerwithout depending on the server singleton.- Parameters:
sphereOffsetsSupplier- supplies the current maximum view offsets for the spiral iterator.
-
-
Method Details
-
getComponentType
- Returns:
- the component type for the
ChunkTrackercomponent.
-
clear
public void clear()Called to clear all loaded and loading chunks without sending unload packets. -
tick
public void tick(@Nonnull Player playerComponent, @Nonnull PlayerRef playerRefComponent, @Nonnull TransformComponent transformComponent, float dt, @Nonnull CommandBuffer<EntityStore> commandBuffer) Called to tick the chunk tracker component for the given player entity.- Parameters:
dt- The delta time since the last tick.commandBuffer- TheCommandBuffer<EntityStore>for component access.
-
isLoaded
public boolean isLoaded(long indexChunk) Determines whether the given chunk is loaded.- Parameters:
indexChunk- The index of the chunk to check- Returns:
trueif the chunk is loaded,falseotherwise
-
isLoaded
public boolean isLoaded(int x, int y, int z) -
removeForReload
Deprecated, for removal: This API element is subject to removal in a future version. -
removeForReload
public void removeForReload(int x, int y, int z) -
shouldBeVisible
public boolean shouldBeVisible(long chunkCoordinates) Determines whether the given chunk coordinates should be visible.- Parameters:
chunkCoordinates- The chunk coordinates to check.- Returns:
trueif the chunk should be visible,falseotherwise.
-
shouldBeVisible
public boolean shouldBeVisible(int x, int y, int z) Determines whether the given section coordinates should be visible from the player's current position, using the same sphere predicate that drives section load/unload.- Parameters:
x- The section X coordinate to check.y- The section Y coordinate to check.z- The section Z coordinate to check.- Returns:
trueif the section is inside the player's sphere,falseotherwise.
-
getChunkVisibility
Fetches the visibility state of a chunk column using a flat 2D disc test around the player. This is the column-level (legacy) view of visibility and does not match the sphere predicate that drives section load/unload. For per-section visibility usegetSectionVisibility(int, int, int)instead.- Parameters:
indexChunk- The index of the chunk to check.- Returns:
- the
ChunkTracker.ChunkVisibilitystate of the chunk.
-
getSectionVisibility
Fetches the visibility state of a chunk section. The 3D analog ofgetChunkVisibility(long). Uses the sphere predicate that drives section load/unload for the COLD test and a Euclidean sphere of radiusmaxHotLoadedRadiusfor the HOT test.- Parameters:
x- The section X coordinate.y- The section Y coordinate.z- The section Z coordinate.- Returns:
- the
ChunkTracker.ChunkVisibilitystate of the section.
-
getMaxSectionsPerSecond
public int getMaxSectionsPerSecond()- Returns:
- the maximum sections per second allowed to be sent to the player.
-
setMaxSectionsPerSecond
public void setMaxSectionsPerSecond(int maxSectionsPerSecond) Called to set the maximum sections per second allowed to be sent to the player.- Parameters:
maxSectionsPerSecond- The maximum sections per second.
-
setDefaultMaxSectionsPerSecond
-
getMaxSectionsPerTick
public int getMaxSectionsPerTick()- Returns:
- the maximum sections per tick allowed to be sent to the player.
-
setMaxSectionsPerTick
public void setMaxSectionsPerTick(int maxSectionsPerTick) Called to set the maximum sections per tick allowed to be sent to the player.- Parameters:
maxSectionsPerTick- the maximum sections per tick allowed to be sent to the player.
-
getMinLoadedRadius
public int getMinLoadedRadius()- Returns:
- the minimum loaded chunks radius.
-
setMinLoadedRadius
public void setMinLoadedRadius(int minLoadedRadius) Called to set the minimum loaded chunks radius.- Parameters:
minLoadedRadius- the minimum loaded chunks radius.
-
getMaxHotLoadedRadius
public int getMaxHotLoadedRadius()- Returns:
- the maximum hot loaded chunks radius.
-
setMaxHotLoadedRadius
public void setMaxHotLoadedRadius(int maxHotLoadedRadius) Called to set the maximum hot loaded chunks radius.- Parameters:
maxHotLoadedRadius- the maximum hot loaded chunks radius.
-
getLoadedSectionsCount
public int getLoadedSectionsCount()Returns the number of sections loaded by the player that owns this tracker.- Returns:
- The number of sections loaded by the player
-
forEachLoadedSection
Visits each section the client has received from this tracker, callingconsumer.accept(x, y, z)once per section under the tracker's read lock.The consumer must not mutate the tracker (directly or via a method that takes the write lock). The lock is not reentrant.
- Parameters:
consumer- Called once per loaded section.
-
getLoadingSectionsCount
public int getLoadingSectionsCount()Returns the number of sections being loaded by the player that owns this tracker.- Returns:
- The number of sections being loaded by the player
-
getLoadedChunksDebug
Formats a debug string containing tracker state and two top-down grids: loaded section counts per column and hot section counts per column. Each cell holds a 2-digit number plus a trailing space; untracked columns render as" . ". The grids are centred on the player's column.- Returns:
- a debug string suitable for the server dump.
-
setReadyForChunks
public void setReadyForChunks(boolean readyForChunks) Called to set whether the chunk tracker is ready to send chunks.- Parameters:
readyForChunks- whether the chunk tracker is ready to send chunks.
-
isReadyForChunks
public boolean isReadyForChunks()- Returns:
trueif the chunk tracker is ready to send chunks,falseotherwise.
-
copyFrom
Called to copy the state from anotherChunkTrackerinstance.Only
ChunkTracker.ColumnState.READYcolumns and their loaded section sets are carried over. Those represent state the client already has. In-flight columns/sections are dropped because the source tracker still owns their async load chains; the spiral re-walk triggered by resettingsentViewRadiusSqwill re-issue any loads we need.- Parameters:
chunkTracker- The otherChunkTrackerinstance to copy from.
-
tryLoadColumnAsync
public void tryLoadColumnAsync(@Nonnull ChunkStore chunkStore, @Nonnull PlayerRef playerRefComponent, long chunkIndex, @Nonnull TransformComponent transformComponent, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Called to try and load a chunk asynchronously for the given player.- Parameters:
chunkStore- The chunk store.playerRefComponent- ThePlayerRefcomponent of the player.chunkIndex- The index of the chunk to load.transformComponent- TheTransformComponentof the player.componentAccessor- TheComponentAccessor<EntityStore>for component access.
-
tryLoadSectionAsync
public void tryLoadSectionAsync(@Nonnull ChunkStore chunkStore, @Nonnull PlayerRef playerRefComponent, int x, int y, int z, @Nonnull TransformComponent transformComponent, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Called to try and load a section asynchronously for the given player. MirrorstryLoadColumnAsync(ChunkStore, PlayerRef, long, TransformComponent, ComponentAccessor)but for a single section identified by its (x, y, z) chunk-section coordinates.Caller is expected to have placed
yin the parentChunkTracker.TrackedColumn.loadingSectionsset before invoking; this method takes responsibility for the transition from that set once the load completes (success: move toloadedSections; failure / null ref: drop so it can be retried next tick).- Parameters:
chunkStore- The chunk store.playerRefComponent- ThePlayerRefcomponent of the player.x- The section's x position.y- The section's y position.z- The section's z position.transformComponent- TheTransformComponentof the player.componentAccessor- TheComponentAccessor<EntityStore>for component access.
-
clone
- Specified by:
clonein interfaceComponent<EntityStore>- Returns:
- a clone instance of the original component instance.
-
calculateSectionPriority
public float calculateSectionPriority(int x, int y, int z) -
calculateColumnPriority
public float calculateColumnPriority(int x, int z)
-