Skip to content

Game.EdgeLane

Assembly: Assembly-CSharp
Namespace: Game.Net

Type: struct (public)
Base: System.ValueType, implements Unity.Entities.IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary: Represents edge lane metadata used by the network system. Stores a two-component float2 (m_EdgeDelta) describing the relative positions/offsets along the edge (commonly one of 0, 0.5 or 1) and two byte counters for the number of connections at the start and end of the lane. Implements a compact serialization scheme that encodes common edgeDelta pairs into a single byte to reduce save size, and falls back to writing the full float2 when not matching a known pattern. The struct is an ECS component (IComponentData) and can be used in queries (IQueryTypeParameter).


Fields

  • public float2 m_EdgeDelta
    Stores the lane edge delta as two floats (x, y). Typical values are 0, 0.5, or 1 for each component. The Serialize/Deserialize methods apply a small-code optimization for common combinations of these values; otherwise the full float2 is written/read.

  • public byte m_ConnectedStartCount
    Number of connections at the start end of the lane. Stored as a byte.

  • public byte m_ConnectedEndCount
    Number of connections at the end of the lane. Stored as a byte.

Properties

  • This struct does not expose any C# properties. It contains public fields only and implements interfaces (IComponentData, IQueryTypeParameter, ISerializable).

Constructors

  • public EdgeLane() (implicit default)
    As a value type, EdgeLane has the implicit parameterless constructor. Default initialization sets m_EdgeDelta to (0,0) and the connection counts to zero.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the struct. Optimization logic:
  • Detects if m_EdgeDelta.x and m_EdgeDelta.y match the common set {0, 0.5, 1}.
  • If the pair matches one of six common combinations it writes a single byte code (1..6) representing that combination.
  • If none match it writes a zero byte and then writes the full float2.
  • The byte codes map to float2 values as follows:

    • 1 => (0f, 0.5f)
    • 2 => (0.5f, 1f)
    • 3 => (0f, 1f)
    • 4 => (1f, 0.5f)
    • 5 => (0.5f, 0f)
    • 6 => (1f, 0f)
  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the struct. Behavior:

  • If reader.context.version >= Version.saveOptimizations it reads one byte and maps codes 1..6 to the pre-defined float2 values listed above. If the byte is 0 (or an unknown code) it reads the full float2 from the stream.
  • If the saved version is older than Version.saveOptimizations it reads the float2 directly (no compact encoding applied).

Notes: - The Serialize/Deserialize generics depend on the Colossal.Serialization.Entities IWriter/IReader interfaces and a reader.context.version integer; ensure your reader/writer implementations provide these. - The code is designed to save space on common values while preserving full-precision fallback.

Usage Example

// Example: create an EdgeLane and serialize it with a writer.
// The actual writer/reader types come from Colossal.Serialization.Entities in the game's save system.

EdgeLane lane = new EdgeLane();
lane.m_EdgeDelta = new float2(0f, 0.5f); // common pair -> serialized as a single byte (1)
lane.m_ConnectedStartCount = 2;
lane.m_ConnectedEndCount = 1;

// Serialize (pseudocode - replace MyWriter with the game's writer type)
using (var writer = new MyWriter(/*stream, context, etc.*/))
{
    lane.Serialize(writer);
}

// Deserialize (pseudocode - replace MyReader with the game's reader type)
EdgeLane loaded = new EdgeLane();
using (var reader = new MyReader(/*stream, context, etc.*/))
{
    loaded.Deserialize(reader);
    // loaded.m_EdgeDelta will be (0f, 0.5f) for the example above
}

Additional info: - This component is intended for use in the game's ECS (Unity.Entities) pipeline and in the network/save systems. When writing custom serialization logic or migrating save formats, be mindful of the Version.saveOptimizations flag used to maintain backward compatibility.