using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Common.Collections.Specialized;
using System.Collections.Generic;

namespace Cryville.Crtr.Event {
	internal class RMVPool : CategorizedPool<int, RealtimeMotionValue> {
		public static RMVPool Shared;
		private class Bucket : ObjectPool<RealtimeMotionValue> {
			readonly MotionRegistry _reg;
			public Bucket(Identifier name, int capacity) : base(capacity) {
				_reg = ChartPlayer.motionRegistry[name];
			}
			protected override RealtimeMotionValue Construct() {
				return new RealtimeMotionValue().Init(_reg.InitValue);
			}
			protected override void Reset(RealtimeMotionValue obj) {
				base.Reset(obj);
				obj.ReturnAllRelativeNodes();
			}
		}
		readonly IntKeyedDictionary<ObjectPool<RealtimeMotionValue>> m_buckets;
		protected override IDictionary<int, ObjectPool<RealtimeMotionValue>> Buckets { get { return m_buckets; } }
		public RMVPool() {
			m_buckets = new IntKeyedDictionary<ObjectPool<RealtimeMotionValue>>(ChartPlayer.motionRegistry.Count);
			foreach (var reg in ChartPlayer.motionRegistry)
				m_buckets.Add(reg.Key.Key, new Bucket(reg.Key, 4096));
		}
	}
}
