-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking changes, introduced
Signature
. Renamed Group
to `Compone…
…nt`, moved methods around and several other small changes for improved performance.
- Loading branch information
Showing
16 changed files
with
376 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
namespace Arch.SourceGen; | ||
|
||
public static class ComponentExtensions | ||
{ | ||
public static StringBuilder AppendComponents(this StringBuilder sb, int amount) | ||
{ | ||
for (var index = 1; index < amount; index++) | ||
{ | ||
sb.AppendComponent(index); | ||
} | ||
|
||
return sb; | ||
} | ||
|
||
public static StringBuilder AppendComponent(this StringBuilder sb, int amount) | ||
{ | ||
var generics = new StringBuilder().GenericWithoutBrackets(amount); | ||
var types = new StringBuilder(); | ||
for (var index = 0; index <= amount; index++) | ||
{ | ||
types.Append($"Component<T{index}>.ComponentType,"); | ||
} | ||
|
||
var template = | ||
$$""" | ||
/// <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(); | ||
} | ||
} | ||
"""; | ||
|
||
return sb.AppendLine(template); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.