Class SphereOffsets
A point (dx, dy, dz) is inside when dx² + dy² + dz² <= R².
Build once at the server's maximum allowed radius and share the resulting instance
across every SphereSpiralIterator; each player iterator records its own
(smaller-or-equal) radius and the iterator's upfront binary search clamps the cursor so a
player smaller than the shared maximum walks only their portion of the list. Because the
list is sorted by distSq, every offset before the player's clamp is guaranteed
inside the player's sphere, so no per-cell filter is needed in the hot loop.
Memory: roughly 10 bytes per offset (three shorts plus an int
for distSq). At R=24 the list is ~58k offsets ≈ 580 KB.
Thread-safe: all fields are final, all arrays are read-only after construction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intNumber of offsets stored (length of each array).final int[]distSq[i] = dx[i]² + dy[i]² + dz[i]², sorted ascending.final short[]Offset x-components in distance² order.final short[]Offset y-components in distance² order.final short[]Offset z-components in distance² order.final intRadiusRthe list was built for. -
Method Summary
Modifier and TypeMethodDescriptionstatic SphereOffsetsbuild(int maxR) Builds the sorted offset list for a sphere of the given radius.
-
Field Details
-
dx
@Nonnull public final short[] dxOffset x-components in distance² order. Read-only. -
dy
@Nonnull public final short[] dyOffset y-components in distance² order. Read-only. -
dz
@Nonnull public final short[] dzOffset z-components in distance² order. Read-only. -
distSq
@Nonnull public final int[] distSqdistSq[i] = dx[i]² + dy[i]² + dz[i]², sorted ascending. Read-only. -
count
public final int countNumber of offsets stored (length of each array). -
maxR
public final int maxRRadiusRthe list was built for.
-
-
Method Details
-
build
Builds the sorted offset list for a sphere of the given radius.One-shot cost is dominated by the sort: roughly
O(V log V)whereVis the sphere's cell count. AtR=24this is a few ms on contemporary hardware. Intended to run once at server startup (and again on configuration reload).- Parameters:
maxR- radius, must be>= 0- Returns:
- the immutable, sorted offset list
-