Introduce IntKeyedDictionary
to improve performance.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Buffers;
|
||||
using Cryville.Common.Collections.Specialized;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -91,13 +92,13 @@ namespace Cryville.Crtr.Event {
|
||||
Parent = parent;
|
||||
}
|
||||
|
||||
_rmvpa = new CategorizedPoolAccessor<Identifier, RealtimeMotionValue>(RMVPool);
|
||||
_mcpa = new CategorizedPoolAccessor<Identifier, MotionCache>(MCPool);
|
||||
_rmvpa = new CategorizedPoolAccessor<int, RealtimeMotionValue>(RMVPool);
|
||||
_mcpa = new CategorizedPoolAccessor<int, MotionCache>(MCPool);
|
||||
|
||||
Values = new Dictionary<Identifier, RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
|
||||
CachedValues = new Dictionary<Identifier, MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||
Values = new IntKeyedDictionary<RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
|
||||
CachedValues = new IntKeyedDictionary<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));
|
||||
Values.Add(m.Key.Key, new RealtimeMotionValue().Init(Parent == null ? m.Value.GlobalInitValue : m.Value.InitValue));
|
||||
|
||||
rootPrototype = this;
|
||||
}
|
||||
@@ -114,13 +115,13 @@ namespace Cryville.Crtr.Event {
|
||||
public ContainerState Clone(byte ct) {
|
||||
var r = (ContainerState)MemberwiseClone();
|
||||
|
||||
var mvs = new Dictionary<Identifier, RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
|
||||
var mvs = new IntKeyedDictionary<RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
|
||||
foreach (var mv in Values) {
|
||||
mvs.Add(mv.Key, mv.Value.Clone());
|
||||
}
|
||||
r.Values = mvs;
|
||||
|
||||
var cvs = new Dictionary<Identifier, MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||
var cvs = new IntKeyedDictionary<MotionCache>(ChartPlayer.motionRegistry.Count);
|
||||
r.CachedValues = cvs;
|
||||
|
||||
r.Children = new Dictionary<EventContainer, ContainerState>();
|
||||
@@ -218,11 +219,11 @@ namespace Cryville.Crtr.Event {
|
||||
#region Motion
|
||||
internal static RMVPool RMVPool;
|
||||
internal static MotionCachePool MCPool;
|
||||
readonly CategorizedPoolAccessor<Identifier, RealtimeMotionValue> _rmvpa;
|
||||
readonly CategorizedPoolAccessor<Identifier, MotionCache> _mcpa;
|
||||
readonly CategorizedPoolAccessor<int, RealtimeMotionValue> _rmvpa;
|
||||
readonly CategorizedPoolAccessor<int, MotionCache> _mcpa;
|
||||
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
|
||||
Dictionary<Identifier, RealtimeMotionValue> Values;
|
||||
Dictionary<Identifier, MotionCache> CachedValues;
|
||||
IntKeyedDictionary<RealtimeMotionValue> Values;
|
||||
IntKeyedDictionary<MotionCache> CachedValues;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a motion value.
|
||||
@@ -230,13 +231,13 @@ namespace Cryville.Crtr.Event {
|
||||
/// <param name="name">The motion name.</param>
|
||||
/// <param name="clone">Returns a cloned motion value instead.</param>
|
||||
/// <returns>A motion value.</returns>
|
||||
RealtimeMotionValue GetMotionValue(Identifier name, bool clone = false) {
|
||||
RealtimeMotionValue GetMotionValue(int name, bool clone = false) {
|
||||
RealtimeMotionValue value = Values[name];
|
||||
if (clone) return value.Clone();
|
||||
return value;
|
||||
}
|
||||
|
||||
void InvalidateMotion(Identifier name) {
|
||||
void InvalidateMotion(int name) {
|
||||
MotionCache cache;
|
||||
if (!CachedValues.TryGetValue(name, out cache))
|
||||
CachedValues.Add(name, cache = _mcpa.Rent(name));
|
||||
@@ -245,7 +246,7 @@ namespace Cryville.Crtr.Event {
|
||||
Children[c].InvalidateMotion(name);
|
||||
}
|
||||
|
||||
public Vector GetRawValue(Identifier key) {
|
||||
public Vector GetRawValue(int key) {
|
||||
MotionCache tr;
|
||||
if (!CachedValues.TryGetValue(key, out tr))
|
||||
CachedValues.Add(key, tr = _mcpa.Rent(key));
|
||||
@@ -263,11 +264,11 @@ namespace Cryville.Crtr.Event {
|
||||
return r;
|
||||
}
|
||||
|
||||
public T GetRawValue<T>(Identifier key) where T : Vector {
|
||||
public T GetRawValue<T>(int key) where T : Vector {
|
||||
return (T)GetRawValue(key);
|
||||
}
|
||||
|
||||
static readonly Identifier n_pt = new Identifier("pt");
|
||||
static readonly int n_pt = IdentifierManager.SharedInstance.Request("pt");
|
||||
public Vector2 ScreenPoint {
|
||||
get {
|
||||
var mv = GetRawValue<VecPt>(n_pt);
|
||||
@@ -275,7 +276,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Identifier n_dir = new Identifier("dir");
|
||||
static readonly int n_dir = IdentifierManager.SharedInstance.Request("dir");
|
||||
public Vector3 Direction {
|
||||
get {
|
||||
Vec3 r = GetRawValue<Vec3>(n_dir);
|
||||
@@ -283,7 +284,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Identifier n_normal = new Identifier("normal");
|
||||
static readonly int n_normal = IdentifierManager.SharedInstance.Request("normal");
|
||||
public Vector3 Normal {
|
||||
get {
|
||||
Vec3 r = GetRawValue<Vec3>(n_normal);
|
||||
@@ -297,8 +298,8 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Identifier n_sv = new Identifier("sv");
|
||||
static readonly Identifier n_svm = new Identifier("svm");
|
||||
static readonly int n_sv = IdentifierManager.SharedInstance.Request("sv");
|
||||
static readonly int n_svm = IdentifierManager.SharedInstance.Request("svm");
|
||||
public float ScrollVelocity {
|
||||
get {
|
||||
return GetRawValue<VecPtComp>(n_sv).ToFloat(ChartPlayer.hitRect)
|
||||
@@ -306,7 +307,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Identifier n_dist = new Identifier("dist");
|
||||
static readonly int n_dist = IdentifierManager.SharedInstance.Request("dist");
|
||||
public float Distance {
|
||||
get {
|
||||
var mv = GetRawValue<VecPtComp>(n_dist);
|
||||
@@ -314,15 +315,15 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Identifier n_corner = new Identifier("corner");
|
||||
static readonly int n_corner = IdentifierManager.SharedInstance.Request("corner");
|
||||
public bool Corner {
|
||||
get {
|
||||
return GetRawValue<VecI1>(n_corner).Value % 2 >= 1;
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Identifier n_ctrl0 = new Identifier("ctrl0");
|
||||
static readonly Identifier n_ctrl1 = new Identifier("ctrl1");
|
||||
static readonly int n_ctrl0 = IdentifierManager.SharedInstance.Request("ctrl0");
|
||||
static readonly int n_ctrl1 = IdentifierManager.SharedInstance.Request("ctrl1");
|
||||
public Vector3 GetControlPoint(bool alt1, float deltaz) {
|
||||
var mv = GetRawValue<VecCtrl>(alt1 ? n_ctrl1 : n_ctrl0);
|
||||
if (alt1 && mv.IsZero()) {
|
||||
@@ -331,7 +332,7 @@ namespace Cryville.Crtr.Event {
|
||||
return mv.ToVector3(ChartPlayer.hitRect, deltaz);
|
||||
}
|
||||
|
||||
static readonly Identifier n_track = new Identifier("track");
|
||||
static readonly int n_track = IdentifierManager.SharedInstance.Request("track");
|
||||
public float Track {
|
||||
get {
|
||||
return GetRawValue<Vec1>(n_track).Value;
|
||||
@@ -357,9 +358,9 @@ namespace Cryville.Crtr.Event {
|
||||
if (ev != null) {
|
||||
if (ev.Unstamped is Chart.Motion) {
|
||||
var tev = (Chart.Motion)ev.Unstamped;
|
||||
var mv = _rmvpa.Rent(tev.Name);
|
||||
var mv = _rmvpa.Rent(tev.Name.Key);
|
||||
mv.CloneTypeFlag = CloneType;
|
||||
GetMotionValue(tev.Name).CopyTo(mv);
|
||||
GetMotionValue(tev.Name.Key).CopyTo(mv);
|
||||
PlayingMotions.Add(ev, mv);
|
||||
Update(ev);
|
||||
if (!ev.Unstamped.IsLong) {
|
||||
@@ -407,8 +408,8 @@ namespace Cryville.Crtr.Event {
|
||||
foreach (var m in PlayingMotions) {
|
||||
var tev = (Chart.Motion)m.Key.Unstamped;
|
||||
if (tev.RelativeNode != null && CloneType == 2) continue;
|
||||
var value = GetMotionValue(tev.Name/*, true*/);
|
||||
InvalidateMotion(tev.Name);
|
||||
var value = GetMotionValue(tev.Name.Key/*, true*/);
|
||||
InvalidateMotion(tev.Name.Key);
|
||||
if (m.Key.Duration == 0) {
|
||||
if (tev.RelativeNode != null) {
|
||||
value.SetRelativeNode(tev.RelativeNode);
|
||||
@@ -428,7 +429,7 @@ namespace Cryville.Crtr.Event {
|
||||
tev.AbsoluteValue.LerpWith(m.Value.AbsoluteValue, lerpedTime, ref value.AbsoluteValue);
|
||||
}
|
||||
}
|
||||
Values[tev.Name] = value;
|
||||
Values[tev.Name.Key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user