diff --git a/src/ECS.Boost/Friflo.Engine.ECS.Boost.csproj b/src/ECS.Boost/Friflo.Engine.ECS.Boost.csproj index 2ac010fa..2ab3c254 100644 --- a/src/ECS.Boost/Friflo.Engine.ECS.Boost.csproj +++ b/src/ECS.Boost/Friflo.Engine.ECS.Boost.csproj @@ -2,7 +2,7 @@ library - net8.0;net7.0;net6.0;netstandard2.1 + net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0 disable disable Friflo.Engine.ECS diff --git a/src/ECS/Archetype/EntityStore.Archetype.cs b/src/ECS/Archetype/EntityStore.Archetype.cs index 59c150a1..273def6f 100644 --- a/src/ECS/Archetype/EntityStore.Archetype.cs +++ b/src/ECS/Archetype/EntityStore.Archetype.cs @@ -186,7 +186,11 @@ internal static void AddArchetype (EntityStoreBase store, Archetype archetype) } store.archs[store.archsCount] = archetype; store.archsCount++; +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + store.archSet.Add(archetype.key, archetype.key); +#else store.archSet.Add(archetype.key); +#endif } #endregion } diff --git a/src/ECS/Archetype/EntityStore.cs b/src/ECS/Archetype/EntityStore.cs index 6c1a32fc..a6a5ba75 100644 --- a/src/ECS/Archetype/EntityStore.cs +++ b/src/ECS/Archetype/EntityStore.cs @@ -78,7 +78,11 @@ public abstract partial class EntityStoreBase // --- archetypes [Browse(Never)] internal Archetype[] archs; // 8 - array of all archetypes. never null [Browse(Never)] private int archsCount; // 4 - number of archetypes +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + [Browse(Never)] private readonly Dictionary archSet; // 8 - Set<> to get archetypes by key +#else [Browse(Never)] private readonly HashSet archSet; // 8 - Set<> to get archetypes by key +#endif /// The default has no and .
/// Its . is always 0 ().
[Browse(Never)] internal readonly Archetype defaultArchetype; // 8 - default archetype. has no components & tags @@ -142,7 +146,11 @@ internal static class Static protected EntityStoreBase() { archs = new Archetype[2]; +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + archSet = new Dictionary(ArchetypeKeyEqualityComparer.Instance); +#else archSet = new HashSet(ArchetypeKeyEqualityComparer.Instance); +#endif var config = GetArchetypeConfig(this); defaultArchetype = new Archetype(config); searchKey = new ArchetypeKey(); diff --git a/src/ECS/Base/SchemaUtils.cs b/src/ECS/Base/SchemaUtils.cs index e089fc71..99808b1b 100644 --- a/src/ECS/Base/SchemaUtils.cs +++ b/src/ECS/Base/SchemaUtils.cs @@ -18,7 +18,11 @@ private static bool RegisterComponentTypesByReflection() { if (Platform.IsUnityRuntime) { return true; } +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + return true; +#else return System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled; +#endif } [ExcludeFromCodeCoverage] diff --git a/src/ECS/Entity/MemberPath.cs b/src/ECS/Entity/MemberPath.cs index 555fa53b..2bfb58b2 100644 --- a/src/ECS/Entity/MemberPath.cs +++ b/src/ECS/Entity/MemberPath.cs @@ -104,6 +104,10 @@ private MemberPath(MemberPathKey key, ComponentType componentType, int structInd private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.GetProperty; +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + private static readonly char[] SplitDotArray = ['.']; +#endif + /// /// Returns a identifying a specific field / property by its /// within the passed . @@ -122,7 +126,11 @@ public static MemberPath Get(Type type, string path) if (Map.TryGetValue(key, out var componentFieldInfo)) { return componentFieldInfo; } +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + var pathItems = path.Split(SplitDotArray, StringSplitOptions.RemoveEmptyEntries); +#else var pathItems = path.Split('.', StringSplitOptions.RemoveEmptyEntries); +#endif var memberInfos = new MemberInfo[pathItems.Length]; var memberType = type; bool canWrite = true; @@ -188,10 +196,24 @@ public static MemberPath Get(Type type, string path) // See ThrowIfTypeNeverValidGenericArgument() at: // https://github.com/dotnet/runtime/blob/4f5c6938d09e935830492c006aa8381611b65ad8/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs#L736 - private static bool IsInvalidType(Type type) { - return type.IsPointer || type.IsByRef || type == typeof(void) || - type.IsByRefLike; // type is a ref struct. E.g. Span<> +private static bool IsInvalidType(Type type) +{ + if (type.IsPointer || type.IsByRef || type == typeof(void)) + return true; +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + if (type.IsByRef) + return true; + if (type.IsGenericType) + { + var genericTypeDef = type.GetGenericTypeDefinition(); + if (genericTypeDef == typeof(Span<>) || genericTypeDef == typeof(ReadOnlySpan<>)) + return true; } + return false; +#else + return type.IsByRefLike; // type is a ref struct. E.g. Span<> +#endif +} // ReSharper disable UnusedMember.Local [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "Not called for NativeAOT")] diff --git a/src/ECS/Friflo.Engine.ECS.csproj b/src/ECS/Friflo.Engine.ECS.csproj index 1fd4ceb4..fa5b2068 100644 --- a/src/ECS/Friflo.Engine.ECS.csproj +++ b/src/ECS/Friflo.Engine.ECS.csproj @@ -2,7 +2,7 @@ library - net8.0;net7.0;net6.0;netstandard2.1 + net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0 disable disable Friflo.Engine.ECS diff --git a/src/ECS/Systems/Extensions/SystemPerf.cs b/src/ECS/Systems/Extensions/SystemPerf.cs index e5db3d5c..20e84300 100644 --- a/src/ECS/Systems/Extensions/SystemPerf.cs +++ b/src/ECS/Systems/Extensions/SystemPerf.cs @@ -92,7 +92,11 @@ public PerfResource () { [ExcludeFromCodeCoverage] internal static long GetAllocatedBytes() { +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + return 0; +#else return Platform.IsUnityRuntime ? 0 : GC.GetAllocatedBytesForCurrentThread(); +#endif } } diff --git a/src/ECS/Utils/TreeUtils.cs b/src/ECS/Utils/TreeUtils.cs index fa94f27a..27d292f4 100644 --- a/src/ECS/Utils/TreeUtils.cs +++ b/src/ECS/Utils/TreeUtils.cs @@ -80,7 +80,12 @@ private static void DuplicateChildren(Entity entity, Entity clone, EntityStore s public static AddDataEntitiesResult AddDataEntitiesToEntity(Entity targetEntity, IReadOnlyList dataEntities) { var entityCount = dataEntities.Count; +#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER + var childEntities = new HashSet (); + childEntities.EnsureCapacity(entityCount); +#else var childEntities = new HashSet (entityCount); +#endif var oldToNewPid = new Dictionary(entityCount); var newToOldPid = new Dictionary(entityCount); var store = targetEntity.Store; diff --git a/src/Hub/Engine.Hub.csproj b/src/Hub/Engine.Hub.csproj index e772da1c..a61ccf6f 100644 --- a/src/Hub/Engine.Hub.csproj +++ b/src/Hub/Engine.Hub.csproj @@ -2,7 +2,7 @@ library - net8.0;netstandard2.1 + net8.0;netstandard2.1;netstandard2.0 disable disable Friflo.Engine.Hub diff --git a/src/Tests-NativeAOT/Tests-NativeAOT.csproj b/src/Tests-NativeAOT/Tests-NativeAOT.csproj index a856e958..6f94e6d5 100644 --- a/src/Tests-NativeAOT/Tests-NativeAOT.csproj +++ b/src/Tests-NativeAOT/Tests-NativeAOT.csproj @@ -2,7 +2,6 @@ Exe - true