Skip to content

Game.EndFrameBarrier

Assembly:
Namespace: Game.Economy

Type: struct Resources : IBufferElementData, ISerializable

Base: System.ValueType (implements Unity.Entities.IBufferElementData, Colossal.Serialization.Entities.ISerializable)

Summary: This struct represents a single resource entry used by the game's economy systems. It is intended to be stored in an ECS DynamicBuffer (IBufferElementData) and supports custom serialization/deserialization (ISerializable) for saves/load. Each entry pairs a Resource (an enum identifying the kind of resource, e.g., Electricity, Water, Money, etc.) with an integer amount. The serializer writes a compact sbyte index for the resource type followed by the int amount. During deserialization older save versions are handled with clamping logic for negative or excessively large amounts (except for Money).


Fields

  • private System.Diagnostics.Stopwatch m_Stopwatch This field is not present on this type. Instead, Resources contains the following public fields used to represent the resource and its quantity:
  • public Resource m_Resource — the resource type (enum). The code stores/reads this as an sbyte index via EconomyUtils.GetResourceIndex / EconomyUtils.GetResource.
  • public int m_Amount — the integer amount of that resource.

  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField This field is not present on this type. See above for the actual fields (m_Resource, m_Amount).

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set } There are no properties declared in this struct. The struct exposes two public fields (m_Resource, m_Amount) and implements serialization methods.

{{ Notes on interfaces: - IBufferElementData: intended to be used inside a Unity ECS DynamicBuffer. - ISerializable (Colossal.Serialization.Entities.ISerializable): provides Serialize/Deserialize methods used by the game's save system. }}

Constructors

  • public EndFrameBarrier() As a value type (struct), Resources has the default implicit parameterless constructor. No explicit constructors are declared in the source.

Methods

  • protected virtual OnCreate() : System.Void Not applicable to this struct. The actual methods implemented are:

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter

    • Behavior: Writes the resource type as an sbyte (EconomyUtils.GetResourceIndex(m_Resource)) and then writes the m_Amount as an int. This provides a compact on-disk format for resource entries.
    • Generic constraint: TWriter must implement the writer interface used by the Colossal save system.
  • public void Deserialize<TReader>(TReader reader) where TReader : IReader

    • Behavior:
    • Reads an sbyte value that identifies the resource type, then reads an int into m_Amount.
    • Converts the resource index to a Resource enum via EconomyUtils.GetResource(value).
    • Applies compatibility/clamping logic for older save versions: if reader.context.version < Version.resetNegativeResource and the resource is not Money, then m_Amount is clamped to the range [0, 1_000_000]. Values above 1_000_000 are reduced to 1_000_000; negative values are set to 0. Money is excluded from this clamp.
    • Generic constraint: TReader must implement the reader interface used by the Colossal save system.
    • Note: reader.context.version and Version.resetNegativeResource are part of the save/versioning system; behavior depends on those values.

Usage Example

// Example: creating a Resources element and serializing it
var res = new Game.Economy.Resources
{
    m_Resource = Resource.Water,
    m_Amount = 5000
};

// When stored in an ECS DynamicBuffer<Game.Economy.Resources>, each element will be serialized
// using the provided Serialize<TWriter>/Deserialize<TReader> implementation by the game's save system.