diff --git a/.gitignore b/.gitignore index f1249a2..ac529bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /EntitySystem/note.txt /EntitySystem/note.txt.meta +/*.meta +*.meta diff --git a/Context.meta b/Context.meta deleted file mode 100644 index fe9df04..0000000 --- a/Context.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 9e37272d8aa8b6e4cb7b1fc15f1e57a8 -folderAsset: yes -timeCreated: 1431201025 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Context/ContextNotifier.cs.meta b/Context/ContextNotifier.cs.meta deleted file mode 100644 index 5bd27d3..0000000 --- a/Context/ContextNotifier.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: d74bed1689bb4114aa8a1f95cd95c788 -timeCreated: 1431300049 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Context/Factories.meta b/Context/Factories.meta deleted file mode 100644 index f14959d..0000000 --- a/Context/Factories.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: ec4bd87e898bf7c42823fb5ec2456b43 -folderAsset: yes -timeCreated: 1431630831 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Context/Factories/GameObjectFactory.cs.meta b/Context/Factories/GameObjectFactory.cs.meta deleted file mode 100644 index ef025ff..0000000 --- a/Context/Factories/GameObjectFactory.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 613a705e128b35e4f9361e29f4661191 -timeCreated: 1431630831 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Context/Factories/MonoBehaviourFactory.cs.meta b/Context/Factories/MonoBehaviourFactory.cs.meta deleted file mode 100644 index f19e685..0000000 --- a/Context/Factories/MonoBehaviourFactory.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 369e3378b91069c4aadba2af5aa8882b -timeCreated: 1431630831 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Context/ICompositionRoot.cs.meta b/Context/ICompositionRoot.cs.meta deleted file mode 100644 index 0ce1f88..0000000 --- a/Context/ICompositionRoot.cs.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 48c80cc65bea8254ba8082043f53405e -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} diff --git a/Context/IContextNotifer.cs.meta b/Context/IContextNotifer.cs.meta deleted file mode 100644 index 97fff82..0000000 --- a/Context/IContextNotifer.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a28c8df5741efe54ea588a1bcea92f0f -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Context/IWaitForFrameworkDestruction.cs.meta b/Context/IWaitForFrameworkDestruction.cs.meta deleted file mode 100644 index aa5adc5..0000000 --- a/Context/IWaitForFrameworkDestruction.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 36b1da25aaa515e4bad98fa0f61bc662 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Context/IWaitForFrameworkInitialization.cs.meta b/Context/IWaitForFrameworkInitialization.cs.meta deleted file mode 100644 index 3ba1f65..0000000 --- a/Context/IWaitForFrameworkInitialization.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 93cf465dd97f6144390620250c362485 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Context/UnityContext.cs.meta b/Context/UnityContext.cs.meta deleted file mode 100644 index b3c44ab..0000000 --- a/Context/UnityContext.cs.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 54e46daa2d2d723499a114d6d8de9dc2 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} diff --git a/DataStructures.meta b/DataStructures.meta deleted file mode 100644 index 0f993f8..0000000 --- a/DataStructures.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 6663fc83070cb0842b4665b38356feb2 -folderAsset: yes -timeCreated: 1463348260 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/DataStructures/CircularBufferIndexer.cs b/DataStructures/CircularBufferIndexer.cs index cc9d397..a01d8ba 100644 --- a/DataStructures/CircularBufferIndexer.cs +++ b/DataStructures/CircularBufferIndexer.cs @@ -9,7 +9,7 @@ namespace Svelto.DataStructures // isn't taken into account (we would have to do a shift in both arrays) // Could be added as an option? - class CircularBufferIndexer : IDictionary + public class CircularBufferIndexer : IDictionary { public ICollection Keys { diff --git a/DataStructures/CircularBufferIndexer.cs.meta b/DataStructures/CircularBufferIndexer.cs.meta deleted file mode 100644 index a7e75ad..0000000 --- a/DataStructures/CircularBufferIndexer.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0d87fb4479e8365499c162fe0fc94acc -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/DataStructures/FasterList.cs b/DataStructures/FasterList.cs index ae44d60..6828af0 100644 --- a/DataStructures/FasterList.cs +++ b/DataStructures/FasterList.cs @@ -121,6 +121,8 @@ namespace Svelto.DataStructures public struct FasterReadOnlyList : IList { + public static FasterReadOnlyList DefaultList = new FasterReadOnlyList(new FasterList()); + public int Count { get { return _list.Count; } } public bool IsReadOnly { get { return true; } } @@ -193,7 +195,8 @@ namespace Svelto.DataStructures { public FasterListThreadSafe(FasterList list) { - _list = list; + if (list == null) throw new ArgumentException("invalid list"); + _list = list; _lockQ = new ReaderWriterLockSlim(); } @@ -273,6 +276,19 @@ namespace Svelto.DataStructures } } + public void FastClear() + { + _lockQ.EnterWriteLock(); + try + { + _list.FastClear(); + } + finally + { + _lockQ.ExitWriteLock(); + } + } + public bool Contains(T item) { _lockQ.EnterReadLock(); @@ -288,14 +304,14 @@ namespace Svelto.DataStructures public void CopyTo(T[] array, int arrayIndex) { - _lockQ.EnterWriteLock(); + _lockQ.EnterReadLock(); try { _list.CopyTo(array, arrayIndex); } finally { - _lockQ.ExitWriteLock(); + _lockQ.ExitReadLock(); } } @@ -351,6 +367,19 @@ namespace Svelto.DataStructures } } + public void UnorderedRemoveAt(int index) + { + _lockQ.EnterWriteLock(); + try + { + _list.UnorderedRemoveAt(index); + } + finally + { + _lockQ.ExitWriteLock(); + } + } + IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); @@ -368,7 +397,7 @@ namespace Svelto.DataStructures public struct FasterReadOnlyListCast : IList where U:T { - public static FasterList DefaultList = new FasterList(); + public static FasterReadOnlyListCast DefaultList = new FasterReadOnlyListCast(new FasterList()); public int Count { get { return _list.Count; } } public bool IsReadOnly { get { return true; } } @@ -402,7 +431,7 @@ namespace Svelto.DataStructures public void CopyTo(U[] array, int arrayIndex) { - throw new NotImplementedException(); + Array.Copy(_list.ToArrayFast(), 0, array, arrayIndex, _list.Count); } public bool Remove(U item) @@ -438,7 +467,10 @@ namespace Svelto.DataStructures readonly FasterList _list; } - public class FasterList : IList + public interface IFasterList + {} + + public class FasterList : IList, IFasterList { const int MIN_SIZE = 4; @@ -513,7 +545,7 @@ namespace Svelto.DataStructures for (int i = 0; i < initialSize; i++) list.Add(new U()); - list.Clear(); + list._count = 0; return list; } @@ -553,6 +585,11 @@ namespace Svelto.DataStructures _count += count; } + public void AddRange(T[] items) + { + AddRange(items, items.Length); + } + public FasterReadOnlyList AsReadOnly() { return new FasterReadOnlyList(this); @@ -562,12 +599,12 @@ namespace Svelto.DataStructures /// Careful, you could keep on holding references you don't want to hold to anymore /// Use DeepClear in case. /// - public void Clear() + public void FastClear() { _count = 0; } - public void DeepClear() + public void Clear() { Array.Clear(_buffer, 0, _buffer.Length); @@ -689,32 +726,32 @@ namespace Svelto.DataStructures return _buffer; } - public bool UnorderredRemove(T item) + public bool UnorderedRemove(T item) { var index = IndexOf(item); if (index == -1) return false; - UnorderredRemoveAt(index); + UnorderedRemoveAt(index); return true; } - public T UnorderredRemoveAt(int index) + public bool UnorderedRemoveAt(int index) { DesignByContract.Check.Require(index < _count && _count > 0, "out of bound index"); - T item = _buffer[index]; - if (index == --_count) - return item; + { + _buffer[_count] = default(T); + return false; + } - T swap = _buffer[index]; _buffer[index] = _buffer[_count]; - _buffer[_count] = swap; + _buffer[_count] = default(T); - return item; + return true; } IEnumerator IEnumerable.GetEnumerator() @@ -752,14 +789,15 @@ namespace Svelto.DataStructures Resize(_count); } - public bool Reuse(int index, out T result) + public bool Reuse(int index, out U result) + where U:class, T { - result = default(T); + result = default(U); if (index >= _buffer.Length) return false; - result = _buffer[index]; + result = (U)_buffer[index]; return result != null; } diff --git a/DataStructures/FasterList.cs.meta b/DataStructures/FasterList.cs.meta deleted file mode 100644 index b678658..0000000 --- a/DataStructures/FasterList.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: d19e59cbec974dd4d821a7dd21f87a88 -timeCreated: 1472488070 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/DataStructures/HashableWeakReference.cs.meta b/DataStructures/HashableWeakReference.cs.meta deleted file mode 100644 index 6d88c48..0000000 --- a/DataStructures/HashableWeakReference.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 0cfa789b3147c2e4e80d067693a58103 -timeCreated: 1455809369 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/DataStructures/LockFreeQueue.cs b/DataStructures/LockFreeQueue.cs new file mode 100644 index 0000000..01ae6e5 --- /dev/null +++ b/DataStructures/LockFreeQueue.cs @@ -0,0 +1,142 @@ +using System.Collections.Generic; +using System.Threading; + +//from unify wiki +namespace Svelto.DataStructures +{ + public class SingleLinkNode + { + // Note; the Next member cannot be a property since + // it participates in many CAS operations + public SingleLinkNode Next; + public T Item; + } + + public static class SyncMethods + { + public static bool CAS(ref T location, T comparand, T newValue) where T : class + { + return + (object)comparand == + (object)Interlocked.CompareExchange(ref location, newValue, comparand); + } + } + + public class LockFreeLinkPool + { + private SingleLinkNode head; + + public LockFreeLinkPool() + { + head = new SingleLinkNode(); + } + + public void Push(SingleLinkNode newNode) + { + newNode.Item = default(T); + do + { + newNode.Next = head.Next; + } while (!SyncMethods.CAS>(ref head.Next, newNode.Next, newNode)); + return; + } + + public bool Pop(out SingleLinkNode node) + { + do + { + node = head.Next; + if (node == null) + { + return false; + } + } while (!SyncMethods.CAS>(ref head.Next, node, node.Next)); + return true; + } + } + + public class LockFreeQueue + { + + SingleLinkNode head; + SingleLinkNode tail; + LockFreeLinkPool trash; + + public LockFreeQueue() + { + head = new SingleLinkNode(); + tail = head; + trash = new LockFreeLinkPool(); + } + + public void Enqueue(T item) + { + SingleLinkNode oldTail = null; + SingleLinkNode oldTailNext; + + SingleLinkNode newNode; + if (!trash.Pop(out newNode)) + { + newNode = new SingleLinkNode(); + } + else + { + newNode.Next = null; + } + newNode.Item = item; + + bool newNodeWasAdded = false; + while (!newNodeWasAdded) + { + oldTail = tail; + oldTailNext = oldTail.Next; + + if (tail == oldTail) + { + if (oldTailNext == null) + newNodeWasAdded = SyncMethods.CAS>(ref tail.Next, null, newNode); + else + SyncMethods.CAS>(ref tail, oldTail, oldTailNext); + } + } + SyncMethods.CAS>(ref tail, oldTail, newNode); + } + + public bool Dequeue(out T item) + { + item = default(T); + SingleLinkNode oldHead = null; + + bool haveAdvancedHead = false; + while (!haveAdvancedHead) + { + + oldHead = head; + SingleLinkNode oldTail = tail; + SingleLinkNode oldHeadNext = oldHead.Next; + + if (oldHead == head) + { + if (oldHead == oldTail) + { + if (oldHeadNext == null) + { + return false; + } + SyncMethods.CAS>(ref tail, oldTail, oldHeadNext); + } + else + { + item = oldHeadNext.Item; + haveAdvancedHead = SyncMethods.CAS>(ref head, oldHead, oldHeadNext); + if (haveAdvancedHead) + { + trash.Push(oldHead); + } + } + } + } + return true; + } + } +} \ No newline at end of file diff --git a/DataStructures/Priority Queue.meta b/DataStructures/Priority Queue.meta deleted file mode 100644 index 8f88283..0000000 --- a/DataStructures/Priority Queue.meta +++ /dev/null @@ -1,5 +0,0 @@ -fileFormatVersion: 2 -guid: 8fffa27a4e8919a4db6fe1369e22e1b5 -folderAsset: yes -DefaultImporter: - userData: diff --git a/DataStructures/Priority Queue/HeapPriorityQueue.cs b/DataStructures/Priority Queue/HeapPriorityQueue.cs index c30e06d..606acd5 100644 --- a/DataStructures/Priority Queue/HeapPriorityQueue.cs +++ b/DataStructures/Priority Queue/HeapPriorityQueue.cs @@ -66,7 +66,7 @@ namespace Svelto.DataStructures #endif public void Clear() { - _nodes.Clear(); + _nodes.FastClear(); _numNodes = 0; } diff --git a/DataStructures/Priority Queue/HeapPriorityQueue.cs.meta b/DataStructures/Priority Queue/HeapPriorityQueue.cs.meta deleted file mode 100644 index b994121..0000000 --- a/DataStructures/Priority Queue/HeapPriorityQueue.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ac754b29409379046935c0890bab6dc5 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/DataStructures/Priority Queue/IPriorityQueue.cs.meta b/DataStructures/Priority Queue/IPriorityQueue.cs.meta deleted file mode 100644 index 21920be..0000000 --- a/DataStructures/Priority Queue/IPriorityQueue.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 5d399e4c2c1fe1f47833d6b70bf16184 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/DataStructures/Priority Queue/PriorityQueueNode.cs.meta b/DataStructures/Priority Queue/PriorityQueueNode.cs.meta deleted file mode 100644 index 1002889..0000000 --- a/DataStructures/Priority Queue/PriorityQueueNode.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 2a6cc02a61a6ff549b1dcac74c71681f -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/DataStructures/ReadOnlyDictionary.cs.meta b/DataStructures/ReadOnlyDictionary.cs.meta deleted file mode 100644 index 9d767f0..0000000 --- a/DataStructures/ReadOnlyDictionary.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: e13aaf89d27048246bcf0d30c0993cf3 -timeCreated: 1459332966 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/DataStructures/ThreadSafeDictionary.cs b/DataStructures/ThreadSafeDictionary.cs index 1505547..19e72e4 100644 --- a/DataStructures/ThreadSafeDictionary.cs +++ b/DataStructures/ThreadSafeDictionary.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; using System.Threading; -//note, rewrite like ThreadSafeQueue - namespace Svelto.DataStructures { /// @@ -31,10 +29,15 @@ namespace Svelto.DataStructures { get { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return dict.Count; } + finally + { + LockQ.ExitReadLock(); + } } } @@ -42,10 +45,15 @@ namespace Svelto.DataStructures { get { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return dict.IsReadOnly; } + finally + { + LockQ.ExitReadLock(); + } } } @@ -53,10 +61,15 @@ namespace Svelto.DataStructures { get { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return new FasterList(dict.Keys); } + finally + { + LockQ.ExitReadLock(); + } } } @@ -64,10 +77,15 @@ namespace Svelto.DataStructures { get { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return new FasterList(dict.Values); } + finally + { + LockQ.ExitReadLock(); + } } } @@ -75,91 +93,146 @@ namespace Svelto.DataStructures { get { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return dict[key]; } + finally + { + LockQ.ExitReadLock(); + } } set { - using (new WriteLock(dictionaryLock)) + LockQ.EnterWriteLock(); + try { dict[key] = value; } + finally + { + LockQ.ExitWriteLock(); + } } } public virtual void Add(KeyValuePair item) { - using (new WriteLock(dictionaryLock)) + LockQ.EnterWriteLock(); + try { dict.Add(item); } + finally + { + LockQ.ExitWriteLock(); + } } public virtual void Clear() { - using (new WriteLock(dictionaryLock)) + LockQ.EnterWriteLock(); + try { dict.Clear(); } + finally + { + LockQ.ExitWriteLock(); + } } public virtual bool Contains(KeyValuePair item) { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return dict.Contains(item); } + finally + { + LockQ.ExitReadLock(); + } } public virtual void CopyTo(KeyValuePair[] array, int arrayIndex) { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { dict.CopyTo(array, arrayIndex); } + finally + { + LockQ.ExitReadLock(); + } } public virtual bool Remove(KeyValuePair item) { - using (new WriteLock(dictionaryLock)) + LockQ.EnterWriteLock(); + try { return dict.Remove(item); } + finally + { + LockQ.ExitWriteLock(); + } } public virtual void Add(TKey key, TValue value) { - using (new WriteLock(dictionaryLock)) + LockQ.EnterWriteLock(); + try { dict.Add(key, value); } + finally + { + LockQ.ExitWriteLock(); + } } public virtual bool ContainsKey(TKey key) { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return dict.ContainsKey(key); } + finally + { + LockQ.ExitReadLock(); + } } public virtual bool Remove(TKey key) { - using (new WriteLock(dictionaryLock)) + LockQ.EnterWriteLock(); + try { return dict.Remove(key); } + finally + { + LockQ.ExitWriteLock(); + } } public virtual bool TryGetValue(TKey key, out TValue value) { - using (new ReadOnlyLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { return dict.TryGetValue(key, out value); } + finally + { + LockQ.ExitReadLock(); + } } /// @@ -169,7 +242,8 @@ namespace Svelto.DataStructures /// New Value public void MergeSafe(TKey key, TValue newValue) { - using (new WriteLock(dictionaryLock)) + LockQ.EnterWriteLock(); + try { // take a writelock immediately since we will always be writing if (dict.ContainsKey(key)) @@ -177,6 +251,10 @@ namespace Svelto.DataStructures dict.Add(key, newValue); } + finally + { + LockQ.ExitWriteLock(); + } } /// @@ -185,132 +263,29 @@ namespace Svelto.DataStructures /// Key to remove public void RemoveSafe(TKey key) { - using (new ReadLock(dictionaryLock)) + LockQ.EnterReadLock(); + try { if (dict.ContainsKey(key)) - using (new WriteLock(dictionaryLock)) - { - dict.Remove(key); - } + LockQ.EnterWriteLock(); + try + { + dict.Remove(key); + } + finally + { + LockQ.ExitWriteLock(); + } + } + finally + { + LockQ.ExitReadLock(); } } // This is the internal dictionary that we are wrapping readonly IDictionary dict; - [NonSerialized] readonly ReaderWriterLockSlim dictionaryLock = Locks.GetLockInstance(LockRecursionPolicy.NoRecursion); - } - - public static class Locks - { - public static ReaderWriterLockSlim GetLockInstance() - { - return GetLockInstance(LockRecursionPolicy.SupportsRecursion); - } - - public static ReaderWriterLockSlim GetLockInstance(LockRecursionPolicy recursionPolicy) - { - return new ReaderWriterLockSlim(recursionPolicy); - } - - public static void GetReadLock(ReaderWriterLockSlim locks) - { - var lockAcquired = false; - while (!lockAcquired) - lockAcquired = locks.TryEnterUpgradeableReadLock(1); - } - - public static void GetReadOnlyLock(ReaderWriterLockSlim locks) - { - var lockAcquired = false; - while (!lockAcquired) - lockAcquired = locks.TryEnterReadLock(1); - } - - public static void GetWriteLock(ReaderWriterLockSlim locks) - { - var lockAcquired = false; - while (!lockAcquired) - lockAcquired = locks.TryEnterWriteLock(1); - } - - public static void ReleaseLock(ReaderWriterLockSlim locks) - { - ReleaseWriteLock(locks); - ReleaseReadLock(locks); - ReleaseReadOnlyLock(locks); - } - - public static void ReleaseReadLock(ReaderWriterLockSlim locks) - { - if (locks.IsUpgradeableReadLockHeld) - locks.ExitUpgradeableReadLock(); - } - - public static void ReleaseReadOnlyLock(ReaderWriterLockSlim locks) - { - if (locks.IsReadLockHeld) - locks.ExitReadLock(); - } - - public static void ReleaseWriteLock(ReaderWriterLockSlim locks) - { - if (locks.IsWriteLockHeld) - locks.ExitWriteLock(); - } - } - - public abstract class BaseLock : IDisposable - { - protected ReaderWriterLockSlim _Locks; - - public BaseLock(ReaderWriterLockSlim locks) - { - _Locks = locks; - } - - public abstract void Dispose(); - } - - public class ReadLock : BaseLock - { - public ReadLock(ReaderWriterLockSlim locks) - : base(locks) - { - Locks.GetReadLock(_Locks); - } - - public override void Dispose() - { - Locks.ReleaseReadLock(_Locks); - } - } - - public class ReadOnlyLock : BaseLock - { - public ReadOnlyLock(ReaderWriterLockSlim locks) - : base(locks) - { - Locks.GetReadOnlyLock(_Locks); - } - - public override void Dispose() - { - Locks.ReleaseReadOnlyLock(_Locks); - } - } - - public class WriteLock : BaseLock - { - public WriteLock(ReaderWriterLockSlim locks) - : base(locks) - { - Locks.GetWriteLock(_Locks); - } - - public override void Dispose() - { - Locks.ReleaseWriteLock(_Locks); - } + readonly ReaderWriterLockSlim LockQ = new ReaderWriterLockSlim(); } } diff --git a/DataStructures/ThreadSafeDictionary.cs.meta b/DataStructures/ThreadSafeDictionary.cs.meta deleted file mode 100644 index 07fdea7..0000000 --- a/DataStructures/ThreadSafeDictionary.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: db7c720ce4e437f48b1380223ba08192 -timeCreated: 1470829214 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/DataStructures/ThreadSafeQueue.cs.meta b/DataStructures/ThreadSafeQueue.cs.meta deleted file mode 100644 index 4b4d365..0000000 --- a/DataStructures/ThreadSafeQueue.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 57d029cda5232f8468d50d4eb3bf5489 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/DataStructures/WeakReference.cs.meta b/DataStructures/WeakReference.cs.meta deleted file mode 100644 index c9d3693..0000000 --- a/DataStructures/WeakReference.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 205cba76ee94d0e47aba9510ca92c540 -timeCreated: 1452175408 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS.meta b/ECS.meta deleted file mode 100644 index e1b48eb..0000000 --- a/ECS.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 5015ea56c030d6542bd4daa46f59e549 -folderAsset: yes -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Dispatcher.meta b/ECS/Dispatcher.meta deleted file mode 100644 index 41b7ff9..0000000 --- a/ECS/Dispatcher.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 2eae335fd33e33c4f951bf28bbf4914f -folderAsset: yes -timeCreated: 1462445195 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Dispatcher/DispatchOnChange.cs.meta b/ECS/Dispatcher/DispatchOnChange.cs.meta deleted file mode 100644 index ec4d3e7..0000000 --- a/ECS/Dispatcher/DispatchOnChange.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 908688d3b784d644e88a06e20f9ea159 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/ECS/Dispatcher/DispatcherOnSet.cs.meta b/ECS/Dispatcher/DispatcherOnSet.cs.meta deleted file mode 100644 index d868b59..0000000 --- a/ECS/Dispatcher/DispatcherOnSet.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: cbb1d54b291794b4686526222ee2bbb6 -timeCreated: 1471250507 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/EngineNodeDB.cs b/ECS/EngineNodeDB.cs index 8c73fa2..c10540f 100644 --- a/ECS/EngineNodeDB.cs +++ b/ECS/EngineNodeDB.cs @@ -4,15 +4,15 @@ using Svelto.DataStructures; namespace Svelto.ECS { - class EngineNodeDB : IEngineNodeDB + public class EngineNodeDB : IEngineNodeDB { internal EngineNodeDB( Dictionary> nodesDB, Dictionary> nodesDBdic, - Dictionary> nodesDBgroups) + Dictionary> metaNodesDB) { _nodesDB = nodesDB; _nodesDBdic = nodesDBdic; - _nodesDBgroups = nodesDBgroups; + _metaNodesDB = metaNodesDB; } public FasterReadOnlyListCast QueryNodes() where T:INode @@ -35,33 +35,34 @@ namespace Svelto.ECS return new ReadOnlyDictionary(_nodesDBdic[type]); } - public T QueryNodeFromGroup(int groupID) where T : INode + public T QueryMetaNode(int metaEntityID) where T : INode { - return QueryNode(groupID); + return QueryNode(metaEntityID); } - public bool QueryNodeFromGroup(int groupID, out T node) where T : INode + public bool TryQueryMetaNode(int metaEntityID, out T node) where T : INode { - return QueryNode(groupID, out node); + return TryQueryNode(metaEntityID, out node); } - public FasterReadOnlyListCast QueryNodesFromGroups() where T : INode + public FasterReadOnlyListCast QueryMetaNodes() where T : INode { var type = typeof(T); - if (_nodesDBgroups.ContainsKey(type) == false) + if (_metaNodesDB.ContainsKey(type) == false) return RetrieveEmptyNodeList(); - return new FasterReadOnlyListCast(_nodesDBgroups[type]); + return new FasterReadOnlyListCast(_metaNodesDB[type]); } - public bool QueryNode(int ID, out T node) where T:INode + public bool TryQueryNode(int ID, out T node) where T:INode { var type = typeof(T); INode internalNode; - if (_nodesDBdic.ContainsKey(type) && _nodesDBdic[type].TryGetValue(ID, out internalNode)) + if (_nodesDBdic.ContainsKey(type) && + _nodesDBdic[type].TryGetValue(ID, out internalNode)) { node = (T)internalNode; @@ -79,25 +80,32 @@ namespace Svelto.ECS INode internalNode; - if (_nodesDBdic.ContainsKey(type) && _nodesDBdic[type].TryGetValue(ID, out internalNode)) + if (_nodesDBdic.ContainsKey(type) && + _nodesDBdic[type].TryGetValue(ID, out internalNode)) return (T)internalNode; throw new Exception("Node Not Found"); } - static FasterReadOnlyListCast RetrieveEmptyNodeList() where T : INode + public FasterReadOnlyListCast QueryGroupNodes(int groupID) where T : INode { - return new FasterReadOnlyListCast(FasterReadOnlyListCast.DefaultList); + var type = typeof(T); + + if (_nodesDB.ContainsKey(type) == false) + return RetrieveEmptyNodeList(); + + return new FasterReadOnlyListCast(_nodesDB[type]); } - Dictionary> _nodesDB; - Dictionary> _nodesDBdic; - Dictionary> _nodesDBgroups; + static FasterReadOnlyListCast RetrieveEmptyNodeList() where T : INode + { + return FasterReadOnlyListCast.DefaultList; + } - //Dictionary> _nodesDB; - //Dictionary> _nodesDBdic; -// Dictionary> _nodesDBgroups; + readonly Dictionary> _nodesDB; + readonly Dictionary> _nodesDBdic; + readonly Dictionary> _metaNodesDB; - ReadOnlyDictionary _defaultEmptyNodeDict = new ReadOnlyDictionary(new Dictionary()); + readonly ReadOnlyDictionary _defaultEmptyNodeDict = new ReadOnlyDictionary(new Dictionary()); } } diff --git a/ECS/EngineNodeDB.cs.meta b/ECS/EngineNodeDB.cs.meta deleted file mode 100644 index 3bc56aa..0000000 --- a/ECS/EngineNodeDB.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b8aebbeeaf3d65d438359008c1f5d351 -timeCreated: 1459422025 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/EnginesRoot.cs b/ECS/EnginesRoot.cs index d3af55c..4aa482a 100644 --- a/ECS/EnginesRoot.cs +++ b/ECS/EnginesRoot.cs @@ -2,6 +2,8 @@ using System; using System.Collections; using System.Collections.Generic; using Svelto.DataStructures; +using Svelto.ECS.Internal; +using Svelto.ECS.NodeSchedulers; using UnityEngine; using WeakReference = Svelto.DataStructures.WeakReference; @@ -14,40 +16,39 @@ using System.Reflection; namespace Svelto.ECS { - class Scheduler : MonoBehaviour - { - IEnumerator Start() - { - while (true) - { - yield return new WaitForEndOfFrame(); - - OnTick(); - } - } - - internal Action OnTick; - } - public sealed class EnginesRoot : IEnginesRoot, IEntityFactory { - public EnginesRoot() + public EnginesRoot(NodeSubmissionScheduler nodeScheduler) { - _nodeEngines = new Dictionary>>(); + _nodeEngines = new Dictionary>(); + _activableEngines = new Dictionary>(); + _otherEngines = new FasterList(); + _engineRootWeakReference = new WeakReference(this); - _otherEnginesReferences = new FasterList(); _nodesDB = new Dictionary>(); _nodesDBdic = new Dictionary>(); _nodesToAdd = new FasterList(); - _groupNodesToAdd = new FasterList(); + _metaNodesToAdd = new FasterList(); + + _metaNodesDB = new Dictionary>(); + _sharedStructNodeLists = new SharedStructNodeLists(); + _sharedGroupedStructNodeLists = new SharedGroupedStructNodesLists(); - _nodesDBgroups = new Dictionary>(); + _internalRemove = InternalRemove; + _internalDisable = InternalDisable; + _internalEnable = InternalEnable; + _internalMetaRemove = InternalMetaRemove; - GameObject go = new GameObject("ECSScheduler"); + _scheduler = nodeScheduler; + _scheduler.Schedule(SubmitNodes); - go.AddComponent().OnTick += SubmitNodes; + _structNodeEngineType = typeof(IStructNodeEngine<>); + _groupedStructNodesEngineType = typeof(IGroupedStructNodesEngine<>); + _activableNodeEngineType = typeof(IActivableNodeEngine<>); + + _implementedInterfaceTypes = new Dictionary(); #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR GameObject debugEngineObject = new GameObject("Engine Debugger"); @@ -57,56 +58,75 @@ namespace Svelto.ECS void SubmitNodes() { - int groupNodesCount; - int nodesCount; + int metaNodesCount = _metaNodesToAdd.Count; + int nodesCount = _nodesToAdd.Count; + + if (metaNodesCount + nodesCount == 0) return; + bool newNodesHaveBeenAddedWhileIterating; int startNodes = 0; - int startGroupNodes = 0; + int startMetaNodes = 0; int numberOfReenteringLoops = 0; do { - groupNodesCount = _groupNodesToAdd.Count; - nodesCount = _nodesToAdd.Count; + var nodesToAdd = _nodesToAdd.ToArrayFast(); for (int i = startNodes; i < nodesCount; i++) { - var node = _nodesToAdd[i]; - AddNodeToTheDB(node, node.GetType()); + var node = nodesToAdd[i]; + var nodeType = node.GetType(); + + AddNodeToTheDB(node, nodeType); + var nodeWithId = node as INodeWithID; + if (nodeWithId != null) + AddNodeToNodesDictionary(nodeWithId, nodeType); } - for (int i = startGroupNodes; i < groupNodesCount; i++) + var metaNodesToAdd = _metaNodesToAdd.ToArrayFast(); + + for (int i = startMetaNodes; i < metaNodesCount; i++) { - var node = _groupNodesToAdd[i]; - AddNodeToGroupDB(node, node.GetType()); + var node = metaNodesToAdd[i]; + var nodeType = node.GetType(); + + AddNodeToMetaDB(node, nodeType); + var nodeWithId = node as INodeWithID; + if (nodeWithId != null) + AddNodeToNodesDictionary(nodeWithId, nodeType); } for (int i = startNodes; i < nodesCount; i++) { - var node = _nodesToAdd[i]; + var node = nodesToAdd[i]; AddNodeToTheSuitableEngines(node, node.GetType()); } - for (int i = startGroupNodes; i < groupNodesCount; i++) + for (int i = startMetaNodes; i < metaNodesCount; i++) { - var node = _groupNodesToAdd[i]; + var node = metaNodesToAdd[i]; AddNodeToTheSuitableEngines(node, node.GetType()); } - newNodesHaveBeenAddedWhileIterating = _groupNodesToAdd.Count > groupNodesCount || _nodesToAdd.Count > nodesCount; + newNodesHaveBeenAddedWhileIterating = + _metaNodesToAdd.Count > metaNodesCount || + _nodesToAdd.Count > nodesCount; startNodes = nodesCount; - startGroupNodes = groupNodesCount; + startMetaNodes = metaNodesCount; if (numberOfReenteringLoops > 5) throw new Exception("possible infinite loop found creating Entities inside INodesEngine Add method, please consider building entities outside INodesEngine Add method"); - numberOfReenteringLoops++; + numberOfReenteringLoops++; + + metaNodesCount = _metaNodesToAdd.Count; + nodesCount = _nodesToAdd.Count; } while (newNodesHaveBeenAddedWhileIterating); _nodesToAdd.Clear(); - _groupNodesToAdd.Clear(); + _metaNodesToAdd.Clear(); } public void AddEngine(IEngine engine) @@ -114,88 +134,201 @@ namespace Svelto.ECS #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR EngineProfiler.AddEngine(engine); #endif - if (engine is IQueryableNodeEngine) - (engine as IQueryableNodeEngine).nodesDB = new EngineNodeDB(_nodesDB, _nodesDBdic, _nodesDBgroups); + var queryableNodeEngine = engine as IQueryableNodeEngine; + if (queryableNodeEngine != null) + queryableNodeEngine.nodesDB = + new EngineNodeDB(_nodesDB, _nodesDBdic, _metaNodesDB); + + var engineType = engine.GetType(); + var implementedInterfaces = engineType.GetInterfaces(); + + CollectImplementedInterfaces(implementedInterfaces); + + var engineAdded = CheckGenericEngines(engine); + + if (CheckLegacyNodesEngine(engine, ref engineAdded) == false) + CheckNodesEngine(engine, engineType, ref engineAdded); + + if (engineAdded == false) + _otherEngines.Add(engine); + + var callBackOnAddEngine = engine as ICallBackOnAddEngine; + if (callBackOnAddEngine != null) + callBackOnAddEngine.Ready(); + } - if (engine is INodesEngine) + void CollectImplementedInterfaces(Type[] implementedInterfaces) + { + _implementedInterfaceTypes.Clear(); + + for (int index = 0; index < implementedInterfaces.Length; index++) { - var nodesEngine = engine as INodesEngine; + var interfaceType = implementedInterfaces[index]; +#if !NETFX_CORE - AddEngine(nodesEngine, nodesEngine.AcceptedNodes(), _nodeEngines); + if (false == interfaceType.IsGenericType) +#else + if (false == interfaceType.IsConstructedGenericType) +#endif + { + continue; + } + + var genericTypeDefinition = interfaceType.GetGenericTypeDefinition(); + + _implementedInterfaceTypes.Add(genericTypeDefinition, + interfaceType.GetGenericArguments()); + } + } + + bool CheckGenericEngines(IEngine engine) + { + if (_implementedInterfaceTypes.Count == 0) return false; + + bool engineAdded = false; + + if (_implementedInterfaceTypes.ContainsKey(_structNodeEngineType)) + { + ((IStructNodeEngine)engine).CreateStructNodes + (_sharedStructNodeLists); } - else + + if (_implementedInterfaceTypes.ContainsKey(_groupedStructNodesEngineType)) { + ((IGroupedStructNodesEngine)engine).CreateStructNodes + (_sharedGroupedStructNodeLists); + } - var engineType = engine.GetType(); -// Type baseInterface = null; + Type[] arguments; + if (_implementedInterfaceTypes.TryGetValue(_activableNodeEngineType, + out arguments)) + { + AddEngine(engine, arguments, _activableEngines); -#if !NETFX_CORE - var baseType = engineType.BaseType; + engineAdded = true; + } - if (baseType.IsGenericType + return engineAdded; + } + + bool CheckLegacyNodesEngine(IEngine engine, ref bool engineAdded) + { + var nodesEngine = engine as INodesEngine; + if (nodesEngine != null) + { + AddEngine(nodesEngine, nodesEngine.AcceptedNodes(), _nodeEngines); + + engineAdded = true; + + return true; + } + + return false; + } + + bool CheckNodesEngine(IEngine engine, Type engineType, ref bool engineAdded) + { +#if !NETFX_CORE + var baseType = engineType.BaseType; + + if (baseType.IsGenericType #else var baseType = engineType.GetTypeInfo().BaseType; if (baseType.IsConstructedGenericType #endif - && baseType.GetGenericTypeDefinition() == typeof (SingleNodeEngine<>)) - { - AddEngine(engine as INodeEngine, baseType.GetGenericArguments(), _nodeEngines); - } - else - _otherEnginesReferences.Add(engine); + && engine is INodeEngine) + { + AddEngine(engine as INodeEngine, baseType.GetGenericArguments(), _nodeEngines); + + engineAdded = true; + + return true; } - - if (engine is ICallBackOnAddEngine) - (engine as ICallBackOnAddEngine).Ready(); + + return false; } public void BuildEntity(int ID, EntityDescriptor ed) { - var entityNodes = ed.BuildNodes(ID, (node) => - { - if (_engineRootWeakReference.IsValid == true) - InternalRemove(node); - }); - + var entityNodes = ed.BuildNodes(ID, + _internalRemove, + _internalEnable, + _internalDisable + ); + _nodesToAdd.AddRange(entityNodes); } /// - /// An entity group is a meta entity. It's a way to create a set of entitites that - /// are not easily queriable otherwise. For example you may group existing entities - /// by size and type and then use the groupID to retrieve a single node that is shared - /// among the single entities of the same type and size. This willwd prevent the scenario - /// where the coder is forced to parse all the entities to find the ones of the same - /// size and type. Since the entity group is managed through the shared node, the same + /// A meta entity is a way to manage a set of entitites that are not easily + /// queriable otherwise. For example you may want to group existing entities + /// by size and type and then use the meta entity node to manage the data + /// shared among the single entities of the same type and size. This will + /// prevent the scenario where the coder is forced to parse all the entities to + /// find the ones of the same size and type. + /// Since the entities are managed through the shared node, the same /// shared node must be found on the single entities of the same type and size. - /// The shared node is then used by engines that are meant to manage a group of entities - /// through a single node. The same engine can manage several groups of entitites. + /// The shared node of the meta entity is then used by engines that are meant + /// to manage a group of entities through a single node. + /// The same engine can manage several meta entities nodes too. + /// The Engine manages the logic of the Meta Node data and other engines + /// can read back this data through the normal entity as the shared node + /// will be present in their descriptor too. + /// + /// + /// + public void BuildMetaEntity(int metaEntityID, EntityDescriptor ed) + { + var entityNodes = ed.BuildNodes(metaEntityID, + _internalMetaRemove, + _internalEnable, + _internalDisable + ); + + _metaNodesToAdd.AddRange(entityNodes); + } + + /// + /// Using this function is like building a normal entity, but the nodes + /// are grouped by groupID to be better processed inside engines and + /// improve cache locality. Only IGroupStructNodeWithID nodes are grouped + /// other nodes are managed as usual. /// + /// /// /// - public void BuildEntityGroup(int groupID, EntityDescriptor ed) + public void BuildEntityInGroup(short entityID, short groupID, + EntityDescriptor ed) { - var entityNodes = ed.BuildNodes(groupID, (node) => - { - if (_engineRootWeakReference.IsValid == true) - InternalGroupRemove(node); - }); + var entityNodes = ed.BuildNodes(entityID, + _internalRemove, + _internalEnable, + _internalDisable + ); - _groupNodesToAdd.AddRange(entityNodes); + _nodesToAdd.AddRange(entityNodes); + + for (int i = 0; i < entityNodes.Count; i++) + { + var groupNode = entityNodes[i] as IGroupedStructNodeWithID; + if (groupNode != null) + groupNode.groupID = groupID; + } } - static void AddEngine(T engine, Type[] types, Dictionary>> engines) where T : INodeEngine + static void AddEngine(IEngine engine, Type[] types, + Dictionary> engines) { for (int i = 0; i < types.Length; i++) { - FasterList> list; + FasterList list; var type = types[i]; if (engines.TryGetValue(type, out list) == false) { - list = new FasterList>(); + list = new FasterList(); engines.Add(type, list); } @@ -204,15 +337,13 @@ namespace Svelto.ECS } } - void AddNodeToGroupDB(INode node, Type nodeType) + void AddNodeToMetaDB(INode node, Type nodeType) { FasterList nodes; - if (_nodesDBgroups.TryGetValue(nodeType, out nodes) == false) - nodes = _nodesDBgroups[nodeType] = new FasterList(); + if (_metaNodesDB.TryGetValue(nodeType, out nodes) == false) + nodes = _metaNodesDB[nodeType] = new FasterList(); nodes.Add(node); - - AddNodeToNodesDictionary(node, nodeType); } void AddNodeToTheDB(T node, Type nodeType) where T : INode @@ -222,34 +353,30 @@ namespace Svelto.ECS nodes = _nodesDB[nodeType] = new FasterList(); nodes.Add(node); - - AddNodeToNodesDictionary(node, nodeType); } - void AddNodeToNodesDictionary(T node, Type nodeType) where T : INode + void AddNodeToNodesDictionary(T node, Type nodeType) where T : INodeWithID { - if (node is NodeWithID) - { - Dictionary nodesDic; - if (_nodesDBdic.TryGetValue(nodeType, out nodesDic) == false) - nodesDic = _nodesDBdic[nodeType] = new Dictionary(); + Dictionary nodesDic; - nodesDic[(node as NodeWithID).ID] = node; - } + if (_nodesDBdic.TryGetValue(nodeType, out nodesDic) == false) + nodesDic = _nodesDBdic[nodeType] = new Dictionary(); + + nodesDic.Add(node.ID, node); } - void AddNodeToTheSuitableEngines(T node, Type nodeType) where T : INode + void AddNodeToTheSuitableEngines(INode node, Type nodeType) { - FasterList> enginesForNode; + FasterList enginesForNode; if (_nodeEngines.TryGetValue(nodeType, out enginesForNode)) { for (int j = 0; j < enginesForNode.Count; j++) { #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR - EngineProfiler.MonitorAddDuration(AddNodeToEngine, enginesForNode[j], node); + EngineProfiler.MonitorAddDuration(AddNodeToEngine, enginesForNode[j] as INodeEngine, node); #else - enginesForNode[j].Add(node); + (enginesForNode[j] as INodeEngine).Add(node); #endif } } @@ -259,87 +386,168 @@ namespace Svelto.ECS { FasterList nodes; if (_nodesDB.TryGetValue(nodeType, out nodes) == true) - nodes.UnorderredRemove(node); //should I remove it from the dictionary if length is zero? - - RemoveNodeFromNodesDictionary(node, nodeType); + nodes.UnorderedRemove(node); //should I remove it from the dictionary if length is zero? } - void RemoveNodeFromNodesDictionary(T node, Type nodeType) where T : INode + void RemoveNodeFromMetaDB(T node, Type nodeType) where T : INode { - if (node is NodeWithID) - { - Dictionary nodesDic; - - if (_nodesDBdic.TryGetValue(nodeType, out nodesDic)) - nodesDic.Remove((node as NodeWithID).ID); - } + FasterList nodes; + if (_metaNodesDB.TryGetValue(nodeType, out nodes) == true) + nodes.UnorderedRemove(node); //should I remove it from the dictionary if length is zero? } - void RemoveNodeFromGroupDB(T node, Type nodeType) where T : INode + void RemoveNodeFromNodesDictionary(T node, Type nodeType) where T : INodeWithID { - FasterList nodes; - if (_nodesDBgroups.TryGetValue(nodeType, out nodes) == true) - nodes.UnorderredRemove(node); //should I remove it from the dictionary if length is zero? + Dictionary nodesDic; - RemoveNodeFromNodesDictionary(node, nodeType); + if (_nodesDBdic.TryGetValue(nodeType, out nodesDic)) + nodesDic.Remove(node.ID); } void RemoveNodeFromEngines(T node, Type nodeType) where T : INode { - FasterList> enginesForNode; + FasterList enginesForNode; if (_nodeEngines.TryGetValue(nodeType, out enginesForNode)) { for (int j = 0; j < enginesForNode.Count; j++) { #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR - EngineProfiler.MonitorRemoveDuration(RemoveNodeFromEngine, enginesForNode[j], node); + EngineProfiler.MonitorRemoveDuration(RemoveNodeFromEngine, (enginesForNode[j] as INodeEngine), node); #else - enginesForNode[j].Remove(node); + (enginesForNode[j] as INodeEngine).Remove(node); #endif } } } + + void DisableNodeFromEngines(INode node, Type nodeType) + { + FasterList enginesForNode; + + if (_activableEngines.TryGetValue(nodeType, out enginesForNode)) + { + for (int j = 0; j < enginesForNode.Count; j++) + { + (enginesForNode[j] as IActivableNodeEngine).Disable(node); + } + } + } + + void EnableNodeFromEngines(INode node, Type nodeType) + { + FasterList enginesForNode; + + if (_activableEngines.TryGetValue(nodeType, out enginesForNode)) + { + for (int j = 0; j < enginesForNode.Count; j++) + { + (enginesForNode[j] as IActivableNodeEngine).Enable(node); + } + } + } #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR - void AddNodeToEngine(INodeEngine engine, INode node) + void AddNodeToEngine(IEngine engine, INode node) { - engine.Add(node); + (engine as INodeEngine).Add(node); } - void RemoveNodeFromEngine(INodeEngine engine, INode node) + void RemoveNodeFromEngine(IEngine engine, INode node) { - engine.Remove(node); + (engine as INodeEngine).Remove(node); } #endif - - void InternalRemove(T node) where T : INode + + void InternalDisable(FasterList nodes) + { + if (_engineRootWeakReference.IsValid == false) + return; + + for (int i = 0; i < nodes.Count; i++) + { + var node = nodes[i]; + Type nodeType = node.GetType(); + DisableNodeFromEngines(node, nodeType); + } + } + + void InternalEnable(FasterList nodes) + { + if (_engineRootWeakReference.IsValid == false) + return; + + for (int i = 0; i < nodes.Count; i++) + { + var node = nodes[i]; + Type nodeType = node.GetType(); + EnableNodeFromEngines(node, nodeType); + } + } + + void InternalRemove(FasterList nodes) { - Type nodeType = node.GetType(); + if (_engineRootWeakReference.IsValid == false) + return; - RemoveNodeFromEngines(node, nodeType); - RemoveNodeFromTheDB(node, node.GetType()); + for (int i = 0; i < nodes.Count; i++) + { + var node = nodes[i]; + Type nodeType = node.GetType(); + + RemoveNodeFromEngines(node, nodeType); + RemoveNodeFromTheDB(node, node.GetType()); + + var nodeWithId = node as INodeWithID; + if (nodeWithId != null) + RemoveNodeFromNodesDictionary(nodeWithId, nodeType); + } } - void InternalGroupRemove(T node) where T : INode + void InternalMetaRemove(FasterList nodes) { - Type nodeType = node.GetType(); + for (int i = 0; i < nodes.Count; i++) + { + var node = nodes[i]; + Type nodeType = node.GetType(); + + RemoveNodeFromEngines(node, nodeType); + RemoveNodeFromMetaDB(node, nodeType); - RemoveNodeFromEngines(node, nodeType); - RemoveNodeFromGroupDB(node, node.GetType()); + var nodeWithId = node as INodeWithID; + if (nodeWithId != null) + RemoveNodeFromNodesDictionary(nodeWithId, nodeType); + } } - Dictionary>> _nodeEngines; - FasterList _otherEnginesReferences; + readonly Dictionary> _nodeEngines; + readonly Dictionary> _activableEngines; + + readonly FasterList _otherEngines; + + readonly Dictionary> _nodesDB; + readonly Dictionary> _metaNodesDB; + + readonly Dictionary> _nodesDBdic; + + readonly FasterList _nodesToAdd; + readonly FasterList _metaNodesToAdd; + + readonly WeakReference _engineRootWeakReference; + readonly SharedStructNodeLists _sharedStructNodeLists; + readonly SharedGroupedStructNodesLists _sharedGroupedStructNodeLists; - Dictionary> _nodesDB; - Dictionary> _nodesDBdic; + readonly NodeSubmissionScheduler _scheduler; - Dictionary> _nodesDBgroups; + readonly Action> _internalRemove; + readonly Action> _internalEnable; + readonly Action> _internalDisable; + readonly Action> _internalMetaRemove; - FasterList _nodesToAdd; - FasterList _groupNodesToAdd; + readonly Type _structNodeEngineType; + readonly Type _groupedStructNodesEngineType; + readonly Type _activableNodeEngineType; - WeakReference _engineRootWeakReference; + readonly Dictionary _implementedInterfaceTypes; } } diff --git a/ECS/EnginesRoot.cs.meta b/ECS/EnginesRoot.cs.meta deleted file mode 100644 index aa7b562..0000000 --- a/ECS/EnginesRoot.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 89361a8514a38544ebb87df0bd766dc5 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/ECS/EntityDescriptor.cs b/ECS/EntityDescriptor.cs index 7dab7ee..946e1a8 100644 --- a/ECS/EntityDescriptor.cs +++ b/ECS/EntityDescriptor.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Reflection; using Svelto.DataStructures; #if NETFX_CORE @@ -9,100 +10,176 @@ namespace Svelto.ECS { public class EntityDescriptor { - protected EntityDescriptor(INodeBuilder[] nodesToBuild, params object[] componentsImplementor) + protected EntityDescriptor(INodeBuilder[] nodesToBuild) { - _implementors = componentsImplementor; - _nodesToBuild = nodesToBuild; + _nodesToBuild = new FasterList(nodesToBuild); + } + protected EntityDescriptor(INodeBuilder[] nodesToBuild, params object[] componentsImplementor):this(nodesToBuild) + { + ProcessImplementors(componentsImplementor); } public void AddImplementors(params object[] componentsImplementor) { - var implementors = new object[componentsImplementor.Length + _implementors.Length]; + ProcessImplementors(componentsImplementor); + } + + void ProcessImplementors(object[] implementors) + { + for (int index = 0; index < implementors.Length; index++) + { + var implementor = implementors[index]; + if (implementor is IRemoveEntityComponent) + _removingImplementors.Add(implementor as IRemoveEntityComponent); + if (implementor is IDisableEntityComponent) + _disablingImplementors.Add(implementor as IDisableEntityComponent); + if (implementor is IEnableEntityComponent) + _enablingImplementors.Add(implementor as IEnableEntityComponent); - Array.Copy(_implementors, implementors, _implementors.Length); - Array.Copy(componentsImplementor, 0, implementors, _implementors.Length, componentsImplementor.Length); + var interfaces = implementor.GetType().GetInterfaces(); - _implementors = implementors; + for (int iindex = 0; iindex < interfaces.Length; iindex++) + { + _implementorsByType[interfaces[iindex]] = implementor; + } + } + } + + public void AddNodes(params INodeBuilder[] nodesWithID) + { + _nodesToBuild.AddRange(nodesWithID); } - public virtual FasterList BuildNodes(int ID, Action removeAction) + public virtual FasterList BuildNodes(int ID) { var nodes = new FasterList(); - for (int index = 0; index < _nodesToBuild.Length; index++) + for (int index = 0; index < _nodesToBuild.Count; index++) { var nodeBuilder = _nodesToBuild[index]; - var node = FillNode(nodeBuilder.Build(ID), () => - { - for (int i = 0; i < nodes.Count; i++) - removeAction(nodes[i]); + var node = nodeBuilder.Build(ID); - nodes.Clear(); - } - ); + if (nodeBuilder.reflects != FillNodeMode.None) + node = FillNode(node, nodeBuilder.reflects); - nodes.Add (node); + nodes.Add(node); } return nodes; } - TNode FillNode(TNode node, Action removeAction) where TNode: INode + internal FasterList BuildNodes(int ID, + Action> removeEntity, + Action> enableEntity, + Action> disableEntity) { - var fields = node.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance); + var nodes = BuildNodes(ID); - for (int i = fields.Length - 1; i >=0 ; --i) - { - var field = fields[i]; - Type fieldType = field.FieldType; - object component = null; - - for (int j = 0; j < _implementors.Length; j++) - { - var implementor = _implementors[j]; + SetupImplementors(removeEntity, enableEntity, disableEntity, nodes); - if (implementor != null && fieldType.IsAssignableFrom(implementor.GetType())) - { - component = implementor; + return nodes; + } - if (fieldType.IsAssignableFrom(typeof(IRemoveEntityComponent))) - (component as IRemoveEntityComponent).removeEntity = removeAction; + void SetupImplementors( + Action> removeEntity, + Action> enableEntity, + Action> disableEntity, + FasterList nodes) + { + Action removeEntityAction = () => { removeEntity(nodes); nodes.Clear(); }; + Action disableEntityAction = () => disableEntity(nodes); + Action enableEntityAction = () => enableEntity(nodes); + + for (int index = 0; index < _removingImplementors.Count; index++) + _removingImplementors[index].removeEntity = removeEntityAction; + for (int index = 0; index < _disablingImplementors.Count; index++) + _disablingImplementors[index].disableEntity = disableEntityAction; + for (int index = 0; index < _enablingImplementors.Count; index++) + _enablingImplementors[index].enableEntity = enableEntityAction; + } - break; - } - } + TNode FillNode(TNode node, FillNodeMode mode) where TNode : INode + { + var fields = node.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance); - if (component == null) + for (int i = fields.Length - 1; i >= 0; --i) + { + var field = fields[i]; + Type fieldType = field.FieldType; + object component; + + if ((_implementorsByType.TryGetValue(fieldType, out component)) == false) { - Exception e = new Exception("Svelto.ECS: Implementor not found for a Node. " + - "Implementor Type: " + field.FieldType.Name + " - Node: " + node.GetType().Name + " - EntityDescriptor " + this); + if (mode == FillNodeMode.Strict) + { + Exception e = + new Exception("Svelto.ECS: Implementor not found for a Node. " + "Implementor Type: " + + field.FieldType.Name + " - Node: " + node.GetType().Name + + " - EntityDescriptor " + this); - throw e; + throw e; + } } - - field.SetValue(node, component); + else + field.SetValue(node, component); } return node; } - object[] _implementors; + readonly FasterList _disablingImplementors = new FasterList(); + readonly FasterList _removingImplementors = new FasterList(); + readonly FasterList _enablingImplementors = new FasterList(); + readonly Dictionary _implementorsByType = new Dictionary(); - readonly INodeBuilder[] _nodesToBuild; + readonly FasterList _nodesToBuild; } public interface INodeBuilder { - NodeWithID Build(int ID); + INode Build(int ID); + + FillNodeMode reflects { get; } } - public class NodeBuilder : INodeBuilder where NodeType:NodeWithID, new() + public class NodeBuilder : INodeBuilder where NodeType : NodeWithID, new() { - public NodeWithID Build(int ID) + public INode Build(int ID) { NodeWithID node = NodeWithID.BuildNode(ID); return (NodeType)node; } + + public FillNodeMode reflects { get { return FillNodeMode.Strict; } } + } + + public class StructNodeBuilder : INodeBuilder + where NodeType : struct, IStructNodeWithID + { + public INode Build(int ID) + { + var shortID = (short)ID; + IStructNodeWithID node = default(NodeType); + node.ID = shortID; + + return node; + } + + public virtual FillNodeMode reflects { get { return FillNodeMode.Relaxed; } } + } + + public class FastStructNodeBuilder : StructNodeBuilder + where NodeType : struct, IStructNodeWithID + { + public override FillNodeMode reflects { get { return FillNodeMode.None; } } + } + + public enum FillNodeMode + { + Strict, + Relaxed, + + None } } diff --git a/ECS/EntityDescriptor.cs.meta b/ECS/EntityDescriptor.cs.meta deleted file mode 100644 index 0fdabbc..0000000 --- a/ECS/EntityDescriptor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 42ab9afd9889862468f4afdac4fffd8b -timeCreated: 1457096903 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs b/ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs new file mode 100644 index 0000000..c211f73 --- /dev/null +++ b/ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs @@ -0,0 +1,41 @@ +#if UNITY_5 || UNITY_5_3_OR_NEWER +using System; +using System.Collections; +using UnityEngine; + +namespace Svelto.ECS.NodeSchedulers +{ + public class UnitySumbmissionNodeScheduler : NodeSubmissionScheduler + { + public UnitySumbmissionNodeScheduler() + { + GameObject go = new GameObject("ECSScheduler"); + + _scheduler = go.AddComponent(); + } + + public override void Schedule(Action submitNodes) + { + _scheduler.OnTick += submitNodes; + } + + class Scheduler : MonoBehaviour + { + IEnumerator Start() + { + while (true) + { + yield return _wait; + + OnTick(); + } + } + + internal Action OnTick; + WaitForEndOfFrame _wait = new WaitForEndOfFrame(); + } + + Scheduler _scheduler; + } +} +#endif \ No newline at end of file diff --git a/ECS/GenericEntityDescriptor.cs b/ECS/GenericEntityDescriptor.cs index 62ddd73..1be1793 100644 --- a/ECS/GenericEntityDescriptor.cs +++ b/ECS/GenericEntityDescriptor.cs @@ -1,6 +1,6 @@ namespace Svelto.ECS { - class GenericEntityDescriptor : EntityDescriptor + public class GenericEntityDescriptor : EntityDescriptor where T : NodeWithID, new() { static GenericEntityDescriptor() @@ -10,10 +10,10 @@ public GenericEntityDescriptor(params object[] componentsImplementor) : base(_nodesToBuild, componentsImplementor) {} - static INodeBuilder[] _nodesToBuild; + static readonly INodeBuilder[] _nodesToBuild; } - class GenericEntityDescriptor : EntityDescriptor + public class GenericEntityDescriptor : EntityDescriptor where T : NodeWithID, new() where U : NodeWithID, new() { @@ -29,10 +29,10 @@ public GenericEntityDescriptor(params object[] componentsImplementor) : base(_nodesToBuild, componentsImplementor) {} - static INodeBuilder[] _nodesToBuild; + static readonly INodeBuilder[] _nodesToBuild; } - class GenericEntityDescriptor : EntityDescriptor + public class GenericEntityDescriptor : EntityDescriptor where T : NodeWithID, new() where U : NodeWithID, new() where V : NodeWithID, new() @@ -47,12 +47,12 @@ }; } public GenericEntityDescriptor(params object[] componentsImplementor) : base(_nodesToBuild, componentsImplementor) - { - } - static INodeBuilder[] _nodesToBuild; + {} + + static readonly INodeBuilder[] _nodesToBuild; } - class GenericEntityDescriptor : EntityDescriptor + public class GenericEntityDescriptor : EntityDescriptor where T : NodeWithID, new() where U : NodeWithID, new() where V : NodeWithID, new() @@ -69,12 +69,12 @@ }; } public GenericEntityDescriptor(params object[] componentsImplementor) : base(_nodesToBuild, componentsImplementor) - { - } - static INodeBuilder[] _nodesToBuild; + {} + + static readonly INodeBuilder[] _nodesToBuild; } - class GenericEntityDescriptor : EntityDescriptor + public class GenericEntityDescriptor : EntityDescriptor where T : NodeWithID, new() where U : NodeWithID, new() where V : NodeWithID, new() @@ -93,11 +93,12 @@ }; } public GenericEntityDescriptor(params object[] componentsImplementor) : base(_nodesToBuild, componentsImplementor) - { - } - static INodeBuilder[] _nodesToBuild; + {} + + static readonly INodeBuilder[] _nodesToBuild; } - class GenericEntityDescriptor : EntityDescriptor + + public class GenericEntityDescriptor : EntityDescriptor where T : NodeWithID, new() where U : NodeWithID, new() where V : NodeWithID, new() @@ -118,8 +119,121 @@ }; } public GenericEntityDescriptor(params object[] componentsImplementor) : base(_nodesToBuild, componentsImplementor) + {} + + static readonly INodeBuilder[] _nodesToBuild; + } + + public class GenericMixedEntityDescriptor : EntityDescriptor + where T : INodeBuilder, new() + { + static GenericMixedEntityDescriptor() + { + _nodesToBuild = new INodeBuilder[] + { + new T(), + }; + } + public GenericMixedEntityDescriptor(params object[] componentsImplementor) : + base(_nodesToBuild, componentsImplementor) + { } + + static readonly INodeBuilder[] _nodesToBuild; + } + + public class GenericMixedEntityDescriptor : EntityDescriptor + where T : INodeBuilder, new() + where U : INodeBuilder, new() + where V : INodeBuilder, new() + { + static GenericMixedEntityDescriptor() + { + _nodesToBuild = new INodeBuilder[] + { + new T(), + new U(), + new V() + }; + } + public GenericMixedEntityDescriptor(params object[] componentsImplementor) : + base(_nodesToBuild, componentsImplementor) + { } + + static readonly INodeBuilder[] _nodesToBuild; + } + + public class GenericMixedEntityDescriptor : EntityDescriptor + where T : INodeBuilder, new() + where U : INodeBuilder, new() + where V : INodeBuilder, new() + where W : INodeBuilder, new() + { + static GenericMixedEntityDescriptor() { + _nodesToBuild = new INodeBuilder[] + { + new T(), + new U(), + new V(), + new W() + }; } - static INodeBuilder[] _nodesToBuild; + public GenericMixedEntityDescriptor(params object[] componentsImplementor) : + base(_nodesToBuild, componentsImplementor) + { } + + static readonly INodeBuilder[] _nodesToBuild; + } + + public class GenericMixedEntityDescriptor : EntityDescriptor + where T : INodeBuilder, new() + where U : INodeBuilder, new() + where V : INodeBuilder, new() + where W : INodeBuilder, new() + where X : INodeBuilder, new() + { + static GenericMixedEntityDescriptor() + { + _nodesToBuild = new INodeBuilder[] + { + new T(), + new U(), + new V(), + new W(), + new X() + }; + } + public GenericMixedEntityDescriptor(params object[] componentsImplementor) : + base(_nodesToBuild, componentsImplementor) + { } + + static readonly INodeBuilder[] _nodesToBuild; + } + + public class GenericMixedEntityDescriptor : EntityDescriptor + where T : INodeBuilder, new() + where U : INodeBuilder, new() + where V : INodeBuilder, new() + where W : INodeBuilder, new() + where X : INodeBuilder, new() + where Y : INodeBuilder, new() + { + static GenericMixedEntityDescriptor() + { + _nodesToBuild = new INodeBuilder[] + { + new T(), + new U(), + new V(), + new W(), + new X(), + new Y() + }; + } + public GenericMixedEntityDescriptor(params object[] componentsImplementor) : + base(_nodesToBuild, componentsImplementor) + { } + + static readonly INodeBuilder[] _nodesToBuild; } } diff --git a/ECS/GenericEntityDescriptor.cs.meta b/ECS/GenericEntityDescriptor.cs.meta deleted file mode 100644 index 840728d..0000000 --- a/ECS/GenericEntityDescriptor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: fd70d1b3107162f4790b1b71a129818f -timeCreated: 1484485852 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/GenericEntityDescriptorHolder.cs.meta b/ECS/GenericEntityDescriptorHolder.cs.meta deleted file mode 100644 index fc5bfc6..0000000 --- a/ECS/GenericEntityDescriptorHolder.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: f2bc0783e8d4a7b49a84705c55d8b255 -timeCreated: 1498225965 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/ICallBackOnAddEngine.cs b/ECS/ICallBackOnAddEngine.cs index 30ac6de..815d59d 100644 --- a/ECS/ICallBackOnAddEngine.cs +++ b/ECS/ICallBackOnAddEngine.cs @@ -1,7 +1,7 @@ namespace Svelto.ECS { - interface ICallBackOnAddEngine + public interface ICallBackOnAddEngine { void Ready(); } -} \ No newline at end of file +} diff --git a/ECS/ICallBackOnAddEngine.cs.meta b/ECS/ICallBackOnAddEngine.cs.meta deleted file mode 100644 index 80e5f96..0000000 --- a/ECS/ICallBackOnAddEngine.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 3928de9a08e5b534ab857ea8b5bebdaf -timeCreated: 1497524074 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/IEngine.cs b/ECS/IEngine.cs index 5bddc66..d811e9a 100644 --- a/ECS/IEngine.cs +++ b/ECS/IEngine.cs @@ -1,21 +1,62 @@ -namespace Svelto.ECS +using Svelto.ECS.Internal; + +namespace Svelto.ECS.Internal { - public interface IEngine - {} + public interface IStructNodeEngine : IEngine + { + void CreateStructNodes(SharedStructNodeLists sharedStructNodeLists); + } + + public interface IGroupedStructNodesEngine : IEngine + { + void CreateStructNodes(SharedGroupedStructNodesLists sharedStructNodeLists); + } + + public interface IActivableNodeEngine : IEngine + { + void Enable(INode obj); + void Disable(INode obj); + } - public interface INodeEngine:IEngine where TNodeType:INode + public interface INodeEngine : IEngine { - void Add(TNodeType obj); - void Remove(TNodeType obj); + void Add(INode obj); + void Remove(INode obj); } - public interface INodesEngine : INodeEngine + public interface INodesEngine : INodeEngine { System.Type[] AcceptedNodes(); } +} + +namespace Svelto.ECS +{ + public interface IEngine + {} + + public interface IActivableNodeEngine : IActivableNodeEngine where TNodeType : INode + { } public interface IQueryableNodeEngine:IEngine { IEngineNodeDB nodesDB { set; } } + + /// + /// The engines can receive and store INodes structs + /// Unboxing will happen during the Add, but the + /// data will then be stored and processed as stucts + /// + public interface IStructNodeEngine : IStructNodeEngine where T:struct, IStructNodeWithID + { } + + /// + /// same as above, but the nodes are grouped by ID + /// usually the ID is the owner of the nodes of that + /// group + /// + public interface IGroupedStructNodesEngine : IGroupedStructNodesEngine where T:struct, IGroupedStructNodeWithID + { } } + diff --git a/ECS/IEngine.cs.meta b/ECS/IEngine.cs.meta deleted file mode 100644 index 8ee8df3..0000000 --- a/ECS/IEngine.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 26f6a5fa5638d86448dd3f2d11d62f5c -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/ECS/IEngineNodeDB.cs b/ECS/IEngineNodeDB.cs index 069d532..5e8a154 100644 --- a/ECS/IEngineNodeDB.cs +++ b/ECS/IEngineNodeDB.cs @@ -6,14 +6,14 @@ namespace Svelto.ECS { ReadOnlyDictionary QueryIndexableNodes() where T:INode; - bool QueryNode(int ID, out T node) where T:INode; + bool TryQueryNode(int ID, out T node) where T:INode; T QueryNode(int ID) where T:INode; FasterReadOnlyListCast QueryNodes() where T:INode; - bool QueryNodeFromGroup(int ID, out T node) where T : INode; - T QueryNodeFromGroup(int ID) where T : INode; - FasterReadOnlyListCast QueryNodesFromGroups() where T : INode; + bool TryQueryMetaNode(int metaEntityID, out T node) where T : INode; + T QueryMetaNode(int metaEntityID) where T : INode; + FasterReadOnlyListCast QueryMetaNodes() where T : INode; } } diff --git a/ECS/IEngineNodeDB.cs.meta b/ECS/IEngineNodeDB.cs.meta deleted file mode 100644 index c346d94..0000000 --- a/ECS/IEngineNodeDB.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 44c24b91989f46048abc15039fd070bc -timeCreated: 1459422024 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/IEnginesRoot.cs b/ECS/IEnginesRoot.cs index 72c317a..544fbc6 100644 --- a/ECS/IEnginesRoot.cs +++ b/ECS/IEnginesRoot.cs @@ -1,3 +1,5 @@ +using Svelto.ECS.Internal; + namespace Svelto.ECS { public interface IEnginesRoot @@ -9,6 +11,8 @@ namespace Svelto.ECS { void BuildEntity(int ID, EntityDescriptor ED); - void BuildEntityGroup(int ID, EntityDescriptor ED); + void BuildMetaEntity(int metaEntityID, EntityDescriptor ED); + + void BuildEntityInGroup(short entityID, short groupID, EntityDescriptor ED); } } diff --git a/ECS/IEnginesRoot.cs.meta b/ECS/IEnginesRoot.cs.meta deleted file mode 100644 index b73c9f1..0000000 --- a/ECS/IEnginesRoot.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b0078c1edf75425478b89366d5fe3bae -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/ECS/IEntityDescriptorHolder.cs.meta b/ECS/IEntityDescriptorHolder.cs.meta deleted file mode 100644 index bf596a5..0000000 --- a/ECS/IEntityDescriptorHolder.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 0badb413a22f42a4b9f68e356e88b07f -timeCreated: 1463438461 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/INode.cs b/ECS/INode.cs index 30abb9f..3f3999c 100644 --- a/ECS/INode.cs +++ b/ECS/INode.cs @@ -3,7 +3,22 @@ namespace Svelto.ECS public interface INode {} - public class NodeWithID: INode + public interface INodeWithID:INode + { + int ID { get; } + } + + public interface IStructNodeWithID : INode + { + short ID { get; set; } + } + + public interface IGroupedStructNodeWithID : IStructNodeWithID + { + short groupID { get; set; } + } + + public class NodeWithID: INodeWithID { public static TNodeType BuildNode(int ID) where TNodeType: NodeWithID, new() { diff --git a/ECS/INode.cs.meta b/ECS/INode.cs.meta deleted file mode 100644 index bd3f81b..0000000 --- a/ECS/INode.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fc6bea8c56bd7284693db26502c6b65b -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/ECS/IRemoveEntityComponent.cs b/ECS/IRemoveEntityComponent.cs index a3f1525..5a3ee3b 100644 --- a/ECS/IRemoveEntityComponent.cs +++ b/ECS/IRemoveEntityComponent.cs @@ -6,4 +6,14 @@ namespace Svelto.ECS { Action removeEntity { get; set; } } + + public interface IDisableEntityComponent + { + Action disableEntity { get; set; } + } + + public interface IEnableEntityComponent + { + Action enableEntity { get; set; } + } } diff --git a/ECS/IRemoveEntityComponent.cs.meta b/ECS/IRemoveEntityComponent.cs.meta deleted file mode 100644 index d449680..0000000 --- a/ECS/IRemoveEntityComponent.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: bb9e778a1f85b0d46a065bbd5b549acd -timeCreated: 1462977663 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/MultiNodesEngine.cs b/ECS/MultiNodesEngine.cs new file mode 100644 index 0000000..2907917 --- /dev/null +++ b/ECS/MultiNodesEngine.cs @@ -0,0 +1,47 @@ +using Svelto.ECS.Internal; + +namespace Svelto.ECS.Internal +{ + public abstract class MultiNodesEngine + where T : INode + { + protected abstract void AddNode(T node); + protected abstract void RemoveNode(T node); + } +} + +namespace Svelto.ECS +{ + public abstract class MultiNodesEngine : INodesEngine + { + public abstract System.Type[] AcceptedNodes(); + + public abstract void Add(INode node); + public abstract void Remove(INode node); + } + + public abstract class MultiNodesEngine : MultiNodesEngine, + INodeEngine + where T : INode + where U : INode + { + protected abstract void AddNode(U node); + protected abstract void RemoveNode(U node); + + public void Add(INode node) + { + if (node is T) + AddNode((T)node); + else + AddNode((U)node); + } + + public void Remove(INode node) + { + if (node is T) + RemoveNode((T)node); + else + RemoveNode((U)node); + } + } +} \ No newline at end of file diff --git a/ECS/NodeSubmissionScheduler.cs b/ECS/NodeSubmissionScheduler.cs new file mode 100644 index 0000000..7f04648 --- /dev/null +++ b/ECS/NodeSubmissionScheduler.cs @@ -0,0 +1,9 @@ +using System; + +namespace Svelto.ECS.NodeSchedulers +{ + public abstract class NodeSubmissionScheduler + { + abstract public void Schedule(Action submitNodes); + } +} \ No newline at end of file diff --git a/ECS/Profiler.meta b/ECS/Profiler.meta deleted file mode 100644 index 3a39d53..0000000 --- a/ECS/Profiler.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 8d07544bb8b417f4a9eaefe0d4771d89 -folderAsset: yes -timeCreated: 1462355668 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/Editor.meta b/ECS/Profiler/Editor.meta deleted file mode 100644 index 48dd9b3..0000000 --- a/ECS/Profiler/Editor.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 71a4fc836cd9bde4bbb936a073804ec5 -folderAsset: yes -timeCreated: 1480683133 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/Editor/EngineProfiler.meta b/ECS/Profiler/Editor/EngineProfiler.meta deleted file mode 100644 index b802d05..0000000 --- a/ECS/Profiler/Editor/EngineProfiler.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 777a9420fd80746428f9d2c5b718fd2f -folderAsset: yes -timeCreated: 1462351213 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs.meta b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs.meta deleted file mode 100644 index 02c6f19..0000000 --- a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: a2202d1747b86dc428310091a9c1a7ef -timeCreated: 1462469401 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs index 2c20e59..d7c6b93 100644 --- a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs +++ b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs @@ -5,7 +5,7 @@ using UnityEditor; namespace Svelto.ECS.Profiler { - internal class EngineProfilerMenuItem + class EngineProfilerMenuItem { [MenuItem("Engines/Enable Profiler")] public static void EnableProfiler() diff --git a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs.meta b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs.meta deleted file mode 100644 index b487da4..0000000 --- a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: e7b6bbeaaa16ab84aaa99c3311199efa -timeCreated: 1462351229 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs.meta b/ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs.meta deleted file mode 100644 index aee00e5..0000000 --- a/ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 30f9f7f6468a96d4da2525c65ecfe637 -timeCreated: 1467633311 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta b/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta deleted file mode 100644 index 11f6ff4..0000000 --- a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: de0de03babf2e9d4db95c2be94eb8c95 -timeCreated: 1462527509 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/EngineInfo.cs.meta b/ECS/Profiler/EngineInfo.cs.meta deleted file mode 100644 index 2463af8..0000000 --- a/ECS/Profiler/EngineInfo.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 93c5ba48b51186e44b7094eef7028c90 -timeCreated: 1462357591 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/EngineProfiler.cs b/ECS/Profiler/EngineProfiler.cs index f055f3d..0612925 100644 --- a/ECS/Profiler/EngineProfiler.cs +++ b/ECS/Profiler/EngineProfiler.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using Svelto.ECS.Internal; //This profiler is based on the Entitas Visual Debugging tool //https://github.com/sschmid/Entitas-CSharp @@ -11,7 +12,7 @@ namespace Svelto.ECS.Profiler { static readonly Stopwatch _stopwatch = new Stopwatch(); - public static void MonitorAddDuration(Action, INode> addingFunc, INodeEngine engine, INode node) + public static void MonitorAddDuration(Action addingFunc, INodeEngine engine, INode node) { EngineInfo info; if (engineInfos.TryGetValue(engine.GetType(), out info)) @@ -25,7 +26,7 @@ namespace Svelto.ECS.Profiler } } - public static void MonitorRemoveDuration(Action, INode> removeFunc, INodeEngine engine, INode node) + public static void MonitorRemoveDuration(Action removeFunc, INodeEngine engine, INode node) { EngineInfo info; if (engineInfos.TryGetValue(engine.GetType(), out info)) diff --git a/ECS/Profiler/EngineProfiler.cs.meta b/ECS/Profiler/EngineProfiler.cs.meta deleted file mode 100644 index 7c2b637..0000000 --- a/ECS/Profiler/EngineProfiler.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 74b59045fe5033b4b98facadd4d6b114 -timeCreated: 1462355668 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Profiler/EngineProfilerBehaviour.cs b/ECS/Profiler/EngineProfilerBehaviour.cs index 9039a2a..c924d6c 100644 --- a/ECS/Profiler/EngineProfilerBehaviour.cs +++ b/ECS/Profiler/EngineProfilerBehaviour.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; diff --git a/ECS/Profiler/EngineProfilerBehaviour.cs.meta b/ECS/Profiler/EngineProfilerBehaviour.cs.meta deleted file mode 100644 index 17446f2..0000000 --- a/ECS/Profiler/EngineProfilerBehaviour.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 688f5cf68b171ef4fa0f6aab49644c48 -timeCreated: 1462469401 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/Sequencer.cs.meta b/ECS/Sequencer.cs.meta deleted file mode 100644 index 87596cb..0000000 --- a/ECS/Sequencer.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 4e1f40937ca5027428ed7193729be1a5 -timeCreated: 1484487023 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/SingleNodeEngine.cs b/ECS/SingleNodeEngine.cs index 6b43243..e641f32 100644 --- a/ECS/SingleNodeEngine.cs +++ b/ECS/SingleNodeEngine.cs @@ -1,15 +1,18 @@ -namespace Svelto.ECS +using Svelto.ECS.Internal; + +namespace Svelto.ECS { - public abstract class SingleNodeEngine : INodeEngine where TNodeType : class, INode + public abstract class SingleNodeEngine : INodeEngine + where TNodeType : INode { - void INodeEngine.Add(INode obj) + public void Add(INode obj) { - Add(obj as TNodeType); + Add((TNodeType) obj); } - void INodeEngine.Remove(INode obj) + public void Remove(INode obj) { - Remove(obj as TNodeType); + Remove((TNodeType) obj); } protected abstract void Add(TNodeType node); diff --git a/ECS/SingleNodeEngine.cs.meta b/ECS/SingleNodeEngine.cs.meta deleted file mode 100644 index cdb2bea..0000000 --- a/ECS/SingleNodeEngine.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 406a5e818b179b743b582c8fec087ac1 -timeCreated: 1469806920 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ECS/StructNodes.cs b/ECS/StructNodes.cs new file mode 100644 index 0000000..582abab --- /dev/null +++ b/ECS/StructNodes.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using Svelto.DataStructures; +using Svelto.ECS.Internal; + +namespace Svelto.ECS +{ + public class StructNodes where T:struct, IStructNodeWithID + { + public T[] GetList(out int numberOfItems) + { + numberOfItems = _internalList.Count; + return _internalList.ToArrayFast(); + } + + public StructNodes(SharedStructNodeLists container) + { + _internalList = container.GetList(); + } + + public void Add(T node) + { + T convert = (T)node; + + _internalList.Add(convert); + } + + readonly FasterList _internalList; + } + + public class StructGroupNodes + where T : struct, IGroupedStructNodeWithID + { + public StructGroupNodes(SharedGroupedStructNodesLists container) + { + _container = container; + } + + public void Add(int groupID, T node) + { + T convert = (T)node; + + var fasterList = (_container.GetList(groupID) as FasterList); + indices[node.ID] = fasterList.Count; + + fasterList.Add(convert); + } + + public void Remove(int groupID, T node) + { + var fasterList = (_container.GetList(groupID) as FasterList); + var index = indices[node.ID]; + indices.Remove(node.ID); + + if (fasterList.UnorderedRemoveAt(index)) + indices[fasterList[index].ID] = index; + } + + public T[] GetList(int groupID, out int numberOfItems) + { + var fasterList = (_container.GetList(groupID) as FasterList); + numberOfItems = fasterList.Count; + return fasterList.ToArrayFast(); + } + + readonly SharedGroupedStructNodesLists _container; + readonly Dictionary indices = new Dictionary(); + } + + public class SharedStructNodeLists + { + readonly Dictionary _collection; + + internal SharedStructNodeLists() + { + _collection = new Dictionary(); + } + + internal FasterList GetList() where T:struct + { + IFasterList list; + if (_collection.TryGetValue(typeof (T), out list)) + { + return list as FasterList; + } + + list = new FasterList(); + + _collection.Add(typeof (T), list); + + return (FasterList) list; + } + } + + public class SharedGroupedStructNodesLists + { + internal SharedGroupedStructNodesLists() + { + _collection = new Dictionary>(); + } + + internal IFasterList GetList(int groupID) where T : struct + { + Dictionary dic = GetGroup(); + IFasterList localList; + + if (dic.TryGetValue(groupID, out localList)) + return localList; + + localList = new FasterList(); + dic.Add(groupID, localList); + + return localList; + } + + internal Dictionary GetGroup() where T : struct + { + Dictionary dic; + + if (_collection.TryGetValue(typeof(T), out dic)) + { + return dic; + } + + dic = new Dictionary(); + + _collection.Add(typeof(T), dic); + + return dic; + } + + readonly Dictionary> _collection; + } +} \ No newline at end of file diff --git a/ECS/note.txt.meta b/ECS/note.txt.meta deleted file mode 100644 index 9b67328..0000000 --- a/ECS/note.txt.meta +++ /dev/null @@ -1,4 +0,0 @@ -fileFormatVersion: 2 -guid: 11a3defaf51bc2147904eb737af5efb7 -TextScriptImporter: - userData: diff --git a/Factories.meta b/Factories.meta deleted file mode 100644 index 8a250da..0000000 --- a/Factories.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 7f7896118ef3c4949898b5c30aea0c47 -folderAsset: yes -timeCreated: 1484044925 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Factories/IGameObjectFactory.cs.meta b/Factories/IGameObjectFactory.cs.meta deleted file mode 100644 index dc6c4b9..0000000 --- a/Factories/IGameObjectFactory.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f3720a403a14c51489b5250365b7185c -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Factories/IMonoBehaviourFactory.cs.meta b/Factories/IMonoBehaviourFactory.cs.meta deleted file mode 100644 index 1a2f1b4..0000000 --- a/Factories/IMonoBehaviourFactory.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 22ba598cf1fd5124dbb4b999af89a0c5 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/LICENSE.meta b/LICENSE.meta deleted file mode 100644 index 0999b4e..0000000 --- a/LICENSE.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ab819523a7b1394499edac4ffa37556b -timeCreated: 1440946962 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/README.md.meta b/README.md.meta deleted file mode 100644 index cabd763..0000000 --- a/README.md.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e772c63482a119748ba160ed807765a3 -timeCreated: 1440946962 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Utilities.meta b/Utilities.meta deleted file mode 100644 index d093762..0000000 --- a/Utilities.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: b7374ca2eb247d44c8783d7d23f9b89e -folderAsset: yes -timeCreated: 1484394896 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Utilities/DesignByContract.cs b/Utilities/DesignByContract.cs index d34861e..0ac9bf8 100644 --- a/Utilities/DesignByContract.cs +++ b/Utilities/DesignByContract.cs @@ -26,10 +26,10 @@ // // Alternatively, you can define these in the project properties dialog. -#if UNITY_EDITOR || ROBO_TEST_BUILD -#define DBC_CHECK_ALL +#if DEBUG && !PROFILER +#define DBC_CHECK_ALL #endif - + using System; using System.Diagnostics; diff --git a/Utilities/DesignByContract.cs.meta b/Utilities/DesignByContract.cs.meta deleted file mode 100644 index 729468b..0000000 --- a/Utilities/DesignByContract.cs.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 5a6942e14a8d33d46a05b33d50392652 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Utilities/Print.cs b/Utilities/Print.cs index 6a64d26..095c110 100644 --- a/Utilities/Print.cs +++ b/Utilities/Print.cs @@ -7,7 +7,7 @@ public static class FastConcatUtility { static readonly StringBuilder _stringBuilder = new StringBuilder(256); - public static string FastConcat(this string str1, string str2) + public static string FastConcat(this string str1, T str2) { lock (_stringBuilder) { @@ -136,7 +136,7 @@ namespace Utility logger.Log(txt); } - public static void LogError(string txt, bool showCurrentStack = true) + public static void LogError(string txt) { string toPrint; @@ -148,11 +148,8 @@ namespace Utility toPrint = _stringBuilder.ToString(); } -#if !NETFX_CORE - logger.Log(toPrint, showCurrentStack == true ? new StackTrace().ToString() : null, LogType.Error); -#else + logger.Log(toPrint, null, LogType.Error); -#endif } public static void LogError(string txt, string stack) diff --git a/Utilities/Print.cs.meta b/Utilities/Print.cs.meta deleted file mode 100644 index 121f044..0000000 --- a/Utilities/Print.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 1f5eede659a66c64a9af2ec703db2691 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Utilities/WeakActionStruct.cs b/Utilities/WeakActionStruct.cs index dff59f6..318027b 100644 --- a/Utilities/WeakActionStruct.cs +++ b/Utilities/WeakActionStruct.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/Utilities/WeakActionStruct.cs.meta b/Utilities/WeakActionStruct.cs.meta deleted file mode 100644 index 49656b3..0000000 --- a/Utilities/WeakActionStruct.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 1662357721652524593d7b0f731aef45 -timeCreated: 1484483913 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Utilities/WeakEvent.cs b/Utilities/WeakEvent.cs index e912490..91aa235 100644 --- a/Utilities/WeakEvent.cs +++ b/Utilities/WeakEvent.cs @@ -1,5 +1,6 @@ using Svelto.DataStructures; using System; +using System.Collections.Generic; namespace BetterWeakEvents { @@ -13,7 +14,7 @@ namespace BetterWeakEvents public static WeakEvent operator-(WeakEvent c1, Action x) { - c1._subscribers.UnorderredRemove(new WeakAction(x)); + c1._subscribers.UnorderedRemove(new WeakAction(x)); return c1; } @@ -21,7 +22,7 @@ namespace BetterWeakEvents { for (int i = 0; i < _subscribers.Count; i++) if (_subscribers[i].Invoke(arg1, arg2) == false) - _subscribers.UnorderredRemoveAt(i--); + _subscribers.UnorderedRemoveAt(i--); } ~WeakEvent() @@ -32,4 +33,4 @@ namespace BetterWeakEvents protected FasterList> _subscribers = new FasterList>(); } -} \ No newline at end of file +} diff --git a/Utilities/WeakEvent.cs.meta b/Utilities/WeakEvent.cs.meta deleted file mode 100644 index 884293e..0000000 --- a/Utilities/WeakEvent.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: e2ee3763e7dffd4459c588eda6867ddd -timeCreated: 1484480295 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: