42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using Cryville.Common;
|
|
using Cryville.Common.Buffers;
|
|
using Cryville.Common.Collections.Specialized;
|
|
using System;
|
|
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<int, MotionCache> {
|
|
public static MotionCachePool Shared;
|
|
private class Bucket : ObjectPool<MotionCache> {
|
|
readonly MotionRegistry _reg;
|
|
public Bucket(Identifier name, int capacity) : base(capacity) {
|
|
_reg = ChartPlayer.motionRegistry[name];
|
|
}
|
|
protected override MotionCache Construct() {
|
|
var result = new MotionCache {
|
|
Value = (Vector)Activator.CreateInstance(_reg.Type)
|
|
};
|
|
return result;
|
|
}
|
|
protected override void Reset(MotionCache obj) {
|
|
obj.Valid = false;
|
|
}
|
|
}
|
|
readonly IntKeyedDictionary<ObjectPool<MotionCache>> m_buckets;
|
|
protected override IDictionary<int, ObjectPool<MotionCache>> Buckets { get { return m_buckets; } }
|
|
public MotionCachePool() {
|
|
m_buckets = new IntKeyedDictionary<ObjectPool<MotionCache>>(ChartPlayer.motionRegistry.Count);
|
|
foreach (var reg in ChartPlayer.motionRegistry)
|
|
m_buckets.Add(reg.Key.Key, new Bucket(reg.Key, 4096));
|
|
}
|
|
}
|
|
}
|