Skip to content

Commit

Permalink
Merge pull request #22 from andreakarasho/advanced-or
Browse files Browse the repository at this point in the history
Advanced or
  • Loading branch information
andreakarasho authored May 31, 2024
2 parents 909e42d + d5db6a8 commit 7392d8f
Show file tree
Hide file tree
Showing 10 changed files with 499 additions and 350 deletions.
16 changes: 11 additions & 5 deletions samples/MyBattleground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@


//ecs.Entity().Set(new Position() {X = 2}).Set<Likes>();
ecs.Entity().Set(new Position() {X = 3}).Set<Networked>();

ecs.Query<(Position, ManagedData), Or<(Position, Without<Networked>)>>()
ecs.Entity().Set(new Position() {X = 3});

ecs.Query<
(Position, ManagedData),
Or<(With<Position>, With<Networked>, Without<Velocity>,
Or<(Without<Networked>, With<Position>)>
)>
>()
.Each((EntityView e, ref Position maybe) => {
var isNull = Unsafe.IsNullRef(ref maybe);

Expand Down Expand Up @@ -366,6 +371,7 @@
Console.WriteLine("query done in {0} ms", start - last);
}


enum TileType
{
Land,
Expand Down Expand Up @@ -398,13 +404,13 @@ struct ChunkTile;
class ComplexQuery : ISystemParam
{
public Query<(Position, Velocity)>? Q0;
public Query<(Position, Velocity), (With<PlayerTag>, Not<Likes>)>? Q1;
public Query<(Position, Velocity), (With<PlayerTag>, Without<Likes>)>? Q1;

void ISystemParam.New(object arguments)
{
var world = (World) arguments;
Q0 = (Query<(Position, Velocity)>)world.Query<(Position, Velocity)>();
Q1 = (Query<(Position, Velocity), (With<PlayerTag>, Not<Likes>)>)world.Query<(Position, Velocity), (With<PlayerTag>, Not<Likes>)>();
Q1 = (Query<(Position, Velocity), (With<PlayerTag>, Without<Likes>)>)world.Query<(Position, Velocity), (With<PlayerTag>, Without<Likes>)>();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Archetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private bool IsSuperset(ReadOnlySpan<ComponentInfo> other)
return j == other.Length;
}

internal int FindMatch(ReadOnlySpan<Term> searching)
internal int FindMatch(ReadOnlySpan<QueryTerm> searching)
{
return Match.Validate(_comparer, _ids, searching);
}
Expand Down
101 changes: 101 additions & 0 deletions src/DotnetAddons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,107 @@ public UnscopedRefAttribute() { }
}
}

namespace System.Diagnostics.CodeAnalysis
{
//
// Summary:
// Indicates that certain members on a specified System.Type are accessed dynamically,
// for example, through System.Reflection.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)]
public sealed class DynamicallyAccessedMembersAttribute : Attribute
{
//
// Summary:
// Initializes a new instance of the System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute
// class with the specified member types.
//
// Parameters:
// memberTypes:
// The types of the dynamically accessed members.
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes);

Check failure on line 115 in src/DotnetAddons.cs

View workflow job for this annotation

GitHub Actions / build

'DynamicallyAccessedMembersAttribute.DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes)' must declare a body because it is not marked abstract, extern, or partial

Check failure on line 115 in src/DotnetAddons.cs

View workflow job for this annotation

GitHub Actions / build

'DynamicallyAccessedMembersAttribute.DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes)' must declare a body because it is not marked abstract, extern, or partial

//
// Summary:
// Gets the System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes that
// specifies the type of dynamically accessed members.
public DynamicallyAccessedMemberTypes MemberTypes { get; }
}

//
// Summary:
// Specifies the types of members that are dynamically accessed. This enumeration
// has a System.FlagsAttribute attribute that allows a bitwise combination of its
// member values.
[Flags]
public enum DynamicallyAccessedMemberTypes
{
//
// Summary:
// Specifies all members.
All = -1,
//
// Summary:
// Specifies no members.
None = 0,
//
// Summary:
// Specifies the default, parameterless public constructor.
PublicParameterlessConstructor = 1,
//
// Summary:
// Specifies all public constructors.
PublicConstructors = 3,
//
// Summary:
// Specifies all non-public constructors.
NonPublicConstructors = 4,
//
// Summary:
// Specifies all public methods.
PublicMethods = 8,
//
// Summary:
// Specifies all non-public methods.
NonPublicMethods = 16,
//
// Summary:
// Specifies all public fields.
PublicFields = 32,
//
// Summary:
// Specifies all non-public fields.
NonPublicFields = 64,
//
// Summary:
// Specifies all public nested types.
PublicNestedTypes = 128,
//
// Summary:
// Specifies all non-public nested types.
NonPublicNestedTypes = 256,
//
// Summary:
// Specifies all public properties.
PublicProperties = 512,
//
// Summary:
// Specifies all non-public properties.
NonPublicProperties = 1024,
//
// Summary:
// Specifies all public events.
PublicEvents = 2048,
//
// Summary:
// Specifies all non-public events.
NonPublicEvents = 4096,
//
// Summary:
// Specifies all interfaces implemented by the type.
Interfaces = 8192
}
}

namespace System.Runtime.CompilerServices
{
/// <summary>
Expand Down
31 changes: 31 additions & 0 deletions src/Hashing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace TinyEcs;

internal static class Hashing
{
const ulong FIXED = 314159;

public static ulong Calculate(ReadOnlySpan<ComponentInfo> components)
{
var hc = (ulong)components.Length;
foreach (ref readonly var val in components)
hc = unchecked(hc * FIXED + val.ID);
return hc;
}

public static ulong Calculate(ReadOnlySpan<QueryTerm> terms)
{
var hc = (ulong)terms.Length;
foreach (ref readonly var val in terms)
hc = unchecked(hc * FIXED + (ulong)val.Id + (byte)val.Op +
(val is ContainerQueryTerm container ? container.Terms.Aggregate(0Ul, static (a, b) => a + b.Id.Value) : 0));
return hc;
}

public static ulong Calculate(IEnumerable<EcsID> terms)
{
var hc = (ulong)terms.Count();
foreach (var val in terms)
hc = unchecked(hc * FIXED + val);
return hc;
}
}
Loading

0 comments on commit 7392d8f

Please sign in to comment.