Game.Simulation.PolicePatrolRequest
Assembly:
Namespace: Game.Simulation
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents an ECS component that requests a police patrol to investigate or attend to a target entity. It stores the target entity, a numeric priority for dispatch ordering, and a small dispatch index tag used for compatibility/versioning or dispatch bookkeeping. The struct implements ISerializable so it can be written to/read from the game's serialization streams (save/load or networked state).
Fields
-
public Entity m_Target
Holds the Entity that should be patrolled or investigated. This is the primary target identifier for the patrol request. -
public float m_Priority
A numeric priority value used by dispatching logic to order or choose requests. Higher values typically indicate a more urgent or important request. -
public byte m_DispatchIndex
A small index/flag used by dispatch systems or for compatibility when reading older save versions. Defaulted to 0 in the constructor. Only serialized/deserialized if the reader's version supports the field (see Deserialize).
Properties
- (none)
This component exposes no CLR properties — data is stored directly in public fields to be used as an IComponentData value type.
Constructors
public PolicePatrolRequest(Entity target, float priority)
Creates a new PolicePatrolRequest with the given target and priority. The m_DispatchIndex field is initialized to 0.
Usage: - target: the Entity to patrol. - priority: numeric priority for dispatch ordering.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data into a writer stream in the following order: m_Target, m_Priority, m_DispatchIndex. The writer is expected to know how to write an Entity, a float, and a byte. This method ensures the component can be persisted or transmitted. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component data from a reader stream. It reads m_Target and m_Priority unconditionally. The m_DispatchIndex field is only read when the reader's context version is at or above Version.requestDispatchIndex, preserving backward compatibility with older save formats. The method uses ref locals to populate the struct fields directly.
Notes: - The Deserialize method relies on reader.context.version and a Version.requestDispatchIndex constant (defined elsewhere in the codebase) to determine whether the dispatch index is present in the stream. - Generic type constraints require writer to implement IWriter and reader to implement IReader — these are the game's serialization abstractions.
Usage Example
// Create a new patrol request and add it to an entity as a component
Entity policeRequestTarget = /* some target entity */;
float priority = 1.0f;
var request = new PolicePatrolRequest(policeRequestTarget, priority);
request.m_DispatchIndex = 0; // optional, set by dispatcher if needed
// Add to an entity via the EntityManager (example)
entityManager.AddComponentData(engineEntity, request);
// Serialization example (writing)
someWriter.Write(request.m_Target);
someWriter.Write(request.m_Priority);
someWriter.Write(request.m_DispatchIndex);
// Deserialization example (reading)
var loadedRequest = new PolicePatrolRequest();
loadedRequest.Deserialize(someReader);