71 Commits

577 changed files with 2050 additions and 29990 deletions

1
.gitignore vendored
View File

@@ -68,3 +68,4 @@ crashlytics-build.properties
/UserSettings /UserSettings
/*.zip /*.zip
*.lnk *.lnk
/HybridCLRData

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 5335612e48e4c3947808c99fb99411d5 guid: c4ef48e4a4983de4e9c31483df2a918e
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6823ead66b33bc048bbad48719feb25d guid: 9ec674235c0dd6744af2dab2b58dd53c
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@@ -0,0 +1,8 @@
using System.Collections.Generic;
namespace Cryville.Common.Collections.Generic {
public interface IPairList<TKey, TValue> : IList<KeyValuePair<TKey, TValue>> {
void Add(TKey key, TValue value);
void Insert(int index, TKey key, TValue value);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f5b3f3294f679f14f8ec1195b0def630 guid: 73fb17b484b343242bcce27c15ed7d44
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Cryville.Common.Collections.Generic {
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairCollectionDebugView<,>))]
public struct PairCollection<TKey, TValue> : IDisposable {
public void Dispose() { }
readonly IPairList<TKey, TValue> _pairList;
readonly IDictionary<TKey, TValue> _dictionary;
public PairCollection(object collection) : this() {
var type = collection.GetType();
if (typeof(IPairList<TKey, TValue>).IsAssignableFrom(type)) _pairList = (IPairList<TKey, TValue>)collection;
else if (typeof(IDictionary<TKey, TValue>).IsAssignableFrom(type)) _dictionary = (IDictionary<TKey, TValue>)collection;
else throw new ArgumentException("Parameter is not a pair collection");
}
public int Count {
get {
if (_pairList != null) return _pairList.Count;
else return _dictionary.Count;
}
}
public void Add(TKey key, TValue value) {
if (_pairList != null) _pairList.Add(key, value);
else _dictionary.Add(key, value);
}
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int index) {
if (_pairList != null) _pairList.CopyTo(array, index);
else _dictionary.CopyTo(array, index);
}
}
internal class PairCollectionDebugView<TKey, TValue> {
readonly PairCollection<TKey, TValue> _self;
public PairCollectionDebugView(PairCollection<TKey, TValue> self) {
_self = self;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<TKey, TValue>[] Items {
get {
KeyValuePair<TKey, TValue>[] array = new KeyValuePair<TKey, TValue>[_self.Count];
_self.CopyTo(array, 0);
return array;
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 23377bf2926d93a4b8e3f3ab6040c7f2 guid: 2517e8f040bd36f46948e5fafaf5335c
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Cryville.Common.Collections.Generic {
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairListDebugView<,>))]
public class PairList<TKey, TValue> : List<KeyValuePair<TKey, TValue>>, IPairList<TKey, TValue>, IPairList {
public void Add(TKey key, TValue value) {
Add(new KeyValuePair<TKey, TValue>(key, value));
}
public void Add(object key, object value) {
try {
Add((TKey)key, (TValue)value);
}
catch (InvalidCastException) {
throw new ArgumentException("Wrong key type or value type");
}
}
public void Insert(int index, TKey key, TValue value) {
Insert(index, new KeyValuePair<TKey, TValue>(key, value));
}
public void Insert(int index, object key, object value) {
try {
Insert(index, (TKey)key, (TValue)value);
}
catch (InvalidCastException) {
throw new ArgumentException("Wrong key type or value type");
}
}
}
internal class PairListDebugView<TKey, TValue> {
readonly PairList<TKey, TValue> _self;
public PairListDebugView(PairList<TKey, TValue> self) {
_self = self;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<TKey, TValue>[] Items {
get {
KeyValuePair<TKey, TValue>[] array = new KeyValuePair<TKey, TValue>[_self.Count];
_self.CopyTo(array, 0);
return array;
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4ffe72fef6ebb9e4da3571b4117f0d6d guid: d9ed5ea8b7b1a934287e7ec5971166c0
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,8 @@
using System.Collections;
namespace Cryville.Common.Collections {
public interface IPairList : IList {
void Add(object key, object value);
void Insert(int index, object key, object value);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: e3c5a8bf05d5e284ba498e91cb0dd35e guid: 046617672d437de4ab7e644a55defd3b
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace Cryville.Common.Collections {
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairCollectionDebugView))]
public struct PairCollection : IDisposable {
public void Dispose() { }
readonly IPairList _pairList;
readonly IDictionary _dictionary;
public PairCollection(object collection) : this() {
var type = collection.GetType();
if (typeof(IPairList).IsAssignableFrom(type)) _pairList = (IPairList)collection;
else if (typeof(IDictionary).IsAssignableFrom(type)) _dictionary = (IDictionary)collection;
else throw new ArgumentException("Parameter is not a pair collection");
}
public int Count {
get {
if (_pairList != null) return _pairList.Count;
else return _dictionary.Count;
}
}
public void Add(object key, object value) {
if (_pairList != null) _pairList.Add(key, value);
else _dictionary.Add(key, value);
}
public void CopyTo(KeyValuePair<object, object>[] array, int index) {
if (_pairList != null) _pairList.CopyTo(array, index);
else _dictionary.CopyTo(array, index);
}
}
internal class PairCollectionDebugView {
readonly PairCollection _self;
public PairCollectionDebugView(PairCollection self) {
_self = self;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<object, object>[] Items {
get {
KeyValuePair<object, object>[] array = new KeyValuePair<object, object>[_self.Count];
_self.CopyTo(array, 0);
return array;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1f87dfb8f6a1f5640b6deae741cd715c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Diagnostics;
namespace Cryville.Common.Collections {
[DebuggerDisplay("Count = {Count}"), DebuggerTypeProxy(typeof(PairListDebugView))]
public class PairList : List<KeyValuePair<object, object>>, IPairList {
public void Add(object key, object value) {
Add(new KeyValuePair<object, object>(key, value));
}
public void Insert(int index, object key, object value) {
Insert(index, new KeyValuePair<object, object>(key, value));
}
}
internal class PairListDebugView {
readonly PairList _self;
public PairListDebugView(PairList self) {
_self = self;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<object, object>[] Items {
get {
KeyValuePair<object, object>[] array = new KeyValuePair<object, object>[_self.Count];
_self.CopyTo(array, 0);
return array;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 57fc9f037c1fda5449e2a365a835c82c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -45,7 +45,7 @@ namespace Cryville.Common.Font {
return tableDirectoryOffsets; return tableDirectoryOffsets;
} }
public override TableDirectory GetSubTable(UInt32 item) { public override TableDirectory GetSubTable(UInt32 item) {
var i = (UInt32)item; var i = item;
return new TableDirectory(Reader, i); return new TableDirectory(Reader, i);
} }
} }

View File

@@ -2,6 +2,7 @@
namespace Cryville.Common { namespace Cryville.Common {
public struct Identifier : IEquatable<Identifier> { public struct Identifier : IEquatable<Identifier> {
public static Identifier Empty = new Identifier(0);
public int Key { get; private set; } public int Key { get; private set; }
public object Name { get { return IdentifierManager.SharedInstance.Retrieve(Key); } } public object Name { get { return IdentifierManager.SharedInstance.Retrieve(Key); } }
public Identifier(int key) { public Identifier(int key) {

View File

@@ -0,0 +1,44 @@
using SMath = System.Math;
namespace Cryville.Common.Math {
// Ported from https://github.com/arian/cubic-bezier/blob/master/index.js
public static class CubicBezier {
public static float Evaluate(float t, float x1, float y1, float x2, float y2, float epsilon) {
float x = t, t0, t1, t2, tx, d2, i;
for (t2 = x, i = 0; i < 8; i++) {
tx = CurveX(t2, x1, x2) - x;
if (SMath.Abs(tx) < epsilon) return CurveY(t2, y1, y2);
d2 = DerivativeCurveX(t2, x1, x2);
if (SMath.Abs(d2) < 1e-6) break;
t2 -= tx / d2;
}
t0 = 0; t1 = 1; t2 = x;
if (t2 < t0) return CurveY(t0, y1, y2);
if (t2 > t1) return CurveY(t1, y1, y2);
while (t0 < t1) {
tx = CurveX(t2, x1, x2);
if (SMath.Abs(tx - x) < epsilon) return CurveY(t2, y1, y2);
if (x > tx) t0 = t2;
else t1 = t2;
t2 = (t1 - t0) * .5f + t0;
}
return CurveY(t2, y1, y2);
}
static float CurveX(float t, float x1, float x2) {
float v = 1 - t;
return 3 * v * v * t * x1 + 3 * v * t * t * x2 + t * t * t;
}
static float CurveY(float t, float y1, float y2) {
float v = 1 - t;
return 3 * v * v * t * y1 + 3 * v * t * t * y2 + t * t * t;
}
static float DerivativeCurveX(float t, float x1, float x2) {
float v = 1 - t;
return 3 * (2 * (t - 1) * t + v * v) * x1 + 3 * (-t * t * t + 2 * v * t) * x2;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 17dd6f775fc965f43960da7166b55b87
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,12 +12,12 @@ namespace Cryville.Common.Math {
/// <param name="error">The error.</param> /// <param name="error">The error.</param>
/// <param name="n">The numerator.</param> /// <param name="n">The numerator.</param>
/// <param name="d">The denominator.</param> /// <param name="d">The denominator.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is less than 0 or <paramref name="error" /> is not greater than 0 or not less than 1.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="value" /> is less than 0 or <paramref name="error" /> is not greater than 0 or greater than 1.</exception>
public static void ToFraction(double value, double error, out int n, out int d) { public static void ToFraction(double value, double error, out int n, out int d) {
if (value < 0.0) if (value < 0.0)
throw new ArgumentOutOfRangeException("value", "Must be >= 0."); throw new ArgumentOutOfRangeException("value", "Must be >= 0.");
if (error <= 0.0 || error >= 1.0) if (error <= 0.0 || error > 1.0)
throw new ArgumentOutOfRangeException("accuracy", "Must be > 0 and < 1."); throw new ArgumentOutOfRangeException("error", "Must be > 0 and <= 1.");
int num = (int)System.Math.Floor(value); int num = (int)System.Math.Floor(value);
value -= num; value -= num;

View File

@@ -5,7 +5,7 @@ namespace Cryville.Common.Pdt {
/// Indicates that the attributed member is an element list. /// Indicates that the attributed member is an element list.
/// </summary> /// </summary>
/// <remarks> /// <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> /// <para>An element list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.Generic.IPairList" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
/// </remarks> /// </remarks>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class ElementListAttribute : Attribute { } public class ElementListAttribute : Attribute { }
@@ -14,7 +14,7 @@ namespace Cryville.Common.Pdt {
/// Indicates that the attributed member is a property list. /// Indicates that the attributed member is a property list.
/// </summary> /// </summary>
/// <remarks> /// <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> /// <para>A property list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.Generic.IPairList" /> that represents a collection of PDT properties. There must be at most one property list in a class.</para>
/// </remarks> /// </remarks>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class PropertyListAttribute : Attribute { } public class PropertyListAttribute : Attribute { }

View File

@@ -92,7 +92,7 @@ namespace Cryville.Common.Pdt {
} }
} }
public partial class PdtInterpreter { public partial class PdtInterpreter {
readonly static Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> { static readonly Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> {
{ '@', 7 }, { '@', 7 },
{ '*', 6 }, { '/', 6 }, { '%', 6 }, { '*', 6 }, { '/', 6 }, { '%', 6 },
{ '+', 5 }, { '-', 5 }, { '+', 5 }, { '-', 5 },
@@ -103,7 +103,7 @@ namespace Cryville.Common.Pdt {
{ ',', 0 }, { ',', 0 },
{ '$', -1 }, { '$', -1 },
}; };
readonly static Dictionary<char, int> OP_TYPE = new Dictionary<char, int> { static readonly Dictionary<char, int> OP_TYPE = new Dictionary<char, int> {
{ '@', 0 }, { '@', 0 },
{ '*', 0 }, { '/', 0 }, { '%', 0 }, { '*', 0 }, { '/', 0 }, { '%', 0 },
{ '+', 0 }, { '-', 0 }, { '+', 0 }, { '-', 0 },
@@ -115,7 +115,7 @@ namespace Cryville.Common.Pdt {
{ '$', -1 }, { '$', -1 },
}; };
readonly static PdtExpression _emptyexp; static readonly PdtExpression _emptyexp;
static PdtInterpreter() { static PdtInterpreter() {
var ins = new LinkedList<PdtInstruction>(); var ins = new LinkedList<PdtInstruction>();
ins.AddLast(new PdtInstruction.PushConstant( ins.AddLast(new PdtInstruction.PushConstant(
@@ -143,7 +143,7 @@ namespace Cryville.Common.Pdt {
public override string ToString() { public override string ToString() {
return string.Format("0x{0:x4}: {1}", Type, Value); return string.Format("0x{0:x4}: {1}", Type, Value);
} }
public readonly static PdtExpToken EmptyOperator = new PdtExpToken { public static readonly PdtExpToken EmptyOperator = new PdtExpToken {
Type = 0x0080, Type = 0x0080,
Value = "$", Value = "$",
}; };

View File

@@ -6,30 +6,30 @@
/// <summary> /// <summary>
/// Error type. /// Error type.
/// </summary> /// </summary>
public readonly static int Error = 0x00525245; public const int Error = 0x00525245;
/// <summary> /// <summary>
/// Array of a same variable-length type, with a suffix indicating the element count and the element type. /// Array of a same variable-length type, with a suffix indicating the element count and the element type.
/// </summary> /// </summary>
public readonly static int Array = 0x00525241; public const int Array = 0x00525241;
/// <summary> /// <summary>
/// Null type. /// Null type.
/// </summary> /// </summary>
public readonly static int Null = 0x4c4c554e; public const int Null = 0x4c4c554e;
/// <summary> /// <summary>
/// IEEE 754 32-bit floating-point number. /// IEEE 754 32-bit floating-point number.
/// </summary> /// </summary>
public readonly static int Number = 0x004d554e; public const int Number = 0x004d554e;
/// <summary> /// <summary>
/// A sequence of UTF-16 code units, with a prefix indicating the number of the code units. /// A sequence of UTF-16 code units, with a prefix indicating the number of the code units.
/// </summary> /// </summary>
public readonly static int String = 0x00525453; public const int String = 0x00525453;
/// <summary> /// <summary>
/// A sequence of UTF-16 code units, with a prefix indicating the number of the code units, representing the name of an undefined variable. /// A sequence of UTF-16 code units, with a prefix indicating the number of the code units, representing the name of an undefined variable.
/// </summary> /// </summary>
public readonly static int Undefined = 0x00444e55; public const int Undefined = 0x00444e55;
/// <summary> /// <summary>
/// Vector of a same constant-length type, with a suffix indicating the element type. /// Vector of a same constant-length type, with a suffix indicating the element type.
/// </summary> /// </summary>
public readonly static int Vector = 0x00434556; public const int Vector = 0x00434556;
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using Cryville.Common.Collections;
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -27,7 +28,7 @@ namespace Cryville.Common.Pdt {
/// <item><term><c>0x1000</c></term><description>End of Key</description></item> /// <item><term><c>0x1000</c></term><description>End of Key</description></item>
/// </list> /// </list>
/// </remarks> /// </remarks>
readonly static int[] cm = new int[] { static readonly int[] cm = new int[] {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F // 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
@@ -255,13 +256,13 @@ 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));
Type ptype = ReflectionHelper.GetMemberType(prop); Type ptype = ReflectionHelper.GetMemberType(prop);
if (flag) { if (flag) {
if (!typeof(IDictionary).IsAssignableFrom(ptype)) using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
throw new InvalidOperationException("Internal error: Element 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);
object value = InterpretObject(vtype); object value = InterpretObject(vtype);
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value); collection.Add(key, value);
}
} }
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype)); else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
} }
@@ -284,13 +285,13 @@ 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)) using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
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);
object value = _binder.ChangeType(exp, vtype, null); object value = _binder.ChangeType(exp, vtype, null);
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value); collection.Add(key, value);
}
} }
else { else {
object value = _binder.ChangeType(exp, ptype, null); object value = _binder.ChangeType(exp, ptype, null);

View File

@@ -4,7 +4,7 @@ namespace Cryville.Common.Pdt {
/// <summary> /// <summary>
/// PDT operator. /// PDT operator.
/// </summary> /// </summary>
public unsafe abstract class PdtOperator { public abstract unsafe class PdtOperator {
byte* _prmem; byte* _prmem;
int _loadindex; int _loadindex;
readonly PdtVariableMemory[] _operands; readonly PdtVariableMemory[] _operands;

View File

@@ -28,8 +28,8 @@ namespace Cryville.Common.Unity {
set { m_filter = value; } set { m_filter = value; }
} }
public Dictionary<string, string> m_presetPaths = new Dictionary<string, string>(); public IReadOnlyDictionary<string, string> m_presetPaths = new Dictionary<string, string>();
public Dictionary<string, string> PresetPaths { public IReadOnlyDictionary<string, string> PresetPaths {
get { return m_presetPaths; } get { return m_presetPaths; }
set { m_presetPaths = value; } set { m_presetPaths = value; }
} }

View File

@@ -3,6 +3,6 @@ using UnityEngine;
namespace Cryville.Common.Unity.UI { namespace Cryville.Common.Unity.UI {
public abstract class SetParameterBehaviour : StateMachineBehaviour { public abstract class SetParameterBehaviour : StateMachineBehaviour {
[SerializeField] protected string m_name; [SerializeField] protected string m_name;
public override abstract void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex); public abstract override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
} }
} }

View File

@@ -1,8 +0,0 @@
using System.Collections.Generic;
namespace Cryville.Crtr.Browsing {
public abstract class ExtensionInterface {
public abstract IEnumerable<ResourceConverter> GetResourceConverters();
public abstract IEnumerable<LocalResourceFinder> GetResourceFinders();
}
}

View File

@@ -0,0 +1,138 @@
using Cryville.Common;
using Cryville.Crtr.Extension;
using Mono.Cecil;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace Cryville.Crtr.Browsing {
internal static class ExtensionManager {
static readonly Dictionary<string, List<ResourceConverter>> _converters
= new Dictionary<string, List<ResourceConverter>>();
public static IEnumerable<string> GetSupportedFormats() {
return _converters.Keys;
}
public static bool TryGetConverters(string extension, out IEnumerable<ResourceConverter> converters) {
List<ResourceConverter> outResult;
bool result = _converters.TryGetValue(extension, out outResult);
converters = outResult;
return result;
}
static readonly Dictionary<string, string> _localRes
= new Dictionary<string, string>();
public static IReadOnlyDictionary<string, string> GetLocalResourcePaths() {
return _localRes;
}
public static void Init(string rootPath) {
LoadExtension(typeof(Extensions.Umg.Extension));
var asms = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToHashSet();
var modules = new Queue<ModuleItem>();
var extensionDir = new DirectoryInfo(Path.Combine(rootPath, "extensions"));
if (extensionDir.Exists) {
foreach (var extension in extensionDir.EnumerateFiles("*.dll")) {
try {
modules.Enqueue(new ModuleItem(extension.OpenRead()));
}
catch (Exception ex) {
Logger.Log("main", 4, "Extension", "Failed to load DLL {0}: {1}", extension, ex);
}
}
}
int refCounter = 0;
while (modules.Count > 0 && refCounter < modules.Count) {
var module = modules.Dequeue();
bool flag = false;
foreach (var reference in module.Definition.AssemblyReferences) {
if (!asms.Contains(reference.Name)) {
flag = true;
break;
}
}
if (flag) {
modules.Enqueue(module);
refCounter++;
}
else {
try {
var stream = module.Stream;
stream.Seek(0, SeekOrigin.Begin);
var buf = new byte[stream.Length];
stream.Read(buf, 0, buf.Length);
var asm = Assembly.Load(buf);
if (asm == null) throw new TypeLoadException("Failed to load the module");
asms.Add(asm.GetName().Name);
foreach (var type in asm.GetTypes()) {
if (typeof(ExtensionInterface).IsAssignableFrom(type)) {
LoadExtension(type);
}
}
Logger.Log("main", 1, "Extension", "Loaded module {0}", module.Definition.Name);
}
catch (Exception ex) {
Logger.Log("main", 4, "Extension", "An error occured while trying to load module {0}: {1}", module.Definition.Name, ex);
}
finally {
module.Definition.Dispose();
module.Stream.Dispose();
refCounter = 0;
}
}
}
var missingList = new List<string>();
while (modules.Count > 0) {
missingList.Clear();
var module = modules.Dequeue();
foreach (var reference in module.Definition.AssemblyReferences) {
if (!asms.Contains(reference.Name)) {
missingList.Add(reference.Name);
}
}
Logger.Log("main", 4, "Extension", "Could not load the module {0} because the following dependencies were missing: {1}", module.Definition.Name, missingList.Aggregate((current, next) => current + ", " + next));
module.Definition.Dispose();
module.Stream.Dispose();
}
}
struct ModuleItem {
public ModuleDefinition Definition { get; set; }
public FileStream Stream { get; set; }
public ModuleItem(FileStream stream) {
Stream = stream;
Definition = ModuleDefinition.ReadModule(stream);
}
}
static void LoadExtension(Type type) {
try {
var extension = (ExtensionInterface)Activator.CreateInstance(type);
var l1 = extension.GetResourceConverters();
if (l1 != null) {
foreach (var c in l1) {
var fs = c.GetSupportedFormats();
if (fs == null) continue;
foreach (var f in fs) {
if (f == null) continue;
if (!_converters.ContainsKey(f))
_converters.Add(f, new List<ResourceConverter> { c });
else _converters[f].Add(c);
}
}
}
var l2 = extension.GetResourceFinders();
if (l2 != null) {
foreach (var f in l2) {
var name = f.Name;
var path = f.GetRootPath();
if (name != null && path != null) _localRes.Add(name, path);
}
}
Logger.Log("main", 1, "Extension", "Loaded extension {0}", type);
}
catch (Exception ex) {
Logger.Log("main", 4, "Extension", "Failed to load extension {0}: {1}", type, ex);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9ea11165e6269b488f916982507a2af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -12,6 +12,6 @@ namespace Cryville.Crtr.Browsing {
bool ImportItemFrom(string path); bool ImportItemFrom(string path);
string[] GetSupportedFormats(); string[] GetSupportedFormats();
Dictionary<string, string> GetPresetPaths(); IReadOnlyDictionary<string, string> GetPresetPaths();
} }
} }

View File

@@ -1,5 +1,7 @@
using Cryville.Common; using Cryville.Common;
using Cryville.Common.Unity; using Cryville.Common.Unity;
using Cryville.Crtr.Extension;
using Cryville.Crtr.Extensions.Umg;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -15,49 +17,13 @@ namespace Cryville.Crtr.Browsing {
private DirectoryInfo[] items = new DirectoryInfo[0]; private DirectoryInfo[] items = new DirectoryInfo[0];
public string[] CurrentDirectory { get; private set; } public string[] CurrentDirectory { get; private set; }
static readonly Dictionary<string, List<ResourceConverter>> converters static bool _init;
= new Dictionary<string, List<ResourceConverter>>();
static readonly Dictionary<string, string> localRes
= new Dictionary<string, string>();
public LegacyResourceManager(string rootPath) { public LegacyResourceManager(string rootPath) {
_rootPath = rootPath; _rootPath = rootPath;
} if (!_init) {
_init = true;
static LegacyResourceManager() { ExtensionManager.Init(rootPath);
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) {
foreach (var type in asm.GetTypes()) {
if (!type.IsSubclassOf(typeof(ExtensionInterface))) continue;
var ext = (ExtensionInterface)Activator.CreateInstance(type);
try {
var cs = ext.GetResourceConverters();
if (cs != null) {
foreach (var c in cs) {
var fs = c.GetSupportedFormats();
if (fs == null) continue;
foreach (var f in fs) {
if (f == null) continue;
if (!converters.ContainsKey(f))
converters.Add(f, new List<ResourceConverter> { c });
else converters[f].Add(c);
}
}
}
var fs2 = ext.GetResourceFinders();
if (fs2 != null) {
foreach (var f in fs2) {
var name = f.Name;
var path = f.GetRootPath();
if (name != null && path != null)
localRes.Add(name, path);
}
}
Logger.Log("main", 1, "Resource", "Loaded extension {0}", ReflectionHelper.GetNamespaceQualifiedName(type));
}
catch (Exception ex) {
Logger.Log("main", 4, "Resource", "Failed to initialize extension {0}: {1}", ReflectionHelper.GetNamespaceQualifiedName(type), ex);
}
}
} }
} }
@@ -149,14 +115,15 @@ namespace Cryville.Crtr.Browsing {
public bool ImportItemFrom(string path) { public bool ImportItemFrom(string path) {
var file = new FileInfo(path); var file = new FileInfo(path);
if (!converters.ContainsKey(file.Extension)) return false; IEnumerable<ResourceConverter> converters;
foreach (var converter in converters[file.Extension]) { if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
foreach (var converter in converters) {
IEnumerable<Resource> resources = null; IEnumerable<Resource> resources = null;
try { try {
resources = converter.ConvertFrom(file); resources = converter.ConvertFrom(file);
} }
catch (Exception ex) { catch (Exception ex) {
LogAndPopup(4, ex.Message); LogAndPopupExtra(4, ex, "Failed to import resource: {0}", ex.Message);
return false; return false;
} }
foreach (var res in resources) { foreach (var res in resources) {
@@ -168,7 +135,7 @@ namespace Cryville.Crtr.Browsing {
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name); var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
if (!dir.Exists) dir.Create(); if (!dir.Exists) dir.Create();
using (var writer = new StreamWriter(dir.FullName + "/.json")) { using (var writer = new StreamWriter(dir.FullName + "/.json")) {
writer.Write(JsonConvert.SerializeObject(tres.Main, Game.GlobalJsonSerializerSettings)); writer.Write(JsonConvert.SerializeObject(ConvertChartData(tres.Main), Game.GlobalJsonSerializerSettings));
} }
using (var writer = new StreamWriter(dir.FullName + "/.umgc")) { using (var writer = new StreamWriter(dir.FullName + "/.umgc")) {
tres.Meta.data = ""; tres.Meta.data = "";
@@ -219,12 +186,89 @@ namespace Cryville.Crtr.Browsing {
Popup.Create(msg); Popup.Create(msg);
} }
public string[] GetSupportedFormats() { void LogAndPopupExtra(int level, object extraLog, string format, params object[] args) {
return converters.Keys.ToArray(); var msg = string.Format(format, args);
Logger.Log("main", level, "Resource", "{0}\n{1}", msg, extraLog);
Popup.Create(msg);
} }
public Dictionary<string, string> GetPresetPaths() { public string[] GetSupportedFormats() {
return localRes; return ExtensionManager.GetSupportedFormats().ToArray();
}
public IReadOnlyDictionary<string, string> GetPresetPaths() {
return ExtensionManager.GetLocalResourcePaths();
}
static Chart ConvertChartData(ChartData i) {
return new Chart {
endtime = ConvertBeatTime(i.endtime),
format = i.format,
groups = ConvertGroups(i.groups),
motions = ConvertMotions(i.motions),
ruleset = i.ruleset,
sigs = ConvertSignatures(i.sigs),
sounds = ConvertSounds(i.sounds),
time = ConvertBeatTime(i.time),
};
}
static BeatTime? ConvertBeatTime(Extension.BeatTime? value) {
if (value == null) return null;
return new BeatTime(value.Value.b, value.Value.n, value.Value.d);
}
static List<Chart.Group> ConvertGroups(List<ChartData.Group> l) {
return l.Select(i => new Chart.Group {
endtime = ConvertBeatTime(i.endtime),
motions = ConvertMotions(i.motions),
notes = ConvertNotes(i.notes),
time = ConvertBeatTime(i.time),
tracks = ConvertTracks(i.tracks),
}).ToList();
}
static List<Chart.Judge> ConvertJudges(List<ChartData.Judge> l) {
return l.Select(i => new Chart.Judge {
endtime = ConvertBeatTime(i.endtime),
name = i.name,
time = ConvertBeatTime(i.time),
}).ToList();
}
static List<Chart.Motion> ConvertMotions(List<ChartData.Motion> l) {
return l.Select(i => new Chart.Motion {
endtime = ConvertBeatTime(i.endtime),
motion = i.motion,
sumfix = i.sumfix,
time = ConvertBeatTime(i.time),
}).ToList();
}
static List<Chart.Note> ConvertNotes(List<ChartData.Note> l) {
return l.Select(i => new Chart.Note {
endtime = ConvertBeatTime(i.endtime),
judges = ConvertJudges(i.judges),
motions = ConvertMotions(i.motions),
time = ConvertBeatTime(i.time),
}).ToList();
}
static List<Chart.Signature> ConvertSignatures(List<ChartData.Signature> l) {
return l.Select(i => new Chart.Signature {
endtime = ConvertBeatTime(i.endtime),
tempo = i.tempo,
time = ConvertBeatTime(i.time),
}).ToList();
}
static List<Chart.Sound> ConvertSounds(List<ChartData.Sound> l) {
return l.Select(i => new Chart.Sound {
endtime = ConvertBeatTime(i.endtime),
id = i.id,
offset = i.offset,
time = ConvertBeatTime(i.time),
}).ToList();
}
static List<Chart.Track> ConvertTracks(List<ChartData.Track> l) {
return l.Select(i => new Chart.Track {
endtime = ConvertBeatTime(i.endtime),
motions = ConvertMotions(i.motions),
time = ConvertBeatTime(i.time),
}).ToList();
} }
} }
} }

View File

@@ -1,6 +0,0 @@
namespace Cryville.Crtr.Browsing {
public abstract class LocalResourceFinder {
public abstract string Name { get; }
public abstract string GetRootPath();
}
}

View File

@@ -9,11 +9,11 @@ namespace Cryville.Crtr.Browsing {
public override object Value { public override object Value {
get { get {
float s_value = GetDisplayValue(); float s_value = GetDisplayValue();
return IntegerMode ? (object)(int)s_value : (object)s_value; return IntegerMode ? (int)s_value : (object)s_value;
} }
set { set {
if (value is double) m_value = (double)value; if (value is double) m_value = (double)value;
else m_value = IntegerMode ? (double)(int)value : (double)(float)value; else m_value = IntegerMode ? (int)value : (double)(float)value;
float s_value = GetDisplayValue(); float s_value = GetDisplayValue();
m_text.text = s_value.ToString(); m_text.text = s_value.ToString();
if (Range != null && MaxStep == 0) { if (Range != null && MaxStep == 0) {

View File

@@ -1,7 +1,7 @@
using Cryville.Common; using Cryville.Common;
using Cryville.Common.Unity.UI; using Cryville.Common.Unity.UI;
using Cryville.Crtr.Config; using Cryville.Crtr.Config;
using Newtonsoft.Json; using Cryville.Crtr.Extension;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@@ -94,24 +94,4 @@ namespace Cryville.Crtr.Browsing {
public AsyncDelivery<Texture2D> Cover { get; set; } public AsyncDelivery<Texture2D> Cover { get; set; }
public ChartMeta Meta { get; set; } public ChartMeta Meta { get; set; }
} }
#pragma warning disable IDE1006
public class MetaInfo {
public string name { get; set; }
public string author { get; set; }
[JsonRequired]
public string data { get; set; }
}
public class SongMetaInfo {
public string name { get; set; }
public string author { get; set; }
}
public class ChartMeta : MetaInfo {
public SongMetaInfo song { get; set; }
public float length { get; set; }
public string ruleset { get; set; }
public int note_count { get; set; }
public string cover { get; set; }
}
#pragma warning restore IDE1006
} }

View File

@@ -1,79 +0,0 @@
using Cryville.Common;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
namespace Cryville.Crtr.Browsing {
public abstract class ResourceConverter {
public abstract string[] GetSupportedFormats();
public abstract IEnumerable<Resource> ConvertFrom(FileInfo file);
}
public abstract class Resource {
protected Resource(string name) {
Name = StringUtils.EscapeFileName(name);
}
public string Name { get; private set; }
public abstract bool Valid { get; }
public override string ToString() {
return string.Format("{0} ({1})", Name, ReflectionHelper.GetSimpleName(GetType()));
}
}
public class RawChartResource : Resource {
public RawChartResource(string name, Chart main, ChartMeta meta) : base(name) {
Main = main; Meta = meta;
}
public Chart Main { get; private set; }
public ChartMeta Meta { get; private set; }
public override bool Valid { get { return true; } }
}
public abstract class FileResource : Resource {
public FileResource(string name, FileInfo master) : base(name) {
Master = master;
Attachments = new List<FileInfo>();
}
public FileInfo Master { get; private set; }
public List<FileInfo> Attachments { get; private set; }
public override bool Valid {
get {
if (!Master.Exists) return false;
foreach (var file in Attachments) {
if (!file.Exists) return false;
}
return true;
}
}
}
public class ChartResource : FileResource {
public ChartResource(string name, FileInfo master) : base(name, master) {
using (var reader = new StreamReader(master.FullName)) {
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
}
}
}
public class SongResource : FileResource {
public SongResource(string name, FileInfo master) : base(name, master) { }
}
public class RulesetResource : FileResource {
public RulesetResource(string name, FileInfo master) : base(name, master) {
using (var reader = new StreamReader(master.FullName)) {
var meta = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd());
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
}
}
}
public class SkinResource : FileResource {
public string RulesetName { get; private set; }
public SkinResource(string name, FileInfo master) : base(name, master) {
using (var reader = new StreamReader(master.FullName)) {
var meta = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
RulesetName = meta.ruleset;
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
foreach (var frame in meta.frames) {
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
}
}
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 2546fb1d514348842a14a03531be192d
timeCreated: 1637982768
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,20 +0,0 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Cryville.Crtr.Browsing {
public class SkinResourceImporter : ResourceConverter {
static readonly string[] SUPPORTED_FORMATS = { ".umgs" };
public override string[] GetSupportedFormats() {
return SUPPORTED_FORMATS;
}
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
var data = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd());
return new Resource[] { new SkinResource(data.name, file) };
}
}
}
}

View File

@@ -24,7 +24,7 @@ namespace Cryville.Crtr {
#region Fields #region Fields
Chart chart; Chart chart;
Skin skin; Skin skin;
PdtSkin pskin; public static PdtSkin pskin;
Ruleset ruleset; Ruleset ruleset;
PdtRuleset pruleset; PdtRuleset pruleset;
Dictionary<string, Texture2D> texs; Dictionary<string, Texture2D> texs;
@@ -485,7 +485,6 @@ namespace Cryville.Crtr {
} }
Game.AudioSequencer.Playing = true; Game.AudioSequencer.Playing = true;
atime0 = Game.AudioClient.BufferPosition; atime0 = Game.AudioClient.BufferPosition;
Thread.Sleep((int)((atime0 - Game.AudioClient.Position) * 1000));
inputProxy.SyncTime(cbus.Time); inputProxy.SyncTime(cbus.Time);
started = true; started = true;
} }

View File

@@ -2,6 +2,7 @@
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr.Components { namespace Cryville.Crtr.Components {
[DisallowMultipleComponent]
public abstract class MeshBase : SkinComponent { public abstract class MeshBase : SkinComponent {
public MeshBase() { public MeshBase() {
SubmitProperty("color", new PropOp.Color(v => Color = v)); SubmitProperty("color", new PropOp.Color(v => Color = v));

View File

@@ -72,7 +72,7 @@ namespace Cryville.Crtr.Components {
public op_set_shape(PolygonSGO self) : base(1) { public op_set_shape(PolygonSGO self) : base(1) {
_self = self; _self = self;
} }
protected unsafe override void Execute() { protected override unsafe void Execute() {
var o = GetOperand(0); var o = GetOperand(0);
if (o.Type != PdtInternalType.Vector) throw new ArgumentException("Not a vector"); if (o.Type != PdtInternalType.Vector) throw new ArgumentException("Not a vector");
_self._shapeLength = (o.Length - sizeof(int)) / sizeof(Vector2); _self._shapeLength = (o.Length - sizeof(int)) / sizeof(Vector2);

View File

@@ -1,5 +1,89 @@
namespace Cryville.Crtr.Components { using Cryville.Common;
using System;
using UnityEngine;
using Logger = Cryville.Common.Logger;
namespace Cryville.Crtr.Components {
public class SkinAnimation : SkinComponent { public class SkinAnimation : SkinComponent {
public SkinAnimation() {
SubmitProperty("name", new PropOp.Identifier(v => Name = v));
SubmitProperty("duration", new PropOp.Float(v => Duration = v));
SubmitProperty("iteration", new PropOp.Float(v => Iteration = v));
SubmitProperty("direction", new PropOp.Enum<AnimationDirection>(v => Direction = v, v => (AnimationDirection)v));
SubmitProperty("delay", new PropOp.Float(v => Delay = v));
Iteration = 1;
}
SkinContext _skinContext;
Transform _writeTransform;
AnimationSpan _anim;
int _name;
public int Name {
set {
if (_name == value) return;
_name = value;
if (value == 0) {
_anim = null;
}
else {
var id = new Identifier(value);
AnimationSpan anim;
if (!ChartPlayer.pskin.animations.TryGetValue(id, out anim)) {
Logger.Log("main", 4, "Skin", "Animation {0} not found", id.Name);
_anim = null;
return;
}
_anim = anim;
}
}
}
public float Duration { get; private set; }
public float Iteration { get; private set; }
public AnimationDirection Direction { get; private set; }
public float Delay { get; private set; }
double _startTime;
public override void Init() {
_skinContext = new SkinContext(transform);
}
public override void Rewind(double time, Transform target) {
_startTime = time;
if (target == null) target = transform;
_writeTransform = target;
}
public override void Tick(SkinContainer c, double time) {
float _rtime = (float)(time - _startTime - Delay) / Duration;
if (_rtime < 0) _rtime = 0;
else if (_rtime > Iteration) {
if (Direction.HasFlag(AnimationDirection.alternate)) {
_rtime = Iteration % 2;
if (_rtime > 1) _rtime = 2 - _rtime;
}
else {
_rtime = Iteration % 1;
if (_rtime == 0) _rtime = 1;
}
}
else {
if (Direction.HasFlag(AnimationDirection.alternate)) {
_rtime %= 2;
if (_rtime > 1) _rtime = 2 - _rtime;
}
else {
_rtime %= 1;
}
}
if (Direction.HasFlag(AnimationDirection.reverse)) _rtime = 1 - _rtime;
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext, _writeTransform));
}
protected override void OnDestroy() { } protected override void OnDestroy() { }
} }
[Flags]
public enum AnimationDirection {
normal = 0,
reverse = 1,
alternate = 2,
}
} }

View File

@@ -26,6 +26,8 @@ namespace Cryville.Crtr.Components {
} }
public virtual void Init() { } public virtual void Init() { }
public virtual void Rewind(double time, Transform target) { }
public virtual void Tick(SkinContainer c, double time) { }
protected abstract void OnDestroy(); protected abstract void OnDestroy();
} }
public struct SkinProperty { public struct SkinProperty {

View File

@@ -8,12 +8,12 @@ namespace Cryville.Crtr.Components {
SubmitProperty("border", new PropOp.Vector2(v => Border = v)); SubmitProperty("border", new PropOp.Vector2(v => Border = v));
} }
readonly static Dictionary<float, int> uvrefl static readonly Dictionary<float, int> uvrefl
= new Dictionary<float, int>() { = new Dictionary<float, int>() {
{-0.5f, 0}, {-0.4f, 1}, {0.4f, 2}, {0.5f, 3}, {-0.5f, 0}, {-0.4f, 1}, {0.4f, 2}, {0.5f, 3},
}; };
static Vector2[] _origuv; static Vector2[] _origuv;
protected new static Vector2[] OriginalUV { protected static new Vector2[] OriginalUV {
get { get {
if (_origuv == null) { if (_origuv == null) {
var m = GenericResources.Meshes["quad_scale3h"]; var m = GenericResources.Meshes["quad_scale3h"];

View File

@@ -19,7 +19,7 @@ namespace Cryville.Crtr.Components {
public op_set_frames(SpriteText self) : base(2) { public op_set_frames(SpriteText self) : base(2) {
_self = self; _self = self;
} }
protected unsafe override void Execute() { protected override unsafe void Execute() {
var keys = GetOperand(0).AsString(); var keys = GetOperand(0).AsString();
var values = GetOperand(1); var values = GetOperand(1);
int arrtype; int len; int arrtype; int len;

View File

@@ -1,5 +1,6 @@
using Cryville.Common.Buffers; using Cryville.Common.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class EffectGroup { public class EffectGroup {
@@ -35,28 +36,37 @@ namespace Cryville.Crtr {
while (_endQueue.Count > 0) { while (_endQueue.Count > 0) {
var item = _endQueue[0]; var item = _endQueue[0];
if (item.EndTime > _time) break; if (item.EndTime > _time) break;
item.OnDone(); _endQueue.RemoveAt(0);
if (item.OnStateDone()) {
QueueInstance(item);
}
else {
item.Tick(time);
_instances.Remove(item.Index); _instances.Remove(item.Index);
_pool.Return(item); _pool.Return(item);
_endQueue.RemoveAt(0); }
} }
foreach (var instance in _instances) { foreach (var instance in _instances) {
instance.Value.Tick(); instance.Value.Tick(time);
} }
} }
public void Emit(float index) { public void Emit(float index, Transform target = null) {
EffectInstance instance; EffectInstance instance;
if (_instances.TryGetValue(index, out instance)) { bool flag = _instances.TryGetValue(index, out instance);
if (!flag) _instances.Add(index, instance = _pool.Rent());
instance.Index = index;
if (instance.CanEmit()) {
if (flag) {
var i = _endQueue.BinarySearch(instance); var i = _endQueue.BinarySearch(instance);
_endQueue.RemoveAt(i); _endQueue.RemoveAt(i);
} }
else { instance.OnEmit(_time, target);
_instances.Add(index, instance = _pool.Rent()); QueueInstance(instance);
} }
instance.Index = index; }
instance.OnEmit(_time); void QueueInstance(EffectInstance i) {
var i2 = ~_endQueue.BinarySearch(instance); var index = ~_endQueue.BinarySearch(i);
_endQueue.Insert(i2, instance); _endQueue.Insert(index, i);
} }
public void Dispose() { public void Dispose() {
_pool.DisposeAll(); _pool.DisposeAll();

View File

@@ -1,5 +1,6 @@
using Cryville.Common; using Cryville.Common;
using Cryville.Crtr.Components; using Cryville.Crtr.Components;
using Cryville.Crtr.Event;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@@ -10,19 +11,24 @@ namespace Cryville.Crtr {
readonly EffectDefinition _def; readonly EffectDefinition _def;
readonly SkinContainer _skinContainer; readonly SkinContainer _skinContainer;
public Transform RootTransform { get; private set; } public Transform RootTransform { get; private set; }
readonly SkinComponent[] _comps;
public EffectInstance(EffectDefinition def) { public EffectInstance(EffectDefinition def) {
_def = def; _def = def;
_skinContainer = new SkinContainer(_def.elements); _skinContainer = new SkinContainer(this, _def.elements);
RootTransform = new GameObject("effect:" + GetHashCode().ToString(CultureInfo.InvariantCulture)).transform; RootTransform = new GameObject("effect:" + GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
SkinContext = new SkinContext(RootTransform); SkinContext = new SkinContext(RootTransform);
ChartPlayer.etor.ContextCascadeInsertBlock(); ChartPlayer.etor.ContextCascadeInsertBlock();
_skinContainer.MatchStatic(this); _skinContainer.MatchStatic();
ChartPlayer.etor.ContextCascadeDiscardBlock(); ChartPlayer.etor.ContextCascadeDiscardBlock();
foreach (var i in RootTransform.GetComponentsInChildren<SkinComponent>()) _comps = RootTransform.GetComponentsInChildren<SkinComponent>();
i.Init(); foreach (var i in _comps) i.Init();
_indexSrc = new PropSrc.Float(() => Index); _indexSrc = new PropSrc.Float(() => Index);
_durationOp = new PropOp.Float(v => _duration = v); _durationOp = new PropOp.Float(v => _duration = v);
} }
public void Rewind(double time, Transform target) {
_startTime = time;
foreach (var i in _comps) i.Rewind(time, target);
}
private float m_index; private float m_index;
public float Index { public float Index {
get { return m_index; } get { return m_index; }
@@ -32,26 +38,62 @@ namespace Cryville.Crtr {
_indexSrc.Invalidate(); _indexSrc.Invalidate();
} }
} }
Transform _currentTarget;
Identifier _currentStateName = Identifier.Empty;
EffectState _currentState;
ChartEvent _ctxev;
ContainerState _ctxstate;
internal static readonly int _VAR_EFFECT_INDEX = IdentifierManager.SharedInstance.Request("effect_index"); internal static readonly int _VAR_EFFECT_INDEX = IdentifierManager.SharedInstance.Request("effect_index");
readonly PropSrc _indexSrc; readonly PropSrc _indexSrc;
double _startTime; double _startTime;
float _duration; float _duration;
readonly PropOp _durationOp; readonly PropOp _durationOp;
public double EndTime { get { return _startTime + _duration; } } public double EndTime { get { return _startTime + _duration; } }
public void Tick() { public void Tick(double time) {
_skinContainer.MatchDynamic(this, 1); foreach (var i in _comps) i.Tick(_skinContainer, time);
} }
public void OnEmit(double time) { public bool CanEmit() {
_startTime = time; return _currentStateName.Key == 0 || _currentState.rewind.Key != 0;
}
public void OnEmit(double time, Transform target) {
_currentTarget = target;
_ctxev = ChartPlayer.etor.ContextEvent;
_ctxstate = ChartPlayer.etor.ContextState;
if (_currentStateName.Key == 0) {
EnterState(_def.init, time, _currentTarget, true);
}
else {
if (_currentState.rewind.Key == 0) throw new InvalidOperationException("Cannot rewind");
EnterState(_currentState.rewind, time, _currentTarget, true);
}
}
void EnterState(Identifier name, double time, Transform target, bool emitting) {
_currentStateName = name;
_currentState = _def.states[name];
Rewind(time, target);
RootTransform.gameObject.SetActive(true); RootTransform.gameObject.SetActive(true);
ChartPlayer.etor.ContextCascadeInsert(); ChartPlayer.etor.ContextCascadeInsert();
ChartPlayer.etor.ContextCascadeUpdate(_VAR_EFFECT_INDEX, _indexSrc); ChartPlayer.etor.ContextCascadeUpdate(_VAR_EFFECT_INDEX, _indexSrc);
ChartPlayer.etor.Evaluate(_durationOp, _def.duration); ChartPlayer.etor.Evaluate(_durationOp, _currentState.duration);
_skinContainer.MatchDynamic(this, 0); if (emitting) _skinContainer.MatchDynamic(0, true);
_skinContainer.MatchDynamic(1, emitting);
ChartPlayer.etor.ContextCascadeDiscard(); ChartPlayer.etor.ContextCascadeDiscard();
} }
public void OnDone() { public bool OnStateDone() {
if (_currentState.next.Key == 0) {
RootTransform.gameObject.SetActive(false); RootTransform.gameObject.SetActive(false);
_currentStateName = Identifier.Empty;
_currentState = null;
return false;
}
else {
ChartPlayer.etor.ContextEvent = _ctxev;
ChartPlayer.etor.ContextState = _ctxstate;
EnterState(_currentState.next, EndTime, _currentTarget, false);
ChartPlayer.etor.ContextEvent = null;
ChartPlayer.etor.ContextState = null;
return true;
}
} }
public void Dispose() { public void Dispose() {
GameObject.Destroy(RootTransform.gameObject); GameObject.Destroy(RootTransform.gameObject);
@@ -59,7 +101,7 @@ namespace Cryville.Crtr {
public string TypeName { get { throw new InvalidOperationException("Type name undefined"); } } public string TypeName { get { throw new InvalidOperationException("Type name undefined"); } }
public SkinContext SkinContext { get; private set; } public SkinContext SkinContext { get; private set; }
public Anchor OpenedAnchor { get { throw new InvalidOperationException("Anchor not supported"); } } public int OpenedAnchorName { get { return _currentStateName.Key; } }
public void PushAnchorEvent(double time, int name) { public void PushAnchorEvent(double time, int name) {
throw new InvalidOperationException("Anchor not supported"); throw new InvalidOperationException("Anchor not supported");
} }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class EffectManager { public class EffectManager {
@@ -15,6 +16,9 @@ namespace Cryville.Crtr {
public void Emit(int id, float index) { public void Emit(int id, float index) {
_groups[id].Emit(index); _groups[id].Emit(index);
} }
public void EmitSelf(int id, float index, Transform target) {
_groups[id].Emit(index, target);
}
public void Dispose() { public void Dispose() {
foreach (var g in _groups) g.Value.Dispose(); foreach (var g in _groups) g.Value.Dispose();
} }

View File

@@ -37,10 +37,9 @@ namespace Cryville.Crtr.Event {
/// </summary> /// </summary>
public ContainerState ts; public ContainerState ts;
/// <summary> protected Transform RootTransform;
/// <see cref="GameObject"/> group, the <see cref="Transform"/> containing all the generated elements in the <see cref="ContainerHandler"/>.
/// </summary> SkinComponent[] _comps;
protected Transform gogroup;
public Vector3 Position { get; protected set; } public Vector3 Position { get; protected set; }
public Quaternion Rotation { get; protected set; } public Quaternion Rotation { get; protected set; }
@@ -70,7 +69,7 @@ namespace Cryville.Crtr.Event {
SkinContainer skinContainer; SkinContainer skinContainer;
protected Judge judge; protected Judge judge;
public void AttachSystems(PdtSkin skin, Judge judge) { public void AttachSystems(PdtSkin skin, Judge judge) {
skinContainer = new SkinContainer(skin.elements); skinContainer = new SkinContainer(this, skin.elements);
this.judge = judge; this.judge = judge;
} }
@@ -80,15 +79,15 @@ namespace Cryville.Crtr.Event {
Anchor a_cur; Anchor a_cur;
Anchor a_head; Anchor a_head;
Anchor a_tail; Anchor a_tail;
readonly static int _a_cur = IdentifierManager.SharedInstance.Request("cur"); static readonly int _a_cur = IdentifierManager.SharedInstance.Request("cur");
readonly static int _a_head = IdentifierManager.SharedInstance.Request("head"); static readonly int _a_head = IdentifierManager.SharedInstance.Request("head");
readonly static int _a_tail = IdentifierManager.SharedInstance.Request("tail"); static readonly int _a_tail = IdentifierManager.SharedInstance.Request("tail");
double atime_head; double atime_head;
double atime_tail; double atime_tail;
public Anchor RegisterAnchor(int name, bool dyn = false, int propSrcCount = 0) { public Anchor RegisterAnchor(int name, bool dyn = false, int propSrcCount = 0) {
var strname = IdentifierManager.SharedInstance.Retrieve(name); var strname = IdentifierManager.SharedInstance.Retrieve(name);
var go = new GameObject("." + strname).transform; var go = new GameObject("." + strname).transform;
go.SetParent(gogroup, false); go.SetParent(RootTransform, false);
var result = new Anchor(name, go, propSrcCount); var result = new Anchor(name, go, propSrcCount);
if (dyn) { if (dyn) {
if (DynamicAnchors.ContainsKey(name)) if (DynamicAnchors.ContainsKey(name))
@@ -103,22 +102,22 @@ namespace Cryville.Crtr.Event {
return result; return result;
} }
protected void OpenAnchor(Anchor anchor) { protected void OpenAnchor(Anchor anchor) {
if (OpenedAnchor != null) throw new InvalidOperationException("An anchor has been opened"); if (_openedAnchor != null) throw new InvalidOperationException("An anchor has been opened");
anchor.Transform.gameObject.SetActive(true); anchor.Transform.gameObject.SetActive(true);
OpenedAnchor = anchor; _openedAnchor = anchor;
} }
protected void CloseAnchor() { protected void CloseAnchor() {
OpenedAnchor = null; _openedAnchor = null;
} }
#endregion #endregion
#region Logic #region Logic
#region Init methods: Called on prehandle #region Init methods: Called on prehandle
public virtual void PreInit() { public virtual void PreInit() {
gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform; RootTransform = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
SkinContext = new SkinContext(gogroup); SkinContext = new SkinContext(RootTransform);
if (cs.Parent != null) if (cs.Parent != null)
gogroup.SetParent(cs.Parent.Handler.gogroup, false); RootTransform.SetParent(cs.Parent.Handler.RootTransform, false);
a_cur = RegisterAnchor(_a_cur); a_cur = RegisterAnchor(_a_cur);
a_head = RegisterAnchor(_a_head, true); a_head = RegisterAnchor(_a_head, true);
a_tail = RegisterAnchor(_a_tail, true); a_tail = RegisterAnchor(_a_tail, true);
@@ -126,16 +125,16 @@ namespace Cryville.Crtr.Event {
public virtual void Init() { public virtual void Init() {
ChartPlayer.etor.ContextState = ps; ChartPlayer.etor.ContextState = ps;
ChartPlayer.etor.ContextEvent = Container; ChartPlayer.etor.ContextEvent = Container;
skinContainer.MatchStatic(this); skinContainer.MatchStatic();
ChartPlayer.etor.ContextEvent = null; ChartPlayer.etor.ContextEvent = null;
ChartPlayer.etor.ContextState = null; ChartPlayer.etor.ContextState = null;
foreach (var i in gogroup.GetComponentsInChildren<SkinComponent>()) _comps = RootTransform.GetComponentsInChildren<SkinComponent>();
i.Init(); foreach (var i in _comps) i.Init();
} }
public virtual void PostInit() { public virtual void PostInit() {
PropSrcs.Add(_var_current_time, new PropSrc.Float(() => (float)cs.rootPrototype.Time)); PropSrcs.Add(_var_current_time, new PropSrc.Float(() => (float)cs.rootPrototype.Time));
PropSrcs.Add(_var_invisible_bounds, new PropSrc.Boolean(() => atime_head > atime_tail)); PropSrcs.Add(_var_invisible_bounds, new PropSrc.Boolean(() => atime_head > atime_tail));
gogroup.gameObject.SetActive(false); RootTransform.gameObject.SetActive(false);
} }
#endregion #endregion
#region Start methods #region Start methods
@@ -146,14 +145,14 @@ namespace Cryville.Crtr.Event {
public virtual void StartLogicalUpdate(ContainerState s) { } public virtual void StartLogicalUpdate(ContainerState s) { }
protected virtual void StartPreGraphicalUpdate(ContainerState s) { } protected virtual void StartPreGraphicalUpdate(ContainerState s) { }
protected virtual void StartGraphicalUpdate(ContainerState s) { protected virtual void StartGraphicalUpdate(ContainerState s) {
if (gogroup) gogroup.gameObject.SetActive(true); if (RootTransform) RootTransform.gameObject.SetActive(true);
} }
#endregion #endregion
public virtual void Update(ContainerState s, StampedEvent ev) { public virtual void Update(ContainerState s, StampedEvent ev) {
if (s.CloneType == 3) SetPreGraphicalActive(true, s); if (s.CloneType == 3) SetPreGraphicalActive(true, s);
else if (ev is StampedEvent.Anchor) { else if (ev is StampedEvent.Anchor) {
var tev = (StampedEvent.Anchor)ev; var tev = (StampedEvent.Anchor)ev;
if (gogroup) { if (RootTransform) {
OpenAnchor(tev.Target); OpenAnchor(tev.Target);
#if UNITY_5_6_OR_NEWER #if UNITY_5_6_OR_NEWER
tev.Target.Transform.SetPositionAndRotation(Position, Rotation); tev.Target.Transform.SetPositionAndRotation(Position, Rotation);
@@ -172,7 +171,7 @@ namespace Cryville.Crtr.Event {
} }
anchorEvPool.Return(tev); anchorEvPool.Return(tev);
} }
else if (gogroup && s.CloneType == 2) MatchDynamic(s, 1); else if (RootTransform && s.CloneType == 2) MatchDynamic(s, 1);
} }
#region End methods #region End methods
protected virtual void EndGraphicalUpdate(ContainerState s) { } protected virtual void EndGraphicalUpdate(ContainerState s) { }
@@ -180,8 +179,8 @@ namespace Cryville.Crtr.Event {
public virtual void EndLogicalUpdate(ContainerState s) { } public virtual void EndLogicalUpdate(ContainerState s) { }
public virtual void EndPhysicalUpdate(ContainerState s) { } public virtual void EndPhysicalUpdate(ContainerState s) { }
public virtual void Dispose() { public virtual void Dispose() {
if (gogroup) if (RootTransform)
GameObject.Destroy(gogroup.gameObject); GameObject.Destroy(RootTransform.gameObject);
Alive = false; Alive = false;
} }
public virtual void DisposeAll() { } public virtual void DisposeAll() { }
@@ -193,7 +192,7 @@ namespace Cryville.Crtr.Event {
void MatchDynamic(ContainerState s, int dl) { void MatchDynamic(ContainerState s, int dl) {
ChartPlayer.etor.ContextState = s; ChartPlayer.etor.ContextState = s;
ChartPlayer.etor.ContextEvent = Container; ChartPlayer.etor.ContextEvent = Container;
skinContainer.MatchDynamic(this, dl); skinContainer.MatchDynamic(dl);
ChartPlayer.etor.ContextEvent = null; ChartPlayer.etor.ContextEvent = null;
ChartPlayer.etor.ContextState = null; ChartPlayer.etor.ContextState = null;
} }
@@ -205,6 +204,7 @@ namespace Cryville.Crtr.Event {
atime_head = cs.StampedContainer.Time; atime_head = cs.StampedContainer.Time;
atime_tail = atime_head + cs.StampedContainer.Duration; atime_tail = atime_head + cs.StampedContainer.Duration;
MatchDynamic(cs, 0); MatchDynamic(cs, 0);
foreach (var i in _comps) i.Tick(skinContainer, cs.Time);
if (cs.Active) PushAnchorEvent(cs.Time, a_cur); if (cs.Active) PushAnchorEvent(cs.Time, a_cur);
if (double.IsNaN(DynamicAnchorSetTime[_a_head])) DynamicAnchorSetTime[_a_head] = atime_head; if (double.IsNaN(DynamicAnchorSetTime[_a_head])) DynamicAnchorSetTime[_a_head] = atime_head;
if (double.IsNaN(DynamicAnchorSetTime[_a_tail])) DynamicAnchorSetTime[_a_tail] = atime_tail; if (double.IsNaN(DynamicAnchorSetTime[_a_tail])) DynamicAnchorSetTime[_a_tail] = atime_tail;
@@ -241,7 +241,8 @@ namespace Cryville.Crtr.Event {
#region ISkinnableGroup #region ISkinnableGroup
public abstract string TypeName { get; } public abstract string TypeName { get; }
public SkinContext SkinContext { get; private set; } public SkinContext SkinContext { get; private set; }
public Anchor OpenedAnchor { get; private set; } Anchor _openedAnchor;
public int OpenedAnchorName { get { return _openedAnchor == null ? 0 : _openedAnchor.Name; } }
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) { public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
List<Anchor> anchors; List<Anchor> anchors;
var ret = Anchors.TryGetValue(name, out anchors); var ret = Anchors.TryGetValue(name, out anchors);

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: dbc046e7cabacbb4fbf74520399a7340 guid: b35ffffce02252548a66e18cf98050e2
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

Some files were not shown because too many files have changed in this diff Show More