Compare commits
208 Commits
Author | SHA1 | Date | |
---|---|---|---|
2784544884 | |||
c39a02a1c2 | |||
4c397ab2f7 | |||
6b3a9c9f0a | |||
1c1560f17f | |||
0699bc5614 | |||
d86da00258 | |||
d1ad68debe | |||
b937285a74 | |||
69fe03475b | |||
e5956f2b34 | |||
fdb4ab55a3 | |||
e30df8bdbc | |||
251b7bc352 | |||
61b72107ae | |||
d6208f19fb | |||
93d9fdd4b8 | |||
8670482c04 | |||
d2b71e41c9 | |||
29a8ac2136 | |||
a9fc5130bb | |||
b51c7d2352 | |||
56fd0936bb | |||
2b3898655f | |||
1b30d3e62c | |||
bdbb1fcb07 | |||
659f2165ff | |||
a5439430fb | |||
0f683e403c | |||
cf6a7a795b | |||
f664708165 | |||
a7be55f2b0 | |||
398cec1fc5 | |||
a8b9ba0af4 | |||
f54564c567 | |||
a2c5850fcd | |||
f4411629e4 | |||
17d620ff0c | |||
5887b1267a | |||
400723d83b | |||
07babcb0ff | |||
f7bfe07660 | |||
3690adf5dd | |||
48349b598d | |||
d6e3d3ad00 | |||
c57c82bdd1 | |||
4bc921d47e | |||
8907dd19b0 | |||
2221658e7a | |||
916c55b4b2 | |||
3d8a4a64a9 | |||
6cb36a7064 | |||
1fc5ea8ac6 | |||
6fd8e44d10 | |||
ff19b45a9f | |||
f467832115 | |||
0a25b5260d | |||
c877437ab6 | |||
676d19f452 | |||
fd7c1e6635 | |||
c98536e8ab | |||
a013d59379 | |||
2e69035618 | |||
072703efe7 | |||
0c796c4d7a | |||
ee4b0c5483 | |||
ba7a458e7c | |||
06d9df304e | |||
578e10bbd7 | |||
c685e634d5 | |||
824f401b77 | |||
aafc326f95 | |||
88a6410439 | |||
d6e1b19d32 | |||
6fa459e5d3 | |||
bde6216295 | |||
e03dbef5ff | |||
e2c683567e | |||
89f391f040 | |||
92a3d5018f | |||
d510fec57b | |||
054b17811d | |||
94d5f7f82e | |||
0e4445e52b | |||
c5214dd477 | |||
ed2c216cf4 | |||
609645c108 | |||
d280d27a0a | |||
5b727065f3 | |||
7aa2577059 | |||
c1b7e9ab55 | |||
99384397ed | |||
a2391aeb22 | |||
2207c80951 | |||
bf578d7cb9 | |||
0bc57c368f | |||
b64f85aaa2 | |||
93fa2f2d7e | |||
d72216de8b | |||
df5133a91a | |||
88b959a118 | |||
310bf91fbd | |||
699f47f98d | |||
24e881b138 | |||
2eef1b5c4e | |||
c18ceb50d4 | |||
27ca1a7292 | |||
dc59176eac | |||
aec7470ff8 | |||
983cba6843 | |||
871782e73f | |||
9aaa96fe10 | |||
22190a29c1 | |||
613ca467d0 | |||
536a3066b2 | |||
43488cd002 | |||
a11ccbd39c | |||
76df4929a7 | |||
505b826627 | |||
26a8675922 | |||
b89e1f983e | |||
717e77b47e | |||
2f10c79dee | |||
55f7790f89 | |||
ae5f4a8c16 | |||
1851bd3c54 | |||
6d74685cb7 | |||
03fd7f6d01 | |||
28c878f3e5 | |||
7736eba14d | |||
2e54b38d2b | |||
da60dc0903 | |||
215f72b3b5 | |||
a93c081dd8 | |||
456782930a | |||
ba3cbbd64c | |||
dfc3e9ca06 | |||
f567a2b78e | |||
c7e7bd8a77 | |||
67720fd0e1 | |||
1a30149942 | |||
a755cc13bd | |||
9a51cf1b56 | |||
256c656e9c | |||
2ac7f05316 | |||
28d46dbabe | |||
18b3e0bc84 | |||
23f2e7c1f2 | |||
998713b41f | |||
3561354231 | |||
0cccb170c1 | |||
d2480b8a6f | |||
6837d3f7ee | |||
3ecf3b4bfc | |||
1da8647ff1 | |||
2f19e8daad | |||
07f62c7aeb | |||
39db8dfa45 | |||
f04cd370f1 | |||
5c4acd54ce | |||
82dbc5c479 | |||
1f1663d714 | |||
a3c5392caa | |||
6c983cc2cb | |||
3bf3fdac3d | |||
f2f3dba098 | |||
3728360dd2 | |||
887837bb3d | |||
99b4c2dfc1 | |||
e59769158a | |||
ba3238614b | |||
a115999aab | |||
393947db9f | |||
e9b2a7f894 | |||
9c73455761 | |||
59c2210359 | |||
4fab20953a | |||
ee7b0f5081 | |||
33ee7a9a87 | |||
900bd7b77a | |||
6bd32c9aef | |||
13893b2853 | |||
23789c15eb | |||
a1f7418d32 | |||
274a823d02 | |||
ba6239068a | |||
ff8c925f32 | |||
2a6a33e60c | |||
8910b1f4a0 | |||
36dddea4d9 | |||
6a648c2dcd | |||
2d4087dc89 | |||
f91aacd78e | |||
9c08cbf0d2 | |||
88d35e4eaf | |||
675ce68073 | |||
db0165d145 | |||
7015426300 | |||
0d4cc5e208 | |||
e7ce0985fb | |||
eb6dafbd60 | |||
b6e238780e | |||
c7ea6f1d4b | |||
4a5b2a6889 | |||
b84d645aee | |||
67b44db1ae | |||
ee4399109a | |||
87ef534f59 |
@@ -1,6 +1,9 @@
|
||||
# Remove the line below if you want to inherit .editorconfig settings from higher directories
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
|
||||
# C# files
|
||||
[*.cs]
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -68,3 +68,4 @@ crashlytics-build.properties
|
||||
/UserSettings
|
||||
/*.zip
|
||||
*.lnk
|
||||
/HybridCLRData
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common {
|
||||
/// <summary>
|
||||
|
@@ -13,7 +13,7 @@ namespace Cryville.Common {
|
||||
public static Binder CreateBinderOfType(Type type) {
|
||||
var l = type.GetCustomAttributes(typeof(BinderAttribute), true);
|
||||
if (l.Length > 0) {
|
||||
return (Binder)ReflectionHelper.InvokeEmptyConstructor(
|
||||
return (Binder)Activator.CreateInstance(
|
||||
((BinderAttribute)l[0]).BinderType
|
||||
);
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace Cryville.Common.Buffers {
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A resource pool that allows reusing instances of arrays of type <typeparamref name="T" />.
|
||||
/// </summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace Cryville.Common.Buffers {
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A resource pool that allows reusing instances of type <typeparamref name="T" />.
|
||||
/// </summary>
|
||||
@@ -28,7 +28,6 @@
|
||||
_objs[_index++] = null;
|
||||
}
|
||||
if (obj == null) obj = Construct();
|
||||
else Reset(obj);
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -36,7 +35,10 @@
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to return.</param>
|
||||
public void Return(T obj) {
|
||||
if (_index > 0) _objs[--_index] = obj;
|
||||
if (_index > 0) {
|
||||
Reset(obj);
|
||||
_objs[--_index] = obj;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a new instance of type <typeparamref name="T" />.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace Cryville.Common.Buffers {
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A resource pool that allows reusing instances of type <typeparamref name="T" />, which has a parameterless constructor.
|
||||
/// </summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5335612e48e4c3947808c99fb99411d5
|
||||
guid: c4ef48e4a4983de4e9c31483df2a918e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9bd9e24d7c553341a2a12391843542f
|
||||
guid: 9ec674235c0dd6744af2dab2b58dd53c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
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);
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ffe72fef6ebb9e4da3571b4117f0d6d
|
||||
guid: 73fb17b484b343242bcce27c15ed7d44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
50
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal file
50
Assets/Cryville/Common/Collections/Generic/PairCollection.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public static bool IsPairCollection(Type type) {
|
||||
return typeof(IPairList<TKey, TValue>).IsAssignableFrom(type) || typeof(IDictionary<TKey, TValue>).IsAssignableFrom(type);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3c5a8bf05d5e284ba498e91cb0dd35e
|
||||
guid: 2517e8f040bd36f46948e5fafaf5335c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5b3f3294f679f14f8ec1195b0def630
|
||||
guid: d9ed5ea8b7b1a934287e7ec5971166c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
106
Assets/Cryville/Common/Collections/HashHelpers.cs
Normal file
106
Assets/Cryville/Common/Collections/HashHelpers.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cryville.Common.Collections {
|
||||
internal static class HashHelpers {
|
||||
#if FEATURE_RANDOMIZED_STRING_HASHING
|
||||
public const int HashCollisionThreshold = 100;
|
||||
public static bool s_UseRandomizedStringHashing = String.UseRandomizedHashing();
|
||||
#endif
|
||||
|
||||
// Table of prime numbers to use as hash table sizes.
|
||||
// A typical resize algorithm would pick the smallest prime number in this array
|
||||
// that is larger than twice the previous capacity.
|
||||
// Suppose our Hashtable currently has capacity x and enough elements are added
|
||||
// such that a resize needs to occur. Resizing first computes 2x then finds the
|
||||
// first prime in the table greater than 2x, i.e. if primes are ordered
|
||||
// p_1, p_2, ..., p_i, ..., it finds p_n such that p_n-1 < 2x < p_n.
|
||||
// Doubling is important for preserving the asymptotic complexity of the
|
||||
// hashtable operations such as add. Having a prime guarantees that double
|
||||
// hashing does not lead to infinite loops. IE, your hash function will be
|
||||
// h1(key) + i*h2(key), 0 <= i < size. h2 and the size must be relatively prime.
|
||||
public static readonly int[] primes = {
|
||||
3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
|
||||
1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
|
||||
17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437,
|
||||
187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263,
|
||||
1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369};
|
||||
|
||||
// Used by Hashtable and Dictionary's SeralizationInfo .ctor's to store the SeralizationInfo
|
||||
// object until OnDeserialization is called.
|
||||
private static ConditionalWeakTable<object, SerializationInfo> s_SerializationInfoTable;
|
||||
|
||||
internal static ConditionalWeakTable<object, SerializationInfo> SerializationInfoTable {
|
||||
get {
|
||||
if (s_SerializationInfoTable == null) {
|
||||
ConditionalWeakTable<object, SerializationInfo> newTable = new ConditionalWeakTable<object, SerializationInfo>();
|
||||
Interlocked.CompareExchange(ref s_SerializationInfoTable, newTable, null);
|
||||
}
|
||||
|
||||
return s_SerializationInfoTable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
public static bool IsPrime(int candidate) {
|
||||
if ((candidate & 1) != 0) {
|
||||
int limit = (int)System.Math.Sqrt (candidate);
|
||||
for (int divisor = 3; divisor <= limit; divisor += 2) {
|
||||
if ((candidate % divisor) == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return (candidate == 2);
|
||||
}
|
||||
|
||||
internal const Int32 HashPrime = 101;
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
public static int GetPrime(int min) {
|
||||
if (min < 0)
|
||||
throw new ArgumentException("Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.");
|
||||
Contract.EndContractBlock();
|
||||
|
||||
for (int i = 0; i < primes.Length; i++) {
|
||||
int prime = primes[i];
|
||||
if (prime >= min) return prime;
|
||||
}
|
||||
|
||||
//outside of our predefined table.
|
||||
//compute the hard way.
|
||||
for (int i = (min | 1); i < Int32.MaxValue; i += 2) {
|
||||
if (IsPrime(i) && ((i - 1) % HashPrime != 0))
|
||||
return i;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
public static int GetMinPrime() {
|
||||
return primes[0];
|
||||
}
|
||||
|
||||
// Returns size of hashtable to grow to.
|
||||
public static int ExpandPrime(int oldSize) {
|
||||
int newSize = 2 * oldSize;
|
||||
|
||||
// Allow the hashtables to grow to maximum possible size (~2G elements) before encoutering capacity overflow.
|
||||
// Note that this check works even when _items.Length overflowed thanks to the (uint) cast
|
||||
if ((uint)newSize > MaxPrimeArrayLength && MaxPrimeArrayLength > oldSize) {
|
||||
Contract.Assert(MaxPrimeArrayLength == GetPrime(MaxPrimeArrayLength), "Invalid MaxPrimeArrayLength");
|
||||
return MaxPrimeArrayLength;
|
||||
}
|
||||
|
||||
return GetPrime(newSize);
|
||||
}
|
||||
|
||||
|
||||
// This is the maximum prime smaller than Array.MaxArrayLength
|
||||
public const int MaxPrimeArrayLength = 0x7FEFFFFD;
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23377bf2926d93a4b8e3f3ab6040c7f2
|
||||
guid: e7fe2c6f3299681448c1a546cce4dc65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
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:
|
51
Assets/Cryville/Common/Collections/PairCollection.cs
Normal file
51
Assets/Cryville/Common/Collections/PairCollection.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public static bool IsPairCollection(Type type) {
|
||||
return typeof(IPairList).IsAssignableFrom(type) || typeof(IDictionary).IsAssignableFrom(type);
|
||||
}
|
||||
}
|
||||
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:
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6823ead66b33bc048bbad48719feb25d
|
||||
guid: f68b44d5226a73441b94e7dd5873529f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
1037
Assets/Cryville/Common/Collections/Specialized/IntKeyedDictionary.cs
Normal file
1037
Assets/Cryville/Common/Collections/Specialized/IntKeyedDictionary.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 634536d804abc784394d4ac028a77879
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
|
26
Assets/Cryville/Common/Coroutine.cs
Normal file
26
Assets/Cryville/Common/Coroutine.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Cryville.Common {
|
||||
public class Coroutine {
|
||||
readonly IEnumerator<float> _enumerator;
|
||||
readonly Stopwatch _stopwatch = new Stopwatch();
|
||||
public float Progress { get; private set; }
|
||||
public Coroutine(IEnumerator<float> enumerator) {
|
||||
_enumerator = enumerator;
|
||||
}
|
||||
public bool TickOnce() {
|
||||
if (!_enumerator.MoveNext()) return false;
|
||||
Progress = _enumerator.Current;
|
||||
return true;
|
||||
}
|
||||
public bool Tick(double minTime) {
|
||||
_stopwatch.Restart();
|
||||
while (_stopwatch.Elapsed.TotalSeconds < minTime) {
|
||||
if (!_enumerator.MoveNext()) return false;
|
||||
Progress = _enumerator.Current;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Coroutine.cs.meta
Normal file
11
Assets/Cryville/Common/Coroutine.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 387adc7d494be0147b7cb930bc2e726b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common {
|
||||
public class FileStringAttribute : Attribute {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using Cryville.Common.IO;
|
||||
using Cryville.Common.IO;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using Cryville.Common.Culture;
|
||||
using Cryville.Common.Culture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Common.Font {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common {
|
||||
/// <summary>
|
||||
|
27
Assets/Cryville/Common/Math/CubicBezier.cs
Normal file
27
Assets/Cryville/Common/Math/CubicBezier.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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 = 0, t1 = 1, t2 = x;
|
||||
|
||||
if (t2 < t0) return Curve(t0, y1, y2);
|
||||
if (t2 > t1) return Curve(t1, y1, y2);
|
||||
|
||||
while (t0 < t1) {
|
||||
float tx = Curve(t2, x1, x2);
|
||||
if (SMath.Abs(tx - x) < epsilon) return Curve(t2, y1, y2);
|
||||
if (x > tx) t0 = t2;
|
||||
else t1 = t2;
|
||||
t2 = (t1 - t0) * .5f + t0;
|
||||
}
|
||||
|
||||
return Curve(t2, y1, y2);
|
||||
}
|
||||
static float Curve(float t, float p1, float p2) {
|
||||
float v = 1 - t;
|
||||
return 3 * v * v * t * p1 + 3 * v * t * t * p2 + t * t * t;
|
||||
}
|
||||
}
|
||||
}
|
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:
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.Math {
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnsafeIL;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace Cryville.Common.Math {
|
||||
/// <summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
@@ -130,4 +130,4 @@ namespace Cryville.Common.Network {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Indicates that the attributed member is an element list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
|
||||
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> or <see cref="Cryville.Common.Collections.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.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 { }
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
@@ -17,22 +17,23 @@ namespace Cryville.Common.Pdt {
|
||||
readonly StackFrame[] _stack = new StackFrame[256];
|
||||
readonly byte[] _mem = new byte[0x100000];
|
||||
bool _revokepttconst;
|
||||
LinkedListNode<PdtInstruction> _rip;
|
||||
LinkedListNode<PdtInstruction> _ip;
|
||||
/// <summary>
|
||||
/// Evaluates an expression and passes the result to a target operator.
|
||||
/// </summary>
|
||||
/// <param name="target">The target operator.</param>
|
||||
/// <param name="exp">The expression to evaluate.</param>
|
||||
public void Evaluate(PdtOperator target, PdtExpression exp) {
|
||||
/// <returns>Whether the evaluaton succeeded.</returns>
|
||||
public bool Evaluate(PdtOperator target, PdtExpression exp) {
|
||||
_framecount = 0;
|
||||
_goffset = 0;
|
||||
_revokepttconst = false;
|
||||
for (_rip = exp.Instructions.First; _rip != null; _rip = _rip.Next)
|
||||
_rip.Value.Execute(this);
|
||||
Operate(target, _framecount, true);
|
||||
for (_ip = exp.Instructions.First; _ip != null; _ip = _ip.Next)
|
||||
_ip.Value.Execute(this);
|
||||
if (exp.IsPotentialConstant) {
|
||||
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
|
||||
}
|
||||
return Operate(target, _framecount, true);
|
||||
}
|
||||
/// <summary>
|
||||
/// Patches an expression with a lefthand variable and a compound operator.
|
||||
@@ -54,8 +55,10 @@ namespace Cryville.Common.Pdt {
|
||||
List<PdtInstruction.Collapse> ct;
|
||||
var cols = new Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>>();
|
||||
var il = exp.Instructions;
|
||||
for (_rip = il.First; _rip != null; _rip = _rip == null ? il.First : _rip.Next) {
|
||||
var i = _rip.Value;
|
||||
_ip = il.First;
|
||||
while (_ip != null) {
|
||||
bool nextFlag = false;
|
||||
var i = _ip.Value;
|
||||
if (i is PdtInstruction.Operate) {
|
||||
int fc0 = _framecount;
|
||||
int fc1 = ((PdtInstruction.Operate)i).Signature.ParamCount;
|
||||
@@ -71,29 +74,36 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
else {
|
||||
var frame = _stack[_framecount - 1];
|
||||
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
|
||||
for (var j = 0; j <= fc1; j++) il.Remove(_rip.Previous);
|
||||
ReplaceIP(il, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length), cols);
|
||||
for (var j = 0; j < fc1; j++) il.Remove(_ip.Previous);
|
||||
}
|
||||
}
|
||||
else if (i is PdtInstruction.Collapse) {
|
||||
var t = (PdtInstruction.Collapse)i;
|
||||
try {
|
||||
var pins = _rip;
|
||||
var pins = _ip;
|
||||
i.Execute(this);
|
||||
if (_rip == pins) {
|
||||
_rip = _rip.Next;
|
||||
il.Remove(_rip.Previous);
|
||||
il.Remove(_rip.Previous);
|
||||
_rip = _rip.Previous;
|
||||
if (_stack[_framecount - 1].Type == PdtInternalType.Error) {
|
||||
throw new EvaluationFailureException();
|
||||
}
|
||||
if (_ip == pins) {
|
||||
_ip = _ip.Next;
|
||||
il.Remove(_ip.Previous);
|
||||
il.Remove(_ip.Previous);
|
||||
_ip = _ip.Previous;
|
||||
if (_ip == null) {
|
||||
_ip = il.First;
|
||||
nextFlag = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_rip = pins.Previous;
|
||||
while (_rip.Next != t.Target) il.Remove(_rip.Next);
|
||||
il.Remove(_rip.Next);
|
||||
_ip = pins.Previous;
|
||||
while (_ip.Next != t.Target) il.Remove(_ip.Next);
|
||||
il.Remove(_ip.Next);
|
||||
if (cols.TryGetValue(t.Target, out ct)) {
|
||||
foreach (var u in ct) u.Target = _rip;
|
||||
foreach (var u in ct) u.Target = _ip;
|
||||
cols.Remove(t.Target);
|
||||
cols.Add(_rip, ct);
|
||||
cols.Add(_ip, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,12 +116,11 @@ namespace Cryville.Common.Pdt {
|
||||
i.Execute(this);
|
||||
var frame = _stack[_framecount - 1];
|
||||
if (frame.Type != PdtInternalType.Undefined && frame.Type != PdtInternalType.Error) {
|
||||
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
|
||||
il.Remove(_rip.Previous);
|
||||
ReplaceIP(il, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length), cols);
|
||||
}
|
||||
}
|
||||
else i.Execute(this);
|
||||
if (_rip != null && cols.TryGetValue(_rip, out ct)) {
|
||||
if (_ip != null && cols.TryGetValue(_ip, out ct)) {
|
||||
unsafe {
|
||||
fixed (StackFrame* frame = &_stack[_framecount - 1]) {
|
||||
frame->Type = PdtInternalType.Error;
|
||||
@@ -120,6 +129,7 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!nextFlag) _ip = _ip.Next;
|
||||
}
|
||||
exp.IsConstant = true;
|
||||
exp.IsPotentialConstant = true;
|
||||
@@ -133,6 +143,13 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
}
|
||||
void ReplaceIP(LinkedList<PdtInstruction> il, PdtInstruction ins, Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>> cols) {
|
||||
List<PdtInstruction.Collapse> cins;
|
||||
if (cols.TryGetValue(_ip, out cins)) cols.Remove(_ip);
|
||||
_ip = il.AddAfter(_ip, ins);
|
||||
il.Remove(_ip.Previous);
|
||||
if (cins != null) cols.Add(_ip, cins);
|
||||
}
|
||||
/// <summary>
|
||||
/// Revokes the potential constant mark of the current expression.
|
||||
/// </summary>
|
||||
@@ -184,23 +201,34 @@ namespace Cryville.Common.Pdt {
|
||||
/// <returns>An operator of the specific name.</returns>
|
||||
/// <remarks>The parameter count of the returned operator does not necessarily equal to <paramref name="pc" />.</remarks>
|
||||
protected abstract PdtOperator GetOperator(PdtOperatorSignature sig);
|
||||
unsafe void Operate(PdtOperator op, int pc, bool noset = false) {
|
||||
unsafe bool 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];
|
||||
if (frame.Type == PdtInternalType.Error) {
|
||||
_framecount -= pc - i;
|
||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
|
||||
return false;
|
||||
}
|
||||
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
||||
_goffset -= frame.Length;
|
||||
}
|
||||
op.Call(pmem + _goffset, noset);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
internal unsafe void Collapse(int name, LinkedListNode<PdtInstruction> target) {
|
||||
fixed (byte* pmem = _mem) {
|
||||
var frame = _stack[--_framecount];
|
||||
if (frame.Type == PdtInternalType.Error) {
|
||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
|
||||
_ip = target;
|
||||
return;
|
||||
}
|
||||
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
|
||||
_framecount++;
|
||||
_rip = target;
|
||||
_ip = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,7 +254,7 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The exception that is thrown when the evalution of a <see cref="PdtExpression" /> fails.
|
||||
/// The exception that is thrown when the evaluation of a <see cref="PdtExpression" /> fails.
|
||||
/// </summary>
|
||||
public class EvaluationFailureException : Exception {
|
||||
/// <inheritdoc />
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -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 = "$",
|
||||
};
|
||||
@@ -195,7 +195,7 @@ namespace Cryville.Common.Pdt {
|
||||
default: pc++; break;
|
||||
}
|
||||
}
|
||||
else if (OP_TYPE[t2.Value[0]] == 1) {
|
||||
if (OP_TYPE[t2.Value[0]] == 1) {
|
||||
colp = new Dictionary<LinkedListNode<PdtInstruction>, string> { { ins.Last, t2.Value } };
|
||||
}
|
||||
t1 = t2;
|
||||
|
59
Assets/Cryville/Common/Pdt/PdtFragmentInterpreter.cs
Normal file
59
Assets/Cryville/Common/Pdt/PdtFragmentInterpreter.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Interpreter for fragments in Property Definition Tree (PDT) file format.
|
||||
/// </summary>
|
||||
public class PdtFragmentInterpreter : PdtInterpreter {
|
||||
public PdtFragmentInterpreter() : base(null, new EmptyBinder()) { }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the new source string for the fragment interpreter and resets the position.
|
||||
/// </summary>
|
||||
/// <param name="value">The new source string.</param>
|
||||
public void SetSource(string value) {
|
||||
Source = value;
|
||||
Position = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The binder.
|
||||
/// </summary>
|
||||
public Binder Binder {
|
||||
get { return _binder; }
|
||||
set { _binder = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current character and increments the position.
|
||||
/// </summary>
|
||||
/// <returns>The current character.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
public new char GetChar() { return base.GetChar(); }
|
||||
/// <summary>
|
||||
/// Reads an identifier.
|
||||
/// </summary>
|
||||
/// <returns>An identifier.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
public new string GetIdentifier() { return base.GetIdentifier(); }
|
||||
/// <summary>
|
||||
/// Reads a number.
|
||||
/// </summary>
|
||||
/// <returns>A number.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
public new string GetNumber() { return base.GetNumber(); }
|
||||
/// <summary>
|
||||
/// Reads a string.
|
||||
/// </summary>
|
||||
/// <returns>A string.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
public new string GetString() { return base.GetString(); }
|
||||
/// <summary>
|
||||
/// Reads an expression.
|
||||
/// </summary>
|
||||
/// <returns>An expression.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
public new PdtExpression GetExp() { return base.GetExp(); }
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Pdt/PdtFragmentInterpreter.cs.meta
Normal file
11
Assets/Cryville/Common/Pdt/PdtFragmentInterpreter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7088ba23ed4b424eadaf664be48e376
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,4 +1,4 @@
|
||||
namespace Cryville.Common.Pdt {
|
||||
namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// The identifiers of the internal types of PDT.
|
||||
/// </summary>
|
||||
@@ -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,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Cryville.Common.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using CMath = System.Math;
|
||||
|
||||
namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
@@ -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,19 +55,18 @@ 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;
|
||||
public string Source { get; protected set; }
|
||||
protected Binder _binder;
|
||||
/// <summary>
|
||||
/// The current position in the string being parsed by the interpreter.
|
||||
/// </summary>
|
||||
public int Position { get; private set; }
|
||||
public int Position { get; protected set; }
|
||||
#pragma warning disable IDE1006
|
||||
/// <summary>
|
||||
/// The character at the current position.
|
||||
@@ -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;
|
||||
@@ -221,80 +228,64 @@ namespace Cryville.Common.Pdt {
|
||||
if (!flag) throw new FormatException("Format directive not found");
|
||||
}
|
||||
object InterpretObject(Type type) {
|
||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
||||
bool dictflag = typeof(IDictionary).IsAssignableFrom(type);
|
||||
var result = Activator.CreateInstance(type);
|
||||
bool pcflag = PairCollection.IsPairCollection(type);
|
||||
while (true) {
|
||||
try { ws(); }
|
||||
catch (IndexOutOfRangeException) { return result; }
|
||||
if (cc == '}') {
|
||||
GetChar();
|
||||
return result;
|
||||
}
|
||||
object pkey = InterpretKey(type);
|
||||
char c = GetChar();
|
||||
switch (c) {
|
||||
case '{':
|
||||
if (dictflag) {
|
||||
var ktype = type.GetGenericArguments()[0];
|
||||
var ptype = type.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = InterpretObject(ptype);
|
||||
((IDictionary)result).Add(key, value);
|
||||
}
|
||||
else {
|
||||
MemberInfo prop = null;
|
||||
bool flag = false;
|
||||
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
|
||||
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);
|
||||
}
|
||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
||||
}
|
||||
InterpretObjectInternal<ElementListAttribute>(pcflag, type, pkey, result, type => InterpretObject(type));
|
||||
break;
|
||||
case ':':
|
||||
case ';':
|
||||
var exp = c == ';' ? _emptyexp : GetExp();
|
||||
if (dictflag) {
|
||||
var ktype = type.GetGenericArguments()[0];
|
||||
var vtype = type.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = _binder.ChangeType(exp, vtype, null);
|
||||
((IDictionary)result).Add(key, value);
|
||||
}
|
||||
else {
|
||||
MemberInfo prop = null;
|
||||
bool flag = false;
|
||||
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
|
||||
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);
|
||||
}
|
||||
else {
|
||||
object value = _binder.ChangeType(exp, ptype, null);
|
||||
ReflectionHelper.SetValue(prop, result, value, _binder);
|
||||
}
|
||||
}
|
||||
InterpretObjectInternal<PropertyListAttribute>(pcflag, type, pkey, result, type => _binder.ChangeType(exp, type, null));
|
||||
break;
|
||||
case '}':
|
||||
return result;
|
||||
default:
|
||||
throw new InvalidOperationException("Internal error: Invalid key interpretation");
|
||||
}
|
||||
}
|
||||
}
|
||||
void InterpretObjectInternal<T>(bool pcflag, Type type, object pkey, object result, Func<Type, object> vfunc) where T : Attribute {
|
||||
if (pcflag) {
|
||||
using (var collection = new PairCollection(result)) {
|
||||
var ktype = type.GetGenericArguments()[0];
|
||||
var ptype = type.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = vfunc(ptype);
|
||||
collection.Add(key, value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
MemberInfo prop = null;
|
||||
bool flag = false;
|
||||
if (pkey is string) prop = ReflectionHelper.TryGetMember(type, (string)pkey);
|
||||
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<T>(type, out prop);
|
||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||
Type ptype = ReflectionHelper.GetMemberType(prop);
|
||||
if (flag) {
|
||||
var origCollection = ReflectionHelper.GetValue(prop, result);
|
||||
if (origCollection == null) {
|
||||
ReflectionHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
|
||||
}
|
||||
using (var collection = new PairCollection(origCollection)) {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
object value = vfunc(vtype);
|
||||
collection.Add(key, value);
|
||||
}
|
||||
}
|
||||
else ReflectionHelper.SetValue(prop, result, vfunc(ptype), _binder);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interprets a key from the current position.
|
||||
/// </summary>
|
||||
@@ -315,13 +306,13 @@ namespace Cryville.Common.Pdt {
|
||||
int pos = interpreter.Position;
|
||||
if (pos >= src.Length) return "Failed to interpret the PDT: There are some missing or redundant tokens";
|
||||
int lineStartPos = src.LastIndexOf('\n', pos) + 1;
|
||||
int previewStartPos = src.LastIndexOf('\n', pos, 64);
|
||||
int previewStartPos = src.LastIndexOf('\n', pos, CMath.Min(64, pos));
|
||||
if (previewStartPos == -1) {
|
||||
previewStartPos = pos - 64;
|
||||
if (previewStartPos < 0) previewStartPos = 0;
|
||||
}
|
||||
else previewStartPos++;
|
||||
int previewEndPos = src.IndexOf('\n', pos, 64);
|
||||
int previewEndPos = src.IndexOf('\n', pos, CMath.Min(64, src.Length - pos));
|
||||
if (previewEndPos == -1) {
|
||||
previewEndPos = pos + 64;
|
||||
if (previewEndPos > src.Length) previewEndPos = src.Length;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
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;
|
||||
@@ -116,4 +116,4 @@ namespace Cryville.Common.Pdt {
|
||||
return string.Format("{0}({1})", IdentifierManager.SharedInstance.Retrieve(Name), ParamCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace Cryville.Common.Pdt {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -8,24 +8,7 @@ namespace Cryville.Common {
|
||||
/// Provides a set of <see langword="static" /> methods for refletion.
|
||||
/// </summary>
|
||||
public static class ReflectionHelper {
|
||||
static readonly Type[] emptyTypeArray = {};
|
||||
/// <summary>
|
||||
/// Gets the parameterless constructor of a type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>The parameterless constructor of the type.</returns>
|
||||
public static ConstructorInfo GetEmptyConstructor(Type type) {
|
||||
return type.GetConstructor(emptyTypeArray);
|
||||
}
|
||||
static readonly object[] emptyObjectArray = {};
|
||||
/// <summary>
|
||||
/// Invokes the parameterless constructor of a type and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>The created instance.</returns>
|
||||
public static object InvokeEmptyConstructor(Type type) {
|
||||
return GetEmptyConstructor(type).Invoke(emptyObjectArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find a member with the specified attribute type in a type.
|
||||
@@ -90,6 +73,22 @@ namespace Cryville.Common {
|
||||
return mil[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the member from a type with the specified name.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="name">The name of the member.</param>
|
||||
/// <returns>The member. <see langword="null" /> when not found.</returns>
|
||||
public static MemberInfo TryGetMember(Type type, string name) {
|
||||
var mil = type.GetMember(
|
||||
name,
|
||||
MemberTypes.Field | MemberTypes.Property,
|
||||
BindingFlags.Public | BindingFlags.Instance
|
||||
);
|
||||
if (mil.Length != 1) return null;
|
||||
return mil[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of a member.
|
||||
/// </summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
@@ -28,8 +28,8 @@ namespace Cryville.Common.Unity {
|
||||
set { m_filter = value; }
|
||||
}
|
||||
|
||||
public Dictionary<string, string> m_presetPaths = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> PresetPaths {
|
||||
public IReadOnlyDictionary<string, string> m_presetPaths = new Dictionary<string, string>();
|
||||
public IReadOnlyDictionary<string, string> PresetPaths {
|
||||
get { return m_presetPaths; }
|
||||
set { m_presetPaths = value; }
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
|
@@ -17,7 +17,7 @@ namespace Cryville.Common.Unity.Input {
|
||||
foreach (var t in HandlerRegistries) {
|
||||
try {
|
||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
||||
var h = (InputHandler)Activator.CreateInstance(t);
|
||||
_typemap.Add(t, h);
|
||||
_handlers.Add(h);
|
||||
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
|
||||
|
@@ -1,4 +1,4 @@
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public enum WindowMessages : uint {
|
||||
WM_NULL = 0x0000,
|
||||
WM_CREATE = 0x0001,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public static class UnityCameraUtils {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
@@ -179,7 +179,7 @@ namespace Cryville.Common.Unity {
|
||||
if (!www.isDone) return false;
|
||||
if (handler.isDone && handler.texture != null) {
|
||||
var buffer = handler.texture;
|
||||
/*var result = new Texture2D(buffer.width, buffer.height, buffer.format, true);
|
||||
var result = new Texture2D(buffer.width, buffer.height, buffer.format, true);
|
||||
if (SystemInfo.copyTextureSupport.HasFlag(CopyTextureSupport.Basic)) {
|
||||
Graphics.CopyTexture(buffer, 0, 0, result, 0, 0);
|
||||
}
|
||||
@@ -188,8 +188,8 @@ namespace Cryville.Common.Unity {
|
||||
}
|
||||
result.Apply(true, true);
|
||||
Texture2D.Destroy(buffer);
|
||||
Callback(true, result);*/
|
||||
Callback(true, buffer);
|
||||
Callback(true, result);
|
||||
// Callback(true, buffer);
|
||||
}
|
||||
else {
|
||||
Callback(false, null);
|
||||
|
@@ -1,145 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Common.Unity {
|
||||
public class PropItem : MonoBehaviour {
|
||||
public object Target;
|
||||
public PropertyEditor editor;
|
||||
public DirectoryInfo ContextPath;
|
||||
|
||||
public string PropertyName = "";
|
||||
InputField valueObj;
|
||||
string value;
|
||||
string desc = "";
|
||||
PropertyInfo prop;
|
||||
Type bindToType;
|
||||
TypeConverter converter;
|
||||
|
||||
bool mustExpand = false;
|
||||
bool readOnly = false;
|
||||
string[] filter = null;
|
||||
FileDialog fdialog;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
transform.Find("Value").GetComponent<InputField>().onEndEdit.AddListener(s => OnValueChanged(s));
|
||||
var entry = new EventTrigger.Entry(){
|
||||
eventID = EventTriggerType.PointerClick,
|
||||
callback = new EventTrigger.TriggerEvent()
|
||||
};
|
||||
entry.callback.AddListener(e => OnClick(e));
|
||||
transform.Find("Value").GetComponent<EventTrigger>().triggers.Add(entry);
|
||||
}
|
||||
|
||||
void Start() {
|
||||
transform.Find("Name").GetComponent<Text>().text = PropertyName;
|
||||
valueObj = transform.Find("Value").GetComponent<InputField>();
|
||||
prop = Target.GetType().GetProperty(PropertyName);
|
||||
bindToType = prop.PropertyType;
|
||||
converter = TypeDescriptor.GetConverter(bindToType);
|
||||
|
||||
var descattr = (DescriptionAttribute[])prop.GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
if (descattr.Length > 0) desc = descattr[0].Description;
|
||||
|
||||
var roattr = (ReadOnlyAttribute[])prop.GetCustomAttributes(typeof(ReadOnlyAttribute), true);
|
||||
if (roattr.Length > 0) if (roattr[0].IsReadOnly == true) {
|
||||
readOnly = true;
|
||||
valueObj.enabled = false;
|
||||
valueObj.transform.Find("ValueString").GetComponent<Text>().color = Color.gray;
|
||||
}
|
||||
|
||||
if (converter == null || !converter.CanConvertFrom(typeof(string)) || converter.GetPropertiesSupported()){
|
||||
mustExpand = true;
|
||||
valueObj.enabled = false;
|
||||
}
|
||||
|
||||
var fsattr = (FileStringAttribute[])prop.GetCustomAttributes(typeof(FileStringAttribute), true);
|
||||
if (fsattr.Length > 0) {
|
||||
valueObj.enabled = false;
|
||||
filter = fsattr[0].Filter;
|
||||
}
|
||||
|
||||
UpdateValue();
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
|
||||
void OnFileDialogClosed() {
|
||||
var file = fdialog.GetComponent<FileDialog>().FileName;
|
||||
if (file != "") {
|
||||
var f = new FileInfo(file);
|
||||
if (f.Directory.FullName != ContextPath.FullName) {
|
||||
string targetFile = ContextPath.FullName + "\\" + f.Name;
|
||||
f.CopyTo(targetFile, true);
|
||||
}
|
||||
OnValueChanged(f.Name);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateValue() {
|
||||
object v;
|
||||
valueObj.placeholder.GetComponent<Text>().text = "";
|
||||
v = prop.GetValue(Target, new object[]{ });
|
||||
if (v == null) {
|
||||
DefaultValueAttribute[] defvattr = (DefaultValueAttribute[])prop.GetCustomAttributes(typeof(DefaultValueAttribute), true);
|
||||
if (defvattr.Length > 0) {
|
||||
v = defvattr[0].Value;
|
||||
if (v == null) {
|
||||
v = "";
|
||||
valueObj.placeholder.GetComponent<Text>().text = "null";
|
||||
}
|
||||
}
|
||||
else {
|
||||
v = "";
|
||||
valueObj.placeholder.GetComponent<Text>().text = "null";
|
||||
}
|
||||
}
|
||||
|
||||
if (mustExpand || readOnly || filter != null) {
|
||||
valueObj.transform.Find("ValueString").GetComponent<Text>().text = v.ToString();
|
||||
}
|
||||
else {
|
||||
valueObj.text = v.ToString();
|
||||
}
|
||||
value = valueObj.text;
|
||||
}
|
||||
|
||||
void OnClick(BaseEventData e) {
|
||||
if (mustExpand && !readOnly) {
|
||||
GameObject subeditor = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/PropertyEditor"));
|
||||
object obj = prop.GetValue(Target, new object[]{ });
|
||||
subeditor.GetComponent<PropertyEditor>().TargetObject = obj;
|
||||
}
|
||||
else if (filter != null && !readOnly) {
|
||||
fdialog = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
||||
fdialog.Filter = filter;
|
||||
fdialog.CurrentDirectory = ContextPath;
|
||||
fdialog.OnClose += OnFileDialogClosed;
|
||||
}
|
||||
editor.SetDescription(PropertyName, desc);
|
||||
UpdateValue();
|
||||
}
|
||||
|
||||
void OnValueChanged(string s) {
|
||||
if (s == value) return;
|
||||
object v = null;
|
||||
if (!(mustExpand || readOnly)) {
|
||||
try {
|
||||
v = converter.ConvertFrom(s);
|
||||
prop.SetValue(Target, v, new object[]{ });
|
||||
}
|
||||
catch (TargetInvocationException ex) {
|
||||
// CallHelper.ShowMessageBox(ex.InnerException.Message);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// CallHelper.ShowMessageBox(ex.Message);
|
||||
}
|
||||
}
|
||||
UpdateValue();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 499dc47d3f108de4eb80b2d73e5851c5
|
||||
timeCreated: 1608801352
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Common.Unity {
|
||||
public class PropertyEditor : MonoBehaviour {
|
||||
|
||||
private object target;
|
||||
public object TargetObject {
|
||||
get { return target; }
|
||||
set {
|
||||
target = value;
|
||||
ReloadProperties();
|
||||
}
|
||||
}
|
||||
|
||||
private Text desc;
|
||||
private Transform list;
|
||||
|
||||
public Action Callback;
|
||||
|
||||
private void ReloadProperties() {
|
||||
foreach (Transform p in list) {
|
||||
GameObject.Destroy(p.gameObject);
|
||||
}
|
||||
PropertyInfo[] props = target.GetType().GetProperties();
|
||||
foreach (PropertyInfo m in props) {
|
||||
var brattr = (BrowsableAttribute[])m.GetCustomAttributes(typeof(BrowsableAttribute), true);
|
||||
if (brattr.Length > 0)
|
||||
if (brattr[0].Browsable == false)
|
||||
continue;
|
||||
GameObject mi = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/PropItem"));
|
||||
mi.transform.SetParent(list, false);
|
||||
mi.GetComponent<PropItem>().PropertyName = m.Name;
|
||||
mi.GetComponent<PropItem>().Target = target;
|
||||
mi.GetComponent<PropItem>().editor = this;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
Transform panel = transform.Find("Panel");
|
||||
desc = panel.Find("Description").GetComponent<Text>();
|
||||
list = panel.Find("PropList").Find("PropListInner");
|
||||
SetDescription("(Property)", "");
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
|
||||
public void SetDescription(string n, string d) {
|
||||
desc.text = "<b>" + n + "</b>\n" + d;
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
if (Callback != null) Callback.Invoke();
|
||||
GameObject.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de5a0d32ac5669347ac4570c014967d1
|
||||
timeCreated: 1608801356
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
/// <summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
/// <summary>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Sprites;
|
||||
using UnityEngine.UI;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.UI {
|
||||
public class SetIntegerParameterBehaviour : SetParameterBehaviour {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user