Pull up CategorizedPool. Add Reset method for ObjectPool.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Buffers;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Crtr.Event {
|
||||
internal class RMVPool {
|
||||
internal class RMVPool : CategorizedPool<Identifier, RealtimeMotionValue> {
|
||||
private class Bucket : ObjectPool<RealtimeMotionValue> {
|
||||
readonly MotionRegistry _reg;
|
||||
public Bucket(string name, int capacity) : base(capacity) {
|
||||
@@ -13,33 +12,9 @@ namespace Cryville.Crtr.Event {
|
||||
return new RealtimeMotionValue().Init(_reg.InitValue);
|
||||
}
|
||||
}
|
||||
static Dictionary<Identifier, Bucket> _buckets;
|
||||
public static void Prepare() {
|
||||
_buckets = new Dictionary<Identifier, Bucket>(ChartPlayer.motionRegistry.Count);
|
||||
public RMVPool() {
|
||||
foreach (var reg in ChartPlayer.motionRegistry)
|
||||
_buckets.Add(reg.Key, new Bucket(reg.Key, 4096));
|
||||
}
|
||||
|
||||
static readonly SimpleObjectPool<Dictionary<RealtimeMotionValue, Identifier>> _dictPool
|
||||
= new SimpleObjectPool<Dictionary<RealtimeMotionValue, Identifier>>(1024);
|
||||
Dictionary<RealtimeMotionValue, Identifier> _rented;
|
||||
public RealtimeMotionValue Rent(Identifier name) {
|
||||
var obj = _buckets[name].Rent();
|
||||
if (_rented == null) _rented = _dictPool.Rent();
|
||||
_rented.Add(obj, name);
|
||||
return obj;
|
||||
}
|
||||
public void Return(RealtimeMotionValue obj) {
|
||||
_buckets[_rented[obj]].Return(obj);
|
||||
_rented.Remove(obj);
|
||||
}
|
||||
public void ReturnAll() {
|
||||
if (_rented == null) return;
|
||||
foreach (var obj in _rented)
|
||||
_buckets[obj.Value].Return(obj.Key);
|
||||
_rented.Clear();
|
||||
_dictPool.Return(_rented);
|
||||
_rented = null;
|
||||
Buckets.Add(reg.Key, new Bucket(reg.Key, 4096));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user