コード例 #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));
            }
        }