Skip to content

Commit

Permalink
Released 1.3.0-alpha.
Browse files Browse the repository at this point in the history
  • Loading branch information
genaray committed Aug 12, 2024
1 parent 1fc2968 commit b166e88
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A high-performance C# based Archetype & Chunks [Entity Component System](https:/

Download the [package](https://github.com/genaray/Arch/packages/1697222), get started today and join the [Discord](https://discord.gg/htc8tX3NxZ)!
```console
dotnet add PROJECT package Arch --version 1.2.8.1-alpha
dotnet add PROJECT package Arch --version 1.3.0-alpha
```

# ⏩ Quickstart
Expand Down
2 changes: 0 additions & 2 deletions src/Arch.Samples/Systems.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics;
using Arch.Core;
using Arch.Core.Extensions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

Expand Down
8 changes: 4 additions & 4 deletions src/Arch.SourceGen/Queries/QueryDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static StringBuilder AppendQueryDescriptionWithAll(this StringBuilder sb,
public ref QueryDescription WithAll<{{generics}}>()
{
All = Component<{{generics}}>.Signature;
_hashCode = -1;
Build();
return ref this;
}
""";
Expand Down Expand Up @@ -53,7 +53,7 @@ public static StringBuilder AppendQueryDescriptionWithAny(this StringBuilder sb,
public ref QueryDescription WithAny<{{generics}}>()
{
Any = Component<{{generics}}>.Signature;
_hashCode = -1;
Build();
return ref this;
}
""";
Expand Down Expand Up @@ -83,7 +83,7 @@ public static StringBuilder AppendQueryDescriptionWithNone(this StringBuilder sb
public ref QueryDescription WithNone<{{generics}}>()
{
None = Component<{{generics}}>.Signature;
_hashCode = -1;
Build();
return ref this;
}
""";
Expand Down Expand Up @@ -113,7 +113,7 @@ public static StringBuilder AppendQueryDescriptionWithExclusive(this StringBuild
public ref QueryDescription WithExclusive<{{generics}}>()
{
Exclusive = Component<{{generics}}>.Signature;
_hashCode = -1;
Build();
return ref this;
}
""";
Expand Down
11 changes: 8 additions & 3 deletions src/Arch/Arch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@

<PackageId>Arch</PackageId>
<Title>Arch</Title>
<Version>1.2.8.2-alpha</Version>
<Version>1.3.0-alpha</Version>
<Authors>genaray</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Description>A high performance c# net.6 and net.7 archetype based ECS ( Entity component system ).</Description>
<Description>A high performance c# net.7 and net.8 archetype based ECS ( Entity component system ).</Description>
<PackageReleaseNotes>Updated CommunityToolkit, increases speed slightly.
Fixed some DangerousUtilities.
Refactored adding of entities to be faster.
Introduced Signature for improved performance.
Added MemoryMarshal.CreateSpan in some places for improved performance.
Introduced breaking changes by renaming Group to Component and several other small changes. </PackageReleaseNotes>
Introduced breaking changes by renaming Group to Component and several other small changes.
Updated Arch.LowLevel.
Improved performance of almost all operations.
Refatored QueryDescription, use the constructor or generics now instead.
Improved ASM-Code generation for improved performance for smaller querys.
Removed several methods from arch to slim down the core. </PackageReleaseNotes>
<PackageTags>c#;.net;.net6;.net7;ecs;game;entity;gamedev; game-development; game-engine; entity-component-system;stride;unity;godot;</PackageTags>

<PackageProjectUrl>https://github.com/genaray/Arch</PackageProjectUrl>
Expand Down
20 changes: 10 additions & 10 deletions src/Arch/Core/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,26 +224,26 @@ public partial struct QueryDescription : IEquatable<QueryDescription>

/// <summary>
/// An <see cref="Signature"/> of all components that an <see cref="Entity"/> should have mandatory.
/// <remarks>If the content of the array is subsequently changed, a <see cref="Rebuild"/> should be carried out.</remarks>
/// <remarks>If the content of the array is subsequently changed, a <see cref="Build"/> should be carried out.</remarks>
/// </summary>
public Signature All { get; private set; } = Signature.Null;

/// <summary>
/// An array of all components of which an <see cref="Entity"/> should have at least one.
/// <remarks>If the content of the array is subsequently changed, a <see cref="Rebuild"/> should be carried out.</remarks>
/// <remarks>If the content of the array is subsequently changed, a <see cref="Build"/> should be carried out.</remarks>
/// </summary>
public Signature Any { get; private set; } = Signature.Null;

/// <summary>
/// An array of all components of which an <see cref="Entity"/> should not have any.
/// <remarks>If the content of the array is subsequently changed, a <see cref="Rebuild"/> should be carried out.</remarks>
/// <remarks>If the content of the array is subsequently changed, a <see cref="Build"/> should be carried out.</remarks>
/// </summary>
public Signature None { get; private set; } = Signature.Null;

/// <summary>
/// An array of all components that exactly match the structure of an <see cref="Entity"/>.
/// <see cref="Entity"/>'s with more or less components than those defined in the array are not addressed.
/// <remarks>If the content of the array is subsequently changed, a <see cref="Rebuild"/> should be carried out.</remarks>
/// <remarks>If the content of the array is subsequently changed, a <see cref="Build"/> should be carried out.</remarks>
/// </summary>
public Signature Exclusive { get; private set; } = Signature.Null;

Expand Down Expand Up @@ -292,11 +292,11 @@ public QueryDescription(ComponentType[]? all = null, ComponentType[]? any = null
}

/// <summary>
/// Recreates this instance by calculating a new <see cref="_hashCode"/>.
/// Builds this instance by calculating a new <see cref="_hashCode"/>.
/// Is actually only needed if the passed arrays are changed afterwards.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Rebuild()
public void Build()
{
_hashCode = -1;
_hashCode = GetHashCode();
Expand All @@ -312,7 +312,7 @@ public void Rebuild()
public ref QueryDescription WithAll<T>()
{
All = Component<T>.Signature;
_hashCode = -1;
Build();
return ref this;
}

Expand All @@ -326,7 +326,7 @@ public ref QueryDescription WithAll<T>()
public ref QueryDescription WithAny<T>()
{
Any = Component<T>.Signature;
_hashCode = -1;
Build();
return ref this;
}

Expand All @@ -340,7 +340,7 @@ public ref QueryDescription WithAny<T>()
public ref QueryDescription WithNone<T>()
{
None = Component<T>.Signature;
_hashCode = -1;
Build();
return ref this;
}

Expand All @@ -355,7 +355,7 @@ public ref QueryDescription WithNone<T>()
public ref QueryDescription WithExclusive<T>()
{
Exclusive = Component<T>.Signature;
_hashCode = -1;
Build();
return ref this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Arch/Core/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ internal record struct RecycledEntity
/// <summary>
/// The recycled id.
/// </summary>
public int Id;
public readonly int Id;

/// <summary>
/// The new version.
/// </summary>
public int Version;
public readonly int Version;

/// <summary>
/// Initializes a new instance of the <see cref="RecycledEntity"/> struct.
Expand Down
55 changes: 55 additions & 0 deletions src/Arch/Templates/Chunk.GetArray.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#@ import namespace="System.Text" #>
<#@ include file="Helpers.ttinclude" #>

using System;
using System.Runtime.CompilerServices;
using CommunityToolkit.HighPerformance;
using Arch.Core.Utils;

namespace Arch.Core;

public partial struct Chunk
{

<#
for (var index = 1; index < Amount; index++)
{
var generics = AppendGenerics(index);

var addEvents = new StringBuilder();
for (var i = 0; i < index; i++)
addEvents.AppendLine($"OnComponentAdded<T{i}>(entity);");

var outs = new StringBuilder();
for (var i = 0; i < index; i++)
outs.Append($"out T{i}[] t{i}Array,");
outs.Length--;

var indexes = new StringBuilder();
for (var i = 0; i < index; i++)
indexes.Append($"out var t{i}Index,");
indexes.Length--;

var assignComponents = new StringBuilder();
for (var i = 0; i < index; i++)
assignComponents.AppendLine($"t{i}Array = Unsafe.As<T{i}[]>(Unsafe.Add(ref arrays, t{i}Index));");

#>

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public void GetArray<<#= generics #>>(<#= outs #>)
{
Index<<#= generics #>>(<#= indexes #>);
ref var arrays = ref Components.DangerousGetReference();
<#= assignComponents #>
}
<#
}
#>

}


47 changes: 47 additions & 0 deletions src/Arch/Templates/Chunk.GetFirst.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#@ import namespace="System.Text" #>
<#@ include file="Helpers.ttinclude" #>

using System;
using System.Runtime.CompilerServices;
using CommunityToolkit.HighPerformance;
using Arch.Core.Utils;

namespace Arch.Core;

public partial struct Chunk
{

<#
for (var index = 1; index < Amount; index++)
{
var generics = AppendGenerics(index);

var arrays = new StringBuilder();
for (var i = 0; i <= index; i++)
arrays.Append($"out var t{i}Array,");
arrays.Length--;

var insertParams = new StringBuilder();
for (var i = 0; i <= index; i++)
insertParams.Append($"ref t{i}Array.DangerousGetReference(),");
insertParams.Length--;

#>

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public Components<<#= generics #>> GetFirst<<#= generics #>>()
{
GetArray<<#= generics #>>(<#= arrays #>);
return new Components<<#= generics #>>(<#= insertParams #>);
}

<#
}
#>

}


49 changes: 49 additions & 0 deletions src/Arch/Templates/Chunk.GetSpan.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#@ import namespace="System.Text" #>
<#@ include file="Helpers.ttinclude" #>

using System;
using System.Runtime.CompilerServices;
using CommunityToolkit.HighPerformance;
using Arch.Core.Utils;

namespace Arch.Core;

public partial struct Chunk
{
<#
for (var index = 1; index < Amount; index++)
{
var generics = AppendGenerics(index);

var outs = new StringBuilder();
for (var i = 0; i <= index; i++)
outs.Append($"out Span<T{i}> t{i}Span,");
outs.Length--;

var arrays = new StringBuilder();
for (var i = 0; i <= index; i++)
arrays.Append($"out var t{i}Array,");
arrays.Length--;

var assignComponents = new StringBuilder();
for (var i = 0; i <= index; i++)
assignComponents.AppendLine($"t{i}Span = new Span<T{i}>(t{i}Array);");

#>

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public void GetSpan<<#= generics #>>(<#= outs #>)
{
GetArray<<#= generics #>>(<#= arrays #>);
<#= assignComponents #>
}

<#
}
#>
}


Loading

0 comments on commit b166e88

Please sign in to comment.