Compare commits
104 Commits
0.6.0-rc1
...
2eef1b5c4e
8
Assets/Cryville/Common/Collections.meta
Normal file
8
Assets/Cryville/Common/Collections.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4ef48e4a4983de4e9c31483df2a918e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Cryville/Common/Collections/Generic.meta
Normal file
8
Assets/Cryville/Common/Collections/Generic.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ec674235c0dd6744af2dab2b58dd53c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Cryville/Common/Collections/Generic/IPairList.cs
Normal file
8
Assets/Cryville/Common/Collections/Generic/IPairList.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Common/Collections/Generic/IPairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/Generic/IPairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73fb17b484b343242bcce27c15ed7d44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal file
46
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2517e8f040bd36f46948e5fafaf5335c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Assets/Cryville/Common/Collections/Generic/PairList.cs
Normal file
48
Assets/Cryville/Common/Collections/Generic/PairList.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Common/Collections/Generic/PairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/Generic/PairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9ed5ea8b7b1a934287e7ec5971166c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Cryville/Common/Collections/IPairList.cs
Normal file
8
Assets/Cryville/Common/Collections/IPairList.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Common/Collections/IPairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/IPairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 046617672d437de4ab7e644a55defd3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Cryville/Common/Collections/PairCollection.cs
Normal file
47
Assets/Cryville/Common/Collections/PairCollection.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Common/Collections/PairCollection.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/PairCollection.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f87dfb8f6a1f5640b6deae741cd715c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Cryville/Common/Collections/PairList.cs
Normal file
29
Assets/Cryville/Common/Collections/PairList.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Common/Collections/PairList.cs.meta
Normal file
11
Assets/Cryville/Common/Collections/PairList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57fc9f037c1fda5449e2a365a835c82c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -45,7 +45,7 @@ namespace Cryville.Common.Font {
|
||||
return tableDirectoryOffsets;
|
||||
}
|
||||
public override TableDirectory GetSubTable(UInt32 item) {
|
||||
var i = (UInt32)item;
|
||||
var i = item;
|
||||
return new TableDirectory(Reader, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Cryville.Common {
|
||||
public struct Identifier : IEquatable<Identifier> {
|
||||
public static Identifier Empty = new Identifier(0);
|
||||
public int Key { get; private set; }
|
||||
public object Name { get { return IdentifierManager.SharedInstance.Retrieve(Key); } }
|
||||
public Identifier(int key) {
|
||||
@@ -24,11 +25,11 @@ namespace Cryville.Common {
|
||||
if (Key == 0) return "";
|
||||
return Name.ToString();
|
||||
}
|
||||
public static implicit operator Identifier(string identifier) {
|
||||
return new Identifier(identifier);
|
||||
public static bool operator ==(Identifier lhs, Identifier rhs) {
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
public static implicit operator string(Identifier identifier) {
|
||||
return identifier.ToString();
|
||||
public static bool operator !=(Identifier lhs, Identifier rhs) {
|
||||
return !lhs.Equals(rhs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
Assets/Cryville/Common/Math/CubicBezier.cs
Normal file
44
Assets/Cryville/Common/Math/CubicBezier.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Common/Math/CubicBezier.cs.meta
Normal file
11
Assets/Cryville/Common/Math/CubicBezier.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17dd6f775fc965f43960da7166b55b87
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,12 +12,12 @@ namespace Cryville.Common.Math {
|
||||
/// <param name="error">The error.</param>
|
||||
/// <param name="n">The numerator.</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) {
|
||||
if (value < 0.0)
|
||||
throw new ArgumentOutOfRangeException("value", "Must be >= 0.");
|
||||
if (error <= 0.0 || error >= 1.0)
|
||||
throw new ArgumentOutOfRangeException("accuracy", "Must be > 0 and < 1.");
|
||||
if (error <= 0.0 || error > 1.0)
|
||||
throw new ArgumentOutOfRangeException("error", "Must be > 0 and <= 1.");
|
||||
|
||||
int num = (int)System.Math.Floor(value);
|
||||
value -= num;
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// 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>
|
||||
/// <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>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class ElementListAttribute : Attribute { }
|
||||
@@ -14,7 +14,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// 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>
|
||||
/// <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>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class PropertyListAttribute : Attribute { }
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace Cryville.Common.Pdt {
|
||||
protected abstract PdtOperator GetOperator(PdtOperatorSignature sig);
|
||||
unsafe void Operate(PdtOperator op, int pc, bool noset = false) {
|
||||
fixed (byte* pmem = _mem) {
|
||||
op.Begin(this);
|
||||
op.Begin(this, pc);
|
||||
for (int i = 0; i < pc; i++) {
|
||||
var frame = _stack[--_framecount];
|
||||
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
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 },
|
||||
{ '*', 6 }, { '/', 6 }, { '%', 6 },
|
||||
{ '+', 5 }, { '-', 5 },
|
||||
@@ -103,7 +103,7 @@ namespace Cryville.Common.Pdt {
|
||||
{ ',', 0 },
|
||||
{ '$', -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 },
|
||||
@@ -115,7 +115,7 @@ namespace Cryville.Common.Pdt {
|
||||
{ '$', -1 },
|
||||
};
|
||||
|
||||
readonly static PdtExpression _emptyexp;
|
||||
static readonly PdtExpression _emptyexp;
|
||||
static PdtInterpreter() {
|
||||
var ins = new LinkedList<PdtInstruction>();
|
||||
ins.AddLast(new PdtInstruction.PushConstant(
|
||||
@@ -143,7 +143,7 @@ namespace Cryville.Common.Pdt {
|
||||
public override string ToString() {
|
||||
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,
|
||||
Value = "$",
|
||||
};
|
||||
|
||||
@@ -6,30 +6,30 @@
|
||||
/// <summary>
|
||||
/// Error type.
|
||||
/// </summary>
|
||||
public readonly static int Error = 0x00525245;
|
||||
public const int Error = 0x00525245;
|
||||
/// <summary>
|
||||
/// Array of a same variable-length type, with a suffix indicating the element count and the element type.
|
||||
/// </summary>
|
||||
public readonly static int Array = 0x00525241;
|
||||
public const int Array = 0x00525241;
|
||||
/// <summary>
|
||||
/// Null type.
|
||||
/// </summary>
|
||||
public readonly static int Null = 0x4c4c554e;
|
||||
public const int Null = 0x4c4c554e;
|
||||
/// <summary>
|
||||
/// IEEE 754 32-bit floating-point number.
|
||||
/// </summary>
|
||||
public readonly static int Number = 0x004d554e;
|
||||
public const int Number = 0x004d554e;
|
||||
/// <summary>
|
||||
/// A sequence of UTF-16 code units, with a prefix indicating the number of the code units.
|
||||
/// </summary>
|
||||
public readonly static int String = 0x00525453;
|
||||
public const int String = 0x00525453;
|
||||
/// <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.
|
||||
/// </summary>
|
||||
public readonly static int Undefined = 0x00444e55;
|
||||
public const int Undefined = 0x00444e55;
|
||||
/// <summary>
|
||||
/// Vector of a same constant-length type, with a suffix indicating the element type.
|
||||
/// </summary>
|
||||
public readonly static int Vector = 0x00434556;
|
||||
public const int Vector = 0x00434556;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Cryville.Common.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -27,7 +28,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// <item><term><c>0x1000</c></term><description>End of Key</description></item>
|
||||
/// </list>
|
||||
/// </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
|
||||
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,
|
||||
@@ -54,15 +55,14 @@ namespace Cryville.Common.Pdt {
|
||||
/// <param name="binder">The binder.</param>
|
||||
/// <returns>The interpreted object.</returns>
|
||||
public static T Interpret<T>(string src, Binder binder) {
|
||||
return (T)new PdtInterpreter(src, typeof(T), binder).Interpret();
|
||||
return (T)new PdtInterpreter(src, binder).Interpret(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The source string.
|
||||
/// </summary>
|
||||
public string Source { get; private set; }
|
||||
readonly Type _type;
|
||||
readonly Binder _binder;
|
||||
Binder _binder;
|
||||
/// <summary>
|
||||
/// The current position in the string being parsed by the interpreter.
|
||||
/// </summary>
|
||||
@@ -167,23 +167,27 @@ namespace Cryville.Common.Pdt {
|
||||
/// Creates an instance of the <see cref="PdtInterpreter" /> class.
|
||||
/// </summary>
|
||||
/// <param name="src">The source string.</param>
|
||||
/// <param name="type">The destination type.</param>
|
||||
/// <param name="binder">The binder. May be <c>null</c>.</param>
|
||||
public PdtInterpreter(string src, Type type, Binder binder) {
|
||||
public PdtInterpreter(string src, Binder binder) {
|
||||
Source = src;
|
||||
_type = type;
|
||||
_binder = binder;
|
||||
if (_binder == null)
|
||||
_binder = BinderAttribute.CreateBinderOfType(_type);
|
||||
}
|
||||
int[] m_formatVersion;
|
||||
public int[] GetFormatVersion() {
|
||||
if (m_formatVersion == null) InterpretDirectives();
|
||||
return m_formatVersion;
|
||||
}
|
||||
/// <summary>
|
||||
/// Interprets the source to an object.
|
||||
/// </summary>
|
||||
/// <param name="type">The output type.</param>
|
||||
/// <returns>The interpreted object.</returns>
|
||||
public object Interpret() {
|
||||
public object Interpret(Type type) {
|
||||
try {
|
||||
InterpretDirectives();
|
||||
return InterpretObject(_type);
|
||||
if (m_formatVersion == null) InterpretDirectives();
|
||||
if (_binder == null)
|
||||
_binder = BinderAttribute.CreateBinderOfType(type);
|
||||
return InterpretObject(type);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new PdtParsingException(this, ex);
|
||||
@@ -201,7 +205,10 @@ namespace Cryville.Common.Pdt {
|
||||
break;
|
||||
case "format":
|
||||
ws();
|
||||
if (GetNumber() != "1")
|
||||
m_formatVersion = (from i in GetNumber().Split('.') select int.Parse(i)).ToArray();
|
||||
if (m_formatVersion.Length == 0)
|
||||
throw new FormatException("Invalid format version");
|
||||
if (m_formatVersion[0] != 1)
|
||||
throw new NotSupportedException("Format not supported");
|
||||
flag = true;
|
||||
break;
|
||||
@@ -226,6 +233,10 @@ namespace Cryville.Common.Pdt {
|
||||
while (true) {
|
||||
try { ws(); }
|
||||
catch (IndexOutOfRangeException) { return result; }
|
||||
if (cc == '}') {
|
||||
GetChar();
|
||||
return result;
|
||||
}
|
||||
object pkey = InterpretKey(type);
|
||||
char c = GetChar();
|
||||
switch (c) {
|
||||
@@ -245,13 +256,13 @@ namespace Cryville.Common.Pdt {
|
||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||
Type ptype = ReflectionHelper.GetMemberType(prop);
|
||||
if (flag) {
|
||||
if (!typeof(IDictionary).IsAssignableFrom(ptype))
|
||||
throw new InvalidOperationException("Internal error: Element list is not a dictionary");
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = InterpretObject(vtype);
|
||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||
using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = InterpretObject(vtype);
|
||||
collection.Add(key, value);
|
||||
}
|
||||
}
|
||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
||||
}
|
||||
@@ -274,13 +285,13 @@ namespace Cryville.Common.Pdt {
|
||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||
var ptype = ReflectionHelper.GetMemberType(prop);
|
||||
if (flag) {
|
||||
if (!typeof(IDictionary).IsAssignableFrom(ptype))
|
||||
throw new InvalidOperationException("Internal error: Property list is not a dictionary");
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = _binder.ChangeType(exp, vtype, null);
|
||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||
using (var collection = new PairCollection(ReflectionHelper.GetValue(prop, result))) {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = _binder.ChangeType(exp, vtype, null);
|
||||
collection.Add(key, value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
object value = _binder.ChangeType(exp, ptype, null);
|
||||
@@ -288,8 +299,6 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
return result;
|
||||
default:
|
||||
throw new InvalidOperationException("Internal error: Invalid key interpretation");
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// PDT operator.
|
||||
/// </summary>
|
||||
public unsafe abstract class PdtOperator {
|
||||
public abstract unsafe class PdtOperator {
|
||||
byte* _prmem;
|
||||
int _loadindex;
|
||||
readonly PdtVariableMemory[] _operands;
|
||||
/// <summary>
|
||||
/// The count of the operands loaded.
|
||||
/// </summary>
|
||||
protected int LoadedOperandCount { get { return _pc - _loadindex; } }
|
||||
protected int LoadedOperandCount { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets the operand at the specified index.
|
||||
/// </summary>
|
||||
@@ -35,13 +35,13 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
PdtEvaluatorBase _etor;
|
||||
bool _rfreq = true;
|
||||
internal void Begin(PdtEvaluatorBase etor) {
|
||||
internal void Begin(PdtEvaluatorBase etor, int pc) {
|
||||
_etor = etor;
|
||||
_loadindex = _pc;
|
||||
_loadindex = LoadedOperandCount = pc;
|
||||
}
|
||||
internal void LoadOperand(PdtVariableMemory mem) {
|
||||
if (_loadindex == 0) return;
|
||||
_operands[--_loadindex] = mem;
|
||||
if (--_loadindex >= _pc) return;
|
||||
_operands[_loadindex] = mem;
|
||||
}
|
||||
internal void Call(byte* prmem, bool noset) {
|
||||
_prmem = prmem;
|
||||
|
||||
@@ -3,6 +3,6 @@ using UnityEngine;
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
public abstract class SetParameterBehaviour : StateMachineBehaviour {
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace Cryville.Crtr.Browsing {
|
||||
public override object Value {
|
||||
get {
|
||||
float s_value = GetDisplayValue();
|
||||
return IntegerMode ? (object)(int)s_value : (object)s_value;
|
||||
return IntegerMode ? (int)s_value : (object)s_value;
|
||||
}
|
||||
set {
|
||||
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();
|
||||
m_text.text = s_value.ToString();
|
||||
if (Range != null && MaxStep == 0) {
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
[JsonConverter(typeof(BeatTimeConverter))]
|
||||
@@ -154,6 +155,10 @@ namespace Cryville.Crtr {
|
||||
protected ChartEvent() {
|
||||
PropSrcs = new Dictionary<int, PropSrc>();
|
||||
PropOps = new Dictionary<int, PropOp>();
|
||||
SubmitPropSrc("event", new PropSrc.Float(() => {
|
||||
int hash = GetHashCode();
|
||||
return Unsafe.As<int, float>(ref hash);
|
||||
}));
|
||||
SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong));
|
||||
SubmitPropSrc("time", new PropSrc.BeatTime(() => time.Value));
|
||||
SubmitPropSrc("endtime", new PropSrc.BeatTime(() => endtime.Value));
|
||||
@@ -320,7 +325,7 @@ namespace Cryville.Crtr {
|
||||
else {
|
||||
AbsoluteValue = Vector.Construct(registry.Type, m.Groups[11].Value);
|
||||
}
|
||||
SubmitPropSrc("value", VectorSrc.Construct(() => {
|
||||
SubmitPropSrc("value", new VectorSrc(() => {
|
||||
if (RelativeNode != null) return RelativeNode.Value;
|
||||
else return AbsoluteValue;
|
||||
}));
|
||||
|
||||
@@ -16,7 +16,6 @@ using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Scripting;
|
||||
using UnityEngine.UI;
|
||||
using diag = System.Diagnostics;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
@@ -25,7 +24,7 @@ namespace Cryville.Crtr {
|
||||
#region Fields
|
||||
Chart chart;
|
||||
Skin skin;
|
||||
PdtSkin pskin;
|
||||
public static PdtSkin pskin;
|
||||
Ruleset ruleset;
|
||||
PdtRuleset pruleset;
|
||||
Dictionary<string, Texture2D> texs;
|
||||
@@ -43,14 +42,14 @@ namespace Cryville.Crtr {
|
||||
EventBus bbus;
|
||||
EventBus tbus;
|
||||
EventBus nbus;
|
||||
InputProxy inputProxy;
|
||||
Judge judge;
|
||||
public static EffectManager effectManager;
|
||||
bool started = false;
|
||||
|
||||
static bool initialized;
|
||||
static Text logs;
|
||||
TextMeshProUGUI logs;
|
||||
TextMeshProUGUI status;
|
||||
readonly TargetString statusstr = new TargetString();
|
||||
readonly StringBuffer statusbuf = new StringBuffer();
|
||||
|
||||
static Vector2 screenSize;
|
||||
public static Rect hitRect;
|
||||
@@ -71,15 +70,15 @@ namespace Cryville.Crtr {
|
||||
public static Dictionary<Identifier, MotionRegistry> motionRegistry = new Dictionary<Identifier, MotionRegistry>();
|
||||
|
||||
public static PdtEvaluator etor;
|
||||
|
||||
InputProxy inputProxy;
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour
|
||||
void Start() {
|
||||
d_addLogEntry = new Action<int, string, string>(AddLogEntry);
|
||||
|
||||
var logobj = GameObject.Find("Logs");
|
||||
if (logobj != null)
|
||||
logs = logobj.GetComponent<Text>();
|
||||
logs = logobj.GetComponent<TextMeshProUGUI>();
|
||||
if (!initialized) {
|
||||
Game.Init();
|
||||
GenericResources.LoadDefault();
|
||||
@@ -162,6 +161,8 @@ namespace Cryville.Crtr {
|
||||
tbus.ForwardStepByTime(renderDist, step);
|
||||
tbus.EndGraphicalUpdate();
|
||||
UnityEngine.Profiling.Profiler.EndSample();
|
||||
|
||||
effectManager.Tick(cbus.Time);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Game.LogException("Game", "An error occured while playing", ex);
|
||||
@@ -174,10 +175,21 @@ namespace Cryville.Crtr {
|
||||
string url = texLoader.url;
|
||||
string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1));
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
if (texHandler.isDone) {
|
||||
var tex = texHandler.texture;
|
||||
tex.wrapMode = TextureWrapMode.Clamp;
|
||||
texs.Add(name, tex);
|
||||
if (texLoader.isDone) {
|
||||
if (texHandler.isDone) {
|
||||
var tex = texHandler.texture;
|
||||
tex.wrapMode = TextureWrapMode.Clamp;
|
||||
if (frames.ContainsKey(name)) {
|
||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", name);
|
||||
}
|
||||
else {
|
||||
frames.Add(name, new SpriteFrame(tex));
|
||||
}
|
||||
texs.Add(name, tex);
|
||||
}
|
||||
else {
|
||||
Logger.Log("main", 4, "Load/Prehandle", "Unable to load texture: {0}", name);
|
||||
}
|
||||
texLoader.Dispose();
|
||||
texHandler.Dispose();
|
||||
texLoader = null;
|
||||
@@ -192,14 +204,14 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (texLoader == null)
|
||||
if (texLoader == null) {
|
||||
if (texLoadQueue.Count > 0) {
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
texHandler = new DownloadHandlerTexture();
|
||||
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + texLoadQueue.Dequeue(), "GET", texHandler, null);
|
||||
texLoader.SendWebRequest();
|
||||
#else
|
||||
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
||||
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
||||
#endif
|
||||
}
|
||||
else if (!texloaddone) {
|
||||
@@ -207,6 +219,7 @@ namespace Cryville.Crtr {
|
||||
texloadtimer.Stop();
|
||||
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", texloadtimer.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
if (!loadThread.IsAlive) {
|
||||
if (threadException != null) {
|
||||
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
||||
@@ -222,25 +235,46 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
readonly TargetString statusstr = new TargetString();
|
||||
readonly StringBuffer statusbuf = new StringBuffer();
|
||||
readonly TargetString logsstr = new TargetString();
|
||||
readonly StringBuffer logsbuf = new StringBuffer();
|
||||
readonly List<string> logEntries = new List<string>();
|
||||
int logsLength = 0;
|
||||
Action<int, string, string> d_addLogEntry;
|
||||
void AddLogEntry(int level, string module, string msg) {
|
||||
string color;
|
||||
switch (level) {
|
||||
case 0: color = "#888888"; break;
|
||||
case 1: color = "#bbbbbb"; break;
|
||||
case 2: color = "#0088ff"; break;
|
||||
case 3: color = "#ffff00"; break;
|
||||
case 4: color = "#ff0000"; break;
|
||||
case 5: color = "#bb0000"; break;
|
||||
default: color = "#ff00ff"; break;
|
||||
}
|
||||
var l = string.Format(
|
||||
"\n<color={1}bb><{2}> {3}</color>",
|
||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||
);
|
||||
logEntries.Add(l);
|
||||
logsLength += l.Length;
|
||||
}
|
||||
void LogUpdate() {
|
||||
string _logs = logs.text;
|
||||
Game.MainLogger.Enumerate((level, module, msg) => {
|
||||
string color;
|
||||
switch (level) {
|
||||
case 0: color = "#888888"; break;
|
||||
case 1: color = "#bbbbbb"; break;
|
||||
case 2: color = "#0088ff"; break;
|
||||
case 3: color = "#ffff00"; break;
|
||||
case 4: color = "#ff0000"; break;
|
||||
case 5: color = "#bb0000"; break;
|
||||
default: color = "#ff00ff"; break;
|
||||
}
|
||||
_logs += string.Format(
|
||||
"\r\n<color={1}bb><{2}> {3}</color>",
|
||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||
);
|
||||
});
|
||||
logs.text = _logs.Substring(Mathf.Max(0, _logs.IndexOf('\n', Mathf.Max(0, _logs.Length - 4096))));
|
||||
logsbuf.Clear();
|
||||
Game.MainLogger.Enumerate(d_addLogEntry);
|
||||
while (logsLength >= 4096) {
|
||||
logsLength -= logEntries[0].Length;
|
||||
logEntries.RemoveAt(0);
|
||||
}
|
||||
foreach (var l in logEntries) {
|
||||
logsbuf.Append(l);
|
||||
}
|
||||
logsstr.Length = logsbuf.Count;
|
||||
var larr = logsstr.TrustedAsArray();
|
||||
logsbuf.CopyTo(0, larr, 0, logsbuf.Count);
|
||||
logs.SetText(larr, 0, logsbuf.Count);
|
||||
|
||||
statusbuf.Clear();
|
||||
statusbuf.AppendFormat(
|
||||
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
||||
@@ -281,9 +315,9 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
statusstr.Length = statusbuf.Count;
|
||||
var arr = statusstr.TrustedAsArray();
|
||||
statusbuf.CopyTo(0, arr, 0, statusbuf.Count);
|
||||
status.SetText(arr, 0, statusbuf.Count);
|
||||
var sarr = statusstr.TrustedAsArray();
|
||||
statusbuf.CopyTo(0, sarr, 0, statusbuf.Count);
|
||||
status.SetText(sarr, 0, statusbuf.Count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -313,6 +347,8 @@ namespace Cryville.Crtr {
|
||||
|
||||
bool logEnabled = true;
|
||||
public void ToggleLogs() {
|
||||
logEntries.Clear();
|
||||
logsLength = 0;
|
||||
logs.text = "";
|
||||
status.SetText("");
|
||||
logEnabled = !logEnabled;
|
||||
@@ -424,16 +460,6 @@ namespace Cryville.Crtr {
|
||||
try {
|
||||
diag::Stopwatch timer = new diag::Stopwatch();
|
||||
timer.Reset(); timer.Start();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Initializing textures");
|
||||
foreach (var t in texs) {
|
||||
if (frames.ContainsKey(t.Key)) {
|
||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
|
||||
continue;
|
||||
}
|
||||
var f = new SpriteFrame(t.Value);
|
||||
f.Init();
|
||||
frames.Add(t.Key, f);
|
||||
}
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)");
|
||||
cbus.BroadcastPreInit();
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
||||
@@ -447,15 +473,18 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up");
|
||||
GC.Collect();
|
||||
if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
|
||||
cbus.ForwardByTime(startOffset);
|
||||
bbus.ForwardByTime(startOffset);
|
||||
timer.Stop();
|
||||
Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds);
|
||||
if (Settings.Default.ClearLogOnPlay) {
|
||||
logs.text = "";
|
||||
logEntries.Clear();
|
||||
logsLength = 0;
|
||||
Game.MainLogger.Enumerate((level, module, msg) => { });
|
||||
logs.text = "";
|
||||
}
|
||||
Game.AudioSequencer.Playing = true;
|
||||
atime0 = Game.AudioClient.BufferPosition;
|
||||
Thread.Sleep((int)((atime0 - Game.AudioClient.Position) * 1000));
|
||||
inputProxy.SyncTime(cbus.Time);
|
||||
started = true;
|
||||
}
|
||||
@@ -476,6 +505,9 @@ namespace Cryville.Crtr {
|
||||
if (tbus != null) { tbus.Dispose(); tbus = null; }
|
||||
if (bbus != null) { bbus.Dispose(); bbus = null; }
|
||||
if (cbus != null) { cbus.Dispose(); cbus.DisposeAll(); cbus = null; }
|
||||
effectManager.Dispose();
|
||||
effectManager = null;
|
||||
etor = null;
|
||||
Logger.Log("main", 1, "Game", "Stopped");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -559,7 +591,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
inputProxy = new InputProxy(pruleset, judge);
|
||||
inputProxy.LoadFrom(_rscfg.inputs);
|
||||
if (!inputProxy.IsCompleted) {
|
||||
if (!inputProxy.IsCompleted()) {
|
||||
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
||||
}
|
||||
|
||||
@@ -617,6 +649,7 @@ namespace Cryville.Crtr {
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(etor);
|
||||
effectManager = new EffectManager(pskin);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
[DisallowMultipleComponent]
|
||||
public abstract class MeshBase : SkinComponent {
|
||||
public MeshBase() {
|
||||
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => {
|
||||
var c = Color;
|
||||
c.a *= v;
|
||||
Color = c;
|
||||
}));
|
||||
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
|
||||
}
|
||||
|
||||
protected MeshWrapper mesh = new MeshWrapper();
|
||||
protected Material[] materials;
|
||||
|
||||
short _zindex;
|
||||
public short ZIndex {
|
||||
@@ -22,9 +31,36 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
protected void UpdateZIndex() {
|
||||
if (!mesh.Initialized) return;
|
||||
foreach (var mat in mesh.Renderer.materials) {
|
||||
foreach (var mat in materials) {
|
||||
mat.renderQueue = _zindex;
|
||||
}
|
||||
}
|
||||
|
||||
Color _color = Color.white;
|
||||
public Color Color {
|
||||
get { return _color; }
|
||||
set {
|
||||
_color = value;
|
||||
UpdateColor();
|
||||
}
|
||||
}
|
||||
protected void UpdateColor() {
|
||||
if (!mesh.Initialized) return;
|
||||
foreach (var mat in materials) {
|
||||
mat.color = _color;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDestroy() {
|
||||
DestroyMaterials();
|
||||
mesh.Destroy();
|
||||
}
|
||||
|
||||
protected void DestroyMaterials() {
|
||||
if (materials == null) return;
|
||||
foreach (var mat in materials) {
|
||||
Material.Destroy(mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,7 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
public SectionalGameObject() {
|
||||
SubmitProperty("partial", new PropOp.Boolean(v => part = Part.idle));
|
||||
SubmitProperty("part", new PropOp.Enum<Part>(v => part = v, v => (Part)v), 2);
|
||||
}
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
SubmitProperty("part", new PropOp.Enum<Part>(v => part = v, v => (Part)v), 1);
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
@@ -67,7 +63,7 @@ namespace Cryville.Crtr.Components {
|
||||
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
||||
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
||||
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
||||
SubmitProperty("shape", new op_set_shape(this), 2);
|
||||
SubmitProperty("shape", new op_set_shape(this), 1);
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
@@ -76,7 +72,7 @@ namespace Cryville.Crtr.Components {
|
||||
public op_set_shape(PolygonSGO self) : base(1) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
protected override unsafe void Execute() {
|
||||
var o = GetOperand(0);
|
||||
if (o.Type != PdtInternalType.Vector) throw new ArgumentException("Not a vector");
|
||||
_self._shapeLength = (o.Length - sizeof(int)) / sizeof(Vector2);
|
||||
@@ -103,7 +99,6 @@ namespace Cryville.Crtr.Components {
|
||||
public SpriteInfo body = new SpriteInfo();
|
||||
public SpriteInfo tail = new SpriteInfo();
|
||||
|
||||
Material[] mats;
|
||||
List<Vector3> vertices;
|
||||
List<float> lengths;
|
||||
float sumLength = 0;
|
||||
@@ -112,23 +107,25 @@ namespace Cryville.Crtr.Components {
|
||||
base.Init();
|
||||
mesh.Init(transform);
|
||||
|
||||
mats = mesh.Renderer.materials = new Material[] { mesh.NewMaterial, mesh.NewMaterial, mesh.NewMaterial };
|
||||
head.Bind(mats[0]);
|
||||
body.Bind(mats[1]);
|
||||
tail.Bind(mats[2]);
|
||||
mesh.Renderer.sharedMaterials = materials = new Material[] {
|
||||
MeshWrapper.NewMaterial(),
|
||||
MeshWrapper.NewMaterial(),
|
||||
MeshWrapper.NewMaterial(),
|
||||
};
|
||||
head.Bind(materials[0]);
|
||||
body.Bind(materials[1]);
|
||||
tail.Bind(materials[2]);
|
||||
|
||||
UpdateZIndex();
|
||||
}
|
||||
|
||||
protected override void OnDestroy() {
|
||||
base.OnDestroy();
|
||||
Reset();
|
||||
foreach (var m in mats) Material.Destroy(m);
|
||||
if (_shape != null) _shapePool.Return(_shape);
|
||||
if (vertices != null) {
|
||||
_ptPool.Return(vertices);
|
||||
_lPool.Return(lengths);
|
||||
}
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
protected override void AppendPointInternal(Vector3 p, Quaternion r) {
|
||||
|
||||
89
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
89
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Cryville.Common;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
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() { }
|
||||
}
|
||||
[Flags]
|
||||
public enum AnimationDirection {
|
||||
normal = 0,
|
||||
reverse = 1,
|
||||
alternate = 2,
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80318e36af5412345871bdbf80d49ef2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,8 +14,8 @@ namespace Cryville.Crtr.Components {
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
/// <param name="property">The property.</param>
|
||||
protected void SubmitProperty(string name, PdtOperator property, int uct = 1) {
|
||||
Properties.Add(IdentifierManager.SharedInstance.Request(name), new SkinProperty(property, uct));
|
||||
protected void SubmitProperty(string name, PdtOperator property, int udl = 0) {
|
||||
Properties.Add(IdentifierManager.SharedInstance.Request(name), new SkinProperty(property, udl));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -26,14 +26,16 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
|
||||
public virtual void Init() { }
|
||||
public virtual void Rewind(double time, Transform target) { }
|
||||
public virtual void Tick(SkinContainer c, double time) { }
|
||||
protected abstract void OnDestroy();
|
||||
}
|
||||
public struct SkinProperty {
|
||||
public PdtOperator Operator { get; set; }
|
||||
public int UpdateCloneType { get; set; }
|
||||
public SkinProperty(PdtOperator op, int uct = 1) {
|
||||
public int UpdateDynamicLevel { get; set; }
|
||||
public SkinProperty(PdtOperator op, int udl = 0) {
|
||||
Operator = op;
|
||||
UpdateCloneType = uct;
|
||||
UpdateDynamicLevel = udl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,6 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
protected override void OnDestroy() {
|
||||
mesh.Destroy();
|
||||
}
|
||||
|
||||
Vector2 _scale = Vector2.one;
|
||||
public Vector2 Scale {
|
||||
get { return _scale; }
|
||||
@@ -92,7 +88,9 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
protected void InternalInit(string meshName = "quad") {
|
||||
mesh.Init(transform);
|
||||
mesh.Renderer.sharedMaterials = materials = new Material[] { MeshWrapper.NewMaterial() };
|
||||
mesh.Mesh = GenericResources.Meshes[meshName];
|
||||
UpdateColor();
|
||||
UpdateScale();
|
||||
UpdateZIndex();
|
||||
}
|
||||
|
||||
@@ -29,19 +29,12 @@ namespace Cryville.Crtr.Components {
|
||||
return Rect.width / Rect.height;
|
||||
}
|
||||
}
|
||||
bool _loaded;
|
||||
Material _mat;
|
||||
public void Bind(Material mat) {
|
||||
_loaded = true;
|
||||
_mat = mat;
|
||||
Reload();
|
||||
}
|
||||
public void Load() {
|
||||
_loaded = true;
|
||||
Reload();
|
||||
}
|
||||
public void Reload() {
|
||||
if (!_loaded) return;
|
||||
if (!string.IsNullOrEmpty(FrameName)) {
|
||||
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
||||
Frame = ChartPlayer.frames[FrameName];
|
||||
@@ -56,13 +49,18 @@ namespace Cryville.Crtr.Components {
|
||||
_mat.mainTexture = Frame == null ? null : Frame.Texture;
|
||||
}
|
||||
}
|
||||
public static bool IsNullOrEmpty(SpriteInfo sprite) {
|
||||
return sprite == null || sprite.Frame == null;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpritePlane : SpriteBase {
|
||||
public SpritePlane() {
|
||||
SubmitProperty("frame", new PropOp.String(v => Frame = v));
|
||||
SubmitProperty("frames", new PropOp.StringArray(v => Frames = v));
|
||||
SubmitProperty("index", new PropOp.Integer(v => Index = v));
|
||||
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v, v => (FitMode)v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||
SubmitProperty("shader", new PropOp.String(v => Shader = v));
|
||||
}
|
||||
|
||||
static Vector2[] _origuv;
|
||||
@@ -83,52 +81,73 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
}
|
||||
|
||||
protected SpriteInfo frameInfo = new SpriteInfo();
|
||||
|
||||
public string Frame {
|
||||
get { return frameInfo.FrameName; }
|
||||
int m_index;
|
||||
public int Index {
|
||||
get { return m_index; }
|
||||
set {
|
||||
frameInfo.FrameName = value;
|
||||
m_index = value;
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
SpriteInfo[] m_frames = new SpriteInfo[] { new SpriteInfo() };
|
||||
public string[] Frames {
|
||||
set {
|
||||
m_frames = new SpriteInfo[value.Length];
|
||||
for (int i = 0; i < value.Length; i++) {
|
||||
m_frames[i] = new SpriteInfo() { FrameName = value[i] };
|
||||
}
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
public string Frame {
|
||||
set {
|
||||
if (value == CurrentFrame.FrameName) return;
|
||||
CurrentFrame.FrameName = value;
|
||||
OnFrameUpdate();
|
||||
}
|
||||
}
|
||||
protected SpriteInfo CurrentFrame {
|
||||
get {
|
||||
if (m_frames.Length == 0) return null;
|
||||
if (m_index < 0) m_index = 0;
|
||||
else if (m_index >= m_frames.Length) m_index = m_frames.Length - 1;
|
||||
return m_frames[m_index];
|
||||
}
|
||||
}
|
||||
protected void OnFrameUpdate() {
|
||||
if (!mesh.Initialized) return;
|
||||
if (frameInfo.Frame == null) {
|
||||
var frame = CurrentFrame;
|
||||
if (SpriteInfo.IsNullOrEmpty(frame)) {
|
||||
mesh.Renderer.enabled = false;
|
||||
return;
|
||||
}
|
||||
mesh.Renderer.enabled = true;
|
||||
mesh.Renderer.sharedMaterial.mainTexture = frame.Frame.Texture;
|
||||
UpdateUV();
|
||||
UpdateScale();
|
||||
}
|
||||
Shader m_shader;
|
||||
public string Shader {
|
||||
set {
|
||||
m_shader = GenericResources.Shaders[value];
|
||||
UpdateShader();
|
||||
}
|
||||
}
|
||||
void UpdateShader() {
|
||||
if (!mesh.Initialized) return;
|
||||
if (m_shader == null) m_shader = GenericResources.Shaders["default"];
|
||||
mesh.Renderer.sharedMaterial.shader = m_shader;
|
||||
UpdateZIndex();
|
||||
}
|
||||
readonly Vector2[] _uvs = new Vector2[4];
|
||||
protected virtual void UpdateUV() {
|
||||
if (frameInfo.Frame == null) {
|
||||
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frameInfo.FrameName);
|
||||
return;
|
||||
}
|
||||
var frame = CurrentFrame;
|
||||
if (SpriteInfo.IsNullOrEmpty(frame)) return;
|
||||
Vector2[] muv = OriginalUV;
|
||||
Vector2[] uv = new Vector2[muv.Length];
|
||||
for (int i = 0; i < uv.Length; i++) {
|
||||
uv[i] = frameInfo.Frame.GetUV(muv[i]);
|
||||
for (int i = 0; i < _uvs.Length; i++) {
|
||||
_uvs[i] = frame.Frame.GetUV(muv[i]);
|
||||
}
|
||||
mesh.Mesh.uv = uv;
|
||||
}
|
||||
|
||||
float _opacity = 1;
|
||||
public float Opacity {
|
||||
get { return _opacity; }
|
||||
set {
|
||||
_opacity = value;
|
||||
UpdateOpacity();
|
||||
}
|
||||
}
|
||||
void UpdateOpacity() {
|
||||
if (!mesh.Initialized) return;
|
||||
var c = mesh.Renderer.material.color;
|
||||
c.a = _opacity;
|
||||
mesh.Renderer.material.color = c;
|
||||
mesh.Mesh.uv = _uvs;
|
||||
}
|
||||
|
||||
private FitMode m_fit = FitMode.height;
|
||||
@@ -144,7 +163,7 @@ namespace Cryville.Crtr.Components {
|
||||
}
|
||||
|
||||
protected override void UpdateScale() {
|
||||
if (frameInfo.Frame == null) return;
|
||||
if (SpriteInfo.IsNullOrEmpty(CurrentFrame)) return;
|
||||
base.UpdateScale();
|
||||
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
||||
}
|
||||
@@ -153,8 +172,8 @@ namespace Cryville.Crtr.Components {
|
||||
get {
|
||||
switch (m_fit) {
|
||||
case FitMode.none: return Vector3.one;
|
||||
case FitMode.width: return new Vector3(1, 1, 1 / frameInfo.Ratio);
|
||||
case FitMode.height: return new Vector3(frameInfo.Ratio, 1, 1);
|
||||
case FitMode.width: return new Vector3(1, 1, 1 / CurrentFrame.Ratio);
|
||||
case FitMode.height: return new Vector3(CurrentFrame.Ratio, 1, 1);
|
||||
default: throw new NotSupportedException("Unsupported fit mode");
|
||||
}
|
||||
}
|
||||
@@ -162,9 +181,8 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
frameInfo.Bind(mesh.Renderer.material);
|
||||
OnFrameUpdate();
|
||||
UpdateOpacity();
|
||||
UpdateShader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,7 @@
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteRect : SpriteBase {
|
||||
public SpriteRect() {
|
||||
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
||||
}
|
||||
|
||||
Color _color;
|
||||
public Color Color {
|
||||
get { return _color; }
|
||||
set {
|
||||
_color = value;
|
||||
OnColorUpdate();
|
||||
}
|
||||
}
|
||||
void OnColorUpdate() {
|
||||
if (!mesh.Initialized) return;
|
||||
mesh.Renderer.material.SetColor("_Color", _color);
|
||||
}
|
||||
public SpriteRect() { }
|
||||
|
||||
protected override Vector3 BaseScale {
|
||||
get { return Vector3.one; }
|
||||
@@ -25,7 +10,6 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
OnColorUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ namespace Cryville.Crtr.Components {
|
||||
SubmitProperty("border", new PropOp.Vector2(v => Border = v));
|
||||
}
|
||||
|
||||
readonly static Dictionary<float, int> uvrefl
|
||||
static readonly Dictionary<float, int> uvrefl
|
||||
= new Dictionary<float, int>() {
|
||||
{-0.5f, 0}, {-0.4f, 1}, {0.4f, 2}, {0.5f, 3},
|
||||
};
|
||||
static Vector2[] _origuv;
|
||||
protected new static Vector2[] OriginalUV {
|
||||
protected static new Vector2[] OriginalUV {
|
||||
get {
|
||||
if (_origuv == null) {
|
||||
var m = GenericResources.Meshes["quad_scale3h"];
|
||||
@@ -44,24 +44,26 @@ namespace Cryville.Crtr.Components {
|
||||
UpdateUV();
|
||||
}
|
||||
|
||||
readonly Vector2[] _uvs = new Vector2[8];
|
||||
readonly Vector3[] _verts = new Vector3[8];
|
||||
protected override void UpdateUV() {
|
||||
Vector2[] muv = OriginalUV;
|
||||
Vector2[] uv = new Vector2[muv.Length];
|
||||
var frame = CurrentFrame;
|
||||
if (SpriteInfo.IsNullOrEmpty(frame)) return;
|
||||
|
||||
var or = frameInfo.Ratio;
|
||||
Vector2[] muv = OriginalUV;
|
||||
|
||||
var or = frame.Ratio;
|
||||
var sr = Scale.x / Scale.y;
|
||||
var b = new Vector2(
|
||||
(or / sr) * _border.x,
|
||||
1 - (or / sr) * (1 - _border.y)
|
||||
);
|
||||
Vector3[] vert = mesh.Mesh.vertices;
|
||||
var rr = or / sr;
|
||||
var b1 = rr * _border.x;
|
||||
var b2 = 1 - rr * (1 - _border.y);
|
||||
|
||||
for (int i = 0; i < muv.Length; i++) {
|
||||
float x; float bx;
|
||||
switch ((int)muv[i].x) {
|
||||
case 0: x = 0; bx = 0; break;
|
||||
case 1: x = _border.x; bx = b.x; break;
|
||||
case 2: x = _border.y; bx = b.y; break;
|
||||
case 1: x = _border.x; bx = b1; break;
|
||||
case 2: x = _border.y; bx = b2; break;
|
||||
case 3: x = 1; bx = 1; break;
|
||||
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||
}
|
||||
@@ -71,16 +73,15 @@ namespace Cryville.Crtr.Components {
|
||||
case 3: y = 1; break;
|
||||
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||
}
|
||||
uv[i] = frameInfo.Frame.GetUV(x, y);
|
||||
_uvs[i] = frame.Frame.GetUV(x, y);
|
||||
bx -= 0.5f; y -= 0.5f;
|
||||
vert[i] = new Vector3(bx, 0, y);
|
||||
_verts[i] = new Vector3(bx, 0, y);
|
||||
}
|
||||
mesh.Mesh.uv = uv;
|
||||
mesh.Mesh.vertices = vert;
|
||||
mesh.Mesh.uv = _uvs;
|
||||
mesh.Mesh.vertices = _verts;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
frameInfo.Load();
|
||||
InternalInit("quad_scale3h");
|
||||
OnFrameUpdate();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace Cryville.Crtr.Components {
|
||||
SubmitProperty("value", new PropOp.TargetString(() => Value));
|
||||
SubmitProperty("size", new PropOp.Float(v => Size = v));
|
||||
SubmitProperty("spacing", new PropOp.Float(v => Spacing = v));
|
||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
@@ -20,11 +19,13 @@ namespace Cryville.Crtr.Components {
|
||||
public op_set_frames(SpriteText self) : base(2) {
|
||||
_self = self;
|
||||
}
|
||||
protected unsafe override void Execute() {
|
||||
protected override unsafe void Execute() {
|
||||
var keys = GetOperand(0).AsString();
|
||||
var values = GetOperand(1);
|
||||
int arrtype; int len;
|
||||
values.GetArraySuffix(out arrtype, out len);
|
||||
if (arrtype != PdtInternalType.String) throw new InvalidCastException("Not an array of strings");
|
||||
if (len != keys.Length) throw new ArgumentException("Length of key not equal to frame count");
|
||||
var result = new Dictionary<char, SpriteInfo>(len);
|
||||
int o = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -45,7 +46,7 @@ namespace Cryville.Crtr.Components {
|
||||
Dictionary<char, SpriteInfo> m_frames;
|
||||
public Dictionary<char, SpriteInfo> Frames {
|
||||
get { return m_frames; }
|
||||
set { m_frames = value; UpdateFrames(); UpdateScale(); }
|
||||
set { m_frames = value; UpdateFrames(); }
|
||||
}
|
||||
|
||||
readonly TargetString m_value = new TargetString();
|
||||
@@ -76,8 +77,11 @@ namespace Cryville.Crtr.Components {
|
||||
meshes.Clear();
|
||||
verts.Clear();
|
||||
uvs.Clear();
|
||||
DestroyMaterials();
|
||||
materials = new Material[m_frames.Count];
|
||||
int i = 0;
|
||||
foreach (var f in m_frames) {
|
||||
f.Value.Load();
|
||||
if (SpriteInfo.IsNullOrEmpty(f.Value)) continue;
|
||||
if (frameHeight == 0) frameHeight = f.Value.Rect.height;
|
||||
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height for text component");
|
||||
var tex = f.Value.Frame.Texture;
|
||||
@@ -85,13 +89,17 @@ namespace Cryville.Crtr.Components {
|
||||
var m = new MeshWrapper();
|
||||
m.Init(mesh.MeshTransform);
|
||||
m.Mesh = new Mesh();
|
||||
m.Renderer.material.mainTexture = tex;
|
||||
var mat = MeshWrapper.NewMaterial();
|
||||
mat.mainTexture = tex;
|
||||
m.Renderer.sharedMaterial = materials[i++] = mat;
|
||||
meshes.Add(tex, m);
|
||||
verts.Add(tex, new List<Vector3>());
|
||||
uvs.Add(tex, new List<Vector2>());
|
||||
tris.Add(tex, new List<int>());
|
||||
}
|
||||
}
|
||||
UpdateColor();
|
||||
UpdateScale();
|
||||
}
|
||||
|
||||
float sum_x;
|
||||
@@ -102,10 +110,11 @@ namespace Cryville.Crtr.Components {
|
||||
void UpdateMeshes() {
|
||||
if (meshes.Count == 0) return;
|
||||
sum_x = 0;
|
||||
foreach (var t in meshes.Keys) {
|
||||
verts[t].Clear();
|
||||
uvs[t].Clear();
|
||||
tris[t].Clear();
|
||||
foreach (var t in meshes) {
|
||||
var key = t.Key;
|
||||
verts[key].Clear();
|
||||
uvs[key].Clear();
|
||||
tris[key].Clear();
|
||||
}
|
||||
foreach (var c in m_value) {
|
||||
var f = m_frames[c];
|
||||
@@ -121,11 +130,12 @@ namespace Cryville.Crtr.Components {
|
||||
uvs[t].Add(f.Frame.GetUV(new Vector2(0, 1)));
|
||||
sum_x += w + m_spacing;
|
||||
}
|
||||
foreach (var t in meshes.Keys) {
|
||||
var m = meshes[t].Mesh;
|
||||
foreach (var t in meshes) {
|
||||
var key = t.Key;
|
||||
var m = meshes[key].Mesh;
|
||||
m.Clear();
|
||||
int cc = verts[t].Count / 4;
|
||||
var _tris = tris[t];
|
||||
int cc = verts[key].Count / 4;
|
||||
var _tris = tris[key];
|
||||
for (int i = 0; i < cc; i++) {
|
||||
_tris.Add(i * 4);
|
||||
_tris.Add(i * 4 + 3);
|
||||
@@ -134,9 +144,9 @@ namespace Cryville.Crtr.Components {
|
||||
_tris.Add(i * 4 + 3);
|
||||
_tris.Add(i * 4 + 2);
|
||||
}
|
||||
m.SetVertices(verts[t]);
|
||||
m.SetUVs(0, uvs[t]);
|
||||
m.SetTriangles(tris[t], 0);
|
||||
m.SetVertices(verts[key]);
|
||||
m.SetUVs(0, uvs[key]);
|
||||
m.SetTriangles(tris[key], 0);
|
||||
m.RecalculateNormals();
|
||||
}
|
||||
sum_x -= m_spacing;
|
||||
@@ -154,23 +164,6 @@ namespace Cryville.Crtr.Components {
|
||||
get { return new Vector2(-0.5f, -0.5f); }
|
||||
}
|
||||
|
||||
float _opacity = 1;
|
||||
public float Opacity {
|
||||
get { return _opacity; }
|
||||
set {
|
||||
_opacity = value;
|
||||
UpdateOpacity();
|
||||
}
|
||||
}
|
||||
void UpdateOpacity() {
|
||||
if (!mesh.Initialized) return;
|
||||
foreach (var m in meshes.Values) {
|
||||
var c = m.Renderer.material.color;
|
||||
c.a = _opacity;
|
||||
m.Renderer.material.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
InternalInit();
|
||||
UpdateFrames();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common.Unity.Input;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -26,10 +27,10 @@ namespace Cryville.Crtr.Config {
|
||||
|
||||
SimpleInputConsumer _consumer;
|
||||
public InputProxy proxy;
|
||||
readonly Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
||||
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
|
||||
|
||||
string _sel;
|
||||
public void OpenDialog(string entry) {
|
||||
Identifier _sel;
|
||||
public void OpenDialog(Identifier entry) {
|
||||
_sel = entry;
|
||||
m_inputDialog.SetActive(true);
|
||||
CallHelper.Purge(m_deviceList);
|
||||
@@ -85,9 +86,21 @@ namespace Cryville.Crtr.Config {
|
||||
if (_recvsrcs.Contains(src)) return;
|
||||
_recvsrcs.Add(src);
|
||||
var obj = Instantiate(m_prefabListItem, m_deviceList);
|
||||
obj.transform.Find("Text").GetComponent<Text>().text = src == null ? "(None)" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||
var text = obj.transform.Find("Text").GetComponent<Text>();
|
||||
text.text = src == null ? "(None)" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||
var btn = obj.GetComponent<Button>();
|
||||
if (src != null) btn.interactable = !proxy.IsUsed(src.Value);
|
||||
if (src != null) {
|
||||
var tsrc = src.Value;
|
||||
bool flag = false;
|
||||
if (proxy.IsUsed(tsrc)) {
|
||||
text.text += " <size=9>(Used)</size>";
|
||||
}
|
||||
else if (tsrc.Handler.GetDimension(src.Value.Type) < m_configScene.ruleset.Root.inputs[_sel].dim) {
|
||||
text.text += " <size=9>(Not Applicable)</size>";
|
||||
}
|
||||
else flag = true;
|
||||
btn.interactable = flag;
|
||||
}
|
||||
btn.onClick.AddListener(() => {
|
||||
CloseDialog(src);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using Cryville.Common;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -13,8 +14,8 @@ namespace Cryville.Crtr.Config {
|
||||
[SerializeField]
|
||||
Button m_button;
|
||||
|
||||
public void SetKey(InputConfigPanel master, string name) {
|
||||
m_key.text = name;
|
||||
public void SetKey(InputConfigPanel master, Identifier name) {
|
||||
m_key.text = (string)name.Name;
|
||||
m_value.text = "None";
|
||||
m_button.onClick.AddListener(() => {
|
||||
master.OpenDialog(name);
|
||||
@@ -26,27 +27,18 @@ namespace Cryville.Crtr.Config {
|
||||
if (e.Used) {
|
||||
m_button.interactable = false;
|
||||
m_value.text = "(Not Required)";
|
||||
m_value.color = Color.black;
|
||||
}
|
||||
else {
|
||||
m_button.interactable = true;
|
||||
if (e.Proxy == null) {
|
||||
m_value.text = "(Unassigned)";
|
||||
m_value.color = Color.yellow;
|
||||
if (e.Required) m_value.text += " (Required)";
|
||||
}
|
||||
else {
|
||||
m_value.text = e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type);
|
||||
m_value.color = Color.black;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue(string name) {
|
||||
m_value.text = name;
|
||||
}
|
||||
|
||||
public void SetEnabled(bool flag) {
|
||||
m_button.interactable = flag;
|
||||
m_value.color = e.Required ? Color.yellow : Color.black;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
75
Assets/Cryville/Crtr/EffectGroup.cs
Normal file
75
Assets/Cryville/Crtr/EffectGroup.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Cryville.Common.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class EffectGroup {
|
||||
public EffectDefinition Definition { get; private set; }
|
||||
readonly EffectPool _pool;
|
||||
class EffectPool : ObjectPool<EffectInstance> {
|
||||
readonly List<EffectInstance> _instances
|
||||
= new List<EffectInstance>();
|
||||
readonly EffectGroup _group;
|
||||
public EffectPool(EffectGroup group) : base(256) {
|
||||
_group = group;
|
||||
}
|
||||
protected override EffectInstance Construct() {
|
||||
var result = new EffectInstance(_group.Definition);
|
||||
_instances.Add(result);
|
||||
return result;
|
||||
}
|
||||
public void DisposeAll() {
|
||||
foreach (var i in _instances) i.Dispose();
|
||||
}
|
||||
}
|
||||
readonly Dictionary<float, EffectInstance> _instances
|
||||
= new Dictionary<float, EffectInstance>();
|
||||
readonly List<EffectInstance> _endQueue
|
||||
= new List<EffectInstance>();
|
||||
public EffectGroup(EffectDefinition def) {
|
||||
Definition = def;
|
||||
_pool = new EffectPool(this);
|
||||
}
|
||||
double _time;
|
||||
public void Tick(double time) {
|
||||
_time = time;
|
||||
while (_endQueue.Count > 0) {
|
||||
var item = _endQueue[0];
|
||||
if (item.EndTime > _time) break;
|
||||
_endQueue.RemoveAt(0);
|
||||
if (item.OnStateDone()) {
|
||||
QueueInstance(item);
|
||||
}
|
||||
else {
|
||||
item.Tick(time);
|
||||
_instances.Remove(item.Index);
|
||||
_pool.Return(item);
|
||||
}
|
||||
}
|
||||
foreach (var instance in _instances) {
|
||||
instance.Value.Tick(time);
|
||||
}
|
||||
}
|
||||
public void Emit(float index, Transform target = null) {
|
||||
EffectInstance 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);
|
||||
_endQueue.RemoveAt(i);
|
||||
}
|
||||
instance.OnEmit(_time, target);
|
||||
QueueInstance(instance);
|
||||
}
|
||||
}
|
||||
void QueueInstance(EffectInstance i) {
|
||||
var index = ~_endQueue.BinarySearch(i);
|
||||
_endQueue.Insert(index, i);
|
||||
}
|
||||
public void Dispose() {
|
||||
_pool.DisposeAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Crtr/EffectGroup.cs.meta
Normal file
11
Assets/Cryville/Crtr/EffectGroup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0d27f9b4383b3445a2a27bfe94173a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
121
Assets/Cryville/Crtr/EffectInstance.cs
Normal file
121
Assets/Cryville/Crtr/EffectInstance.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Crtr.Components;
|
||||
using Cryville.Crtr.Event;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class EffectInstance : ISkinnableGroup, IComparable<EffectInstance> {
|
||||
readonly EffectDefinition _def;
|
||||
readonly SkinContainer _skinContainer;
|
||||
public Transform RootTransform { get; private set; }
|
||||
readonly SkinComponent[] _comps;
|
||||
public EffectInstance(EffectDefinition def) {
|
||||
_def = def;
|
||||
_skinContainer = new SkinContainer(this, _def.elements);
|
||||
RootTransform = new GameObject("effect:" + GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
|
||||
SkinContext = new SkinContext(RootTransform);
|
||||
ChartPlayer.etor.ContextCascadeInsertBlock();
|
||||
_skinContainer.MatchStatic();
|
||||
ChartPlayer.etor.ContextCascadeDiscardBlock();
|
||||
_comps = RootTransform.GetComponentsInChildren<SkinComponent>();
|
||||
foreach (var i in _comps) i.Init();
|
||||
_indexSrc = new PropSrc.Float(() => Index);
|
||||
_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;
|
||||
public float Index {
|
||||
get { return m_index; }
|
||||
set {
|
||||
if (m_index == value) return;
|
||||
m_index = value;
|
||||
_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");
|
||||
readonly PropSrc _indexSrc;
|
||||
double _startTime;
|
||||
float _duration;
|
||||
readonly PropOp _durationOp;
|
||||
public double EndTime { get { return _startTime + _duration; } }
|
||||
public void Tick(double time) {
|
||||
foreach (var i in _comps) i.Tick(_skinContainer, time);
|
||||
}
|
||||
public bool CanEmit() {
|
||||
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);
|
||||
ChartPlayer.etor.ContextCascadeInsert();
|
||||
ChartPlayer.etor.ContextCascadeUpdate(_VAR_EFFECT_INDEX, _indexSrc);
|
||||
ChartPlayer.etor.Evaluate(_durationOp, _currentState.duration);
|
||||
if (emitting) _skinContainer.MatchDynamic(0, true);
|
||||
_skinContainer.MatchDynamic(1, emitting);
|
||||
ChartPlayer.etor.ContextCascadeDiscard();
|
||||
}
|
||||
public bool OnStateDone() {
|
||||
if (_currentState.next.Key == 0) {
|
||||
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() {
|
||||
GameObject.Destroy(RootTransform.gameObject);
|
||||
}
|
||||
|
||||
public string TypeName { get { throw new InvalidOperationException("Type name undefined"); } }
|
||||
public SkinContext SkinContext { get; private set; }
|
||||
public int OpenedAnchorName { get { return _currentStateName.Key; } }
|
||||
public void PushAnchorEvent(double time, int name) {
|
||||
throw new InvalidOperationException("Anchor not supported");
|
||||
}
|
||||
public void RegisterAnchor(int name) {
|
||||
throw new InvalidOperationException("Anchor not supported");
|
||||
}
|
||||
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
|
||||
throw new InvalidOperationException("Anchor not supported");
|
||||
}
|
||||
|
||||
public int CompareTo(EffectInstance other) {
|
||||
int r = EndTime.CompareTo(other.EndTime);
|
||||
if (r != 0) return r;
|
||||
return GetHashCode().CompareTo(other.GetHashCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Crtr/EffectInstance.cs.meta
Normal file
11
Assets/Cryville/Crtr/EffectInstance.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f442db34239c47046ba1b6fdae8e1216
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Cryville/Crtr/EffectManager.cs
Normal file
26
Assets/Cryville/Crtr/EffectManager.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class EffectManager {
|
||||
readonly Dictionary<int, EffectGroup> _groups
|
||||
= new Dictionary<int, EffectGroup>();
|
||||
public EffectManager(PdtSkin skin) {
|
||||
foreach (var e in skin.effects) {
|
||||
_groups.Add(e.Key.Key, new EffectGroup(e.Value));
|
||||
}
|
||||
}
|
||||
public void Tick(double time) {
|
||||
foreach (var g in _groups) g.Value.Tick(time);
|
||||
}
|
||||
public void Emit(int id, float index) {
|
||||
_groups[id].Emit(index);
|
||||
}
|
||||
public void EmitSelf(int id, float index, Transform target) {
|
||||
_groups[id].Emit(index, target);
|
||||
}
|
||||
public void Dispose() {
|
||||
foreach (var g in _groups) g.Value.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Cryville/Crtr/EffectManager.cs.meta
Normal file
11
Assets/Cryville/Crtr/EffectManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 980c0f18a6f491d44a866a85910cb458
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,10 +8,9 @@ using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Event {
|
||||
public abstract class ContainerHandler {
|
||||
public abstract class ContainerHandler : ISkinnableGroup {
|
||||
#region Struct
|
||||
public ContainerHandler() { }
|
||||
public abstract string TypeName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Prehandling <see cref="ContainerState"/>, prehandling the events.
|
||||
@@ -38,11 +37,9 @@ namespace Cryville.Crtr.Event {
|
||||
/// </summary>
|
||||
public ContainerState ts;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="GameObject"/> group, the <see cref="Transform"/> containing all the generated elements in the <see cref="ContainerHandler"/>.
|
||||
/// </summary>
|
||||
protected Transform gogroup;
|
||||
public SkinContext SkinContext;
|
||||
protected Transform RootTransform;
|
||||
|
||||
SkinComponent[] _comps;
|
||||
|
||||
public Vector3 Position { get; protected set; }
|
||||
public Quaternion Rotation { get; protected set; }
|
||||
@@ -72,32 +69,31 @@ namespace Cryville.Crtr.Event {
|
||||
SkinContainer skinContainer;
|
||||
protected Judge judge;
|
||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||
skinContainer = new SkinContainer(skin);
|
||||
skinContainer = new SkinContainer(this, skin.elements);
|
||||
this.judge = judge;
|
||||
}
|
||||
|
||||
public readonly Dictionary<int, List<Anchor>> Anchors = new Dictionary<int, List<Anchor>>();
|
||||
public readonly Dictionary<int, Anchor> DynamicAnchors = new Dictionary<int, Anchor>();
|
||||
public readonly Dictionary<int, bool> DynamicAnchorSet = new Dictionary<int, bool>();
|
||||
public Anchor OpenedAnchor;
|
||||
public readonly Dictionary<int, double> DynamicAnchorSetTime = new Dictionary<int, double>();
|
||||
Anchor a_cur;
|
||||
Anchor a_head;
|
||||
Anchor a_tail;
|
||||
readonly static int _a_cur = IdentifierManager.SharedInstance.Request("cur");
|
||||
readonly static int _a_head = IdentifierManager.SharedInstance.Request("head");
|
||||
readonly static int _a_tail = IdentifierManager.SharedInstance.Request("tail");
|
||||
static readonly int _a_cur = IdentifierManager.SharedInstance.Request("cur");
|
||||
static readonly int _a_head = IdentifierManager.SharedInstance.Request("head");
|
||||
static readonly int _a_tail = IdentifierManager.SharedInstance.Request("tail");
|
||||
double atime_head;
|
||||
double atime_tail;
|
||||
public Anchor RegisterAnchor(int name, bool dyn = false, int propSrcCount = 0) {
|
||||
var strname = IdentifierManager.SharedInstance.Retrieve(name);
|
||||
var go = new GameObject("." + strname).transform;
|
||||
go.SetParent(gogroup, false);
|
||||
go.SetParent(RootTransform, false);
|
||||
var result = new Anchor(name, go, propSrcCount);
|
||||
if (dyn) {
|
||||
if (DynamicAnchors.ContainsKey(name))
|
||||
throw new ArgumentException(string.Format("The anchor \"{0}\" already exists", strname));
|
||||
DynamicAnchors.Add(name, result);
|
||||
DynamicAnchorSet.Add(name, false);
|
||||
DynamicAnchorSetTime.Add(name, double.NaN);
|
||||
}
|
||||
List<Anchor> list;
|
||||
if (!Anchors.TryGetValue(name, out list))
|
||||
@@ -106,35 +102,39 @@ namespace Cryville.Crtr.Event {
|
||||
return result;
|
||||
}
|
||||
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);
|
||||
OpenedAnchor = anchor;
|
||||
_openedAnchor = anchor;
|
||||
}
|
||||
protected void CloseAnchor() {
|
||||
OpenedAnchor = null;
|
||||
_openedAnchor = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Logic
|
||||
#region Init methods: Called on prehandle
|
||||
public virtual void PreInit() {
|
||||
gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
|
||||
SkinContext = new SkinContext(gogroup);
|
||||
RootTransform = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
|
||||
SkinContext = new SkinContext(RootTransform);
|
||||
if (cs.Parent != null)
|
||||
gogroup.SetParent(cs.Parent.Handler.gogroup, false);
|
||||
RootTransform.SetParent(cs.Parent.Handler.RootTransform, false);
|
||||
a_cur = RegisterAnchor(_a_cur);
|
||||
a_head = RegisterAnchor(_a_head, true);
|
||||
a_tail = RegisterAnchor(_a_tail, true);
|
||||
}
|
||||
public virtual void Init() {
|
||||
skinContainer.MatchStatic(ps);
|
||||
foreach (var i in gogroup.GetComponentsInChildren<SkinComponent>())
|
||||
i.Init();
|
||||
ChartPlayer.etor.ContextState = ps;
|
||||
ChartPlayer.etor.ContextEvent = Container;
|
||||
skinContainer.MatchStatic();
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
_comps = RootTransform.GetComponentsInChildren<SkinComponent>();
|
||||
foreach (var i in _comps) i.Init();
|
||||
}
|
||||
public virtual void PostInit() {
|
||||
PropSrcs.Add(_var_current_time, new PropSrc.Float(() => (float)cs.rootPrototype.Time));
|
||||
PropSrcs.Add(_var_invisible_bounds, new PropSrc.Boolean(() => atime_head > atime_tail));
|
||||
gogroup.gameObject.SetActive(false);
|
||||
RootTransform.gameObject.SetActive(false);
|
||||
}
|
||||
#endregion
|
||||
#region Start methods
|
||||
@@ -143,16 +143,16 @@ namespace Cryville.Crtr.Event {
|
||||
else if (s.CloneType == 17) Init();
|
||||
}
|
||||
public virtual void StartLogicalUpdate(ContainerState s) { }
|
||||
public virtual void StartPreGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void StartGraphicalUpdate(ContainerState s) {
|
||||
if (gogroup) gogroup.gameObject.SetActive(true);
|
||||
protected virtual void StartPreGraphicalUpdate(ContainerState s) { }
|
||||
protected virtual void StartGraphicalUpdate(ContainerState s) {
|
||||
if (RootTransform) RootTransform.gameObject.SetActive(true);
|
||||
}
|
||||
#endregion
|
||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||
if (s.CloneType == 3) SetPreGraphicalActive(true, s);
|
||||
else if (ev is StampedEvent.Anchor) {
|
||||
var tev = (StampedEvent.Anchor)ev;
|
||||
if (gogroup) {
|
||||
if (RootTransform) {
|
||||
OpenAnchor(tev.Target);
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
tev.Target.Transform.SetPositionAndRotation(Position, Rotation);
|
||||
@@ -160,7 +160,7 @@ namespace Cryville.Crtr.Event {
|
||||
tev.Target.Transform.position = Position;
|
||||
tev.Target.Transform.rotation = Rotation;
|
||||
#endif
|
||||
skinContainer.MatchDynamic(s);
|
||||
MatchDynamic(s, 1);
|
||||
CloseAnchor();
|
||||
}
|
||||
if (tev.Target == a_head) {
|
||||
@@ -171,52 +171,56 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
anchorEvPool.Return(tev);
|
||||
}
|
||||
else if (gogroup && s.CloneType == 2) skinContainer.MatchDynamic(s);
|
||||
else if (RootTransform && s.CloneType == 2) MatchDynamic(s, 1);
|
||||
}
|
||||
#region End methods
|
||||
public virtual void EndGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void EndPreGraphicalUpdate(ContainerState s) { }
|
||||
protected virtual void EndGraphicalUpdate(ContainerState s) { }
|
||||
protected virtual void EndPreGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void EndLogicalUpdate(ContainerState s) { }
|
||||
public virtual void EndPhysicalUpdate(ContainerState s) { }
|
||||
public virtual void Dispose() {
|
||||
if (gogroup)
|
||||
GameObject.Destroy(gogroup.gameObject);
|
||||
if (RootTransform)
|
||||
GameObject.Destroy(RootTransform.gameObject);
|
||||
Alive = false;
|
||||
}
|
||||
public virtual void DisposeAll() { }
|
||||
#endregion
|
||||
#region Utils
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected static bool CanDoGraphicalUpdate(ContainerState s) { return s.CloneType >= 2 && s.CloneType < 16; }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void MatchDynamic(ContainerState s, int dl) {
|
||||
ChartPlayer.etor.ContextState = s;
|
||||
ChartPlayer.etor.ContextEvent = Container;
|
||||
skinContainer.MatchDynamic(dl);
|
||||
ChartPlayer.etor.ContextEvent = null;
|
||||
ChartPlayer.etor.ContextState = null;
|
||||
}
|
||||
#endregion
|
||||
#region Anchor
|
||||
public virtual void Anchor() {
|
||||
foreach (var p in PropSrcs.Values) p.Invalidate();
|
||||
foreach (var a in DynamicAnchors.Keys) DynamicAnchorSet[a] = false;
|
||||
foreach (var p in PropSrcs) p.Value.Invalidate();
|
||||
foreach (var a in DynamicAnchors) DynamicAnchorSetTime[a.Key] = double.NaN;
|
||||
atime_head = cs.StampedContainer.Time;
|
||||
atime_tail = atime_head + cs.StampedContainer.Duration;
|
||||
skinContainer.MatchDynamic(cs);
|
||||
MatchDynamic(cs, 0);
|
||||
foreach (var i in _comps) i.Tick(skinContainer, cs.Time);
|
||||
if (cs.Active) PushAnchorEvent(cs.Time, a_cur);
|
||||
if (Alive) {
|
||||
if (!DynamicAnchorSet[_a_head]) PushAnchorEvent(atime_head, a_head, -1, true);
|
||||
if (!DynamicAnchorSet[_a_tail]) PushAnchorEvent(atime_tail, a_tail, 1, true);
|
||||
foreach (var anchors in Anchors.Values) foreach (var anchor in anchors) anchor.Transform.gameObject.SetActive(false);
|
||||
if (double.IsNaN(DynamicAnchorSetTime[_a_head])) DynamicAnchorSetTime[_a_head] = atime_head;
|
||||
if (double.IsNaN(DynamicAnchorSetTime[_a_tail])) DynamicAnchorSetTime[_a_tail] = atime_tail;
|
||||
foreach (var t in DynamicAnchorSetTime) {
|
||||
if (double.IsNaN(t.Value)) continue;
|
||||
int priority = 0;
|
||||
bool forced = true;
|
||||
if (t.Key == _a_head) { priority = -1; }
|
||||
else if (t.Key == _a_tail) { priority = 1; }
|
||||
else forced = false;
|
||||
PushAnchorEvent(t.Value, DynamicAnchors[t.Key], priority, forced);
|
||||
}
|
||||
foreach (var anchors in Anchors) foreach (var anchor in anchors.Value) anchor.Transform.gameObject.SetActive(false);
|
||||
}
|
||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||
public void PushAnchorEvent(double time, int name) {
|
||||
Anchor anchor;
|
||||
if (!DynamicAnchors.TryGetValue(name, out anchor))
|
||||
throw new ArgumentException(string.Format("Specified anchor \"{0}\" not found", IdentifierManager.SharedInstance.Retrieve(name)));
|
||||
if (DynamicAnchorSet[name])
|
||||
throw new InvalidOperationException(string.Format("Specified anchor \"{0}\" has been set", IdentifierManager.SharedInstance.Retrieve(name)));
|
||||
int priority = 0;
|
||||
bool forced = true;
|
||||
if (name == _a_head) { priority = -1; atime_head = time; }
|
||||
else if (name == _a_tail) { priority = 1; atime_tail = time; }
|
||||
else forced = false;
|
||||
PushAnchorEvent(time, anchor, priority, forced);
|
||||
DynamicAnchorSet[name] = true;
|
||||
}
|
||||
void PushAnchorEvent(double time, Anchor anchor, int priority = 0, bool forced = false) {
|
||||
var tev = anchorEvPool.Rent();
|
||||
tev.Time = time;
|
||||
@@ -233,5 +237,28 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region ISkinnableGroup
|
||||
public abstract string TypeName { get; }
|
||||
public SkinContext SkinContext { get; private set; }
|
||||
Anchor _openedAnchor;
|
||||
public int OpenedAnchorName { get { return _openedAnchor == null ? 0 : _openedAnchor.Name; } }
|
||||
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
|
||||
List<Anchor> anchors;
|
||||
var ret = Anchors.TryGetValue(name, out anchors);
|
||||
result = anchors;
|
||||
return ret;
|
||||
}
|
||||
void ISkinnableGroup.RegisterAnchor(int name) {
|
||||
RegisterAnchor(name, true);
|
||||
}
|
||||
public void PushAnchorEvent(double time, int name) {
|
||||
if (!DynamicAnchors.ContainsKey(name))
|
||||
throw new ArgumentException(string.Format("Specified anchor \"{0}\" not found", IdentifierManager.SharedInstance.Retrieve(name)));
|
||||
if (name == _a_head) atime_head = time;
|
||||
else if (name == _a_tail) atime_tail = time;
|
||||
DynamicAnchorSetTime[name] = time;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,14 +434,14 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
public void BroadcastPreInit() {
|
||||
Handler.PreInit();
|
||||
foreach (var c in Children.Values) {
|
||||
c.BroadcastPreInit();
|
||||
foreach (var c in Children) {
|
||||
c.Value.BroadcastPreInit();
|
||||
}
|
||||
}
|
||||
public void BroadcastPostInit() {
|
||||
Handler.PostInit();
|
||||
foreach (var c in Children.Values) {
|
||||
c.BroadcastPostInit();
|
||||
foreach (var c in Children) {
|
||||
c.Value.BroadcastPostInit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,8 +461,8 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
public void Anchor() {
|
||||
Handler.Anchor();
|
||||
foreach (var ls in Children.Values) {
|
||||
if (ls.Handler.Alive) ls.Anchor();
|
||||
foreach (var ls in Children) {
|
||||
if (ls.Value.Handler.Alive) ls.Value.Anchor();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -63,8 +63,8 @@ namespace Cryville.Crtr.Event {
|
||||
s = RootState;
|
||||
}
|
||||
AddState(s);
|
||||
foreach (var c in s.Children.Values)
|
||||
Expand(c);
|
||||
foreach (var c in s.Children)
|
||||
Expand(c.Value);
|
||||
}
|
||||
|
||||
public void AddState(ContainerState s) {
|
||||
@@ -73,13 +73,13 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
void AttachBus() {
|
||||
foreach (var s in states.Values)
|
||||
s.Bus = this;
|
||||
foreach (var s in states)
|
||||
s.Value.Bus = this;
|
||||
}
|
||||
|
||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||
foreach (var s in states.Values)
|
||||
s.AttachSystems(skin, judge);
|
||||
foreach (var s in states)
|
||||
s.Value.AttachSystems(skin, judge);
|
||||
}
|
||||
|
||||
List<StampedEvent.Temporary> tempEvents = new List<StampedEvent.Temporary>();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user