using Cryville.Common; using Cryville.Common.Buffers; using System.Collections.Generic; namespace Cryville.Crtr.Event { internal class MotionCache { public bool Valid { get; set; } public Vector Value { get; set; } public void CopyTo(MotionCache dest) { dest.Valid = Valid; Value.CopyTo(dest.Value); } } internal class MotionCachePool : CategorizedPool { private class Bucket : ObjectPool { readonly MotionRegistry _reg; public Bucket(Identifier name, int capacity) : base(capacity) { _reg = ChartPlayer.motionRegistry[name]; } protected override MotionCache Construct() { var result = new MotionCache(); result.Value = (Vector)ReflectionHelper.InvokeEmptyConstructor(_reg.Type); return result; } protected override void Reset(MotionCache obj) { obj.Valid = false; } } readonly Dictionary> m_buckets; protected override IReadOnlyDictionary> Buckets { get { return m_buckets; } } public MotionCachePool() { m_buckets = new Dictionary>(ChartPlayer.motionRegistry.Count); foreach (var reg in ChartPlayer.motionRegistry) m_buckets.Add(reg.Key, new Bucket(reg.Key, 4096)); } } }