Compare commits
139 Commits
Author | SHA1 | Date | |
---|---|---|---|
e40c98ae1b | |||
642a9563ba | |||
4a1fa48352 | |||
4dc0767e91 | |||
9e82c04898 | |||
0776eca49d | |||
af01fb2119 | |||
9044631fe7 | |||
3b22d4fce3 | |||
5393ff1451 | |||
e34a9cc868 | |||
440581261e | |||
b78e99c59c | |||
3db8f61e3b | |||
8b64165fb7 | |||
799b1e12da | |||
957270c41a | |||
bc51a45df8 | |||
9b091a0084 | |||
98e35fc6f6 | |||
d83f447e82 | |||
898885b116 | |||
fd05f6c1dd | |||
86da71f2cb | |||
ba2f1d4858 | |||
3687a70aec | |||
8da54093aa | |||
b057ea8074 | |||
e7bc9d0294 | |||
08de91b04d | |||
ea70fbb051 | |||
cee6a08240 | |||
f04b9cfb75 | |||
1dcbc03829 | |||
d89423caf5 | |||
c9b348dd4f | |||
636f45f03f | |||
7fce9591a9 | |||
f65e4f1900 | |||
a4d0e3867a | |||
83b9c27e94 | |||
864ea91be0 | |||
ea02fc22bd | |||
60cc763cd0 | |||
8955b69cdf | |||
a7aff4d625 | |||
22cb8f0cb4 | |||
db07ace927 | |||
094c3fe2a3 | |||
cc156e0d81 | |||
9833052849 | |||
a6a0ac3f9e | |||
82060a6403 | |||
02441eb328 | |||
2fe2a40e74 | |||
754e3be906 | |||
65c225e93b | |||
74ce265016 | |||
2eba0e490f | |||
82f769f798 | |||
a008760918 | |||
832facdf5b | |||
d5ba09cbea | |||
59b4f14fb3 | |||
4d13c06f27 | |||
de72fcf572 | |||
1470dbb5aa | |||
ce31f3e15f | |||
f6741d0acc | |||
910e3ce277 | |||
52adef8e9b | |||
3d7639b94e | |||
b306a9d3d1 | |||
0cc15f0c8e | |||
0959b5cc25 | |||
44c54cd837 | |||
6e553b9ebb | |||
88a46127d7 | |||
4310b67e7b | |||
7deff3c6be | |||
5f4d35b3b3 | |||
5b510fa5da | |||
17042b6664 | |||
3fb123ff30 | |||
ca928eb731 | |||
906c82972b | |||
cee74b9e31 | |||
25b4f3ccb7 | |||
d1b9b9607b | |||
6ccc86c28d | |||
3d75cd9a11 | |||
b30d35c937 | |||
a8231f7c86 | |||
ed60859406 | |||
0d0902735a | |||
5bed3cf05b | |||
5d520609b5 | |||
bf53298706 | |||
3d09ec8c94 | |||
bc083541aa | |||
5b04426cd3 | |||
8d606524fc | |||
5bab0ca648 | |||
fb31e833cb | |||
346040574a | |||
959d07b0a9 | |||
c41d41c881 | |||
f09e3d3545 | |||
12b3373aeb | |||
9480904db7 | |||
bee3401283 | |||
fe4280aa2e | |||
3e273d67ba | |||
fcec43f694 | |||
904581c520 | |||
b983e32d56 | |||
f2aea2bd40 | |||
cc8e1f7ce4 | |||
749e1395bc | |||
21af9582f8 | |||
26dd373e7b | |||
1bd35d2c51 | |||
d275f61602 | |||
f5f1a5de67 | |||
56153f5eed | |||
b4984c0b3a | |||
dad399facf | |||
b536871da7 | |||
bd028c1b72 | |||
fa9303c0a1 | |||
d030c48b4d | |||
beab3d7f8b | |||
0b2ea3ddbc | |||
b143fb49ce | |||
8f211568be | |||
6d276c99ac | |||
72a93721f9 | |||
a1fd420493 | |||
d72afaa75b |
@@ -1,65 +0,0 @@
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A resource pool that allows reusing instances of arrays of type <typeparamref name="T" />.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item type of the arrays in the pool.</typeparam>
|
||||
public class ArrayPool<T> {
|
||||
private class Bucket : ObjectPool<T[]> {
|
||||
readonly int _size;
|
||||
public Bucket(int size, int capacity) : base(capacity) {
|
||||
_size = size;
|
||||
}
|
||||
protected override T[] Construct() {
|
||||
return new T[_size];
|
||||
}
|
||||
}
|
||||
readonly Bucket[] _buckets;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="ArrayPool{T}" /> class with the default maximum list size and bucket capacity.
|
||||
/// </summary>
|
||||
public ArrayPool() : this(0x40000000, 256) { }
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="ArrayPool{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="maxSize">The maximum size of the arrays in the pool.</param>
|
||||
/// <param name="capacityPerBucket">The capacity of each bucket. The pool groups arrays of similar sizes into buckets for faster access.</param>
|
||||
public ArrayPool(int maxSize, int capacityPerBucket) {
|
||||
if (maxSize < 16) maxSize = 16;
|
||||
int num = GetID(maxSize) + 1;
|
||||
_buckets = new Bucket[num];
|
||||
for (int i = 0; i < num; i++) {
|
||||
_buckets[i] = new Bucket(GetSize(i), capacityPerBucket);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Rents an array that is at least the specified size from the pool.
|
||||
/// </summary>
|
||||
/// <param name="size">The minimum size of the array.</param>
|
||||
/// <returns>An array of type <see cref="T" /> that is at least the specified size.</returns>
|
||||
public T[] Rent(int size) {
|
||||
int len2 = size;
|
||||
if (len2 < 16) len2 = 16;
|
||||
var arr = _buckets[GetID(len2)].Rent();
|
||||
return arr;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a rented array to the pool.
|
||||
/// </summary>
|
||||
/// <param name="arr">The array to return.</param>
|
||||
public void Return(T[] arr) {
|
||||
int len2 = arr.Length;
|
||||
if (len2 < 16) len2 = 16;
|
||||
_buckets[GetID(len2)].Return(arr);
|
||||
}
|
||||
static int GetID(int size) {
|
||||
size -= 1;
|
||||
size >>= 4;
|
||||
int num = 0;
|
||||
for (; size != 0; size >>= 1) num++;
|
||||
return num;
|
||||
}
|
||||
static int GetSize(int id) {
|
||||
return 0x10 << id;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A set of resource pools categorized by a category type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCategory">The category type.</typeparam>
|
||||
/// <typeparam name="TObject">The type of the objects in the pool.</typeparam>
|
||||
public abstract class CategorizedPool<TCategory, TObject> where TObject : class {
|
||||
/// <summary>
|
||||
/// The set of underlying pools.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The <see cref="Rent(TCategory)" /> and <see cref="Return(TCategory, TObject)" /> method select an underlying pool directly from this set with the category as the key. When overridden, this set must be available since construction.</para>
|
||||
/// </remarks>
|
||||
protected abstract IReadOnlyDictionary<TCategory, ObjectPool<TObject>> Buckets { get; }
|
||||
/// <summary>
|
||||
/// The count of objects rented from the set of pools.
|
||||
/// </summary>
|
||||
public int RentedCount { get; private set; }
|
||||
/// <summary>
|
||||
/// Rents an object from the pool.
|
||||
/// </summary>
|
||||
/// <param name="category">The category.</param>
|
||||
/// <returns>The rented object.</returns>
|
||||
public TObject Rent(TCategory category) {
|
||||
var obj = Buckets[category].Rent();
|
||||
RentedCount++;
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a rented object to the pool.
|
||||
/// </summary>
|
||||
/// <param name="category">The category.</param>
|
||||
/// <param name="obj">The object to return.</param>
|
||||
public void Return(TCategory category, TObject obj) {
|
||||
Buckets[category].Return(obj);
|
||||
--RentedCount;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A utility to access a categorized pool, representing a single unit that uses a shared categorized pool.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCategory">The category type.</typeparam>
|
||||
/// <typeparam name="TObject">The type of the objects in the pool.</typeparam>
|
||||
public class CategorizedPoolAccessor<TCategory, TObject> where TObject : class {
|
||||
readonly CategorizedPool<TCategory, TObject> _pool;
|
||||
static readonly SimpleObjectPool<Dictionary<TObject, TCategory>> _dictPool
|
||||
= new SimpleObjectPool<Dictionary<TObject, TCategory>>(1024);
|
||||
Dictionary<TObject, TCategory> _rented;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="CategorizedPoolAccessor{TCategory, TObject}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="pool">The categorized pool.</param>
|
||||
public CategorizedPoolAccessor(CategorizedPool<TCategory, TObject> pool) {
|
||||
_pool = pool;
|
||||
}
|
||||
/// <summary>
|
||||
/// Rents an object from the pool.
|
||||
/// </summary>
|
||||
/// <param name="category">The category.</param>
|
||||
/// <returns>The rented object.</returns>
|
||||
public TObject Rent(TCategory category) {
|
||||
var obj = _pool.Rent(category);
|
||||
if (_rented == null) _rented = _dictPool.Rent();
|
||||
_rented.Add(obj, category);
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a rented object to the pool.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to return.</param>
|
||||
public void Return(TObject obj) {
|
||||
_pool.Return(_rented[obj], obj);
|
||||
_rented.Remove(obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns all objects rented by this accessor to the pool.
|
||||
/// </summary>
|
||||
public void ReturnAll() {
|
||||
if (_rented == null) return;
|
||||
foreach (var obj in _rented) {
|
||||
_pool.Return(obj.Value, obj.Key);
|
||||
}
|
||||
_rented.Clear();
|
||||
_dictPool.Return(_rented);
|
||||
_rented = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A resource pool that allows reusing instances of lists of type <typeparamref name="T" />.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The item type of the lists in the pool.</typeparam>
|
||||
public class ListPool<T> {
|
||||
private class Bucket : ObjectPool<List<T>> {
|
||||
readonly int _size;
|
||||
public Bucket(int size, int capacity) : base(capacity) {
|
||||
_size = size;
|
||||
}
|
||||
protected override List<T> Construct() {
|
||||
return new List<T>(_size);
|
||||
}
|
||||
}
|
||||
readonly Bucket[] _buckets;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="ListPool{T}" /> class with the default maximum list size and bucket capacity.
|
||||
/// </summary>
|
||||
public ListPool() : this(0x40000000, 256) { }
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="ListPool{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="maxSize">The maximum size of the lists in the pool.</param>
|
||||
/// <param name="capacityPerBucket">The capacity of each bucket. The pool groups lists of similar sizes into buckets for faster access.</param>
|
||||
public ListPool(int maxSize, int capacityPerBucket) {
|
||||
if (maxSize < 16) maxSize = 16;
|
||||
int num = GetID(maxSize) + 1;
|
||||
_buckets = new Bucket[num];
|
||||
for (int i = 0; i < num; i++) {
|
||||
_buckets[i] = new Bucket(GetSize(i), capacityPerBucket);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Rents a list of the specified size from the pool. The size of the list must not be changed when it is rented.
|
||||
/// </summary>
|
||||
/// <param name="size">The size of the list.</param>
|
||||
/// <returns>A <see cref="List{T}" /> of the specified size.</returns>
|
||||
public List<T> Rent(int size) {
|
||||
int len2 = size;
|
||||
if (len2 < 16) len2 = 16;
|
||||
var list = _buckets[GetID(len2)].Rent();
|
||||
if (list.Count < size)
|
||||
for (int i = list.Count; i < size; i++) list.Add(default(T));
|
||||
else if (list.Count > size)
|
||||
list.RemoveRange(size, list.Count - size);
|
||||
return list;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a rented list to the pool.
|
||||
/// </summary>
|
||||
/// <param name="list">The list to return.</param>
|
||||
public void Return(List<T> list) {
|
||||
int len2 = list.Capacity;
|
||||
if (len2 < 16) len2 = 16;
|
||||
_buckets[GetID(len2)].Return(list);
|
||||
}
|
||||
static int GetID(int size) {
|
||||
size -= 1;
|
||||
size >>= 4;
|
||||
int num = 0;
|
||||
for (; size != 0; size >>= 1) num++;
|
||||
return num;
|
||||
}
|
||||
static int GetSize(int id) {
|
||||
return 0x10 << id;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A resource pool that allows reusing instances of type <typeparamref name="T" />.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the objects in the pool.</typeparam>
|
||||
public abstract class ObjectPool<T> where T : class {
|
||||
int _index;
|
||||
readonly T[] _objs;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="ObjectPool{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="capacity">The capacity of the pool.</param>
|
||||
public ObjectPool(int capacity) {
|
||||
_objs = new T[capacity];
|
||||
}
|
||||
/// <summary>
|
||||
/// The count of objects rented from the pool.
|
||||
/// </summary>
|
||||
public int RentedCount { get { return _index; } }
|
||||
/// <summary>
|
||||
/// Rents a object from the pool.
|
||||
/// </summary>
|
||||
/// <returns>The rented object.</returns>
|
||||
public T Rent() {
|
||||
T obj = null;
|
||||
if (_index < _objs.Length) {
|
||||
obj = _objs[_index];
|
||||
_objs[_index++] = null;
|
||||
}
|
||||
if (obj == null) obj = Construct();
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a rented object to the pool.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to return.</param>
|
||||
public void Return(T obj) {
|
||||
if (_index > 0) {
|
||||
Reset(obj);
|
||||
_objs[--_index] = obj;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a new instance of type <typeparamref name="T" />.
|
||||
/// </summary>
|
||||
/// <returns>The new instance.</returns>
|
||||
protected abstract T Construct();
|
||||
/// <summary>
|
||||
/// Resets an object.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object.</param>
|
||||
protected virtual void Reset(T obj) { }
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// A resource pool that allows reusing instances of type <typeparamref name="T" />, which has a parameterless constructor.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the objects in the pool.</typeparam>
|
||||
public class SimpleObjectPool<T> : ObjectPool<T> where T : class, new() {
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="SimpleObjectPool{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="capacity">The capacity of the pool.</param>
|
||||
public SimpleObjectPool(int capacity) : base(capacity) { }
|
||||
protected override T Construct() {
|
||||
return new T();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8cd439340f088d4eb83711a5bc6384d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,135 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Buffers {
|
||||
/// <summary>
|
||||
/// An auto-resized <see cref="char" /> array as a variable-length string used as a target that is modified frequently.
|
||||
/// </summary>
|
||||
public class TargetString : IEnumerable<char> {
|
||||
public event Action OnUpdate;
|
||||
char[] _arr;
|
||||
bool _invalidated;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="TargetString" /> class with a capacity of 16.
|
||||
/// </summary>
|
||||
public TargetString() : this(16) { }
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="TargetString" /> class.
|
||||
/// </summary>
|
||||
/// <param name="capacity">The initial capacity of the string.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity" /> is less than or equal to 0.</exception>
|
||||
public TargetString(int capacity) {
|
||||
if (capacity <= 0) throw new ArgumentOutOfRangeException("capacity");
|
||||
_arr = new char[capacity];
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets one of the characters in the string.
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index of the character.</param>
|
||||
/// <returns>The character at the given index.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index" /> is less than 0 or not less than <see cref="Length" />.</exception>
|
||||
/// <remarks>
|
||||
/// <para>Set <see cref="Length" /> to a desired value before updating the characters.</para>
|
||||
/// <para>Call <see cref=" Validate" /> after all the characters are updated.</para>
|
||||
/// </remarks>
|
||||
public char this[int index] {
|
||||
get {
|
||||
if (index < 0 || index >= m_length)
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
return _arr[index];
|
||||
}
|
||||
set {
|
||||
if (index < 0 || index >= m_length)
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
if (_arr[index] == value) return;
|
||||
_arr[index] = value;
|
||||
_invalidated = true;
|
||||
}
|
||||
}
|
||||
int m_length;
|
||||
/// <summary>
|
||||
/// The length of the string.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentOutOfRangeException">The value specified for a set operation is less than 0.</exception>
|
||||
public int Length {
|
||||
get {
|
||||
return m_length;
|
||||
}
|
||||
set {
|
||||
if (Length < 0) throw new ArgumentOutOfRangeException("length");
|
||||
if (m_length == value) return;
|
||||
if (_arr.Length < value) {
|
||||
var len = _arr.Length;
|
||||
while (len < value) len *= 2;
|
||||
var arr2 = new char[len];
|
||||
Array.Copy(_arr, arr2, m_length);
|
||||
_arr = arr2;
|
||||
}
|
||||
m_length = value;
|
||||
_invalidated = true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Validates the string.
|
||||
/// </summary>
|
||||
public void Validate() {
|
||||
if (!_invalidated) return;
|
||||
_invalidated = false;
|
||||
var ev = OnUpdate;
|
||||
if (ev != null) ev.Invoke();
|
||||
}
|
||||
internal char[] TrustedAsArray() { return _arr; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the <see cref="TargetString" />.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Enumerator" /> for the <see cref="TargetString" />.</returns>
|
||||
public Enumerator GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
IEnumerator<char> IEnumerable<char>.GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
public struct Enumerator : IEnumerator<char> {
|
||||
readonly TargetString _self;
|
||||
int _index;
|
||||
internal Enumerator(TargetString self) {
|
||||
_self = self;
|
||||
_index = -1;
|
||||
}
|
||||
|
||||
public char Current {
|
||||
get {
|
||||
if (_index < 0)
|
||||
throw new InvalidOperationException(_index == -1 ? "Enum not started" : "Enum ended");
|
||||
return _self[_index];
|
||||
}
|
||||
}
|
||||
|
||||
object IEnumerator.Current { get { return Current; } }
|
||||
|
||||
public void Dispose() {
|
||||
_index = -2;
|
||||
}
|
||||
|
||||
public bool MoveNext() {
|
||||
if (_index == -2) return false;
|
||||
_index++;
|
||||
if (_index >= _self.Length) {
|
||||
_index = -2;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
_index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0fc34ac257793d4883a9cfcdb6941b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
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,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73fb17b484b343242bcce27c15ed7d44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,50 +0,0 @@
|
||||
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,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2517e8f040bd36f46948e5fafaf5335c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,48 +0,0 @@
|
||||
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,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9ed5ea8b7b1a934287e7ec5971166c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,106 +0,0 @@
|
||||
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,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7fe2c6f3299681448c1a546cce4dc65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 046617672d437de4ab7e644a55defd3b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,51 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f87dfb8f6a1f5640b6deae741cd715c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,29 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57fc9f037c1fda5449e2a365a835c82c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 634536d804abc784394d4ac028a77879
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -3,12 +3,12 @@ using System;
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
public class RangeAttribute : Attribute {
|
||||
public RangeAttribute(float min, float max) {
|
||||
public RangeAttribute(double min, double max) {
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
|
||||
public float Min { get; set; }
|
||||
public float Max { get; set; }
|
||||
public double Min { get; set; }
|
||||
public double Max { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,9 @@ using System;
|
||||
namespace Cryville.Common.ComponentModel {
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
|
||||
public class StepAttribute : Attribute {
|
||||
public StepAttribute(float step) {
|
||||
public StepAttribute(double step) {
|
||||
Step = step;
|
||||
}
|
||||
public float Step { get; set; }
|
||||
public double Step { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -6,295 +6,295 @@ using System.Linq;
|
||||
namespace Cryville.Common.Font {
|
||||
public abstract class FontMatcher {
|
||||
protected FontManager Manager { get; private set; }
|
||||
public FontMatcher(FontManager manafer) { Manager = manafer; }
|
||||
public FontMatcher(FontManager manager) { Manager = manager; }
|
||||
public abstract IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false);
|
||||
}
|
||||
public class FallbackListFontMatcher : FontMatcher {
|
||||
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
|
||||
public void LoadDefaultWindowsFallbackList() {
|
||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return;
|
||||
MapScriptToTypefaces.Clear();
|
||||
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
|
||||
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
|
||||
var map = new Dictionary<string, List<string>>();
|
||||
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
|
||||
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "SimSun"); // Custom
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "SimHei"); // Custom
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Arial");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Segoe UI"); // Custom
|
||||
MapScriptToTypefaces["arab"].Insert(0, "Tahoma");
|
||||
MapScriptToTypefaces["cyrl"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["grek"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["hebr"].Insert(0, "David");
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "MS PGothic");
|
||||
MapScriptToTypefaces["latn"].Insert(0, "Times New Roman");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "SimSun");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "SimHei"); // Custom
|
||||
MapScriptToTypefaces["thai"].Insert(0, "Tahoma");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "PMingLiU");
|
||||
map["zyyy"].Insert(0, "SimSun"); // Custom
|
||||
map["zyyy"].Insert(0, "SimHei"); // Custom
|
||||
map["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
|
||||
map["zyyy"].Insert(0, "Arial");
|
||||
map["zyyy"].Insert(0, "Times New Roman");
|
||||
map["zyyy"].Insert(0, "Segoe UI"); // Custom
|
||||
map["arab"].Insert(0, "Tahoma");
|
||||
map["cyrl"].Insert(0, "Times New Roman");
|
||||
map["grek"].Insert(0, "Times New Roman");
|
||||
map["hebr"].Insert(0, "David");
|
||||
map["jpan"].Insert(0, "MS PGothic");
|
||||
map["latn"].Insert(0, "Times New Roman");
|
||||
map["hans"].Insert(0, "SimSun");
|
||||
map["hans"].Insert(0, "SimHei"); // Custom
|
||||
map["thai"].Insert(0, "Tahoma");
|
||||
map["hans"].Insert(0, "PMingLiU");
|
||||
// Reference: https://learn.microsoft.com/en-us/globalization/input/font-support
|
||||
var ver = Environment.OSVersion.Version;
|
||||
if (ver >= new Version(5, 0)) { // Windows 2000
|
||||
MapScriptToTypefaces["armn"].Insert(0, "Sylfaen");
|
||||
MapScriptToTypefaces["deva"].Insert(0, "Mangal");
|
||||
MapScriptToTypefaces["geor"].Insert(0, "Sylfaen");
|
||||
MapScriptToTypefaces["taml"].Insert(0, "Latha");
|
||||
map["armn"].Insert(0, "Sylfaen");
|
||||
map["deva"].Insert(0, "Mangal");
|
||||
map["geor"].Insert(0, "Sylfaen");
|
||||
map["taml"].Insert(0, "Latha");
|
||||
}
|
||||
if (ver >= new Version(5, 1)) { // Windows XP
|
||||
MapScriptToTypefaces["gujr"].Insert(0, "Shruti");
|
||||
MapScriptToTypefaces["guru"].Insert(0, "Raavi");
|
||||
MapScriptToTypefaces["knda"].Insert(0, "Tunga");
|
||||
MapScriptToTypefaces["syrc"].Insert(0, "Estrangelo Edessa");
|
||||
MapScriptToTypefaces["telu"].Insert(0, "Gautami");
|
||||
MapScriptToTypefaces["thaa"].Insert(0, "MV Boli");
|
||||
map["gujr"].Insert(0, "Shruti");
|
||||
map["guru"].Insert(0, "Raavi");
|
||||
map["knda"].Insert(0, "Tunga");
|
||||
map["syrc"].Insert(0, "Estrangelo Edessa");
|
||||
map["telu"].Insert(0, "Gautami");
|
||||
map["thaa"].Insert(0, "MV Boli");
|
||||
// SP2
|
||||
MapScriptToTypefaces["beng"].Insert(0, "Vrinda");
|
||||
MapScriptToTypefaces["mlym"].Insert(0, "Kartika");
|
||||
map["beng"].Insert(0, "Vrinda");
|
||||
map["mlym"].Insert(0, "Kartika");
|
||||
}
|
||||
if (ver >= new Version(6, 0)) { // Windows Vista
|
||||
MapScriptToTypefaces["cans"].Insert(0, "Euphemia");
|
||||
MapScriptToTypefaces["cher"].Insert(0, "Plantagenet");
|
||||
MapScriptToTypefaces["ethi"].Insert(0, "Nyala");
|
||||
MapScriptToTypefaces["khmr"].Insert(0, "DaunPenh MoolBoran");
|
||||
MapScriptToTypefaces["laoo"].Insert(0, "DokChampa");
|
||||
MapScriptToTypefaces["mong"].Insert(0, "Mongolian Baiti");
|
||||
MapScriptToTypefaces["orya"].Insert(0, "Kalinga");
|
||||
MapScriptToTypefaces["sinh"].Insert(0, "Iskoola Pota");
|
||||
MapScriptToTypefaces["tibt"].Insert(0, "Microsoft Himalaya");
|
||||
MapScriptToTypefaces["yiii"].Insert(0, "Microsoft Yi Baiti");
|
||||
MapScriptToTypefaces["arab"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["cyrl"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["grek"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["latn"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["hans"].Add("SimSun-ExtB");
|
||||
MapScriptToTypefaces["hant"].Add("MingLiU-ExtB");
|
||||
MapScriptToTypefaces["hant"].Add("MingLiU_HKSCS-ExtB");
|
||||
MapScriptToTypefaces["arab"].Add("Microsoft Uighur");
|
||||
MapScriptToTypefaces["zmth"].Insert(0, "Cambria Math");
|
||||
map["cans"].Insert(0, "Euphemia");
|
||||
map["cher"].Insert(0, "Plantagenet");
|
||||
map["ethi"].Insert(0, "Nyala");
|
||||
map["khmr"].Insert(0, "DaunPenh MoolBoran");
|
||||
map["laoo"].Insert(0, "DokChampa");
|
||||
map["mong"].Insert(0, "Mongolian Baiti");
|
||||
map["orya"].Insert(0, "Kalinga");
|
||||
map["sinh"].Insert(0, "Iskoola Pota");
|
||||
map["tibt"].Insert(0, "Microsoft Himalaya");
|
||||
map["yiii"].Insert(0, "Microsoft Yi Baiti");
|
||||
map["arab"].Insert(0, "Segoe UI");
|
||||
map["cyrl"].Insert(0, "Segoe UI");
|
||||
map["grek"].Insert(0, "Segoe UI");
|
||||
map["latn"].Insert(0, "Segoe UI");
|
||||
map["hans"].Add("SimSun-ExtB");
|
||||
map["hant"].Add("MingLiU-ExtB");
|
||||
map["hant"].Add("MingLiU_HKSCS-ExtB");
|
||||
map["arab"].Add("Microsoft Uighur");
|
||||
map["zmth"].Insert(0, "Cambria Math");
|
||||
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "Meiryo");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei");
|
||||
map["jpan"].Insert(0, "Meiryo");
|
||||
map["hans"].Insert(0, "Microsoft YaHei");
|
||||
}
|
||||
if (ver >= new Version(6, 1)) { // Windows 7
|
||||
MapScriptToTypefaces["brai"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["dsrt"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["talu"].Insert(0, "Microsoft New Tai Lue");
|
||||
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["osma"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["phag"].Insert(0, "Microsoft PhagsPa");
|
||||
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["zsym"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["tale"].Insert(0, "Microsoft Tai Le");
|
||||
MapScriptToTypefaces["tfng"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["vaii"].Insert(0, "Ebrima");
|
||||
map["brai"].Insert(0, "Segoe UI Symbol");
|
||||
map["dsrt"].Insert(0, "Segoe UI Symbol");
|
||||
map["talu"].Insert(0, "Microsoft New Tai Lue");
|
||||
map["ogam"].Insert(0, "Segoe UI Symbol");
|
||||
map["osma"].Insert(0, "Ebrima");
|
||||
map["phag"].Insert(0, "Microsoft PhagsPa");
|
||||
map["runr"].Insert(0, "Segoe UI Symbol");
|
||||
map["zsym"].Insert(0, "Segoe UI Symbol");
|
||||
map["tale"].Insert(0, "Microsoft Tai Le");
|
||||
map["tfng"].Insert(0, "Ebrima");
|
||||
map["vaii"].Insert(0, "Ebrima");
|
||||
}
|
||||
if (ver >= new Version(6, 2)) { // Windows 8
|
||||
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["hang"].Add("Malgun Gothic");
|
||||
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["lisu"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["mymr"].Insert(0, "Myanmar Text");
|
||||
MapScriptToTypefaces["nkoo"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["ethi"].Insert(0, "Ebrima");
|
||||
MapScriptToTypefaces["cans"].Insert(0, "Gadugi");
|
||||
MapScriptToTypefaces["hant"].Insert(0, "Microsoft JhengHei UI");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei UI");
|
||||
MapScriptToTypefaces["beng"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["deva"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["gujr"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["mlym"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["orya"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
MapScriptToTypefaces["telu"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["armn"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["geor"].Insert(0, "Segoe UI");
|
||||
MapScriptToTypefaces["hebr"].Insert(0, "Segoe UI");
|
||||
map["glag"].Insert(0, "Segoe UI Symbol");
|
||||
map["goth"].Insert(0, "Segoe UI Symbol");
|
||||
map["hang"].Add("Malgun Gothic");
|
||||
map["ital"].Insert(0, "Segoe UI Symbol");
|
||||
map["lisu"].Insert(0, "Segoe UI");
|
||||
map["mymr"].Insert(0, "Myanmar Text");
|
||||
map["nkoo"].Insert(0, "Ebrima");
|
||||
map["orkh"].Insert(0, "Segoe UI Symbol");
|
||||
map["ethi"].Insert(0, "Ebrima");
|
||||
map["cans"].Insert(0, "Gadugi");
|
||||
map["hant"].Insert(0, "Microsoft JhengHei UI");
|
||||
map["hans"].Insert(0, "Microsoft YaHei UI");
|
||||
map["beng"].Insert(0, "Nirmala UI");
|
||||
map["deva"].Insert(0, "Nirmala UI");
|
||||
map["gujr"].Insert(0, "Nirmala UI");
|
||||
map["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
map["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
map["mlym"].Insert(0, "Nirmala UI");
|
||||
map["orya"].Insert(0, "Nirmala UI");
|
||||
map["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
map["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
|
||||
map["telu"].Insert(0, "Nirmala UI");
|
||||
map["armn"].Insert(0, "Segoe UI");
|
||||
map["geor"].Insert(0, "Segoe UI");
|
||||
map["hebr"].Insert(0, "Segoe UI");
|
||||
}
|
||||
if (ver >= new Version(6, 3)) { // Windows 8.1
|
||||
MapScriptToTypefaces["bugi"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["copt"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["java"].Insert(0, "Javanese Text");
|
||||
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Symbol");
|
||||
MapScriptToTypefaces["olck"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["sora"].Insert(0, "Nirmala UI");
|
||||
MapScriptToTypefaces["khmr"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["laoo"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["thai"].Insert(0, "Leelawadee UI");
|
||||
MapScriptToTypefaces["zsye"].Insert(0, "Segoe UI Emoji");
|
||||
map["bugi"].Insert(0, "Leelawadee UI");
|
||||
map["copt"].Insert(0, "Segoe UI Symbol");
|
||||
map["java"].Insert(0, "Javanese Text");
|
||||
map["merc"].Insert(0, "Segoe UI Symbol");
|
||||
map["olck"].Insert(0, "Nirmala UI");
|
||||
map["sora"].Insert(0, "Nirmala UI");
|
||||
map["khmr"].Insert(0, "Leelawadee UI");
|
||||
map["laoo"].Insert(0, "Leelawadee UI");
|
||||
map["thai"].Insert(0, "Leelawadee UI");
|
||||
map["zsye"].Insert(0, "Segoe UI Emoji");
|
||||
}
|
||||
if (ver >= new Version(10, 0)) { // Windows 10
|
||||
MapScriptToTypefaces["brah"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["cari"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["cprt"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["egyp"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["armi"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["phli"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["prti"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["khar"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["lyci"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["lydi"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["phnx"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["xpeo"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["sarb"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["shaw"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["xsux"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["ugar"].Insert(0, "Segoe UI Historic");
|
||||
map["brah"].Insert(0, "Segoe UI Historic");
|
||||
map["cari"].Insert(0, "Segoe UI Historic");
|
||||
map["cprt"].Insert(0, "Segoe UI Historic");
|
||||
map["egyp"].Insert(0, "Segoe UI Historic");
|
||||
map["armi"].Insert(0, "Segoe UI Historic");
|
||||
map["phli"].Insert(0, "Segoe UI Historic");
|
||||
map["prti"].Insert(0, "Segoe UI Historic");
|
||||
map["khar"].Insert(0, "Segoe UI Historic");
|
||||
map["lyci"].Insert(0, "Segoe UI Historic");
|
||||
map["lydi"].Insert(0, "Segoe UI Historic");
|
||||
map["phnx"].Insert(0, "Segoe UI Historic");
|
||||
map["xpeo"].Insert(0, "Segoe UI Historic");
|
||||
map["sarb"].Insert(0, "Segoe UI Historic");
|
||||
map["shaw"].Insert(0, "Segoe UI Historic");
|
||||
map["xsux"].Insert(0, "Segoe UI Historic");
|
||||
map["ugar"].Insert(0, "Segoe UI Historic");
|
||||
// Segoe UI Symbol -> Segoe UI Historic
|
||||
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Historic");
|
||||
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Historic");
|
||||
map["glag"].Insert(0, "Segoe UI Historic");
|
||||
map["goth"].Insert(0, "Segoe UI Historic");
|
||||
map["merc"].Insert(0, "Segoe UI Historic");
|
||||
map["ogam"].Insert(0, "Segoe UI Historic");
|
||||
map["ital"].Insert(0, "Segoe UI Historic");
|
||||
map["orkh"].Insert(0, "Segoe UI Historic");
|
||||
map["runr"].Insert(0, "Segoe UI Historic");
|
||||
//
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "Yu Gothic UI");
|
||||
MapScriptToTypefaces["zsym"].Add("Segoe MDL2 Assets");
|
||||
map["jpan"].Insert(0, "Yu Gothic UI");
|
||||
map["zsym"].Add("Segoe MDL2 Assets");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
public void LoadDefaultAndroidFallbackList() {
|
||||
if (Environment.OSVersion.Platform != PlatformID.Unix) return;
|
||||
MapScriptToTypefaces.Clear();
|
||||
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK JP");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK SC");
|
||||
MapScriptToTypefaces["zyyy"].Insert(0, "Roboto");
|
||||
MapScriptToTypefaces["zsye"].Insert(0, "Noto Color Emoji");
|
||||
MapScriptToTypefaces["zsye"].Add("Noto Color Emoji Flags");
|
||||
MapScriptToTypefaces["arab"].Insert(0, "Noto Naskh Arabic");
|
||||
MapScriptToTypefaces["adlm"].Insert(0, "Noto Sans Adlam");
|
||||
MapScriptToTypefaces["ahom"].Insert(0, "Noto Sans Ahom");
|
||||
MapScriptToTypefaces["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
|
||||
MapScriptToTypefaces["armn"].Insert(0, "Noto Sans Armenian");
|
||||
MapScriptToTypefaces["avst"].Insert(0, "Noto Sans Avestan");
|
||||
MapScriptToTypefaces["bali"].Insert(0, "Noto Sans Balinese");
|
||||
MapScriptToTypefaces["bamu"].Insert(0, "Noto Sans Bamum");
|
||||
MapScriptToTypefaces["bass"].Insert(0, "Noto Sans Bassa Vah");
|
||||
MapScriptToTypefaces["batk"].Insert(0, "Noto Sans Batak");
|
||||
MapScriptToTypefaces["beng"].Insert(0, "Noto Sans Bengali");
|
||||
MapScriptToTypefaces["bhks"].Insert(0, "Noto Sans Bhaiksuki");
|
||||
MapScriptToTypefaces["brah"].Insert(0, "Noto Sans Brahmi");
|
||||
MapScriptToTypefaces["bugi"].Insert(0, "Noto Sans Buginese");
|
||||
MapScriptToTypefaces["buhd"].Insert(0, "Noto Sans Buhid");
|
||||
MapScriptToTypefaces["jpan"].Insert(0, "Noto Sans CJK JP");
|
||||
MapScriptToTypefaces["kore"].Insert(0, "Noto Sans CJK KR");
|
||||
MapScriptToTypefaces["hans"].Insert(0, "Noto Sans CJK SC");
|
||||
MapScriptToTypefaces["hant"].Insert(0, "Noto Sans CJK TC");
|
||||
MapScriptToTypefaces["hant"].Add("Noto Sans CJK HK");
|
||||
MapScriptToTypefaces["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
|
||||
MapScriptToTypefaces["cari"].Insert(0, "Noto Sans Carian");
|
||||
MapScriptToTypefaces["cakm"].Insert(0, "Noto Sans Chakma");
|
||||
MapScriptToTypefaces["cham"].Insert(0, "Noto Sans Cham");
|
||||
MapScriptToTypefaces["cher"].Insert(0, "Noto Sans Cherokee");
|
||||
MapScriptToTypefaces["copt"].Insert(0, "Noto Sans Coptic");
|
||||
MapScriptToTypefaces["xsux"].Insert(0, "Noto Sans Cuneiform");
|
||||
MapScriptToTypefaces["cprt"].Insert(0, "Noto Sans Cypriot");
|
||||
MapScriptToTypefaces["dsrt"].Insert(0, "Noto Sans Deseret");
|
||||
MapScriptToTypefaces["deva"].Insert(0, "Noto Sans Devanagari");
|
||||
MapScriptToTypefaces["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
|
||||
MapScriptToTypefaces["elba"].Insert(0, "Noto Sans Elbasan");
|
||||
MapScriptToTypefaces["ethi"].Insert(0, "Noto Sans Ethiopic");
|
||||
MapScriptToTypefaces["geor"].Insert(0, "Noto Sans Georgian");
|
||||
MapScriptToTypefaces["glag"].Insert(0, "Noto Sans Glagolitic");
|
||||
MapScriptToTypefaces["goth"].Insert(0, "Noto Sans Gothic");
|
||||
MapScriptToTypefaces["gran"].Insert(0, "Noto Sans Grantha");
|
||||
MapScriptToTypefaces["gujr"].Insert(0, "Noto Sans Gujarati");
|
||||
MapScriptToTypefaces["gong"].Insert(0, "Noto Sans Gunjala Gondi");
|
||||
MapScriptToTypefaces["guru"].Insert(0, "Noto Sans Gurmukhi");
|
||||
MapScriptToTypefaces["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
|
||||
MapScriptToTypefaces["hano"].Insert(0, "Noto Sans Hanunoo");
|
||||
MapScriptToTypefaces["hatr"].Insert(0, "Noto Sans Hatran");
|
||||
MapScriptToTypefaces["hebr"].Insert(0, "Noto Sans Hebrew");
|
||||
MapScriptToTypefaces["armi"].Insert(0, "Noto Sans Imperial Aramaic");
|
||||
MapScriptToTypefaces["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
|
||||
MapScriptToTypefaces["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
|
||||
MapScriptToTypefaces["java"].Insert(0, "Noto Sans Javanese");
|
||||
MapScriptToTypefaces["kthi"].Insert(0, "Noto Sans Kaithi");
|
||||
MapScriptToTypefaces["knda"].Insert(0, "Noto Sans Kannada");
|
||||
MapScriptToTypefaces["kali"].Insert(0, "Noto Sans KayahLi");
|
||||
MapScriptToTypefaces["khar"].Insert(0, "Noto Sans Kharoshthi");
|
||||
MapScriptToTypefaces["khmr"].Insert(0, "Noto Sans Khmer");
|
||||
MapScriptToTypefaces["khoj"].Insert(0, "Noto Sans Khojki");
|
||||
MapScriptToTypefaces["laoo"].Insert(0, "Noto Sans Lao");
|
||||
MapScriptToTypefaces["lepc"].Insert(0, "Noto Sans Lepcha");
|
||||
MapScriptToTypefaces["limb"].Insert(0, "Noto Sans Limbu");
|
||||
MapScriptToTypefaces["lina"].Insert(0, "Noto Sans Linear A");
|
||||
MapScriptToTypefaces["linb"].Insert(0, "Noto Sans Linear B");
|
||||
MapScriptToTypefaces["lisu"].Insert(0, "Noto Sans Lisu");
|
||||
MapScriptToTypefaces["lyci"].Insert(0, "Noto Sans Lycian");
|
||||
MapScriptToTypefaces["lydi"].Insert(0, "Noto Sans Lydian");
|
||||
MapScriptToTypefaces["mlym"].Insert(0, "Noto Sans Malayalam");
|
||||
MapScriptToTypefaces["mand"].Insert(0, "Noto Sans Mandiac");
|
||||
MapScriptToTypefaces["mani"].Insert(0, "Noto Sans Manichaean");
|
||||
MapScriptToTypefaces["marc"].Insert(0, "Noto Sans Marchen");
|
||||
MapScriptToTypefaces["gonm"].Insert(0, "Noto Sans Masaram Gondi");
|
||||
MapScriptToTypefaces["medf"].Insert(0, "Noto Sans Medefaidrin");
|
||||
MapScriptToTypefaces["mtei"].Insert(0, "Noto Sans Meetei Mayek");
|
||||
MapScriptToTypefaces["merc"].Insert(0, "Noto Sans Meroitic");
|
||||
MapScriptToTypefaces["mero"].Insert(0, "Noto Sans Meroitic");
|
||||
MapScriptToTypefaces["plrd"].Insert(0, "Noto Sans Miao");
|
||||
MapScriptToTypefaces["modi"].Insert(0, "Noto Sans Modi");
|
||||
MapScriptToTypefaces["mong"].Insert(0, "Noto Sans Mongolian");
|
||||
MapScriptToTypefaces["mroo"].Insert(0, "Noto Sans Mro");
|
||||
MapScriptToTypefaces["mult"].Insert(0, "Noto Sans Multani");
|
||||
MapScriptToTypefaces["mymr"].Insert(0, "Noto Sans Myanmar");
|
||||
MapScriptToTypefaces["nkoo"].Insert(0, "Noto Sans Nko");
|
||||
MapScriptToTypefaces["nbat"].Insert(0, "Noto Sans Nabataean");
|
||||
MapScriptToTypefaces["talu"].Insert(0, "Noto Sans New Tai Lue");
|
||||
MapScriptToTypefaces["newa"].Insert(0, "Noto Sans Newa");
|
||||
MapScriptToTypefaces["ogam"].Insert(0, "Noto Sans Ogham");
|
||||
MapScriptToTypefaces["olck"].Insert(0, "Noto Sans Ol Chiki");
|
||||
MapScriptToTypefaces["ital"].Insert(0, "Noto Sans Old Italian");
|
||||
MapScriptToTypefaces["narb"].Insert(0, "Noto Sans Old North Arabian");
|
||||
MapScriptToTypefaces["perm"].Insert(0, "Noto Sans Old Permic");
|
||||
MapScriptToTypefaces["xpeo"].Insert(0, "Noto Sans Old Persian");
|
||||
MapScriptToTypefaces["sarb"].Insert(0, "Noto Sans Old South Arabian");
|
||||
MapScriptToTypefaces["orkh"].Insert(0, "Noto Sans Old Turkic");
|
||||
MapScriptToTypefaces["orya"].Insert(0, "Noto Sans Oriya");
|
||||
MapScriptToTypefaces["osge"].Insert(0, "Noto Sans Osage");
|
||||
MapScriptToTypefaces["osma"].Insert(0, "Noto Sans Osmanya");
|
||||
MapScriptToTypefaces["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
|
||||
MapScriptToTypefaces["palm"].Insert(0, "Noto Sans Palmyrene");
|
||||
MapScriptToTypefaces["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
|
||||
MapScriptToTypefaces["phag"].Insert(0, "Noto Sans Phags Pa");
|
||||
MapScriptToTypefaces["phnx"].Insert(0, "Noto Sans Phoenician");
|
||||
MapScriptToTypefaces["rjng"].Insert(0, "Noto Sans Rejang");
|
||||
MapScriptToTypefaces["runr"].Insert(0, "Noto Sans Runic");
|
||||
MapScriptToTypefaces["samr"].Insert(0, "Noto Sans Samaritan");
|
||||
MapScriptToTypefaces["saur"].Insert(0, "Noto Sans Saurashtra");
|
||||
MapScriptToTypefaces["shrd"].Insert(0, "Noto Sans Sharada");
|
||||
MapScriptToTypefaces["shaw"].Insert(0, "Noto Sans Shavian");
|
||||
MapScriptToTypefaces["sinh"].Insert(0, "Noto Sans Sinhala");
|
||||
MapScriptToTypefaces["sora"].Insert(0, "Noto Sans Sora Sompeng");
|
||||
MapScriptToTypefaces["soyo"].Insert(0, "Noto Sans Soyombo");
|
||||
MapScriptToTypefaces["sund"].Insert(0, "Noto Sans Sundanese");
|
||||
MapScriptToTypefaces["sylo"].Insert(0, "Noto Sans Syloti Nagri");
|
||||
MapScriptToTypefaces["zsym"].Insert(0, "Noto Sans Symbols");
|
||||
MapScriptToTypefaces["syrn"].Insert(0, "Noto Sans Syriac Eastern");
|
||||
MapScriptToTypefaces["syre"].Insert(0, "Noto Sans Syriac Estrangela");
|
||||
MapScriptToTypefaces["syrj"].Insert(0, "Noto Sans Syriac Western");
|
||||
MapScriptToTypefaces["tglg"].Insert(0, "Noto Sans Tagalog");
|
||||
MapScriptToTypefaces["tagb"].Insert(0, "Noto Sans Tagbanwa");
|
||||
MapScriptToTypefaces["tale"].Insert(0, "Noto Sans Tai Le");
|
||||
MapScriptToTypefaces["lana"].Insert(0, "Noto Sans Tai Tham");
|
||||
MapScriptToTypefaces["tavt"].Insert(0, "Noto Sans Tai Viet");
|
||||
MapScriptToTypefaces["takr"].Insert(0, "Noto Sans Takri");
|
||||
MapScriptToTypefaces["taml"].Insert(0, "Noto Sans Tamil");
|
||||
MapScriptToTypefaces["telu"].Insert(0, "Noto Sans Telugu");
|
||||
MapScriptToTypefaces["thaa"].Insert(0, "Noto Sans Thaana");
|
||||
MapScriptToTypefaces["thai"].Insert(0, "Noto Sans Thai");
|
||||
MapScriptToTypefaces["tfng"].Insert(0, "Noto Sans Tifinagh");
|
||||
MapScriptToTypefaces["ugar"].Insert(0, "Noto Sans Ugaritic");
|
||||
MapScriptToTypefaces["vaii"].Insert(0, "Noto Sans Vai");
|
||||
MapScriptToTypefaces["wcho"].Insert(0, "Noto Sans Wancho");
|
||||
MapScriptToTypefaces["wara"].Insert(0, "Noto Sans Warang Citi");
|
||||
MapScriptToTypefaces["yiii"].Insert(0, "Noto Sans Yi");
|
||||
public static Dictionary<string, List<string>> GetDefaultAndroidFallbackMap() {
|
||||
var map = new Dictionary<string, List<string>>();
|
||||
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
|
||||
map["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
|
||||
map["zyyy"].Insert(0, "Noto Sans CJK JP");
|
||||
map["zyyy"].Insert(0, "Noto Sans CJK SC");
|
||||
map["zyyy"].Insert(0, "Roboto");
|
||||
map["zsye"].Insert(0, "Noto Color Emoji");
|
||||
map["zsye"].Add("Noto Color Emoji Flags");
|
||||
map["arab"].Insert(0, "Noto Naskh Arabic");
|
||||
map["adlm"].Insert(0, "Noto Sans Adlam");
|
||||
map["ahom"].Insert(0, "Noto Sans Ahom");
|
||||
map["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
|
||||
map["armn"].Insert(0, "Noto Sans Armenian");
|
||||
map["avst"].Insert(0, "Noto Sans Avestan");
|
||||
map["bali"].Insert(0, "Noto Sans Balinese");
|
||||
map["bamu"].Insert(0, "Noto Sans Bamum");
|
||||
map["bass"].Insert(0, "Noto Sans Bassa Vah");
|
||||
map["batk"].Insert(0, "Noto Sans Batak");
|
||||
map["beng"].Insert(0, "Noto Sans Bengali");
|
||||
map["bhks"].Insert(0, "Noto Sans Bhaiksuki");
|
||||
map["brah"].Insert(0, "Noto Sans Brahmi");
|
||||
map["bugi"].Insert(0, "Noto Sans Buginese");
|
||||
map["buhd"].Insert(0, "Noto Sans Buhid");
|
||||
map["jpan"].Insert(0, "Noto Sans CJK JP");
|
||||
map["kore"].Insert(0, "Noto Sans CJK KR");
|
||||
map["hans"].Insert(0, "Noto Sans CJK SC");
|
||||
map["hant"].Insert(0, "Noto Sans CJK TC");
|
||||
map["hant"].Add("Noto Sans CJK HK");
|
||||
map["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
|
||||
map["cari"].Insert(0, "Noto Sans Carian");
|
||||
map["cakm"].Insert(0, "Noto Sans Chakma");
|
||||
map["cham"].Insert(0, "Noto Sans Cham");
|
||||
map["cher"].Insert(0, "Noto Sans Cherokee");
|
||||
map["copt"].Insert(0, "Noto Sans Coptic");
|
||||
map["xsux"].Insert(0, "Noto Sans Cuneiform");
|
||||
map["cprt"].Insert(0, "Noto Sans Cypriot");
|
||||
map["dsrt"].Insert(0, "Noto Sans Deseret");
|
||||
map["deva"].Insert(0, "Noto Sans Devanagari");
|
||||
map["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
|
||||
map["elba"].Insert(0, "Noto Sans Elbasan");
|
||||
map["ethi"].Insert(0, "Noto Sans Ethiopic");
|
||||
map["geor"].Insert(0, "Noto Sans Georgian");
|
||||
map["glag"].Insert(0, "Noto Sans Glagolitic");
|
||||
map["goth"].Insert(0, "Noto Sans Gothic");
|
||||
map["gran"].Insert(0, "Noto Sans Grantha");
|
||||
map["gujr"].Insert(0, "Noto Sans Gujarati");
|
||||
map["gong"].Insert(0, "Noto Sans Gunjala Gondi");
|
||||
map["guru"].Insert(0, "Noto Sans Gurmukhi");
|
||||
map["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
|
||||
map["hano"].Insert(0, "Noto Sans Hanunoo");
|
||||
map["hatr"].Insert(0, "Noto Sans Hatran");
|
||||
map["hebr"].Insert(0, "Noto Sans Hebrew");
|
||||
map["armi"].Insert(0, "Noto Sans Imperial Aramaic");
|
||||
map["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
|
||||
map["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
|
||||
map["java"].Insert(0, "Noto Sans Javanese");
|
||||
map["kthi"].Insert(0, "Noto Sans Kaithi");
|
||||
map["knda"].Insert(0, "Noto Sans Kannada");
|
||||
map["kali"].Insert(0, "Noto Sans KayahLi");
|
||||
map["khar"].Insert(0, "Noto Sans Kharoshthi");
|
||||
map["khmr"].Insert(0, "Noto Sans Khmer");
|
||||
map["khoj"].Insert(0, "Noto Sans Khojki");
|
||||
map["laoo"].Insert(0, "Noto Sans Lao");
|
||||
map["lepc"].Insert(0, "Noto Sans Lepcha");
|
||||
map["limb"].Insert(0, "Noto Sans Limbu");
|
||||
map["lina"].Insert(0, "Noto Sans Linear A");
|
||||
map["linb"].Insert(0, "Noto Sans Linear B");
|
||||
map["lisu"].Insert(0, "Noto Sans Lisu");
|
||||
map["lyci"].Insert(0, "Noto Sans Lycian");
|
||||
map["lydi"].Insert(0, "Noto Sans Lydian");
|
||||
map["mlym"].Insert(0, "Noto Sans Malayalam");
|
||||
map["mand"].Insert(0, "Noto Sans Mandiac");
|
||||
map["mani"].Insert(0, "Noto Sans Manichaean");
|
||||
map["marc"].Insert(0, "Noto Sans Marchen");
|
||||
map["gonm"].Insert(0, "Noto Sans Masaram Gondi");
|
||||
map["medf"].Insert(0, "Noto Sans Medefaidrin");
|
||||
map["mtei"].Insert(0, "Noto Sans Meetei Mayek");
|
||||
map["merc"].Insert(0, "Noto Sans Meroitic");
|
||||
map["mero"].Insert(0, "Noto Sans Meroitic");
|
||||
map["plrd"].Insert(0, "Noto Sans Miao");
|
||||
map["modi"].Insert(0, "Noto Sans Modi");
|
||||
map["mong"].Insert(0, "Noto Sans Mongolian");
|
||||
map["mroo"].Insert(0, "Noto Sans Mro");
|
||||
map["mult"].Insert(0, "Noto Sans Multani");
|
||||
map["mymr"].Insert(0, "Noto Sans Myanmar");
|
||||
map["nkoo"].Insert(0, "Noto Sans Nko");
|
||||
map["nbat"].Insert(0, "Noto Sans Nabataean");
|
||||
map["talu"].Insert(0, "Noto Sans New Tai Lue");
|
||||
map["newa"].Insert(0, "Noto Sans Newa");
|
||||
map["ogam"].Insert(0, "Noto Sans Ogham");
|
||||
map["olck"].Insert(0, "Noto Sans Ol Chiki");
|
||||
map["ital"].Insert(0, "Noto Sans Old Italian");
|
||||
map["narb"].Insert(0, "Noto Sans Old North Arabian");
|
||||
map["perm"].Insert(0, "Noto Sans Old Permic");
|
||||
map["xpeo"].Insert(0, "Noto Sans Old Persian");
|
||||
map["sarb"].Insert(0, "Noto Sans Old South Arabian");
|
||||
map["orkh"].Insert(0, "Noto Sans Old Turkic");
|
||||
map["orya"].Insert(0, "Noto Sans Oriya");
|
||||
map["osge"].Insert(0, "Noto Sans Osage");
|
||||
map["osma"].Insert(0, "Noto Sans Osmanya");
|
||||
map["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
|
||||
map["palm"].Insert(0, "Noto Sans Palmyrene");
|
||||
map["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
|
||||
map["phag"].Insert(0, "Noto Sans Phags Pa");
|
||||
map["phnx"].Insert(0, "Noto Sans Phoenician");
|
||||
map["rjng"].Insert(0, "Noto Sans Rejang");
|
||||
map["runr"].Insert(0, "Noto Sans Runic");
|
||||
map["samr"].Insert(0, "Noto Sans Samaritan");
|
||||
map["saur"].Insert(0, "Noto Sans Saurashtra");
|
||||
map["shrd"].Insert(0, "Noto Sans Sharada");
|
||||
map["shaw"].Insert(0, "Noto Sans Shavian");
|
||||
map["sinh"].Insert(0, "Noto Sans Sinhala");
|
||||
map["sora"].Insert(0, "Noto Sans Sora Sompeng");
|
||||
map["soyo"].Insert(0, "Noto Sans Soyombo");
|
||||
map["sund"].Insert(0, "Noto Sans Sundanese");
|
||||
map["sylo"].Insert(0, "Noto Sans Syloti Nagri");
|
||||
map["zsym"].Insert(0, "Noto Sans Symbols");
|
||||
map["syrn"].Insert(0, "Noto Sans Syriac Eastern");
|
||||
map["syre"].Insert(0, "Noto Sans Syriac Estrangela");
|
||||
map["syrj"].Insert(0, "Noto Sans Syriac Western");
|
||||
map["tglg"].Insert(0, "Noto Sans Tagalog");
|
||||
map["tagb"].Insert(0, "Noto Sans Tagbanwa");
|
||||
map["tale"].Insert(0, "Noto Sans Tai Le");
|
||||
map["lana"].Insert(0, "Noto Sans Tai Tham");
|
||||
map["tavt"].Insert(0, "Noto Sans Tai Viet");
|
||||
map["takr"].Insert(0, "Noto Sans Takri");
|
||||
map["taml"].Insert(0, "Noto Sans Tamil");
|
||||
map["telu"].Insert(0, "Noto Sans Telugu");
|
||||
map["thaa"].Insert(0, "Noto Sans Thaana");
|
||||
map["thai"].Insert(0, "Noto Sans Thai");
|
||||
map["tfng"].Insert(0, "Noto Sans Tifinagh");
|
||||
map["ugar"].Insert(0, "Noto Sans Ugaritic");
|
||||
map["vaii"].Insert(0, "Noto Sans Vai");
|
||||
map["wcho"].Insert(0, "Noto Sans Wancho");
|
||||
map["wara"].Insert(0, "Noto Sans Warang Citi");
|
||||
map["yiii"].Insert(0, "Noto Sans Yi");
|
||||
return map;
|
||||
}
|
||||
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
|
||||
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
|
||||
|
@@ -4,12 +4,12 @@ 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 object Name { get { return IdentifierManager.Shared.Retrieve(Key); } }
|
||||
public Identifier(int key) {
|
||||
Key = key;
|
||||
}
|
||||
public Identifier(object name) {
|
||||
Key = IdentifierManager.SharedInstance.Request(name);
|
||||
Key = IdentifierManager.Shared.Request(name);
|
||||
}
|
||||
public override bool Equals(object obj) {
|
||||
if (obj == null || !(obj is Identifier)) return false;
|
||||
|
@@ -1,52 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common {
|
||||
/// <summary>
|
||||
/// A manager that assigns each given identifiers a unique integer ID.
|
||||
/// </summary>
|
||||
public class IdentifierManager {
|
||||
/// <summary>
|
||||
/// A shared instance of the <see cref="IdentifierManager" /> class.
|
||||
/// </summary>
|
||||
public static IdentifierManager SharedInstance = new IdentifierManager();
|
||||
|
||||
readonly Dictionary<object, int> _idents = new Dictionary<object, int>();
|
||||
readonly List<object> _ids = new List<object>();
|
||||
|
||||
readonly object _syncRoot = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="IdentifierManager" /> class.
|
||||
/// </summary>
|
||||
public IdentifierManager() {
|
||||
Request(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests an integer ID for an identifier.
|
||||
/// </summary>
|
||||
/// <param name="ident">The identifier.</param>
|
||||
/// <returns>The integer ID.</returns>
|
||||
public int Request(object ident) {
|
||||
lock (_syncRoot) {
|
||||
int id;
|
||||
if (!_idents.TryGetValue(ident, out id)) {
|
||||
_idents.Add(ident, id = _idents.Count);
|
||||
_ids.Add(ident);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the identifier assigned with an integer ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The integer ID.</param>
|
||||
/// <returns>The identifier.</returns>
|
||||
public object Retrieve(int id) {
|
||||
lock (_syncRoot) {
|
||||
return _ids[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 478086496f56eaf46be4df4e2ad37fee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,128 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Common {
|
||||
/// <summary>
|
||||
/// A logger.
|
||||
/// </summary>
|
||||
public abstract class Logger {
|
||||
static readonly Dictionary<string, Logger> Instances = new Dictionary<string, Logger>();
|
||||
static readonly Dictionary<string, StreamWriter> Files = new Dictionary<string, StreamWriter>();
|
||||
static string logPath = null;
|
||||
/// <summary>
|
||||
/// Sets the path where the log files shall be stored.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
public static void SetLogPath(string path) {
|
||||
logPath = path;
|
||||
var dir = new DirectoryInfo(path);
|
||||
if (!dir.Exists) dir.Create();
|
||||
}
|
||||
/// <summary>
|
||||
/// Logs to the specified logger.
|
||||
/// </summary>
|
||||
/// <param name="key">The key of the logger.</param>
|
||||
/// <param name="level">The severity level.</param>
|
||||
/// <param name="module">The module that is logging.</param>
|
||||
/// <param name="format">The format string.</param>
|
||||
/// <param name="args">The arguments for formatting.</param>
|
||||
public static void Log(string key, int level, string module, string format, params object[] args) {
|
||||
if (!Instances.ContainsKey(key)) return;
|
||||
Instances[key].Log(level, module, string.Format(format, args));
|
||||
if (Files.ContainsKey(key)) Files[key].WriteLine("[{0:O}] [{1}] <{2}> {3}", DateTime.UtcNow, level, module, string.Format(format, args));
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a created logger to the shared logger manager.
|
||||
/// </summary>
|
||||
/// <param name="key">The key of the logger.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public static void Create(string key, Logger logger) {
|
||||
Instances[key] = logger;
|
||||
if (logPath != null) {
|
||||
Files[key] = new StreamWriter(logPath + "/" + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture) + "-" + key + ".log") {
|
||||
AutoFlush = true
|
||||
};
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Closes all loggers and related file streams.
|
||||
/// </summary>
|
||||
public static void Close() {
|
||||
Instances.Clear();
|
||||
foreach (var f in Files) f.Value.Dispose();
|
||||
Files.Clear();
|
||||
}
|
||||
/// <summary>
|
||||
/// Logs to the logger.
|
||||
/// </summary>
|
||||
/// <param name="level">The severity level.</param>
|
||||
/// <param name="module">The module that is logging.</param>
|
||||
/// <param name="msg">The message.</param>
|
||||
public virtual void Log(int level, string module, string msg) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Logger" /> that calls a callback function on log.
|
||||
/// </summary>
|
||||
public class InstantLogger : Logger {
|
||||
readonly Action<int, string, string> callback;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="InstantLogger" /> class.
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback function.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="callback" /> is <see langword="null" />.</exception>
|
||||
public InstantLogger(Action<int, string, string> callback) {
|
||||
if (callback == null)
|
||||
throw new ArgumentNullException("callback");
|
||||
this.callback = callback;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override void Log(int level, string module, string msg) {
|
||||
base.Log(level, module, msg);
|
||||
callback(level, module, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Logger" /> that buffers the logs for enumeration.
|
||||
/// </summary>
|
||||
public class BufferedLogger : Logger {
|
||||
readonly List<LogEntry> buffer = new List<LogEntry>();
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="BufferedLogger" /> class.
|
||||
/// </summary>
|
||||
public BufferedLogger() { }
|
||||
/// <inheritdoc />
|
||||
public override void Log(int level, string module, string msg) {
|
||||
base.Log(level, module, msg);
|
||||
lock (buffer) {
|
||||
buffer.Add(new LogEntry(level, module, msg));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Enumerates the buffered logs.
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback function to receive the logs.</param>
|
||||
public void Enumerate(Action<int, string, string> callback) {
|
||||
lock (buffer) {
|
||||
foreach (var i in buffer) {
|
||||
callback(i.level, i.module, i.msg);
|
||||
}
|
||||
}
|
||||
buffer.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
struct LogEntry {
|
||||
public int level;
|
||||
public string module;
|
||||
public string msg;
|
||||
public LogEntry(int level, string module, string msg) {
|
||||
this.level = level;
|
||||
this.module = module;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c1729cfde78f1c479c9f7eb166e0107
|
||||
timeCreated: 1611126212
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53f4e3167a1eee2478b0abc6302aee8f
|
||||
guid: 1a624371d4108614b9cdc4acca1499e2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@@ -1,14 +1,14 @@
|
||||
using Cryville.Common.Logging;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Common.Network {
|
||||
public class HttpClient {
|
||||
namespace Cryville.Common.Network.Http11 {
|
||||
public class Http11Client : IDisposable {
|
||||
private readonly string _directHost;
|
||||
protected string DirectHost { get { return _directHost; } }
|
||||
|
||||
@@ -18,29 +18,17 @@ namespace Cryville.Common.Network {
|
||||
readonly Uri _baseUri;
|
||||
readonly int origPort;
|
||||
|
||||
protected string Version = "HTTP/1.1";
|
||||
protected const string Version = "HTTP/1.1";
|
||||
protected TcpClient TcpClient { get; private set; }
|
||||
protected Stream RawTcpStream {
|
||||
get {
|
||||
return TcpClient.GetStream();
|
||||
}
|
||||
}
|
||||
protected virtual Stream Stream {
|
||||
get {
|
||||
return TcpClient.GetStream();
|
||||
}
|
||||
}
|
||||
protected virtual string WindowsProxyProtocolName {
|
||||
get {
|
||||
return "http";
|
||||
}
|
||||
}
|
||||
protected Stream RawTcpStream { get { return TcpClient.GetStream(); } }
|
||||
protected virtual Stream Stream { get { return TcpClient.GetStream(); } }
|
||||
protected virtual string WindowsProxyProtocolName { get { return "http"; } }
|
||||
|
||||
private readonly bool _proxied = false;
|
||||
|
||||
public Dictionary<string, string> Headers { get; set; }
|
||||
|
||||
public HttpClient(Uri baseUri, int port = 80) {
|
||||
public Http11Client(Uri baseUri, int port = 80) {
|
||||
_directHost = baseUri.Host;
|
||||
_directPort = port;
|
||||
_baseUri = baseUri;
|
||||
@@ -60,18 +48,29 @@ namespace Cryville.Common.Network {
|
||||
public virtual void Close() {
|
||||
TcpClient.Close();
|
||||
}
|
||||
|
||||
public HttpResponse Request(string method, Uri uri, string body = null, Encoding encoding = null) {
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public virtual void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
public Http11Response Request(string method, Uri uri, string body = null, Encoding encoding = null) {
|
||||
string struri = GetUri(uri).PathAndQuery;
|
||||
return Request(Stream, method, struri, body, encoding);
|
||||
}
|
||||
|
||||
public HttpResponse Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
|
||||
var headers = new Dictionary<string, string>();
|
||||
Http11Response Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
|
||||
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var h in Headers)
|
||||
headers.Add(h.Key, h.Value);
|
||||
headers["Host"] = _baseUri.Host;
|
||||
byte[] payload = new byte[0];
|
||||
byte[] payload = null;
|
||||
if (body != null) {
|
||||
if (encoding == null)
|
||||
encoding = Encoding.UTF8;
|
||||
@@ -79,22 +78,24 @@ namespace Cryville.Common.Network {
|
||||
headers.Add("Content-Encoding", encoding.EncodingName);
|
||||
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
string request_line = string.Format(
|
||||
"{0} {1} {2}\r\n", method, uri, Version
|
||||
);
|
||||
string header_fields = string.Concat((
|
||||
from h in headers select h.Key + ":" + h.Value + "\r\n"
|
||||
).ToArray());
|
||||
byte[] buffer0 = Encoding.ASCII.GetBytes(string.Format(
|
||||
"{0}{1}\r\n", request_line, header_fields
|
||||
));
|
||||
byte[] buffer1 = new byte[buffer0.Length + payload.Length];
|
||||
Array.Copy(buffer0, buffer1, buffer0.Length);
|
||||
Array.Copy(payload, 0, buffer1, buffer0.Length, payload.Length);
|
||||
Logger.Log("main", 0, "Network", Encoding.UTF8.GetString(buffer1));
|
||||
stream.Write(buffer1, 0, buffer1.Length);
|
||||
stream.Flush();
|
||||
var response = new HttpResponse(stream);
|
||||
using (var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true)) {
|
||||
writer.Write(method);
|
||||
writer.Write(' ');
|
||||
writer.Write(uri);
|
||||
writer.Write(' ');
|
||||
writer.Write(Version);
|
||||
writer.Write("\r\n");
|
||||
foreach (var header in headers) {
|
||||
writer.Write(header.Key);
|
||||
writer.Write(':');
|
||||
writer.Write(header.Value);
|
||||
writer.Write("\r\n");
|
||||
}
|
||||
writer.Write("\r\n");
|
||||
if (payload != null) writer.Write(payload);
|
||||
writer.Flush();
|
||||
}
|
||||
var response = new Http11Response(stream);
|
||||
Logger.Log("main", 0, "Network", "{0}", response);
|
||||
return response;
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2745c44c3cc32be4ab3a43888c14b9a1
|
||||
guid: 5a795e416e54c69418de1a3c27a88932
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,30 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Common.Network {
|
||||
public class HttpResponse {
|
||||
namespace Cryville.Common.Network.Http11 {
|
||||
public class Http11Response : IDisposable {
|
||||
static readonly char[] spchar = new char[]{ ' ' };
|
||||
public string HttpVersion { get; private set; }
|
||||
public string StatusCode { get; private set; }
|
||||
public string ReasonPhase { get; private set; }
|
||||
public Dictionary<string, string> Headers { get; private set; }
|
||||
public HttpResponseStream MessageBody { get; private set; }
|
||||
internal HttpResponse(Stream stream) {
|
||||
public Http11ResponseStream MessageBody { get; private set; }
|
||||
internal Http11Response(Stream stream) {
|
||||
var reader = new BinaryReader(stream, Encoding.ASCII);
|
||||
var statu_line = ReadLine(reader).Split(spchar, 3);
|
||||
HttpVersion = statu_line[0];
|
||||
StatusCode = statu_line[1];
|
||||
ReasonPhase = statu_line[2];
|
||||
Logger.Log("main", 0, "Network", "Receive Response: {0} {1} {2}", HttpVersion, StatusCode, ReasonPhase);
|
||||
Headers = new Dictionary<string, string>();
|
||||
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
while (ParseHeader(reader, Headers)) ;
|
||||
if (Headers.ContainsKey("content-length")) {
|
||||
int length = int.Parse(Headers["content-length"]);
|
||||
MessageBody = new HttpResponseBlockStream(reader, length);
|
||||
MessageBody = new Http11ResponseBlockStream(reader, length);
|
||||
}
|
||||
else if (Headers.ContainsKey("transfer-encoding") && Headers["transfer-encoding"] == "chunked") {
|
||||
MessageBody = new HttpResponseChunkedStream(reader);
|
||||
MessageBody = new Http11ResponseChunkedStream(reader);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public virtual void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
MessageBody.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +47,11 @@ namespace Cryville.Common.Network {
|
||||
// TODO Multiline header
|
||||
var header = ReadLine(reader);
|
||||
if (header == "") return false;
|
||||
var s = header.Split(':');
|
||||
var s = header.Split(':', 2);
|
||||
string field_name = s[0].Trim().ToLower();
|
||||
string field_value = s[1].Trim();
|
||||
if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value;
|
||||
else headers.Add(field_name, field_value);
|
||||
Logger.Log("main", 0, "Network", "Receive Header {0}: {1}", field_name, field_value);
|
||||
return true;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec18f22479042d747b88c093aa90c5c0
|
||||
guid: 71234dd1c93d47b4893750686b2333a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -4,8 +4,8 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Common.Network {
|
||||
public abstract class HttpResponseStream : Stream {
|
||||
namespace Cryville.Common.Network.Http11 {
|
||||
public abstract class Http11ResponseStream : Stream {
|
||||
public override bool CanRead { get { return true; } }
|
||||
|
||||
public override bool CanSeek { get { return false; } }
|
||||
@@ -36,11 +36,11 @@ namespace Cryville.Common.Network {
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class HttpResponseBlockStream : HttpResponseStream {
|
||||
internal sealed class Http11ResponseBlockStream : Http11ResponseStream {
|
||||
readonly BinaryReader _reader;
|
||||
readonly int _length;
|
||||
int _pos = 0;
|
||||
internal HttpResponseBlockStream(BinaryReader reader, int length) {
|
||||
internal Http11ResponseBlockStream(BinaryReader reader, int length) {
|
||||
_reader = reader;
|
||||
_length = length;
|
||||
}
|
||||
@@ -50,7 +50,6 @@ namespace Cryville.Common.Network {
|
||||
if (recv_len == 0) return 0;
|
||||
while (recv < recv_len) {
|
||||
recv += _reader.Read(buffer, offset + recv, count - recv);
|
||||
Logger.Log("main", 0, "Network", "Message body received: {0}/{1}/{2}", recv, recv_len, _length);
|
||||
}
|
||||
_pos += recv_len;
|
||||
return recv_len;
|
||||
@@ -62,36 +61,34 @@ namespace Cryville.Common.Network {
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class HttpResponseChunkedStream : HttpResponseStream {
|
||||
internal sealed class Http11ResponseChunkedStream : Http11ResponseStream {
|
||||
readonly BinaryReader _reader;
|
||||
byte[] _chunk = null;
|
||||
int _pos = 0;
|
||||
internal HttpResponseChunkedStream(BinaryReader reader) {
|
||||
internal Http11ResponseChunkedStream(BinaryReader reader) {
|
||||
_reader = reader;
|
||||
ReadChunk();
|
||||
}
|
||||
public void ReadChunk() {
|
||||
if (_chunk != null && _chunk.Length == 0) return;
|
||||
string[] chunkHeader = HttpResponse.ReadLine(_reader).Split(';');
|
||||
// int chunkSize = Array.IndexOf(LEN, chunkHeader[0].ToLower()[0]);
|
||||
int chunkSize = int.Parse(chunkHeader[0], NumberStyles.HexNumber);
|
||||
if (chunkSize == -1)
|
||||
string[] chunkHeader = Http11Response.ReadLine(_reader).Split(';');
|
||||
int chunkSize;
|
||||
if (!int.TryParse(chunkHeader[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out chunkSize))
|
||||
throw new IOException("Corrupted chunk received");
|
||||
if (chunkSize == 0) {
|
||||
_chunk = new byte[0];
|
||||
// TODO TE Header, now just discard
|
||||
var headers = new Dictionary<string, string>();
|
||||
while (HttpResponse.ParseHeader(_reader, headers)) ;
|
||||
while (Http11Response.ParseHeader(_reader, headers)) ;
|
||||
return;
|
||||
}
|
||||
_chunk = new byte[chunkSize];
|
||||
int recv = 0;
|
||||
while (recv < chunkSize) {
|
||||
recv += _reader.Read(_chunk, recv, chunkSize - recv);
|
||||
Logger.Log("main", 0, "Network", "Message chunk received: {0}/{1}", recv, chunkSize);
|
||||
}
|
||||
_pos = 0;
|
||||
if (HttpResponse.ReadLine(_reader) != "")
|
||||
if (Http11Response.ReadLine(_reader) != "")
|
||||
throw new IOException("Corrupted chunk received");
|
||||
}
|
||||
public override int Read(byte[] buffer, int offset, int count) {
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df66519fa93e1b94ea5bb1702cc91b3f
|
||||
guid: 49a8d5b9869e5bb42bafbe71f84fecc5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Cryville.Common.Network {
|
||||
public class HttpsClient : HttpClient {
|
||||
namespace Cryville.Common.Network.Http11 {
|
||||
public class Https11Client : Http11Client {
|
||||
readonly TlsClient _tlsClient;
|
||||
|
||||
protected override Stream Stream {
|
||||
@@ -16,7 +16,7 @@ namespace Cryville.Common.Network {
|
||||
}
|
||||
}
|
||||
|
||||
public HttpsClient(Uri baseUri) : base(baseUri, 443) {
|
||||
public Https11Client(Uri baseUri) : base(baseUri, 443) {
|
||||
_tlsClient = new TlsClient(RawTcpStream, baseUri.Host);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b7b45ff20c33ac47b476371673b037c
|
||||
guid: c5c233e6228ce204fa1a9724c48ac8fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ea931bf5488011468f3d1243a038874
|
||||
timeCreated: 1622589817
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07e8215a93e3eb1418685009f0c58dcd
|
||||
timeCreated: 1622596274
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f191de447a708da4f9d230e6545ce0a6
|
||||
timeCreated: 1635470462
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b35290e0e147a342acc29a20c8fceaf
|
||||
timeCreated: 1622503538
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -2,6 +2,7 @@ using Org.BouncyCastle.Security;
|
||||
using Org.BouncyCastle.Tls;
|
||||
using Org.BouncyCastle.Tls.Crypto;
|
||||
using Org.BouncyCastle.Tls.Crypto.Impl.BC;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -9,7 +10,7 @@ using System.Text;
|
||||
using BcTlsClient = Org.BouncyCastle.Tls.TlsClient;
|
||||
|
||||
namespace Cryville.Common.Network {
|
||||
public class TlsClient {
|
||||
public class TlsClient : IDisposable {
|
||||
readonly TlsClientProtocol _protocol;
|
||||
readonly BcTlsClient _tlsClient;
|
||||
public Stream Stream { get; private set; }
|
||||
@@ -27,6 +28,17 @@ namespace Cryville.Common.Network {
|
||||
_protocol.Close();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public virtual void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private class InternalTlsClient : DefaultTlsClient {
|
||||
readonly string _host;
|
||||
|
||||
@@ -71,20 +83,6 @@ namespace Cryville.Common.Network {
|
||||
public override TlsAuthentication GetAuthentication() {
|
||||
return new NullTlsAuthentication();
|
||||
}
|
||||
|
||||
public override void NotifyAlertReceived(short alertLevel, short alertDescription) {
|
||||
Logger.Log("main", 0, "Network/TLS", "TLS Alert {0} {1}", alertLevel, alertDescription);
|
||||
}
|
||||
|
||||
public override void NotifyServerVersion(ProtocolVersion serverVersion) {
|
||||
base.NotifyServerVersion(serverVersion);
|
||||
Logger.Log("main", 0, "Network/TLS", "NotifyServerVersion {0}", serverVersion);
|
||||
}
|
||||
|
||||
public override void NotifySelectedCipherSuite(int selectedCipherSuite) {
|
||||
base.NotifySelectedCipherSuite(selectedCipherSuite);
|
||||
Logger.Log("main", 0, "Network/TLS", "NotifySelectedCipherSuite {0}", selectedCipherSuite);
|
||||
}
|
||||
}
|
||||
|
||||
private class NullTlsAuthentication : TlsAuthentication {
|
||||
|
@@ -17,7 +17,6 @@ namespace Cryville.Common.Pdt {
|
||||
readonly StackFrame[] _stack = new StackFrame[256];
|
||||
readonly byte[] _mem = new byte[0x100000];
|
||||
bool _revokepttconst;
|
||||
LinkedListNode<PdtInstruction> _ip;
|
||||
/// <summary>
|
||||
/// Evaluates an expression and passes the result to a target operator.
|
||||
/// </summary>
|
||||
@@ -25,25 +24,23 @@ namespace Cryville.Common.Pdt {
|
||||
/// <param name="exp">The expression to evaluate.</param>
|
||||
/// <returns>Whether the evaluaton succeeded.</returns>
|
||||
public bool Evaluate(PdtOperator target, PdtExpression exp) {
|
||||
_framecount = 0;
|
||||
_goffset = 0;
|
||||
_revokepttconst = false;
|
||||
for (_ip = exp.Instructions.First; _ip != null; _ip = _ip.Next)
|
||||
_ip.Value.Execute(this);
|
||||
if (exp.IsPotentialConstant) {
|
||||
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
|
||||
var prevFrameCount = _framecount;
|
||||
try {
|
||||
_revokepttconst = false;
|
||||
for (var ip = exp.Instructions.First; ip != null; ip = ip.Next)
|
||||
ip.Value.Execute(this, ref ip);
|
||||
if (exp.IsPotentialConstant) {
|
||||
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
|
||||
}
|
||||
var ret = Operate(target, _framecount - prevFrameCount, true);
|
||||
return ret;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new EvaluationFailureException(exp, ex);
|
||||
}
|
||||
finally {
|
||||
for (var i = prevFrameCount; i < _framecount; i++) DiscardStack();
|
||||
}
|
||||
return Operate(target, _framecount, true);
|
||||
}
|
||||
/// <summary>
|
||||
/// Patches an expression with a lefthand variable and a compound operator.
|
||||
/// </summary>
|
||||
/// <param name="target">The name of the lefthand variable.</param>
|
||||
/// <param name="op">The name of the compound operator.</param>
|
||||
/// <param name="exp">The expression.</param>
|
||||
public void PatchCompound(int target, int op, PdtExpression exp) {
|
||||
exp.Instructions.AddFirst(new PdtInstruction.PushVariable(target));
|
||||
exp.Instructions.AddLast(new PdtInstruction.Operate(op, 2));
|
||||
}
|
||||
/// <summary>
|
||||
/// Optimizes an expression by merging its instructions.
|
||||
@@ -55,14 +52,14 @@ namespace Cryville.Common.Pdt {
|
||||
List<PdtInstruction.Collapse> ct;
|
||||
var cols = new Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>>();
|
||||
var il = exp.Instructions;
|
||||
_ip = il.First;
|
||||
while (_ip != null) {
|
||||
var ip = il.First;
|
||||
while (ip != null) {
|
||||
bool nextFlag = false;
|
||||
var i = _ip.Value;
|
||||
var i = ip.Value;
|
||||
if (i is PdtInstruction.Operate) {
|
||||
int fc0 = _framecount;
|
||||
int fc1 = ((PdtInstruction.Operate)i).Signature.ParamCount;
|
||||
try { i.Execute(this); } catch (Exception) { }
|
||||
try { i.Execute(this, ref ip); } catch (Exception) { }
|
||||
if (fc0 - _framecount == fc1) {
|
||||
unsafe {
|
||||
fixed (StackFrame* frame = &_stack[_framecount++]) {
|
||||
@@ -74,36 +71,38 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
else {
|
||||
var frame = _stack[_framecount - 1];
|
||||
ReplaceIP(il, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length), cols);
|
||||
for (var j = 0; j < fc1; j++) il.Remove(_ip.Previous);
|
||||
if (frame.Type != PdtInternalType.Error) {
|
||||
ReplaceIP(il, ref ip, 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 = _ip;
|
||||
i.Execute(this);
|
||||
var pins = ip;
|
||||
i.Execute(this, ref ip);
|
||||
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;
|
||||
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 {
|
||||
_ip = pins.Previous;
|
||||
while (_ip.Next != t.Target) il.Remove(_ip.Next);
|
||||
il.Remove(_ip.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 = _ip;
|
||||
foreach (var u in ct) u.Target = ip;
|
||||
cols.Remove(t.Target);
|
||||
cols.Add(_ip, ct);
|
||||
cols.Add(ip, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,14 +112,14 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
else if (i is PdtInstruction.PushVariable) {
|
||||
i.Execute(this);
|
||||
i.Execute(this, ref ip);
|
||||
var frame = _stack[_framecount - 1];
|
||||
if (frame.Type != PdtInternalType.Undefined && frame.Type != PdtInternalType.Error) {
|
||||
ReplaceIP(il, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length), cols);
|
||||
ReplaceIP(il, ref ip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length), cols);
|
||||
}
|
||||
}
|
||||
else i.Execute(this);
|
||||
if (_ip != null && cols.TryGetValue(_ip, out ct)) {
|
||||
else i.Execute(this, ref ip);
|
||||
if (ip != null && cols.TryGetValue(ip, out ct)) {
|
||||
unsafe {
|
||||
fixed (StackFrame* frame = &_stack[_framecount - 1]) {
|
||||
frame->Type = PdtInternalType.Error;
|
||||
@@ -129,26 +128,23 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!nextFlag) _ip = _ip.Next;
|
||||
if (!nextFlag) ip = ip.Next;
|
||||
}
|
||||
exp.IsConstant = true;
|
||||
exp.IsPotentialConstant = true;
|
||||
for (var ins = il.First; ins != null; ins = ins.Next) {
|
||||
if (!(ins.Value is PdtInstruction.PushConstant)) {
|
||||
exp.IsConstant = false;
|
||||
}
|
||||
else if (!(ins.Value is PdtInstruction.PushVariable)) {
|
||||
exp.IsPotentialConstant = false;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void ReplaceIP(LinkedList<PdtInstruction> il, PdtInstruction ins, Dictionary<LinkedListNode<PdtInstruction>, List<PdtInstruction.Collapse>> cols) {
|
||||
void ReplaceIP(LinkedList<PdtInstruction> il, ref LinkedListNode<PdtInstruction> ip, 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);
|
||||
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.
|
||||
@@ -207,8 +203,8 @@ namespace Cryville.Common.Pdt {
|
||||
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 };
|
||||
_framecount -= pc - i - 1;
|
||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
|
||||
return false;
|
||||
}
|
||||
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
||||
@@ -218,17 +214,19 @@ namespace Cryville.Common.Pdt {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
internal unsafe void Collapse(int name, LinkedListNode<PdtInstruction> target) {
|
||||
internal unsafe void Collapse(int name, ref LinkedListNode<PdtInstruction> self, LinkedListNode<PdtInstruction> target) {
|
||||
fixed (byte* pmem = _mem) {
|
||||
var frame = _stack[--_framecount];
|
||||
_goffset -= frame.Length;
|
||||
if (frame.Type == PdtInternalType.Error) {
|
||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
|
||||
_ip = target;
|
||||
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
|
||||
self = target;
|
||||
return;
|
||||
}
|
||||
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
|
||||
_framecount++;
|
||||
_ip = target;
|
||||
_goffset += frame.Length;
|
||||
self = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,5 +263,16 @@ namespace Cryville.Common.Pdt {
|
||||
public EvaluationFailureException(string message, Exception innerException) : base(message, innerException) { }
|
||||
/// <inheritdoc />
|
||||
protected EvaluationFailureException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="EvaluationFailureException" /> class with the failing expression.
|
||||
/// </summary>
|
||||
/// <param name="exp">The failing expression.</param>
|
||||
public EvaluationFailureException(PdtExpression exp) : base("Evaluation failed for the expression: " + exp.ToString()) { }
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="EvaluationFailureException" /> class with the failing expression and the inner exception.
|
||||
/// </summary>
|
||||
/// <param name="exp">The failing expression.</param>
|
||||
/// <param name="innerException">The inner exception.</param>
|
||||
public EvaluationFailureException(PdtExpression exp, Exception innerException) : base("Evaluation failed for the expression: " + exp.ToString(), innerException) { }
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,18 @@ namespace Cryville.Common.Pdt {
|
||||
/// PDT expression.
|
||||
/// </summary>
|
||||
public class PdtExpression {
|
||||
/// <summary>
|
||||
/// The empty expression.
|
||||
/// </summary>
|
||||
public static readonly PdtExpression Empty;
|
||||
static PdtExpression() {
|
||||
var ins = new LinkedList<PdtInstruction>();
|
||||
ins.AddLast(new PdtInstruction.PushConstant(
|
||||
PdtInternalType.Number, BitConverter.GetBytes(1f)
|
||||
));
|
||||
Empty = new PdtExpression(ins);
|
||||
}
|
||||
|
||||
internal LinkedList<PdtInstruction> Instructions;
|
||||
/// <summary>
|
||||
/// Whether the value of this expression is constant.
|
||||
@@ -27,9 +39,19 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
return r;
|
||||
}
|
||||
/// <summary>
|
||||
/// Patches an expression with a lefthand variable and a compound operator.
|
||||
/// </summary>
|
||||
/// <param name="target">The name of the lefthand variable.</param>
|
||||
/// <param name="op">The name of the compound operator.</param>
|
||||
/// <param name="exp">The expression.</param>
|
||||
public static void PatchCompound(int target, int op, PdtExpression exp) {
|
||||
exp.Instructions.AddFirst(new PdtInstruction.PushVariable(target));
|
||||
exp.Instructions.AddLast(new PdtInstruction.Operate(op, 2));
|
||||
}
|
||||
}
|
||||
internal abstract class PdtInstruction {
|
||||
internal abstract void Execute(PdtEvaluatorBase etor);
|
||||
internal abstract void Execute(PdtEvaluatorBase etor, ref LinkedListNode<PdtInstruction> self);
|
||||
public class PushConstant : PdtInstruction {
|
||||
public int Type { get; private set; }
|
||||
public byte[] Value { get; private set; }
|
||||
@@ -42,7 +64,7 @@ namespace Cryville.Common.Pdt {
|
||||
Value = new byte[len];
|
||||
Array.Copy(buffer, offset, Value, 0, len);
|
||||
}
|
||||
internal override void Execute(PdtEvaluatorBase etor) {
|
||||
internal override void Execute(PdtEvaluatorBase etor, ref LinkedListNode<PdtInstruction> self) {
|
||||
etor.PushConstant(Type, Value);
|
||||
}
|
||||
public override string ToString() {
|
||||
@@ -53,12 +75,12 @@ namespace Cryville.Common.Pdt {
|
||||
public int Name { get; private set; }
|
||||
public bool Forced { get; private set; }
|
||||
public PushVariable(int name, bool forced = false) { Name = name; Forced = forced; }
|
||||
public PushVariable(string name, bool forced = false) : this(IdentifierManager.SharedInstance.Request(name)) { Forced = forced; }
|
||||
internal override void Execute(PdtEvaluatorBase etor) {
|
||||
public PushVariable(string name, bool forced = false) : this(IdentifierManager.Shared.Request(name)) { Forced = forced; }
|
||||
internal override void Execute(PdtEvaluatorBase etor, ref LinkedListNode<PdtInstruction> self) {
|
||||
etor.PushVariable(Name, Forced);
|
||||
}
|
||||
public override string ToString() {
|
||||
return string.Format(Forced ? "pushv ?{0}" : "pushv {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
||||
return string.Format(Forced ? "pushv ?{0}" : "pushv {0}", IdentifierManager.Shared.Retrieve(Name));
|
||||
}
|
||||
}
|
||||
public class Operate : PdtInstruction {
|
||||
@@ -69,7 +91,7 @@ namespace Cryville.Common.Pdt {
|
||||
public Operate(string name, int paramCount) {
|
||||
Signature = new PdtOperatorSignature(name, paramCount);
|
||||
}
|
||||
internal override void Execute(PdtEvaluatorBase etor) {
|
||||
internal override void Execute(PdtEvaluatorBase etor, ref LinkedListNode<PdtInstruction> self) {
|
||||
etor.Operate(Signature);
|
||||
}
|
||||
public override string ToString() {
|
||||
@@ -80,14 +102,14 @@ namespace Cryville.Common.Pdt {
|
||||
public int Name { get; private set; }
|
||||
public LinkedListNode<PdtInstruction> Target { get; internal set; }
|
||||
public Collapse(string name, LinkedListNode<PdtInstruction> target) {
|
||||
Name = IdentifierManager.SharedInstance.Request(name);
|
||||
Name = IdentifierManager.Shared.Request(name);
|
||||
Target = target;
|
||||
}
|
||||
internal override void Execute(PdtEvaluatorBase etor) {
|
||||
etor.Collapse(Name, Target);
|
||||
internal override void Execute(PdtEvaluatorBase etor, ref LinkedListNode<PdtInstruction> self) {
|
||||
etor.Collapse(Name, ref self, Target);
|
||||
}
|
||||
public override string ToString() {
|
||||
return string.Format("col {0}{{{1}}}", IdentifierManager.SharedInstance.Retrieve(Name), Target.Value);
|
||||
return string.Format("col {0}{{{1}}}", IdentifierManager.Shared.Retrieve(Name), Target.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,15 +137,6 @@ namespace Cryville.Common.Pdt {
|
||||
{ '$', -1 },
|
||||
};
|
||||
|
||||
static readonly PdtExpression _emptyexp;
|
||||
static PdtInterpreter() {
|
||||
var ins = new LinkedList<PdtInstruction>();
|
||||
ins.AddLast(new PdtInstruction.PushConstant(
|
||||
PdtInternalType.Number, BitConverter.GetBytes(1f)
|
||||
));
|
||||
_emptyexp = new PdtExpression(ins);
|
||||
}
|
||||
|
||||
PdtExpToken GetToken() {
|
||||
ws();
|
||||
var result = new PdtExpToken {
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using Cryville.Common.Collections;
|
||||
using Cryville.Common.Logging;
|
||||
using Cryville.Common.Reflection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -245,7 +247,7 @@ namespace Cryville.Common.Pdt {
|
||||
break;
|
||||
case ':':
|
||||
case ';':
|
||||
var exp = c == ';' ? _emptyexp : GetExp();
|
||||
var exp = c == ';' ? PdtExpression.Empty : GetExp();
|
||||
InterpretObjectInternal<PropertyListAttribute>(pcflag, type, pkey, result, type => _binder.ChangeType(exp, type, null));
|
||||
break;
|
||||
default:
|
||||
@@ -266,14 +268,17 @@ namespace Cryville.Common.Pdt {
|
||||
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 (pkey is string) prop = FieldLikeHelper.GetMember(type, (string)pkey);
|
||||
if (prop == null) {
|
||||
prop = FieldLikeHelper.FindMemberWithAttribute<T>(type);
|
||||
flag = true;
|
||||
}
|
||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||
Type ptype = ReflectionHelper.GetMemberType(prop);
|
||||
Type ptype = FieldLikeHelper.GetMemberType(prop);
|
||||
if (flag) {
|
||||
var origCollection = ReflectionHelper.GetValue(prop, result);
|
||||
var origCollection = FieldLikeHelper.GetValue(prop, result);
|
||||
if (origCollection == null) {
|
||||
ReflectionHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
|
||||
FieldLikeHelper.SetValue(prop, result, origCollection = Activator.CreateInstance(ptype));
|
||||
}
|
||||
using (var collection = new PairCollection(origCollection)) {
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
@@ -283,7 +288,7 @@ namespace Cryville.Common.Pdt {
|
||||
collection.Add(key, value);
|
||||
}
|
||||
}
|
||||
else ReflectionHelper.SetValue(prop, result, vfunc(ptype), _binder);
|
||||
else FieldLikeHelper.SetValue(prop, result, vfunc(ptype), _binder);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@@ -91,7 +91,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// <param name="name">The name of the operator.</param>
|
||||
/// <param name="paramCount">The parameter count.</param>
|
||||
public PdtOperatorSignature(string name, int paramCount)
|
||||
: this(IdentifierManager.SharedInstance.Request(name), paramCount) { }
|
||||
: this(IdentifierManager.Shared.Request(name), paramCount) { }
|
||||
/// <summary>
|
||||
/// Creates an operator signature.
|
||||
/// </summary>
|
||||
@@ -113,7 +113,7 @@ namespace Cryville.Common.Pdt {
|
||||
return _hash;
|
||||
}
|
||||
public override string ToString() {
|
||||
return string.Format("{0}({1})", IdentifierManager.SharedInstance.Retrieve(Name), ParamCount);
|
||||
return string.Format("{0}({1})", IdentifierManager.Shared.Retrieve(Name), ParamCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,185 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Common {
|
||||
/// <summary>
|
||||
/// Provides a set of <see langword="static" /> methods for refletion.
|
||||
/// </summary>
|
||||
public static class ReflectionHelper {
|
||||
static readonly object[] emptyObjectArray = {};
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find a member with the specified attribute type in a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The attribute type.</typeparam>
|
||||
/// <param name="t">The type containing the member with the specified attribute type.</param>
|
||||
/// <param name="mi">The member.</param>
|
||||
/// <returns>Whether the member is found.</returns>
|
||||
public static bool TryFindMemberWithAttribute<T>(Type t, out MemberInfo mi) where T : Attribute {
|
||||
try {
|
||||
mi = FindMemberWithAttribute<T>(t);
|
||||
return true;
|
||||
}
|
||||
catch (MissingMemberException) {
|
||||
mi = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Finds a member with the specified attribute type in a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The attribute type.</typeparam>
|
||||
/// <param name="type">The type containing the member with the specified attribute type.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="MissingMemberException">The member is not found or multiple members are found.</exception>
|
||||
public static MemberInfo FindMemberWithAttribute<T>(Type type) where T : Attribute {
|
||||
var mil = type.FindMembers(
|
||||
MemberTypes.Field | MemberTypes.Property,
|
||||
BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static,
|
||||
(m, o) => m.GetCustomAttributes(typeof(T), true).Length != 0,
|
||||
null
|
||||
);
|
||||
if (mil.Length != 1)
|
||||
throw new MissingMemberException(type.Name, typeof(T).Name);
|
||||
return mil[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether a type is a <see cref="Dictionary{TKey, TValue}" />.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>Whether the type is a <see cref="Dictionary{TKey, TValue}" />.</returns>
|
||||
public static bool IsGenericDictionary(Type type) {
|
||||
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets 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.</returns>
|
||||
/// <exception cref="MissingMemberException">The member is not found or multiple members are found.</exception>
|
||||
public static MemberInfo GetMember(Type type, string name) {
|
||||
var mil = type.GetMember(
|
||||
name,
|
||||
MemberTypes.Field | MemberTypes.Property,
|
||||
BindingFlags.Public | BindingFlags.Instance
|
||||
);
|
||||
if (mil.Length != 1)
|
||||
throw new MissingMemberException(type.Name, name);
|
||||
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>
|
||||
/// <param name="mi">The member.</param>
|
||||
/// <returns>The type of the member.</returns>
|
||||
/// <exception cref="ArgumentException"><paramref name="mi" /> is not a field or a property.</exception>
|
||||
public static Type GetMemberType(MemberInfo mi) {
|
||||
if (mi is FieldInfo)
|
||||
return ((FieldInfo)mi).FieldType;
|
||||
if (mi is PropertyInfo)
|
||||
return ((PropertyInfo)mi).PropertyType;
|
||||
else
|
||||
throw new ArgumentException("Member is not field or property.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of a member of an object.
|
||||
/// </summary>
|
||||
/// <param name="mi">The member.</param>
|
||||
/// <param name="obj">The object.</param>
|
||||
/// <returns>The value.</returns>
|
||||
/// <exception cref="ArgumentException"><paramref name="mi" /> is not a field or a property.</exception>
|
||||
public static object GetValue(MemberInfo mi, object obj) {
|
||||
if (mi is FieldInfo)
|
||||
return ((FieldInfo)mi).GetValue(obj);
|
||||
else if (mi is PropertyInfo)
|
||||
return ((PropertyInfo)mi).GetValue(obj, new object[]{});
|
||||
else
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of a member of an object.
|
||||
/// </summary>
|
||||
/// <param name="mi">The member.</param>
|
||||
/// <param name="obj">The object.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="binder">An optional binder to convert the value.</param>
|
||||
/// <exception cref="ArgumentException"><paramref name="mi" /> is not a field or a property.</exception>
|
||||
public static void SetValue(MemberInfo mi, object obj, object value, Binder binder = null) {
|
||||
if (mi is FieldInfo)
|
||||
((FieldInfo)mi).SetValue(obj, value, BindingFlags.Default, binder, null);
|
||||
else if (mi is PropertyInfo)
|
||||
((PropertyInfo)mi).SetValue(obj, value, BindingFlags.Default, binder, emptyObjectArray, null);
|
||||
else
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the subclasses of a type in the current app domain.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type.</typeparam>
|
||||
/// <returns>An array containing all the subclasses of the type in the current app domain.</returns>
|
||||
public static Type[] GetSubclassesOf<T>() where T : class {
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
IEnumerable<Type> r = Enumerable.Empty<Type>();
|
||||
foreach (var a in assemblies)
|
||||
r = r.Concat(a.GetTypes().Where(
|
||||
t => t.IsClass
|
||||
&& !t.IsAbstract
|
||||
&& t.IsSubclassOf(typeof(T))
|
||||
));
|
||||
return r.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a simple name of a type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>A simple name of the class.</returns>
|
||||
public static string GetSimpleName(Type type) {
|
||||
string result = type.Name;
|
||||
var typeargs = type.GetGenericArguments();
|
||||
if (typeargs.Length > 0) {
|
||||
result = string.Format("{0}[{1}]", result, string.Join(",", from a in typeargs select GetSimpleName(a)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the namespace qualified name of a type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>The namespace qualified name of the class.</returns>
|
||||
public static string GetNamespaceQualifiedName(Type type) {
|
||||
string result = type.Namespace + "." + type.Name;
|
||||
var typeargs = type.GetGenericArguments();
|
||||
if (typeargs.Length > 0) {
|
||||
result = string.Format("{0}[{1}]", result, string.Join(",", from a in typeargs select GetNamespaceQualifiedName(a)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16857d076fc8d534788424e6c6d180e0
|
||||
timeCreated: 1608801352
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7548d5a078795b04b8c54524389ba0fe
|
||||
folderAsset: yes
|
||||
timeCreated: 1611035780
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,109 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public delegate void InputEventDelegate(InputIdentifier id, InputVector vec);
|
||||
public abstract class InputHandler : IDisposable {
|
||||
InputEventDelegate m_onInput;
|
||||
public event InputEventDelegate OnInput {
|
||||
add {
|
||||
if (m_onInput == null) Activate();
|
||||
m_onInput -= value;
|
||||
m_onInput += value;
|
||||
}
|
||||
remove {
|
||||
if (m_onInput == null) return;
|
||||
m_onInput -= value;
|
||||
if (m_onInput == null) Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
~InputHandler() {
|
||||
Dispose(false);
|
||||
}
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected abstract void Activate();
|
||||
protected abstract void Deactivate();
|
||||
public abstract void Dispose(bool disposing);
|
||||
public abstract bool IsNullable(int type);
|
||||
public abstract byte GetDimension(int type);
|
||||
public abstract string GetTypeName(int type);
|
||||
public abstract double GetCurrentTimestamp();
|
||||
protected void Feed(int type, int id, InputVector vec) {
|
||||
var del = m_onInput;
|
||||
if (del != null) del(new InputIdentifier { Source = new InputSource { Handler = this, Type = type }, Id = id }, vec);
|
||||
}
|
||||
}
|
||||
|
||||
public struct InputSource : IEquatable<InputSource> {
|
||||
public InputHandler Handler { get; set; }
|
||||
public int Type { get; set; }
|
||||
public override bool Equals(object obj) {
|
||||
if (obj == null || !(obj is InputSource)) return false;
|
||||
return Equals((InputSource)obj);
|
||||
}
|
||||
public bool Equals(InputSource other) {
|
||||
return Handler == other.Handler && Type == other.Type;
|
||||
}
|
||||
public override int GetHashCode() {
|
||||
return Handler.GetHashCode() ^ Type;
|
||||
}
|
||||
public override string ToString() {
|
||||
return string.Format("{0}:{1}", ReflectionHelper.GetSimpleName(Handler.GetType()), Handler.GetTypeName(Type));
|
||||
}
|
||||
public static bool operator ==(InputSource lhs, InputSource rhs) {
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
public static bool operator !=(InputSource lhs, InputSource rhs) {
|
||||
return !lhs.Equals(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
public struct InputIdentifier : IEquatable<InputIdentifier> {
|
||||
public InputSource Source { get; set; }
|
||||
public int Id { get; set; }
|
||||
public override bool Equals(object obj) {
|
||||
if (obj == null || !(obj is InputIdentifier)) return false;
|
||||
return Equals((InputIdentifier)obj);
|
||||
}
|
||||
public bool Equals(InputIdentifier other) {
|
||||
return Source == other.Source && Id == other.Id;
|
||||
}
|
||||
public override int GetHashCode() {
|
||||
return Source.GetHashCode() ^ ((Id << 16) | (Id >> 16));
|
||||
}
|
||||
public override string ToString() {
|
||||
return string.Format("{0},{1}", Source, Id);
|
||||
}
|
||||
public static bool operator ==(InputIdentifier lhs, InputIdentifier rhs) {
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
public static bool operator !=(InputIdentifier lhs, InputIdentifier rhs) {
|
||||
return !lhs.Equals(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
public struct InputVector {
|
||||
public double Time { get; set; }
|
||||
public bool IsNull { get; set; }
|
||||
public Vector3 Vector { get; set; }
|
||||
public InputVector(double time) {
|
||||
Time = time;
|
||||
IsNull = true;
|
||||
Vector = default(Vector3);
|
||||
}
|
||||
public InputVector(double time, Vector3 vector) {
|
||||
Time = time;
|
||||
IsNull = false;
|
||||
Vector = vector;
|
||||
}
|
||||
public override string ToString() {
|
||||
if (IsNull) return string.Format("null@{0}", Time);
|
||||
else return string.Format("{0}@{1}", Vector.ToString("G9"), Time);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 139cf0675329c9d46b902249fecdb500
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public class InputManager {
|
||||
static readonly HashSet<Type> HandlerRegistries = new HashSet<Type> {
|
||||
typeof(WindowsPointerHandler),
|
||||
typeof(UnityKeyHandler<UnityKeyboardReceiver>),
|
||||
typeof(UnityKeyHandler<UnityMouseButtonReceiver>),
|
||||
typeof(UnityMouseHandler),
|
||||
typeof(UnityTouchHandler),
|
||||
};
|
||||
readonly HashSet<InputHandler> _handlers = new HashSet<InputHandler>();
|
||||
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
||||
public InputManager() {
|
||||
foreach (var t in HandlerRegistries) {
|
||||
try {
|
||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||
var h = (InputHandler)Activator.CreateInstance(t);
|
||||
_typemap.Add(t, h);
|
||||
_handlers.Add(h);
|
||||
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
|
||||
}
|
||||
catch (TargetInvocationException ex) {
|
||||
Logger.Log("main", 1, "Input", "Cannot initialize {0}: {1}", ReflectionHelper.GetSimpleName(t), ex.InnerException.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
public InputHandler GetHandler(string name) {
|
||||
return _typemap[Type.GetType(name)];
|
||||
}
|
||||
public void EnumerateHandlers(Action<InputHandler> cb) {
|
||||
foreach (var h in _handlers) cb(h);
|
||||
}
|
||||
}
|
||||
|
||||
public struct InputEvent {
|
||||
public InputIdentifier Id { get; set; }
|
||||
public InputVector From { get; set; }
|
||||
public InputVector To { get; set; }
|
||||
public override string ToString() {
|
||||
return string.Format("[{0}] {1} -> {2}", Id, From, To);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aaf7daeaf7afb3146b3eea2a07f88055
|
||||
timeCreated: 1611035810
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,528 +0,0 @@
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public enum WindowMessages : uint {
|
||||
WM_NULL = 0x0000,
|
||||
WM_CREATE = 0x0001,
|
||||
WM_DESTROY = 0x0002,
|
||||
WM_MOVE = 0x0003,
|
||||
WM_SIZE = 0x0005,
|
||||
|
||||
WM_ACTIVATE = 0x0006,
|
||||
/*
|
||||
* WM_ACTIVATE state values
|
||||
*/
|
||||
WA_INACTIVE = 0,
|
||||
WA_ACTIVE = 1,
|
||||
WA_CLICKACTIVE = 2,
|
||||
|
||||
WM_SETFOCUS = 0x0007,
|
||||
WM_KILLFOCUS = 0x0008,
|
||||
WM_ENABLE = 0x000A,
|
||||
WM_SETREDRAW = 0x000B,
|
||||
WM_SETTEXT = 0x000C,
|
||||
WM_GETTEXT = 0x000D,
|
||||
WM_GETTEXTLENGTH = 0x000E,
|
||||
WM_PAINT = 0x000F,
|
||||
WM_CLOSE = 0x0010,
|
||||
//#ifndef _WIN32_WCE
|
||||
WM_QUERYENDSESSION = 0x0011,
|
||||
WM_QUERYOPEN = 0x0013,
|
||||
WM_ENDSESSION = 0x0016,
|
||||
//#endif
|
||||
WM_QUIT = 0x0012,
|
||||
WM_ERASEBKGND = 0x0014,
|
||||
WM_SYSCOLORCHANGE = 0x0015,
|
||||
WM_SHOWWINDOW = 0x0018,
|
||||
WM_WININICHANGE = 0x001A,
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_SETTINGCHANGE = WM_WININICHANGE,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
|
||||
WM_DEVMODECHANGE = 0x001B,
|
||||
WM_ACTIVATEAPP = 0x001C,
|
||||
WM_FONTCHANGE = 0x001D,
|
||||
WM_TIMECHANGE = 0x001E,
|
||||
WM_CANCELMODE = 0x001F,
|
||||
WM_SETCURSOR = 0x0020,
|
||||
WM_MOUSEACTIVATE = 0x0021,
|
||||
WM_CHILDACTIVATE = 0x0022,
|
||||
WM_QUEUESYNC = 0x0023,
|
||||
|
||||
WM_GETMINMAXINFO = 0x0024,
|
||||
WM_PAINTICON = 0x0026,
|
||||
WM_ICONERASEBKGND = 0x0027,
|
||||
WM_NEXTDLGCTL = 0x0028,
|
||||
WM_SPOOLERSTATUS = 0x002A,
|
||||
WM_DRAWITEM = 0x002B,
|
||||
WM_MEASUREITEM = 0x002C,
|
||||
WM_DELETEITEM = 0x002D,
|
||||
WM_VKEYTOITEM = 0x002E,
|
||||
WM_CHARTOITEM = 0x002F,
|
||||
WM_SETFONT = 0x0030,
|
||||
WM_GETFONT = 0x0031,
|
||||
WM_SETHOTKEY = 0x0032,
|
||||
WM_GETHOTKEY = 0x0033,
|
||||
WM_QUERYDRAGICON = 0x0037,
|
||||
WM_COMPAREITEM = 0x0039,
|
||||
//#if(WINVER >= 0x0500)
|
||||
//#ifndef _WIN32_WCE
|
||||
WM_GETOBJECT = 0x003D,
|
||||
//#endif
|
||||
//#endif /* WINVER >= 0x0500 */
|
||||
WM_COMPACTING = 0x0041,
|
||||
WM_COMMNOTIFY = 0x0044, /* no longer suported */
|
||||
WM_WINDOWPOSCHANGING = 0x0046,
|
||||
WM_WINDOWPOSCHANGED = 0x0047,
|
||||
|
||||
WM_POWER = 0x0048,
|
||||
/*
|
||||
* wParam for WM_POWER window message and DRV_POWER driver notification
|
||||
*/
|
||||
/*PWR_OK = 1,
|
||||
PWR_FAIL = (-1),
|
||||
PWR_SUSPENDREQUEST = 1,
|
||||
PWR_SUSPENDRESUME = 2,
|
||||
PWR_CRITICALRESUME = 3,*/
|
||||
|
||||
WM_COPYDATA = 0x004A,
|
||||
WM_CANCELJOURNAL = 0x004B,
|
||||
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_NOTIFY = 0x004E,
|
||||
WM_INPUTLANGCHANGEREQUEST = 0x0050,
|
||||
WM_INPUTLANGCHANGE = 0x0051,
|
||||
WM_TCARD = 0x0052,
|
||||
WM_HELP = 0x0053,
|
||||
WM_USERCHANGED = 0x0054,
|
||||
WM_NOTIFYFORMAT = 0x0055,
|
||||
|
||||
NFR_ANSI = 1,
|
||||
NFR_UNICODE = 2,
|
||||
NF_QUERY = 3,
|
||||
NF_REQUERY = 4,
|
||||
|
||||
WM_CONTEXTMENU = 0x007B,
|
||||
WM_STYLECHANGING = 0x007C,
|
||||
WM_STYLECHANGED = 0x007D,
|
||||
WM_DISPLAYCHANGE = 0x007E,
|
||||
WM_GETICON = 0x007F,
|
||||
WM_SETICON = 0x0080,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
WM_NCCREATE = 0x0081,
|
||||
WM_NCDESTROY = 0x0082,
|
||||
WM_NCCALCSIZE = 0x0083,
|
||||
WM_NCHITTEST = 0x0084,
|
||||
WM_NCPAINT = 0x0085,
|
||||
WM_NCACTIVATE = 0x0086,
|
||||
WM_GETDLGCODE = 0x0087,
|
||||
//#ifndef _WIN32_WCE
|
||||
WM_SYNCPAINT = 0x0088,
|
||||
//#endif
|
||||
WM_NCMOUSEMOVE = 0x00A0,
|
||||
WM_NCLBUTTONDOWN = 0x00A1,
|
||||
WM_NCLBUTTONUP = 0x00A2,
|
||||
WM_NCLBUTTONDBLCLK = 0x00A3,
|
||||
WM_NCRBUTTONDOWN = 0x00A4,
|
||||
WM_NCRBUTTONUP = 0x00A5,
|
||||
WM_NCRBUTTONDBLCLK = 0x00A6,
|
||||
WM_NCMBUTTONDOWN = 0x00A7,
|
||||
WM_NCMBUTTONUP = 0x00A8,
|
||||
WM_NCMBUTTONDBLCLK = 0x00A9,
|
||||
|
||||
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0500)
|
||||
WM_NCXBUTTONDOWN = 0x00AB,
|
||||
WM_NCXBUTTONUP = 0x00AC,
|
||||
WM_NCXBUTTONDBLCLK = 0x00AD,
|
||||
//#endif /* _WIN32_WINNT >= 0x0500 */
|
||||
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0501)
|
||||
WM_INPUT_DEVICE_CHANGE = 0x00FE,
|
||||
//#endif /* _WIN32_WINNT >= 0x0501 */
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0501)
|
||||
WM_INPUT = 0x00FF,
|
||||
//#endif /* _WIN32_WINNT >= 0x0501 */
|
||||
|
||||
WM_KEYFIRST = 0x0100,
|
||||
WM_KEYDOWN = 0x0100,
|
||||
WM_KEYUP = 0x0101,
|
||||
WM_CHAR = 0x0102,
|
||||
WM_DEADCHAR = 0x0103,
|
||||
WM_SYSKEYDOWN = 0x0104,
|
||||
WM_SYSKEYUP = 0x0105,
|
||||
WM_SYSCHAR = 0x0106,
|
||||
WM_SYSDEADCHAR = 0x0107,
|
||||
//#if(_WIN32_WINNT >= 0x0501)
|
||||
WM_UNICHAR = 0x0109,
|
||||
WM_KEYLAST = 0x0109,
|
||||
UNICODE_NOCHAR = 0xFFFF,
|
||||
//#else
|
||||
WM_KEYLAST__WIN2000 = 0x0108,
|
||||
//#endif /* _WIN32_WINNT >= 0x0501 */
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_IME_STARTCOMPOSITION = 0x010D,
|
||||
WM_IME_ENDCOMPOSITION = 0x010E,
|
||||
WM_IME_COMPOSITION = 0x010F,
|
||||
WM_IME_KEYLAST = 0x010F,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
WM_INITDIALOG = 0x0110,
|
||||
WM_COMMAND = 0x0111,
|
||||
WM_SYSCOMMAND = 0x0112,
|
||||
WM_TIMER = 0x0113,
|
||||
WM_HSCROLL = 0x0114,
|
||||
WM_VSCROLL = 0x0115,
|
||||
WM_INITMENU = 0x0116,
|
||||
WM_INITMENUPOPUP = 0x0117,
|
||||
//#if(WINVER >= 0x0601)
|
||||
WM_GESTURE = 0x0119,
|
||||
WM_GESTURENOTIFY = 0x011A,
|
||||
//#endif /* WINVER >= 0x0601 */
|
||||
WM_MENUSELECT = 0x011F,
|
||||
WM_MENUCHAR = 0x0120,
|
||||
WM_ENTERIDLE = 0x0121,
|
||||
//#if(WINVER >= 0x0500)
|
||||
//#ifndef _WIN32_WCE
|
||||
WM_MENURBUTTONUP = 0x0122,
|
||||
WM_MENUDRAG = 0x0123,
|
||||
WM_MENUGETOBJECT = 0x0124,
|
||||
WM_UNINITMENUPOPUP = 0x0125,
|
||||
WM_MENUCOMMAND = 0x0126,
|
||||
|
||||
//#ifndef _WIN32_WCE
|
||||
//#if(_WIN32_WINNT >= 0x0500)
|
||||
WM_CHANGEUISTATE = 0x0127,
|
||||
WM_UPDATEUISTATE = 0x0128,
|
||||
WM_QUERYUISTATE = 0x0129,
|
||||
|
||||
/*
|
||||
* LOWORD(wParam) values in WM_*UISTATE*
|
||||
*/
|
||||
UIS_SET = 1,
|
||||
UIS_CLEAR = 2,
|
||||
UIS_INITIALIZE = 3,
|
||||
|
||||
/*
|
||||
* HIWORD(wParam) values in WM_*UISTATE*
|
||||
*/
|
||||
UISF_HIDEFOCUS = 0x1,
|
||||
UISF_HIDEACCEL = 0x2,
|
||||
//#if(_WIN32_WINNT >= 0x0501)
|
||||
UISF_ACTIVE = 0x4,
|
||||
//#endif /* _WIN32_WINNT >= 0x0501 */
|
||||
//#endif /* _WIN32_WINNT >= 0x0500 */
|
||||
//#endif
|
||||
|
||||
//#endif
|
||||
//#endif /* WINVER >= 0x0500 */
|
||||
|
||||
WM_CTLCOLORMSGBOX = 0x0132,
|
||||
WM_CTLCOLOREDIT = 0x0133,
|
||||
WM_CTLCOLORLISTBOX = 0x0134,
|
||||
WM_CTLCOLORBTN = 0x0135,
|
||||
WM_CTLCOLORDLG = 0x0136,
|
||||
WM_CTLCOLORSCROLLBAR = 0x0137,
|
||||
WM_CTLCOLORSTATIC = 0x0138,
|
||||
MN_GETHMENU = 0x01E1,
|
||||
|
||||
WM_MOUSEFIRST = 0x0200,
|
||||
WM_MOUSEMOVE = 0x0200,
|
||||
WM_LBUTTONDOWN = 0x0201,
|
||||
WM_LBUTTONUP = 0x0202,
|
||||
WM_LBUTTONDBLCLK = 0x0203,
|
||||
WM_RBUTTONDOWN = 0x0204,
|
||||
WM_RBUTTONUP = 0x0205,
|
||||
WM_RBUTTONDBLCLK = 0x0206,
|
||||
WM_MBUTTONDOWN = 0x0207,
|
||||
WM_MBUTTONUP = 0x0208,
|
||||
WM_MBUTTONDBLCLK = 0x0209,
|
||||
//#if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
|
||||
WM_MOUSEWHEEL = 0x020A,
|
||||
//#endif
|
||||
//#if (_WIN32_WINNT >= 0x0500)
|
||||
WM_XBUTTONDOWN = 0x020B,
|
||||
WM_XBUTTONUP = 0x020C,
|
||||
WM_XBUTTONDBLCLK = 0x020D,
|
||||
//#endif
|
||||
//#if (_WIN32_WINNT >= 0x0600)
|
||||
WM_MOUSEHWHEEL = 0x020E,
|
||||
//#endif
|
||||
|
||||
//#if (_WIN32_WINNT >= 0x0600)
|
||||
WM_MOUSELAST = 0x020E,
|
||||
//#elif (_WIN32_WINNT >= 0x0500)
|
||||
WM_MOUSELAST__WIN2000 = 0x020D,
|
||||
//#elif (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
|
||||
WM_MOUSELAST__WIN4 = 0x020A,
|
||||
//#else
|
||||
WM_MOUSELAST__WIN3 = 0x0209,
|
||||
//#endif /* (_WIN32_WINNT >= 0x0600) */
|
||||
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0400)
|
||||
/* Value for rolling one detent */
|
||||
WHEEL_DELTA = 120,
|
||||
//GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam))
|
||||
|
||||
/* Setting to scroll one page for SPI_GET/SETWHEELSCROLLLINES */
|
||||
WHEEL_PAGESCROLL = (uint.MaxValue),
|
||||
//#endif /* _WIN32_WINNT >= 0x0400 */
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0500)
|
||||
//GET_KEYSTATE_WPARAM(wParam) (LOWORD(wParam))
|
||||
//GET_NCHITTEST_WPARAM(wParam) ((short)LOWORD(wParam))
|
||||
//GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam))
|
||||
|
||||
/* XButton values are WORD flags */
|
||||
XBUTTON1 = 0x0001,
|
||||
XBUTTON2 = 0x0002,
|
||||
/* Were there to be an XBUTTON3, its value would be 0x0004 */
|
||||
//#endif /* _WIN32_WINNT >= 0x0500 */
|
||||
|
||||
WM_PARENTNOTIFY = 0x0210,
|
||||
WM_ENTERMENULOOP = 0x0211,
|
||||
WM_EXITMENULOOP = 0x0212,
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_NEXTMENU = 0x0213,
|
||||
WM_SIZING = 0x0214,
|
||||
WM_CAPTURECHANGED = 0x0215,
|
||||
WM_MOVING = 0x0216,
|
||||
WM_POWERBROADCAST = 0x0218,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_DEVICECHANGE = 0x0219,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
WM_MDICREATE = 0x0220,
|
||||
WM_MDIDESTROY = 0x0221,
|
||||
WM_MDIACTIVATE = 0x0222,
|
||||
WM_MDIRESTORE = 0x0223,
|
||||
WM_MDINEXT = 0x0224,
|
||||
WM_MDIMAXIMIZE = 0x0225,
|
||||
WM_MDITILE = 0x0226,
|
||||
WM_MDICASCADE = 0x0227,
|
||||
WM_MDIICONARRANGE = 0x0228,
|
||||
WM_MDIGETACTIVE = 0x0229,
|
||||
|
||||
|
||||
WM_MDISETMENU = 0x0230,
|
||||
WM_ENTERSIZEMOVE = 0x0231,
|
||||
WM_EXITSIZEMOVE = 0x0232,
|
||||
WM_DROPFILES = 0x0233,
|
||||
WM_MDIREFRESHMENU = 0x0234,
|
||||
|
||||
//#if(WINVER >= 0x0602)
|
||||
WM_POINTERDEVICECHANGE = 0x238,
|
||||
WM_POINTERDEVICEINRANGE = 0x239,
|
||||
WM_POINTERDEVICEOUTOFRANGE = 0x23A,
|
||||
//#endif /* WINVER >= 0x0602 */
|
||||
|
||||
|
||||
//#if(WINVER >= 0x0601)
|
||||
WM_TOUCH = 0x0240,
|
||||
//#endif /* WINVER >= 0x0601 */
|
||||
|
||||
//#if(WINVER >= 0x0602)
|
||||
WM_NCPOINTERUPDATE = 0x0241,
|
||||
WM_NCPOINTERDOWN = 0x0242,
|
||||
WM_NCPOINTERUP = 0x0243,
|
||||
WM_POINTERUPDATE = 0x0245,
|
||||
WM_POINTERDOWN = 0x0246,
|
||||
WM_POINTERUP = 0x0247,
|
||||
WM_POINTERENTER = 0x0249,
|
||||
WM_POINTERLEAVE = 0x024A,
|
||||
WM_POINTERACTIVATE = 0x024B,
|
||||
WM_POINTERCAPTURECHANGED = 0x024C,
|
||||
WM_TOUCHHITTESTING = 0x024D,
|
||||
WM_POINTERWHEEL = 0x024E,
|
||||
WM_POINTERHWHEEL = 0x024F,
|
||||
DM_POINTERHITTEST = 0x0250,
|
||||
WM_POINTERROUTEDTO = 0x0251,
|
||||
WM_POINTERROUTEDAWAY = 0x0252,
|
||||
WM_POINTERROUTEDRELEASED = 0x0253,
|
||||
//#endif /* WINVER >= 0x0602 */
|
||||
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_IME_SETCONTEXT = 0x0281,
|
||||
WM_IME_NOTIFY = 0x0282,
|
||||
WM_IME_CONTROL = 0x0283,
|
||||
WM_IME_COMPOSITIONFULL = 0x0284,
|
||||
WM_IME_SELECT = 0x0285,
|
||||
WM_IME_CHAR = 0x0286,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
//#if(WINVER >= 0x0500)
|
||||
WM_IME_REQUEST = 0x0288,
|
||||
//#endif /* WINVER >= 0x0500 */
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_IME_KEYDOWN = 0x0290,
|
||||
WM_IME_KEYUP = 0x0291,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
//#if((_WIN32_WINNT >= 0x0400) || (WINVER >= 0x0500))
|
||||
WM_MOUSEHOVER = 0x02A1,
|
||||
WM_MOUSELEAVE = 0x02A3,
|
||||
//#endif
|
||||
//#if(WINVER >= 0x0500)
|
||||
WM_NCMOUSEHOVER = 0x02A0,
|
||||
WM_NCMOUSELEAVE = 0x02A2,
|
||||
//#endif /* WINVER >= 0x0500 */
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0501)
|
||||
WM_WTSSESSION_CHANGE = 0x02B1,
|
||||
|
||||
WM_TABLET_FIRST = 0x02c0,
|
||||
WM_TABLET_LAST = 0x02df,
|
||||
//#endif /* _WIN32_WINNT >= 0x0501 */
|
||||
|
||||
//#if(WINVER >= 0x0601)
|
||||
WM_DPICHANGED = 0x02E0,
|
||||
//#endif /* WINVER >= 0x0601 */
|
||||
//#if(WINVER >= 0x0605)
|
||||
WM_DPICHANGED_BEFOREPARENT = 0x02E2,
|
||||
WM_DPICHANGED_AFTERPARENT = 0x02E3,
|
||||
WM_GETDPISCALEDSIZE = 0x02E4,
|
||||
//#endif /* WINVER >= 0x0605 */
|
||||
|
||||
|
||||
WM_CUT = 0x0300,
|
||||
WM_COPY = 0x0301,
|
||||
WM_PASTE = 0x0302,
|
||||
WM_CLEAR = 0x0303,
|
||||
WM_UNDO = 0x0304,
|
||||
WM_RENDERFORMAT = 0x0305,
|
||||
WM_RENDERALLFORMATS = 0x0306,
|
||||
WM_DESTROYCLIPBOARD = 0x0307,
|
||||
WM_DRAWCLIPBOARD = 0x0308,
|
||||
WM_PAINTCLIPBOARD = 0x0309,
|
||||
WM_VSCROLLCLIPBOARD = 0x030A,
|
||||
WM_SIZECLIPBOARD = 0x030B,
|
||||
WM_ASKCBFORMATNAME = 0x030C,
|
||||
WM_CHANGECBCHAIN = 0x030D,
|
||||
WM_HSCROLLCLIPBOARD = 0x030E,
|
||||
WM_QUERYNEWPALETTE = 0x030F,
|
||||
WM_PALETTEISCHANGING = 0x0310,
|
||||
WM_PALETTECHANGED = 0x0311,
|
||||
WM_HOTKEY = 0x0312,
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_PRINT = 0x0317,
|
||||
WM_PRINTCLIENT = 0x0318,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0500)
|
||||
WM_APPCOMMAND = 0x0319,
|
||||
//#endif /* _WIN32_WINNT >= 0x0500 */
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0501)
|
||||
WM_THEMECHANGED = 0x031A,
|
||||
//#endif /* _WIN32_WINNT >= 0x0501 */
|
||||
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0501)
|
||||
WM_CLIPBOARDUPDATE = 0x031D,
|
||||
//#endif /* _WIN32_WINNT >= 0x0501 */
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0600)
|
||||
WM_DWMCOMPOSITIONCHANGED = 0x031E,
|
||||
WM_DWMNCRENDERINGCHANGED = 0x031F,
|
||||
WM_DWMCOLORIZATIONCOLORCHANGED= 0x0320,
|
||||
WM_DWMWINDOWMAXIMIZEDCHANGE = 0x0321,
|
||||
//#endif /* _WIN32_WINNT >= 0x0600 */
|
||||
|
||||
//#if(_WIN32_WINNT >= 0x0601)
|
||||
WM_DWMSENDICONICTHUMBNAIL = 0x0323,
|
||||
WM_DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326,
|
||||
//#endif /* _WIN32_WINNT >= 0x0601 */
|
||||
|
||||
|
||||
//#if(WINVER >= 0x0600)
|
||||
WM_GETTITLEBARINFOEX = 0x033F,
|
||||
//#endif /* WINVER >= 0x0600 */
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_HANDHELDFIRST = 0x0358,
|
||||
WM_HANDHELDLAST = 0x035F,
|
||||
|
||||
WM_AFXFIRST = 0x0360,
|
||||
WM_AFXLAST = 0x037F,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
WM_PENWINFIRST = 0x0380,
|
||||
WM_PENWINLAST = 0x038F,
|
||||
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WM_APP = 0x8000,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
|
||||
/*
|
||||
* NOTE: All Message Numbers below 0x0400 are RESERVED.
|
||||
*
|
||||
* Private Window Messages Start Here:
|
||||
*/
|
||||
WM_USER = 0x0400,
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
|
||||
/* wParam for WM_SIZING message */
|
||||
WMSZ_LEFT = 1,
|
||||
WMSZ_RIGHT = 2,
|
||||
WMSZ_TOP = 3,
|
||||
WMSZ_TOPLEFT = 4,
|
||||
WMSZ_TOPRIGHT = 5,
|
||||
WMSZ_BOTTOM = 6,
|
||||
WMSZ_BOTTOMLEFT = 7,
|
||||
WMSZ_BOTTOMRIGHT = 8,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
|
||||
//#ifndef NONCMESSAGES
|
||||
|
||||
/*
|
||||
* WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
|
||||
*/
|
||||
/*HTERROR = (-2),
|
||||
HTTRANSPARENT = (-1),
|
||||
HTNOWHERE = 0,
|
||||
HTCLIENT = 1,
|
||||
HTCAPTION = 2,
|
||||
HTSYSMENU = 3,
|
||||
HTGROWBOX = 4,
|
||||
HTSIZE = HTGROWBOX,
|
||||
HTMENU = 5,
|
||||
HTHSCROLL = 6,
|
||||
HTVSCROLL = 7,
|
||||
HTMINBUTTON = 8,
|
||||
HTMAXBUTTON = 9,
|
||||
HTLEFT = 10,
|
||||
HTRIGHT = 11,
|
||||
HTTOP = 12,
|
||||
HTTOPLEFT = 13,
|
||||
HTTOPRIGHT = 14,
|
||||
HTBOTTOM = 15,
|
||||
HTBOTTOMLEFT = 16,
|
||||
HTBOTTOMRIGHT = 17,
|
||||
HTBORDER = 18,
|
||||
HTREDUCE = HTMINBUTTON,
|
||||
HTZOOM = HTMAXBUTTON,
|
||||
HTSIZEFIRST = HTLEFT,
|
||||
HTSIZELAST = HTBOTTOMRIGHT,
|
||||
//#if(WINVER >= 0x0400)
|
||||
HTOBJECT = 19,
|
||||
HTCLOSE = 20,
|
||||
HTHELP = 21,
|
||||
//#endif /* WINVER >= 0x0400 */
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 466300df0840ba54d95240e3a800a642
|
||||
timeCreated: 1611373988
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,252 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
static class NativeMethods {
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MONITORINFO {
|
||||
public int cbSize;
|
||||
public RECT rcMonitor;
|
||||
public RECT rcWork;
|
||||
public uint dwFlags;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT {
|
||||
public int Left, Top, Right, Bottom;
|
||||
|
||||
public RECT(int left, int top, int right, int bottom) {
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
public int X {
|
||||
get { return Left; }
|
||||
set {
|
||||
Right -= (Left - value);
|
||||
Left = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Y {
|
||||
get { return Top; }
|
||||
set {
|
||||
Bottom -= (Top - value);
|
||||
Top = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Height {
|
||||
get { return Bottom - Top; }
|
||||
set { Bottom = value + Top; }
|
||||
}
|
||||
|
||||
public int Width {
|
||||
get { return Right - Left; }
|
||||
set { Right = value + Left; }
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetTouchInputInfo(IntPtr hTouchInput, int cInputs, [Out] TOUCHINPUT[] pInputs, int cbSize);
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct TOUCHINPUT {
|
||||
public int x;
|
||||
public int y;
|
||||
public IntPtr hSource;
|
||||
public int dwID;
|
||||
public TOUCHINPUT_Flags dwFlags;
|
||||
public TOUCHINPUT_Mask dwMask;
|
||||
public int dwTime;
|
||||
public IntPtr dwExtraInfo;
|
||||
public int cxContact;
|
||||
public int cyContact;
|
||||
}
|
||||
[Flags]
|
||||
public enum TOUCHINPUT_Flags : int {
|
||||
TOUCHEVENTF_MOVE = 0x0001,
|
||||
TOUCHEVENTF_DOWN = 0x0002,
|
||||
TOUCHEVENTF_UP = 0x0004,
|
||||
TOUCHEVENTF_INRANGE = 0x0008,
|
||||
TOUCHEVENTF_PRIMARY = 0x0010,
|
||||
TOUCHEVENTF_NOCOALESCE = 0x0020,
|
||||
TOUCHEVENTF_PEN = 0x0040,
|
||||
TOUCHEVENTF_PALM = 0x0080,
|
||||
}
|
||||
[Flags]
|
||||
public enum TOUCHINPUT_Mask : int {
|
||||
TOUCHINPUTMASKF_CONTACTAREA = 0x0004,
|
||||
TOUCHINPUTMASKF_EXTRAINFO = 0x0002,
|
||||
TOUCHINPUTMASKF_TIMEFROMSYSTEM = 0x0001,
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetPointerInfo(int pointerID, ref POINTER_INFO pPointerInfo);
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct POINTER_INFO {
|
||||
public POINTER_INPUT_TYPE pointerType;
|
||||
public UInt32 pointerId;
|
||||
public UInt32 frameId;
|
||||
public POINTER_FLAGS pointerFlags;
|
||||
public IntPtr sourceDevice;
|
||||
public IntPtr hwndTarget;
|
||||
public POINT ptPixelLocation;
|
||||
public POINT ptHimetricLocation;
|
||||
public POINT ptPixelLocationRaw;
|
||||
public POINT ptHimetricLocationRaw;
|
||||
public UInt32 dwTime;
|
||||
public UInt32 historyCount;
|
||||
public Int32 inputData;
|
||||
public UInt32 dwKeyStates;
|
||||
public UInt64 PerformanceCount;
|
||||
public POINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
|
||||
}
|
||||
public enum POINTER_INPUT_TYPE {
|
||||
PT_POINTER = 0x00000001,
|
||||
PT_TOUCH = 0x00000002,
|
||||
PT_PEN = 0x00000003,
|
||||
PT_MOUSE = 0x00000004,
|
||||
PT_TOUCHPAD = 0x00000005,
|
||||
}
|
||||
[Flags]
|
||||
public enum POINTER_FLAGS {
|
||||
POINTER_FLAG_NONE = 0x00000000,
|
||||
POINTER_FLAG_NEW = 0x00000001,
|
||||
POINTER_FLAG_INRANGE = 0x00000002,
|
||||
POINTER_FLAG_INCONTACT = 0x00000004,
|
||||
POINTER_FLAG_FIRSTBUTTON = 0x00000010,
|
||||
POINTER_FLAG_SECONDBUTTON = 0x00000020,
|
||||
POINTER_FLAG_THIRDBUTTON = 0x00000040,
|
||||
POINTER_FLAG_FOURTHBUTTON = 0x00000080,
|
||||
POINTER_FLAG_FIFTHBUTTON = 0x00000100,
|
||||
POINTER_FLAG_PRIMARY = 0x00002000,
|
||||
POINTER_FLAG_CONFIDENCE = 0x00004000,
|
||||
POINTER_FLAG_CANCELED = 0x00008000,
|
||||
POINTER_FLAG_DOWN = 0x00010000,
|
||||
POINTER_FLAG_UPDATE = 0x00020000,
|
||||
POINTER_FLAG_UP = 0x00040000,
|
||||
POINTER_FLAG_WHEEL = 0x00080000,
|
||||
POINTER_FLAG_HWHEEL = 0x00100000,
|
||||
POINTER_FLAG_CAPTURECHANGED = 0x00200000,
|
||||
POINTER_FLAG_HASTRANSFORM = 0x00400000,
|
||||
}
|
||||
public enum POINTER_BUTTON_CHANGE_TYPE {
|
||||
POINTER_CHANGE_NONE,
|
||||
POINTER_CHANGE_FIRSTBUTTON_DOWN,
|
||||
POINTER_CHANGE_FIRSTBUTTON_UP,
|
||||
POINTER_CHANGE_SECONDBUTTON_DOWN,
|
||||
POINTER_CHANGE_SECONDBUTTON_UP,
|
||||
POINTER_CHANGE_THIRDBUTTON_DOWN,
|
||||
POINTER_CHANGE_THIRDBUTTON_UP,
|
||||
POINTER_CHANGE_FOURTHBUTTON_DOWN,
|
||||
POINTER_CHANGE_FOURTHBUTTON_UP,
|
||||
POINTER_CHANGE_FIFTHBUTTON_DOWN,
|
||||
POINTER_CHANGE_FIFTHBUTTON_UP,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT {
|
||||
public int X;
|
||||
public int Y;
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetPointerTouchInfo(int pointerId, ref POINTER_TOUCH_INFO touchInfo);
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINTER_TOUCH_INFO {
|
||||
public POINTER_INFO pointerInfo;
|
||||
public TOUCH_FLAGS touchFlags;
|
||||
public TOUCH_MASK touchMask;
|
||||
public RECT rcContact;
|
||||
public RECT rcContactRaw;
|
||||
public uint orientation;
|
||||
public uint pressure;
|
||||
}
|
||||
[Flags]
|
||||
public enum TOUCH_FLAGS {
|
||||
TOUCH_FLAG_NONE = 0x00000000,
|
||||
}
|
||||
[Flags]
|
||||
public enum TOUCH_MASK {
|
||||
TOUCH_MASK_NONE = 0x00000000,
|
||||
TOUCH_MASK_CONTACTAREA = 0x00000001,
|
||||
TOUCH_MASK_ORIENTATION = 0x00000002,
|
||||
TOUCH_MASK_PRESSURE = 0x00000004,
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr EnableMouseInPointer(bool value);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern uint GetCurrentThreadId();
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
|
||||
public delegate bool EnumWindowsProc(IntPtr hWnd,IntPtr lParam);
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool EnumThreadWindows(uint dwThreadId, EnumWindowsProc lpEnumFunc, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
|
||||
public static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
|
||||
public static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, uint msg, IntPtr wParam,
|
||||
IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool RegisterTouchWindow(IntPtr hWnd, TOUCH_WINDOW_FLAGS ulFlags);
|
||||
[Flags]
|
||||
public enum TOUCH_WINDOW_FLAGS {
|
||||
TWF_FINETOUCH = 1,
|
||||
TWF_WANTPALM = 2,
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool UnregisterTouchWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern void CloseTouchInputHandle(IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint);
|
||||
|
||||
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern ushort GlobalAddAtom(string lpString);
|
||||
|
||||
[DllImport("Kernel32.dll")]
|
||||
public static extern ushort GlobalDeleteAtom(ushort nAtom);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern int SetProp(IntPtr hWnd, string lpString, int hData);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern int RemoveProp(IntPtr hWnd, string lpString);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern uint QueryPerformanceFrequency(out Int64 lpFrequency);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern uint QueryPerformanceCounter(out Int64 lpPerformanceCount);
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6ff72ea2b7f71345aa19940faf026e8
|
||||
timeCreated: 1622589747
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public class SimpleInputConsumer {
|
||||
readonly InputManager _manager;
|
||||
readonly object _lock = new object();
|
||||
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
||||
readonly List<InputEvent> _events = new List<InputEvent>();
|
||||
public SimpleInputConsumer(InputManager manager) { _manager = manager; }
|
||||
public void Activate() {
|
||||
lock (_lock) {
|
||||
_events.Clear();
|
||||
}
|
||||
_manager.EnumerateHandlers(h => h.OnInput += OnInput);
|
||||
}
|
||||
public void Deactivate() {
|
||||
_manager.EnumerateHandlers(h => h.OnInput -= OnInput);
|
||||
}
|
||||
protected void OnInput(InputIdentifier id, InputVector vec) {
|
||||
lock (_lock) {
|
||||
InputVector vec0;
|
||||
if (_vectors.TryGetValue(id, out vec0)) {
|
||||
_events.Add(new InputEvent {
|
||||
Id = id,
|
||||
From = vec0,
|
||||
To = vec,
|
||||
});
|
||||
if (vec.IsNull) _vectors.Remove(id);
|
||||
else _vectors[id] = vec;
|
||||
}
|
||||
else {
|
||||
_events.Add(new InputEvent {
|
||||
Id = id,
|
||||
From = new InputVector(vec.Time),
|
||||
To = vec,
|
||||
});
|
||||
_vectors.Add(id, vec);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void EnumerateEvents(Action<InputEvent> cb) {
|
||||
lock (_lock) {
|
||||
foreach (var ev in _events) cb(ev);
|
||||
_events.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fd2d5f1c7ba0c74c9ce8775075750db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,12 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public static class UnityCameraUtils {
|
||||
public static Vector2 ScreenToWorldPoint(Vector2 pos) {
|
||||
Vector3 i = pos;
|
||||
i.z = -Camera.main.transform.localPosition.z;
|
||||
i = Camera.main.ScreenToWorldPoint(i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35a1c45601c39f94db20178505a68be2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,114 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public class UnityKeyHandler<T> : InputHandler where T : UnityKeyReceiver<T> {
|
||||
GameObject receiver;
|
||||
T recvcomp;
|
||||
|
||||
public UnityKeyHandler() { }
|
||||
|
||||
protected override void Activate() {
|
||||
receiver = new GameObject("__keyrecv__");
|
||||
recvcomp = receiver.AddComponent<T>();
|
||||
recvcomp.SetCallback(Feed);
|
||||
}
|
||||
|
||||
protected override void Deactivate() {
|
||||
if (receiver) GameObject.Destroy(receiver);
|
||||
}
|
||||
|
||||
public override void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsNullable(int type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override byte GetDimension(int type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override string GetTypeName(int type) {
|
||||
return recvcomp.GetKeyName(type);
|
||||
}
|
||||
|
||||
public override double GetCurrentTimestamp() {
|
||||
return Time.realtimeSinceStartupAsDouble;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class UnityKeyReceiver<T> : MonoBehaviour where T : UnityKeyReceiver<T> {
|
||||
protected Action<int, int, InputVector> Callback;
|
||||
protected readonly HashSet<int> Keys = new HashSet<int>();
|
||||
public void SetCallback(Action<int, int, InputVector> h) {
|
||||
Callback = h;
|
||||
}
|
||||
public abstract string GetKeyName(int type);
|
||||
void Awake() {
|
||||
useGUILayout = false;
|
||||
}
|
||||
void Update() {
|
||||
double time = Time.realtimeSinceStartupAsDouble;
|
||||
foreach (var k in Keys) {
|
||||
Callback(k, 0, new InputVector(time, Vector3.zero));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UnityKeyboardReceiver : UnityKeyReceiver<UnityKeyboardReceiver> {
|
||||
public override string GetKeyName(int type) {
|
||||
return Enum.GetName(typeof(KeyCode), type);
|
||||
}
|
||||
void OnGUI() {
|
||||
var e = Event.current;
|
||||
if (e.keyCode == KeyCode.None) return;
|
||||
double time = Time.realtimeSinceStartupAsDouble;
|
||||
var key = (int)e.keyCode;
|
||||
switch (e.type) {
|
||||
case EventType.KeyDown:
|
||||
if (!Keys.Contains(key)) {
|
||||
Callback(key, 0, new InputVector(time, Vector3.zero));
|
||||
Keys.Add(key);
|
||||
}
|
||||
break;
|
||||
case EventType.KeyUp:
|
||||
Keys.Remove(key);
|
||||
Callback(key, 0, new InputVector(time));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UnityMouseButtonReceiver : UnityKeyReceiver<UnityMouseButtonReceiver> {
|
||||
public override string GetKeyName(int type) {
|
||||
switch (type) {
|
||||
case 0: return "Mouse Left";
|
||||
case 1: return "Mouse Right";
|
||||
case 2: return "Mouse Middle";
|
||||
default: return string.Format("Mouse Button {0}", type);
|
||||
}
|
||||
}
|
||||
void OnGUI() {
|
||||
var e = Event.current;
|
||||
double time = Time.realtimeSinceStartupAsDouble;
|
||||
var key = e.button;
|
||||
switch (e.type) {
|
||||
case EventType.MouseDown:
|
||||
if (!Keys.Contains(key)) {
|
||||
Callback(key, 0, new InputVector(time, Vector3.zero));
|
||||
Keys.Add(key);
|
||||
}
|
||||
break;
|
||||
case EventType.MouseUp:
|
||||
Keys.Remove(key);
|
||||
Callback(key, 0, new InputVector(time));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8aa36fa1966064f489cf5c318f576d3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,63 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using unity = UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public class UnityMouseHandler : InputHandler {
|
||||
GameObject receiver;
|
||||
|
||||
public UnityMouseHandler() {
|
||||
if (!unity::Input.mousePresent) {
|
||||
throw new NotSupportedException("Unity mouse is not supported on this device");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Activate() {
|
||||
receiver = new GameObject("__mouserecv__");
|
||||
receiver.AddComponent<UnityMouseReceiver>().SetHandler(this);
|
||||
}
|
||||
|
||||
protected override void Deactivate() {
|
||||
if (receiver) GameObject.Destroy(receiver);
|
||||
}
|
||||
|
||||
public override void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsNullable(int type) {
|
||||
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||
return false;
|
||||
}
|
||||
|
||||
public override byte GetDimension(int type) {
|
||||
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||
return 2;
|
||||
}
|
||||
|
||||
public override string GetTypeName(int type) {
|
||||
switch (type) {
|
||||
case 0: return "Mouse Position";
|
||||
default: throw new ArgumentOutOfRangeException("type");
|
||||
}
|
||||
}
|
||||
|
||||
public override double GetCurrentTimestamp() {
|
||||
return Time.realtimeSinceStartupAsDouble;
|
||||
}
|
||||
|
||||
public class UnityMouseReceiver : MonoBehaviour {
|
||||
UnityMouseHandler handler;
|
||||
public void SetHandler(UnityMouseHandler h) {
|
||||
handler = h;
|
||||
}
|
||||
void Update() {
|
||||
double time = Time.realtimeSinceStartupAsDouble;
|
||||
Vector3 pos = UnityCameraUtils.ScreenToWorldPoint(unity::Input.mousePosition);
|
||||
handler.Feed(0, 0, new InputVector(time, pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using unity = UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public class UnityTouchHandler : InputHandler {
|
||||
GameObject receiver;
|
||||
|
||||
public UnityTouchHandler() {
|
||||
if (!unity::Input.touchSupported) {
|
||||
throw new NotSupportedException("Unity touch is not supported on this device");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Activate() {
|
||||
receiver = new GameObject("__touchrecv__");
|
||||
receiver.AddComponent<UnityPointerReceiver>().SetHandler(this);
|
||||
}
|
||||
|
||||
protected override void Deactivate() {
|
||||
if (receiver) GameObject.Destroy(receiver);
|
||||
}
|
||||
|
||||
public override void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsNullable(int type) {
|
||||
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||
return true;
|
||||
}
|
||||
|
||||
public override byte GetDimension(int type) {
|
||||
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||
return 2;
|
||||
}
|
||||
|
||||
public override string GetTypeName(int type) {
|
||||
switch (type) {
|
||||
case 0: return "Touch";
|
||||
default: throw new ArgumentOutOfRangeException("type");
|
||||
}
|
||||
}
|
||||
|
||||
public override double GetCurrentTimestamp() {
|
||||
return Time.realtimeSinceStartupAsDouble;
|
||||
}
|
||||
|
||||
public class UnityPointerReceiver : MonoBehaviour {
|
||||
UnityTouchHandler handler;
|
||||
public void SetHandler(UnityTouchHandler h) {
|
||||
handler = h;
|
||||
}
|
||||
void Update() {
|
||||
double time = Time.realtimeSinceStartupAsDouble;
|
||||
for (int i = 0; i < unity::Input.touchCount; i++) {
|
||||
var t = unity::Input.GetTouch(i);
|
||||
Vector2 pos = UnityCameraUtils.ScreenToWorldPoint(t.position);
|
||||
var vec = new InputVector(time, pos);
|
||||
if (t.phase == TouchPhase.Began || t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Moved) {
|
||||
handler.Feed(0, t.fingerId, vec);
|
||||
}
|
||||
else if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled) {
|
||||
handler.Feed(0, t.fingerId, vec);
|
||||
handler.Feed(0, t.fingerId, new InputVector(time));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93f60577ebaa5824dba5f322bbd1ad26
|
||||
timeCreated: 1618910605
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,348 +0,0 @@
|
||||
/*
|
||||
* @author Valentin Simonov / http://va.lent.in/
|
||||
* @author Valentin Frolov
|
||||
* @author Andrew David Griffiths
|
||||
* @author Cryville:Lime
|
||||
*/
|
||||
using AOT;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Common.Unity.Input {
|
||||
public class WindowsPointerHandler : InputHandler {
|
||||
static WindowsPointerHandler Instance;
|
||||
|
||||
const string PRESS_AND_HOLD_ATOM = "MicrosoftTabletPenServiceProperty";
|
||||
delegate IntPtr WndProcDelegate(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public const int MONITOR_DEFAULTTONEAREST = 2;
|
||||
readonly IntPtr hMainWindow;
|
||||
IntPtr oldWndProcPtr;
|
||||
IntPtr newWndProcPtr;
|
||||
WndProcDelegate newWndProc;
|
||||
ushort pressAndHoldAtomID;
|
||||
|
||||
readonly int touchInputSize;
|
||||
readonly long freq;
|
||||
static bool usePointerMessage;
|
||||
|
||||
public WindowsPointerHandler() {
|
||||
if (Instance != null)
|
||||
throw new InvalidOperationException("WindowsPointerHandler already created");
|
||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
|
||||
throw new NotSupportedException("Windows pointer is not supported on this device");
|
||||
Instance = this;
|
||||
usePointerMessage = true;
|
||||
|
||||
hMainWindow = GetUnityWindowHandle();
|
||||
if (hMainWindow == IntPtr.Zero) {
|
||||
throw new InvalidOperationException("Cannot find the game window");
|
||||
}
|
||||
NativeMethods.QueryPerformanceFrequency(out freq);
|
||||
retry:
|
||||
if (usePointerMessage) {
|
||||
try {
|
||||
NativeMethods.EnableMouseInPointer(true);
|
||||
Logger.Log("main", 0, "Input", "Touch input frequency: {0}", freq);
|
||||
}
|
||||
catch (TypeLoadException) {
|
||||
usePointerMessage = false;
|
||||
Logger.Log("main", 2, "Input", "Advanced touch handling not supported");
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
else {
|
||||
touchInputSize = Marshal.SizeOf(typeof(NativeMethods.TOUCHINPUT));
|
||||
}
|
||||
}
|
||||
|
||||
public const int TABLET_DISABLE_PRESSANDHOLD = 0x00000001;
|
||||
public const int TABLET_DISABLE_PENTAPFEEDBACK = 0x00000008;
|
||||
public const int TABLET_DISABLE_PENBARRELFEEDBACK = 0x00000010;
|
||||
public const int TABLET_DISABLE_FLICKS = 0x00010000;
|
||||
|
||||
protected override void Activate() {
|
||||
newWndProc = WndProc;
|
||||
newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
|
||||
oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);
|
||||
if (!NativeMethods.RegisterTouchWindow(hMainWindow, NativeMethods.TOUCH_WINDOW_FLAGS.TWF_WANTPALM)) {
|
||||
throw new InvalidOperationException("Failed to register touch window");
|
||||
}
|
||||
pressAndHoldAtomID = NativeMethods.GlobalAddAtom(PRESS_AND_HOLD_ATOM);
|
||||
NativeMethods.SetProp(hMainWindow, PRESS_AND_HOLD_ATOM,
|
||||
TABLET_DISABLE_PRESSANDHOLD | // disables press and hold (right-click) gesture
|
||||
TABLET_DISABLE_PENTAPFEEDBACK | // disables UI feedback on pen up (waves)
|
||||
TABLET_DISABLE_PENBARRELFEEDBACK | // disables UI feedback on pen button down (circle)
|
||||
TABLET_DISABLE_FLICKS // disables pen flicks (back, forward, drag down, drag up);
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Deactivate() {
|
||||
if (pressAndHoldAtomID != 0) {
|
||||
NativeMethods.RemoveProp(hMainWindow, PRESS_AND_HOLD_ATOM);
|
||||
NativeMethods.GlobalDeleteAtom(pressAndHoldAtomID);
|
||||
}
|
||||
if (!NativeMethods.UnregisterTouchWindow(hMainWindow)) {
|
||||
throw new InvalidOperationException("Failed to unregister touch window");
|
||||
}
|
||||
SetWindowLongPtr(hMainWindow, -4, oldWndProcPtr);
|
||||
newWndProcPtr = IntPtr.Zero;
|
||||
newWndProc = null;
|
||||
}
|
||||
|
||||
const string UnityWindowClassName = "UnityWndClass";
|
||||
|
||||
static IntPtr _windowHandle;
|
||||
public static IntPtr GetUnityWindowHandle() {
|
||||
uint threadId = NativeMethods.GetCurrentThreadId();
|
||||
NativeMethods.EnumThreadWindows(
|
||||
threadId,
|
||||
UnityWindowFilter,
|
||||
IntPtr.Zero
|
||||
);
|
||||
return _windowHandle;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(NativeMethods.EnumWindowsProc))]
|
||||
public static bool UnityWindowFilter(IntPtr hWnd, IntPtr lParam) {
|
||||
var classText = new StringBuilder(UnityWindowClassName.Length + 1);
|
||||
NativeMethods.GetClassName(hWnd, classText, classText.Capacity);
|
||||
if (classText.ToString() == UnityWindowClassName) {
|
||||
_windowHandle = hWnd;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool IsNullable(int type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override byte GetDimension(int type) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public override string GetTypeName(int type) {
|
||||
switch (type) {
|
||||
case 0: return "Windows Pointer Unknown";
|
||||
case 1: return "Windows Pointer Pointer";
|
||||
case 2: return "Windows Pointer Touch";
|
||||
case 3: return "Windows Pointer Pen";
|
||||
case 4: return "Windows Pointer Mouse";
|
||||
case 5: return "Windows Pointer Touch Pad";
|
||||
case 255: return "Windows Touch";
|
||||
default: throw new ArgumentOutOfRangeException(nameof(type));
|
||||
}
|
||||
}
|
||||
|
||||
public override double GetCurrentTimestamp() {
|
||||
long tick;
|
||||
NativeMethods.QueryPerformanceCounter(out tick);
|
||||
return (double)tick / freq;
|
||||
}
|
||||
|
||||
public override void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
Deactivate();
|
||||
if (usePointerMessage)
|
||||
NativeMethods.EnableMouseInPointer(false);
|
||||
}
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(WndProcDelegate))]
|
||||
static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) {
|
||||
try {
|
||||
var m = (WindowMessages)msg;
|
||||
/*if (m >= WindowMessages.WM_MOUSEFIRST && m <= WindowMessages.WM_MOUSELAST) {
|
||||
if (!usePointerMessage)
|
||||
Instance.handleMouseMsg(msg, wParam, lParam);
|
||||
}
|
||||
else*/
|
||||
switch (m) {
|
||||
case WindowMessages.WM_TOUCH:
|
||||
if (usePointerMessage)
|
||||
NativeMethods.CloseTouchInputHandle(lParam);
|
||||
else
|
||||
Instance.HandleTouchMsg(wParam, lParam);
|
||||
break;
|
||||
case WindowMessages.WM_POINTERDOWN:
|
||||
case WindowMessages.WM_POINTERUP:
|
||||
case WindowMessages.WM_POINTERUPDATE:
|
||||
if (usePointerMessage)
|
||||
Instance.HandlePointerMsg(msg, wParam, lParam);
|
||||
break;
|
||||
case WindowMessages.WM_CLOSE:
|
||||
Instance.Dispose();
|
||||
// Calling oldWndProcPtr here would crash the application
|
||||
Application.Quit();
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
return NativeMethods.CallWindowProc(Instance.oldWndProcPtr, hWnd, msg, wParam, lParam);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Log("main", 4, "Input", "An error occured while handling pointer:\n{0}", ex);
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
void HandlePointerMsg(uint msg, IntPtr wParam, IntPtr lParam) {
|
||||
int id = LOWORD(wParam.ToInt32());
|
||||
|
||||
var rawpinfo = new NativeMethods.POINTER_INFO();
|
||||
if (!NativeMethods.GetPointerInfo(id, ref rawpinfo))
|
||||
throw new InvalidOperationException("Failed to get pointer info");
|
||||
|
||||
/*
|
||||
Vector2? _cs = null;
|
||||
uint? orientation = null;
|
||||
uint? pressure = null;
|
||||
if (pointerInfo.pointerType == NativeMethods.POINTER_INPUT_TYPE.PT_TOUCH) {
|
||||
var pointerTouchInfo = new NativeMethods.POINTER_TOUCH_INFO();
|
||||
NativeMethods.GetPointerTouchInfo(pointerId, ref pointerTouchInfo);
|
||||
if (pointerTouchInfo.touchMask.HasFlag(NativeMethods.TOUCH_MASK.TOUCH_MASK_CONTACTAREA)) {
|
||||
Vector2 cs;
|
||||
cs.x = pointerTouchInfo.rcContact.Width;
|
||||
cs.y = pointerTouchInfo.rcContact.Height;
|
||||
_cs = cs;
|
||||
}
|
||||
if (pointerTouchInfo.touchMask.HasFlag(NativeMethods.TOUCH_MASK.TOUCH_MASK_ORIENTATION)) {
|
||||
orientation = pointerTouchInfo.orientation;
|
||||
}
|
||||
if (pointerTouchInfo.touchMask.HasFlag(NativeMethods.TOUCH_MASK.TOUCH_MASK_PRESSURE)) {
|
||||
pressure = pointerTouchInfo.pressure;
|
||||
}
|
||||
}*/
|
||||
|
||||
NativeMethods.POINT p = rawpinfo.ptPixelLocation;
|
||||
NativeMethods.ScreenToClient(hMainWindow, ref p);
|
||||
Vector2 _p = UnityCameraUtils.ScreenToWorldPoint(new Vector2(p.X, Screen.height - p.Y));
|
||||
|
||||
double time = (double)rawpinfo.PerformanceCount / freq;
|
||||
|
||||
int type;
|
||||
switch (rawpinfo.pointerType) {
|
||||
case NativeMethods.POINTER_INPUT_TYPE.PT_POINTER : type = 1; break;
|
||||
case NativeMethods.POINTER_INPUT_TYPE.PT_TOUCH : type = 2; break;
|
||||
case NativeMethods.POINTER_INPUT_TYPE.PT_PEN : type = 3; break;
|
||||
case NativeMethods.POINTER_INPUT_TYPE.PT_MOUSE : type = 4; break;
|
||||
case NativeMethods.POINTER_INPUT_TYPE.PT_TOUCHPAD: type = 5; break;
|
||||
default: type = 0; break;
|
||||
}
|
||||
if (rawpinfo.pointerFlags.HasFlag(NativeMethods.POINTER_FLAGS.POINTER_FLAG_CANCELED)) {
|
||||
Feed(type, id, new InputVector(time));
|
||||
return;
|
||||
}
|
||||
|
||||
InputVector vec = new InputVector(time, _p);
|
||||
|
||||
switch ((WindowMessages)msg) {
|
||||
case WindowMessages.WM_POINTERDOWN:
|
||||
case WindowMessages.WM_POINTERUPDATE:
|
||||
Feed(type, id, vec);
|
||||
break;
|
||||
case WindowMessages.WM_POINTERUP:
|
||||
Feed(type, id, vec);
|
||||
Feed(type, id, new InputVector(time));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*void handleMouseMsg(uint msg, IntPtr wParam, IntPtr lParam) {
|
||||
int id = mouseId;
|
||||
double procTime = diag::Stopwatch.GetTimestamp()
|
||||
/ (double)diag::Stopwatch.Frequency;
|
||||
Vector2 _p;
|
||||
_p.x = ((int)(short)LOWORD(lParam.ToInt32()));
|
||||
_p.y = ((int)(short)HIWORD(lParam.ToInt32()));
|
||||
PointerPhase phase;
|
||||
switch ((WindowMessages)msg) {
|
||||
case WindowMessages.WM_LBUTTONDOWN:
|
||||
case WindowMessages.WM_LBUTTONDBLCLK:
|
||||
phase = PointerPhase.Begin;
|
||||
id = mouseId = newIdCallback();
|
||||
break;
|
||||
case WindowMessages.WM_MOUSEMOVE:
|
||||
if (mouseId == 0)
|
||||
return;
|
||||
phase = PointerPhase.Update;
|
||||
break;
|
||||
case WindowMessages.WM_LBUTTONUP:
|
||||
phase = PointerPhase.End;
|
||||
mouseId = 0;
|
||||
break;
|
||||
case WindowMessages.WM_MOUSELEAVE:
|
||||
phase = PointerPhase.Cancel;
|
||||
mouseId = 0;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
callback(id, new PointerInfo() {
|
||||
Id = id,
|
||||
ProcessTime = procTime,
|
||||
Phase = phase,
|
||||
Type = PointerType.Mouse,
|
||||
Position = _p,
|
||||
});
|
||||
}*/
|
||||
|
||||
void HandleTouchMsg(IntPtr wParam, IntPtr lParam) {
|
||||
int inputCount = LOWORD(wParam.ToInt32());
|
||||
NativeMethods.TOUCHINPUT[] inputs = new NativeMethods.TOUCHINPUT[inputCount];
|
||||
|
||||
if (!NativeMethods.GetTouchInputInfo(lParam, inputCount, inputs, touchInputSize))
|
||||
throw new InvalidOperationException("Failed to get touch input info");
|
||||
|
||||
for (int i = 0; i < inputCount; i++) {
|
||||
NativeMethods.TOUCHINPUT touch = inputs[i];
|
||||
|
||||
NativeMethods.POINT p = new NativeMethods.POINT {
|
||||
X = touch.x / 100,
|
||||
Y = touch.y / 100
|
||||
};
|
||||
NativeMethods.ScreenToClient(hMainWindow, ref p);
|
||||
Vector2 _p = UnityCameraUtils.ScreenToWorldPoint(new Vector2(p.X, Screen.height - p.Y));
|
||||
|
||||
/*Vector2? _cs = null;
|
||||
if (touch.dwMask.HasFlag(NativeMethods.TOUCHINPUT_Mask.TOUCHINPUTMASKF_CONTACTAREA)) {
|
||||
Vector2 cs;
|
||||
cs.x = touch.cxContact / 100;
|
||||
cs.y = touch.cyContact / 100;
|
||||
_cs = cs;
|
||||
}*/
|
||||
|
||||
int id = touch.dwID;
|
||||
double time = touch.dwTime / 1000.0;
|
||||
InputVector vec = new InputVector(time, _p);
|
||||
|
||||
if (touch.dwFlags.HasFlag(NativeMethods.TOUCHINPUT_Flags.TOUCHEVENTF_MOVE) ||
|
||||
touch.dwFlags.HasFlag(NativeMethods.TOUCHINPUT_Flags.TOUCHEVENTF_DOWN)) {
|
||||
Feed(255, id, vec);
|
||||
}
|
||||
else if (touch.dwFlags.HasFlag(NativeMethods.TOUCHINPUT_Flags.TOUCHEVENTF_UP)) {
|
||||
Feed(255, id, vec);
|
||||
Feed(255, id, new InputVector(time));
|
||||
}
|
||||
}
|
||||
|
||||
NativeMethods.CloseTouchInputHandle(lParam);
|
||||
}
|
||||
|
||||
public static int LOWORD(int value) {
|
||||
return value & 0xffff;
|
||||
}
|
||||
|
||||
public static int HIWORD(int value) {
|
||||
return (value & (0xffff << 16)) >> 16;
|
||||
}
|
||||
|
||||
public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong) {
|
||||
if (IntPtr.Size == 8)
|
||||
return NativeMethods.SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
|
||||
return new IntPtr(NativeMethods.SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1b353deb73c51b409b15e54c54a6bb1
|
||||
timeCreated: 1611282071
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -57,6 +57,7 @@ namespace Cryville.Common.Unity {
|
||||
suspended = true;
|
||||
if (currentNetworkTask != null) {
|
||||
currentNetworkTask.Cancel();
|
||||
networkTasks.Enqueue(currentNetworkTask);
|
||||
currentNetworkTask = null;
|
||||
}
|
||||
}
|
||||
@@ -91,15 +92,6 @@ namespace Cryville.Common.Unity {
|
||||
/// A network task.
|
||||
/// </summary>
|
||||
public abstract class NetworkTask {
|
||||
protected NetworkTask(string uri) {
|
||||
Uri = uri;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The URI of the resource.
|
||||
/// </summary>
|
||||
public string Uri { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the task is cancelled.
|
||||
/// </summary>
|
||||
@@ -108,40 +100,56 @@ namespace Cryville.Common.Unity {
|
||||
/// <summary>
|
||||
/// Cancels the task.
|
||||
/// </summary>
|
||||
public virtual void Cancel() {
|
||||
public void Cancel() {
|
||||
Cancelled = true;
|
||||
OnCancel();
|
||||
}
|
||||
protected virtual void OnCancel() { }
|
||||
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
protected UnityWebRequest www;
|
||||
|
||||
/// <summary>
|
||||
/// Starts the task.
|
||||
/// </summary>
|
||||
public virtual void Start() {
|
||||
www = new UnityWebRequest(Uri);
|
||||
www.SendWebRequest();
|
||||
}
|
||||
public abstract void Start();
|
||||
/// <summary>
|
||||
/// Gets whether the task is done.
|
||||
/// </summary>
|
||||
/// <returns>Whether the task is done.</returns>
|
||||
public virtual bool Done() {
|
||||
public abstract bool Done();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A Unity network task.
|
||||
/// </summary>
|
||||
public abstract class UnityNetworkTask : NetworkTask {
|
||||
protected UnityNetworkTask(string uri) {
|
||||
Uri = uri;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The URI of the resource.
|
||||
/// </summary>
|
||||
public string Uri { get; private set; }
|
||||
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
protected UnityWebRequest www;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Start() {
|
||||
www = new UnityWebRequest(Uri);
|
||||
www.SendWebRequest();
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public override bool Done() {
|
||||
if (!www.isDone) return false;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
protected WWW www;
|
||||
/// <summary>
|
||||
/// Starts the task.
|
||||
/// </summary>
|
||||
/// <inheritdoc />
|
||||
public virtual void Start() {
|
||||
www = new WWW(Uri);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets whether the task is done.
|
||||
/// </summary>
|
||||
/// <returns>Whether the task is done.</returns>
|
||||
/// <inheritdoc />
|
||||
public virtual bool Done() {
|
||||
if (!www.isDone) return false;
|
||||
return true;
|
||||
@@ -149,9 +157,9 @@ namespace Cryville.Common.Unity {
|
||||
#endif
|
||||
}
|
||||
/// <summary>
|
||||
/// A <see cref="NetworkTask" /> that loads a texture.
|
||||
/// A <see cref="UnityNetworkTask" /> that loads a texture.
|
||||
/// </summary>
|
||||
public class LoadTextureTask : NetworkTask {
|
||||
public class LoadTextureTask : UnityNetworkTask {
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="LoadTextureTask" /> class.
|
||||
/// </summary>
|
||||
|
26
Assets/Cryville/Common/Unity/UrlOpener.cs
Normal file
26
Assets/Cryville/Common/Unity/UrlOpener.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace Cryville.Common.Unity {
|
||||
public static class UrlOpener {
|
||||
public static void Open(string url) {
|
||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||
System.Diagnostics.Process.Start(url);
|
||||
#elif UNITY_ANDROID
|
||||
using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) {
|
||||
clazz.CallStatic("open", url);
|
||||
}
|
||||
#else
|
||||
#error Unknown platform.
|
||||
#endif
|
||||
}
|
||||
public static void OpenThreaded(string url) {
|
||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||
Open(url);
|
||||
#elif UNITY_ANDROID
|
||||
UnityEngine.AndroidJNI.AttachCurrentThread();
|
||||
Open(url);
|
||||
UnityEngine.AndroidJNI.DetachCurrentThread();
|
||||
#else
|
||||
#error Unknown platform.
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Common/Unity/UrlOpener.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/UrlOpener.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c827ee181de8c51499777e5a822981b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Assets/Cryville/Common/Unity/UrlOpener.java
Normal file
17
Assets/Cryville/Common/Unity/UrlOpener.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package world.cryville.common.unity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import com.unity3d.player.UnityPlayer;
|
||||
import com.unity3d.player.UnityPlayerActivity;
|
||||
|
||||
public final class UrlOpener {
|
||||
private UrlOpener() { }
|
||||
|
||||
static UnityPlayerActivity activity;
|
||||
|
||||
public static void open(String url) {
|
||||
if (activity == null) activity = (UnityPlayerActivity)UnityPlayer.currentActivity;
|
||||
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||
}
|
||||
}
|
32
Assets/Cryville/Common/Unity/UrlOpener.java.meta
Normal file
32
Assets/Cryville/Common/Unity/UrlOpener.java.meta
Normal file
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2d08ba79acb0564b9802b57dbc2f8d3
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,5 +1,4 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity.UI;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -16,7 +15,6 @@ namespace Cryville.Crtr.Browsing {
|
||||
ChartDetail _data;
|
||||
GameObject _placeholder;
|
||||
GameObject _outerContent;
|
||||
DockOccupiedRatioLayoutGroup _outerContentGroup;
|
||||
Transform _content;
|
||||
Image _cover;
|
||||
TMP_Text _title;
|
||||
@@ -26,7 +24,6 @@ namespace Cryville.Crtr.Browsing {
|
||||
base.Awake();
|
||||
_placeholder = transform.Find("__placeholder__").gameObject;
|
||||
_outerContent = transform.Find("__content__").gameObject;
|
||||
_outerContentGroup = _outerContent.GetComponent<DockOccupiedRatioLayoutGroup>();
|
||||
_content = _outerContent.transform.Find("__content__");
|
||||
_cover = _content.Find("Cover").GetComponent<Image>();
|
||||
_title = _content.Find("Texts/Title").GetComponent<TMP_Text>();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Logging;
|
||||
using Cryville.Crtr.Extension;
|
||||
using Mono.Cecil;
|
||||
using System;
|
||||
@@ -26,7 +26,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
return _localRes;
|
||||
}
|
||||
public static void Init(string rootPath) {
|
||||
LoadExtension(typeof(Extensions.Umg.Extension));
|
||||
LoadExtension(typeof(Extensions.Extension));
|
||||
var asms = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToHashSet();
|
||||
var modules = new Queue<ModuleItem>();
|
||||
var extensionDir = new DirectoryInfo(Path.Combine(rootPath, "extensions"));
|
||||
@@ -71,7 +71,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
Logger.Log("main", 1, "Extension", "Loaded module {0}", module.Definition.Name);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Log("main", 4, "Extension", "An error occured while trying to load module {0}: {1}", module.Definition.Name, ex);
|
||||
Logger.Log("main", 4, "Extension", "An error occurred while trying to load module {0}: {1}", module.Definition.Name, ex);
|
||||
}
|
||||
finally {
|
||||
module.Definition.Dispose();
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Crtr.Extension;
|
||||
using Cryville.Crtr.Extensions;
|
||||
using Cryville.Crtr.Extensions.Umg;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
@@ -8,7 +9,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
using Logger = Cryville.Common.Logging.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
internal class LegacyResourceManager : IResourceManager<ChartDetail> {
|
||||
@@ -65,7 +66,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
var coverFile = item.GetFiles(meta.cover);
|
||||
if (coverFile.Length > 0) {
|
||||
cover = new AsyncDelivery<Texture2D>();
|
||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||
cover.CancelSource = task.Cancel;
|
||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||
}
|
||||
@@ -92,7 +93,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
var coverFile = item.GetFiles(meta.cover);
|
||||
if (coverFile.Length > 0) {
|
||||
cover = new AsyncDelivery<Texture2D>();
|
||||
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
|
||||
cover.CancelSource = task.Cancel;
|
||||
Game.NetworkTaskWorker.SubmitNetworkTask(task);
|
||||
}
|
||||
@@ -118,9 +119,12 @@ namespace Cryville.Crtr.Browsing {
|
||||
IEnumerable<ResourceConverter> converters;
|
||||
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
|
||||
foreach (var converter in converters) {
|
||||
IEnumerable<Resource> resources = null;
|
||||
var resources = new List<Resource>();
|
||||
var ses = new ConversionSession {
|
||||
OnResourceAdd = res => resources.Add(res)
|
||||
};
|
||||
try {
|
||||
resources = converter.ConvertFrom(file);
|
||||
converter.Convert(file, ses);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogAndPopupExtra(4, ex, "Failed to import resource: {0}", ex.Message);
|
||||
@@ -150,8 +154,14 @@ namespace Cryville.Crtr.Browsing {
|
||||
else if (res is FileResource) {
|
||||
var tres = (FileResource)res;
|
||||
DirectoryInfo dest;
|
||||
bool singleFileFlag = false;
|
||||
if (res is ChartResource)
|
||||
dest = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
|
||||
else if (res is ExtensionResource) {
|
||||
dest = new DirectoryInfo(_rootPath + "/extensions");
|
||||
singleFileFlag = true;
|
||||
Popup.Create("Please restart the game to reload the extensions");
|
||||
}
|
||||
else if (res is RulesetResource)
|
||||
dest = new DirectoryInfo(_rootPath + "/rulesets/" + res.Name);
|
||||
else if (res is SkinResource)
|
||||
@@ -162,10 +172,11 @@ namespace Cryville.Crtr.Browsing {
|
||||
LogAndPopup(3, "Attempt to import unsupported file resource: {0}", res);
|
||||
continue;
|
||||
}
|
||||
if (!dest.Exists) {
|
||||
if (singleFileFlag || !dest.Exists) {
|
||||
dest.Create();
|
||||
tres.Master.CopyTo(Path.Combine(dest.FullName, tres.Master.Extension));
|
||||
tres.Master.CopyTo(Path.Combine(dest.FullName, singleFileFlag ? tres.Master.Name : tres.Master.Extension));
|
||||
foreach (var attachment in tres.Attachments) {
|
||||
if (singleFileFlag) throw new InvalidOperationException("Internal error");
|
||||
attachment.CopyTo(Path.Combine(dest.FullName, attachment.Name));
|
||||
}
|
||||
}
|
||||
@@ -271,4 +282,4 @@ namespace Cryville.Crtr.Browsing {
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a13b7ea14b96e54ea8a7e6ba1275281
|
||||
timeCreated: 1638435211
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,76 +0,0 @@
|
||||
using Cryville.Common.ComponentModel;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using RangeAttribute = Cryville.Common.ComponentModel.RangeAttribute;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public class PropertyPanel : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject m_bool;
|
||||
[SerializeField]
|
||||
GameObject m_number;
|
||||
[SerializeField]
|
||||
GameObject m_string;
|
||||
|
||||
PropertyInfo _property;
|
||||
object _target;
|
||||
|
||||
Text _key;
|
||||
Transform _valueContainer;
|
||||
PropertyValuePanel _value;
|
||||
|
||||
#pragma warning disable IDE0051
|
||||
void Awake() {
|
||||
_key = transform.Find("Key").GetComponent<Text>();
|
||||
_valueContainer = transform.Find("Value");
|
||||
}
|
||||
#pragma warning restore IDE0051
|
||||
public void Load(PropertyInfo prop, object target) {
|
||||
_target = target;
|
||||
_property = prop;
|
||||
_key.text = prop.Name;
|
||||
|
||||
GameObject vp;
|
||||
if (prop.PropertyType == typeof(bool)) vp = m_bool;
|
||||
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
|
||||
else if (prop.PropertyType == typeof(string)) vp = m_string;
|
||||
else return;
|
||||
_value = GameObject.Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
|
||||
if (_value is PVPNumber) {
|
||||
var t = (PVPNumber)_value;
|
||||
t.IntegerMode = prop.PropertyType == typeof(int);
|
||||
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (RangeAttribute)attr[0];
|
||||
t.Range = new Vector2(u.Min, u.Max);
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (PrecisionAttribute)attr[0];
|
||||
t.Precision = u.Precision;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (StepAttribute)attr[0];
|
||||
t.MaxStep = u.Step;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
t.LogarithmicMode = true;
|
||||
}
|
||||
}
|
||||
_value.Callback = SetValueToObject;
|
||||
GetValueFromObject();
|
||||
}
|
||||
|
||||
void GetValueFromObject() {
|
||||
_value.Value = _property.GetValue(_target, null);
|
||||
}
|
||||
|
||||
void SetValueToObject(object value) {
|
||||
_property.SetValue(_target, value, null);
|
||||
GetValueFromObject();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcca29fea992ac24698a213f0e2baedc
|
||||
timeCreated: 1638435590
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
public abstract class PropertyValuePanel : MonoBehaviour {
|
||||
public Action<object> Callback { protected get; set; }
|
||||
public abstract object Value { get; set; }
|
||||
}
|
||||
}
|
@@ -9,6 +9,12 @@ using System.Linq;
|
||||
using UnsafeIL;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
[Flags]
|
||||
public enum CoeventMode {
|
||||
None = 0x0,
|
||||
Coevent = 0x1,
|
||||
Standalone = 0x2,
|
||||
}
|
||||
public abstract class ChartEvent {
|
||||
public BeatTime? time;
|
||||
|
||||
@@ -36,7 +42,7 @@ namespace Cryville.Crtr {
|
||||
public abstract int Priority { get; }
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual bool Standalone { get { return false; } }
|
||||
public virtual CoeventMode CoeventMode { get { return CoeventMode.Coevent; } }
|
||||
|
||||
public ChartEvent Clone() {
|
||||
return (ChartEvent)MemberwiseClone();
|
||||
@@ -67,12 +73,12 @@ namespace Cryville.Crtr {
|
||||
[JsonIgnore]
|
||||
public IntKeyedDictionary<PropSrc> PropSrcs { get; private set; }
|
||||
protected void SubmitPropSrc(string name, PropSrc property) {
|
||||
PropSrcs.Add(IdentifierManager.SharedInstance.Request(name), property);
|
||||
PropSrcs.Add(IdentifierManager.Shared.Request(name), property);
|
||||
}
|
||||
[JsonIgnore]
|
||||
public IntKeyedDictionary<PropOp> PropOps { get; private set; }
|
||||
protected void SubmitPropOp(string name, PropOp property) {
|
||||
PropOps.Add(IdentifierManager.SharedInstance.Request(name), property);
|
||||
PropOps.Add(IdentifierManager.Shared.Request(name), property);
|
||||
}
|
||||
|
||||
protected ChartEvent() {
|
||||
@@ -209,26 +215,32 @@ namespace Cryville.Crtr {
|
||||
default: return base.GetEventsOfType(type);
|
||||
}
|
||||
}
|
||||
public override int Priority { get { return 10; } }
|
||||
public override int Priority { get { return 12; } }
|
||||
}
|
||||
|
||||
public class Track : EventContainer {
|
||||
public override int Priority { get { return 10; } }
|
||||
public override int Priority { get { return 14; } }
|
||||
}
|
||||
|
||||
public class Motion : ChartEvent {
|
||||
#pragma warning disable IDE1006
|
||||
string m_motion;
|
||||
[JsonRequired]
|
||||
public string motion {
|
||||
get { return ToString(); }
|
||||
get { return m_motion == null ? ToString() : m_motion; }
|
||||
set { LoadFromString(value); }
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
private void LoadFromString(string s) {
|
||||
if (Node != null)
|
||||
throw new InvalidOperationException("The motion property can only be set at initialization");
|
||||
ChartCompatibilityHandler.MotionStringParser.Parse(s, out name, out Node);
|
||||
SubmitPropSrc("value", new VectorSrc(() => Node.Value));
|
||||
if (ChartPlayer.motionRegistry == null) {
|
||||
m_motion = s;
|
||||
}
|
||||
else {
|
||||
ChartCompatibilityHandler.MotionStringParser.Parse(s, out name, out Node);
|
||||
SubmitPropSrc("value", new VectorSrc(() => Node.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
@@ -273,6 +285,7 @@ namespace Cryville.Crtr {
|
||||
public float sumfix = 0.0f;
|
||||
|
||||
public override int Priority { get { return 0x1000; } }
|
||||
public override CoeventMode CoeventMode { get { return IsLong ? CoeventMode.Standalone : CoeventMode.Coevent; } }
|
||||
|
||||
public Motion() {
|
||||
SubmitPropOp("motion", new PropOp.String(v => motion = v)); // TODO Obsolete
|
||||
@@ -321,7 +334,7 @@ namespace Cryville.Crtr {
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public override int Priority { get { return 0; } }
|
||||
public override bool Standalone { get { return true; } }
|
||||
public override CoeventMode CoeventMode { get { return CoeventMode.Standalone; } }
|
||||
|
||||
public Judge() {
|
||||
SubmitPropSrc("name", new PropSrc.Identifier(() => Id.Key));
|
||||
|
@@ -66,7 +66,7 @@ namespace Cryville.Crtr {
|
||||
if (comps[i] == "") comps[i] = "0";
|
||||
}
|
||||
_itor.SetSource(string.Format("({0});", string.Join(',', comps)));
|
||||
ChartPlayer.etor.Evaluate(_vecop, _itor.GetExp());
|
||||
PdtEvaluator.Instance.Evaluate(_vecop, _itor.GetExp());
|
||||
return _vecbuf;
|
||||
}
|
||||
}
|
||||
@@ -99,18 +99,18 @@ namespace Cryville.Crtr {
|
||||
var exp = _itor.GetExp();
|
||||
switch (c) {
|
||||
case '@':
|
||||
ChartPlayer.etor.Evaluate(_vecop, exp);
|
||||
PdtEvaluator.Instance.Evaluate(_vecop, exp);
|
||||
node.Time = new Vec1(_vecbuf);
|
||||
break;
|
||||
case '~':
|
||||
ChartPlayer.etor.Evaluate(_vecop, exp);
|
||||
PdtEvaluator.Instance.Evaluate(_vecop, exp);
|
||||
node.EndTime = new Vec1(_vecbuf);
|
||||
break;
|
||||
case '^':
|
||||
node.Transition = exp;
|
||||
break;
|
||||
case ':':
|
||||
ChartPlayer.etor.Evaluate(_vecop, exp);
|
||||
PdtEvaluator.Instance.Evaluate(_vecop, exp);
|
||||
node.Value = Vector.Construct(ChartPlayer.motionRegistry[name].Type, _vecbuf);
|
||||
break;
|
||||
default:
|
||||
|
@@ -7,7 +7,7 @@ namespace Cryville.Crtr {
|
||||
public class ChartHandler : TransformHandler {
|
||||
protected override TransformHandler Parent { get { return null; } }
|
||||
|
||||
Chart chart;
|
||||
readonly Chart chart;
|
||||
readonly List<LibavFileAudioSource> sounds = new List<LibavFileAudioSource>();
|
||||
|
||||
public ChartHandler(Chart _chart) {
|
||||
|
@@ -1,5 +1,3 @@
|
||||
#define BUILD
|
||||
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Buffers;
|
||||
using Cryville.Crtr.Config;
|
||||
@@ -17,8 +15,8 @@ using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Scripting;
|
||||
using Coroutine = Cryville.Common.Coroutine;
|
||||
using Logger = Cryville.Common.Logging.Logger;
|
||||
using Stopwatch = System.Diagnostics.Stopwatch;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class ChartPlayer : MonoBehaviour {
|
||||
@@ -58,11 +56,10 @@ namespace Cryville.Crtr {
|
||||
public static float graphicalOffset = 0;
|
||||
public static float soundOffset = 0;
|
||||
static float startOffset = 0;
|
||||
public static int areaJudgePrecision = 16;
|
||||
public static float sv = 16f;
|
||||
|
||||
public static Dictionary<Identifier, MotionRegistry> motionRegistry = new Dictionary<Identifier, MotionRegistry>();
|
||||
|
||||
public static PdtEvaluator etor;
|
||||
public static Dictionary<Identifier, MotionRegistry> motionRegistry;
|
||||
#endregion
|
||||
|
||||
#region MonoBehaviour
|
||||
@@ -81,16 +78,14 @@ namespace Cryville.Crtr {
|
||||
|
||||
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
|
||||
|
||||
#if BUILD
|
||||
try {
|
||||
Play();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Game.LogException("Load/WorkerThread", "An error occured while loading the data", ex);
|
||||
Game.LogException("Load/WorkerThread", "An error occurred while loading the data", ex);
|
||||
Popup.CreateException(ex);
|
||||
ReturnToMenu();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Camera.main.RenderToCubemap();
|
||||
}
|
||||
@@ -121,7 +116,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Game.LogException("Load/Prehandle", "An error occured while prehandling the data", ex);
|
||||
Game.LogException("Load/Prehandle", "An error occurred while prehandling the data", ex);
|
||||
Popup.CreateException(ex);
|
||||
prehandler = null;
|
||||
Stop();
|
||||
@@ -173,7 +168,7 @@ namespace Cryville.Crtr {
|
||||
effectManager.Tick(cbus.Time);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Game.LogException("Game", "An error occured while playing", ex);
|
||||
Game.LogException("Game", "An error occurred while playing", ex);
|
||||
Popup.CreateException(ex);
|
||||
Stop();
|
||||
}
|
||||
@@ -185,12 +180,14 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
||||
loadThread = null;
|
||||
Popup.CreateException(threadException);
|
||||
#if BUILD
|
||||
ReturnToMenu();
|
||||
#endif
|
||||
}
|
||||
else if (texloaddone) {
|
||||
prehandler = new Coroutine(Prehandle());
|
||||
if (texLoader == null) Stop();
|
||||
else {
|
||||
prehandler = new Coroutine(Prehandle());
|
||||
texLoader = null;
|
||||
}
|
||||
loadThread = null;
|
||||
}
|
||||
}
|
||||
@@ -252,7 +249,7 @@ namespace Cryville.Crtr {
|
||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
|
||||
#endif
|
||||
);
|
||||
if (RMVPool.Shared != null) {
|
||||
if (MotionNodePool.Shared != null) {
|
||||
statusbuf.AppendFormat(
|
||||
"\nPools: RMV {0}, MC {1}, MN {2}",
|
||||
RMVPool.Shared.RentedCount,
|
||||
@@ -260,23 +257,21 @@ namespace Cryville.Crtr {
|
||||
MotionNodePool.Shared.RentedCount
|
||||
);
|
||||
}
|
||||
if (loadThread != null) {
|
||||
statusbuf.AppendFormat(
|
||||
"\n(Loading textures) Progress: {0:P}\n(Loading files) Progress: {1:P}",
|
||||
texLoader.Progress, loadPregress
|
||||
);
|
||||
}
|
||||
if (texLoader != null) statusbuf.AppendFormat("\n(Loading textures) Progress: {0:P}", texLoader.Progress);
|
||||
if (loadThread != null) statusbuf.AppendFormat("\n(Loading files) Progress: {0:P}", loadPregress);
|
||||
if (prehandler != null) statusbuf.AppendFormat("\n(Prehandling) Progress: {0:P}", prehandler.Progress);
|
||||
if (started) {
|
||||
statusbuf.AppendFormat(
|
||||
"\nStates: c{0} / b{1}",
|
||||
cbus.ActiveStateCount, bbus.ActiveStateCount
|
||||
);
|
||||
var aTime = Game.AudioClient.Position;
|
||||
var iTime = inputProxy.GetTimestampAverage();
|
||||
statusbuf.AppendFormat(
|
||||
"\nSTime: {0:G17}s {3} {4}\ndATime: {1:+0.0ms;-0.0ms;0} {3} {4}\ndITime: {2:+0.0ms;-0.0ms;0} {3} {5}",
|
||||
cbus.Time,
|
||||
(Game.AudioClient.Position - atime0 - cbus.Time) * 1e3,
|
||||
(inputProxy.GetTimestampAverage() - cbus.Time) * 1e3,
|
||||
"\nSTime: {0:G9}s {5} {6}\nATime: {1:G9}s ({3:+0.0ms;-0.0ms;0}) {5} {6}\nITime: {2:G9}s ({4:+0.0ms;-0.0ms;0}) {5} {7}",
|
||||
cbus.Time, aTime, iTime,
|
||||
(aTime - atime0 - cbus.Time) * 1e3,
|
||||
(iTime - cbus.Time) * 1e3,
|
||||
forceSyncFrames != 0 ? "(force sync)" : "",
|
||||
paused ? "(paused)" : "",
|
||||
paused ? "(semi-locked)" : ""
|
||||
@@ -329,9 +324,19 @@ namespace Cryville.Crtr {
|
||||
|
||||
public void TogglePlay() {
|
||||
if (started) Stop();
|
||||
else if (prehandler != null) {
|
||||
prehandler = null;
|
||||
Stop();
|
||||
}
|
||||
else if (texLoader != null || loadThread != null) {
|
||||
texloaddone = true;
|
||||
texLoader = null;
|
||||
if (loadThread.IsAlive) {
|
||||
Logger.Log("main", 2, "Game", "Stop requested while the chart is loading. Waiting for the loading thread to exit...");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (texLoader == null && loadThread == null && prehandler == null) Play();
|
||||
else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading");
|
||||
Play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,13 +347,19 @@ namespace Cryville.Crtr {
|
||||
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
||||
Game.AudioClient.Start();
|
||||
inputProxy.UnlockTime();
|
||||
#if !UNITY_ANDROID || UNITY_EDITOR
|
||||
DiscordController.Instance.SetResume(cbus.Time);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
Game.AudioClient.Pause();
|
||||
inputProxy.LockTime();
|
||||
#if !UNITY_ANDROID || UNITY_EDITOR
|
||||
DiscordController.Instance.SetPaused();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Load
|
||||
void Play() {
|
||||
@@ -361,9 +372,10 @@ namespace Cryville.Crtr {
|
||||
graphicalOffset = Settings.Default.GraphicalOffset;
|
||||
soundOffset = Settings.Default.SoundOffset;
|
||||
startOffset = Settings.Default.StartOffset;
|
||||
areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision;
|
||||
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
||||
texloaddone = false;
|
||||
Game.NetworkTaskWorker.SuspendBackgroundTasks();
|
||||
Game.SuspendBackgroundTasks();
|
||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||
|
||||
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
||||
@@ -441,7 +453,7 @@ namespace Cryville.Crtr {
|
||||
for (int i = 0; i < queue.Count; i++) {
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
texHandler = new DownloadHandlerTexture();
|
||||
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + queue[i], "GET", texHandler, null);
|
||||
texLoader = new UnityWebRequest(PlatformConfig.FileProtocolPrefix + queue[i], "GET", texHandler, null);
|
||||
texLoader.SendWebRequest();
|
||||
#else
|
||||
texLoader = new WWW(Game.FileProtocolPrefix + queue[i]);
|
||||
@@ -502,7 +514,7 @@ namespace Cryville.Crtr {
|
||||
Game.AudioSequencer.SeekTime(startOffset, SeekOrigin.Current);
|
||||
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return .95f;
|
||||
if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs();
|
||||
inputProxy.Activate();
|
||||
Camera.main.cullingMask |= 1;
|
||||
GC.Collect();
|
||||
if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
|
||||
timer.Stop();
|
||||
@@ -514,8 +526,9 @@ namespace Cryville.Crtr {
|
||||
logs.text = "";
|
||||
}
|
||||
Game.AudioSequencer.Playing = true;
|
||||
atime0 = Game.AudioClient.BufferPosition - startOffset;
|
||||
atime0 = Game.AudioClient.Position - startOffset;
|
||||
inputProxy.SyncTime(cbus.Time);
|
||||
inputProxy.Activate();
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
@@ -523,21 +536,27 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 1, "Game", "Stopping");
|
||||
Game.AudioClient.Start();
|
||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||
inputProxy.Deactivate();
|
||||
inputProxy = null;
|
||||
Camera.main.cullingMask &= ~1;
|
||||
if (inputProxy != null) {
|
||||
inputProxy.Deactivate();
|
||||
inputProxy = null;
|
||||
}
|
||||
judge = null;
|
||||
if (nbus != null) { nbus.Dispose(); nbus = null; }
|
||||
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;
|
||||
if (effectManager != null) {
|
||||
effectManager.Dispose();
|
||||
effectManager = null;
|
||||
}
|
||||
PdtEvaluator.Instance.Reset();
|
||||
motionRegistry = null;
|
||||
Logger.Log("main", 1, "Game", "Stopped");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (!logEnabled) ToggleLogs();
|
||||
Game.LogException("Game", "An error occured while stopping", ex);
|
||||
Game.LogException("Game", "An error occurred while stopping", ex);
|
||||
Popup.CreateException(ex);
|
||||
}
|
||||
finally {
|
||||
@@ -547,10 +566,8 @@ namespace Cryville.Crtr {
|
||||
started = false;
|
||||
}
|
||||
}
|
||||
Game.NetworkTaskWorker.ResumeBackgroundTasks();
|
||||
#if BUILD
|
||||
Game.ResumeBackgroundTasks();
|
||||
ReturnToMenu();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnSettingsUpdate() {
|
||||
@@ -567,11 +584,9 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
Exception threadException;
|
||||
#if !NO_THREAD
|
||||
Thread loadThread = null;
|
||||
volatile float loadPregress;
|
||||
Stopwatch workerTimer;
|
||||
#endif
|
||||
void Load(object _info) {
|
||||
var info = (LoadInfo)_info;
|
||||
try {
|
||||
@@ -582,7 +597,7 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Game.LogException("Load/WorkerThread", "An error occured while loading the data", ex);
|
||||
Game.LogException("Load/WorkerThread", "An error occurred while loading the data", ex);
|
||||
threadException = ex;
|
||||
}
|
||||
}
|
||||
@@ -601,7 +616,7 @@ namespace Cryville.Crtr {
|
||||
};
|
||||
|
||||
using (StreamReader reader = new StreamReader(info.chartFile.FullName, Encoding.UTF8)) {
|
||||
etor = new PdtEvaluator();
|
||||
PdtEvaluator.Instance.Reset();
|
||||
|
||||
LoadRuleset(info.rulesetFile); loadPregress = .05f;
|
||||
|
||||
@@ -621,12 +636,13 @@ namespace Cryville.Crtr {
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
|
||||
judge = new Judge(this, pruleset);
|
||||
etor.ContextJudge = judge;
|
||||
PdtEvaluator.Instance.ContextJudge = judge;
|
||||
|
||||
inputProxy = new InputProxy(pruleset, judge);
|
||||
inputProxy = new InputProxy(pruleset, judge, screenSize);
|
||||
inputProxy.LoadFrom(_rscfg.inputs);
|
||||
if (!inputProxy.IsCompleted()) {
|
||||
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
||||
Logger.Log("main", 2, "Game", "Input config not completed. Input disabled");
|
||||
inputProxy.Clear();
|
||||
}
|
||||
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
|
||||
@@ -672,8 +688,9 @@ namespace Cryville.Crtr {
|
||||
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
ruleset.LoadPdt(dir);
|
||||
pruleset = ruleset.Root;
|
||||
pruleset.Optimize(etor);
|
||||
pruleset.Optimize(PdtEvaluator.Instance);
|
||||
}
|
||||
PdtEvaluator.Instance.ContextRulesetConfig = new RulesetConfigStore(pruleset.configs, _rscfg.configs);
|
||||
RMVPool.Shared = new RMVPool();
|
||||
MotionCachePool.Shared = new MotionCachePool();
|
||||
MotionNodePool.Shared = new MotionNodePool();
|
||||
@@ -684,7 +701,7 @@ namespace Cryville.Crtr {
|
||||
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
|
||||
skin.LoadPdt(dir);
|
||||
pskin = skin.Root;
|
||||
pskin.Optimize(etor);
|
||||
pskin.Optimize(PdtEvaluator.Instance);
|
||||
effectManager = new EffectManager(pskin);
|
||||
}
|
||||
#endregion
|
||||
|
@@ -140,13 +140,13 @@ namespace Cryville.Crtr.Components {
|
||||
|
||||
verts = _vertPool.Rent(vc * vcpsec);
|
||||
uvs = _uvPool.Rent(vc * vcpsec);
|
||||
int i = 0; int t = 0; float l = 0; int m = 0;
|
||||
if (head.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trih, head, ref i, ref t, ref l, 0, headLength, vcpsec, hvc); }
|
||||
m++; GenerateMeshTo(verts, uvs, out trib, body, ref i, ref t, ref l, headLength, sumLength - tailLength, vcpsec, hvc + bvc);
|
||||
if (tail.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trit, tail, ref i, ref t, ref l, sumLength - tailLength, sumLength, vcpsec, vc); }
|
||||
int i = 0; int t = 0; float l = 0;
|
||||
if (head.Frame != null) { GenerateMeshTo(verts, uvs, out trih, head, ref i, ref t, ref l, 0, headLength, vcpsec, hvc); }
|
||||
GenerateMeshTo(verts, uvs, out trib, body, ref i, ref t, ref l, headLength, sumLength - tailLength, vcpsec, hvc + bvc);
|
||||
if (tail.Frame != null) { GenerateMeshTo(verts, uvs, out trit, tail, ref i, ref t, ref l, sumLength - tailLength, sumLength, vcpsec, vc); }
|
||||
|
||||
mesh.Mesh.subMeshCount = 3;
|
||||
m = 0;
|
||||
int m = 0;
|
||||
mesh.Mesh.SetVertices(verts);
|
||||
mesh.Mesh.SetUVs(0, uvs);
|
||||
mesh.Mesh.SetTriangles(head.Frame == null ? _emptyTris : trih, m++);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
using Logger = Cryville.Common.Logging.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SkinAnimation : SkinComponent {
|
||||
|
@@ -15,7 +15,7 @@ namespace Cryville.Crtr.Components {
|
||||
/// <param name="name">The name of the property.</param>
|
||||
/// <param name="property">The property.</param>
|
||||
protected void SubmitProperty(string name, PdtOperator property, int udl = 1) {
|
||||
Properties.Add(IdentifierManager.SharedInstance.Request(name), new SkinProperty(property, udl));
|
||||
Properties.Add(IdentifierManager.Shared.Request(name), new SkinProperty(property, udl));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
using Logger = Cryville.Common.Logging.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Components {
|
||||
public class SpriteInfo {
|
||||
|
@@ -3,7 +3,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Logger = Cryville.Common.Logger;
|
||||
using Logger = Cryville.Common.Logging.Logger;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class ConfigPanelMaster : MonoBehaviour {
|
||||
@@ -14,7 +14,10 @@ namespace Cryville.Crtr.Config {
|
||||
Transform m_content;
|
||||
|
||||
[SerializeField]
|
||||
SettingsPanel m_genericConfigPanel;
|
||||
PropertyMasterPanel m_genericConfigPanel;
|
||||
|
||||
[SerializeField]
|
||||
PropertyMasterPanel m_rulesetConfigPanel;
|
||||
|
||||
[SerializeField]
|
||||
InputConfigPanel m_inputConfigPanel;
|
||||
@@ -22,9 +25,11 @@ namespace Cryville.Crtr.Config {
|
||||
public Ruleset ruleset;
|
||||
RulesetConfig _rscfg;
|
||||
|
||||
bool _loaded;
|
||||
|
||||
void OnEnable() {
|
||||
try {
|
||||
ChartPlayer.etor = new PdtEvaluator();
|
||||
PdtEvaluator.Instance.Reset();
|
||||
FileInfo file = new FileInfo(
|
||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
||||
);
|
||||
@@ -54,17 +59,20 @@ namespace Cryville.Crtr.Config {
|
||||
}
|
||||
}
|
||||
|
||||
m_genericConfigPanel.Target = _rscfg.generic;
|
||||
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
||||
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
|
||||
|
||||
var proxy = new InputProxy(ruleset.Root, null);
|
||||
var proxy = new InputProxy(ruleset.Root, null, new Vector2(Screen.width, Screen.height));
|
||||
proxy.LoadFrom(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy = proxy;
|
||||
|
||||
m_inputConfigPanel.OnConfigEnable();
|
||||
|
||||
_loaded = true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Popup.CreateException(ex);
|
||||
Logger.Log("main", 4, "Config", "An error occured while loading the config: {0}", ex);
|
||||
Logger.Log("main", 4, "Config", "An error occurred while loading the config: {0}", ex);
|
||||
m_menu.Back();
|
||||
}
|
||||
}
|
||||
@@ -77,15 +85,18 @@ namespace Cryville.Crtr.Config {
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy.Dispose();
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
||||
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
if (_loaded) {
|
||||
_loaded = false;
|
||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy.Dispose();
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
|
||||
);
|
||||
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
||||
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
m_inputConfigPanel.OnConfigDisable();
|
||||
}
|
||||
m_inputConfigPanel.OnConfigDisable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
101
Assets/Cryville/Crtr/Config/IPropertyAdapter.cs
Normal file
101
Assets/Cryville/Crtr/Config/IPropertyAdapter.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using Cryville.Common.ComponentModel;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public interface IPropertyAdapter {
|
||||
string Category { get; }
|
||||
string Name { get; }
|
||||
PropertyType Type { get; }
|
||||
object[] Range { get; }
|
||||
object GetValue();
|
||||
void SetValue(object value);
|
||||
event Action ValueChanged;
|
||||
object MapValue(object value);
|
||||
bool SetMapped { get; }
|
||||
object MapValueInverse(object value);
|
||||
}
|
||||
|
||||
public enum PropertyType {
|
||||
Unknown,
|
||||
Number,
|
||||
NumberStepped,
|
||||
Boolean,
|
||||
String,
|
||||
}
|
||||
|
||||
public class DefaultPropertyAdapter : IPropertyAdapter {
|
||||
readonly object _target;
|
||||
readonly PropertyInfo _prop;
|
||||
public string Category { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public PropertyType Type { get; private set; }
|
||||
public object[] Range { get; private set; }
|
||||
public object GetValue() { return _prop.GetValue(_target, null); }
|
||||
public void SetValue(object value) { _prop.SetValue(_target, value, null); }
|
||||
|
||||
public event Action ValueChanged { add { } remove { } }
|
||||
|
||||
readonly double _precision;
|
||||
readonly double _step;
|
||||
readonly bool _logarithmic;
|
||||
public object MapValue(object value) {
|
||||
if (Type == PropertyType.Number || Type == PropertyType.NumberStepped) {
|
||||
var result = (double)value;
|
||||
if (_step != 0) result *= _step;
|
||||
if (_logarithmic) result = Math.Pow(Math.E, result);
|
||||
if (_precision != 0) result = Math.Round(result / _precision) * _precision;
|
||||
return Convert.ChangeType(result, _prop.PropertyType);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public bool SetMapped { get { return true; } }
|
||||
public object MapValueInverse(object value) {
|
||||
if (Type == PropertyType.Number || Type == PropertyType.NumberStepped) {
|
||||
var result = Convert.ToDouble(value);
|
||||
if (_logarithmic) result = Math.Log(result);
|
||||
if (_step != 0) result /= _step;
|
||||
return result;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public DefaultPropertyAdapter(object target, PropertyInfo prop) {
|
||||
_target = target;
|
||||
_prop = prop;
|
||||
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
|
||||
if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
|
||||
Name = prop.Name;
|
||||
if (prop.PropertyType == typeof(bool)) Type = PropertyType.Boolean;
|
||||
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
|
||||
else if (prop.PropertyType.IsPrimitive) {
|
||||
Type = prop.GetCustomAttributes(typeof(StepAttribute), true).Length > 0
|
||||
? PropertyType.NumberStepped
|
||||
: PropertyType.Number;
|
||||
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (RangeAttribute)attr.Single();
|
||||
Range = new object[] { u.Min, u.Max };
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (PrecisionAttribute)attr.Single();
|
||||
_precision = u.Precision;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
var u = (StepAttribute)attr.Single();
|
||||
_step = u.Step;
|
||||
}
|
||||
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
|
||||
if (attr.Length > 0) {
|
||||
_logarithmic = true;
|
||||
}
|
||||
}
|
||||
else if (prop.PropertyType == typeof(string)) Type = PropertyType.String;
|
||||
else return;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Config/IPropertyAdapter.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/IPropertyAdapter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b3e9219783719544bcbceade34a1090
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs
Normal file
29
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public interface IPropertyMasterAdapter {
|
||||
string DefaultCategory { get; }
|
||||
IEnumerable<IPropertyAdapter> GetProperties();
|
||||
}
|
||||
public class DefaultPropertyMasterAdapter : IPropertyMasterAdapter {
|
||||
readonly object _target;
|
||||
|
||||
public DefaultPropertyMasterAdapter(object target) {
|
||||
if (target == null) throw new ArgumentNullException("target");
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public string DefaultCategory { get { return "miscellaneous"; } }
|
||||
|
||||
public IEnumerable<IPropertyAdapter> GetProperties() {
|
||||
return _target.GetType().GetProperties().Where(p => {
|
||||
var attrs = p.GetCustomAttributes(typeof(BrowsableAttribute), true);
|
||||
if (attrs.Length == 0) return true;
|
||||
else return ((BrowsableAttribute)attrs.Single()).Browsable;
|
||||
}).Select(p => new DefaultPropertyAdapter(_target, p));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e0b160d43716cf4d8ba20b5a7eafd13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,6 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common.Unity.Input;
|
||||
using Cryville.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -29,16 +30,47 @@ namespace Cryville.Crtr.Config {
|
||||
public InputProxy proxy;
|
||||
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
|
||||
|
||||
int _applicableEntries;
|
||||
Identifier _sel;
|
||||
int _targetDim;
|
||||
PhysicalDimension? _targetPDim;
|
||||
bool _targetNotNull;
|
||||
public void OpenDialog(Identifier entry) {
|
||||
_sel = entry;
|
||||
var def = m_configScene.ruleset.Root.inputs[_sel];
|
||||
_targetDim = def.dim;
|
||||
if (def.pdim != null) _targetPDim = ParsePhysicalDimension(def.pdim);
|
||||
else _targetPDim = null;
|
||||
_targetNotNull = def.notnull;
|
||||
m_inputDialog.SetActive(true);
|
||||
CallHelper.Purge(m_deviceList);
|
||||
_consumer.EnumerateEvents(ev => { });
|
||||
_recvsrcs.Clear();
|
||||
_applicableEntries = 1;
|
||||
AddSourceItem(null);
|
||||
}
|
||||
|
||||
static PhysicalDimension ParsePhysicalDimension(string str) {
|
||||
var comps = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
var result = new PhysicalDimension();
|
||||
foreach (var comp in comps) {
|
||||
int dim = 1;
|
||||
if (comp.Length > 1) dim = int.Parse(comp.Substring(1));
|
||||
switch (comp[0]) {
|
||||
case 'T': result.Time += dim; break;
|
||||
case 'L': result.Length += dim; break;
|
||||
case 'M': result.Mass += dim; break;
|
||||
case 'I': result.ElectricCurrent += dim; break;
|
||||
case '\x0398':
|
||||
case 'H': result.ThermodynamicTemperature += dim; break;
|
||||
case 'N': result.AmountOfSubstance += dim; break;
|
||||
case 'J': result.LuminousIntensity += dim; break;
|
||||
default: throw new ArgumentException(string.Format("Invalid dimension symbol {0}", comp[0]));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void CloseDialog() {
|
||||
m_inputDialog.SetActive(false);
|
||||
}
|
||||
@@ -73,15 +105,22 @@ namespace Cryville.Crtr.Config {
|
||||
_entries[e.Name].OnProxyChanged(e);
|
||||
}
|
||||
|
||||
void Start() {
|
||||
_d_HandleInputEvent = HandleInputEvent;
|
||||
}
|
||||
|
||||
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
|
||||
void Update() {
|
||||
if (m_inputDialog.activeSelf) {
|
||||
_consumer.EnumerateEvents(ev => {
|
||||
AddSourceItem(ev.Id.Source);
|
||||
});
|
||||
_consumer.EnumerateEvents(_d_HandleInputEvent);
|
||||
}
|
||||
}
|
||||
|
||||
Action<InputEvent> _d_HandleInputEvent;
|
||||
void HandleInputEvent(InputEvent ev) {
|
||||
AddSourceItem(ev.Identifier.Source);
|
||||
}
|
||||
|
||||
void AddSourceItem(InputSource? src) {
|
||||
if (_recvsrcs.Contains(src)) return;
|
||||
_recvsrcs.Add(src);
|
||||
@@ -95,11 +134,21 @@ namespace Cryville.Crtr.Config {
|
||||
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) {
|
||||
else if (tsrc.Handler.Dimension < _targetDim) {
|
||||
text.text += " <size=9>(Not Applicable)</size>";
|
||||
}
|
||||
else if (_targetPDim != null && tsrc.Handler.ReferenceCue.PhysicalDimension != _targetPDim) {
|
||||
text.text += " <size=9>(Not Applicable)</size>";
|
||||
}
|
||||
else if (!_targetNotNull && !tsrc.Handler.IsNullable) {
|
||||
text.text += " <size=9>(Not Applicable)</size>";
|
||||
}
|
||||
else flag = true;
|
||||
btn.interactable = flag;
|
||||
obj.transform.SetSiblingIndex(flag ? _applicableEntries++ : m_deviceList.childCount - 1);
|
||||
}
|
||||
else {
|
||||
obj.transform.SetSiblingIndex(0);
|
||||
}
|
||||
btn.onClick.AddListener(() => {
|
||||
CloseDialog(src);
|
||||
|
@@ -1,14 +1,8 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Cryville.Crtr.Browsing {
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
|
||||
bool _value;
|
||||
public override object Value {
|
||||
get { return _value; }
|
||||
set { _value = (bool)value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
RectTransform m_on;
|
||||
[SerializeField]
|
||||
@@ -16,21 +10,22 @@ namespace Cryville.Crtr.Browsing {
|
||||
[SerializeField]
|
||||
RectTransform m_handle;
|
||||
|
||||
protected override void OnValueUpdated() { }
|
||||
|
||||
public void Toggle() {
|
||||
_value = !_value;
|
||||
Callback(Value);
|
||||
RawValue = !(bool)RawValue;
|
||||
}
|
||||
|
||||
const float SPEED = 8;
|
||||
float _ratio;
|
||||
#pragma warning disable IDE0051
|
||||
void Update() {
|
||||
if (_value && _ratio != 1) {
|
||||
if ((bool)RawValue && _ratio != 1) {
|
||||
_ratio += SPEED * Time.deltaTime;
|
||||
if (_ratio > 1) _ratio = 1;
|
||||
UpdateGraphics();
|
||||
}
|
||||
else if (!_value && _ratio != 0) {
|
||||
else if (!(bool)RawValue && _ratio != 0) {
|
||||
_ratio -= SPEED * Time.deltaTime;
|
||||
if (_ratio < 0) _ratio = 0;
|
||||
UpdateGraphics();
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b281561aca5d19f43ba8af035de8ec98
|
||||
guid: 362a7cfafb57b9f46bbca9ed88d18c53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user