Skip to content

Commit

Permalink
netstandard2.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
andreakarasho committed May 31, 2024
1 parent ad50586 commit da75c7f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/DotnetAddons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public sealed class DynamicallyAccessedMembersAttribute : Attribute
// Parameters:
// memberTypes:
// The types of the dynamically accessed members.
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes);
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes) => MemberTypes = memberTypes;

//
// Summary:
Expand Down
30 changes: 29 additions & 1 deletion src/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,56 @@ namespace TinyEcs;

public ref struct QueryInternal
{
#if NET
private ref Archetype _value;
private readonly ref Archetype _first, _last;
#else
private Ref<Archetype> _value;
private readonly Ref<Archetype> _first, _last;
#endif


internal QueryInternal(Span<Archetype> archetypes)
{
#if NET
_first = ref MemoryMarshal.GetReference(archetypes);
_last = ref Unsafe.Add(ref _first, archetypes.Length);
_value = ref Unsafe.NullRef<Archetype>();
#else
_first = new(ref MemoryMarshal.GetReference(archetypes));
_last = new(ref Unsafe.Add(ref _first.Value, archetypes.Length));
_value = new(ref Unsafe.NullRef<Archetype>());
#endif
}

public readonly ref Archetype Current => ref _value;
public readonly ref Archetype Current => ref
_value
#if !NET
.Value
#endif
;


public bool MoveNext()
{
while (true)
{
#if NET
_value = ref Unsafe.IsNullRef(ref _value) ? ref _first : ref Unsafe.Add(ref _value, 1);
if (!Unsafe.IsAddressLessThan(ref _value, ref _last))
break;

if (_value.Count > 0)
return true;
#else
ref var value = ref _value.Value;
value = ref Unsafe.IsNullRef(ref value) ? ref _first.Value : ref Unsafe.Add(ref value, 1);

Check warning on line 50 in src/Query.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in value of type 'TinyEcs.Archetype' doesn't match target type 'TinyEcs.Archetype?'.
if (!Unsafe.IsAddressLessThan(ref value, ref _last.Value))
break;

if (value.Count > 0)
return true;
#endif
}

return false;
Expand Down

0 comments on commit da75c7f

Please sign in to comment.