Skip to content

Game.Net.LaneOverlap

Assembly:
Assembly-CSharp (Assembly-CSharp.dll)

Namespace:
Game.Net

Type:
struct

Base:
Implements: Unity.Entities.IBufferElementData, IEmptySerializable, System.IComparable

Summary:
Represents an overlap entry between two lane entities in the ECS world. This struct is intended to be stored in an entity buffer (IBufferElementData) to describe how one lane overlaps with another — including the overlapping ranges on each lane, flags describing the overlap, a measure of parallelism, and a priority delta used for ordering or decision-making. Numeric overlap and parallelism values are compactly encoded into bytes to minimize memory usage and bandwidth in serialization.


Fields

  • public Unity.Entities.Entity m_Other
    Stores the Entity reference of the other lane involved in the overlap.

  • public OverlapFlags m_Flags
    Flags describing properties of the overlap. (OverlapFlags is an enum defined elsewhere in the codebase; it typically encodes qualitative properties of the overlap such as direction, containment, or special cases used by traffic logic.)

  • public byte m_ThisStart
    Start of the overlap range on "this" lane, encoded as a byte. The constructor maps a floating-range value into 0..255.

  • public byte m_ThisEnd
    End of the overlap range on "this" lane, encoded as a byte (0..255).

  • public byte m_OtherStart
    Start of the overlap range on the other lane, encoded as a byte (0..255).

  • public byte m_OtherEnd
    End of the overlap range on the other lane, encoded as a byte (0..255).

  • public byte m_Parallelism
    A compact encoding of the parallelism measure between the two lanes. In the constructor this is computed as round(parallelism * 128) clamped to [0,255] and stored as a byte. Consumers must decode using the same scale factor.

  • public sbyte m_PriorityDelta
    Signed small integer representing a priority delta or offset between the lanes. Stored as sbyte (range -128..127).

Properties

  • This type has no properties (fields are public instance fields). It is primarily used as a raw buffer element in ECS.

Constructors

  • public LaneOverlap(Unity.Entities.Entity other, Unity.Mathematics.float4 overlap, OverlapFlags flags, float parallelism, int priorityDelta)
    Constructs a compact LaneOverlap entry.

Details: - overlap: expected as float4 holding four normalized values (presumably in range 0..1) representing [thisStart, thisEnd, otherStart, otherEnd]. Each component is multiplied by 255, rounded, clamped to [0,255], and stored into the corresponding byte field. - parallelism: multiplied by 128, rounded and clamped to [0,255], then stored in m_Parallelism (byte). Decoding should divide the stored value by 128.0f to approximate the original. - priorityDelta: stored as sbyte; values outside sbyte range will be truncated.

This constructor is optimized for compact storage and serialization inside ECS buffers.

Methods

  • public int CompareTo(LaneOverlap other)
    Provides ordering by packing this lane's start and end into a 16-bit key ((m_ThisStart << 8) | m_ThisEnd) and subtracting the same key from the other. Effectively sorts overlaps first by m_ThisStart, then by m_ThisEnd. Useful for stable ordering of overlap entries (e.g., when merging, deduplicating or iterating overlaps in a consistent order).

Implementation note: Because the packed value is treated as an int subtraction, the result follows standard integer comparison semantics; this CompareTo does not consider other fields (m_Other, flags, priority, etc.).

Usage Example

// Example: create a LaneOverlap representing a 10%-30% overlap on this lane
// and 40%-60% on the other lane, with some flags, parallelism and priority delta.

using Unity.Mathematics;
using Unity.Entities;

Entity otherLane = /* obtain other lane entity */;
float4 overlap = new float4(0.10f, 0.30f, 0.40f, 0.60f);
OverlapFlags flags = OverlapFlags.None; // example; use appropriate flags
float parallelism = 0.75f; // will be stored as round(0.75*128) = 96
int priorityDelta = 1;

LaneOverlap entry = new LaneOverlap(otherLane, overlap, flags, parallelism, priorityDelta);

// Typical usage: add to an entity's dynamic buffer:
var buffer = entityManager.GetBuffer<LaneOverlap>(laneEntity);
buffer.Add(entry);

// Sorting the buffer by range:
buffer.AsNativeArray().Sort(); // relies on CompareTo to sort by thisStart/thisEnd

Notes and recommendations: - Because overlap and parallelism are quantized when constructed, avoid assuming perfect fidelity when reconstructing floating values; use the same scale factors (255 for overlap components, 128 for parallelism) to decode. - This struct is designed for low-memory, high-performance ECS usage; prefer using its packed representation when serializing or transferring across systems.