Code cleanup.
This commit is contained in:
@@ -1,7 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Cryville.Common.Pdt {
|
namespace Cryville.Common.Pdt {
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates that the attributed member is an element list.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
|
||||||
|
/// </remarks>
|
||||||
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||||
public class ElementListAttribute : Attribute { }
|
public class ElementListAttribute : Attribute { }
|
||||||
public class ComponentListAttribute : Attribute { }
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates that the attributed member is a property list.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>A property list is a <see cref="System.Collections.IDictionary" /> that represents a collection of PDT properties. There must be at most one property list in a class.</para>
|
||||||
|
/// </remarks>
|
||||||
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||||
public class PropertyListAttribute : Attribute { }
|
public class PropertyListAttribute : Attribute { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the value of this expression is constant.
|
/// Whether the value of this expression is constant.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>The value of this property is <c>false</c> until it is optimized.</remarks>
|
/// <remarks>The value of this property is <see langword="false" /> until it is optimized.</remarks>
|
||||||
public bool IsConstant { get; internal set; }
|
public bool IsConstant { get; internal set; }
|
||||||
internal bool IsPotentialConstant;
|
internal bool IsPotentialConstant;
|
||||||
internal PdtExpression(LinkedList<PdtInstruction> ins) {
|
internal PdtExpression(LinkedList<PdtInstruction> ins) {
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
0x0001, 0x0080, 0x0100, 0x0000, 0x0030, 0x0080, 0x0080, 0x0000, 0x0200, 0x0400, 0x0080, 0x0080, 0x0080, 0x0080, 0x0040, 0x0080,
|
0x0001, 0x0080, 0x0100, 0x0000, 0x0030, 0x0080, 0x0080, 0x0000, 0x0200, 0x0400, 0x0080, 0x0080, 0x0080, 0x0080, 0x0040, 0x0080,
|
||||||
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x1000, 0x1800, 0x0080, 0x0080, 0x0080, 0x0030,
|
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x1000, 0x1800, 0x0080, 0x0080, 0x0080, 0x0030,
|
||||||
0x0080, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
0x0080, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030,
|
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0080, 0x0000, 0x0080, 0x0030,
|
||||||
0x0000, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
0x0000, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x1000, 0x0080, 0x1000, 0x0000, 0x0000,
|
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x1000, 0x0080, 0x1000, 0x0080, 0x0000,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -57,40 +57,90 @@ namespace Cryville.Common.Pdt {
|
|||||||
return (T)new PdtInterpreter(src, typeof(T), binder).Interpret();
|
return (T)new PdtInterpreter(src, typeof(T), binder).Interpret();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The source string.
|
||||||
|
/// </summary>
|
||||||
public string Source { get; private set; }
|
public string Source { get; private set; }
|
||||||
readonly Type _type;
|
readonly Type _type;
|
||||||
readonly Binder _binder;
|
readonly Binder _binder;
|
||||||
|
/// <summary>
|
||||||
|
/// The current position in the string being parsed by the interpreter.
|
||||||
|
/// </summary>
|
||||||
public int Position { get; private set; }
|
public int Position { get; private set; }
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
|
/// <summary>
|
||||||
|
/// The character at the current position.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected char cc { get { return Source[Position]; } }
|
protected char cc { get { return Source[Position]; } }
|
||||||
|
/// <summary>
|
||||||
|
/// The category of the character.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected int ct { get { return cm[cc]; } }
|
protected int ct { get { return cm[cc]; } }
|
||||||
protected string tokenb(int flag) { // Token Whitelist
|
/// <summary>
|
||||||
|
/// Reads a token until a character of type <paramref name="flag" /> is met.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="flag">The type filter.</param>
|
||||||
|
/// <returns>A token from the current position (inclusive) to the next character of type <paramref name="flag" /> (exclusive).</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">No character of type <paramref name="flag" /> is met.</exception>
|
||||||
|
protected string tokenb(int flag) {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
while ((ct & flag) == 0) Position++;
|
while ((ct & flag) == 0) Position++;
|
||||||
return Source.Substring(sp, Position - sp);
|
return Source.Substring(sp, Position - sp);
|
||||||
}
|
}
|
||||||
protected string tokenw(int flag) { // Token Whitelist
|
/// <summary>
|
||||||
|
/// Reads a token until a character that is not of type <paramref name="flag" /> is met.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="flag">The type filter.</param>
|
||||||
|
/// <returns>A token from the current position (inclusive) to the next character that is not of type <paramref name="flag" /> (exclusive).</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">No character that is not of type <paramref name="flag" /> is met.</exception>
|
||||||
|
protected string tokenw(int flag) {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
while ((ct & flag) != 0) Position++;
|
while ((ct & flag) != 0) Position++;
|
||||||
return Source.Substring(sp, Position - sp);
|
return Source.Substring(sp, Position - sp);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Skips over whitespaces.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected void ws() {
|
protected void ws() {
|
||||||
while ((ct & 0x0001) != 0) Position++;
|
while ((ct & 0x0001) != 0) Position++;
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the current character and increments the position.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The current character.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected char GetChar() {
|
protected char GetChar() {
|
||||||
char r = cc;
|
char r = cc;
|
||||||
Position++;
|
Position++;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads an identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An identifier.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected string GetIdentifier() {
|
protected string GetIdentifier() {
|
||||||
if ((ct & 0x0020) == 0) return "";
|
if ((ct & 0x0020) == 0) return "";
|
||||||
return tokenw(0x0010);
|
return tokenw(0x0010);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a number.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A number.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected string GetNumber() {
|
protected string GetNumber() {
|
||||||
return tokenw(0x0040);
|
return tokenw(0x0040);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A string.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected string GetString() {
|
protected string GetString() {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
do {
|
do {
|
||||||
@@ -100,6 +150,11 @@ namespace Cryville.Common.Pdt {
|
|||||||
Position++;
|
Position++;
|
||||||
return Regex.Replace(Source.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
return Regex.Replace(Source.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads an expression.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An expression.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected PdtExpression GetExp() {
|
protected PdtExpression GetExp() {
|
||||||
var ins = new LinkedList<PdtInstruction>();
|
var ins = new LinkedList<PdtInstruction>();
|
||||||
int _;
|
int _;
|
||||||
@@ -219,6 +274,8 @@ namespace Cryville.Common.Pdt {
|
|||||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||||
var ptype = ReflectionHelper.GetMemberType(prop);
|
var ptype = ReflectionHelper.GetMemberType(prop);
|
||||||
if (flag) {
|
if (flag) {
|
||||||
|
if (!typeof(IDictionary).IsAssignableFrom(ptype))
|
||||||
|
throw new InvalidOperationException("Internal error: Property list is not a dictionary");
|
||||||
var ktype = ptype.GetGenericArguments()[0];
|
var ktype = ptype.GetGenericArguments()[0];
|
||||||
var vtype = ptype.GetGenericArguments()[1];
|
var vtype = ptype.GetGenericArguments()[1];
|
||||||
object key = _binder.ChangeType(pkey, ktype, null);
|
object key = _binder.ChangeType(pkey, ktype, null);
|
||||||
@@ -238,6 +295,10 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Interprets a key from the current position.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The interpreted key.</returns>
|
||||||
protected virtual object InterpretKey(Type type) {
|
protected virtual object InterpretKey(Type type) {
|
||||||
return tokenb(0x1000).Trim();
|
return tokenb(0x1000).Trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The count of the operands loaded.
|
/// The count of the operands loaded.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int LoadedOperandCount { get { return ParamCount - _loadindex; } }
|
protected int LoadedOperandCount { get { return _pc - _loadindex; } }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the operand at the specified index.
|
/// Gets the operand at the specified index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,20 +24,20 @@ namespace Cryville.Common.Pdt {
|
|||||||
int i = index + _loadindex;
|
int i = index + _loadindex;
|
||||||
return _operands[i];
|
return _operands[i];
|
||||||
}
|
}
|
||||||
internal int ParamCount { get; private set; }
|
readonly int _pc;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the <see cref="PdtOperator" /> class.
|
/// Creates an instance of the <see cref="PdtOperator" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pc">The suggested parameter count.</param>
|
/// <param name="pc">The suggested parameter count.</param>
|
||||||
protected PdtOperator(int pc) {
|
protected PdtOperator(int pc) {
|
||||||
ParamCount = pc;
|
_pc = pc;
|
||||||
_operands = new PdtVariableMemory[pc];
|
_operands = new PdtVariableMemory[pc];
|
||||||
}
|
}
|
||||||
PdtEvaluatorBase _etor;
|
PdtEvaluatorBase _etor;
|
||||||
bool _rfreq = true;
|
bool _rfreq = true;
|
||||||
internal void Begin(PdtEvaluatorBase etor) {
|
internal void Begin(PdtEvaluatorBase etor) {
|
||||||
_etor = etor;
|
_etor = etor;
|
||||||
_loadindex = ParamCount;
|
_loadindex = _pc;
|
||||||
}
|
}
|
||||||
internal void LoadOperand(PdtVariableMemory mem) {
|
internal void LoadOperand(PdtVariableMemory mem) {
|
||||||
if (_loadindex == 0) return;
|
if (_loadindex == 0) return;
|
||||||
@@ -55,6 +55,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the operator.
|
/// Executes the operator.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>When overridden, this method reads operands by calling <see cref="GetOperand(int)" />, and writes the result to the frame obtained by calling <see cref="GetReturnFrame(int, int)" />.</para>
|
||||||
|
/// </remarks>
|
||||||
protected abstract void Execute();
|
protected abstract void Execute();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a return frame.
|
/// Gets a return frame.
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="dest">The destination buffer.</param>
|
/// <param name="dest">The destination buffer.</param>
|
||||||
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
||||||
/// <param name="length">The length to copy.</param>
|
/// <param name="length">The length to copy.</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is greater than the length of the span.</exception>
|
||||||
public void CopyTo(byte* dest, int destOffset, int length) {
|
public void CopyTo(byte* dest, int destOffset, int length) {
|
||||||
|
if (length > Length) throw new ArgumentOutOfRangeException("length");
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
dest[destOffset + i] = _ptr[i];
|
dest[destOffset + i] = _ptr[i];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static MethodInfo _methodCreateFontAsset;
|
static MethodInfo _methodCreateFontAsset;
|
||||||
static object[] _paramsCreateFontAsset = new object[] { null, null, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, Type.Missing, Type.Missing };
|
static readonly object[] _paramsCreateFontAsset = new object[] { null, null, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, Type.Missing, Type.Missing };
|
||||||
static FontAsset CreateFontAsset(string path, int index) {
|
static FontAsset CreateFontAsset(string path, int index) {
|
||||||
if (_methodCreateFontAsset == null) {
|
if (_methodCreateFontAsset == null) {
|
||||||
_methodCreateFontAsset = typeof(FontAsset).GetMethod(
|
_methodCreateFontAsset = typeof(FontAsset).GetMethod(
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
List<Vector3> verts;
|
List<Vector3> verts;
|
||||||
List<Vector2> uvs;
|
List<Vector2> uvs;
|
||||||
List<int> trih = null, trib = null, trit = null;
|
List<int> trih = null, trib = null, trit = null;
|
||||||
static List<int> _emptyTris = new List<int>();
|
static readonly List<int> _emptyTris = new List<int>();
|
||||||
|
|
||||||
public override void Seal() {
|
public override void Seal() {
|
||||||
if (vertCount <= 1 || sumLength == 0) return;
|
if (vertCount <= 1 || sumLength == 0) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user