コード例 #1
0
        public static NativeEGIDMapper <T> QueryNativeMappedEntities <T>(this EntitiesDB entitiesDb, ExclusiveGroupStruct groupStructId)
            where T : unmanaged, IEntityComponent
        {
            if (entitiesDb.SafeQueryEntityDictionary <T>(groupStructId, out var typeSafeDictionary) == false)
            {
                throw new EntityGroupNotFoundException(typeof(T), groupStructId.ToName());
            }

            return((typeSafeDictionary as TypeSafeDictionary <T>).ToNativeEGIDMapper(groupStructId));
        }
コード例 #2
0
        public static bool TryQueryNativeMappedEntities <T>(this EntitiesDB entitiesDb, ExclusiveGroupStruct groupStructId,
                                                            out NativeEGIDMapper <T> mapper)
            where T : unmanaged, IEntityComponent
        {
            mapper = default;
            if (entitiesDb.SafeQueryEntityDictionary <T>(groupStructId, out var typeSafeDictionary) == false ||
                typeSafeDictionary.count == 0)
            {
                return(false);
            }

            mapper = (typeSafeDictionary as TypeSafeDictionary <T>).ToNativeEGIDMapper(groupStructId);

            return(true);
        }
コード例 #3
0
        ///Note: if I use a SharedNativeSveltoDictionary for implUnmg, I may be able to cache NativeEGIDMultiMapper
        /// and reuse it
        /// TODO: the ability to retain a NativeEGIDMultiMapper thanks to the use of shareable arrays
        /// must be unit tested!
        public static NativeEGIDMultiMapper <T> QueryNativeMappedEntities <T>(this EntitiesDB entitiesDb,
                                                                              LocalFasterReadOnlyList <ExclusiveGroupStruct> groups, Allocator allocator)
            where T : unmanaged, IBaseEntityComponent
        {
            var dictionary = new SveltoDictionaryNative <ExclusiveGroupStruct, SharedSveltoDictionaryNative <uint, T> >
                                 ((uint)groups.count, allocator);

            foreach (var group in groups)
            {
                if (entitiesDb.SafeQueryEntityDictionary <T>(group, out var typeSafeDictionary) == true)
                {
                    //if (typeSafeDictionary.count > 0)
                    dictionary.Add(group, ((UnmanagedTypeSafeDictionary <T>)typeSafeDictionary).implUnmgd);
                }
            }

            return(new NativeEGIDMultiMapper <T>(dictionary));
        }
コード例 #4
0
        public static NativeEGIDMultiMapper <T> QueryNativeMappedEntities <T>(this EntitiesDB entitiesDb,
                                                                              LocalFasterReadOnlyList <ExclusiveGroupStruct> groups)
            where T : unmanaged, IEntityComponent
        {
            var dictionary = new SveltoDictionary <ExclusiveGroupStruct,                                                                                                                                          //key
                                                   SveltoDictionary <uint, T,
                                                                     NativeStrategy <SveltoDictionaryNode <uint> >, NativeStrategy <T>, NativeStrategy <int> >,                                                   //value
                                                   NativeStrategy <SveltoDictionaryNode <ExclusiveGroupStruct> >,                                                                                                 //strategy to store the key
                                                   NativeStrategy <SveltoDictionary <uint, T, NativeStrategy <SveltoDictionaryNode <uint> >, NativeStrategy <T>, NativeStrategy <int> > >, NativeStrategy <int> > //strategy to store the value
                                 ((uint)groups.count, Allocator.TempJob);

            foreach (var group in groups)
            {
                if (entitiesDb.SafeQueryEntityDictionary <T>(group, out var typeSafeDictionary) == true)
                {
                    if (typeSafeDictionary.count > 0)
                    {
                        dictionary.Add(group, ((TypeSafeDictionary <T>)typeSafeDictionary).implUnmgd);
                    }
                }
            }

            return(new NativeEGIDMultiMapper <T>(dictionary));
        }