Skip to content

Game.NoisePollution

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: struct

Base: System.ValueType

Summary:
Represents noise pollution values for a simulation cell/entity. Holds the stable pollution value and a temporary accumulator used during simulation ticks. Implements IPollution for pollution behavior and the serialization interfaces IStrideSerializable and ISerializable for efficient persistence and streaming. The serialized footprint is two 16-bit integers (4 bytes).


Fields

  • public short m_Pollution
    Stores the committed/current noise pollution value (16-bit signed). This is the value that represents the pollution persisted between simulation steps.

  • public short m_PollutionTemp
    Temporary accumulator for pollution changes within a frame or tick. Values added via Add(short) are accumulated here and clamped to a maximum of 32767 to avoid overflow. This field is also serialized.

Properties

  • None

Constructors

  • public NoisePollution()
    Implicit default struct constructor. Both m_Pollution and m_PollutionTemp are initialized to 0.

Methods

  • public void Add(short amount)
    Adds amount to the temporary accumulator (m_PollutionTemp). The result is clamped to 32767 using Unity.Mathematics.math.min to prevent exceeding the positive range of a signed 16-bit value.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the two short fields to the provided writer in order: m_Pollution, then m_PollutionTemp. Intended for saving or streaming the struct state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the two short fields from the provided reader into m_Pollution and m_PollutionTemp respectively. Uses ref locals to read directly into the struct fields.

  • public int GetStride(Context context)
    Implements IStrideSerializable. Returns 4, the total byte size of the serialized struct (2 bytes per short × 2).

Usage Example

// Create and use a NoisePollution instance
var noise = new Game.Simulation.NoisePollution();

// Add 10 units of noise to the temporary accumulator
noise.Add(10);

// Commit logic elsewhere might transfer m_PollutionTemp into m_Pollution
// (not shown here), and then serialize for saving:
// (IWriter implementation is game-specific; this shows intended usage)
IWriter writer = /* obtain writer */;
noise.Serialize(writer);

// Later, to restore:
IReader reader = /* obtain reader */;
var restored = new Game.Simulation.NoisePollution();
restored.Deserialize(reader);