Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ECS.Boost/Friflo.Engine.ECS.Boost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>library</OutputType>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<RootNamespace>Friflo.Engine.ECS</RootNamespace>
Expand Down
4 changes: 4 additions & 0 deletions src/ECS/Archetype/EntityStore.Archetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions src/ECS/Archetype/EntityStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArchetypeKey, ArchetypeKey> archSet; // 8 - Set<> to get archetypes by key
#else
[Browse(Never)] private readonly HashSet<ArchetypeKey> archSet; // 8 - Set<> to get archetypes by key
#endif
/// <summary>The default <see cref="Archetype"/> has no <see cref="Archetype.ComponentTypes"/> and <see cref="Archetype.Tags"/>.<br/>
/// Its <see cref="Archetype"/>.<see cref="Archetype.archIndex"/> is always 0 (<see cref="Static.DefaultArchIndex"/>).</summary>
[Browse(Never)] internal readonly Archetype defaultArchetype; // 8 - default archetype. has no components & tags
Expand Down Expand Up @@ -142,7 +146,11 @@ internal static class Static
protected EntityStoreBase()
{
archs = new Archetype[2];
#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER
archSet = new Dictionary<ArchetypeKey, ArchetypeKey>(ArchetypeKeyEqualityComparer.Instance);
#else
archSet = new HashSet<ArchetypeKey>(ArchetypeKeyEqualityComparer.Instance);
#endif
var config = GetArchetypeConfig(this);
defaultArchetype = new Archetype(config);
searchKey = new ArchetypeKey();
Expand Down
4 changes: 4 additions & 0 deletions src/ECS/Base/SchemaUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 25 additions & 3 deletions src/ECS/Entity/MemberPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
/// Returns a <see cref="MemberPath"/> identifying a specific field / property by its <paramref name="path"/>
/// within the passed <paramref name="type"/>.
Expand All @@ -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;
Expand Down Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion src/ECS/Friflo.Engine.ECS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>library</OutputType>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<RootNamespace>Friflo.Engine.ECS</RootNamespace>
Expand Down
4 changes: 4 additions & 0 deletions src/ECS/Systems/Extensions/SystemPerf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

5 changes: 5 additions & 0 deletions src/ECS/Utils/TreeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ private static void DuplicateChildren(Entity entity, Entity clone, EntityStore s
public static AddDataEntitiesResult AddDataEntitiesToEntity(Entity targetEntity, IReadOnlyList<DataEntity> dataEntities)
{
var entityCount = dataEntities.Count;
#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER
var childEntities = new HashSet<long> ();
childEntities.EnsureCapacity(entityCount);
#else
var childEntities = new HashSet<long> (entityCount);
#endif
var oldToNewPid = new Dictionary<long, long>(entityCount);
var newToOldPid = new Dictionary<long, long>(entityCount);
var store = targetEntity.Store;
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Engine.Hub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>library</OutputType>
<TargetFrameworks>net8.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<RootNamespace>Friflo.Engine.Hub</RootNamespace>
Expand Down
1 change: 0 additions & 1 deletion src/Tests-NativeAOT/Tests-NativeAOT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<PublishAot>true</PublishAot>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, it doesn't compile without this turned off.

<!-- <DefineConstants Condition="'$(PublishAot)' == 'true'">
$(DefineConstants);IS_NATIVE_AOT
</DefineConstants> -->
Expand Down