Class PropChunkLedger
Which of one scene's prop collision chunks are wanted, kept by reference count: every focus point holds the chunks round the 32 m cell it stands in, and a chunk is wanted while any focus holds it. The bookkeeping half of PropColliderStreamer, with no Unity objects in it, so it is testable on its own.
public sealed class PropChunkLedger
- Inheritance
-
PropChunkLedger
- Inherited Members
Remarks
By cell, not by point. A focus is placed again only when it crosses into another cell (or its radius changes), and then holds every chunk within its radius of ANY point of that cell (CellGap(int, int, float)). That is a superset of the chunks within its radius of where it actually stands (PointGap(Vector3, int, int, float)), for every point in the cell, so moving inside a cell never needs a chunk the focus does not already hold.
Released late. A held chunk is let go only once it is more than the radius and the release margin from the focus's cell, so a focus pacing across a cell edge does not empty and rebuild the chunks along the far rim each time. It only ever keeps more collision, never less.
Constructors
PropChunkLedger(float, HashSet<long>)
public PropChunkLedger(float cellMetres, HashSet<long> propCells)
Parameters
Fields
Acquired
Chunks a hold newly took since the lists were last cleared, each with its distance from the focus then.
public readonly List<(long cell, float distance)> Acquired
Field Value
CellMetres
Chunk side, metres.
public readonly float CellMetres
Field Value
PropCells
The chunks that have collidable props; no other chunk is ever wanted.
public readonly HashSet<long> PropCells
Field Value
Released
Chunks whose last hold let go since the lists were last cleared. One may be wanted again by now: check IsWanted(long).
public readonly List<long> Released
Field Value
Properties
Wanted
Every wanted chunk.
public Dictionary<long, int>.KeyCollection Wanted { get; }
Property Value
WantedCount
Chunks wanted by at least one hold.
public int WantedCount { get; }
Property Value
Methods
CellGap(int, int, float)
Least distance between two chunks' squares dx, dz chunks apart: never more
than PointGap(Vector3, int, int, float) from any point of the one to the other, in float arithmetic as well (each step is
monotonic and the whole-chunk gaps are exact), which is what makes holding by cell a superset.
public static float CellGap(int dx, int dz, float cellMetres)
Parameters
Returns
CellsNear(int, int, float, List<long>)
The chunks with props within radius of any point of cell (x, z).
public void CellsNear(int x, int z, float radius, List<long> into)
Parameters
Drop(Hold)
Lets go of everything a hold keeps; it is placed afresh next time.
public void Drop(PropChunkLedger.Hold hold)
Parameters
holdPropChunkLedger.Hold
IsWanted(long)
public bool IsWanted(long cell)
Parameters
celllong
Returns
Key(int, int)
public static long Key(int x, int z)
Parameters
Returns
Place(Hold, Vector3, float, float)
Places a hold at at: when that is a new cell (or radius) for it, it lets go of the chunks now
beyond radius + releaseMargin of the cell and takes every chunk within
radius of it. Returns whether anything was recomputed.
public bool Place(PropChunkLedger.Hold hold, Vector3 at, float radius, float releaseMargin)
Parameters
holdPropChunkLedger.HoldatVector3radiusfloatreleaseMarginfloat
Returns
PointCells(Vector3, float, float, List<(long cell, float distance)>)
The chunks within radius of the point at (whether they have props or not),
with their distances: the per-point rule, as the streamer measured it before chunks were held by cell.
public static void PointCells(Vector3 at, float radius, float cellMetres, List<(long cell, float distance)> into)
Parameters
PointGap(Vector3, int, int, float)
Distance from a point to chunk (x, z)'s square, horizontally.
public static float PointGap(Vector3 at, int x, int z, float cellMetres)
Parameters
Returns
References(long)
How many holds keep cell wanted.
public int References(long cell)
Parameters
celllong
Returns
Unkey(long, out int, out int)
public static void Unkey(long key, out int x, out int z)