Game.Simulation.WaterPipeEdge
Assembly:
Namespace: Game.Simulation
Type: struct
Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a water pipe edge in the simulation graph. Stores endpoints (Entities), flow and capacity for fresh water and sewage, a pollution value for fresh water, an index identifier, and edge flags. Implements IComponentData so it can be attached to entities in ECS, IQueryTypeParameter for query usage, and ISerializable to support save/load serialization with version-aware reading/writing.
Fields
-
public int m_Index
Index/identifier for the edge. Typically used as an internal ID for lookup or debugging. -
public Entity m_Start
Entity representing the edge's start node. -
public Entity m_End
Entity representing the edge's end node. -
public int m_FreshFlow
Current fresh water flow value through the edge. -
public float m_FreshPollution
Pollution level associated with the fresh water flow. Read/written conditionally based on save version. -
public int m_SewageFlow
Current sewage flow value through the edge. -
public int m_FreshCapacity
Capacity limit for fresh water flow. -
public int m_SewageCapacity
Capacity limit for sewage flow. -
public WaterPipeEdgeFlags m_Flags
Flags describing edge properties (stored as a byte during serialization). Flags presence depends on save version.
Properties
-
public int2 flow => new int2(m_FreshFlow, m_SewageFlow)
Convenience property returning fresh and sewage flows as a Unity.Mathematics.int2 (x = fresh, y = sewage). -
public int2 capacity => new int2(m_FreshCapacity, m_SewageCapacity)
Convenience property returning fresh and sewage capacities as a Unity.Mathematics.int2 (x = fresh capacity, y = sewage capacity).
Constructors
public WaterPipeEdge()
Struct has the default parameterless constructor (value-type default). Initialize fields manually when creating instances.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the edge's data to a serializer in a fixed order:- Writes start and end Entities
- Writes fresh flow (int)
- Writes fresh pollution (float)
- Writes sewage flow (int)
- Writes fresh capacity (int)
- Writes sewage capacity (int)
-
Writes flags as a single byte This method is used when saving simulation state.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the edge's data from a serializer and is version-aware: - Reads start and end Entities
- Reads fresh flow
- If reader.context.version >= Version.waterPipePollution, reads freshPollution (float); otherwise reads and discards an int placeholder
- Reads sewage flow, fresh capacity, sewage capacity
- For versions in [Version.stormWater, Version.waterPipeFlowSim) it reads and discards two ints (legacy values)
- If reader.context.version >= Version.waterPipeFlags it reads a byte and stores it into m_Flags This method ensures backward compatibility with older save formats.
Notes: - The order of reads/writes must match between Serialize and Deserialize. - Deserialize contains explicit version checks (Version.waterPipePollution, Version.stormWater, Version.waterPipeFlowSim, Version.waterPipeFlags) to handle format differences across game versions.
Usage Example
using Unity.Entities;
using Unity.Mathematics;
using Colossal.Serialization.Entities;
using Game.Simulation;
// create/populate an edge struct
var edge = new WaterPipeEdge
{
m_Index = 42,
m_Start = startEntity, // previously obtained Entity
m_End = endEntity, // previously obtained Entity
m_FreshFlow = 120,
m_FreshPollution = 0.0f,
m_SewageFlow = 30,
m_FreshCapacity = 300,
m_SewageCapacity = 200,
m_Flags = WaterPipeEdgeFlags.None
};
// attach to an ECS entity (example)
entityManager.AddComponentData(edgeEntity, edge);
// read convenience properties
int2 currentFlow = edge.flow; // x = fresh, y = sewage
int2 currentCapacity = edge.capacity;
Additional notes: - Requires Unity.Entities and Unity.Mathematics for ECS and int2 usage. - Serialization depends on the game's IWriter/IReader and Version constants; modders should ensure compatibility with the target game version when manipulating saved data.