Optimize GC for vector property source.
This commit is contained in:
@@ -320,7 +320,7 @@ namespace Cryville.Crtr {
|
|||||||
else {
|
else {
|
||||||
AbsoluteValue = Vector.Construct(registry.Type, m.Groups[11].Value);
|
AbsoluteValue = Vector.Construct(registry.Type, m.Groups[11].Value);
|
||||||
}
|
}
|
||||||
SubmitPropSrc("value", VectorSrc.Construct(() => {
|
SubmitPropSrc("value", new VectorSrc(() => {
|
||||||
if (RelativeNode != null) return RelativeNode.Value;
|
if (RelativeNode != null) return RelativeNode.Value;
|
||||||
else return AbsoluteValue;
|
else return AbsoluteValue;
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ namespace Cryville.Crtr {
|
|||||||
public abstract float DelerpWith(Vector start, Vector value);
|
public abstract float DelerpWith(Vector start, Vector value);
|
||||||
public abstract bool IsZero();
|
public abstract bool IsZero();
|
||||||
public override abstract string ToString();
|
public override abstract string ToString();
|
||||||
public abstract float[] ToArray();
|
public abstract unsafe void ToArray(float* arr);
|
||||||
|
|
||||||
public Vector Clone() {
|
public Vector Clone() {
|
||||||
return (Vector)MemberwiseClone();
|
return (Vector)MemberwiseClone();
|
||||||
@@ -442,8 +442,8 @@ namespace Cryville.Crtr {
|
|||||||
return Value.ToString(CultureInfo.InvariantCulture);
|
return Value.ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float[] ToArray() {
|
public override unsafe void ToArray(float* arr) {
|
||||||
return new float[] { Value };
|
arr[0] = Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,8 +504,8 @@ namespace Cryville.Crtr {
|
|||||||
return Value.ToString(CultureInfo.InvariantCulture);
|
return Value.ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float[] ToArray() {
|
public override unsafe void ToArray(float* arr) {
|
||||||
return new float[] { Value };
|
arr[0] = Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,8 +566,8 @@ namespace Cryville.Crtr {
|
|||||||
return Value.ToString(CultureInfo.InvariantCulture);
|
return Value.ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float[] ToArray() {
|
public override unsafe void ToArray(float* arr) {
|
||||||
return new float[] { Value };
|
arr[0] = Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,8 +669,9 @@ namespace Cryville.Crtr {
|
|||||||
return ToString(w, h);
|
return ToString(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float[] ToArray() {
|
public override unsafe void ToArray(float* arr) {
|
||||||
return new float[] { w.Value, h.Value };
|
arr[0] = w.Value;
|
||||||
|
arr[1] = h.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -764,8 +765,10 @@ namespace Cryville.Crtr {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float[] ToArray() {
|
public override unsafe void ToArray(float* arr) {
|
||||||
return new float[] { x.Value, y.Value, z.Value };
|
arr[0] = x.Value;
|
||||||
|
arr[1] = y.Value;
|
||||||
|
arr[2] = z.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -845,8 +848,11 @@ namespace Cryville.Crtr {
|
|||||||
return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh);
|
return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float[] ToArray() {
|
public override unsafe void ToArray(float* arr) {
|
||||||
return new float[] { xw.Value, xh.Value, yw.Value, yh.Value };
|
arr[0] = xw.Value;
|
||||||
|
arr[1] = xh.Value;
|
||||||
|
arr[2] = yw.Value;
|
||||||
|
arr[3] = yh.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -936,40 +942,25 @@ namespace Cryville.Crtr {
|
|||||||
return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh) + "," + (z != null ? z.Value.ToString(CultureInfo.InvariantCulture) : "");
|
return VecPtComp.ToString(xw, xh) + "," + VecPtComp.ToString(yw, yh) + "," + (z != null ? z.Value.ToString(CultureInfo.InvariantCulture) : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float[] ToArray() {
|
public override unsafe void ToArray(float* arr) {
|
||||||
return new float[] { xw.Value, xh.Value, yw.Value, yh.Value, z.Value };
|
arr[0] = xw.Value;
|
||||||
|
arr[1] = xh.Value;
|
||||||
|
arr[2] = yw.Value;
|
||||||
|
arr[3] = yh.Value;
|
||||||
|
arr[4] = z.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class VectorSrc : PropSrc {
|
public class VectorSrc : PropSrc.FixedBuffer {
|
||||||
protected readonly Func<Vector> _cb;
|
protected readonly Func<Vector> _cb;
|
||||||
public VectorSrc(Func<Vector> cb, int type) : base(type) { _cb = cb; }
|
public VectorSrc(Func<Vector> cb) : base(PdtInternalType.Vector, 8 * sizeof(float) + sizeof(int)) { _cb = cb; }
|
||||||
public static VectorSrc Construct(Func<Vector> cb) {
|
|
||||||
if (cb().Dimension == 1) return new INumber(cb);
|
|
||||||
else return new IVector(cb);
|
|
||||||
}
|
|
||||||
class INumber : VectorSrc {
|
|
||||||
public INumber(Func<Vector> cb) : base(cb, PdtInternalType.Number) { }
|
|
||||||
protected override unsafe void InternalGet() {
|
protected override unsafe void InternalGet() {
|
||||||
var arr = _cb().ToArray();
|
var v = _cb();
|
||||||
buf = new byte[sizeof(float)];
|
if (v.Dimension > 8) throw new NotSupportedException("Vector dimension too large");
|
||||||
fixed (byte* ptr = buf) {
|
|
||||||
*(float*)ptr = arr[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class IVector : VectorSrc {
|
|
||||||
public IVector(Func<Vector> cb) : base(cb, PdtInternalType.Vector) { }
|
|
||||||
protected override unsafe void InternalGet() {
|
|
||||||
var arr = _cb().ToArray();
|
|
||||||
buf = new byte[sizeof(float) * arr.Length + sizeof(int)];
|
|
||||||
fixed (byte* rptr = buf) {
|
fixed (byte* rptr = buf) {
|
||||||
var ptr = (float*)rptr;
|
var ptr = (float*)rptr;
|
||||||
for (int i = 0; i < arr.Length; i++, ptr++) {
|
v.ToArray(ptr);
|
||||||
*ptr = arr[i];
|
*(int*)(ptr + v.Dimension) = PdtInternalType.Number;
|
||||||
}
|
|
||||||
*(int*)ptr = PdtInternalType.Number;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
static readonly byte[] _nullbuf = new byte[0];
|
static readonly byte[] _nullbuf = new byte[0];
|
||||||
readonly byte[] _numbuf = new byte[4];
|
readonly byte[] _numbuf = new byte[4];
|
||||||
|
readonly PropSrc _vecsrc;
|
||||||
|
Vector _vec;
|
||||||
static readonly int _var_w = IdentifierManager.SharedInstance.Request("w");
|
static readonly int _var_w = IdentifierManager.SharedInstance.Request("w");
|
||||||
static readonly int _var_h = IdentifierManager.SharedInstance.Request("h");
|
static readonly int _var_h = IdentifierManager.SharedInstance.Request("h");
|
||||||
static readonly int _var_current_time = IdentifierManager.SharedInstance.Request("current_time");
|
static readonly int _var_current_time = IdentifierManager.SharedInstance.Request("current_time");
|
||||||
@@ -32,8 +34,9 @@ namespace Cryville.Crtr {
|
|||||||
prop.Get(out type, out value);
|
prop.Get(out type, out value);
|
||||||
}
|
}
|
||||||
else if (ContextState != null && ChartPlayer.motionRegistry.ContainsKey(id)) {
|
else if (ContextState != null && ChartPlayer.motionRegistry.ContainsKey(id)) {
|
||||||
var vec = ContextState.GetRawValue(id);
|
_vec = ContextState.GetRawValue(id);
|
||||||
VectorSrc.Construct(() => vec).Get(out type, out value);
|
_vecsrc.Invalidate();
|
||||||
|
_vecsrc.Get(out type, out value);
|
||||||
}
|
}
|
||||||
else if (ContextState != null && ContextState.Handler.PropSrcs.TryGetValue(name, out prop)) {
|
else if (ContextState != null && ContextState.Handler.PropSrcs.TryGetValue(name, out prop)) {
|
||||||
prop.Get(out type, out value);
|
prop.Get(out type, out value);
|
||||||
@@ -140,6 +143,7 @@ namespace Cryville.Crtr {
|
|||||||
public PdtEvaluator() {
|
public PdtEvaluator() {
|
||||||
ContextCascadeBlocks.Push(0);
|
ContextCascadeBlocks.Push(0);
|
||||||
for (int i = 0; i < ContextCascade.Length; i++) ContextCascade[i] = new Dictionary<int, PropSrc>();
|
for (int i = 0; i < ContextCascade.Length; i++) ContextCascade[i] = new Dictionary<int, PropSrc>();
|
||||||
|
_vecsrc = new VectorSrc(() => _vec);
|
||||||
|
|
||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("screen_edge"), new func_screen_edge(() => ContextTransform));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("screen_edge"), new func_screen_edge(() => ContextTransform));
|
||||||
_ctxops.Add(IdentifierManager.SharedInstance.Request("int"), new func_int(() => ContextSelfValue));
|
_ctxops.Add(IdentifierManager.SharedInstance.Request("int"), new func_int(() => ContextSelfValue));
|
||||||
|
|||||||
Reference in New Issue
Block a user