Make the output type of a property source read-only.
This commit is contained in:
@@ -351,6 +351,8 @@ namespace Cryville.Crtr {
|
||||
public abstract class Vector : IComparable<Vector> {
|
||||
public Vector() { }
|
||||
|
||||
public abstract byte Dimension { get; }
|
||||
|
||||
public abstract int CompareTo(Vector other);
|
||||
|
||||
public abstract void ApplyFrom(Vector parent);
|
||||
@@ -392,6 +394,8 @@ namespace Cryville.Crtr {
|
||||
Value = i;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 1; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
return CompareTo((Vec1)other);
|
||||
}
|
||||
@@ -457,6 +461,8 @@ namespace Cryville.Crtr {
|
||||
Value = i;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 1; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -517,6 +523,8 @@ namespace Cryville.Crtr {
|
||||
Value = i;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 1; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -578,6 +586,8 @@ namespace Cryville.Crtr {
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 2; } }
|
||||
|
||||
public static void Parse(string s, out float? w, out float? h) {
|
||||
string[] c = s.Split('+');
|
||||
float rw = 0, rh = 0;
|
||||
@@ -697,6 +707,8 @@ namespace Cryville.Crtr {
|
||||
this.x = x; this.y = y; this.z = z;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 3; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -773,6 +785,8 @@ namespace Cryville.Crtr {
|
||||
this.xw = xw; this.xh = xh; this.yw = yw; this.yh = yh;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 4; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -852,6 +866,8 @@ namespace Cryville.Crtr {
|
||||
this.xw = xw; this.xh = xh; this.yw = yw; this.yh = yh; this.z = z;
|
||||
}
|
||||
|
||||
public override byte Dimension { get { return 5; } }
|
||||
|
||||
public override int CompareTo(Vector other) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -925,19 +941,27 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public class VectorSrc : PropSrc {
|
||||
readonly Func<Vector> _cb;
|
||||
public VectorSrc(Func<Vector> cb) { _cb = cb; }
|
||||
protected override unsafe int InternalGet() {
|
||||
var arr = _cb().ToArray();
|
||||
if (arr.Length == 1) {
|
||||
public abstract class VectorSrc : PropSrc {
|
||||
protected readonly Func<Vector> _cb;
|
||||
public VectorSrc(Func<Vector> cb, int type) : base(type) { _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() {
|
||||
var arr = _cb().ToArray();
|
||||
buf = new byte[sizeof(float)];
|
||||
fixed (byte* ptr = buf) {
|
||||
*(float*)ptr = arr[0];
|
||||
}
|
||||
return PdtInternalType.Number;
|
||||
}
|
||||
else {
|
||||
}
|
||||
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) {
|
||||
var ptr = (float*)rptr;
|
||||
@@ -946,7 +970,6 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
*(int*)ptr = PdtInternalType.Number;
|
||||
}
|
||||
return PdtInternalType.Vector;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user