#if UNITY_NATIVE using System.Runtime.CompilerServices; using Svelto.Common; using Svelto.DataStructures; using Svelto.DataStructures.Native; using Svelto.ECS.Internal; namespace Svelto.ECS.Native { public static class UnityNativeEntityDBExtensions { internal static NativeEGIDMapper ToNativeEGIDMapper(this TypeSafeDictionary dic, ExclusiveGroupStruct groupStructId) where T : unmanaged, IEntityComponent { var mapper = new NativeEGIDMapper(groupStructId, dic.implUnmgd); return mapper; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NativeEGIDMapper QueryNativeMappedEntities(this EntitiesDB entitiesDb, ExclusiveGroupStruct groupStructId) where T : unmanaged, IEntityComponent { if (entitiesDb.SafeQueryEntityDictionary(groupStructId, out var typeSafeDictionary) == false) throw new EntityGroupNotFoundException(typeof(T), groupStructId.ToName()); return (typeSafeDictionary as TypeSafeDictionary).ToNativeEGIDMapper(groupStructId); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryQueryNativeMappedEntities(this EntitiesDB entitiesDb, ExclusiveGroupStruct groupStructId, out NativeEGIDMapper mapper) where T : unmanaged, IEntityComponent { mapper = default; if (entitiesDb.SafeQueryEntityDictionary(groupStructId, out var typeSafeDictionary) == false || typeSafeDictionary.count == 0) return false; mapper = (typeSafeDictionary as TypeSafeDictionary).ToNativeEGIDMapper(groupStructId); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static NativeEGIDMultiMapper QueryNativeMappedEntities(this EntitiesDB entitiesDb, LocalFasterReadOnlyList groups, Allocator allocator) where T : unmanaged, IEntityComponent { var dictionary = new SveltoDictionary>, NativeStrategy, NativeStrategy>, //value NativeStrategy>, //strategy to store the key NativeStrategy>, NativeStrategy, NativeStrategy>>, NativeStrategy> //strategy to store the value ((uint) groups.count, allocator); foreach (var group in groups) { if (entitiesDb.SafeQueryEntityDictionary(group, out var typeSafeDictionary) == true) if (typeSafeDictionary.count > 0) dictionary.Add(group, ((TypeSafeDictionary)typeSafeDictionary).implUnmgd); } return new NativeEGIDMultiMapper(dictionary); } } } #endif