Nebula
Interest

RegionKeys

How an interest region id is made unique to its scope.

generated from the sources
public static class RegionKeys

How an interest region id is made unique to its scope. A region id is a packing of absolute coordinates (InterestGrid.PackRegion), and with per-scope origin frames two scopes may legitimately occupy exactly the same absolute coordinates on one worker (docs/scope-frames.md). Without a salt, region (3, 0, 7) of two worlds is one key in the worker's index, one entry in a gateway's subscription set and one bucket in the publisher's masks — so a worker would stream a gateway the entities of a scope that gateway has no client in, and drop them again on the per-client instance check. That was the deliberate cost recorded as docs/scoped-chunk-grids.md D12; this closes it.

The salt is an XOR with a strong mix of the scope's isolation id, so it is invertible by any holder that knows which scope the id belongs to — which both ends always do, because a subscription, a focus and an entity each sit in exactly one scope. That is what keeps the region arithmetic (InterestGrid.BoundsOf, InterestGrid.SqrDistanceToRegion) working on the plain packing while the keys that travel and the keys that bucket are per scope.

The public world is not salted at all (Salt with 0 is the identity), so an unscoped mesh puts exactly the bytes on the wire it did before, and no message, field or protocol version changed.

Methods

SaltOf

public static ulong SaltOf(ulong instanceId);
public static ulong SaltOf(ulong instanceId, ulong frameKey);

SplitMix64 finalizer of the isolation id: the per-scope constant the region id is XORed with.

Salt

public static ulong Salt(ulong region, ulong instanceId);
public static ulong Salt(ulong region, ulong instanceId, ulong frameKey);

The key a region of instanceId is known by: the plain packing in the public world, and the packing XORed with the scope's salt everywhere else.

Unsalt

public static ulong Unsalt(ulong key, ulong instanceId);
public static ulong Unsalt(ulong key, ulong instanceId, ulong frameKey);

The inverse of Salt: the plain packing the region arithmetic works on.

FrameKeyOf

public static ulong FrameKeyOf(ContainerRef reference);

The key of a physics frame whose contents are bucketed in regions of its own (FrameInterestMode.OwnRegions, docs/container-tree.md D18): a planet's surface is bucketed in the planet's coordinates, so its rotation never churns regions in system space. Made from the container's wire name, which the worker and the gateway both hold; 0 for no reference.

On this page