#if UNITY_NATIVE using System.Runtime.CompilerServices; using Svelto.Common; using Svelto.DataStructures; using Svelto.ECS.Internal; namespace Svelto.ECS { public static class UnityEntityDBExtensions { 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) where T : unmanaged, IEntityComponent { var dictionary = new SveltoDictionary>, NativeStrategy, NativeStrategy>, NativeStrategy>, NativeStrategy>, NativeStrategy, NativeStrategy>>, NativeStrategy> ((uint) groups.count, Allocator.TempJob); 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