Game.UtilityLane
Assembly: Assembly-CSharp
Namespace: Game.Net
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
UtilityLane is a small ECS component used by the game's networking/simulation systems to record per-lane utility flags. It stores a bitmask (UtilityLaneFlags) and implements Colossal's generic serialization interfaces so it can be efficiently written to and read from network/save streams or other serialized representations used by the engine.
Fields
public UtilityLaneFlags m_Flags
Stores the lane's utility state as a bitmask of UtilityLaneFlags. This field is written as an unsigned 32-bit integer during serialization and restored by casting the read value back to the enum. Default value is the enum's default (0) when the struct is default-constructed.
Properties
- This struct exposes no C# properties. Use the public field m_Flags to read or modify the flag bits.
Constructors
public UtilityLane()
Structs in C# have an implicit parameterless constructor which initializes m_Flags to its default value (typically 0). To initialize with a specific flag set, construct with an object initializer: new UtilityLane { m_Flags = UtilityLaneFlags.SomeFlag }
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to a writer by casting the flags to uint and calling writer.Write((uint)m_Flags). This is the method used by the engine's serialization pipeline for network or disk I/O. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads a uint from the reader, casts it back to UtilityLaneFlags, and stores the result in m_Flags. This restores the component's flag state from serialized data.
Notes: - The methods are generic over writer/reader types constrained by IWriter/IReader; they rely on those interfaces' primitive read/write methods for efficient serialization. - UtilityLaneFlags is treated as a 32-bit bitmask; ensure any added enum members fit within the uint range and maintain backward compatibility for serialization.
Usage Example
// Create a UtilityLane component and set flags
var laneComponent = new UtilityLane { m_Flags = UtilityLaneFlags.HasPower | UtilityLaneFlags.HasWater };
// Add the component to an entity (EntityManager usage)
entityManager.AddComponentData(someLaneEntity, laneComponent);
// Example: manual serialization using a hypothetical writer
using (var writer = new SomeConcreteWriter(...))
{
laneComponent.Serialize(writer);
}
// Example: manual deserialization using a hypothetical reader
UtilityLane loaded = default;
using (var reader = new SomeConcreteReader(...))
{
loaded.Deserialize(reader);
}
// Example: update flags later
loaded.m_Flags |= UtilityLaneFlags.NeedsRepair;
entityManager.SetComponentData(someLaneEntity, loaded);
Additional tips: - Use bitwise operations to test/set/clear specific flags in m_Flags. - Because this is an IComponentData, prefer bulk operations (ComponentDataFromEntity, archetype creation, or jobs) when modifying or reading many instances for performance in large simulations.