using System; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace PKHeX.Core { /// /// Frame List used to cache results. /// public sealed class FrameCache { private const int DefaultSize = 32; private readonly List Seeds = new List(DefaultSize); private readonly List Values = new List(DefaultSize); private readonly Func Advance; /// /// Creates a new instance of a . /// /// Seed at frame 0. /// method used to get the next seed. Can use or . public FrameCache(uint origin, Func advance) { Advance = advance; Add(origin); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Add(uint seed) { Seeds.Add(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(Advance(Seeds[Seeds.Count - 1])); 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(Advance(Seeds[Seeds.Count - 1])); return Seeds[index]; } } }