Compare commits
271 Commits
Author | SHA1 | Date | |
---|---|---|---|
3ecf3b4bfc | |||
1da8647ff1 | |||
2f19e8daad | |||
07f62c7aeb | |||
39db8dfa45 | |||
f04cd370f1 | |||
5c4acd54ce | |||
82dbc5c479 | |||
1f1663d714 | |||
a3c5392caa | |||
6c983cc2cb | |||
3bf3fdac3d | |||
f2f3dba098 | |||
3728360dd2 | |||
887837bb3d | |||
99b4c2dfc1 | |||
e59769158a | |||
ba3238614b | |||
a115999aab | |||
393947db9f | |||
e9b2a7f894 | |||
9c73455761 | |||
59c2210359 | |||
4fab20953a | |||
ee7b0f5081 | |||
33ee7a9a87 | |||
900bd7b77a | |||
6bd32c9aef | |||
13893b2853 | |||
23789c15eb | |||
a1f7418d32 | |||
274a823d02 | |||
ba6239068a | |||
ff8c925f32 | |||
2a6a33e60c | |||
8910b1f4a0 | |||
36dddea4d9 | |||
6a648c2dcd | |||
2d4087dc89 | |||
f91aacd78e | |||
9c08cbf0d2 | |||
88d35e4eaf | |||
675ce68073 | |||
db0165d145 | |||
7015426300 | |||
0d4cc5e208 | |||
e7ce0985fb | |||
eb6dafbd60 | |||
b6e238780e | |||
c7ea6f1d4b | |||
4a5b2a6889 | |||
b84d645aee | |||
67b44db1ae | |||
ee4399109a | |||
87ef534f59 | |||
87362b47c5 | |||
f60ba1088d | |||
abb7ad6f24 | |||
880b475c07 | |||
4707c40e6a | |||
7f87c23da2 | |||
6df10837fe | |||
42cb54de1d | |||
9fd685b8b3 | |||
b364005741 | |||
7d938de409 | |||
bb4ecfcd8c | |||
ff410529b0 | |||
fdc55a8e3b | |||
fc8512ff63 | |||
1b1ed42a1b | |||
b437925f92 | |||
c04e50e959 | |||
314cdb9935 | |||
77c91d015a | |||
291a018c13 | |||
18ff4b8e16 | |||
7714c277fd | |||
d6c2ac6be6 | |||
682fe38d40 | |||
3e525842cb | |||
3dd25b51a8 | |||
041c1e374e | |||
16b1d323dc | |||
c4d5e5f480 | |||
187f07d2c9 | |||
4e9d7e5b87 | |||
7df5b15e2e | |||
4863aa0ae7 | |||
eb53c3465b | |||
f683d61298 | |||
fbd03c8037 | |||
da68c8b877 | |||
c0744a3464 | |||
3ca3746cec | |||
5e76ddf2cd | |||
dca1ba304e | |||
8dd32afb74 | |||
313824b4bb | |||
b166c0f5ef | |||
300e44bd4b | |||
ab6f983392 | |||
596c6395e4 | |||
404a36f9b8 | |||
1711fbadf7 | |||
84b7a6d183 | |||
6d0fd0f9ec | |||
b407ba88c4 | |||
bd256ba1a6 | |||
623c53f79a | |||
969fdc8069 | |||
cbc874dd72 | |||
450bd52095 | |||
5727fcf177 | |||
8ab0c2698b | |||
6c7b52d93c | |||
91f55cd9a3 | |||
a1ce459a0e | |||
9700992c3a | |||
f9a1ea72fe | |||
507b656eab | |||
c16776aee9 | |||
e109e0bd24 | |||
776a615464 | |||
5514b6cf37 | |||
8932d1b8d0 | |||
10988847b3 | |||
c4b139c7a4 | |||
130896df1f | |||
5d5c519a1d | |||
3d1a11f78b | |||
cc985844cd | |||
feffbaa5a6 | |||
d0f0c8ce6d | |||
3fdc236b1d | |||
46870e163a | |||
601f64cc61 | |||
c015b60dc3 | |||
5e01b654bd | |||
2304257201 | |||
02794d88b9 | |||
9f73c8ffad | |||
c1c354959d | |||
94428d9e18 | |||
5198ecec1f | |||
6779b88055 | |||
c5dab3a232 | |||
a7608bcd7e | |||
be64bc76b5 | |||
39bc34fd42 | |||
4185303bd2 | |||
3280693e8f | |||
29432feabc | |||
86559c681e | |||
79f11b9c33 | |||
5b9149cb34 | |||
9d6bdd968f | |||
bc4fec33ef | |||
09e917dbe8 | |||
1003a0e199 | |||
e3a805b855 | |||
4222176979 | |||
43c87fba70 | |||
d0a23aaf30 | |||
a09a5686d7 | |||
609bb317d0 | |||
898fb7d557 | |||
c39f258a19 | |||
4fdd4e1935 | |||
7662011d60 | |||
c24372b308 | |||
5e4c53113a | |||
4f93995bbd | |||
5b14466059 | |||
1d3aa85446 | |||
6efe70d751 | |||
555c88855c | |||
105aacc133 | |||
ea9000f2b0 | |||
4e851d9b73 | |||
0a1e512f41 | |||
a7baef2c9d | |||
723ec937ad | |||
7c77ba83f8 | |||
6da4b96b24 | |||
e8f8593555 | |||
2b5bc5dd08 | |||
cf6186aa16 | |||
4d7773a2ac | |||
e8f74399f2 | |||
ca72f7adb5 | |||
5e19a8b886 | |||
a416f772d4 | |||
989a6b5554 | |||
732af15d9b | |||
8cdab36cd6 | |||
44180c7e0f | |||
e589e37640 | |||
94107de97d | |||
13c55dc23e | |||
617eddc030 | |||
7475b19547 | |||
0049ace91a | |||
356f4df9a9 | |||
ff5928b556 | |||
1f0ac2a2e9 | |||
95628f07d1 | |||
3bead4f1b3 | |||
ec9b23f797 | |||
8175ca7e82 | |||
451ebbe91a | |||
da2313ab57 | |||
c5571e7d17 | |||
959157255f | |||
06d8012675 | |||
571320630b | |||
207dee9932 | |||
d7b0ca77e9 | |||
e55642cdeb | |||
595fd74662 | |||
3f7becf580 | |||
5d17555744 | |||
e6d94f248c | |||
b0c70bc62e | |||
8eb0b11027 | |||
7f2cfe94c1 | |||
e4524bda0b | |||
226fb15eb1 | |||
645c4af2f2 | |||
6e0f41c7fd | |||
b9001ed9b2 | |||
04abf59521 | |||
251f92532d | |||
f5df56687b | |||
b582da90e5 | |||
815f48fe06 | |||
1470fa87dd | |||
4b4356aaab | |||
a8658856ca | |||
1477e907e6 | |||
f559cea826 | |||
d363042036 | |||
69e4ecd0a9 | |||
35d2e06625 | |||
358e654f51 | |||
d16548e570 | |||
c7201dd62c | |||
e43a0e62b7 | |||
4bcf76819c | |||
31155c909c | |||
ab2670358a | |||
3da70bdccc | |||
e370e1937c | |||
d9f6dd33d4 | |||
e5d6e549bd | |||
145c0ce6c8 | |||
a0174b94c6 | |||
109b489104 | |||
784c3fc338 | |||
77d6ac2caf | |||
321af22775 | |||
39ef9815e8 | |||
bb3afba11f | |||
e4fa160a90 | |||
34df9e2257 | |||
cfdb5f021e | |||
d08eea5c1e | |||
ce30b5427b | |||
e38fed89e9 | |||
d4b12bf3f7 | |||
40d75a91c6 |
Binary file not shown.
BIN
Assets/Animations/IConfig.anim
Normal file
BIN
Assets/Animations/IConfig.anim
Normal file
Binary file not shown.
8
Assets/Animations/IConfig.anim.meta
Normal file
8
Assets/Animations/IConfig.anim.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2e0c61e29fd90f04b9e41265d93e2029
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 7400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
BIN
Assets/Animations/TConfig_Main.anim
Normal file
BIN
Assets/Animations/TConfig_Main.anim
Normal file
Binary file not shown.
8
Assets/Animations/TConfig_Main.anim.meta
Normal file
8
Assets/Animations/TConfig_Main.anim.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d815e4d844e6a1c4d849e96e199f8881
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 7400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
BIN
Assets/Animations/TMain_Config.anim
Normal file
BIN
Assets/Animations/TMain_Config.anim
Normal file
Binary file not shown.
8
Assets/Animations/TMain_Config.anim.meta
Normal file
8
Assets/Animations/TMain_Config.anim.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 82867c59112ff5a419fbea2ebff2d3b9
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 7400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
|
|
||||||
[assembly: AssemblyCompany("Cryville")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © Cryville 2020-2022")]
|
|
||||||
[assembly: AssemblyDefaultAlias("Cosmo Resona")]
|
|
||||||
[assembly: AssemblyProduct("Cosmo Resona")]
|
|
||||||
[assembly: AssemblyTitle("Cosmo Resona")]
|
|
||||||
[assembly: AssemblyVersion("0.5.0")]
|
|
Binary file not shown.
@@ -33,12 +33,12 @@ namespace Cryville.Common {
|
|||||||
public override object ChangeType(object value, Type type, CultureInfo culture) {
|
public override object ChangeType(object value, Type type, CultureInfo culture) {
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return null;
|
return null;
|
||||||
else if (type == value.GetType())
|
else if (type.IsAssignableFrom(value.GetType()))
|
||||||
return value;
|
return value;
|
||||||
else if (type.IsEnum && value is string) {
|
else if (type.IsEnum && value is string) {
|
||||||
return Enum.Parse(type, (string)value);
|
return Enum.Parse(type, (string)value);
|
||||||
}
|
}
|
||||||
throw new InvalidCastException();
|
throw new InvalidCastException(string.Format("Cannot cast {0} to {1}", value.GetType(), type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReorderArgumentArray(ref object[] args, object state) {
|
public override void ReorderArgumentArray(ref object[] args, object state) {
|
||||||
|
90
Assets/Cryville/Common/Buffers/CategorizedPool.cs
Normal file
90
Assets/Cryville/Common/Buffers/CategorizedPool.cs
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
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,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d6a3a023271b82a4985d1bbcc86e6fa8
|
guid: ec18f22479042d747b88c093aa90c5c0
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -14,6 +14,10 @@
|
|||||||
_objs = new T[capacity];
|
_objs = new T[capacity];
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The count of objects rented from the pool.
|
||||||
|
/// </summary>
|
||||||
|
public int RentedCount { get { return _index; } }
|
||||||
|
/// <summary>
|
||||||
/// Rents a object from the pool.
|
/// Rents a object from the pool.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The rented object.</returns>
|
/// <returns>The rented object.</returns>
|
||||||
@@ -24,6 +28,7 @@
|
|||||||
_objs[_index++] = null;
|
_objs[_index++] = null;
|
||||||
}
|
}
|
||||||
if (obj == null) obj = Construct();
|
if (obj == null) obj = Construct();
|
||||||
|
else Reset(obj);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -38,5 +43,10 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The new instance.</returns>
|
/// <returns>The new instance.</returns>
|
||||||
protected abstract T Construct();
|
protected abstract T Construct();
|
||||||
|
/// <summary>
|
||||||
|
/// Resets an object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The object.</param>
|
||||||
|
protected virtual void Reset(T obj) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
135
Assets/Cryville/Common/Buffers/TargetString.cs
Normal file
135
Assets/Cryville/Common/Buffers/TargetString.cs
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
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,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 9ed0687e714ce1042921c0057f42039f
|
guid: f0fc34ac257793d4883a9cfcdb6941b9
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
@@ -1,9 +1,8 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: abad95983f1ca394a92bb061b76ebb2f
|
guid: 520554ce9a8205b4b91e0ff2b8011673
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
timeCreated: 1638411493
|
|
||||||
licenseType: Free
|
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
assetBundleVariant:
|
assetBundleVariant:
|
37
Assets/Cryville/Common/Culture/ScriptUtils.cs
Normal file
37
Assets/Cryville/Common/Culture/ScriptUtils.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Culture {
|
||||||
|
public static class ScriptUtils {
|
||||||
|
public static string[] Scripts = new string[] { "adlm", "afak", "aghb", "ahom", "arab", "aran", "armi", "armn", "avst", "bali", "bamu", "bass", "batk", "beng", "bhks", "blis", "bopo", "brah", "brai", "bugi", "buhd", "cakm", "cans", "cari", "cham", "cher", "chrs", "cirt", "copt", "cpmn", "cprt", "cyrl", "cyrs", "deva", "diak", "dogr", "dsrt", "dupl", "egyd", "egyh", "egyp", "elba", "elym", "ethi", "geok", "geor", "glag", "gong", "gonm", "goth", "gran", "grek", "gujr", "guru", "hanb", "hang", "hani", "hano", "hans", "hant", "hatr", "hebr", "hira", "hluw", "hmng", "hmnp", "hrkt", "hung", "inds", "ital", "jamo", "java", "jpan", "jurc", "kali", "kana", "khar", "khmr", "khoj", "kitl", "kits", "knda", "kore", "kpel", "kthi", "lana", "laoo", "latf", "latg", "latn", "leke", "lepc", "limb", "lina", "linb", "lisu", "loma", "lyci", "lydi", "mahj", "maka", "mand", "mani", "marc", "maya", "medf", "mend", "merc", "mero", "mlym", "modi", "mong", "moon", "mroo", "mtei", "mult", "mymr", "nand", "narb", "nbat", "newa", "nkdb", "nkgb", "nkoo", "nshu", "ogam", "olck", "orkh", "orya", "osge", "osma", "ougr", "palm", "pauc", "pcun", "pelm", "perm", "phag", "phli", "phlp", "phlv", "phnx", "piqd", "plrd", "prti", "psin", "qaaa", "qaai", "qabx", "ranj", "rjng", "rohg", "roro", "runr", "samr", "sara", "sarb", "saur", "sgnw", "shaw", "shrd", "shui", "sidd", "sind", "sinh", "sogd", "sogo", "sora", "soyo", "sund", "sylo", "syrc", "syre", "syrj", "syrn", "tagb", "takr", "tale", "talu", "taml", "tang", "tavt", "telu", "teng", "tfng", "tglg", "thaa", "thai", "tibt", "tirh", "toto", "ugar", "vaii", "visp", "wara", "wcho", "wole", "xpeo", "xsux", "yezi", "yiii", "zanb", "zinh", "zmth", "zsye", "zsym", "zxxx", "zyyy", "zzzz", };
|
||||||
|
public static string UltimateFallbackScript = "zyyy";
|
||||||
|
public static Dictionary<string, string[]> FallbackScriptMap = new Dictionary<string, string[]> {
|
||||||
|
{ "aran", new string[] { "arab" } }, { "cyrs", new string[] { "cyrl" } },
|
||||||
|
{ "hanb", new string[] { "hant", "bopo" } }, { "hans", new string[] { "hani" } }, { "hant", new string[] { "hani" } },
|
||||||
|
{ "hrkt", new string[] { "hira", "kana" } }, { "jpan", new string[] { "hani", "hira", "kana" } },
|
||||||
|
{ "jamo", new string[] { "hang" } }, { "kore", new string[] { "hang", "hani" } },
|
||||||
|
{ "latf", new string[] { "latn" } }, { "latg", new string[] { "latn" } },
|
||||||
|
{ "syre", new string[] { "syrc" } }, { "syrj", new string[] { "syrc" } }, { "syrn", new string[] { "syrc" } },
|
||||||
|
{ "zsye", new string[] { "zsym" } },
|
||||||
|
};
|
||||||
|
public static void FillKeysWithScripts(IDictionary dict, Func<object> value) {
|
||||||
|
foreach (var s in Scripts) dict.Add(s, value());
|
||||||
|
}
|
||||||
|
public static IEnumerable<string> EnumerateFallbackScripts(string script) {
|
||||||
|
if (string.IsNullOrEmpty(script)) throw new ArgumentNullException("script");
|
||||||
|
script = script.ToLower();
|
||||||
|
if (script == UltimateFallbackScript) {
|
||||||
|
yield return null;
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
string[] fblist;
|
||||||
|
if (FallbackScriptMap.TryGetValue(script, out fblist)) {
|
||||||
|
foreach (var fb in fblist) {
|
||||||
|
yield return fb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else yield return UltimateFallbackScript;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,7 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 58e01e1e11af164408a19c1086709bd7
|
guid: ae9dab8f520fadc4194032f523ca87c1
|
||||||
timeCreated: 1638411495
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences: []
|
defaultReferences: []
|
||||||
executionOrder: 0
|
executionOrder: 0
|
113
Assets/Cryville/Common/Font/FontFile.cs
Normal file
113
Assets/Cryville/Common/Font/FontFile.cs
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
using Cryville.Common.IO;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Font {
|
||||||
|
public abstract class FontFile : IEnumerable<Typeface> {
|
||||||
|
public abstract int Count { get; }
|
||||||
|
public abstract Typeface this[int index] { get; }
|
||||||
|
protected FileInfo File { get; private set; }
|
||||||
|
protected BinaryReader Reader { get; private set; }
|
||||||
|
public FontFile(FileInfo file) {
|
||||||
|
File = file;
|
||||||
|
Reader = new BinaryReaderBE(new FileStream(file.FullName, FileMode.Open, FileAccess.Read));
|
||||||
|
}
|
||||||
|
public void Close() { Reader.Close(); }
|
||||||
|
|
||||||
|
public static FontFile Create(FileInfo file) {
|
||||||
|
switch (file.Extension) {
|
||||||
|
case ".ttf": case ".otf": return new FontFileTTF(file);
|
||||||
|
case ".ttc": case ".otc": return new FontFileTTC(file);
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Enumerator GetEnumerator() {
|
||||||
|
return new Enumerator(this);
|
||||||
|
}
|
||||||
|
IEnumerator<Typeface> IEnumerable<Typeface>.GetEnumerator() {
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() {
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct Enumerator : IEnumerator<Typeface> {
|
||||||
|
readonly FontFile _self;
|
||||||
|
int _index;
|
||||||
|
internal Enumerator(FontFile self) {
|
||||||
|
_self = self;
|
||||||
|
_index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Typeface 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.Count) {
|
||||||
|
_index = -2;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset() {
|
||||||
|
_index = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class FontFileTTF : FontFile {
|
||||||
|
public override int Count { get { return 1; } }
|
||||||
|
public override Typeface this[int index] {
|
||||||
|
get {
|
||||||
|
if (index != 0) throw new ArgumentOutOfRangeException("index");
|
||||||
|
try {
|
||||||
|
return new TypefaceTTF(Reader, File, index);
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
throw new InvalidDataException("Invalid font");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public FontFileTTF(FileInfo file) : base(file) { }
|
||||||
|
}
|
||||||
|
public class FontFileTTC : FontFile {
|
||||||
|
readonly IReadOnlyList<uint> _offsets;
|
||||||
|
public override int Count { get { return _offsets.Count; } }
|
||||||
|
public override Typeface this[int index] {
|
||||||
|
get {
|
||||||
|
if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException("index");
|
||||||
|
Reader.BaseStream.Position = _offsets[index];
|
||||||
|
try {
|
||||||
|
return new TypefaceTTF(Reader, File, index);
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
throw new InvalidDataException("Invalid font");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public FontFileTTC(FileInfo file) : base(file) {
|
||||||
|
try {
|
||||||
|
_offsets = new TTCHeader(Reader, 0).GetItems();
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
throw new InvalidDataException("Invalid font");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Font/FontFile.cs.meta
Normal file
11
Assets/Cryville/Common/Font/FontFile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c9f44ccf8ddd364418b4f4965414ff9c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
63
Assets/Cryville/Common/Font/FontManager.cs
Normal file
63
Assets/Cryville/Common/Font/FontManager.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Font {
|
||||||
|
public abstract class FontManager {
|
||||||
|
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapFullNameToTypeface { get; private set; }
|
||||||
|
public IReadOnlyDictionary<string, IReadOnlyCollection<Typeface>> MapNameToTypefaces { get; private set; }
|
||||||
|
public FontManager() {
|
||||||
|
var map1 = new Dictionary<string, List<Typeface>>();
|
||||||
|
var map2 = new Dictionary<string, List<Typeface>>();
|
||||||
|
foreach (var f in EnumerateAllTypefaces()) {
|
||||||
|
List<Typeface> set1;
|
||||||
|
if (!map1.TryGetValue(f.FullName, out set1)) {
|
||||||
|
map1.Add(f.FullName, set1 = new List<Typeface>());
|
||||||
|
}
|
||||||
|
set1.Add(f);
|
||||||
|
List<Typeface> set2;
|
||||||
|
if (!map2.TryGetValue(f.FamilyName, out set2)) {
|
||||||
|
map2.Add(f.FamilyName, set2 = new List<Typeface>());
|
||||||
|
}
|
||||||
|
set2.Add(f);
|
||||||
|
}
|
||||||
|
MapFullNameToTypeface = map1.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
|
||||||
|
MapNameToTypefaces = map2.ToDictionary(i => i.Key, i => (IReadOnlyCollection<Typeface>)i.Value);
|
||||||
|
}
|
||||||
|
protected abstract IEnumerable<Typeface> EnumerateAllTypefaces();
|
||||||
|
protected static IEnumerable<Typeface> ScanDirectoryForTypefaces(string dir) {
|
||||||
|
foreach (var f in new DirectoryInfo(dir).EnumerateFiles()) {
|
||||||
|
FontFile file;
|
||||||
|
try {
|
||||||
|
file = FontFile.Create(f);
|
||||||
|
}
|
||||||
|
catch (InvalidDataException) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (file == null) continue;
|
||||||
|
var enumerator = file.GetEnumerator();
|
||||||
|
while (enumerator.MoveNext()) {
|
||||||
|
Typeface ret;
|
||||||
|
try {
|
||||||
|
ret = enumerator.Current;
|
||||||
|
}
|
||||||
|
catch (InvalidDataException) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
yield return ret;
|
||||||
|
}
|
||||||
|
file.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class FontManagerAndroid : FontManager {
|
||||||
|
protected override IEnumerable<Typeface> EnumerateAllTypefaces() {
|
||||||
|
return ScanDirectoryForTypefaces("/system/fonts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class FontManagerWindows : FontManager {
|
||||||
|
protected override IEnumerable<Typeface> EnumerateAllTypefaces() {
|
||||||
|
return ScanDirectoryForTypefaces("C:/Windows/Fonts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
329
Assets/Cryville/Common/Font/FontMatcher.cs
Normal file
329
Assets/Cryville/Common/Font/FontMatcher.cs
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
using Cryville.Common.Culture;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Font {
|
||||||
|
public abstract class FontMatcher {
|
||||||
|
protected FontManager Manager { get; private set; }
|
||||||
|
public FontMatcher(FontManager manafer) { Manager = manafer; }
|
||||||
|
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>());
|
||||||
|
// 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");
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
// SP2
|
||||||
|
MapScriptToTypefaces["beng"].Insert(0, "Vrinda");
|
||||||
|
MapScriptToTypefaces["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");
|
||||||
|
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
|
||||||
|
MapScriptToTypefaces["jpan"].Insert(0, "Meiryo");
|
||||||
|
MapScriptToTypefaces["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");
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
// 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");
|
||||||
|
//
|
||||||
|
MapScriptToTypefaces["jpan"].Insert(0, "Yu Gothic UI");
|
||||||
|
MapScriptToTypefaces["zsym"].Add("Segoe MDL2 Assets");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 FallbackListFontMatcher(FontManager manager) : base(manager) { }
|
||||||
|
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {
|
||||||
|
if (string.IsNullOrEmpty(script)) script = ScriptUtils.UltimateFallbackScript;
|
||||||
|
List<string> candidates;
|
||||||
|
IEnumerable<string> candidateScripts = new string[] { script };
|
||||||
|
while (candidateScripts != null) {
|
||||||
|
foreach (var candidateScript in candidateScripts) {
|
||||||
|
if (MapScriptToTypefaces.TryGetValue(candidateScript, out candidates)) {
|
||||||
|
foreach (var candidate in candidates) {
|
||||||
|
IReadOnlyCollection<Typeface> typefaces1;
|
||||||
|
if (Manager.MapFullNameToTypeface.TryGetValue(candidate, out typefaces1)) {
|
||||||
|
foreach (var typeface in typefaces1) {
|
||||||
|
yield return typeface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (distinctFamily) continue;
|
||||||
|
IReadOnlyCollection<Typeface> typefaces2;
|
||||||
|
if (Manager.MapNameToTypefaces.TryGetValue(candidate, out typefaces2)) {
|
||||||
|
foreach (var typeface in typefaces2) {
|
||||||
|
if (typefaces1.Contains(typeface)) continue;
|
||||||
|
yield return typeface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
candidateScripts = ScriptUtils.EnumerateFallbackScripts(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Font/FontMatcher.cs.meta
Normal file
11
Assets/Cryville/Common/Font/FontMatcher.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: afcde0ad1865db24da79ca1ce7256791
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
222
Assets/Cryville/Common/Font/FontTable.cs
Normal file
222
Assets/Cryville/Common/Font/FontTable.cs
Normal file
@@ -0,0 +1,222 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Font {
|
||||||
|
public abstract class FontTable<T> {
|
||||||
|
protected UInt32 Offset { get; private set; }
|
||||||
|
protected BinaryReader Reader { get; private set; }
|
||||||
|
|
||||||
|
protected FontTable(BinaryReader reader, UInt32 offset) {
|
||||||
|
Reader = reader;
|
||||||
|
Offset = offset;
|
||||||
|
reader.BaseStream.Position = offset;
|
||||||
|
}
|
||||||
|
public abstract IReadOnlyList<T> GetItems();
|
||||||
|
}
|
||||||
|
public abstract class FontTable<T, U> : FontTable<T> {
|
||||||
|
protected FontTable(BinaryReader reader, UInt32 offset) : base(reader, offset) { }
|
||||||
|
public abstract U GetSubTable(T item);
|
||||||
|
}
|
||||||
|
public sealed class TTCHeader : FontTable<UInt32, TableDirectory> {
|
||||||
|
readonly String ttcTag;
|
||||||
|
readonly UInt16 majorVersion;
|
||||||
|
readonly UInt16 minorVersion;
|
||||||
|
readonly UInt32 numFonts;
|
||||||
|
readonly List<UInt32> tableDirectoryOffsets = new List<UInt32>();
|
||||||
|
readonly String dsigTag;
|
||||||
|
readonly UInt32 dsigLength;
|
||||||
|
readonly UInt32 dsigOffset;
|
||||||
|
public TTCHeader(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
|
ttcTag = reader.ReadTag();
|
||||||
|
if (ttcTag != "ttcf") throw new NotImplementedException();
|
||||||
|
majorVersion = reader.ReadUInt16();
|
||||||
|
minorVersion = reader.ReadUInt16();
|
||||||
|
numFonts = reader.ReadUInt32();
|
||||||
|
for (UInt32 i = 0; i < numFonts; i++) tableDirectoryOffsets.Add(reader.ReadUInt32());
|
||||||
|
if (majorVersion == 2) {
|
||||||
|
dsigTag = reader.ReadTag();
|
||||||
|
dsigLength = reader.ReadUInt32();
|
||||||
|
dsigOffset = reader.ReadUInt32();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override IReadOnlyList<UInt32> GetItems() {
|
||||||
|
return tableDirectoryOffsets;
|
||||||
|
}
|
||||||
|
public override TableDirectory GetSubTable(UInt32 item) {
|
||||||
|
var i = (UInt32)item;
|
||||||
|
return new TableDirectory(Reader, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public sealed class TableDirectory : FontTable<TableRecord, object> {
|
||||||
|
readonly UInt32 sfntVersion;
|
||||||
|
readonly UInt16 numTables;
|
||||||
|
readonly UInt16 searchRange;
|
||||||
|
readonly UInt16 entrySelector;
|
||||||
|
readonly UInt16 rangeShift;
|
||||||
|
readonly List<TableRecord> tableRecords = new List<TableRecord>();
|
||||||
|
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
|
sfntVersion = reader.ReadUInt32();
|
||||||
|
numTables = reader.ReadUInt16();
|
||||||
|
searchRange = reader.ReadUInt16();
|
||||||
|
entrySelector = reader.ReadUInt16();
|
||||||
|
rangeShift = reader.ReadUInt16();
|
||||||
|
for (int i = 0; i < numTables; i++)
|
||||||
|
tableRecords.Add(new TableRecord {
|
||||||
|
tableTag = reader.ReadTag(),
|
||||||
|
checksum = reader.ReadUInt32(),
|
||||||
|
offset = reader.ReadUInt32(),
|
||||||
|
length = reader.ReadUInt32(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public override IReadOnlyList<TableRecord> GetItems() {
|
||||||
|
return tableRecords;
|
||||||
|
}
|
||||||
|
public override object GetSubTable(TableRecord item) {
|
||||||
|
switch (item.tableTag) {
|
||||||
|
case "name": return new NameTable(Reader, item.offset);
|
||||||
|
case "meta": return new MetaTable(Reader, item.offset);
|
||||||
|
default: throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public struct TableRecord {
|
||||||
|
public string tableTag;
|
||||||
|
public UInt32 checksum;
|
||||||
|
public UInt32 offset;
|
||||||
|
public UInt32 length;
|
||||||
|
}
|
||||||
|
public sealed class NameTable : FontTable<NameRecord> {
|
||||||
|
readonly UInt16 version;
|
||||||
|
readonly UInt16 count;
|
||||||
|
readonly UInt16 storageOffset;
|
||||||
|
readonly List<NameRecord> nameRecord = new List<NameRecord>();
|
||||||
|
readonly UInt16 langTagCount;
|
||||||
|
readonly List<LangTagRecord> langTagRecord = new List<LangTagRecord>();
|
||||||
|
public NameTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
|
version = reader.ReadUInt16();
|
||||||
|
count = reader.ReadUInt16();
|
||||||
|
storageOffset = reader.ReadUInt16();
|
||||||
|
for (UInt16 i = 0; i < count; i++)
|
||||||
|
nameRecord.Add(new NameRecord {
|
||||||
|
platformID = reader.ReadUInt16(),
|
||||||
|
encodingID = reader.ReadUInt16(),
|
||||||
|
languageID = reader.ReadUInt16(),
|
||||||
|
nameID = (NameID)reader.ReadUInt16(),
|
||||||
|
length = reader.ReadUInt16(),
|
||||||
|
stringOffset = reader.ReadUInt16(),
|
||||||
|
});
|
||||||
|
if (version == 1) {
|
||||||
|
langTagCount = reader.ReadUInt16();
|
||||||
|
for (UInt16 i = 0; i < langTagCount; i++)
|
||||||
|
langTagRecord.Add(new LangTagRecord {
|
||||||
|
length = reader.ReadUInt16(),
|
||||||
|
langTagOffset = reader.ReadUInt16(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
UInt32 origin = (UInt32)reader.BaseStream.Position;
|
||||||
|
for (int i = 0; i < nameRecord.Count; i++) nameRecord[i] = nameRecord[i].Load(reader, origin);
|
||||||
|
for (int i = 0; i < langTagRecord.Count; i++) langTagRecord[i] = langTagRecord[i].Load(reader, origin);
|
||||||
|
}
|
||||||
|
public sealed override IReadOnlyList<NameRecord> GetItems() {
|
||||||
|
return nameRecord;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public struct NameRecord {
|
||||||
|
public UInt16 platformID;
|
||||||
|
public UInt16 encodingID;
|
||||||
|
public UInt16 languageID;
|
||||||
|
public NameID nameID;
|
||||||
|
public UInt16 length;
|
||||||
|
public UInt16 stringOffset;
|
||||||
|
public String value { get; private set; }
|
||||||
|
public NameRecord Load(BinaryReader reader, UInt32 origin) {
|
||||||
|
reader.BaseStream.Position = origin + stringOffset;
|
||||||
|
Encoding encoding;
|
||||||
|
switch (platformID) {
|
||||||
|
case 0: encoding = Encoding.BigEndianUnicode; break;
|
||||||
|
case 3: encoding = Encoding.BigEndianUnicode; break;
|
||||||
|
default: return this;
|
||||||
|
}
|
||||||
|
value = encoding.GetString(reader.ReadBytes(length));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public enum NameID : UInt16 {
|
||||||
|
CopyrightNotice = 0,
|
||||||
|
FontFamilyName = 1,
|
||||||
|
FontSubfamilyName = 2,
|
||||||
|
UniqueFontIdentifier = 3,
|
||||||
|
FullFontName = 4,
|
||||||
|
VersionString = 5,
|
||||||
|
PostScriptName = 6,
|
||||||
|
Trademark = 7,
|
||||||
|
ManufacturerName = 8,
|
||||||
|
Designer = 9,
|
||||||
|
Description = 10,
|
||||||
|
URLVendor = 11,
|
||||||
|
URLDesigner = 12,
|
||||||
|
LicenseDescription = 13,
|
||||||
|
LicenseInfoURL = 14,
|
||||||
|
|
||||||
|
TypographicFamilyName = 16,
|
||||||
|
TypographicSubfamilyName = 17,
|
||||||
|
CompatibleFull = 18,
|
||||||
|
SampleText = 19,
|
||||||
|
PostScriptCIDFindfontName = 20,
|
||||||
|
WWSFamilyName = 21,
|
||||||
|
WWSSubfamilyName = 22,
|
||||||
|
LightBackgroundPalette = 23,
|
||||||
|
DarkBackgroundPalette = 24,
|
||||||
|
VariationsPostScriptNamePrefix = 25,
|
||||||
|
}
|
||||||
|
public struct LangTagRecord {
|
||||||
|
public UInt16 length;
|
||||||
|
public UInt16 langTagOffset;
|
||||||
|
public String value { get; private set; }
|
||||||
|
public LangTagRecord Load(BinaryReader reader, UInt32 origin) {
|
||||||
|
reader.BaseStream.Position = origin + langTagOffset;
|
||||||
|
value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(length));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public sealed class MetaTable : FontTable<DataMap> {
|
||||||
|
readonly UInt32 version;
|
||||||
|
readonly UInt32 flags;
|
||||||
|
readonly UInt32 dataMapCount;
|
||||||
|
readonly List<DataMap> dataMaps = new List<DataMap>();
|
||||||
|
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
|
||||||
|
version = reader.ReadUInt32();
|
||||||
|
flags = reader.ReadUInt32();
|
||||||
|
reader.ReadUInt32();
|
||||||
|
dataMapCount = reader.ReadUInt32();
|
||||||
|
for (UInt32 i = 0; i < dataMapCount; i++)
|
||||||
|
dataMaps.Add(new DataMap {
|
||||||
|
tag = reader.ReadTag(),
|
||||||
|
dataOffset = reader.ReadUInt32(),
|
||||||
|
dataLength = reader.ReadUInt32(),
|
||||||
|
});
|
||||||
|
for (int i = 0; i < dataMaps.Count; i++) dataMaps[i] = dataMaps[i].Load(reader, offset);
|
||||||
|
}
|
||||||
|
public sealed override IReadOnlyList<DataMap> GetItems() {
|
||||||
|
return dataMaps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public struct DataMap {
|
||||||
|
public String tag;
|
||||||
|
public UInt32 dataOffset;
|
||||||
|
public UInt32 dataLength;
|
||||||
|
public String value { get; private set; }
|
||||||
|
public DataMap Load(BinaryReader reader, UInt32 origin) {
|
||||||
|
reader.BaseStream.Position = origin + dataOffset;
|
||||||
|
value = Encoding.ASCII.GetString(reader.ReadBytes((int)dataLength));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static class BinaryReaderExtensions {
|
||||||
|
public static string ReadTag(this BinaryReader reader) {
|
||||||
|
return Encoding.ASCII.GetString(reader.ReadBytes(4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Font/FontTable.cs.meta
Normal file
11
Assets/Cryville/Common/Font/FontTable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3eed6aa2387582346b7b21c6f8de5e1f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,9 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace Cryville.Common.Font {
|
|
||||||
public static class FontUtil {
|
|
||||||
/*public static string MatchFontNameWithLang(string lang) {
|
|
||||||
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
31
Assets/Cryville/Common/Font/Typeface.cs
Normal file
31
Assets/Cryville/Common/Font/Typeface.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Font {
|
||||||
|
public abstract class Typeface {
|
||||||
|
public FileInfo File { get; private set; }
|
||||||
|
public int IndexInFile { get; private set; }
|
||||||
|
public string FamilyName { get; protected set; }
|
||||||
|
public string SubfamilyName { get; protected set; }
|
||||||
|
public string FullName { get; protected set; }
|
||||||
|
protected abstract void GetName(BinaryReader reader);
|
||||||
|
|
||||||
|
public Typeface(BinaryReader reader, FileInfo file, int index) {
|
||||||
|
File = file;
|
||||||
|
IndexInFile = index;
|
||||||
|
GetName(reader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class TypefaceTTF : Typeface {
|
||||||
|
public TypefaceTTF(BinaryReader reader, FileInfo file, int index)
|
||||||
|
: base(reader, file, index) { }
|
||||||
|
|
||||||
|
protected override void GetName(BinaryReader reader) {
|
||||||
|
var dir = new TableDirectory(reader, (uint)reader.BaseStream.Position);
|
||||||
|
var nameTable = (NameTable)dir.GetSubTable((from i in dir.GetItems() where i.tableTag == "name" select i).Single());
|
||||||
|
FamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontFamilyName && i.value != null select i.value).First();
|
||||||
|
SubfamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontSubfamilyName && i.value != null select i.value).First();
|
||||||
|
FullName = (from i in nameTable.GetItems() where i.nameID == NameID.FullFontName && i.value != null select i.value).First();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Font/Typeface.cs.meta
Normal file
11
Assets/Cryville/Common/Font/Typeface.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0968fc12b50cffb4682f0c28d0d14703
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
8
Assets/Cryville/Common/IO.meta
Normal file
8
Assets/Cryville/Common/IO.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aaa0d8cecafb37b46a6abe372cfefd93
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
75
Assets/Cryville/Common/IO/BinaryReaderBE.cs
Normal file
75
Assets/Cryville/Common/IO/BinaryReaderBE.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Cryville.Common.IO {
|
||||||
|
public class BinaryReaderBE : BinaryReader {
|
||||||
|
readonly byte[] m_buffer = new byte[8];
|
||||||
|
|
||||||
|
public BinaryReaderBE(Stream input) : base(input) { }
|
||||||
|
|
||||||
|
public BinaryReaderBE(Stream input, Encoding encoding) : base(input, encoding) { }
|
||||||
|
|
||||||
|
public BinaryReaderBE(Stream input, Encoding encoding, bool leaveOpen) : base(input, encoding, leaveOpen) { }
|
||||||
|
|
||||||
|
public override short ReadInt16() {
|
||||||
|
FillBuffer(2);
|
||||||
|
return (short)(m_buffer[1] | (m_buffer[0] << 8));
|
||||||
|
}
|
||||||
|
public override ushort ReadUInt16() {
|
||||||
|
FillBuffer(2);
|
||||||
|
return (ushort)(m_buffer[1] | (m_buffer[0] << 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int ReadInt32() {
|
||||||
|
FillBuffer(4);
|
||||||
|
return m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24);
|
||||||
|
}
|
||||||
|
public override uint ReadUInt32() {
|
||||||
|
FillBuffer(4);
|
||||||
|
return (uint)(m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override long ReadInt64() {
|
||||||
|
FillBuffer(8);
|
||||||
|
uint num = (uint)(m_buffer[7] | (m_buffer[6] << 8) | (m_buffer[5] << 16) | (m_buffer[4] << 24));
|
||||||
|
uint num2 = (uint)(m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24));
|
||||||
|
return (long)(((ulong)num2 << 32) | num);
|
||||||
|
}
|
||||||
|
public override ulong ReadUInt64() {
|
||||||
|
FillBuffer(8);
|
||||||
|
uint num = (uint)(m_buffer[7] | (m_buffer[6] << 8) | (m_buffer[5] << 16) | (m_buffer[4] << 24));
|
||||||
|
uint num2 = (uint)(m_buffer[3] | (m_buffer[2] << 8) | (m_buffer[1] << 16) | (m_buffer[0] << 24));
|
||||||
|
return ((ulong)num2 << 32) | num;
|
||||||
|
}
|
||||||
|
protected new void FillBuffer(int numBytes) {
|
||||||
|
if (m_buffer != null && (numBytes < 0 || numBytes > m_buffer.Length)) {
|
||||||
|
throw new ArgumentOutOfRangeException("numBytes", "Requested numBytes is larger than the internal buffer size");
|
||||||
|
}
|
||||||
|
|
||||||
|
int num = 0, num2;
|
||||||
|
if (BaseStream == null) {
|
||||||
|
throw new IOException("File not open");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numBytes == 1) {
|
||||||
|
num2 = BaseStream.ReadByte();
|
||||||
|
if (num2 == -1) {
|
||||||
|
throw new EndOfStreamException("The end of the stream is reached before numBytes could be read");
|
||||||
|
}
|
||||||
|
m_buffer[0] = (byte)num2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
num2 = BaseStream.Read(m_buffer, num, numBytes - num);
|
||||||
|
if (num2 == 0) {
|
||||||
|
throw new EndOfStreamException("The end of the stream is reached before numBytes could be read");
|
||||||
|
}
|
||||||
|
|
||||||
|
num += num2;
|
||||||
|
}
|
||||||
|
while (num < numBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/IO/BinaryReaderBE.cs.meta
Normal file
11
Assets/Cryville/Common/IO/BinaryReaderBE.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aee537c74ab935940b54cb5d784b7f56
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -24,11 +24,11 @@ namespace Cryville.Common {
|
|||||||
if (Key == 0) return "";
|
if (Key == 0) return "";
|
||||||
return Name.ToString();
|
return Name.ToString();
|
||||||
}
|
}
|
||||||
public static implicit operator Identifier(string identifier) {
|
public static bool operator ==(Identifier lhs, Identifier rhs) {
|
||||||
return new Identifier(identifier);
|
return lhs.Equals(rhs);
|
||||||
}
|
}
|
||||||
public static implicit operator string(Identifier identifier) {
|
public static bool operator !=(Identifier lhs, Identifier rhs) {
|
||||||
return identifier.ToString();
|
return !lhs.Equals(rhs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,10 +10,10 @@ namespace Cryville.Common {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static IdentifierManager SharedInstance = new IdentifierManager();
|
public static IdentifierManager SharedInstance = new IdentifierManager();
|
||||||
|
|
||||||
Dictionary<object, int> _idents = new Dictionary<object, int>();
|
readonly Dictionary<object, int> _idents = new Dictionary<object, int>();
|
||||||
List<object> _ids = new List<object>();
|
readonly List<object> _ids = new List<object>();
|
||||||
|
|
||||||
object _syncRoot = new object();
|
readonly object _syncRoot = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the <see cref="IdentifierManager" /> class.
|
/// Creates an instance of the <see cref="IdentifierManager" /> class.
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Cryville.Common {
|
namespace Cryville.Common {
|
||||||
@@ -40,7 +41,7 @@ namespace Cryville.Common {
|
|||||||
public static void Create(string key, Logger logger) {
|
public static void Create(string key, Logger logger) {
|
||||||
Instances[key] = logger;
|
Instances[key] = logger;
|
||||||
if (logPath != null) {
|
if (logPath != null) {
|
||||||
Files[key] = new StreamWriter(logPath + "/" + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString() + "-" + key + ".log") {
|
Files[key] = new StreamWriter(logPath + "/" + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture) + "-" + key + ".log") {
|
||||||
AutoFlush = true
|
AutoFlush = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -54,16 +54,13 @@ namespace Cryville.Common.Math {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="System.Single" /> column vector and fills it with polynomial coefficients.
|
/// Fills a <see cref="System.Single" /> column vector with polynomial coefficients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="size">The size of the column vector.</param>
|
/// <param name="vec">The column vector.</param>
|
||||||
/// <param name="num">The base number.</param>
|
/// <param name="num">The base number.</param>
|
||||||
/// <returns>A <see cref="System.Single" /> column vector filled with polynomial coefficients.</returns>
|
public static void FillWithPolynomialCoefficients(ColumnVector<float> vec, float num) {
|
||||||
public static ColumnVector<float> WithPolynomialCoefficients(int size, float num) {
|
for (var i = 0; i < vec.Size; i++)
|
||||||
var m = new ColumnVector<float>(size);
|
vec[i] = (float)System.Math.Pow(num, i);
|
||||||
for (var i = 0; i < size; i++)
|
|
||||||
m[i] = (float)System.Math.Pow(num, i);
|
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -48,5 +48,31 @@ namespace Cryville.Common.Math {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the greatest common divisor (GCD) of two integers.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="n">The first integer.</param>
|
||||||
|
/// <param name="d">The second integer.</param>
|
||||||
|
/// <returns>The greatest common divisor (GCD) of the two integers.</returns>
|
||||||
|
public static int GreatestCommonDivisor(int n, int d) {
|
||||||
|
while (d != 0) {
|
||||||
|
int t = d;
|
||||||
|
d = n % d;
|
||||||
|
n = t;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Simplifies a fraction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="n">The numerator.</param>
|
||||||
|
/// <param name="d">The denominator.</param>
|
||||||
|
public static void Simplify(ref int n, ref int d) {
|
||||||
|
var gcd = GreatestCommonDivisor(n, d);
|
||||||
|
n /= gcd;
|
||||||
|
d /= gcd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,13 @@
|
|||||||
namespace Cryville.Common.Math {
|
using UnsafeIL;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Math {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a square matrix.
|
/// Represents a square matrix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SquareMatrix {
|
public class SquareMatrix {
|
||||||
readonly float[,] content;
|
readonly float[,] content;
|
||||||
|
readonly float[,] buffer;
|
||||||
|
readonly int[] refl;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The size of the matrix.
|
/// The size of the matrix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -17,6 +21,8 @@
|
|||||||
/// <param name="size">The size of the matrix.</param>
|
/// <param name="size">The size of the matrix.</param>
|
||||||
public SquareMatrix(int size) {
|
public SquareMatrix(int size) {
|
||||||
content = new float[size, size];
|
content = new float[size, size];
|
||||||
|
buffer = new float[size, size];
|
||||||
|
refl = new int[size];
|
||||||
Size = size;
|
Size = size;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -34,42 +40,43 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The vector type.</typeparam>
|
/// <typeparam name="T">The vector type.</typeparam>
|
||||||
/// <param name="v">The column vector.</param>
|
/// <param name="v">The column vector.</param>
|
||||||
|
/// <param name="result">The result column vector.</param>
|
||||||
/// <param name="o">The column operator.</param>
|
/// <param name="o">The column operator.</param>
|
||||||
/// <returns>The column vector eliminated.</returns>
|
public void Eliminate<T>(ColumnVector<T> v, ColumnVector<T> result, IVectorOperator<T> o) {
|
||||||
public ColumnVector<T> Eliminate<T>(ColumnVector<T> v, IVectorOperator<T> o) {
|
|
||||||
int s = Size;
|
int s = Size;
|
||||||
float[,] d = (float[,])content.Clone();
|
FillBuffer();
|
||||||
int[] refl = new int[s];
|
for (int i = 0; i < s; i++) refl[i] = i;
|
||||||
for (int i = 0; i < s; i++)
|
|
||||||
refl[i] = i;
|
|
||||||
for (int r = 0; r < s; r++) {
|
for (int r = 0; r < s; r++) {
|
||||||
for (int r0 = r; r0 < s; r0++)
|
for (int r0 = r; r0 < s; r0++)
|
||||||
if (d[refl[r0], r] != 0) {
|
if (buffer[refl[r0], r] != 0) {
|
||||||
refl[r] = r0;
|
refl[r] = r0;
|
||||||
refl[r0] = r;
|
refl[r0] = r;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int or = refl[r];
|
int or = refl[r];
|
||||||
float sf0 = d[or, r];
|
float sf0 = buffer[or, r];
|
||||||
for (int c0 = r; c0 < s; c0++)
|
for (int c0 = r; c0 < s; c0++)
|
||||||
d[or, c0] /= sf0;
|
buffer[or, c0] /= sf0;
|
||||||
v[or] = o.ScalarMultiply(1 / sf0, v[or]);
|
v[or] = o.ScalarMultiply(1 / sf0, v[or]);
|
||||||
for (int r1 = r + 1; r1 < s; r1++) {
|
for (int r1 = r + 1; r1 < s; r1++) {
|
||||||
int or1 = refl[r1];
|
int or1 = refl[r1];
|
||||||
float sf1 = d[or1, r];
|
float sf1 = buffer[or1, r];
|
||||||
for (int c1 = r; c1 < s; c1++)
|
for (int c1 = r; c1 < s; c1++)
|
||||||
d[or1, c1] -= d[or, c1] * sf1;
|
buffer[or1, c1] -= buffer[or, c1] * sf1;
|
||||||
v[or1] = o.Add(v[or1], o.ScalarMultiply(-sf1, v[or]));
|
v[or1] = o.Add(v[or1], o.ScalarMultiply(-sf1, v[or]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
T[] res = new T[s];
|
|
||||||
for (int r2 = s - 1; r2 >= 0; r2--) {
|
for (int r2 = s - 1; r2 >= 0; r2--) {
|
||||||
var v2 = v[refl[r2]];
|
var v2 = v[refl[r2]];
|
||||||
for (int c2 = r2 + 1; c2 < s; c2++)
|
for (int c2 = r2 + 1; c2 < s; c2++)
|
||||||
v2 = o.Add(v2, o.ScalarMultiply(-d[refl[r2], c2], res[refl[c2]]));
|
v2 = o.Add(v2, o.ScalarMultiply(-buffer[refl[r2], c2], result[refl[c2]]));
|
||||||
res[refl[r2]] = v2;
|
result[refl[r2]] = v2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe void FillBuffer() {
|
||||||
|
fixed (void* ptrc = content, ptrb = buffer) {
|
||||||
|
Unsafe.CopyBlock(ptrb, ptrc, (uint)(Size * Size * sizeof(float)));
|
||||||
}
|
}
|
||||||
return new ColumnVector<T>(res);
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a square matrix and fills it with polynomial coefficients.
|
/// Creates a square matrix and fills it with polynomial coefficients.
|
||||||
|
@@ -77,7 +77,7 @@ namespace Cryville.Common.Network {
|
|||||||
encoding = Encoding.UTF8;
|
encoding = Encoding.UTF8;
|
||||||
payload = encoding.GetBytes(body);
|
payload = encoding.GetBytes(body);
|
||||||
headers.Add("Content-Encoding", encoding.EncodingName);
|
headers.Add("Content-Encoding", encoding.EncodingName);
|
||||||
headers.Add("Content-Length", payload.Length.ToString());
|
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
|
||||||
}
|
}
|
||||||
string request_line = string.Format(
|
string request_line = string.Format(
|
||||||
"{0} {1} {2}\r\n", method, uri, Version
|
"{0} {1} {2}\r\n", method, uri, Version
|
||||||
|
@@ -19,9 +19,7 @@ namespace Cryville.Common.Network {
|
|||||||
set { throw new NotSupportedException(); }
|
set { throw new NotSupportedException(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Flush() {
|
public override void Flush() { }
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract byte[] ReadToEnd();
|
public abstract byte[] ReadToEnd();
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ namespace Cryville.Common.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class InternalTlsClient : DefaultTlsClient {
|
private class InternalTlsClient : DefaultTlsClient {
|
||||||
string _host;
|
readonly string _host;
|
||||||
|
|
||||||
public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) {
|
public InternalTlsClient(string host, TlsCrypto crypto) : base(crypto) {
|
||||||
_host = host;
|
_host = host;
|
||||||
@@ -92,9 +92,7 @@ namespace Cryville.Common.Network {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyServerCertificate(TlsServerCertificate serverCertificate) {
|
public void NotifyServerCertificate(TlsServerCertificate serverCertificate) { }
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Cryville.Common.Pdt {
|
namespace Cryville.Common.Pdt {
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates that the attributed member is an element list.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
|
||||||
|
/// </remarks>
|
||||||
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||||
public class ElementListAttribute : Attribute { }
|
public class ElementListAttribute : Attribute { }
|
||||||
public class ComponentListAttribute : Attribute { }
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates that the attributed member is a property list.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>A property list is a <see cref="System.Collections.IDictionary" /> that represents a collection of PDT properties. There must be at most one property list in a class.</para>
|
||||||
|
/// </remarks>
|
||||||
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||||
public class PropertyListAttribute : Attribute { }
|
public class PropertyListAttribute : Attribute { }
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace Cryville.Common.Pdt {
|
namespace Cryville.Common.Pdt {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -104,7 +105,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
else if (i is PdtInstruction.PushVariable) {
|
else if (i is PdtInstruction.PushVariable) {
|
||||||
i.Execute(this);
|
i.Execute(this);
|
||||||
var frame = _stack[_framecount - 1];
|
var frame = _stack[_framecount - 1];
|
||||||
if (frame.Type != PdtInternalType.Undefined) {
|
if (frame.Type != PdtInternalType.Undefined && frame.Type != PdtInternalType.Error) {
|
||||||
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
|
_rip = il.AddAfter(_rip, new PdtInstruction.PushConstant(frame.Type, _mem, frame.Offset, frame.Length));
|
||||||
il.Remove(_rip.Previous);
|
il.Remove(_rip.Previous);
|
||||||
}
|
}
|
||||||
@@ -147,10 +148,10 @@ namespace Cryville.Common.Pdt {
|
|||||||
_goffset += value.Length;
|
_goffset += value.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal unsafe void PushVariable(int name) {
|
internal unsafe void PushVariable(int name, bool forced) {
|
||||||
fixed (StackFrame* frame = &_stack[_framecount++]) {
|
fixed (StackFrame* frame = &_stack[_framecount++]) {
|
||||||
byte[] value;
|
byte[] value;
|
||||||
GetVariable(name, out frame->Type, out value);
|
GetVariable(name, forced, out frame->Type, out value);
|
||||||
frame->Offset = _goffset;
|
frame->Offset = _goffset;
|
||||||
frame->Length = value.Length;
|
frame->Length = value.Length;
|
||||||
Array.Copy(value, 0, _mem, _goffset, value.Length);
|
Array.Copy(value, 0, _mem, _goffset, value.Length);
|
||||||
@@ -161,16 +162,17 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// Gets a variable of the specified name.
|
/// Gets a variable of the specified name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the variable.</param>
|
/// <param name="name">The name of the variable.</param>
|
||||||
|
/// <param name="forced">Whether to produce an error stack instead of an identifier stack if the variable is not found.</param>
|
||||||
/// <param name="type">The type of the variable.</param>
|
/// <param name="type">The type of the variable.</param>
|
||||||
/// <param name="value">The value of the variable.</param>
|
/// <param name="value">The value of the variable.</param>
|
||||||
protected abstract void GetVariable(int name, out int type, out byte[] value);
|
protected abstract void GetVariable(int name, bool forced, out int type, out byte[] value);
|
||||||
internal void Operate(PdtOperatorSignature sig) {
|
internal void Operate(PdtOperatorSignature sig) {
|
||||||
PdtOperator op;
|
PdtOperator op;
|
||||||
try { op = GetOperator(sig); }
|
try { op = GetOperator(sig); }
|
||||||
catch (Exception) {
|
catch (Exception ex) {
|
||||||
for (int i = 0; i < sig.ParamCount; i++)
|
for (int i = 0; i < sig.ParamCount; i++)
|
||||||
DiscardStack();
|
DiscardStack();
|
||||||
throw;
|
throw new EvaluationFailureException(string.Format("Failed to get operator {0}", sig), ex);
|
||||||
}
|
}
|
||||||
Operate(op, sig.ParamCount);
|
Operate(op, sig.ParamCount);
|
||||||
}
|
}
|
||||||
@@ -184,7 +186,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
protected abstract PdtOperator GetOperator(PdtOperatorSignature sig);
|
protected abstract PdtOperator GetOperator(PdtOperatorSignature sig);
|
||||||
unsafe void Operate(PdtOperator op, int pc, bool noset = false) {
|
unsafe void Operate(PdtOperator op, int pc, bool noset = false) {
|
||||||
fixed (byte* pmem = _mem) {
|
fixed (byte* pmem = _mem) {
|
||||||
op.Begin(this);
|
op.Begin(this, pc);
|
||||||
for (int i = 0; i < pc; i++) {
|
for (int i = 0; i < pc; i++) {
|
||||||
var frame = _stack[--_framecount];
|
var frame = _stack[--_framecount];
|
||||||
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
|
||||||
@@ -222,4 +224,18 @@ namespace Cryville.Common.Pdt {
|
|||||||
_goffset -= _stack[--_framecount].Length;
|
_goffset -= _stack[--_framecount].Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The exception that is thrown when the evalution of a <see cref="PdtExpression" /> fails.
|
||||||
|
/// </summary>
|
||||||
|
public class EvaluationFailureException : Exception {
|
||||||
|
/// <inheritdoc />
|
||||||
|
public EvaluationFailureException() : base("Evaluation failed") { }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public EvaluationFailureException(string message) : base(message) { }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public EvaluationFailureException(string message, Exception innerException) : base(message, innerException) { }
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected EvaluationFailureException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the value of this expression is constant.
|
/// Whether the value of this expression is constant.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>The value of this property is <c>false</c> until it is optimized.</remarks>
|
/// <remarks>The value of this property is <see langword="false" /> until it is optimized.</remarks>
|
||||||
public bool IsConstant { get; internal set; }
|
public bool IsConstant { get; internal set; }
|
||||||
internal bool IsPotentialConstant;
|
internal bool IsPotentialConstant;
|
||||||
internal PdtExpression(LinkedList<PdtInstruction> ins) {
|
internal PdtExpression(LinkedList<PdtInstruction> ins) {
|
||||||
@@ -51,13 +51,14 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
public class PushVariable : PdtInstruction {
|
public class PushVariable : PdtInstruction {
|
||||||
public int Name { get; private set; }
|
public int Name { get; private set; }
|
||||||
public PushVariable(int name) { Name = name; }
|
public bool Forced { get; private set; }
|
||||||
public PushVariable(string name) : this(IdentifierManager.SharedInstance.Request(name)) { }
|
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) {
|
internal override void Execute(PdtEvaluatorBase etor) {
|
||||||
etor.PushVariable(Name);
|
etor.PushVariable(Name, Forced);
|
||||||
}
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return string.Format("pushv {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
return string.Format(Forced ? "pushv ?{0}" : "pushv {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class Operate : PdtInstruction {
|
public class Operate : PdtInstruction {
|
||||||
@@ -90,7 +91,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public partial class PdtInterpreter<T> {
|
public partial class PdtInterpreter {
|
||||||
readonly static Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> {
|
readonly static Dictionary<char, int> OP_PRIORITY = new Dictionary<char, int> {
|
||||||
{ '@', 7 },
|
{ '@', 7 },
|
||||||
{ '*', 6 }, { '/', 6 }, { '%', 6 },
|
{ '*', 6 }, { '/', 6 }, { '%', 6 },
|
||||||
@@ -239,7 +240,11 @@ namespace Cryville.Common.Pdt {
|
|||||||
if (defs.TryGetValue(buf.Value.Value, out def)) {
|
if (defs.TryGetValue(buf.Value.Value, out def)) {
|
||||||
foreach (var i in def.Instructions) ins.AddLast(i);
|
foreach (var i in def.Instructions) ins.AddLast(i);
|
||||||
}
|
}
|
||||||
else ins.AddLast(new PdtInstruction.PushVariable(buf.Value.Value));
|
else {
|
||||||
|
var name = buf.Value.Value;
|
||||||
|
if (name[0] == '?') ins.AddLast(new PdtInstruction.PushVariable(name.Substring(1), true));
|
||||||
|
else ins.AddLast(new PdtInstruction.PushVariable(name));
|
||||||
|
}
|
||||||
buf = null;
|
buf = null;
|
||||||
TryPushAdjMul(ins, ref flag);
|
TryPushAdjMul(ins, ref flag);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
@@ -8,8 +9,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interpreter for Property Definition Tree (PDT) file format.
|
/// Interpreter for Property Definition Tree (PDT) file format.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The object type represented by the PDT.</typeparam>
|
public partial class PdtInterpreter {
|
||||||
public partial class PdtInterpreter<T> {
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The character category map.
|
/// The character category map.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -32,11 +32,11 @@ namespace Cryville.Common.Pdt {
|
|||||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000,
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000,
|
||||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
0x0001, 0x0080, 0x0100, 0x0000, 0x0030, 0x0080, 0x0080, 0x0000, 0x0200, 0x0400, 0x0080, 0x0080, 0x0080, 0x0080, 0x0040, 0x0080,
|
0x0001, 0x0080, 0x0100, 0x0000, 0x0030, 0x0080, 0x0080, 0x0000, 0x0200, 0x0400, 0x0080, 0x0080, 0x0080, 0x0080, 0x0040, 0x0080,
|
||||||
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x1000, 0x1800, 0x0080, 0x0080, 0x0080, 0x0000,
|
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x1000, 0x1800, 0x0080, 0x0080, 0x0080, 0x0030,
|
||||||
0x0080, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
0x0080, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030,
|
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0080, 0x0000, 0x0080, 0x0030,
|
||||||
0x0000, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
0x0000, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x1000, 0x0080, 0x1000, 0x0000, 0x0000,
|
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x1000, 0x0080, 0x1000, 0x0080, 0x0000,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -44,52 +44,102 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="src">The source string.</param>
|
/// <param name="src">The source string.</param>
|
||||||
/// <returns>The interpreted object.</returns>
|
/// <returns>The interpreted object.</returns>
|
||||||
public static T Interpret(string src) {
|
public static T Interpret<T>(string src) {
|
||||||
return Interpret(src, BinderAttribute.CreateBinderOfType(typeof(T)));
|
return Interpret<T>(src, BinderAttribute.CreateBinderOfType(typeof(T)));
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interprets a source string to an object of type <typeparamref name="T" /> with a binder.
|
/// Interprets a source string to an object of type <typeparamref name="T"/> with a binder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="src">The source string.</param>
|
/// <param name="src">The source string.</param>
|
||||||
/// <param name="binder">The binder.</param>
|
/// <param name="binder">The binder.</param>
|
||||||
/// <returns>The interpreted object.</returns>
|
/// <returns>The interpreted object.</returns>
|
||||||
public static T Interpret(string src, Binder binder) {
|
public static T Interpret<T>(string src, Binder binder) {
|
||||||
return new PdtInterpreter<T>(src, binder).Interpret();
|
return (T)new PdtInterpreter(src, binder).Interpret(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly string _src;
|
/// <summary>
|
||||||
readonly Binder _binder;
|
/// The source string.
|
||||||
protected int Position { get; private set; }
|
/// </summary>
|
||||||
|
public string Source { get; private set; }
|
||||||
|
Binder _binder;
|
||||||
|
/// <summary>
|
||||||
|
/// The current position in the string being parsed by the interpreter.
|
||||||
|
/// </summary>
|
||||||
|
public int Position { get; private set; }
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
protected char cc { get { return _src[Position]; } }
|
/// <summary>
|
||||||
|
/// The character at the current position.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
|
protected char cc { get { return Source[Position]; } }
|
||||||
|
/// <summary>
|
||||||
|
/// The category of the character.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected int ct { get { return cm[cc]; } }
|
protected int ct { get { return cm[cc]; } }
|
||||||
protected string tokenb(int flag) { // Token Whitelist
|
/// <summary>
|
||||||
|
/// Reads a token until a character of type <paramref name="flag" /> is met.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="flag">The type filter.</param>
|
||||||
|
/// <returns>A token from the current position (inclusive) to the next character of type <paramref name="flag" /> (exclusive).</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">No character of type <paramref name="flag" /> is met.</exception>
|
||||||
|
protected string tokenb(int flag) {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
while ((ct & flag) == 0) Position++;
|
while ((ct & flag) == 0) Position++;
|
||||||
return _src.Substring(sp, Position - sp);
|
return Source.Substring(sp, Position - sp);
|
||||||
}
|
}
|
||||||
protected string tokenw(int flag) { // Token Whitelist
|
/// <summary>
|
||||||
|
/// Reads a token until a character that is not of type <paramref name="flag" /> is met.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="flag">The type filter.</param>
|
||||||
|
/// <returns>A token from the current position (inclusive) to the next character that is not of type <paramref name="flag" /> (exclusive).</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">No character that is not of type <paramref name="flag" /> is met.</exception>
|
||||||
|
protected string tokenw(int flag) {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
while ((ct & flag) != 0) Position++;
|
while ((ct & flag) != 0) Position++;
|
||||||
return _src.Substring(sp, Position - sp);
|
return Source.Substring(sp, Position - sp);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Skips over whitespaces.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected void ws() {
|
protected void ws() {
|
||||||
while ((ct & 0x0001) != 0) Position++;
|
while ((ct & 0x0001) != 0) Position++;
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the current character and increments the position.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The current character.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected char GetChar() {
|
protected char GetChar() {
|
||||||
char r = cc;
|
char r = cc;
|
||||||
Position++;
|
Position++;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads an identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An identifier.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected string GetIdentifier() {
|
protected string GetIdentifier() {
|
||||||
if ((ct & 0x0020) == 0) return "";
|
if ((ct & 0x0020) == 0) return "";
|
||||||
return tokenw(0x0010);
|
return tokenw(0x0010);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a number.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A number.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected string GetNumber() {
|
protected string GetNumber() {
|
||||||
return tokenw(0x0040);
|
return tokenw(0x0040);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A string.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected string GetString() {
|
protected string GetString() {
|
||||||
int sp = Position;
|
int sp = Position;
|
||||||
do {
|
do {
|
||||||
@@ -97,8 +147,13 @@ namespace Cryville.Common.Pdt {
|
|||||||
Position++;
|
Position++;
|
||||||
} while (ct != 0x0100);
|
} while (ct != 0x0100);
|
||||||
Position++;
|
Position++;
|
||||||
return Regex.Replace(_src.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
return Regex.Replace(Source.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Reads an expression.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An expression.</returns>
|
||||||
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected PdtExpression GetExp() {
|
protected PdtExpression GetExp() {
|
||||||
var ins = new LinkedList<PdtInstruction>();
|
var ins = new LinkedList<PdtInstruction>();
|
||||||
int _;
|
int _;
|
||||||
@@ -108,23 +163,34 @@ namespace Cryville.Common.Pdt {
|
|||||||
|
|
||||||
readonly Dictionary<string, PdtExpression> defs = new Dictionary<string, PdtExpression>();
|
readonly Dictionary<string, PdtExpression> defs = new Dictionary<string, PdtExpression>();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the <see cref="PdtInterpreter{T}" /> class.
|
/// Creates an instance of the <see cref="PdtInterpreter" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="src">The source string.</param>
|
/// <param name="src">The source string.</param>
|
||||||
/// <param name="binder">The binder. May be <c>null</c>.</param>
|
/// <param name="binder">The binder. May be <c>null</c>.</param>
|
||||||
public PdtInterpreter(string src, Binder binder) {
|
public PdtInterpreter(string src, Binder binder) {
|
||||||
_src = src;
|
Source = src;
|
||||||
_binder = binder;
|
_binder = binder;
|
||||||
if (_binder == null)
|
}
|
||||||
_binder = BinderAttribute.CreateBinderOfType(typeof(T));
|
int[] m_formatVersion;
|
||||||
|
public int[] GetFormatVersion() {
|
||||||
|
if (m_formatVersion == null) InterpretDirectives();
|
||||||
|
return m_formatVersion;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interprets the source to an object of type <typeparamref name="T" />.
|
/// Interprets the source to an object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="type">The output type.</param>
|
||||||
/// <returns>The interpreted object.</returns>
|
/// <returns>The interpreted object.</returns>
|
||||||
public T Interpret() {
|
public object Interpret(Type type) {
|
||||||
InterpretDirectives();
|
try {
|
||||||
return (T)InterpretObject(typeof(T));
|
if (m_formatVersion == null) InterpretDirectives();
|
||||||
|
if (_binder == null)
|
||||||
|
_binder = BinderAttribute.CreateBinderOfType(type);
|
||||||
|
return InterpretObject(type);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
throw new PdtParsingException(this, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void InterpretDirectives() {
|
void InterpretDirectives() {
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
@@ -138,7 +204,10 @@ namespace Cryville.Common.Pdt {
|
|||||||
break;
|
break;
|
||||||
case "format":
|
case "format":
|
||||||
ws();
|
ws();
|
||||||
if (GetNumber() != "1")
|
m_formatVersion = (from i in GetNumber().Split('.') select int.Parse(i)).ToArray();
|
||||||
|
if (m_formatVersion.Length == 0)
|
||||||
|
throw new FormatException("Invalid format version");
|
||||||
|
if (m_formatVersion[0] != 1)
|
||||||
throw new NotSupportedException("Format not supported");
|
throw new NotSupportedException("Format not supported");
|
||||||
flag = true;
|
flag = true;
|
||||||
break;
|
break;
|
||||||
@@ -159,10 +228,14 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
object InterpretObject(Type type) {
|
object InterpretObject(Type type) {
|
||||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
||||||
bool dictflag = ReflectionHelper.IsGenericDictionary(type);
|
bool dictflag = typeof(IDictionary).IsAssignableFrom(type);
|
||||||
while (true) {
|
while (true) {
|
||||||
try { ws(); }
|
try { ws(); }
|
||||||
catch (IndexOutOfRangeException) { return result; }
|
catch (IndexOutOfRangeException) { return result; }
|
||||||
|
if (cc == '}') {
|
||||||
|
GetChar();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
object pkey = InterpretKey(type);
|
object pkey = InterpretKey(type);
|
||||||
char c = GetChar();
|
char c = GetChar();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -175,19 +248,20 @@ namespace Cryville.Common.Pdt {
|
|||||||
((IDictionary)result).Add(key, value);
|
((IDictionary)result).Add(key, value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MemberInfo prop;
|
MemberInfo prop = null;
|
||||||
bool flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
|
bool flag = false;
|
||||||
if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||||
|
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
|
||||||
|
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||||
Type ptype = ReflectionHelper.GetMemberType(prop);
|
Type ptype = ReflectionHelper.GetMemberType(prop);
|
||||||
if (ReflectionHelper.IsGenericDictionary(ptype)) {
|
if (flag) {
|
||||||
|
if (!typeof(IDictionary).IsAssignableFrom(ptype))
|
||||||
|
throw new InvalidOperationException("Internal error: Element list is not a dictionary");
|
||||||
var ktype = ptype.GetGenericArguments()[0];
|
var ktype = ptype.GetGenericArguments()[0];
|
||||||
var vtype = ptype.GetGenericArguments()[1];
|
var vtype = ptype.GetGenericArguments()[1];
|
||||||
if (flag) {
|
object key = _binder.ChangeType(pkey, ktype, null);
|
||||||
object key = _binder.ChangeType(pkey, ktype, null);
|
object value = InterpretObject(vtype);
|
||||||
object value = InterpretObject(vtype);
|
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
|
||||||
}
|
|
||||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
|
||||||
}
|
}
|
||||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
||||||
}
|
}
|
||||||
@@ -203,30 +277,70 @@ namespace Cryville.Common.Pdt {
|
|||||||
((IDictionary)result).Add(key, value);
|
((IDictionary)result).Add(key, value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MemberInfo prop;
|
MemberInfo prop = null;
|
||||||
bool flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
|
bool flag = false;
|
||||||
if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||||
|
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
|
||||||
|
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||||
var ptype = ReflectionHelper.GetMemberType(prop);
|
var ptype = ReflectionHelper.GetMemberType(prop);
|
||||||
if (!typeof(IDictionary).IsAssignableFrom(ptype)) {
|
if (flag) {
|
||||||
object value = _binder.ChangeType(exp, ptype, null);
|
if (!typeof(IDictionary).IsAssignableFrom(ptype))
|
||||||
ReflectionHelper.SetValue(prop, result, value, _binder);
|
throw new InvalidOperationException("Internal error: Property list is not a dictionary");
|
||||||
}
|
|
||||||
else {
|
|
||||||
var ktype = ptype.GetGenericArguments()[0];
|
var ktype = ptype.GetGenericArguments()[0];
|
||||||
var vtype = ptype.GetGenericArguments()[1];
|
var vtype = ptype.GetGenericArguments()[1];
|
||||||
object key = _binder.ChangeType(pkey, ktype, null);
|
object key = _binder.ChangeType(pkey, ktype, null);
|
||||||
object value = _binder.ChangeType(exp, vtype, null);
|
object value = _binder.ChangeType(exp, vtype, null);
|
||||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
object value = _binder.ChangeType(exp, ptype, null);
|
||||||
|
ReflectionHelper.SetValue(prop, result, value, _binder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '}':
|
default:
|
||||||
return result;
|
throw new InvalidOperationException("Internal error: Invalid key interpretation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Interprets a key from the current position.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The interpreted key.</returns>
|
||||||
protected virtual object InterpretKey(Type type) {
|
protected virtual object InterpretKey(Type type) {
|
||||||
return tokenb(0x1000).Trim();
|
return tokenb(0x1000).Trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The exception that is thrown when the interpretation of a PDT fails.
|
||||||
|
/// </summary>
|
||||||
|
public class PdtParsingException : Exception {
|
||||||
|
public PdtParsingException(PdtInterpreter interpreter) : this(interpreter, null) { }
|
||||||
|
public PdtParsingException(PdtInterpreter interpreter, Exception innerException)
|
||||||
|
: base(GenerateMessage(interpreter, innerException), innerException) { }
|
||||||
|
static string GenerateMessage(PdtInterpreter interpreter, Exception innerException) {
|
||||||
|
string src = interpreter.Source;
|
||||||
|
int pos = interpreter.Position;
|
||||||
|
if (pos >= src.Length) return "Failed to interpret the PDT: There are some missing or redundant tokens";
|
||||||
|
int lineStartPos = src.LastIndexOf('\n', pos) + 1;
|
||||||
|
int previewStartPos = src.LastIndexOf('\n', pos, 64);
|
||||||
|
if (previewStartPos == -1) {
|
||||||
|
previewStartPos = pos - 64;
|
||||||
|
if (previewStartPos < 0) previewStartPos = 0;
|
||||||
|
}
|
||||||
|
else previewStartPos++;
|
||||||
|
int previewEndPos = src.IndexOf('\n', pos, 64);
|
||||||
|
if (previewEndPos == -1) {
|
||||||
|
previewEndPos = pos + 64;
|
||||||
|
if (previewEndPos > src.Length) previewEndPos = src.Length;
|
||||||
|
}
|
||||||
|
return string.Format(
|
||||||
|
"Failed to interpret the PDT at line {0}, position {1}: {2}\n{3}",
|
||||||
|
src.Take(interpreter.Position).Count(c => c == '\n') + 1,
|
||||||
|
pos - lineStartPos + 1,
|
||||||
|
innerException == null ? "Unknown error" : innerException.Message,
|
||||||
|
src.Substring(previewStartPos, previewEndPos - previewStartPos)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The count of the operands loaded.
|
/// The count of the operands loaded.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected int LoadedOperandCount { get { return ParamCount - _loadindex; } }
|
protected int LoadedOperandCount { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the operand at the specified index.
|
/// Gets the operand at the specified index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,47 +19,45 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <returns>The operand at the specified index.</returns>
|
/// <returns>The operand at the specified index.</returns>
|
||||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> is not less than <see cref="LoadedOperandCount" /> or less than 0.</exception>
|
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> is not less than <see cref="LoadedOperandCount" /> or less than 0.</exception>
|
||||||
protected PdtVariableMemory GetOperand(int index) {
|
protected PdtVariableMemory GetOperand(int index) {
|
||||||
if (index >= LoadedOperandCount || index < 0) throw new IndexOutOfRangeException();
|
if (index >= LoadedOperandCount || index < 0)
|
||||||
|
throw new ArgumentOutOfRangeException("index");
|
||||||
int i = index + _loadindex;
|
int i = index + _loadindex;
|
||||||
return _operands[i];
|
return _operands[i];
|
||||||
}
|
}
|
||||||
internal int ParamCount { get; private set; }
|
readonly int _pc;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of the <see cref="PdtOperator" /> class.
|
/// Creates an instance of the <see cref="PdtOperator" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pc">The suggested parameter count.</param>
|
/// <param name="pc">The suggested parameter count.</param>
|
||||||
protected PdtOperator(int pc) {
|
protected PdtOperator(int pc) {
|
||||||
ParamCount = pc;
|
_pc = pc;
|
||||||
_operands = new PdtVariableMemory[pc];
|
_operands = new PdtVariableMemory[pc];
|
||||||
}
|
}
|
||||||
PdtEvaluatorBase _etor;
|
PdtEvaluatorBase _etor;
|
||||||
bool _failure = false;
|
|
||||||
bool _rfreq = true;
|
bool _rfreq = true;
|
||||||
internal void Begin(PdtEvaluatorBase etor) {
|
internal void Begin(PdtEvaluatorBase etor, int pc) {
|
||||||
_etor = etor;
|
_etor = etor;
|
||||||
_failure = false;
|
_loadindex = LoadedOperandCount = pc;
|
||||||
_loadindex = ParamCount;
|
|
||||||
}
|
}
|
||||||
internal void LoadOperand(PdtVariableMemory mem) {
|
internal void LoadOperand(PdtVariableMemory mem) {
|
||||||
if (_loadindex == 0) return;
|
if (--_loadindex >= _pc) return;
|
||||||
_operands[--_loadindex] = mem;
|
_operands[_loadindex] = mem;
|
||||||
}
|
}
|
||||||
internal void Call(byte* prmem, bool noset) {
|
internal void Call(byte* prmem, bool noset) {
|
||||||
_prmem = prmem;
|
_prmem = prmem;
|
||||||
_rfreq = false;
|
_rfreq = false;
|
||||||
try { Execute(); } catch (Exception ex) {
|
try { Execute(); } catch (Exception ex) {
|
||||||
if (_rfreq) _etor.DiscardStack();
|
if (_rfreq) _etor.DiscardStack();
|
||||||
throw new InvalidOperationException("Evaluation failed", ex);
|
throw new EvaluationFailureException("Evaluation failed", ex);
|
||||||
}
|
}
|
||||||
if (_failure) {
|
if (!_rfreq && !noset) throw new EvaluationFailureException("Return frame not set");
|
||||||
if (_rfreq) _etor.DiscardStack();
|
|
||||||
throw new InvalidOperationException("Evaluation failed");
|
|
||||||
}
|
|
||||||
if (!_rfreq && !noset) throw new InvalidOperationException("Return frame not set");
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the operator.
|
/// Executes the operator.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>When overridden, this method reads operands by calling <see cref="GetOperand(int)" />, and writes the result to the frame obtained by calling <see cref="GetReturnFrame(int, int)" />.</para>
|
||||||
|
/// </remarks>
|
||||||
protected abstract void Execute();
|
protected abstract void Execute();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a return frame.
|
/// Gets a return frame.
|
||||||
@@ -69,10 +67,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <returns>The return frame.</returns>
|
/// <returns>The return frame.</returns>
|
||||||
/// <exception cref="InvalidOperationException">The return frame has already been requested.</exception>
|
/// <exception cref="InvalidOperationException">The return frame has already been requested.</exception>
|
||||||
protected PdtVariableMemory GetReturnFrame(int type, int len) {
|
protected PdtVariableMemory GetReturnFrame(int type, int len) {
|
||||||
if (_rfreq) {
|
if (_rfreq) throw new InvalidOperationException("Return frame requested twice");
|
||||||
_failure = true;
|
|
||||||
throw new InvalidOperationException("Return frame already requested");
|
|
||||||
}
|
|
||||||
_rfreq = true;
|
_rfreq = true;
|
||||||
return _etor.StackAlloc(type, _prmem, len);
|
return _etor.StackAlloc(type, _prmem, len);
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using UnsafeIL;
|
||||||
|
|
||||||
namespace Cryville.Common.Pdt {
|
namespace Cryville.Common.Pdt {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Span on the memory of a <see cref="PdtEvaluatorBase" />.
|
/// Span on the memory of a <see cref="PdtEvaluatorBase" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public unsafe struct PdtVariableMemory {
|
public unsafe struct PdtVariableMemory : IEquatable<PdtVariableMemory> {
|
||||||
readonly byte* _ptr;
|
readonly byte* _ptr;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The length of the span.
|
/// The length of the span.
|
||||||
@@ -42,10 +43,20 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <param name="dest">The destination buffer.</param>
|
/// <param name="dest">The destination buffer.</param>
|
||||||
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
||||||
/// <param name="length">The length to copy.</param>
|
/// <param name="length">The length to copy.</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is greater than the length of the span.</exception>
|
||||||
public void CopyTo(byte* dest, int destOffset, int length) {
|
public void CopyTo(byte* dest, int destOffset, int length) {
|
||||||
|
if (length > Length) throw new ArgumentOutOfRangeException("length");
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
dest[destOffset + i] = _ptr[i];
|
dest[destOffset + i] = _ptr[i];
|
||||||
}
|
}
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool Equals(PdtVariableMemory obj) {
|
||||||
|
if (Type != obj.Type || Length != obj.Length) return false;
|
||||||
|
for (int i = 0; i < Length; i++) {
|
||||||
|
if (*(_ptr + i) != *(obj._ptr + i)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the memory of the span as a number.
|
/// Gets the memory of the span as a number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -118,10 +129,43 @@ namespace Cryville.Common.Pdt {
|
|||||||
throw new InvalidCastException("Not an identifier");
|
throw new InvalidCastException("Not an identifier");
|
||||||
return *(int*)(_ptr + offset);
|
return *(int*)(_ptr + offset);
|
||||||
}
|
}
|
||||||
internal void* TrustedAsOfLength(int len) {
|
/// <summary>
|
||||||
if (Length < len)
|
/// Gets the memory of the span as an instance of the specified type.
|
||||||
throw new InvalidCastException("Type not matched");
|
/// </summary>
|
||||||
return _ptr;
|
/// <typeparam name="T">The specified type.</typeparam>
|
||||||
|
/// <param name="offset">The offset on the span to start reading from.</param>
|
||||||
|
/// <returns>An instance of the specified type.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="offset" /> is not less than the length of the span.</exception>
|
||||||
|
/// <exception cref="InvalidCastException">The length of the span is not sufficient.</exception>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>Use <see cref="AsNumber(int)" /> instead while reading an unaligned number.</para>
|
||||||
|
/// </remarks>
|
||||||
|
public T As<T>(int offset = 0) {
|
||||||
|
var len = Unsafe.SizeOf<T>();
|
||||||
|
if (offset >= Length)
|
||||||
|
throw new ArgumentOutOfRangeException("offset");
|
||||||
|
if (offset + len > Length)
|
||||||
|
throw new InvalidCastException("Frame length not sufficient");
|
||||||
|
return Unsafe.Read<T>(_ptr + offset);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the memory of the span to an instance of the specified type.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The specified type.</typeparam>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
/// <param name="offset">The offset from the start of the span.</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="offset" /> is not less than the length of the span.</exception>
|
||||||
|
/// <exception cref="InvalidCastException">The length of the span is not sufficient.</exception>
|
||||||
|
/// <remarks>
|
||||||
|
/// <para>Use <see cref="SetNumber(float, int)" /> instead while writing an unaligned number.</para>
|
||||||
|
/// </remarks>
|
||||||
|
public void Set<T>(T value, int offset = 0) {
|
||||||
|
var len = Unsafe.SizeOf<T>();
|
||||||
|
if (offset >= Length)
|
||||||
|
throw new ArgumentOutOfRangeException("offset");
|
||||||
|
if (offset + len > Length)
|
||||||
|
throw new InvalidCastException("Frame length not sufficient");
|
||||||
|
Unsafe.Write(_ptr + offset, value);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the array suffix.
|
/// Gets the array suffix.
|
||||||
|
@@ -145,7 +145,7 @@ namespace Cryville.Common {
|
|||||||
/// <returns>An array containing all the subclasses of the type in the current app domain.</returns>
|
/// <returns>An array containing all the subclasses of the type in the current app domain.</returns>
|
||||||
public static Type[] GetSubclassesOf<T>() where T : class {
|
public static Type[] GetSubclassesOf<T>() where T : class {
|
||||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
IEnumerable<Type> r = new List<Type>();
|
IEnumerable<Type> r = Enumerable.Empty<Type>();
|
||||||
foreach (var a in assemblies)
|
foreach (var a in assemblies)
|
||||||
r = r.Concat(a.GetTypes().Where(
|
r = r.Concat(a.GetTypes().Where(
|
||||||
t => t.IsClass
|
t => t.IsClass
|
||||||
|
@@ -44,5 +44,21 @@ namespace Cryville.Common {
|
|||||||
if (result.Length == 0) return "_";
|
if (result.Length == 0) return "_";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the process path from a command.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">The command.</param>
|
||||||
|
/// <returns>The process path.</returns>
|
||||||
|
public static string GetProcessPathFromCommand(string command) {
|
||||||
|
command = command.Trim();
|
||||||
|
if (command[0] == '"') {
|
||||||
|
return command.Substring(1, command.IndexOf('"', 1) - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int e = command.IndexOf(' ');
|
||||||
|
if (e == -1) return command;
|
||||||
|
else return command.Substring(0, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -11,13 +12,13 @@ namespace Cryville.Common.Unity {
|
|||||||
Transform dirs;
|
Transform dirs;
|
||||||
Transform files;
|
Transform files;
|
||||||
|
|
||||||
public Action Callback { private get; set; }
|
public event Action OnClose;
|
||||||
|
|
||||||
#if UNITY_ANDROID && !UNITY_EDITOR_WIN
|
#if UNITY_ANDROID && !UNITY_EDITOR_WIN
|
||||||
string androidStorage = "";
|
string androidStorage = "";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
string fileName = "";
|
string fileName = null;
|
||||||
public string FileName {
|
public string FileName {
|
||||||
get { return fileName; }
|
get { return fileName; }
|
||||||
}
|
}
|
||||||
@@ -27,8 +28,16 @@ namespace Cryville.Common.Unity {
|
|||||||
set { m_filter = value; }
|
set { m_filter = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
public Dictionary<string, string> m_presetPaths = new Dictionary<string, string>();
|
||||||
|
public Dictionary<string, string> PresetPaths {
|
||||||
|
get { return m_presetPaths; }
|
||||||
|
set { m_presetPaths = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
GameObject prefabButton;
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
|
prefabButton = Resources.Load<GameObject>("Common/Button");
|
||||||
panel = gameObject.transform.Find("Panel");
|
panel = gameObject.transform.Find("Panel");
|
||||||
title = panel.Find("Title/Text");
|
title = panel.Find("Title/Text");
|
||||||
drives = panel.Find("Drives/DrivesInner");
|
drives = panel.Find("Drives/DrivesInner");
|
||||||
@@ -38,8 +47,8 @@ namespace Cryville.Common.Unity {
|
|||||||
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
||||||
CurrentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
CurrentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
using (AndroidJavaClass ajc=new AndroidJavaClass("android.os.Environment"))
|
using (AndroidJavaClass ajc = new AndroidJavaClass("android.os.Environment"))
|
||||||
using (AndroidJavaObject file=ajc.CallStatic<AndroidJavaObject>("getExternalStorageDirectory")) {
|
using (AndroidJavaObject file = ajc.CallStatic<AndroidJavaObject>("getExternalStorageDirectory")) {
|
||||||
androidStorage = file.Call<string>("getAbsolutePath");
|
androidStorage = file.Call<string>("getAbsolutePath");
|
||||||
CurrentDirectory = new DirectoryInfo(androidStorage);
|
CurrentDirectory = new DirectoryInfo(androidStorage);
|
||||||
}
|
}
|
||||||
@@ -47,9 +56,8 @@ namespace Cryville.Common.Unity {
|
|||||||
#error No default directory
|
#error No default directory
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
UpdateGUI();
|
UpdateGUI(0);
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE0051
|
|
||||||
|
|
||||||
public void Show() {
|
public void Show() {
|
||||||
fileName = null;
|
fileName = null;
|
||||||
@@ -57,85 +65,82 @@ namespace Cryville.Common.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Close() {
|
public void Close() {
|
||||||
if (Callback != null) Callback.Invoke();
|
var ev = OnClose;
|
||||||
|
if (ev != null) ev.Invoke();
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectoryInfo CurrentDirectory;
|
public DirectoryInfo CurrentDirectory;
|
||||||
|
|
||||||
void OnDriveChanged(string s) {
|
void ChangeDirectory(DirectoryInfo s) {
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
CurrentDirectory = s;
|
||||||
CurrentDirectory = new DirectoryInfo(s);
|
UpdateGUI(1);
|
||||||
#elif UNITY_ANDROID
|
|
||||||
switch (s) {
|
|
||||||
case "?storage":
|
|
||||||
CurrentDirectory = new DirectoryInfo(androidStorage);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error No change drive logic
|
|
||||||
#endif
|
|
||||||
UpdateGUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDirectoryChanged(string s) {
|
void SelectFile(string s) {
|
||||||
CurrentDirectory = new DirectoryInfo(CurrentDirectory.FullName + "/" + s);
|
|
||||||
UpdateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnFileChanged(string s) {
|
|
||||||
fileName = s;
|
fileName = s;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateGUI() {
|
void UpdateGUI(int depth) {
|
||||||
title.GetComponent<Text>().text = CurrentDirectory.FullName;
|
title.GetComponent<Text>().text = CurrentDirectory.FullName;
|
||||||
|
|
||||||
CallHelper.Purge(drives);
|
if (depth <= 0) {
|
||||||
|
CallHelper.Purge(drives);
|
||||||
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
var dl = Directory.GetLogicalDrives();
|
var dl = Directory.GetLogicalDrives();
|
||||||
foreach (string d in dl) {
|
foreach (string d in dl) {
|
||||||
GameObject btn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject btn = Instantiate(prefabButton);
|
||||||
btn.GetComponentInChildren<Text>().text = d;
|
btn.GetComponentInChildren<Text>().text = d;
|
||||||
var ts = d;
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(d)));
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDriveChanged(ts));
|
btn.transform.SetParent(drives, false);
|
||||||
btn.transform.SetParent(drives, false);
|
}
|
||||||
}
|
|
||||||
#elif UNITY_ANDROID
|
#elif UNITY_ANDROID
|
||||||
GameObject sbtn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject sbtn = GameObject.Instantiate<GameObject>(prefabButton);
|
||||||
sbtn.GetComponentInChildren<Text>().text = "Storage";
|
sbtn.GetComponentInChildren<Text>().text = "Storage";
|
||||||
sbtn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDriveChanged("?storage"));
|
sbtn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(androidStorage)));
|
||||||
sbtn.transform.SetParent(drives, false);
|
sbtn.transform.SetParent(drives, false);
|
||||||
#else
|
#else
|
||||||
#error No update GUI logic
|
#error No update GUI logic
|
||||||
#endif
|
#endif
|
||||||
|
foreach (var p in m_presetPaths) {
|
||||||
|
var d = new DirectoryInfo(p.Value);
|
||||||
|
if (d.Exists) {
|
||||||
|
GameObject btn = Instantiate(prefabButton);
|
||||||
|
btn.GetComponentInChildren<Text>().text = p.Key;
|
||||||
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(d));
|
||||||
|
btn.transform.SetParent(drives, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CallHelper.Purge(dirs);
|
CallHelper.Purge(dirs);
|
||||||
DirectoryInfo[] subdirs = CurrentDirectory.GetDirectories();
|
DirectoryInfo[] subdirs = CurrentDirectory.GetDirectories();
|
||||||
GameObject pbtn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject pbtn = Instantiate(prefabButton);
|
||||||
pbtn.GetComponentInChildren<Text>().text = "..";
|
pbtn.GetComponentInChildren<Text>().text = "..";
|
||||||
pbtn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDirectoryChanged(".."));
|
pbtn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(new DirectoryInfo(Path.Combine(CurrentDirectory.FullName, ".."))));
|
||||||
pbtn.transform.SetParent(dirs, false);
|
pbtn.transform.SetParent(dirs, false);
|
||||||
foreach (DirectoryInfo d in subdirs) {
|
foreach (DirectoryInfo d in subdirs) {
|
||||||
GameObject btn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
GameObject btn = Instantiate(prefabButton);
|
||||||
btn.GetComponentInChildren<Text>().text = d.Name;
|
btn.GetComponentInChildren<Text>().text = d.Name;
|
||||||
var ts = d.Name;
|
var ts = d;
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => OnDirectoryChanged(ts));
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => ChangeDirectory(ts));
|
||||||
btn.transform.SetParent(dirs, false);
|
btn.transform.SetParent(dirs, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallHelper.Purge(files);
|
CallHelper.Purge(files);
|
||||||
FileInfo[] fl = CurrentDirectory.GetFiles();
|
FileInfo[] fl = CurrentDirectory.GetFiles();
|
||||||
foreach (FileInfo d in fl) {
|
foreach (FileInfo d in fl) {
|
||||||
foreach (string ext in m_filter)
|
foreach (string ext in m_filter) {
|
||||||
if (d.Extension == ext) goto ext_matched;
|
if (d.Extension == ext) {
|
||||||
continue;
|
GameObject btn = Instantiate(prefabButton);
|
||||||
ext_matched:
|
btn.GetComponentInChildren<Text>().text = d.Name + " / " + (d.Length / 1024.0).ToString("0.0 KiB");
|
||||||
GameObject btn = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/Button"));
|
var ts = d.FullName;
|
||||||
btn.GetComponentInChildren<Text>().text = d.Name + " / " + (d.Length / 1024.0).ToString("0.0 KiB");
|
btn.GetComponentInChildren<Button>().onClick.AddListener(() => SelectFile(ts));
|
||||||
var ts = d.FullName;
|
btn.transform.SetParent(files, false);
|
||||||
btn.GetComponentInChildren<Button>().onClick.AddListener(() => OnFileChanged(ts));
|
break;
|
||||||
btn.transform.SetParent(files, false);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,19 @@ using UnityEngine;
|
|||||||
namespace Cryville.Common.Unity.Input {
|
namespace Cryville.Common.Unity.Input {
|
||||||
public delegate void InputEventDelegate(InputIdentifier id, InputVector vec);
|
public delegate void InputEventDelegate(InputIdentifier id, InputVector vec);
|
||||||
public abstract class InputHandler : IDisposable {
|
public abstract class InputHandler : IDisposable {
|
||||||
public event InputEventDelegate OnInput;
|
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() {
|
~InputHandler() {
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
@@ -14,26 +26,15 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Activated { get; private set; }
|
protected abstract void Activate();
|
||||||
public void Activate() {
|
protected abstract void Deactivate();
|
||||||
if (Activated) return;
|
|
||||||
Activated = true;
|
|
||||||
ActivateImpl();
|
|
||||||
}
|
|
||||||
protected abstract void ActivateImpl();
|
|
||||||
public void Deactivate() {
|
|
||||||
if (!Activated) return;
|
|
||||||
Activated = false;
|
|
||||||
DeactivateImpl();
|
|
||||||
}
|
|
||||||
protected abstract void DeactivateImpl();
|
|
||||||
public abstract void Dispose(bool disposing);
|
public abstract void Dispose(bool disposing);
|
||||||
public abstract bool IsNullable(int type);
|
public abstract bool IsNullable(int type);
|
||||||
public abstract byte GetDimension(int type);
|
public abstract byte GetDimension(int type);
|
||||||
public abstract string GetTypeName(int type);
|
public abstract string GetTypeName(int type);
|
||||||
public abstract double GetCurrentTimestamp();
|
public abstract double GetCurrentTimestamp();
|
||||||
protected void Feed(int type, int id, InputVector vec) {
|
protected void Feed(int type, int id, InputVector vec) {
|
||||||
var del = OnInput;
|
var del = m_onInput;
|
||||||
if (del != null) del(new InputIdentifier { Source = new InputSource { Handler = this, Type = type }, Id = id }, vec);
|
if (del != null) del(new InputIdentifier { Source = new InputSource { Handler = this, Type = type }, Id = id }, vec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,29 +4,22 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace Cryville.Common.Unity.Input {
|
namespace Cryville.Common.Unity.Input {
|
||||||
public class InputManager {
|
public class InputManager {
|
||||||
static readonly List<Type> HandlerRegistries = new List<Type> {
|
static readonly HashSet<Type> HandlerRegistries = new HashSet<Type> {
|
||||||
typeof(WindowsPointerHandler),
|
typeof(WindowsPointerHandler),
|
||||||
typeof(UnityKeyHandler<UnityKeyboardReceiver>),
|
typeof(UnityKeyHandler<UnityKeyboardReceiver>),
|
||||||
typeof(UnityKeyHandler<UnityMouseButtonReceiver>),
|
typeof(UnityKeyHandler<UnityMouseButtonReceiver>),
|
||||||
typeof(UnityMouseHandler),
|
typeof(UnityMouseHandler),
|
||||||
typeof(UnityTouchHandler),
|
typeof(UnityTouchHandler),
|
||||||
};
|
};
|
||||||
// TODO set private
|
readonly HashSet<InputHandler> _handlers = new HashSet<InputHandler>();
|
||||||
public readonly List<InputHandler> _handlers = new List<InputHandler>();
|
|
||||||
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
readonly Dictionary<Type, InputHandler> _typemap = new Dictionary<Type, InputHandler>();
|
||||||
readonly Dictionary<InputHandler, double> _timeOrigins = new Dictionary<InputHandler, double>();
|
|
||||||
readonly object _lock = new object();
|
|
||||||
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
|
|
||||||
readonly List<InputEvent> _events = new List<InputEvent>();
|
|
||||||
public InputManager() {
|
public InputManager() {
|
||||||
foreach (var t in HandlerRegistries) {
|
foreach (var t in HandlerRegistries) {
|
||||||
try {
|
try {
|
||||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||||
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
||||||
_typemap.Add(t, h);
|
_typemap.Add(t, h);
|
||||||
h.OnInput += OnInput;
|
|
||||||
_handlers.Add(h);
|
_handlers.Add(h);
|
||||||
_timeOrigins.Add(h, 0);
|
|
||||||
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
|
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
|
||||||
}
|
}
|
||||||
catch (TargetInvocationException ex) {
|
catch (TargetInvocationException ex) {
|
||||||
@@ -37,49 +30,8 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
public InputHandler GetHandler(string name) {
|
public InputHandler GetHandler(string name) {
|
||||||
return _typemap[Type.GetType(name)];
|
return _typemap[Type.GetType(name)];
|
||||||
}
|
}
|
||||||
public void Activate() {
|
public void EnumerateHandlers(Action<InputHandler> cb) {
|
||||||
lock (_lock) {
|
foreach (var h in _handlers) cb(h);
|
||||||
_events.Clear();
|
|
||||||
}
|
|
||||||
foreach (var h in _handlers) h.Activate();
|
|
||||||
}
|
|
||||||
public void SyncTime(double time) {
|
|
||||||
foreach (var h in _handlers) {
|
|
||||||
_timeOrigins[h] = time - h.GetCurrentTimestamp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void Deactivate() {
|
|
||||||
foreach (var h in _handlers) h.Deactivate();
|
|
||||||
}
|
|
||||||
void OnInput(InputIdentifier id, InputVector vec) {
|
|
||||||
lock (_lock) {
|
|
||||||
double timeOrigin = _timeOrigins[id.Source.Handler];
|
|
||||||
vec.Time += timeOrigin;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
49
Assets/Cryville/Common/Unity/Input/SimpleInputConsumer.cs
Normal file
49
Assets/Cryville/Common/Unity/Input/SimpleInputConsumer.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8fd2d5f1c7ba0c74c9ce8775075750db
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -9,19 +9,19 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
|
|
||||||
public UnityKeyHandler() { }
|
public UnityKeyHandler() { }
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
receiver = new GameObject("__keyrecv__");
|
receiver = new GameObject("__keyrecv__");
|
||||||
recvcomp = receiver.AddComponent<T>();
|
recvcomp = receiver.AddComponent<T>();
|
||||||
recvcomp.SetCallback(Feed);
|
recvcomp.SetCallback(Feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (receiver) GameObject.Destroy(receiver);
|
if (receiver) GameObject.Destroy(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
DeactivateImpl();
|
Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,11 +44,14 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
|
|
||||||
public abstract class UnityKeyReceiver<T> : MonoBehaviour where T : UnityKeyReceiver<T> {
|
public abstract class UnityKeyReceiver<T> : MonoBehaviour where T : UnityKeyReceiver<T> {
|
||||||
protected Action<int, int, InputVector> Callback;
|
protected Action<int, int, InputVector> Callback;
|
||||||
protected readonly List<int> Keys = new List<int>();
|
protected readonly HashSet<int> Keys = new HashSet<int>();
|
||||||
public void SetCallback(Action<int, int, InputVector> h) {
|
public void SetCallback(Action<int, int, InputVector> h) {
|
||||||
Callback = h;
|
Callback = h;
|
||||||
}
|
}
|
||||||
public abstract string GetKeyName(int type);
|
public abstract string GetKeyName(int type);
|
||||||
|
void Awake() {
|
||||||
|
useGUILayout = false;
|
||||||
|
}
|
||||||
void Update() {
|
void Update() {
|
||||||
double time = Time.realtimeSinceStartupAsDouble;
|
double time = Time.realtimeSinceStartupAsDouble;
|
||||||
foreach (var k in Keys) {
|
foreach (var k in Keys) {
|
||||||
|
@@ -12,35 +12,35 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
receiver = new GameObject("__mouserecv__");
|
receiver = new GameObject("__mouserecv__");
|
||||||
receiver.AddComponent<UnityMouseReceiver>().SetHandler(this);
|
receiver.AddComponent<UnityMouseReceiver>().SetHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (receiver) GameObject.Destroy(receiver);
|
if (receiver) GameObject.Destroy(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
DeactivateImpl();
|
Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsNullable(int type) {
|
public override bool IsNullable(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte GetDimension(int type) {
|
public override byte GetDimension(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetTypeName(int type) {
|
public override string GetTypeName(int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: return "Mouse Position";
|
case 0: return "Mouse Position";
|
||||||
default: throw new ArgumentOutOfRangeException(nameof(type));
|
default: throw new ArgumentOutOfRangeException("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,35 +12,35 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
receiver = new GameObject("__touchrecv__");
|
receiver = new GameObject("__touchrecv__");
|
||||||
receiver.AddComponent<UnityPointerReceiver>().SetHandler(this);
|
receiver.AddComponent<UnityPointerReceiver>().SetHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (receiver) GameObject.Destroy(receiver);
|
if (receiver) GameObject.Destroy(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
DeactivateImpl();
|
Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsNullable(int type) {
|
public override bool IsNullable(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte GetDimension(int type) {
|
public override byte GetDimension(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetTypeName(int type) {
|
public override string GetTypeName(int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: return "Touch";
|
case 0: return "Touch";
|
||||||
default: throw new ArgumentOutOfRangeException(nameof(type));
|
default: throw new ArgumentOutOfRangeException("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,6 +31,8 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
public WindowsPointerHandler() {
|
public WindowsPointerHandler() {
|
||||||
if (Instance != null)
|
if (Instance != null)
|
||||||
throw new InvalidOperationException("WindowsPointerHandler already created");
|
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;
|
Instance = this;
|
||||||
usePointerMessage = true;
|
usePointerMessage = true;
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
public const int TABLET_DISABLE_PENBARRELFEEDBACK = 0x00000010;
|
public const int TABLET_DISABLE_PENBARRELFEEDBACK = 0x00000010;
|
||||||
public const int TABLET_DISABLE_FLICKS = 0x00010000;
|
public const int TABLET_DISABLE_FLICKS = 0x00010000;
|
||||||
|
|
||||||
protected override void ActivateImpl() {
|
protected override void Activate() {
|
||||||
newWndProc = WndProc;
|
newWndProc = WndProc;
|
||||||
newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
|
newWndProcPtr = Marshal.GetFunctionPointerForDelegate(newWndProc);
|
||||||
oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);
|
oldWndProcPtr = SetWindowLongPtr(hMainWindow, -4, newWndProcPtr);
|
||||||
@@ -77,7 +79,7 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeactivateImpl() {
|
protected override void Deactivate() {
|
||||||
if (pressAndHoldAtomID != 0) {
|
if (pressAndHoldAtomID != 0) {
|
||||||
NativeMethods.RemoveProp(hMainWindow, PRESS_AND_HOLD_ATOM);
|
NativeMethods.RemoveProp(hMainWindow, PRESS_AND_HOLD_ATOM);
|
||||||
NativeMethods.GlobalDeleteAtom(pressAndHoldAtomID);
|
NativeMethods.GlobalDeleteAtom(pressAndHoldAtomID);
|
||||||
@@ -142,9 +144,11 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose(bool disposing) {
|
public override void Dispose(bool disposing) {
|
||||||
DeactivateImpl();
|
if (disposing) {
|
||||||
if (usePointerMessage)
|
Deactivate();
|
||||||
NativeMethods.EnableMouseInPointer(false);
|
if (usePointerMessage)
|
||||||
|
NativeMethods.EnableMouseInPointer(false);
|
||||||
|
}
|
||||||
Instance = null;
|
Instance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -118,7 +118,7 @@ namespace Cryville.Common.Unity {
|
|||||||
fdialog = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
fdialog = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
||||||
fdialog.Filter = filter;
|
fdialog.Filter = filter;
|
||||||
fdialog.CurrentDirectory = ContextPath;
|
fdialog.CurrentDirectory = ContextPath;
|
||||||
fdialog.Callback = () => OnFileDialogClosed();
|
fdialog.OnClose += OnFileDialogClosed;
|
||||||
}
|
}
|
||||||
editor.SetDescription(PropertyName, desc);
|
editor.SetDescription(PropertyName, desc);
|
||||||
UpdateValue();
|
UpdateValue();
|
||||||
|
@@ -126,8 +126,8 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
void Update() {
|
void Update() {
|
||||||
Vector2 cprectsize = ((RectTransform)transform.parent).rect.size;
|
Vector2 cprectsize = ((RectTransform)transform.parent).rect.size;
|
||||||
if (cprectsize != pprectsize) {
|
if (cprectsize != pprectsize) {
|
||||||
OnFrameUpdate();
|
|
||||||
pprectsize = cprectsize;
|
pprectsize = cprectsize;
|
||||||
|
OnFrameUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE0051
|
#pragma warning restore IDE0051
|
||||||
|
@@ -0,0 +1,10 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Unity.UI {
|
||||||
|
public class SetIntegerParameterBehaviour : SetParameterBehaviour {
|
||||||
|
[SerializeField] int m_value;
|
||||||
|
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
|
||||||
|
animator.SetInteger(m_name, m_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 57079cdf55a0d1149903f00ee732fa85
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
8
Assets/Cryville/Common/Unity/UI/SetParameterBehaviour.cs
Normal file
8
Assets/Cryville/Common/Unity/UI/SetParameterBehaviour.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Unity.UI {
|
||||||
|
public abstract class SetParameterBehaviour : StateMachineBehaviour {
|
||||||
|
[SerializeField] protected string m_name;
|
||||||
|
public override abstract void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d48088ca586ef5a41a42f6564e35b230
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
66
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs
Normal file
66
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using Cryville.Common.Font;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TextCore.LowLevel;
|
||||||
|
using UnityEngine.TextCore.Text;
|
||||||
|
|
||||||
|
namespace Cryville.Common.Unity.UI {
|
||||||
|
[RequireComponent(typeof(TextMeshProUGUI))]
|
||||||
|
public class TMPAutoFont : MonoBehaviour {
|
||||||
|
public static Shader DefaultShader;
|
||||||
|
public static FontMatcher FontMatcher;
|
||||||
|
public static int MaxFallbackCount = 4;
|
||||||
|
static FontAsset _font;
|
||||||
|
TextMeshProUGUI _text;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
Shader m_shader;
|
||||||
|
void Awake() {
|
||||||
|
if (FontMatcher == null) return;
|
||||||
|
_text = GetComponent<TextMeshProUGUI>();
|
||||||
|
if (_font == null) {
|
||||||
|
foreach (var typeface in FontMatcher.MatchScript(null, true)) {
|
||||||
|
try {
|
||||||
|
var ifont = CreateFontAsset(typeface.File.FullName, typeface.IndexInFile);
|
||||||
|
if (m_shader) ifont.material.shader = m_shader;
|
||||||
|
else if (DefaultShader) ifont.material.shader = DefaultShader;
|
||||||
|
if (_font == null) {
|
||||||
|
_font = ifont;
|
||||||
|
if (MaxFallbackCount <= 0) break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (_font.fallbackFontAssetTable == null)
|
||||||
|
_font.fallbackFontAssetTable = new List<FontAsset>();
|
||||||
|
_font.fallbackFontAssetTable.Add(ifont);
|
||||||
|
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_text.font = _font;
|
||||||
|
}
|
||||||
|
|
||||||
|
static MethodInfo _methodCreateFontAsset;
|
||||||
|
static readonly object[] _paramsCreateFontAsset = new object[] { null, null, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, Type.Missing, Type.Missing };
|
||||||
|
static FontAsset CreateFontAsset(string path, int index) {
|
||||||
|
if (_methodCreateFontAsset == null) {
|
||||||
|
_methodCreateFontAsset = typeof(FontAsset).GetMethod(
|
||||||
|
"CreateFontAsset", BindingFlags.Static | BindingFlags.NonPublic, null,
|
||||||
|
new Type[] {
|
||||||
|
typeof(string), typeof(int), typeof(int), typeof(int),
|
||||||
|
typeof(GlyphRenderMode), typeof(int), typeof(int),
|
||||||
|
typeof(AtlasPopulationMode), typeof(bool)
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_paramsCreateFontAsset[0] = path;
|
||||||
|
_paramsCreateFontAsset[1] = index;
|
||||||
|
return (FontAsset)_methodCreateFontAsset.Invoke(null, _paramsCreateFontAsset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs.meta
Normal file
11
Assets/Cryville/Common/Unity/UI/TMPAutoFont.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 57404eb6519ecae44b051485280e879f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: -120
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,15 +1,17 @@
|
|||||||
using UnityEngine;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class Anchor {
|
public class Anchor {
|
||||||
bool _opened;
|
public int Name { get; private set; }
|
||||||
public bool Opened { get { return _opened; } }
|
public Transform Transform { get; private set; }
|
||||||
public Transform Transform { get; set; }
|
public SkinContext SkinContext { get; private set; }
|
||||||
public void Open() {
|
public Dictionary<int, PropSrc> PropSrcs { get; private set; }
|
||||||
_opened = true;
|
public Anchor(int name, Transform transform, int propSrcCount = 0) {
|
||||||
}
|
Name = name;
|
||||||
public void Close() {
|
Transform = transform;
|
||||||
_opened = false;
|
if (propSrcCount > 0) PropSrcs = new Dictionary<int, PropSrc>(propSrcCount);
|
||||||
|
SkinContext = new SkinContext(transform, PropSrcs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
@@ -10,14 +11,14 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
private bool _dir;
|
private bool _dir;
|
||||||
private Image _icon;
|
private Image _icon;
|
||||||
private Text _title;
|
private TMP_Text _title;
|
||||||
private Text _desc;
|
private TMP_Text _desc;
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
#pragma warning disable IDE0051
|
||||||
void Awake() {
|
void Awake() {
|
||||||
_icon = transform.Find("__content__/Icon").GetComponent<Image>();
|
_icon = transform.Find("__content__/Icon").GetComponent<Image>();
|
||||||
_title = transform.Find("__content__/Texts/Title/__text__").GetComponent<Text>();
|
_title = transform.Find("__content__/Texts/Title/__text__").GetComponent<TMP_Text>();
|
||||||
_desc = transform.Find("__content__/Texts/Description/__text__").GetComponent<Text>();
|
_desc = transform.Find("__content__/Texts/Description/__text__").GetComponent<TMP_Text>();
|
||||||
}
|
}
|
||||||
void OnDestroy() {
|
void OnDestroy() {
|
||||||
if (meta.Icon != null) meta.Icon.Cancel();
|
if (meta.Icon != null) meta.Icon.Cancel();
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Unity.UI;
|
using Cryville.Common.Unity.UI;
|
||||||
using System;
|
using System;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@@ -18,8 +19,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
DockOccupiedRatioLayoutGroup _outerContentGroup;
|
DockOccupiedRatioLayoutGroup _outerContentGroup;
|
||||||
Transform _content;
|
Transform _content;
|
||||||
Image _cover;
|
Image _cover;
|
||||||
Text _title;
|
TMP_Text _title;
|
||||||
Text _desc;
|
TMP_Text _desc;
|
||||||
|
|
||||||
protected override void Awake() {
|
protected override void Awake() {
|
||||||
base.Awake();
|
base.Awake();
|
||||||
@@ -28,8 +29,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
_outerContentGroup = _outerContent.GetComponent<DockOccupiedRatioLayoutGroup>();
|
_outerContentGroup = _outerContent.GetComponent<DockOccupiedRatioLayoutGroup>();
|
||||||
_content = _outerContent.transform.Find("__content__");
|
_content = _outerContent.transform.Find("__content__");
|
||||||
_cover = _content.Find("Cover").GetComponent<Image>();
|
_cover = _content.Find("Cover").GetComponent<Image>();
|
||||||
_title = _content.Find("Texts/Title").GetComponent<Text>();
|
_title = _content.Find("Texts/Title").GetComponent<TMP_Text>();
|
||||||
_desc = _content.Find("Texts/Description").GetComponent<Text>();
|
_desc = _content.Find("Texts/Description").GetComponent<TMP_Text>();
|
||||||
}
|
}
|
||||||
void OnDestroy() {
|
void OnDestroy() {
|
||||||
if (_data.Cover != null) _data.Cover.Cancel();
|
if (_data.Cover != null) _data.Cover.Cancel();
|
||||||
|
8
Assets/Cryville/Crtr/Browsing/ExtensionInterface.cs
Normal file
8
Assets/Cryville/Crtr/Browsing/ExtensionInterface.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public abstract class ExtensionInterface {
|
||||||
|
public abstract IEnumerable<ResourceConverter> GetResourceConverters();
|
||||||
|
public abstract IEnumerable<LocalResourceFinder> GetResourceFinders();
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/ExtensionInterface.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/ExtensionInterface.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4ffe72fef6ebb9e4da3571b4117f0d6d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,4 +1,6 @@
|
|||||||
namespace Cryville.Crtr.Browsing {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
public interface IResourceManager<T> {
|
public interface IResourceManager<T> {
|
||||||
string[] CurrentDirectory { get; }
|
string[] CurrentDirectory { get; }
|
||||||
int ChangeDirectory(string[] dir);
|
int ChangeDirectory(string[] dir);
|
||||||
@@ -10,5 +12,6 @@
|
|||||||
|
|
||||||
bool ImportItemFrom(string path);
|
bool ImportItemFrom(string path);
|
||||||
string[] GetSupportedFormats();
|
string[] GetSupportedFormats();
|
||||||
|
Dictionary<string, string> GetPresetPaths();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -17,6 +17,8 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
static readonly Dictionary<string, List<ResourceConverter>> converters
|
static readonly Dictionary<string, List<ResourceConverter>> converters
|
||||||
= new Dictionary<string, List<ResourceConverter>>();
|
= new Dictionary<string, List<ResourceConverter>>();
|
||||||
|
static readonly Dictionary<string, string> localRes
|
||||||
|
= new Dictionary<string, string>();
|
||||||
|
|
||||||
public LegacyResourceManager(string rootPath) {
|
public LegacyResourceManager(string rootPath) {
|
||||||
_rootPath = rootPath;
|
_rootPath = rootPath;
|
||||||
@@ -25,13 +27,35 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
static LegacyResourceManager() {
|
static LegacyResourceManager() {
|
||||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) {
|
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) {
|
||||||
foreach (var type in asm.GetTypes()) {
|
foreach (var type in asm.GetTypes()) {
|
||||||
if (type.IsSubclassOf(typeof(ResourceConverter))) {
|
if (!type.IsSubclassOf(typeof(ExtensionInterface))) continue;
|
||||||
var converter = (ResourceConverter)Activator.CreateInstance(type);
|
var ext = (ExtensionInterface)Activator.CreateInstance(type);
|
||||||
foreach (var f in converter.GetSupportedFormats()) {
|
try {
|
||||||
if (!converters.ContainsKey(f))
|
var cs = ext.GetResourceConverters();
|
||||||
converters.Add(f, new List<ResourceConverter> { converter });
|
if (cs != null) {
|
||||||
else converters[f].Add(converter);
|
foreach (var c in cs) {
|
||||||
|
var fs = c.GetSupportedFormats();
|
||||||
|
if (fs == null) continue;
|
||||||
|
foreach (var f in fs) {
|
||||||
|
if (f == null) continue;
|
||||||
|
if (!converters.ContainsKey(f))
|
||||||
|
converters.Add(f, new List<ResourceConverter> { c });
|
||||||
|
else converters[f].Add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
var fs2 = ext.GetResourceFinders();
|
||||||
|
if (fs2 != null) {
|
||||||
|
foreach (var f in fs2) {
|
||||||
|
var name = f.Name;
|
||||||
|
var path = f.GetRootPath();
|
||||||
|
if (name != null && path != null)
|
||||||
|
localRes.Add(name, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logger.Log("main", 1, "Resource", "Loaded extension {0}", ReflectionHelper.GetNamespaceQualifiedName(type));
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Logger.Log("main", 4, "Resource", "Failed to initialize extension {0}: {1}", ReflectionHelper.GetNamespaceQualifiedName(type), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,9 +174,11 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
tres.Meta.data = "";
|
tres.Meta.data = "";
|
||||||
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
|
writer.Write(JsonConvert.SerializeObject(tres.Meta, Game.GlobalJsonSerializerSettings));
|
||||||
}
|
}
|
||||||
if (tres.Meta.cover != null)
|
if (tres.Meta.cover != null) {
|
||||||
new FileInfo(Path.Combine(file.Directory.FullName, tres.Meta.cover))
|
var coverFile = new FileInfo(Path.Combine(file.Directory.FullName, tres.Meta.cover));
|
||||||
.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
if (coverFile.Exists)
|
||||||
|
coverFile.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (res is FileResource) {
|
else if (res is FileResource) {
|
||||||
var tres = (FileResource)res;
|
var tres = (FileResource)res;
|
||||||
@@ -196,5 +222,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
public string[] GetSupportedFormats() {
|
public string[] GetSupportedFormats() {
|
||||||
return converters.Keys.ToArray();
|
return converters.Keys.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, string> GetPresetPaths() {
|
||||||
|
return localRes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
6
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs
Normal file
6
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
public abstract class LocalResourceFinder {
|
||||||
|
public abstract string Name { get; }
|
||||||
|
public abstract string GetRootPath();
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/LocalResourceFinder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f5b3f3294f679f14f8ec1195b0def630
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common.Unity;
|
using Cryville.Common.Unity;
|
||||||
using Cryville.Common.Unity.UI;
|
using Cryville.Common.Unity.UI;
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@@ -19,6 +20,9 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
_dialog = GameObject.Instantiate(Resources.Load<GameObject>("Common/FileDialog")).GetComponent<FileDialog>();
|
||||||
_dialog.gameObject.SetActive(false);
|
_dialog.gameObject.SetActive(false);
|
||||||
|
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
||||||
|
_dialog.PresetPaths = ResourceManager.GetPresetPaths();
|
||||||
|
_dialog.OnClose += OnAddDialogClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool LoadPathPart(int id, GameObject obj) {
|
private bool LoadPathPart(int id, GameObject obj) {
|
||||||
@@ -29,8 +33,13 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
|
|
||||||
private bool LoadItem(int id, GameObject obj) {
|
private bool LoadItem(int id, GameObject obj) {
|
||||||
var bi = obj.GetComponent<BrowserItem>();
|
var bi = obj.GetComponent<BrowserItem>();
|
||||||
var item = ResourceManager.GetItemMeta(id);
|
try {
|
||||||
bi.Load(id, item);
|
var item = ResourceManager.GetItemMeta(id);
|
||||||
|
bi.Load(id, item);
|
||||||
|
}
|
||||||
|
catch (Exception) {
|
||||||
|
bi.Load(id, new ResourceItemMeta { Name = "<color=#ff0000>Invalid resource</color>" });
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +60,6 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnAddButtonClicked() {
|
public void OnAddButtonClicked() {
|
||||||
_dialog.Callback = OnAddDialogClosed;
|
|
||||||
_dialog.Filter = ResourceManager.GetSupportedFormats();
|
|
||||||
_dialog.Show();
|
_dialog.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Common.Unity.UI;
|
using Cryville.Common.Unity.UI;
|
||||||
|
using Cryville.Crtr.Config;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -12,11 +13,12 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
private Button m_playButton;
|
private Button m_playButton;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Button m_configButton;
|
private Button m_configButton;
|
||||||
|
[SerializeField]
|
||||||
|
private ConfigPanelMaster m_configPanel;
|
||||||
|
|
||||||
private DockLayoutGroup _group;
|
private DockLayoutGroup _group;
|
||||||
public ResourceBrowser MainBrowser { get; private set; }
|
public ResourceBrowser MainBrowser { get; private set; }
|
||||||
private DetailPanel _detailPanel;
|
private DetailPanel _detailPanel;
|
||||||
private SettingsPanel _settingsPanel;
|
|
||||||
readonly List<ResourceBrowserUnit> _units = new List<ResourceBrowserUnit>();
|
readonly List<ResourceBrowserUnit> _units = new List<ResourceBrowserUnit>();
|
||||||
|
|
||||||
#pragma warning disable IDE0051
|
#pragma warning disable IDE0051
|
||||||
@@ -25,7 +27,6 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
MainBrowser = transform.GetChild(0).GetComponent<ResourceBrowser>();
|
MainBrowser = transform.GetChild(0).GetComponent<ResourceBrowser>();
|
||||||
MainBrowser.ResourceManager = new LegacyResourceManager(Settings.Default.GameDataPath);
|
MainBrowser.ResourceManager = new LegacyResourceManager(Settings.Default.GameDataPath);
|
||||||
_detailPanel = transform.GetChild(1).GetComponent<DetailPanel>();
|
_detailPanel = transform.GetChild(1).GetComponent<DetailPanel>();
|
||||||
_settingsPanel = transform.GetChild(2).GetComponent<SettingsPanel>();
|
|
||||||
_units.Add(MainBrowser);
|
_units.Add(MainBrowser);
|
||||||
_units.Add(_detailPanel);
|
_units.Add(_detailPanel);
|
||||||
}
|
}
|
||||||
@@ -73,16 +74,13 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
Application.LoadLevelAdditive("Play");
|
Application.LoadLevelAdditive("Play");
|
||||||
#endif
|
#endif
|
||||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
||||||
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
|
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", detail.Meta.song.name, detail.Meta.name), detail.Meta.length);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenConfig(int id, ChartDetail detail) {
|
public void OpenConfig(int id, ChartDetail detail) {
|
||||||
SetDataSettings(id, detail);
|
SetDataSettings(id, detail);
|
||||||
#if UNITY_5_3_OR_NEWER
|
|
||||||
SceneManager.LoadScene("Config", LoadSceneMode.Additive);
|
|
||||||
#else
|
|
||||||
Application.LoadLevelAdditive("Config");
|
|
||||||
#endif
|
|
||||||
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDataSettings(int id, ChartDetail detail) {
|
void SetDataSettings(int id, ChartDetail detail) {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
|
@@ -3,19 +3,26 @@ using Newtonsoft.Json;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using UnsafeIL;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
[JsonConverter(typeof(BeatTimeConverter))]
|
[JsonConverter(typeof(BeatTimeConverter))]
|
||||||
public struct BeatTime {
|
public struct BeatTime : IComparable<BeatTime>, IEquatable<BeatTime> {
|
||||||
[JsonConstructor()]
|
[JsonConstructor()]
|
||||||
public BeatTime(int _b, int _n, int _d) {
|
public BeatTime(int _b, int _n, int _d) {
|
||||||
b = _b;
|
b = _b;
|
||||||
n = _n;
|
n = _n;
|
||||||
d = _d;
|
d = _d;
|
||||||
}
|
}
|
||||||
|
public BeatTime(int _n, int _d) {
|
||||||
|
b = _n / _d;
|
||||||
|
n = _n % _d;
|
||||||
|
d = _d;
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int b;
|
public int b;
|
||||||
|
|
||||||
@@ -24,6 +31,36 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int d;
|
public int d;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public double Decimal { get { return b + (double)n / d; } }
|
||||||
|
|
||||||
|
public int CompareTo(BeatTime other) {
|
||||||
|
var c = b.CompareTo(other.b);
|
||||||
|
if (c != 0) return c;
|
||||||
|
return ((double)n / d).CompareTo((double)other.n / other.d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) {
|
||||||
|
if (!(obj is BeatTime)) return false;
|
||||||
|
return Equals((BeatTime)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(BeatTime other) {
|
||||||
|
return b.Equals(other.b) && ((double)n / d).Equals((double)other.n / other.d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode() {
|
||||||
|
return Decimal.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(BeatTime left, BeatTime right) {
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(BeatTime left, BeatTime right) {
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BeatTimeConverter : JsonConverter {
|
public class BeatTimeConverter : JsonConverter {
|
||||||
@@ -55,7 +92,7 @@ namespace Cryville.Crtr {
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public float BeatPosition {
|
public float BeatPosition {
|
||||||
get {
|
get {
|
||||||
return time.Value.b + time.Value.n / (float)time.Value.d + BeatOffset;
|
return (float)time.Value.Decimal + BeatOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +102,7 @@ namespace Cryville.Crtr {
|
|||||||
public float EndBeatPosition {
|
public float EndBeatPosition {
|
||||||
get {
|
get {
|
||||||
if (endtime == null) return BeatPosition;
|
if (endtime == null) return BeatPosition;
|
||||||
return endtime.Value.b + endtime.Value.n / (float)endtime.Value.d + BeatOffset;
|
return (float)endtime.Value.Decimal + BeatOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,10 +110,11 @@ namespace Cryville.Crtr {
|
|||||||
public float BeatOffset;
|
public float BeatOffset;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public abstract int Priority {
|
public abstract int Priority { get; }
|
||||||
get;
|
|
||||||
}
|
[JsonIgnore]
|
||||||
|
public virtual bool Standalone { get { return false; } }
|
||||||
|
|
||||||
public ChartEvent Clone() {
|
public ChartEvent Clone() {
|
||||||
return (ChartEvent)MemberwiseClone();
|
return (ChartEvent)MemberwiseClone();
|
||||||
}
|
}
|
||||||
@@ -94,20 +132,11 @@ namespace Cryville.Crtr {
|
|||||||
get { return Duration > 0; }
|
get { return Duration > 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private InstantEvent attev = null;
|
private ReleaseEvent relev = null;
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public InstantEvent AttackEvent {
|
public ReleaseEvent ReleaseEvent {
|
||||||
get {
|
get {
|
||||||
if (attev == null) attev = new InstantEvent(this);
|
if (relev == null) relev = new ReleaseEvent(this);
|
||||||
return attev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private InstantEvent relev = null;
|
|
||||||
[JsonIgnore]
|
|
||||||
public InstantEvent ReleaseEvent {
|
|
||||||
get {
|
|
||||||
if (relev == null) relev = new InstantEvent(this, true);
|
|
||||||
return relev;
|
return relev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,6 +155,10 @@ namespace Cryville.Crtr {
|
|||||||
protected ChartEvent() {
|
protected ChartEvent() {
|
||||||
PropSrcs = new Dictionary<int, PropSrc>();
|
PropSrcs = new Dictionary<int, PropSrc>();
|
||||||
PropOps = new Dictionary<int, PropOp>();
|
PropOps = new Dictionary<int, PropOp>();
|
||||||
|
SubmitPropSrc("event", new PropSrc.Float(() => {
|
||||||
|
int hash = GetHashCode();
|
||||||
|
return Unsafe.As<int, float>(ref hash);
|
||||||
|
}));
|
||||||
SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong));
|
SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong));
|
||||||
SubmitPropSrc("time", new PropSrc.BeatTime(() => time.Value));
|
SubmitPropSrc("time", new PropSrc.BeatTime(() => time.Value));
|
||||||
SubmitPropSrc("endtime", new PropSrc.BeatTime(() => endtime.Value));
|
SubmitPropSrc("endtime", new PropSrc.BeatTime(() => endtime.Value));
|
||||||
@@ -134,18 +167,12 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InstantEvent : ChartEvent {
|
public class ReleaseEvent : ChartEvent {
|
||||||
public readonly ChartEvent Original;
|
public readonly ChartEvent Original;
|
||||||
public bool IsRelease;
|
|
||||||
|
|
||||||
public InstantEvent(ChartEvent orig, bool release = false) {
|
public ReleaseEvent(ChartEvent orig) {
|
||||||
IsRelease = release;
|
Original = orig;
|
||||||
if (orig != null) {
|
time = orig.endtime;
|
||||||
Original = orig;
|
|
||||||
time = orig.time;
|
|
||||||
if (IsRelease)
|
|
||||||
BeatOffset = orig.Duration;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Priority {
|
public override int Priority {
|
||||||
@@ -156,6 +183,13 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
public abstract class EventContainer : ChartEvent {
|
public abstract class EventContainer : ChartEvent {
|
||||||
public List<Chart.Motion> motions = new List<Chart.Motion>();
|
public List<Chart.Motion> motions = new List<Chart.Motion>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public Clip Clip { get; private set; }
|
||||||
|
|
||||||
|
public EventContainer() {
|
||||||
|
SubmitPropOp("clip", new PropOp.Clip(v => Clip = v));
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public virtual IEnumerable<ChartEvent> Events {
|
public virtual IEnumerable<ChartEvent> Events {
|
||||||
@@ -167,7 +201,7 @@ namespace Cryville.Crtr {
|
|||||||
public virtual EventList GetEventsOfType(string type) {
|
public virtual EventList GetEventsOfType(string type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "motions": return new EventList<Chart.Motion>(motions);
|
case "motions": return new EventList<Chart.Motion>(motions);
|
||||||
default: throw new ArgumentException("Unknown type");
|
default: throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,9 +265,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Priority {
|
public override int Priority { get { return 10; } }
|
||||||
get { return 10; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Group : EventContainer {
|
public class Group : EventContainer {
|
||||||
public List<Track> tracks = new List<Track>();
|
public List<Track> tracks = new List<Track>();
|
||||||
@@ -253,15 +285,11 @@ namespace Cryville.Crtr {
|
|||||||
default: return base.GetEventsOfType(type);
|
default: return base.GetEventsOfType(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override int Priority {
|
public override int Priority { get { return 10; } }
|
||||||
get { return 10; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Track : EventContainer {
|
public class Track : EventContainer {
|
||||||
public override int Priority {
|
public override int Priority { get { return 10; } }
|
||||||
get { return 10; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Motion : ChartEvent {
|
public class Motion : ChartEvent {
|
||||||
@@ -274,8 +302,10 @@ namespace Cryville.Crtr {
|
|||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
|
|
||||||
private void LoadFromString(string s) {
|
private void LoadFromString(string s) {
|
||||||
|
if (RelativeNode != null || AbsoluteValue != null)
|
||||||
|
throw new InvalidOperationException("The motion property can only be set at initialization");
|
||||||
Match m = Regex.Match(s, @"^(.+?)(#(\d+))?(@(.+?))?(\^(.+?))?(\*(.+?))?(:(.+))?$");
|
Match m = Regex.Match(s, @"^(.+?)(#(\d+))?(@(.+?))?(\^(.+?))?(\*(.+?))?(:(.+))?$");
|
||||||
if (!m.Success) throw new ArgumentException(); // TODO
|
if (!m.Success) throw new ArgumentException("Invalid motion string format");
|
||||||
name = new Identifier(m.Groups[1].Value);
|
name = new Identifier(m.Groups[1].Value);
|
||||||
var registry = ChartPlayer.motionRegistry[name];
|
var registry = ChartPlayer.motionRegistry[name];
|
||||||
if (m.Groups[3].Success) {
|
if (m.Groups[3].Success) {
|
||||||
@@ -295,6 +325,10 @@ namespace Cryville.Crtr {
|
|||||||
else {
|
else {
|
||||||
AbsoluteValue = Vector.Construct(registry.Type, m.Groups[11].Value);
|
AbsoluteValue = Vector.Construct(registry.Type, m.Groups[11].Value);
|
||||||
}
|
}
|
||||||
|
SubmitPropSrc("value", new VectorSrc(() => {
|
||||||
|
if (RelativeNode != null) return RelativeNode.Value;
|
||||||
|
else return AbsoluteValue;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
@@ -303,7 +337,7 @@ namespace Cryville.Crtr {
|
|||||||
var node = RelativeNode;
|
var node = RelativeNode;
|
||||||
result += "#" + node.Id;
|
result += "#" + node.Id;
|
||||||
if (node.Time != null) result += "@" + node.Time.ToString();
|
if (node.Time != null) result += "@" + node.Time.ToString();
|
||||||
if (node.Transition != null) result = "^" + node.Transition.ToString();
|
if (node.Transition != null) result = "^" + ((byte)node.Transition).ToString(CultureInfo.InvariantCulture);
|
||||||
if (node.Rate != null) result += "*" + node.Rate.ToString();
|
if (node.Rate != null) result += "*" + node.Rate.ToString();
|
||||||
if (node.Value != null) result += ":" + node.Value.ToString();
|
if (node.Value != null) result += ":" + node.Value.ToString();
|
||||||
}
|
}
|
||||||
@@ -341,15 +375,9 @@ namespace Cryville.Crtr {
|
|||||||
[DefaultValue(0.0f)]
|
[DefaultValue(0.0f)]
|
||||||
public float sumfix = 0.0f;
|
public float sumfix = 0.0f;
|
||||||
|
|
||||||
public override int Priority {
|
public override int Priority { get { return -2; } }
|
||||||
get { return -2; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Motion() {
|
public Motion() {
|
||||||
SubmitPropSrc("value", new VectorSrc(() => {
|
|
||||||
if (RelativeNode != null) return RelativeNode.Value;
|
|
||||||
else return AbsoluteValue;
|
|
||||||
}));
|
|
||||||
SubmitPropOp("motion", new PropOp.String(v => motion = v));
|
SubmitPropOp("motion", new PropOp.String(v => motion = v));
|
||||||
SubmitPropOp("name", new PropOp.Identifier(v => {
|
SubmitPropOp("name", new PropOp.Identifier(v => {
|
||||||
var n = new Identifier(v);
|
var n = new Identifier(v);
|
||||||
@@ -383,22 +411,21 @@ namespace Cryville.Crtr {
|
|||||||
default: return base.GetEventsOfType(type);
|
default: return base.GetEventsOfType(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override int Priority {
|
public override int Priority { get { return 12; } }
|
||||||
get { return 12; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Judge : ChartEvent {
|
public class Judge : ChartEvent {
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Identifier Id;
|
public Identifier Id;
|
||||||
|
#pragma warning disable IDE1006
|
||||||
public string name {
|
public string name {
|
||||||
get { return Id.ToString(); }
|
get { return Id.ToString(); }
|
||||||
set { Id = new Identifier(value); }
|
set { Id = new Identifier(value); }
|
||||||
}
|
}
|
||||||
|
#pragma warning restore IDE1006
|
||||||
|
|
||||||
public override int Priority {
|
public override int Priority { get { return 0; } }
|
||||||
get { return 0; }
|
public override bool Standalone { get { return true; } }
|
||||||
}
|
|
||||||
|
|
||||||
public Judge() {
|
public Judge() {
|
||||||
SubmitPropSrc("name", new PropSrc.Identifier(() => Id.Key));
|
SubmitPropSrc("name", new PropSrc.Identifier(() => Id.Key));
|
||||||
@@ -412,9 +439,7 @@ namespace Cryville.Crtr {
|
|||||||
public class Signature : ChartEvent {
|
public class Signature : ChartEvent {
|
||||||
public float? tempo;
|
public float? tempo;
|
||||||
|
|
||||||
public override int Priority {
|
public override int Priority { get { return -4; } }
|
||||||
get { return -4; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Sound> sounds;
|
public List<Sound> sounds;
|
||||||
@@ -425,9 +450,7 @@ namespace Cryville.Crtr {
|
|||||||
// TODO [Obsolete]
|
// TODO [Obsolete]
|
||||||
public float offset;
|
public float offset;
|
||||||
|
|
||||||
public override int Priority {
|
public override int Priority { get { return 0; } }
|
||||||
get { return 0; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,22 +14,12 @@ namespace Cryville.Crtr {
|
|||||||
chart = _chart;
|
chart = _chart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string TypeName {
|
public override string TypeName { get { return "chart"; } }
|
||||||
get {
|
|
||||||
return "chart";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void PreInit() {
|
public override void PreInit() {
|
||||||
base.PreInit();
|
base.PreInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose() {
|
|
||||||
if (Disposed) return;
|
|
||||||
base.Dispose();
|
|
||||||
foreach (var s in sounds) s.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Update(ContainerState s, StampedEvent ev) {
|
public override void Update(ContainerState s, StampedEvent ev) {
|
||||||
base.Update(s, ev);
|
base.Update(s, ev);
|
||||||
if (s.CloneType == 16) {
|
if (s.CloneType == 16) {
|
||||||
@@ -50,9 +40,14 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void EndUpdate(ContainerState s) {
|
public override void EndLogicalUpdate(ContainerState s) {
|
||||||
base.EndUpdate(s);
|
base.EndLogicalUpdate(s);
|
||||||
// TODO End of chart
|
// TODO End of chart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void DisposeAll() {
|
||||||
|
base.DisposeAll();
|
||||||
|
foreach (var s in sounds) s.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#define BUILD
|
#define BUILD
|
||||||
|
|
||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
|
using Cryville.Common.Buffers;
|
||||||
using Cryville.Crtr.Config;
|
using Cryville.Crtr.Config;
|
||||||
using Cryville.Crtr.Event;
|
using Cryville.Crtr.Event;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -8,17 +9,19 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Formatting;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using UnityEngine.Scripting;
|
using UnityEngine.Scripting;
|
||||||
using UnityEngine.UI;
|
|
||||||
using diag = System.Diagnostics;
|
using diag = System.Diagnostics;
|
||||||
using Logger = Cryville.Common.Logger;
|
using Logger = Cryville.Common.Logger;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class ChartPlayer : MonoBehaviour {
|
public class ChartPlayer : MonoBehaviour {
|
||||||
|
#region Fields
|
||||||
Chart chart;
|
Chart chart;
|
||||||
Skin skin;
|
Skin skin;
|
||||||
PdtSkin pskin;
|
PdtSkin pskin;
|
||||||
@@ -39,12 +42,14 @@ namespace Cryville.Crtr {
|
|||||||
EventBus bbus;
|
EventBus bbus;
|
||||||
EventBus tbus;
|
EventBus tbus;
|
||||||
EventBus nbus;
|
EventBus nbus;
|
||||||
|
InputProxy inputProxy;
|
||||||
Judge judge;
|
Judge judge;
|
||||||
|
public static EffectManager effectManager;
|
||||||
bool started = false;
|
bool started = false;
|
||||||
|
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
static Text logs;
|
TextMeshProUGUI logs;
|
||||||
Text status;
|
TextMeshProUGUI status;
|
||||||
|
|
||||||
static Vector2 screenSize;
|
static Vector2 screenSize;
|
||||||
public static Rect hitRect;
|
public static Rect hitRect;
|
||||||
@@ -54,9 +59,10 @@ namespace Cryville.Crtr {
|
|||||||
static bool disableGC = true;
|
static bool disableGC = true;
|
||||||
static float clippingDist = 1f;
|
static float clippingDist = 1f;
|
||||||
static float renderDist = 6f;
|
static float renderDist = 6f;
|
||||||
static float renderStep = 0.05f;
|
static double renderStep = 0.05;
|
||||||
public static float actualRenderStep = 0f;
|
public static double actualRenderStep = 0;
|
||||||
static bool autoRenderStep = false;
|
static bool autoRenderStep = false;
|
||||||
|
public static float graphicalOffset = 0;
|
||||||
public static float soundOffset = 0;
|
public static float soundOffset = 0;
|
||||||
static float startOffset = 0;
|
static float startOffset = 0;
|
||||||
public static float sv = 16f;
|
public static float sv = 16f;
|
||||||
@@ -64,14 +70,15 @@ namespace Cryville.Crtr {
|
|||||||
public static Dictionary<Identifier, MotionRegistry> motionRegistry = new Dictionary<Identifier, MotionRegistry>();
|
public static Dictionary<Identifier, MotionRegistry> motionRegistry = new Dictionary<Identifier, MotionRegistry>();
|
||||||
|
|
||||||
public static PdtEvaluator etor;
|
public static PdtEvaluator etor;
|
||||||
|
#endregion
|
||||||
InputProxy inputProxy;
|
|
||||||
|
|
||||||
#region MonoBehaviour
|
#region MonoBehaviour
|
||||||
void Start() {
|
void Start() {
|
||||||
|
d_addLogEntry = new Action<int, string, string>(AddLogEntry);
|
||||||
|
|
||||||
var logobj = GameObject.Find("Logs");
|
var logobj = GameObject.Find("Logs");
|
||||||
if (logobj != null)
|
if (logobj != null)
|
||||||
logs = logobj.GetComponent<Text>();
|
logs = logobj.GetComponent<TextMeshProUGUI>();
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
Game.Init();
|
Game.Init();
|
||||||
GenericResources.LoadDefault();
|
GenericResources.LoadDefault();
|
||||||
@@ -79,7 +86,7 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
OnSettingsUpdate();
|
OnSettingsUpdate();
|
||||||
|
|
||||||
status = GameObject.Find("Status").GetComponent<Text>();
|
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
|
||||||
|
|
||||||
texHandler = new DownloadHandlerTexture();
|
texHandler = new DownloadHandlerTexture();
|
||||||
#if BUILD
|
#if BUILD
|
||||||
@@ -105,13 +112,12 @@ namespace Cryville.Crtr {
|
|||||||
if (texLoader != null) texLoader.Dispose();
|
if (texLoader != null) texLoader.Dispose();
|
||||||
if (inputProxy != null) inputProxy.Dispose();
|
if (inputProxy != null) inputProxy.Dispose();
|
||||||
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
||||||
Camera.onPostRender -= OnCameraPostRender;
|
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool texloaddone;
|
bool texloaddone;
|
||||||
diag::Stopwatch texloadtimer = new diag::Stopwatch();
|
diag::Stopwatch texloadtimer = new diag::Stopwatch();
|
||||||
bool firstFrame;
|
int forceSyncFrames;
|
||||||
double atime0;
|
double atime0;
|
||||||
void Update() {
|
void Update() {
|
||||||
if (started) GameUpdate();
|
if (started) GameUpdate();
|
||||||
@@ -123,11 +129,20 @@ namespace Cryville.Crtr {
|
|||||||
try {
|
try {
|
||||||
if (Screen.width != screenSize.x || Screen.height != screenSize.y)
|
if (Screen.width != screenSize.x || Screen.height != screenSize.y)
|
||||||
throw new InvalidOperationException("Window resized while playing");
|
throw new InvalidOperationException("Window resized while playing");
|
||||||
float dt = firstFrame
|
double dt, step;
|
||||||
? 1f / Application.targetFrameRate
|
if (forceSyncFrames != 0) {
|
||||||
: Time.deltaTime;
|
forceSyncFrames--;
|
||||||
firstFrame = false;
|
double target = Game.AudioClient.Position - atime0;
|
||||||
|
dt = target - cbus.Time - graphicalOffset;
|
||||||
|
step = autoRenderStep ? 1f / Application.targetFrameRate : renderStep;
|
||||||
|
inputProxy.SyncTime(target);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dt = Time.deltaTime;
|
||||||
|
step = autoRenderStep ? Time.smoothDeltaTime : renderStep;
|
||||||
|
}
|
||||||
inputProxy.ForceTick();
|
inputProxy.ForceTick();
|
||||||
|
if (paused) return;
|
||||||
cbus.ForwardByTime(dt);
|
cbus.ForwardByTime(dt);
|
||||||
bbus.ForwardByTime(dt);
|
bbus.ForwardByTime(dt);
|
||||||
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
|
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
|
||||||
@@ -135,20 +150,19 @@ namespace Cryville.Crtr {
|
|||||||
bbus.CopyTo(2, tbus);
|
bbus.CopyTo(2, tbus);
|
||||||
bbus.CopyTo(3, nbus);
|
bbus.CopyTo(3, nbus);
|
||||||
UnityEngine.Profiling.Profiler.EndSample();
|
UnityEngine.Profiling.Profiler.EndSample();
|
||||||
float step = autoRenderStep ? ( firstFrame
|
|
||||||
? 1f / Application.targetFrameRate
|
|
||||||
: Time.smoothDeltaTime
|
|
||||||
) : renderStep;
|
|
||||||
actualRenderStep = step;
|
actualRenderStep = step;
|
||||||
|
|
||||||
nbus.ForwardStepByTime(clippingDist, step);
|
nbus.ForwardStepByTime(clippingDist, step);
|
||||||
nbus.BroadcastEndUpdate();
|
nbus.EndPreGraphicalUpdate();
|
||||||
nbus.Anchor();
|
nbus.Anchor();
|
||||||
|
|
||||||
|
tbus.StripTempEvents();
|
||||||
tbus.ForwardStepByTime(clippingDist, step);
|
tbus.ForwardStepByTime(clippingDist, step);
|
||||||
tbus.ForwardStepByTime(renderDist, step);
|
tbus.ForwardStepByTime(renderDist, step);
|
||||||
tbus.BroadcastEndUpdate();
|
tbus.EndGraphicalUpdate();
|
||||||
UnityEngine.Profiling.Profiler.EndSample();
|
UnityEngine.Profiling.Profiler.EndSample();
|
||||||
|
|
||||||
|
effectManager.Tick(cbus.Time);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Game.LogException("Game", "An error occured while playing", ex);
|
Game.LogException("Game", "An error occured while playing", ex);
|
||||||
@@ -161,10 +175,21 @@ namespace Cryville.Crtr {
|
|||||||
string url = texLoader.url;
|
string url = texLoader.url;
|
||||||
string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1));
|
string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1));
|
||||||
#if UNITY_5_4_OR_NEWER
|
#if UNITY_5_4_OR_NEWER
|
||||||
if (texHandler.isDone) {
|
if (texLoader.isDone) {
|
||||||
var tex = texHandler.texture;
|
if (texHandler.isDone) {
|
||||||
tex.wrapMode = TextureWrapMode.Clamp;
|
var tex = texHandler.texture;
|
||||||
texs.Add(name, tex);
|
tex.wrapMode = TextureWrapMode.Clamp;
|
||||||
|
if (frames.ContainsKey(name)) {
|
||||||
|
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
frames.Add(name, new SpriteFrame(tex));
|
||||||
|
}
|
||||||
|
texs.Add(name, tex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Logger.Log("main", 4, "Load/Prehandle", "Unable to load texture: {0}", name);
|
||||||
|
}
|
||||||
texLoader.Dispose();
|
texLoader.Dispose();
|
||||||
texHandler.Dispose();
|
texHandler.Dispose();
|
||||||
texLoader = null;
|
texLoader = null;
|
||||||
@@ -179,14 +204,14 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (texLoader == null)
|
if (texLoader == null) {
|
||||||
if (texLoadQueue.Count > 0) {
|
if (texLoadQueue.Count > 0) {
|
||||||
#if UNITY_5_4_OR_NEWER
|
#if UNITY_5_4_OR_NEWER
|
||||||
texHandler = new DownloadHandlerTexture();
|
texHandler = new DownloadHandlerTexture();
|
||||||
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + texLoadQueue.Dequeue(), "GET", texHandler, null);
|
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + texLoadQueue.Dequeue(), "GET", texHandler, null);
|
||||||
texLoader.SendWebRequest();
|
texLoader.SendWebRequest();
|
||||||
#else
|
#else
|
||||||
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
texLoader = new WWW(Game.FileProtocolPrefix + texLoadQueue.Dequeue());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (!texloaddone) {
|
else if (!texloaddone) {
|
||||||
@@ -194,6 +219,7 @@ namespace Cryville.Crtr {
|
|||||||
texloadtimer.Stop();
|
texloadtimer.Stop();
|
||||||
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", texloadtimer.Elapsed.TotalMilliseconds);
|
Logger.Log("main", 1, "Load/MainThread", "Main thread done ({0}ms)", texloadtimer.Elapsed.TotalMilliseconds);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!loadThread.IsAlive) {
|
if (!loadThread.IsAlive) {
|
||||||
if (threadException != null) {
|
if (threadException != null) {
|
||||||
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
Logger.Log("main", 4, "Load/MainThread", "Load failed");
|
||||||
@@ -209,55 +235,89 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string timetext = string.Empty;
|
readonly TargetString statusstr = new TargetString();
|
||||||
void LogUpdate() {
|
readonly StringBuffer statusbuf = new StringBuffer();
|
||||||
string _logs = logs.text;
|
readonly TargetString logsstr = new TargetString();
|
||||||
Game.MainLogger.Enumerate((level, module, msg) => {
|
readonly StringBuffer logsbuf = new StringBuffer();
|
||||||
string color;
|
readonly List<string> logEntries = new List<string>();
|
||||||
switch (level) {
|
int logsLength = 0;
|
||||||
case 0: color = "#888888"; break;
|
Action<int, string, string> d_addLogEntry;
|
||||||
case 1: color = "#bbbbbb"; break;
|
void AddLogEntry(int level, string module, string msg) {
|
||||||
case 2: color = "#0088ff"; break;
|
string color;
|
||||||
case 3: color = "#ffff00"; break;
|
switch (level) {
|
||||||
case 4: color = "#ff0000"; break;
|
case 0: color = "#888888"; break;
|
||||||
case 5: color = "#bb0000"; break;
|
case 1: color = "#bbbbbb"; break;
|
||||||
default: color = "#ff00ff"; break;
|
case 2: color = "#0088ff"; break;
|
||||||
}
|
case 3: color = "#ffff00"; break;
|
||||||
_logs += string.Format(
|
case 4: color = "#ff0000"; break;
|
||||||
"\r\n<color={1}bb><{2}> {3}</color>",
|
case 5: color = "#bb0000"; break;
|
||||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
default: color = "#ff00ff"; break;
|
||||||
);
|
}
|
||||||
});
|
var l = string.Format(
|
||||||
logs.text = _logs.Substring(Mathf.Max(0, _logs.IndexOf('\n', Mathf.Max(0, _logs.Length - 4096))));
|
"\n<color={1}bb><{2}> {3}</color>",
|
||||||
var sttext = string.Format(
|
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||||
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
|
||||||
1 / Time.deltaTime,
|
|
||||||
1 / Time.smoothDeltaTime,
|
|
||||||
#if UNITY_5_6_OR_NEWER
|
|
||||||
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
|
|
||||||
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(),
|
|
||||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
|
|
||||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
|
|
||||||
#else
|
|
||||||
UnityEngine.Profiling.Profiler.GetMonoUsedSize(),
|
|
||||||
UnityEngine.Profiling.Profiler.GetMonoHeapSize(),
|
|
||||||
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemory(),
|
|
||||||
UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
sttext += timetext;
|
|
||||||
if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString();
|
|
||||||
status.text = sttext;
|
|
||||||
}
|
|
||||||
void OnCameraPostRender(Camera cam) {
|
|
||||||
if (!logEnabled) return;
|
|
||||||
if (started) timetext = string.Format(
|
|
||||||
"\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}",
|
|
||||||
cbus.Time,
|
|
||||||
Game.AudioClient.Position - atime0,
|
|
||||||
inputProxy.GetTimestampAverage()
|
|
||||||
);
|
);
|
||||||
else timetext = string.Empty;
|
logEntries.Add(l);
|
||||||
|
logsLength += l.Length;
|
||||||
|
}
|
||||||
|
void LogUpdate() {
|
||||||
|
logsbuf.Clear();
|
||||||
|
Game.MainLogger.Enumerate(d_addLogEntry);
|
||||||
|
while (logsLength >= 4096) {
|
||||||
|
logsLength -= logEntries[0].Length;
|
||||||
|
logEntries.RemoveAt(0);
|
||||||
|
}
|
||||||
|
foreach (var l in logEntries) {
|
||||||
|
logsbuf.Append(l);
|
||||||
|
}
|
||||||
|
logsstr.Length = logsbuf.Count;
|
||||||
|
var larr = logsstr.TrustedAsArray();
|
||||||
|
logsbuf.CopyTo(0, larr, 0, logsbuf.Count);
|
||||||
|
logs.SetText(larr, 0, logsbuf.Count);
|
||||||
|
|
||||||
|
statusbuf.Clear();
|
||||||
|
statusbuf.AppendFormat(
|
||||||
|
"FPS: i{0:0} / s{1:0}\nSMem: {2:N0} / {3:N0}\nIMem: {4:N0} / {5:N0}",
|
||||||
|
1 / Time.deltaTime,
|
||||||
|
1 / Time.smoothDeltaTime,
|
||||||
|
#if UNITY_5_6_OR_NEWER
|
||||||
|
UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong(),
|
||||||
|
UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong(),
|
||||||
|
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong(),
|
||||||
|
UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()
|
||||||
|
#else
|
||||||
|
UnityEngine.Profiling.Profiler.GetMonoUsedSize(),
|
||||||
|
UnityEngine.Profiling.Profiler.GetMonoHeapSize(),
|
||||||
|
UnityEngine.Profiling.Profiler.GetTotalAllocatedMemory(),
|
||||||
|
UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
if (started) {
|
||||||
|
statusbuf.AppendFormat(
|
||||||
|
"\nStates: c{0} / b{1}\nPools: RMV {2}, MC {3}",
|
||||||
|
cbus.ActiveStateCount, bbus.ActiveStateCount,
|
||||||
|
ContainerState.RMVPool.RentedCount,
|
||||||
|
ContainerState.MCPool.RentedCount
|
||||||
|
);
|
||||||
|
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,
|
||||||
|
forceSyncFrames != 0 ? "(force sync)" : "",
|
||||||
|
paused ? "(paused)" : "",
|
||||||
|
paused ? "(semi-locked)" : ""
|
||||||
|
);
|
||||||
|
if (judge != null) {
|
||||||
|
statusbuf.Append("\n== Scores ==\n");
|
||||||
|
var fullScoreStr = judge.GetFullFormattedScoreString();
|
||||||
|
statusbuf.Append(fullScoreStr.TrustedAsArray(), 0, fullScoreStr.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
statusstr.Length = statusbuf.Count;
|
||||||
|
var sarr = statusstr.TrustedAsArray();
|
||||||
|
statusbuf.CopyTo(0, sarr, 0, statusbuf.Count);
|
||||||
|
status.SetText(sarr, 0, statusbuf.Count);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -278,14 +338,19 @@ namespace Cryville.Crtr {
|
|||||||
SceneManager.UnloadSceneAsync("Play");
|
SceneManager.UnloadSceneAsync("Play");
|
||||||
#elif UNITY_5_3_OR_NEWER
|
#elif UNITY_5_3_OR_NEWER
|
||||||
SceneManager.UnloadScene("Play");
|
SceneManager.UnloadScene("Play");
|
||||||
|
#endif
|
||||||
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
||||||
|
DiscordController.Instance.SetIdle();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
|
|
||||||
bool logEnabled = true;
|
bool logEnabled = true;
|
||||||
public void ToggleLogs() {
|
public void ToggleLogs() {
|
||||||
|
logEntries.Clear();
|
||||||
|
logsLength = 0;
|
||||||
logs.text = "";
|
logs.text = "";
|
||||||
status.text = "";
|
status.SetText("");
|
||||||
logEnabled = !logEnabled;
|
logEnabled = !logEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,6 +361,20 @@ namespace Cryville.Crtr {
|
|||||||
else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading");
|
else Logger.Log("main", 2, "Load/MainThread", "The chart is currently loading");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool paused = false;
|
||||||
|
public void TogglePause() {
|
||||||
|
paused = !paused;
|
||||||
|
if (!paused) {
|
||||||
|
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
||||||
|
Game.AudioClient.Start();
|
||||||
|
inputProxy.UnlockTime();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Game.AudioClient.Pause();
|
||||||
|
inputProxy.LockTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Load
|
#region Load
|
||||||
@@ -306,15 +385,14 @@ namespace Cryville.Crtr {
|
|||||||
renderStep = Settings.Default.RenderStep;
|
renderStep = Settings.Default.RenderStep;
|
||||||
actualRenderStep = renderStep;
|
actualRenderStep = renderStep;
|
||||||
autoRenderStep = renderStep == 0;
|
autoRenderStep = renderStep == 0;
|
||||||
|
graphicalOffset = Settings.Default.GraphicalOffset;
|
||||||
soundOffset = Settings.Default.SoundOffset;
|
soundOffset = Settings.Default.SoundOffset;
|
||||||
startOffset = Settings.Default.StartOffset;
|
startOffset = Settings.Default.StartOffset;
|
||||||
firstFrame = true;
|
forceSyncFrames = Settings.Default.ForceSyncFrames;
|
||||||
texloaddone = false;
|
texloaddone = false;
|
||||||
Game.NetworkTaskWorker.SuspendBackgroundTasks();
|
Game.NetworkTaskWorker.SuspendBackgroundTasks();
|
||||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||||
|
|
||||||
Camera.onPostRender += OnCameraPostRender;
|
|
||||||
|
|
||||||
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
||||||
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
||||||
float dist;
|
float dist;
|
||||||
@@ -347,6 +425,7 @@ namespace Cryville.Crtr {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
sv = _rscfg.generic.ScrollVelocity;
|
sv = _rscfg.generic.ScrollVelocity;
|
||||||
|
soundOffset += _rscfg.generic.SoundOffset;
|
||||||
|
|
||||||
FileInfo skinFile = new FileInfo(
|
FileInfo skinFile = new FileInfo(
|
||||||
string.Format("{0}/skins/{1}/{2}/.umgs", Game.GameDataPath, rulesetFile.Directory.Name, _rscfg.generic.Skin)
|
string.Format("{0}/skins/{1}/{2}/.umgs", Game.GameDataPath, rulesetFile.Directory.Name, _rscfg.generic.Skin)
|
||||||
@@ -371,8 +450,9 @@ namespace Cryville.Crtr {
|
|||||||
texloadtimer.Start();
|
texloadtimer.Start();
|
||||||
frames = new Dictionary<string, SpriteFrame>();
|
frames = new Dictionary<string, SpriteFrame>();
|
||||||
texs = new Dictionary<string, Texture2D>();
|
texs = new Dictionary<string, Texture2D>();
|
||||||
|
var skinDir = skinFile.Directory.FullName;
|
||||||
foreach (var f in skin.frames) {
|
foreach (var f in skin.frames) {
|
||||||
texLoadQueue.Enqueue(Path.Combine(skinFile.Directory.FullName, f));
|
texLoadQueue.Enqueue(Path.Combine(skinDir, f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,25 +460,29 @@ namespace Cryville.Crtr {
|
|||||||
try {
|
try {
|
||||||
diag::Stopwatch timer = new diag::Stopwatch();
|
diag::Stopwatch timer = new diag::Stopwatch();
|
||||||
timer.Reset(); timer.Start();
|
timer.Reset(); timer.Start();
|
||||||
|
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)");
|
||||||
|
cbus.BroadcastPreInit();
|
||||||
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)");
|
||||||
foreach (var t in texs) {
|
using (var pbus = cbus.Clone(17)) {
|
||||||
if (frames.ContainsKey(t.Key)) {
|
pbus.Forward();
|
||||||
Logger.Log("main", 3, "Load/Prehandle", "Duplicated texture name: {0}", t.Key);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var f = new SpriteFrame(t.Value);
|
|
||||||
f.Init();
|
|
||||||
frames.Add(t.Key, f);
|
|
||||||
}
|
}
|
||||||
Logger.Log("main", 0, "Load/Prehandle", "Initializing states");
|
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)");
|
||||||
cbus.BroadcastInit();
|
cbus.BroadcastPostInit();
|
||||||
inputProxy.Activate();
|
inputProxy.Activate();
|
||||||
if (logEnabled) ToggleLogs();
|
if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs();
|
||||||
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up");
|
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up");
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
|
if (disableGC) GarbageCollector.GCMode = GarbageCollector.Mode.Disabled;
|
||||||
|
cbus.ForwardByTime(startOffset);
|
||||||
|
bbus.ForwardByTime(startOffset);
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds);
|
Logger.Log("main", 1, "Load/Prehandle", "Prehandling done ({0}ms)", timer.Elapsed.TotalMilliseconds);
|
||||||
|
if (Settings.Default.ClearLogOnPlay) {
|
||||||
|
logEntries.Clear();
|
||||||
|
logsLength = 0;
|
||||||
|
Game.MainLogger.Enumerate((level, module, msg) => { });
|
||||||
|
logs.text = "";
|
||||||
|
}
|
||||||
Game.AudioSequencer.Playing = true;
|
Game.AudioSequencer.Playing = true;
|
||||||
atime0 = Game.AudioClient.BufferPosition;
|
atime0 = Game.AudioClient.BufferPosition;
|
||||||
Thread.Sleep((int)((atime0 - Game.AudioClient.Position) * 1000));
|
Thread.Sleep((int)((atime0 - Game.AudioClient.Position) * 1000));
|
||||||
@@ -415,12 +499,16 @@ namespace Cryville.Crtr {
|
|||||||
public void Stop() {
|
public void Stop() {
|
||||||
try {
|
try {
|
||||||
Logger.Log("main", 1, "Game", "Stopping");
|
Logger.Log("main", 1, "Game", "Stopping");
|
||||||
|
Game.AudioClient.Start();
|
||||||
Game.AudioSession = Game.AudioSequencer.NewSession();
|
Game.AudioSession = Game.AudioSequencer.NewSession();
|
||||||
inputProxy.Deactivate();
|
inputProxy.Deactivate();
|
||||||
if (cbus != null) { cbus.Dispose(); cbus = null; }
|
|
||||||
if (bbus != null) { bbus.Dispose(); bbus = null; }
|
|
||||||
if (tbus != null) { tbus.Dispose(); tbus = null; }
|
|
||||||
if (nbus != null) { nbus.Dispose(); nbus = 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;
|
||||||
Logger.Log("main", 1, "Game", "Stopped");
|
Logger.Log("main", 1, "Game", "Stopped");
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@@ -464,7 +552,6 @@ namespace Cryville.Crtr {
|
|||||||
try {
|
try {
|
||||||
workerTimer = new diag::Stopwatch();
|
workerTimer = new diag::Stopwatch();
|
||||||
workerTimer.Start();
|
workerTimer.Start();
|
||||||
RMVPool.Prepare();
|
|
||||||
LoadChart(info);
|
LoadChart(info);
|
||||||
workerTimer.Stop();
|
workerTimer.Stop();
|
||||||
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
Logger.Log("main", 1, "Load/WorkerThread", "Worker thread done ({0}ms)", workerTimer.Elapsed.TotalMilliseconds);
|
||||||
@@ -496,16 +583,16 @@ namespace Cryville.Crtr {
|
|||||||
var batcher = new EventBatcher(chart);
|
var batcher = new EventBatcher(chart);
|
||||||
batcher.Forward();
|
batcher.Forward();
|
||||||
cbus = batcher.Batch();
|
cbus = batcher.Batch();
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Batched {0} event batches", cbus.events.Count);
|
|
||||||
|
|
||||||
LoadSkin(info.skinFile);
|
LoadSkin(info.skinFile);
|
||||||
|
|
||||||
judge = new Judge(pruleset);
|
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input");
|
||||||
|
judge = new Judge(this, pruleset);
|
||||||
etor.ContextJudge = judge;
|
etor.ContextJudge = judge;
|
||||||
|
|
||||||
inputProxy = new InputProxy(pruleset, judge);
|
inputProxy = new InputProxy(pruleset, judge);
|
||||||
inputProxy.LoadFrom(_rscfg.inputs);
|
inputProxy.LoadFrom(_rscfg.inputs);
|
||||||
if (!inputProxy.IsCompleted) {
|
if (!inputProxy.IsCompleted()) {
|
||||||
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
throw new ArgumentException("Input config not completed\nPlease complete the input settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,10 +605,10 @@ namespace Cryville.Crtr {
|
|||||||
foreach (var ts in gs.Value.Children) {
|
foreach (var ts in gs.Value.Children) {
|
||||||
ContainerHandler th;
|
ContainerHandler th;
|
||||||
if (ts.Key is Chart.Note) {
|
if (ts.Key is Chart.Note) {
|
||||||
th = new NoteHandler(gh, (Chart.Note)ts.Key, pruleset, judge);
|
th = new NoteHandler((Chart.Note)ts.Key, gh);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
th = new TrackHandler(gh, (Chart.Track)ts.Key);
|
th = new TrackHandler((Chart.Track)ts.Key, gh);
|
||||||
}
|
}
|
||||||
ts.Value.AttachHandler(th);
|
ts.Value.AttachHandler(th);
|
||||||
}
|
}
|
||||||
@@ -531,12 +618,6 @@ namespace Cryville.Crtr {
|
|||||||
using (var pbus = cbus.Clone(16)) {
|
using (var pbus = cbus.Clone(16)) {
|
||||||
pbus.Forward();
|
pbus.Forward();
|
||||||
}
|
}
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Patching events");
|
|
||||||
cbus.DoPatch();
|
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Prehandling (iteration 2)");
|
|
||||||
using (var pbus = cbus.Clone(17)) {
|
|
||||||
pbus.Forward();
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)");
|
Logger.Log("main", 0, "Load/WorkerThread", "Cloning states (type 1)");
|
||||||
bbus = cbus.Clone(1, -clippingDist);
|
bbus = cbus.Clone(1, -clippingDist);
|
||||||
@@ -559,6 +640,8 @@ namespace Cryville.Crtr {
|
|||||||
pruleset = ruleset.Root;
|
pruleset = ruleset.Root;
|
||||||
pruleset.Optimize(etor);
|
pruleset.Optimize(etor);
|
||||||
}
|
}
|
||||||
|
ContainerState.RMVPool = new RMVPool();
|
||||||
|
ContainerState.MCPool = new MotionCachePool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSkin(FileInfo file) {
|
void LoadSkin(FileInfo file) {
|
||||||
@@ -567,6 +650,7 @@ namespace Cryville.Crtr {
|
|||||||
skin.LoadPdt(dir);
|
skin.LoadPdt(dir);
|
||||||
pskin = skin.Root;
|
pskin = skin.Root;
|
||||||
pskin.Optimize(etor);
|
pskin.Optimize(etor);
|
||||||
|
effectManager = new EffectManager(pskin);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
10
Assets/Cryville/Crtr/Clip.cs
Normal file
10
Assets/Cryville/Crtr/Clip.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Cryville.Crtr {
|
||||||
|
public struct Clip {
|
||||||
|
public float Behind { get; set; }
|
||||||
|
public float Ahead { get; set; }
|
||||||
|
public Clip(float behind, float ahead) {
|
||||||
|
Behind = behind;
|
||||||
|
Ahead = ahead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Clip.cs.meta
Normal file
11
Assets/Cryville/Crtr/Clip.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 31109f74226deb947b93732206b112ed
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,12 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Components {
|
namespace Cryville.Crtr.Components {
|
||||||
public abstract class MeshBase : SkinComponent {
|
public abstract class MeshBase : SkinComponent {
|
||||||
public MeshBase() {
|
public MeshBase() {
|
||||||
|
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
||||||
|
SubmitProperty("opacity", new PropOp.Float(v => {
|
||||||
|
var c = Color;
|
||||||
|
c.a *= v;
|
||||||
|
Color = c;
|
||||||
|
}));
|
||||||
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
|
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MeshWrapper mesh = new MeshWrapper();
|
protected MeshWrapper mesh = new MeshWrapper();
|
||||||
|
protected Material[] materials;
|
||||||
|
|
||||||
short _zindex;
|
short _zindex;
|
||||||
public short ZIndex {
|
public short ZIndex {
|
||||||
@@ -22,7 +30,36 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
protected void UpdateZIndex() {
|
protected void UpdateZIndex() {
|
||||||
if (!mesh.Initialized) return;
|
if (!mesh.Initialized) return;
|
||||||
mesh.Renderer.material.renderQueue = _zindex;
|
foreach (var mat in materials) {
|
||||||
|
mat.renderQueue = _zindex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Color _color = Color.white;
|
||||||
|
public Color Color {
|
||||||
|
get { return _color; }
|
||||||
|
set {
|
||||||
|
_color = value;
|
||||||
|
UpdateColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void UpdateColor() {
|
||||||
|
if (!mesh.Initialized) return;
|
||||||
|
foreach (var mat in materials) {
|
||||||
|
mat.color = _color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDestroy() {
|
||||||
|
DestroyMaterials();
|
||||||
|
mesh.Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void DestroyMaterials() {
|
||||||
|
if (materials == null) return;
|
||||||
|
foreach (var mat in materials) {
|
||||||
|
Material.Destroy(mat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,9 +9,17 @@ namespace Cryville.Crtr.Components {
|
|||||||
protected Vector3? prevpt;
|
protected Vector3? prevpt;
|
||||||
protected Quaternion? prevrot;
|
protected Quaternion? prevrot;
|
||||||
protected int vertCount = 0;
|
protected int vertCount = 0;
|
||||||
|
Part part = Part.whole;
|
||||||
|
enum Part {
|
||||||
|
whole = 0,
|
||||||
|
idle = 1,
|
||||||
|
start = 2,
|
||||||
|
end = 3,
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnDestroy() {
|
public SectionalGameObject() {
|
||||||
mesh.Destroy();
|
SubmitProperty("partial", new PropOp.Boolean(v => part = Part.idle));
|
||||||
|
SubmitProperty("part", new PropOp.Enum<Part>(v => part = v, v => (Part)v), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
@@ -23,7 +31,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void AppendPoint(Vector3 p, Quaternion r) {
|
public void AppendPoint(Vector3 p, Quaternion r) {
|
||||||
if (prevpt == p && prevrot == r) return;
|
if (prevpt == p && prevrot == r || ((int)part & 1) == 1) return;
|
||||||
AppendPointInternal(p, r);
|
AppendPointInternal(p, r);
|
||||||
// if (!headGenerated) Logger.Log("main", 0, "Skin/Polysec", "{0}", r);
|
// if (!headGenerated) Logger.Log("main", 0, "Skin/Polysec", "{0}", r);
|
||||||
prevpt = p;
|
prevpt = p;
|
||||||
@@ -55,7 +63,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
|
||||||
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
|
||||||
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
|
||||||
SubmitProperty("shape", new op_set_shape(this));
|
SubmitProperty("shape", new op_set_shape(this), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
@@ -68,11 +76,10 @@ namespace Cryville.Crtr.Components {
|
|||||||
var o = GetOperand(0);
|
var o = GetOperand(0);
|
||||||
if (o.Type != PdtInternalType.Vector) throw new ArgumentException("Not a vector");
|
if (o.Type != PdtInternalType.Vector) throw new ArgumentException("Not a vector");
|
||||||
_self._shapeLength = (o.Length - sizeof(int)) / sizeof(Vector2);
|
_self._shapeLength = (o.Length - sizeof(int)) / sizeof(Vector2);
|
||||||
var ptr = (Vector2*)o.TrustedAsOfLength(sizeof(Vector2));
|
|
||||||
if (_self._shape != null) _shapePool.Return(_self._shape);
|
if (_self._shape != null) _shapePool.Return(_self._shape);
|
||||||
_self._shape = _shapePool.Rent(_self._shapeLength);
|
_self._shape = _shapePool.Rent(_self._shapeLength);
|
||||||
for (int i = 0; i < _self._shapeLength; i++) {
|
for (int i = 0; i < _self._shapeLength; i++) {
|
||||||
_self._shape[i] = ptr[i];
|
_self._shape[i] = o.As<Vector2>(i * sizeof(Vector2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,38 +105,29 @@ namespace Cryville.Crtr.Components {
|
|||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
base.Init();
|
base.Init();
|
||||||
|
|
||||||
head.Load();
|
|
||||||
body.Load();
|
|
||||||
tail.Load();
|
|
||||||
|
|
||||||
mesh.Init(transform);
|
mesh.Init(transform);
|
||||||
|
|
||||||
List<Material> materials = new List<Material>();
|
mesh.Renderer.sharedMaterials = materials = new Material[] {
|
||||||
if (head.FrameName != null) AddMat(materials, head.FrameName);
|
MeshWrapper.NewMaterial(),
|
||||||
if (body.FrameName != null) AddMat(materials, body.FrameName);
|
MeshWrapper.NewMaterial(),
|
||||||
if (tail.FrameName != null) AddMat(materials, tail.FrameName);
|
MeshWrapper.NewMaterial(),
|
||||||
mesh.Renderer.materials = materials.ToArray();
|
};
|
||||||
}
|
head.Bind(materials[0]);
|
||||||
|
body.Bind(materials[1]);
|
||||||
|
tail.Bind(materials[2]);
|
||||||
|
|
||||||
void AddMat(List<Material> list, string frame) {
|
UpdateZIndex();
|
||||||
var mat = mesh.NewMaterial;
|
|
||||||
mat.mainTexture = ChartPlayer.frames[frame].Texture;
|
|
||||||
list.Add(mat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDestroy() {
|
protected override void OnDestroy() {
|
||||||
base.OnDestroy();
|
|
||||||
Reset();
|
|
||||||
foreach (var m in mesh.Renderer.materials) Material.Destroy(m);
|
|
||||||
if (_shape != null) _shapePool.Return(_shape);
|
if (_shape != null) _shapePool.Return(_shape);
|
||||||
if (vertices != null) {
|
if (vertices != null) {
|
||||||
_ptPool.Return(vertices);
|
_ptPool.Return(vertices);
|
||||||
_lPool.Return(lengths);
|
_lPool.Return(lengths);
|
||||||
}
|
}
|
||||||
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vector3 prevp = Vector3.zero;
|
|
||||||
protected override void AppendPointInternal(Vector3 p, Quaternion r) {
|
protected override void AppendPointInternal(Vector3 p, Quaternion r) {
|
||||||
if (vertices == null) {
|
if (vertices == null) {
|
||||||
vertices = _ptPool.Rent();
|
vertices = _ptPool.Rent();
|
||||||
@@ -151,15 +149,16 @@ namespace Cryville.Crtr.Components {
|
|||||||
List<Vector3> verts;
|
List<Vector3> verts;
|
||||||
List<Vector2> uvs;
|
List<Vector2> uvs;
|
||||||
List<int> trih = null, trib = null, trit = null;
|
List<int> trih = null, trib = null, trit = null;
|
||||||
|
static readonly List<int> _emptyTris = new List<int>();
|
||||||
|
|
||||||
public override void Seal() {
|
public override void Seal() {
|
||||||
if (vertCount <= 1 || sumLength == 0) return;
|
if (vertCount <= 1 || sumLength == 0) return;
|
||||||
int vcpsec = _shapeLength; // Vertex Count Per Section
|
int vcpsec = _shapeLength; // Vertex Count Per Section
|
||||||
float width = GetWidth();
|
float width = GetWidth();
|
||||||
float headLength = 0;
|
float headLength = 0;
|
||||||
if (head.FrameName != null) headLength = width / head.Ratio;
|
if (head.Frame != null) headLength = width / head.Ratio;
|
||||||
float tailLength = 0;
|
float tailLength = 0;
|
||||||
if (tail.FrameName != null) tailLength = width / tail.Ratio;
|
if (tail.Frame != null) tailLength = width / tail.Ratio;
|
||||||
float endLength = headLength + tailLength;
|
float endLength = headLength + tailLength;
|
||||||
if (sumLength <= endLength) {
|
if (sumLength <= endLength) {
|
||||||
// The total length of the two ends is longer than the whole mesh, squeeze the two ends
|
// The total length of the two ends is longer than the whole mesh, squeeze the two ends
|
||||||
@@ -187,17 +186,17 @@ namespace Cryville.Crtr.Components {
|
|||||||
verts = _vertPool.Rent(vc * vcpsec);
|
verts = _vertPool.Rent(vc * vcpsec);
|
||||||
uvs = _uvPool.Rent(vc * vcpsec);
|
uvs = _uvPool.Rent(vc * vcpsec);
|
||||||
int i = 0; int t = 0; float l = 0; int m = 0;
|
int i = 0; int t = 0; float l = 0; int m = 0;
|
||||||
if (head.FrameName != null) { m++; GenerateMeshTo(verts, uvs, out trih, head, ref i, ref t, ref l, 0, headLength, vcpsec, hvc); }
|
if (head.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trih, head, ref i, ref t, ref l, 0, headLength, vcpsec, hvc); }
|
||||||
if (body.FrameName != null) { m++; GenerateMeshTo(verts, uvs, out trib, body, ref i, ref t, ref l, headLength, sumLength - tailLength, vcpsec, hvc + bvc); }
|
if (body.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trib, body, ref i, ref t, ref l, headLength, sumLength - tailLength, vcpsec, hvc + bvc); }
|
||||||
if (tail.FrameName != null) { m++; GenerateMeshTo(verts, uvs, out trit, tail, ref i, ref t, ref l, sumLength - tailLength, sumLength, vcpsec, vc); }
|
if (tail.Frame != null) { m++; GenerateMeshTo(verts, uvs, out trit, tail, ref i, ref t, ref l, sumLength - tailLength, sumLength, vcpsec, vc); }
|
||||||
|
|
||||||
mesh.Mesh.subMeshCount = m;
|
mesh.Mesh.subMeshCount = 3;
|
||||||
m = 0;
|
m = 0;
|
||||||
mesh.Mesh.SetVertices(verts);
|
mesh.Mesh.SetVertices(verts);
|
||||||
mesh.Mesh.SetUVs(0, uvs);
|
mesh.Mesh.SetUVs(0, uvs);
|
||||||
if (head.FrameName != null) mesh.Mesh.SetTriangles(trih, m++);
|
mesh.Mesh.SetTriangles(head.Frame == null ? _emptyTris : trih, m++);
|
||||||
if (body.FrameName != null) mesh.Mesh.SetTriangles(trib, m++);
|
mesh.Mesh.SetTriangles(body.Frame == null ? _emptyTris : trib, m++);
|
||||||
if (tail.FrameName != null) mesh.Mesh.SetTriangles(trit, m++);
|
mesh.Mesh.SetTriangles(tail.Frame == null ? _emptyTris : trit, m++);
|
||||||
mesh.Mesh.RecalculateNormals();
|
mesh.Mesh.RecalculateNormals();
|
||||||
|
|
||||||
_vertPool.Return(verts); verts = null;
|
_vertPool.Return(verts); verts = null;
|
||||||
|
5
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
5
Assets/Cryville/Crtr/Components/SkinAnimation.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Cryville.Crtr.Components {
|
||||||
|
public class SkinAnimation : SkinComponent {
|
||||||
|
protected override void OnDestroy() { }
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
11
Assets/Cryville/Crtr/Components/SkinAnimation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 80318e36af5412345871bdbf80d49ef2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,4 +1,5 @@
|
|||||||
using Cryville.Common.Pdt;
|
using Cryville.Common;
|
||||||
|
using Cryville.Common.Pdt;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -7,25 +8,32 @@ namespace Cryville.Crtr.Components {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The property operators of the component.
|
/// The property operators of the component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<string, PdtOperator> PropOps { get; private set; }
|
public Dictionary<int, SkinProperty> Properties { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Submits a property.
|
/// Submits a property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the property.</param>
|
/// <param name="name">The name of the property.</param>
|
||||||
/// <param name="property">The property operator.</param>
|
/// <param name="property">The property.</param>
|
||||||
protected void SubmitProperty(string name, PdtOperator property) {
|
protected void SubmitProperty(string name, PdtOperator property, int udl = 0) {
|
||||||
PropOps.Add(name, property);
|
Properties.Add(IdentifierManager.SharedInstance.Request(name), new SkinProperty(property, udl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a skin component
|
/// Creates a skin component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected SkinComponent() {
|
protected SkinComponent() {
|
||||||
// Properties = new Dictionary<string, Property>();
|
Properties = new Dictionary<int, SkinProperty>();
|
||||||
PropOps = new Dictionary<string, PdtOperator>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Init() { }
|
public virtual void Init() { }
|
||||||
protected abstract void OnDestroy();
|
protected abstract void OnDestroy();
|
||||||
}
|
}
|
||||||
|
public struct SkinProperty {
|
||||||
|
public PdtOperator Operator { get; set; }
|
||||||
|
public int UpdateDynamicLevel { get; set; }
|
||||||
|
public SkinProperty(PdtOperator op, int udl = 0) {
|
||||||
|
Operator = op;
|
||||||
|
UpdateDynamicLevel = udl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,19 +16,15 @@ namespace Cryville.Crtr.Components {
|
|||||||
public op_set_bound(SpriteBase self) : base(2) {
|
public op_set_bound(SpriteBase self) : base(2) {
|
||||||
_self = self;
|
_self = self;
|
||||||
}
|
}
|
||||||
protected unsafe override void Execute() {
|
protected override void Execute() {
|
||||||
_self.SetBound(
|
_self.SetBound(
|
||||||
*(Vector2*)GetOperand(0).TrustedAsOfLength(sizeof(Vector2)),
|
GetOperand(0).As<Vector2>(),
|
||||||
*(Vector3*)GetOperand(1).TrustedAsOfLength(sizeof(Vector3))
|
GetOperand(1).As<Vector3>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore IDE1006
|
#pragma warning restore IDE1006
|
||||||
|
|
||||||
protected override void OnDestroy() {
|
|
||||||
mesh.Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 _scale = Vector2.one;
|
Vector2 _scale = Vector2.one;
|
||||||
public Vector2 Scale {
|
public Vector2 Scale {
|
||||||
get { return _scale; }
|
get { return _scale; }
|
||||||
@@ -92,7 +88,9 @@ namespace Cryville.Crtr.Components {
|
|||||||
|
|
||||||
protected void InternalInit(string meshName = "quad") {
|
protected void InternalInit(string meshName = "quad") {
|
||||||
mesh.Init(transform);
|
mesh.Init(transform);
|
||||||
|
mesh.Renderer.sharedMaterials = materials = new Material[] { MeshWrapper.NewMaterial() };
|
||||||
mesh.Mesh = GenericResources.Meshes[meshName];
|
mesh.Mesh = GenericResources.Meshes[meshName];
|
||||||
|
UpdateColor();
|
||||||
UpdateScale();
|
UpdateScale();
|
||||||
UpdateZIndex();
|
UpdateZIndex();
|
||||||
}
|
}
|
||||||
|
@@ -4,13 +4,22 @@ using Logger = Cryville.Common.Logger;
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Components {
|
namespace Cryville.Crtr.Components {
|
||||||
public class SpriteInfo {
|
public class SpriteInfo {
|
||||||
public string FrameName;
|
string m_frameName;
|
||||||
|
public string FrameName {
|
||||||
|
get {
|
||||||
|
return m_frameName;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
m_frameName = value;
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
public SpriteFrame Frame {
|
public SpriteFrame Frame {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public Rect Rect {
|
public Rect Rect {
|
||||||
get { return Frame.frame; }
|
get { return Frame.Frame; }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ratio of width divided by height.
|
/// The ratio of width divided by height.
|
||||||
@@ -20,23 +29,38 @@ namespace Cryville.Crtr.Components {
|
|||||||
return Rect.width / Rect.height;
|
return Rect.width / Rect.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Load() {
|
Material _mat;
|
||||||
if (FrameName != null) {
|
public void Bind(Material mat) {
|
||||||
|
_mat = mat;
|
||||||
|
Reload();
|
||||||
|
}
|
||||||
|
public void Reload() {
|
||||||
|
if (!string.IsNullOrEmpty(FrameName)) {
|
||||||
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
||||||
Frame = ChartPlayer.frames[FrameName];
|
Frame = ChartPlayer.frames[FrameName];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.Log("main", 4, "Skin", "Texture {0} not found", FrameName);
|
Logger.Log("main", 4, "Skin", "Texture {0} not found", FrameName);
|
||||||
|
Frame = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else Frame = null;
|
||||||
|
if (_mat != null) {
|
||||||
|
_mat.mainTexture = Frame == null ? null : Frame.Texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static bool IsNullOrEmpty(SpriteInfo sprite) {
|
||||||
|
return sprite == null || sprite.Frame == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SpritePlane : SpriteBase {
|
public class SpritePlane : SpriteBase {
|
||||||
public SpritePlane() {
|
public SpritePlane() {
|
||||||
SubmitProperty("frame", new PropOp.String(v => Frame = v));
|
SubmitProperty("frame", new PropOp.String(v => Frame = v));
|
||||||
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v));
|
SubmitProperty("frames", new PropOp.StringArray(v => Frames = v));
|
||||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
SubmitProperty("index", new PropOp.Integer(v => Index = v));
|
||||||
|
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v, v => (FitMode)v));
|
||||||
|
SubmitProperty("shader", new PropOp.String(v => Shader = v));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector2[] _origuv;
|
static Vector2[] _origuv;
|
||||||
@@ -57,57 +81,73 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SpriteInfo frameInfo = new SpriteInfo();
|
int m_index;
|
||||||
|
public int Index {
|
||||||
public string Frame {
|
get { return m_index; }
|
||||||
get { return frameInfo.FrameName; }
|
|
||||||
set {
|
set {
|
||||||
frameInfo.FrameName = value;
|
m_index = value;
|
||||||
OnFrameUpdate();
|
OnFrameUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SpriteInfo[] m_frames = new SpriteInfo[] { new SpriteInfo() };
|
||||||
|
public string[] Frames {
|
||||||
|
set {
|
||||||
|
m_frames = new SpriteInfo[value.Length];
|
||||||
|
for (int i = 0; i < value.Length; i++) {
|
||||||
|
m_frames[i] = new SpriteInfo() { FrameName = value[i] };
|
||||||
|
}
|
||||||
|
OnFrameUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string Frame {
|
||||||
|
set {
|
||||||
|
if (value == CurrentFrame.FrameName) return;
|
||||||
|
CurrentFrame.FrameName = value;
|
||||||
|
OnFrameUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected SpriteInfo CurrentFrame {
|
||||||
|
get {
|
||||||
|
if (m_frames.Length == 0) return null;
|
||||||
|
if (m_index < 0) m_index = 0;
|
||||||
|
else if (m_index >= m_frames.Length) m_index = m_frames.Length - 1;
|
||||||
|
return m_frames[m_index];
|
||||||
|
}
|
||||||
|
}
|
||||||
protected void OnFrameUpdate() {
|
protected void OnFrameUpdate() {
|
||||||
if (!mesh.Initialized) return;
|
if (!mesh.Initialized) return;
|
||||||
if (frameInfo.FrameName == null) {
|
var frame = CurrentFrame;
|
||||||
|
if (SpriteInfo.IsNullOrEmpty(frame)) {
|
||||||
mesh.Renderer.enabled = false;
|
mesh.Renderer.enabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mesh.Renderer.enabled = true;
|
mesh.Renderer.enabled = true;
|
||||||
frameInfo.Load();
|
mesh.Renderer.sharedMaterial.mainTexture = frame.Frame.Texture;
|
||||||
if (frameInfo.Frame != null)
|
|
||||||
mesh.Renderer.material.mainTexture = frameInfo.Frame.Texture;
|
|
||||||
else
|
|
||||||
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frameInfo.FrameName);
|
|
||||||
UpdateUV();
|
UpdateUV();
|
||||||
UpdateScale();
|
UpdateScale();
|
||||||
|
}
|
||||||
|
Shader m_shader;
|
||||||
|
public string Shader {
|
||||||
|
set {
|
||||||
|
m_shader = GenericResources.Shaders[value];
|
||||||
|
UpdateShader();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void UpdateShader() {
|
||||||
|
if (!mesh.Initialized) return;
|
||||||
|
if (m_shader == null) m_shader = GenericResources.Shaders["default"];
|
||||||
|
mesh.Renderer.sharedMaterial.shader = m_shader;
|
||||||
UpdateZIndex();
|
UpdateZIndex();
|
||||||
}
|
}
|
||||||
|
readonly Vector2[] _uvs = new Vector2[4];
|
||||||
protected virtual void UpdateUV() {
|
protected virtual void UpdateUV() {
|
||||||
if (frameInfo.Frame == null) {
|
var frame = CurrentFrame;
|
||||||
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frameInfo.FrameName);
|
if (SpriteInfo.IsNullOrEmpty(frame)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
Vector2[] muv = OriginalUV;
|
Vector2[] muv = OriginalUV;
|
||||||
Vector2[] uv = new Vector2[muv.Length];
|
for (int i = 0; i < _uvs.Length; i++) {
|
||||||
for (int i = 0; i < uv.Length; i++) {
|
_uvs[i] = frame.Frame.GetUV(muv[i]);
|
||||||
uv[i] = frameInfo.Frame.GetUV(muv[i]);
|
|
||||||
}
|
}
|
||||||
mesh.Mesh.uv = uv;
|
mesh.Mesh.uv = _uvs;
|
||||||
}
|
|
||||||
|
|
||||||
float _opacity = 1;
|
|
||||||
public float Opacity {
|
|
||||||
get { return _opacity; }
|
|
||||||
set {
|
|
||||||
_opacity = value;
|
|
||||||
UpdateOpacity();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void UpdateOpacity() {
|
|
||||||
if (!mesh.Initialized) return;
|
|
||||||
var c = mesh.Renderer.material.color;
|
|
||||||
c.a = _opacity;
|
|
||||||
mesh.Renderer.material.color = c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FitMode m_fit = FitMode.height;
|
private FitMode m_fit = FitMode.height;
|
||||||
@@ -123,7 +163,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateScale() {
|
protected override void UpdateScale() {
|
||||||
if (frameInfo.Frame == null) return;
|
if (SpriteInfo.IsNullOrEmpty(CurrentFrame)) return;
|
||||||
base.UpdateScale();
|
base.UpdateScale();
|
||||||
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
||||||
}
|
}
|
||||||
@@ -132,18 +172,17 @@ namespace Cryville.Crtr.Components {
|
|||||||
get {
|
get {
|
||||||
switch (m_fit) {
|
switch (m_fit) {
|
||||||
case FitMode.none: return Vector3.one;
|
case FitMode.none: return Vector3.one;
|
||||||
case FitMode.width: return new Vector3(1, 1, 1 / frameInfo.Ratio);
|
case FitMode.width: return new Vector3(1, 1, 1 / CurrentFrame.Ratio);
|
||||||
case FitMode.height: return new Vector3(frameInfo.Ratio, 1, 1);
|
case FitMode.height: return new Vector3(CurrentFrame.Ratio, 1, 1);
|
||||||
default: throw new NotSupportedException("Unsupported fit mode");
|
default: throw new NotSupportedException("Unsupported fit mode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
frameInfo.Load();
|
|
||||||
InternalInit();
|
InternalInit();
|
||||||
OnFrameUpdate();
|
OnFrameUpdate();
|
||||||
UpdateOpacity();
|
UpdateShader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,22 +2,7 @@
|
|||||||
|
|
||||||
namespace Cryville.Crtr.Components {
|
namespace Cryville.Crtr.Components {
|
||||||
public class SpriteRect : SpriteBase {
|
public class SpriteRect : SpriteBase {
|
||||||
public SpriteRect() {
|
public SpriteRect() { }
|
||||||
SubmitProperty("color", new PropOp.Color(v => Color = v));
|
|
||||||
}
|
|
||||||
|
|
||||||
Color _color;
|
|
||||||
public Color Color {
|
|
||||||
get { return _color; }
|
|
||||||
set {
|
|
||||||
_color = value;
|
|
||||||
OnColorUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void OnColorUpdate() {
|
|
||||||
if (!mesh.Initialized) return;
|
|
||||||
mesh.Renderer.material.SetColor("_Color", _color);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Vector3 BaseScale {
|
protected override Vector3 BaseScale {
|
||||||
get { return Vector3.one; }
|
get { return Vector3.one; }
|
||||||
@@ -25,7 +10,6 @@ namespace Cryville.Crtr.Components {
|
|||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
InternalInit();
|
InternalInit();
|
||||||
OnColorUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -44,43 +44,44 @@ namespace Cryville.Crtr.Components {
|
|||||||
UpdateUV();
|
UpdateUV();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readonly Vector2[] _uvs = new Vector2[8];
|
||||||
|
readonly Vector3[] _verts = new Vector3[8];
|
||||||
protected override void UpdateUV() {
|
protected override void UpdateUV() {
|
||||||
Vector2[] muv = OriginalUV;
|
var frame = CurrentFrame;
|
||||||
Vector2[] uv = new Vector2[muv.Length];
|
if (SpriteInfo.IsNullOrEmpty(frame)) return;
|
||||||
|
|
||||||
var or = frameInfo.Ratio;
|
Vector2[] muv = OriginalUV;
|
||||||
|
|
||||||
|
var or = frame.Ratio;
|
||||||
var sr = Scale.x / Scale.y;
|
var sr = Scale.x / Scale.y;
|
||||||
var b = new Vector2(
|
var rr = or / sr;
|
||||||
(or / sr) * _border.x,
|
var b1 = rr * _border.x;
|
||||||
1 - (or / sr) * (1 - _border.y)
|
var b2 = 1 - rr * (1 - _border.y);
|
||||||
);
|
|
||||||
Vector3[] vert = mesh.Mesh.vertices;
|
|
||||||
|
|
||||||
for (int i = 0; i < muv.Length; i++) {
|
for (int i = 0; i < muv.Length; i++) {
|
||||||
float x; float bx;
|
float x; float bx;
|
||||||
switch ((int)muv[i].x) {
|
switch ((int)muv[i].x) {
|
||||||
case 0: x = 0; bx = 0; break;
|
case 0: x = 0; bx = 0; break;
|
||||||
case 1: x = _border.x; bx = b.x; break;
|
case 1: x = _border.x; bx = b1; break;
|
||||||
case 2: x = _border.y; bx = b.y; break;
|
case 2: x = _border.y; bx = b2; break;
|
||||||
case 3: x = 1; bx = 1; break;
|
case 3: x = 1; bx = 1; break;
|
||||||
default: throw new Exception();
|
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||||
}
|
}
|
||||||
float y;
|
float y;
|
||||||
switch ((int)muv[i].y) {
|
switch ((int)muv[i].y) {
|
||||||
case 0: y = 0; break;
|
case 0: y = 0; break;
|
||||||
case 3: y = 1; break;
|
case 3: y = 1; break;
|
||||||
default: throw new Exception();
|
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||||
}
|
}
|
||||||
uv[i] = frameInfo.Frame.GetUV(x, y);
|
_uvs[i] = frame.Frame.GetUV(x, y);
|
||||||
bx -= 0.5f; y -= 0.5f;
|
bx -= 0.5f; y -= 0.5f;
|
||||||
vert[i] = new Vector3(bx, 0, y);
|
_verts[i] = new Vector3(bx, 0, y);
|
||||||
}
|
}
|
||||||
mesh.Mesh.uv = uv;
|
mesh.Mesh.uv = _uvs;
|
||||||
mesh.Mesh.vertices = vert;
|
mesh.Mesh.vertices = _verts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
frameInfo.Load();
|
|
||||||
InternalInit("quad_scale3h");
|
InternalInit("quad_scale3h");
|
||||||
OnFrameUpdate();
|
OnFrameUpdate();
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user