namespace MoonTools.ECS; internal class MessageDepot { private Dictionary storages = new Dictionary(); private MessageStorage Lookup() where TMessage : struct { if (!storages.ContainsKey(typeof(TMessage))) { storages.Add(typeof(TMessage), new MessageStorage()); } return storages[typeof(TMessage)] as MessageStorage; } public void Add(in TMessage message) where TMessage : struct { Lookup().Add(message); } public bool Some() where TMessage : struct { return Lookup().Some(); } public ReadOnlySpan ReadAll() where TMessage : struct { return Lookup().All(); } public TMessage ReadFirst() where TMessage : struct { return Lookup().First(); } public void Clear() { foreach (var storage in storages.Values) { storage.Clear(); } } }