Game.Creatures.Queue
Assembly:
Game
Namespace:
Game.Creatures
Type:
struct
Base:
IBufferElementData, ISerializable
Summary:
Represents a single queue entry used by creature systems. Stored as an ECS dynamic buffer element (InternalBufferCapacity(0)), it references either a target entity or a target spherical area and carries an "obsolete time" (ushort) used by systems to expire/skip the entry. Implements custom binary serialization via Colossal.Serialization.Entities' IWriter/IReader.
Fields
-
public Entity m_TargetEntity
Holds the ECS Entity that is the target for this queue entry. Written/read first during serialization. -
public Sphere3 m_TargetArea
A Sphere3 describing a target area (position + radius). During serialization the radius is always written; the position is written only if radius > 0. Used when the target is an area instead of a single entity. -
public ushort m_ObsoleteTime
A timestamp / tick value indicating when this entry should be considered obsolete by game logic. Written/read after the target entity in the serialized stream.
Properties
- This struct exposes no C# properties. It uses public fields suitable for fast ECS buffer access.
Constructors
public Queue()
Implicit default struct constructor (fields default-initialized). Typical usage is to set fields explicitly when creating a new element before adding it to a buffer.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the element into the provided writer. Serialization order:- m_TargetEntity
- m_ObsoleteTime
- m_TargetArea.radius
- if radius > 0: m_TargetArea.position
The conditional write of the position.Save space when radius is zero (no meaningful position).
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes fields from the provided reader in the same order as Serialize. Reads radius first and, if radius > 0, reads the position into m_TargetArea.position.
Notes: - Generic reader/writer constraints make this agnostic to specific I/O implementations provided by the Colossal serialization infrastructure. - InternalBufferCapacity(0) means buffer elements are stored out-of-line (no inline capacity), which can affect performance characteristics and memory layout.
Usage Example
// Add a Queue element to an entity's buffer and set its values
Entity target = /* obtain target entity */;
Entity bufferOwner = /* the entity that owns the buffer */;
var buffer = EntityManager.AddBuffer<Game.Creatures.Queue>(bufferOwner);
var entry = new Game.Creatures.Queue
{
m_TargetEntity = target,
m_TargetArea = new Colossal.Mathematics.Sphere3 { position = new Unity.Mathematics.float3(10f, 0f, 20f), radius = 5f },
m_ObsoleteTime = 300 // example tick/value
};
buffer.Add(entry);
// Serializing a single entry (pseudo-usage using a writer)
var writer = /* obtain IWriter implementation */;
entry.Serialize(writer);
// Deserializing (pseudo-usage using a reader)
Game.Creatures.Queue readEntry = default;
var reader = /* obtain IReader implementation */;
readEntry.Deserialize(reader);
Additional tips: - When radius == 0, the Sphere3.position is not serialized — callers must be aware of that when interpreting deserialized data. - Use explicit field initialization when creating entries to avoid unintentionally stale/default values in ECS logic.