-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Several changes, upgraded Arch.LowLevel to latest version for improve…
…d performance, some query adjustments for improved performance and added first templates to replace source-gen.
- Loading branch information
Showing
9 changed files
with
358 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<#@ template language="C#" #> | ||
<#@ output extension=".cs" #> | ||
<#@ import namespace="System.Text" #> | ||
<#@ include file="Helpers.ttinclude" #> | ||
|
||
using Arch.Core; | ||
using System; | ||
using System.Threading; | ||
|
||
namespace Arch.Core.Utils; | ||
|
||
<# | ||
for (var index = 1; index < Amount; index++) | ||
{ | ||
var generics = AppendGenerics(index); | ||
var types = AppendTypes(index); | ||
#> | ||
|
||
/// <inheritdoc cref="Component"/> | ||
public static class Component<<#= generics #>> | ||
{ | ||
internal static readonly int Id; | ||
|
||
/// <summary> | ||
/// An <see cref="Signature"/> for this given set of components. | ||
/// </summary> | ||
public static readonly Signature Signature; | ||
|
||
/// <summary> | ||
/// The hash code for this given set of components. | ||
/// </summary> | ||
public static readonly int Hash; | ||
|
||
static Component() | ||
{ | ||
Id = Interlocked.Increment(ref Component.Id); | ||
Signature = new Signature(new [] { <#= types #> }); | ||
Hash = Signature.GetHashCode(); | ||
} | ||
} | ||
|
||
<# | ||
} | ||
#> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<#@ 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; | ||
|
||
<# | ||
for (var index = 1; index < Amount; index++) | ||
{ | ||
var generics = AppendGenerics(index); | ||
var parameters = AppendGenericRefParameters(index); | ||
|
||
var refStructs = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
refStructs.AppendLine($"public Ref<T{i}> t{i};"); | ||
|
||
var references = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
references.AppendLine($"public ref T{i} t{i};"); | ||
|
||
var assignRefStructs = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
assignRefStructs.AppendLine($"t{i} = new Ref<T{i}>(ref t{i}Component);"); | ||
|
||
var assignRefs = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
assignRefs.AppendLine($"t{i} = ref t{i}Component;"); | ||
#> | ||
|
||
[SkipLocalsInit] | ||
public ref struct Components<<#= generics #>> | ||
{ | ||
|
||
#if NETSTANDARD2_1 || NET6_0 | ||
<#= refStructs #> | ||
#else | ||
<#= references #> | ||
#endif | ||
|
||
[SkipLocalsInit] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public Components(<#= parameters #>){ | ||
|
||
#if NETSTANDARD2_1 || NET6_0 | ||
<#= assignRefStructs #> | ||
#else | ||
<#= assignRefs #> | ||
#endif | ||
|
||
} | ||
} | ||
|
||
<# | ||
} | ||
#> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<#@ 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; | ||
|
||
<# | ||
for (var index = 1; index < Amount; index++) | ||
{ | ||
var generics = AppendGenerics(index); | ||
var parameters = AppendGenericRefParameters(index); | ||
|
||
var refStructs = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
refStructs.AppendLine($"public Ref<T{i}> t{i};"); | ||
|
||
var references = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
references.AppendLine($"public ref T{i} t{i};"); | ||
|
||
var assignRefStructs = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
assignRefStructs.AppendLine($"t{i} = new Ref<T{i}>(ref t{i}Component);"); | ||
|
||
var assignRefs = new StringBuilder(); | ||
for (var i = 0; i < index; i++) | ||
assignRefs.AppendLine($"t{i} = ref t{i}Component;"); | ||
#> | ||
|
||
[SkipLocalsInit] | ||
public ref struct EntityComponents<<#= generics #>> | ||
{ | ||
|
||
#if NETSTANDARD2_1 || NET6_0 | ||
public ReadOnlyRef<Entity> Entity; | ||
<#= refStructs #> | ||
#else | ||
public ref readonly Entity Entity; | ||
<#= references #> | ||
#endif | ||
|
||
[SkipLocalsInit] | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public EntityComponents(ref Entity entity, <#= parameters #>){ | ||
|
||
#if NETSTANDARD2_1 || NET6_0 | ||
Entity = new ReadOnlyRef<Entity>(in entity); | ||
<#= assignRefStructs #> | ||
#else | ||
Entity = ref entity; | ||
<#= assignRefs #> | ||
#endif | ||
|
||
} | ||
} | ||
|
||
<# | ||
} | ||
#> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<#@ import namespace="System.Text" #> | ||
<#@ import namespace="System.Collections.Generic" #> | ||
<#+ | ||
|
||
public int Amount = 25; | ||
|
||
string AppendGenerics(int amount) | ||
{ | ||
var sb = new StringBuilder(); | ||
for (var i = 0; i < amount; i++) | ||
{ | ||
if (i > 0) sb.Append(", "); | ||
sb.Append($"T{i}"); | ||
} | ||
return sb.ToString(); | ||
} | ||
|
||
string AppendTypes(int amount) | ||
{ | ||
var sb = new StringBuilder(); | ||
for (var i = 0; i < amount; i++) | ||
{ | ||
sb.Append($"Component<T{i}>.ComponentType,"); | ||
} | ||
return sb.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Lists ref params in a row as parameters. | ||
/// <example> | ||
/// <code> | ||
/// ref T0 t0Component, ref T1 t1Component,... | ||
/// </code> | ||
/// </example> | ||
/// </summary> | ||
/// <param name="sb"></param> | ||
/// <param name="amount"></param> | ||
/// <returns></returns> | ||
public StringBuilder AppendGenericRefParameters(int amount) | ||
{ | ||
var sb = new StringBuilder(); | ||
for (var localIndex = 0; localIndex < amount; localIndex++) | ||
{ | ||
sb.Append($"ref T{localIndex} t{localIndex}Component,"); | ||
} | ||
|
||
sb.Length--; | ||
return sb; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Lists in params in a row as parameters. | ||
/// <example> | ||
/// <code> | ||
/// in T0 t0Component, in T1 t1Component,... | ||
/// </code> | ||
/// </example> | ||
/// </summary> | ||
/// <param name="sb"></param> | ||
/// <param name="amount"></param> | ||
/// <returns></returns> | ||
public StringBuilder AppendGenericInDefaultParams(int amount, string name = "Component") | ||
{ | ||
var sb = new StringBuilder(); | ||
for (var localIndex = 0; localIndex < amount; localIndex++) | ||
{ | ||
sb.Append($"in T{localIndex} t{localIndex}{name} = default,"); | ||
} | ||
|
||
sb.Length--; | ||
return sb; | ||
} | ||
|
||
/// <summary> | ||
/// Inserts ref params in a row as parameters. | ||
/// <example> | ||
/// <code> | ||
/// in t0Component, in t1Component,... | ||
/// </code> | ||
/// </example> | ||
/// </summary> | ||
/// <param name="sb"></param> | ||
/// <param name="amount"></param> | ||
/// <returns></returns> | ||
public StringBuilder InsertGenericInParams(int amount) | ||
{ | ||
var sb = new StringBuilder(); | ||
for (var localIndex = 0; localIndex < amount; localIndex++) | ||
{ | ||
sb.Append($"in t{localIndex}Component,"); | ||
} | ||
|
||
sb.Length--; | ||
return sb; | ||
} | ||
#> |
Oops, something went wrong.