Add MotionCache.
This commit is contained in:
@@ -65,16 +65,10 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
readonly RMVPool RMVPool = new RMVPool();
|
||||
protected Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>();
|
||||
protected Dictionary<Identifier, RealtimeMotionValue> Values;
|
||||
protected Dictionary<Identifier, CacheEntry> CachedValues;
|
||||
protected class CacheEntry {
|
||||
public bool Valid { get; set; }
|
||||
public Vector Value { get; set; }
|
||||
public CacheEntry Clone() {
|
||||
return new CacheEntry { Valid = Valid, Value = Value == null ? null : Value.Clone() };
|
||||
}
|
||||
}
|
||||
readonly MotionCachePool MCPool = new MotionCachePool();
|
||||
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
|
||||
Dictionary<Identifier, RealtimeMotionValue> Values;
|
||||
Dictionary<Identifier, MotionCache> CachedValues;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a motion value.
|
||||
@@ -89,9 +83,9 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
void InvalidateMotion(Identifier name) {
|
||||
CacheEntry cache;
|
||||
MotionCache cache;
|
||||
if (!CachedValues.TryGetValue(name, out cache))
|
||||
CachedValues.Add(name, cache = new CacheEntry());
|
||||
CachedValues.Add(name, cache = MCPool.Rent(name));
|
||||
cache.Valid = false;
|
||||
ValidateChildren();
|
||||
foreach (var c in WorkingChildren)
|
||||
@@ -107,7 +101,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
Values = new Dictionary<Identifier, RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
|
||||
CachedValues = new Dictionary<Identifier, CacheEntry>(ChartPlayer.motionRegistry.Count);
|
||||
CachedValues = new Dictionary<Identifier, MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||
foreach (var m in ChartPlayer.motionRegistry)
|
||||
Values.Add(m.Key, new RealtimeMotionValue().Init(Parent == null ? m.Value.GlobalInitValue : m.Value.InitValue));
|
||||
}
|
||||
@@ -128,9 +122,11 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
r.Values = mvs;
|
||||
|
||||
var cvs = new Dictionary<Identifier, CacheEntry>(ChartPlayer.motionRegistry.Count);
|
||||
var cvs = new Dictionary<Identifier, MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||
foreach (var cv in CachedValues) {
|
||||
cvs.Add(cv.Key, cv.Value.Clone());
|
||||
var dv = r.MCPool.Rent(cv.Key);
|
||||
cv.Value.CopyTo(dv);
|
||||
cvs.Add(cv.Key, dv);
|
||||
}
|
||||
r.CachedValues = cvs;
|
||||
|
||||
@@ -169,12 +165,11 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
foreach (var cv in dest.CachedValues) cv.Value.Valid = false;
|
||||
foreach (var cv in CachedValues) {
|
||||
CacheEntry dv;
|
||||
if (dest.CachedValues.TryGetValue(cv.Key, out dv)) {
|
||||
dv.Valid = cv.Value.Valid;
|
||||
if (cv.Value.Value != null) cv.Value.Value.CopyTo(dv.Value);
|
||||
MotionCache dv;
|
||||
if (!dest.CachedValues.TryGetValue(cv.Key, out dv)) {
|
||||
dest.CachedValues.Add(cv.Key, dv = dest.MCPool.Rent(cv.Key));
|
||||
}
|
||||
else dest.CachedValues.Add(cv.Key, cv.Value.Clone());
|
||||
cv.Value.CopyTo(dv);
|
||||
}
|
||||
|
||||
if (ct != 1) foreach (var cev in WorkingChildren)
|
||||
@@ -198,6 +193,7 @@ namespace Cryville.Crtr.Event {
|
||||
foreach (var s in Children)
|
||||
s.Value.Dispose();
|
||||
RMVPool.ReturnAll();
|
||||
MCPool.ReturnAll();
|
||||
}
|
||||
|
||||
public void AttachHandler(ContainerHandler h) {
|
||||
@@ -212,11 +208,9 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
public Vector GetRawValue(Identifier key) {
|
||||
CacheEntry tr;
|
||||
MotionCache tr;
|
||||
if (!CachedValues.TryGetValue(key, out tr))
|
||||
CachedValues.Add(key, tr = new CacheEntry { });
|
||||
if (tr.Value == null)
|
||||
tr.Value = RMVPool.Rent(key).AbsoluteValue;
|
||||
CachedValues.Add(key, tr = MCPool.Rent(key));
|
||||
Vector r = tr.Value;
|
||||
#if !DISABLE_CACHE
|
||||
if (tr.Valid) return r;
|
||||
|
Reference in New Issue
Block a user