Table of Contents

Class ObserverProximityGrid

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

A uniform horizontal grid over one scene's registered objects, so ranking a viewer reads only the objects that could be within reach of it instead of every object in the scene.

public sealed class ObserverProximityGrid
Inheritance
ObserverProximityGrid
Inherited Members

Remarks

A superset, never a filter of its own. Query(Vector3, float, List<int>) returns every object whose cell overlaps the square round the point, padded by QueryMargin, so anything within the radius in 3D (horizontal distance is never more than 3D distance) is always in it, rounding included. The caller still measures each one exactly as before and applies the same tests; the grid only skips objects no test could pass.

Dense, sorted by cell. The objects' bounding box of cells is one array, and the object indices are sorted by cell (a counting sort), row by row, so each row of a query's square is one contiguous run: a query costs a few array reads per row plus the objects it returns, with no hashing. A box that would be too many cells for the object count (a few far-flung objects) doubles the cell size until it is not.

Fields

QueryMargin

Padding round every query, metres: far more than any float rounding at world coordinates.

public const float QueryMargin = 1

Field Value

float

Properties

CellSize

Cell side, metres.

public float CellSize { get; }

Property Value

float

Count

Objects in the grid.

public int Count { get; }

Property Value

int

Methods

Build(List<Vector3>, float)

Files each position by index, replacing whatever the grid held.

public void Build(List<Vector3> positions, float cellSize)

Parameters

positions List<Vector3>
cellSize float

Query(Vector3, float, List<int>)

Every object that could be within radius of at, by index, in no particular order. Every object for an infinite or NaN radius.

public void Query(Vector3 at, float radius, List<int> into)

Parameters

at Vector3
radius float
into List<int>