Skip to content

Game.Simulation.AvailabilityInfoCell

Assembly:
Namespace: Game.Simulation

Type: struct

Base: IAvailabilityInfoCell, IStrideSerializable, ISerializable

Summary:
Represents a compact availability metrics container used by the simulation. The struct stores four float channels (Unity.Mathematics.float4) that represent, in order: attractiveness (x), consumers (y), workplaces (z) and services (w). It provides small helper methods to add amounts to each channel, and implements serialization and stride reporting for binary persistence/transfer.


Fields

  • public Unity.Mathematics.float4 m_AvailabilityInfo
    Holds the packed availability values:
  • x = attractiveness
  • y = consumers
  • z = workplaces
  • w = services Stored as float4 for compactness and SIMD-friendly layout.

Properties

  • (none)
    This struct exposes no properties; data is accessed/modified via the public field and the Add* methods.

Constructors

  • public AvailabilityInfoCell()
    Implicit default parameterless struct constructor (auto-generated). All components of m_AvailabilityInfo default to 0.0f.

Methods

  • public void AddAttractiveness(float amount)
    Adds amount to m_AvailabilityInfo.x (attractiveness).

  • public void AddConsumers(float amount)
    Adds amount to m_AvailabilityInfo.y (consumers).

  • public void AddWorkplaces(float amount)
    Adds amount to m_AvailabilityInfo.z (workplaces).

  • public void AddServices(float amount)
    Adds amount to m_AvailabilityInfo.w (services).

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the float4 m_AvailabilityInfo to the provided writer. Used by the game's serialization pipeline (Colossal.Serialization).

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads m_AvailabilityInfo from the provided reader.

  • public int GetStride(Context context)
    Returns the byte stride required to store this struct when serialized: UnsafeUtility.SizeOf(). For float4 this is typically 16 bytes. The Context parameter is unused in the implementation.

Usage Example

// create and modify
var cell = new AvailabilityInfoCell();
cell.AddAttractiveness(1.25f);
cell.AddConsumers(3f);
cell.AddWorkplaces(2f);
cell.AddServices(0.5f);

// read raw channels
Unity.Mathematics.float4 raw = cell.m_AvailabilityInfo;
float attractiveness = raw.x;
float consumers = raw.y;

// serialization (pseudo-code, depends on IWriter/IReader implementations)
writer.Write(cell.m_AvailabilityInfo); // equivalent to cell.Serialize(writer)
reader.Read(out cell.m_AvailabilityInfo); // equivalent to cell.Deserialize(reader)

Additional notes: - The struct is purposefully simple and allocation-free, suitable for large arrays or native/managed interop. - The GetStride method uses UnsafeUtility.SizeOf(), so stride equals size of 4 floats (usually 16 bytes). - Because the field is public and mutable, take care when sharing instances across threads; the type itself does not enforce thread-safety.