Skip to content

Game.Simulation.IPopulationCell

Assembly:
Assembly-CSharp (typical for game code; adjust to actual mod assembly if different)

Namespace: Game.Simulation

Type:
interface

Base:
None (interface)

Summary:
Interface representing a simple population cell used by the simulation to accumulate and report a numeric population/amount value. Implementers provide storage and behavior for adding an amount and retrieving the current value. The interface itself is minimal and does not dictate concurrency or clamping behavior — those details are left to specific implementations.


Fields

  • None
    No backing fields are declared by the interface. Concrete implementations will provide their own storage.

Properties

  • None
    The interface exposes only methods; no properties are defined.

Constructors

  • Not applicable
    Interfaces do not define constructors. Concrete implementations will provide construction behavior.

Methods

  • void Add(float amount)
    Adds the provided amount to the cell. Typical uses: incrementing or decrementing the stored population/value. The interface does not define how negative amounts should be handled or whether values should be clamped; implementers must decide whether to accept negative deltas, enforce minimum/maximum limits, and handle threading concerns.

  • float Get()
    Returns the current stored amount/value for this cell. The return value semantics (for example whether it can be negative or if it's clamped) depend on the concrete implementation.

Usage Example

// Simple thread-safe implementation of IPopulationCell
public class PopulationCell : Game.Simulation.IPopulationCell
{
    private float _amount;
    private readonly object _lock = new object();

    public void Add(float amount)
    {
        lock (_lock)
        {
            _amount += amount;
            // Optionally clamp: _amount = Math.Max(0f, _amount);
        }
    }

    public float Get()
    {
        lock (_lock)
        {
            return _amount;
        }
    }
}

// Example usage
var cell = new PopulationCell();
cell.Add(12.5f);
float current = cell.Get(); // 12.5f

Notes: - If your simulation runs across multiple threads or jobs, ensure your implementation handles synchronization or uses thread-safe patterns appropriate for the engine (jobs, atomic operations, or main-thread-only access). - Decide whether negative amounts are allowed and whether values should be clamped (e.g., minimum 0) based on how the simulation uses the cell.