Game.Net.Bottleneck
Assembly:
Namespace: Game.Net
Type: struct
Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a traffic bottleneck state used by the game's networking/traffic systems. Stores a central position (m_Position), an optional min/max range (m_MinPos / m_MaxPos) describing the extent of the bottleneck, and a timer (m_Timer) used to track how long the bottleneck has been active. Implements Colossal.Serialization.ISerializable for efficient network/storage I/O and Unity ECS IComponentData/IQueryTypeParameter to be attachable to entities. The deserialization is backward-compatible: older saved data that lacks separate min/max positions will have m_MinPos and m_MaxPos set to m_Position.
Fields
-
public byte m_Position
The central position of the bottleneck (stored as a byte). In the constructor this is computed as the average of min and max positions (rounded up). -
public byte m_MinPos
Minimum position of the bottleneck range (byte). For older data formats that do not include min/max, this will be set equal to m_Position during Deserialize. -
public byte m_MaxPos
Maximum position of the bottleneck range (byte). For older data formats that do not include min/max, this will be set equal to m_Position during Deserialize. -
public byte m_Timer
A small timer/counter (byte) representing how long the bottleneck has been active (or other timing semantics as used by the caller).
Properties
This type does not declare any C# properties. It is a plain value-type component with public fields.
Constructors
public Bottleneck(byte minPos, byte maxPos, byte timer)
Constructs a Bottleneck with the given min/max positions and timer. m_Position is computed as (minPos + maxPos + 1) >> 1 — i.e., the integer average of min and max, rounded up. m_MinPos and m_MaxPos are set directly from the arguments, and m_Timer is set from timer.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the four fields in order: m_Position, m_MinPos, m_MaxPos, m_Timer. Uses the provided IWriter implementation. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads m_Position first. Then, if reader.context.version >= Version.trafficBottleneckPosition, reads m_MinPos and m_MaxPos from the stream. Otherwise (older versions) assigns m_MinPos = m_Position and m_MaxPos = m_Position to preserve compatibility. Finally reads m_Timer. Uses the provided IReader implementation.
Notes: - Serialization/deserialization order must match to ensure correct round-trip. - The version check (Version.trafficBottleneckPosition) enables backward compatibility with saved/networked data that only stored a single position.
Usage Example
// Create a Bottleneck spanning positions 10..12 with timer 5
var bottleneck = new Bottleneck(minPos: 10, maxPos: 12, timer: 5);
// Access fields
byte center = bottleneck.m_Position; // (10 + 12 + 1) >> 1 => 11
// Add to an ECS entity
// EntityManager em = ...;
// em.AddComponentData(entity, bottleneck);
// Serialization (pseudo-code — replace with actual writer/reader implementations)
IWriter writer = GetWriter();
bottleneck.Serialize(writer);
// Deserialization (pseudo-code)
IReader reader = GetReader();
Bottleneck loaded = default;
loaded.Deserialize(reader);
// If reading old data (version < Version.trafficBottleneckPosition),
// loaded.m_MinPos and loaded.m_MaxPos will be equal to loaded.m_Position.
{{ This struct is intended for use in the traffic/networking systems of Cities: Skylines 2 mods. Treat its fields as compact, on-disk/network representations (bytes) and prefer creating/updating instances atomically when used as an ECS component. Ensure serialization writer/reader versions are compatible when exchanging saved/networked data; the built-in version check handles older formats that only had a single position. }}