RelevanceTiers
The arithmetic of RelevancePriority: pure, shared by the gateway, the worker and the tests.
Nebula · Packages/com.1by3.nebula/Runtime/Interest/RelevanceTiers.cspublic static class RelevanceTiersThe arithmetic of RelevancePriority: pure, shared by the gateway, the worker and the tests.
Fields
PriorityMask
public const EntityInterestFlags PriorityMask = (EntityInterestFlags)0b0000_0110;The bits of EntityInterestFlags that carry the priority.
Near, Middle, Far
public const int Near = 0, Middle = 1, Far = 2;Distance bands, nearest first.
Quiet
public const int Quiet = 0;A divisor meaning "send this client no unreliable updates for this entity".
Methods
WithPriority
public static EntityInterestFlags WithPriority(EntityInterestFlags flags, RelevancePriority priority);flags with its priority bits set to priority.
PriorityOf
public static RelevancePriority PriorityOf(EntityInterestFlags flags);The priority a spawn's interest flags carry; RelevancePriority.Normal from a sender that sets none.
BandOf
public static int BandOf(double sqrDistance, float nearRadius, float farRadius);The distance band of a squared distance: Near within the near radius, Middle within the far radius, Far beyond it or when there is no distance at all (double.MaxValue: a client with no focus in the entity's space).
Divisor
public static int Divisor(RelevancePriority priority, int band, int midDivisor, int farDivisor);Ticks per update window for an entity of priority in distance band band: 1 is every update, Quiet is none (see RelevancePriority).
Resolve
public static RelevanceTierBands Resolve(RelevancePriority priority, in RelevanceTierBands own, float nearRadius, float farRadius, int midDivisor, int farDivisor);The bands a priority uses under the global tiers nearRadius, farRadius, midDivisor and farDivisor: the priority's own when it has an RelevanceTierBands.Override, otherwise the global ones shifted as Divisor says. RelevancePriority.Normal always uses the global tiers: they are its tiers.
DivisorAt
public static int DivisorAt(in RelevanceTierBands bands, double sqrDistance);Ticks per update window for a client at squared distance sqrDistance from an entity whose priority resolved to bands (Resolve); Quiet is none.
CapForSpeed
public static int CapForSpeed(int divisor, float speed, float maxTravelPerUpdate, float tickInterval);divisor, lowered so that an entity moving at speed meters per second travels no more than maxTravelPerUpdate meters between two updates (InterestSettings.MaxTravelPerUpdate): a ship at 400 m/s 100 m away is sent every tick rather than every 12th, where it would move 80 m between updates. Never below 1, never above divisor; Quiet stays quiet (a priority that chose no updates in a band keeps that choice), and a maxTravelPerUpdate of 0 changes nothing.
StartsWindow
public static bool StartsWindow(uint tick, bool hasPrevious, uint previousTick, ulong netId, int divisor);Whether an entry at tick starts a new window of divisor ticks for this entity, given the tick of the entity's previous entry. A client whose rate is one update per window is sent the first entry of each window and nothing else in it. Windows are staggered by net id so a crowd's updates spread over the ticks of a window rather than landing on one.
This, and not "is the tick a multiple of the divisor", is what lets a gateway's rate compose with a worker that sends an entity only every NetworkIdentity.UpdateInterval ticks: an entity updated every 6 ticks and a client asking for every 4th tick get every update, where the tick test would match some entities never.