using System.Collections.Generic; using System.Runtime.CompilerServices; namespace PKHeX.Core; /// /// Frame List used to cache results, lazily reversing backwards and keeping the previous results. /// public sealed class FrameCache { private const int DefaultSize = 32; private readonly List Seeds = new(DefaultSize); private readonly List Values = new(DefaultSize); private uint Last; /// /// Creates a new instance of a . /// /// Seed at frame 0. public FrameCache(uint origin) => Add(origin); [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Add(uint seed) { Seeds.Add(Last = seed); Values.Add(seed >> 16); } /// /// Gets the 16 bit value from at a given . /// /// Index to grab the value from public uint this[int index] { get { while (index >= Seeds.Count) Add(XDRNG.Prev(Last)); return Values[index]; } } /// /// Gets the Seed at a specified frame index. /// /// Frame number /// Seed at index public uint GetSeed(int index) { while (index >= Seeds.Count) Add(XDRNG.Prev(Last)); return Seeds[index]; } }