Class PickHistory
Tracks the pick history for a ProbabilityList<T>, retaining the most recent pick events up to a fixed capacity.
Inherited Members
Namespace: Scylla.Core.Util.Random
Assembly: ScyllaCore.dll
Syntax
public sealed class PickHistory : IEnumerable<PickRecord>, IEnumerable
Remarks
Internally backed by a ScyllaRingBuffer<T> configured with overwrite-on-full behaviour so that once capacity is reached the oldest entry is silently discarded in favour of the newest. Both writes and newest-peek operations are O(1).
PickHistory is created lazily by ProbabilityList<T> on the first pick and is accessible via History. It is also used internally to drive the Spread and Repick repeat-prevention modes.
Constructors
PickHistory(int)
Initializes a new PickHistory with the specified event capacity.
Declaration
public PickHistory(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | The maximum number of pick events to retain. When this limit is reached, the oldest event is silently overwritten by each new one. Must be greater than zero. |
Properties
Capacity
The maximum number of pick events this history retains. Once capacity is reached, the oldest event is overwritten by each new one.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
Count
The number of pick events currently stored in the history.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Returns true when no pick events have been recorded yet, or after
Clear() has been called.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Latest
The most recently recorded pick event.
Declaration
public PickRecord Latest { get; }
Property Value
| Type | Description |
|---|---|
| PickRecord | The newest PickRecord in the ring buffer, or a default PickRecord (index 0, timestamp 0) if the history is empty. Always check IsEmpty before relying on this value. |
Oldest
The oldest recorded pick event still retained by the ring buffer.
Declaration
public PickRecord Oldest { get; }
Property Value
| Type | Description |
|---|---|
| PickRecord | The oldest PickRecord in the ring buffer, or a default PickRecord (index 0, timestamp 0) if the history is empty. Always check IsEmpty before relying on this value. |
Methods
Clear()
Declaration
public void Clear()
GetAt(int)
Returns the pick record at the specified logical position in the ring buffer, where index 0 corresponds to the oldest retained event.
Declaration
public PickRecord GetAt(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Logical position in the history, in the range |
Returns
| Type | Description |
|---|---|
| PickRecord | The PickRecord at the specified position. |
GetEnumerator()
Returns an enumerator that iterates over all stored pick records from oldest to newest.
Declaration
public IEnumerator<PickRecord> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<PickRecord> | An enumerator over the retained PickRecord entries. |
Record(int)
Records a pick event for the given entry index, stamped with the current Unity
game time (UnityEngine.Time.time, seconds since application start).
Declaration
public void Record(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index of the picked entry within its ProbabilityList<T>. |
Record(int, float)
Records a pick event for the given entry index with an explicitly supplied timestamp. Use this overload when replaying history, unit-testing, or when game time is not available (e.g., edit-mode or before the first Unity frame).
Declaration
public void Record(int index, float timestamp)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index of the picked entry within its ProbabilityList<T>. |
| float | timestamp | The timestamp to associate with this pick event, in seconds since application start. |