예제 #1
0
        private static bool IsDefaultObject <T>(ref T component, out int hashCode) where T : struct, ISharedComponentData
        {
            int typeIndex    = TypeManager.GetTypeIndex <T>();
            var layout       = TypeManager.GetComponentType(typeIndex).FastEqualityLayout;
            var defaultValue = default(T);

            hashCode = FastEquality.GetHashCode(ref component, layout);
            return(FastEquality.Equals(ref defaultValue, ref component, layout));
        }
예제 #2
0
 public static int GetHashCode(void *val, int typeIndex)
 {
     #if !UNITY_CSHARP_TINY
     var typeInfo = TypeManager.GetTypeInfo(typeIndex).FastEqualityTypeInfo;
     return(FastEquality.GetHashCode(val, typeInfo));
     #else
     return(StaticTypeRegistry.StaticTypeRegistry.GetHashCode(val, typeIndex & ClearFlagsMask));
     #endif
 }
예제 #3
0
 public static int GetHashCode <T>(ref T val) where T : struct
 {
     #if !UNITY_CSHARP_TINY
     var typeInfo = TypeManager.GetTypeInfo <T>().FastEqualityTypeInfo;
     return(FastEquality.GetHashCode(ref val, typeInfo));
     #else
     return(EqualityHelper <T> .Hash(val));
     #endif
 }
예제 #4
0
        private static unsafe int GetHashCodeFast(object target, FastEquality.TypeInfo typeInfo)
        {
            ulong handle;
            var   ptr      = PinGCObjectAndGetAddress(target, out handle);
            var   hashCode = FastEquality.GetHashCode(ptr, typeInfo);

            UnsafeUtility.ReleaseGCObject(handle);

            return(hashCode);
        }
예제 #5
0
        unsafe static int GetHashCodeFast(object target, FastEquality.Layout[] fastLayout)
        {
            ulong handle;
            void *ptr      = PinGCObjectAndGetAddress(target, out handle);
            var   hashCode = FastEquality.GetHashCode(ptr, fastLayout);

            UnsafeUtility.ReleaseGCObject(handle);

            return(hashCode);
        }
예제 #6
0
        private unsafe int FindSharedComponentIndex <T>(int typeIndex, T newData) where T : struct
        {
            var defaultVal = default(T);
            var typeInfo   = TypeManager.GetTypeInfo(typeIndex).FastEqualityTypeInfo;

            if (FastEquality.Equals(ref defaultVal, ref newData, typeInfo))
            {
                return(0);
            }
            return(FindNonDefaultSharedComponentIndex(typeIndex, FastEquality.GetHashCode(ref newData, typeInfo),
                                                      UnsafeUtility.AddressOf(ref newData), typeInfo));
        }
예제 #7
0
        unsafe int FindSharedComponentIndex <T>(int typeIndex, T newData) where T : struct
        {
            var defaultVal = default(T);
            var fastLayout = TypeManager.GetComponentType(typeIndex).FastEqualityLayout;

            if (FastEquality.Equals(ref defaultVal, ref newData, fastLayout))
            {
                return(0);
            }
            else
            {
                return(FindNonDefaultSharedComponentIndex(typeIndex, FastEquality.GetHashCode(ref newData, fastLayout),
                                                          UnsafeUtility.AddressOf(ref newData), fastLayout));
            }
        }
예제 #8
0
        public int InsertSharedComponent <T>(T newData) where T : struct
        {
            var typeIndex = TypeManager.GetTypeIndex <T>();
            var index     = FindSharedComponentIndex(TypeManager.GetTypeIndex <T>(), newData);

            if (index == 0)
            {
                return(0);
            }

            if (index != -1)
            {
                m_SharedComponentRefCount[index]++;
                return(index);
            }

            var typeInfo = TypeManager.GetTypeInfo(typeIndex).FastEqualityTypeInfo;
            var hashcode = FastEquality.GetHashCode(ref newData, typeInfo);

            return(Add(typeIndex, hashcode, newData));
        }
예제 #9
0
        public int InsertSharedComponent <T>(T newData) where T : struct
        {
            int typeIndex = TypeManager.GetTypeIndex <T>();
            int index     = FindSharedComponentIndex(TypeManager.GetTypeIndex <T>(), newData);

            if (index == 0)
            {
                return(0);
            }
            else if (index != -1)
            {
                m_SharedComponentRefCount[index]++;
                return(index);
            }
            else
            {
                var fastLayout = TypeManager.GetComponentType(typeIndex).FastEqualityLayout;
                var hashcode   = FastEquality.GetHashCode(ref newData, fastLayout);
                return(Add(typeIndex, hashcode, newData));
            }
        }