Nebula
World partition

WorldStreamer

Loads and unloads cell scenes additively and keeps them placed relative to the floating origin.

generated from the sources
Class in namespace Nebula.World · Packages/com.1by3.nebula/World/WorldStreamer.cs
[DefaultExecutionOrder(-500)]
public sealed class WorldStreamer : MonoBehaviour

Loads and unloads cell scenes additively and keeps them placed relative to the floating origin. Which cells are wanted comes from two sources that are unioned every policy pass:

  • anchors (IWorldAnchor): a position plus a radius in cells; the cube of cells around each anchor is loaded. A WorldAnchor component on the player is the usual one.
  • required cells (SetRequired): an explicit set, for callers that know exactly what they need (a server that simulates a region and wants its cells and a ring around them).

Cells leaving the wanted set linger LingerSeconds before unloading so a player pacing on a boundary does not thrash. When AutoShiftOrigin is on and the primary anchor strays more than ShiftThresholdCells from the origin cell, the origin moves to the anchor's cell: every loaded cell's root objects are translated and WorldOrigin.Shifted tells everyone else.

Works on its own (no Nebula dependency); Nebula's integration drives it from leases and the local pawn.

Fields

Definition

public WorldDefinition Definition;

LingerSeconds

public float LingerSeconds = 3f;

Cells stay loaded this long after nothing wants them any more.

MaxConcurrentLoads

public int MaxConcurrentLoads = 2;

How many cell scenes may be loading at once.

PolicyIntervalSeconds

public float PolicyIntervalSeconds = 0.25f;

How often the wanted set is recomputed.

AutoShiftOrigin

public bool AutoShiftOrigin = true;

Move the floating origin to follow the primary anchor.

ShiftThresholdCells

public int ShiftThresholdCells = 1;

Shift once the primary anchor is more than this many cells from the origin cell on any axis.

Passive

public bool Passive;

Load nothing on the streamer's own initiative (a process that only needs the grid maths).

Properties

Instance

public static WorldStreamer Instance { get; }

PrimaryAnchor

public IWorldAnchor PrimaryAnchor { get; set; }

Anchor that the floating origin follows. Defaults to the first registered anchor.

LoadedCount

public int LoadedCount { get; }

LoadsInFlight

public int LoadsInFlight { get; }

HasPendingWork

public bool HasPendingWork { get; }

LoadedCells

public IEnumerable<Vector3Int> LoadedCells { get; }

Events

CellLoaded

public event Action<Vector3Int, Scene> CellLoaded;

CellUnloading

public event Action<Vector3Int, Scene> CellUnloading;

CellUnloaded

public event Action<Vector3Int> CellUnloaded;

OriginShifted

public event Action<Vector3> OriginShifted;

The origin moved by this delta (after the loaded cells were translated). Same as WorldOrigin.Shifted.

Methods

IsLoaded

public bool IsLoaded(Vector3Int coord);

TryGetScene

public bool TryGetScene(Vector3Int coord, out Scene scene);

AddAnchor

public void AddAnchor(IWorldAnchor anchor);

RemoveAnchor

public void RemoveAnchor(IWorldAnchor anchor);

SetRequired

public void SetRequired(IEnumerable<Vector3Int> cells);

Replace the explicitly required set. Cells outside the definition are ignored.

Poke

public void Poke();

Recompute the wanted set on the next frame instead of waiting for the policy interval.

ShiftOrigin

public void ShiftOrigin(Vector3Int cell);

Move the floating origin to cell now (no-op if it already is there).

ComputeWanted

public static void ComputeWanted(WorldDefinition definition, IList<(Vector3Int cell, int radius)> anchors, IEnumerable<Vector3Int> required, HashSet<Vector3Int> result);

The set of cells to have loaded: the cube of radius cells around every anchor plus the required set, limited to cells the definition has. Pure, so it is testable without scenes.

Nested types

CellStatus

public enum CellStatus

Members

NameValueDescription
Loading
Loaded
Unloading

On this page