Skip to content

Game.Simulation.ServiceRequest

Assembly:
Assembly-CSharp

Namespace:
Game.Simulation

Type:
struct

Base:
IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a service request component used by the simulation to track request state for services (for example: how many times a request failed, cooldown until the next attempt, and per-request flags such as Reversed). The struct is a compact, blittable component intended for use with Unity.Entities and implements custom binary serialization to maintain compatibility across game versions. Notably, the flags field is only read from serialized data when the reader's context version includes the reverseServiceRequests feature flag.


Fields

  • private System.Byte m_FailCount
    Holds the number of times this request has failed. Stored as a single byte (0..255). Systems typically increment this to limit retry behavior.

  • private System.Byte m_Cooldown
    Cooldown counter (in ticks/frames or simulation units) until the request may be retried. Stored as a single byte.

  • private ServiceRequestFlags m_Flags
    Bitmask of request-specific flags (type: ServiceRequestFlags). One known flag is Reversed (used when the request direction/semantics are reversed). Flags are serialized as a single byte.

Properties

This type defines no managed properties. It exposes only the fields above and implements IComponentData for ECS usage.

Constructors

  • public ServiceRequest(bool reversed)
    Initializes a new ServiceRequest instance. m_FailCount and m_Cooldown are set to 0. If reversed is true, m_Flags is set to ServiceRequestFlags.Reversed, otherwise m_Flags is set to 0.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the request state to the provided writer in the following order: m_FailCount (byte), m_Cooldown (byte), m_Flags (as byte). This method assumes the writer will record the bytes exactly in that order for later reading.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the request state from the provided reader in the expected order. It always reads m_FailCount and m_Cooldown. It will read the flags byte and set m_Flags only if the reader.context.version is greater than or equal to Version.reverseServiceRequests; this preserves compatibility with older save/data formats that did not include flags.

Usage Example

// Create a request and mark it as reversed
ServiceRequest req = new ServiceRequest(reversed: true);

// Example: increment failure and set cooldown
req.m_FailCount++;
req.m_Cooldown = 10;

// Serializing (pseudo-code, depends on actual writer implementation)
using (var writer = new SomeBinaryWriter(stream, context))
{
    req.Serialize(writer);
}

// Deserializing (pseudo-code)
ServiceRequest loaded = default;
using (var reader = new SomeBinaryReader(stream, context))
{
    reader.context.version = Version.current; // or an older version to test compatibility
    loaded.Deserialize(reader);
}

// After deserialization, loaded.m_Flags will only be populated if
// reader.context.version >= Version.reverseServiceRequests

Notes: - Because fields are bytes, overflow behavior should be handled by calling systems (e.g., clamp or reset m_FailCount when it reaches a threshold). - The Version.reverseServiceRequests check is important for backwards compatibility when reading older data that lacks the flags byte.