Code cleanup.

This commit is contained in:
2023-04-19 13:31:17 +08:00
parent f664708165
commit cf6a7a795b
9 changed files with 27 additions and 31 deletions

View File

@@ -253,8 +253,8 @@ namespace Cryville.Crtr {
if (ContainerState.RMVPool != null) {
statusbuf.AppendFormat(
"\nPools: RMV {0}, MC {1}",
ContainerState.RMVPool.RentedCount,
ContainerState.MCPool.RentedCount
RMVPool.Shared.RentedCount,
MotionCachePool.Shared.RentedCount
);
}
if (loadThread != null) {
@@ -671,8 +671,8 @@ namespace Cryville.Crtr {
pruleset = ruleset.Root;
pruleset.Optimize(etor);
}
ContainerState.RMVPool = new RMVPool();
ContainerState.MCPool = new MotionCachePool();
RMVPool.Shared = new RMVPool();
MotionCachePool.Shared = new MotionCachePool();
}
void LoadSkin(FileInfo file) {

View File

@@ -95,8 +95,8 @@ namespace Cryville.Crtr.Event {
Parent = parent;
}
_rmvpa = new CategorizedPoolAccessor<int, RealtimeMotionValue>(RMVPool);
_mcpa = new CategorizedPoolAccessor<int, MotionCache>(MCPool);
_rmvpa = new CategorizedPoolAccessor<int, RealtimeMotionValue>(RMVPool.Shared);
_mcpa = new CategorizedPoolAccessor<int, MotionCache>(MotionCachePool.Shared);
Values = new IntKeyedDictionary<RealtimeMotionValue>(ChartPlayer.motionRegistry.Count);
CachedValues = new IntKeyedDictionary<MotionCache>(ChartPlayer.motionRegistry.Count);
@@ -151,7 +151,7 @@ namespace Cryville.Crtr.Event {
return r;
}
public void CopyTo(byte ct, ContainerState dest) {
public void CopyTo(ContainerState dest) {
dest.m_lActive = m_lActive;
dest.m_pActive = m_pActive;
dest.m_active = m_active;
@@ -174,12 +174,12 @@ namespace Cryville.Crtr.Event {
foreach (var cev in dest.ActiveChildren) {
if (!ActiveChildren.Contains(cev))
Children[cev].CopyTo(ct, dest.Children[cev]);
Children[cev].CopyTo(dest.Children[cev]);
}
dest.ActiveChildren.Clear();
foreach (var cev in ActiveChildren) {
dest.ActiveChildren.Add(cev);
Children[cev].CopyTo(ct, dest.Children[cev]);
Children[cev].CopyTo(dest.Children[cev]);
}
dest.PlayingMotions.Clear();
@@ -221,8 +221,6 @@ namespace Cryville.Crtr.Event {
#endregion
#region Motion
internal static RMVPool RMVPool;
internal static MotionCachePool MCPool;
readonly CategorizedPoolAccessor<int, RealtimeMotionValue> _rmvpa;
readonly CategorizedPoolAccessor<int, MotionCache> _mcpa;
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);

View File

@@ -38,11 +38,11 @@ namespace Cryville.Crtr.Event {
return r;
}
public void CopyTo(byte ct, EventBus dest) {
public void CopyTo(EventBus dest) {
base.CopyTo(dest);
dest.activeStates.Clear();
dest.invalidatedStates.Clear();
RootState.CopyTo(ct, dest.RootState);
RootState.CopyTo(dest.RootState);
dest.ValidateStates();
}
@@ -150,10 +150,10 @@ namespace Cryville.Crtr.Event {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void HandleTempEvents(double time, int maxPriority = int.MaxValue) {
while (tempEvents.Count > 0) {
var ev2 = tempEvents[0];
if (ev2.Time != time || ev2.Priority >= maxPriority) break;
if (ev2.Container != null) {
states[ev2.Container].Handle(ev2);
var ev = tempEvents[0];
if (ev.Time != time || ev.Priority >= maxPriority) break;
if (ev.Container != null) {
states[ev.Container].Handle(ev);
}
tempEvents.RemoveAt(0);
}
@@ -178,6 +178,10 @@ namespace Cryville.Crtr.Event {
}
public void EndGraphicalUpdate() {
RootState.EndGraphicalUpdate();
ClearTempEvents();
}
void ClearTempEvents() {
foreach (var ev in tempEvents) {
if (ev.Container != null) {
states[ev.Container].Discard(ev);

View File

@@ -14,6 +14,7 @@ namespace Cryville.Crtr.Event {
}
}
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) {

View File

@@ -5,6 +5,7 @@ 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) {

View File

@@ -304,12 +304,7 @@ namespace Cryville.Crtr {
}
public abstract void CopyTo(Vector dest);
static readonly Type[] stringTypeArray = new Type[] { typeof(string) };
static readonly Type[] floatArrayTypeArray = new Type[] { typeof(float[]) };
public static Vector Construct(Type type, string s) {
if (!typeof(Vector).IsAssignableFrom(type)) throw new ArgumentException("Type is not vector");
return (Vector)type.GetConstructor(stringTypeArray).Invoke(new object[] { s });
}
public static Vector Construct(Type type, float[] values) {
if (!typeof(Vector).IsAssignableFrom(type)) throw new ArgumentException("Type is not vector");
return (Vector)type.GetConstructor(floatArrayTypeArray).Invoke(new object[] { values });

View File

@@ -37,7 +37,7 @@ namespace Cryville.Crtr {
prop.Get(out type, out value);
}
else if (ContextState != null && ChartPlayer.motionRegistry.ContainsKey(new Identifier(name))) {
_vec = ContextState.GetRawValue(name);
_vec = ContextState.GetComputedValue(name);
_vecsrc.Invalidate();
_vecsrc.Get(out type, out value);
}

View File

@@ -12,8 +12,7 @@ namespace Cryville.Crtr {
public double Duration {
get {
if (Unstamped == null) return 0;
if (Unstamped.IsLong)
if (ReleaseEvent != null)
return ReleaseEvent.Time - Time;
else return 0;
}

View File

@@ -29,7 +29,10 @@ namespace Cryville.Crtr {
}
protected override void StartPreGraphicalUpdate(ContainerState s) {
base.StartPreGraphicalUpdate(s);
spos = Vector3.zero;
TransformAwake(s);
bpos = Position;
brot = Rotation;
}
protected override void StartGraphicalUpdate(ContainerState s) {
base.StartGraphicalUpdate(s);
@@ -46,11 +49,6 @@ namespace Cryville.Crtr {
pwp = Vector3.zero;
cpt = s.ScreenPoint;
ptime = s.Time;
if (s.CloneType == 3) {
spos = Vector3.zero;
bpos = cpt;
brot = Quaternion.Euler(s.Direction);
}
Position = pwp + cpt + spos;
Rotation = Quaternion.Euler(s.Direction);
}
@@ -112,7 +110,7 @@ namespace Cryville.Crtr {
protected override void EndGraphicalUpdate(ContainerState s) {
base.EndGraphicalUpdate(s);
EndUpdatePosition(s);
var p = pwp + cpt + spos;
var p = Position;
foreach (var i in sgos) {
i.AppendPoint(p, s.QuatDir);
i.Seal();