Game.Simulation.TrafficAmbienceCell
Assembly:
Namespace: Game.Simulation
Type: struct
Base: Colossal.Serialization.Entities.IStrideSerializable, Colossal.Serialization.Entities.ISerializable
Summary:
Lightweight, serializable container representing ambient traffic data for a single simulation cell. Stores two floats (an accumulator and a traffic value) and implements both stride-based and generic reader/writer serialization used by the game's persistence/serialization systems. Suitable for tight, memory-efficient storage and transfer.
Fields
-
public float m_Accumulator
Accumulator value for this cell. Typically used to accumulate ambient-related metrics over time (for example, integrating changes or storing a running value for smoothing). Serialized first in the struct's serialization order. -
public float m_Traffic
Traffic value for this cell. Represents the instantaneous (or sampled) traffic/ambience magnitude. Serialized second after the accumulator.
Properties
- This struct exposes no properties; all data is held in public fields.
Constructors
public TrafficAmbienceCell()
Default value-type constructor (implicit). Initializes both m_Accumulator and m_Traffic to 0.0f. No explicit constructor is defined in source.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct to a generic writer in a fixed order: first writes m_Accumulator, then m_Traffic. The writer type must implement IWriter (from Colossal.Serialization.Entities). Use this for standard (non-stride) serialization flows. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the struct from a generic reader in the same order as written. Uses ref locals to read directly into m_Accumulator and m_Traffic. The reader type must implement IReader. -
public int GetStride(Context context)
Implements IStrideSerializable.GetStride. Returns the stride (byte size) required to store the struct in stride-form serialization. This returns 8 (two 4-byte floats), which is the fixed byte size of this struct in stride mode.
Usage Example
// Create and populate
var cell = new TrafficAmbienceCell();
cell.m_Accumulator = 1.5f;
cell.m_Traffic = 0.75f;
// Example: writing with a generic writer (pseudo-code; obtain writer from the game's serialization API)
writer.Write(cell.m_Accumulator);
writer.Write(cell.m_Traffic);
// Example: stride usage - stride size is 8 bytes (2 floats)
int stride = cell.GetStride(someContext); // returns 8
// Example: reading back with a generic reader (pseudo-code)
ref float acc = ref cell.m_Accumulator;
reader.Read(out acc);
ref float traffic = ref cell.m_Traffic;
reader.Read(out traffic);
Notes: - The serialization order (accumulator then traffic) must be preserved across writer/reader usage. - Being a struct, instances are value types and will be copied by value. Keep that in mind when passing or storing instances.