Deukhoofd 8a857ed232
All checks were successful
Build / Build (push) Successful in 51s
Implements some micro-optimizations
2025-07-05 15:46:32 +02:00

29 lines
952 B
C#

using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Events;
/// <summary>
/// Allows for the batching of multiple events that should be shown at the same time.
/// </summary>
/// <remarks>
/// This is useful for when we send multiple events to the client in sequence, but we want to show them in one go.
/// For example, when a Pokemon gets hurt by poison, we want to show the purple poison animation and the damage at the
/// same time. This is done by batching the events together.
/// </remarks>
public readonly record struct EventBatchId()
{
private static readonly RandomImpl RootRandom = new();
private static readonly ThreadLocal<RandomImpl> Random = new(() =>
{
lock (RootRandom)
{
return new RandomImpl(RootRandom.GetInt());
}
});
/// <summary>
/// The unique identifier for this batch of events.
/// </summary>
public Guid Id { get; init; } = Random.Value.NewGuid();
}