Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing sizes #189

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Arch.SourceGen/Fundamentals/StructuralChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ public static StringBuilder AppendWorldAdd(this StringBuilder sb, int amount)
var inParameters = new StringBuilder().InsertGenericInParams(amount);
var types = new StringBuilder().GenericTypeParams(amount);

var getIds = new StringBuilder();
var setIds = new StringBuilder();
var addEvents = new StringBuilder();
for (var index = 0; index <= amount; index++)
{
setIds.AppendLine($"spanBitSet.SetBit(Component<T{index}>.ComponentType.Id);");
getIds.AppendLine($"var id{index} = Component<T{index}>.ComponentType.Id;");
setIds.AppendLine($"spanBitSet.SetBit(id{index});");
addEvents.AppendLine($"OnComponentAdded<T{index}>(entity);");
}

Expand All @@ -36,6 +38,9 @@ public static StringBuilder AppendWorldAdd(this StringBuilder sb, int amount)
{
var oldArchetype = EntityInfo.GetArchetype(entity.Id);

// Get all the ids here just in case we are adding a new component as this will grow the ComponentRegistry.Size
{{getIds}}

// BitSet to stack/span bitset, size big enough to contain ALL registered components.
Span<uint> stack = stackalloc uint[BitSet.RequiredLength(ComponentRegistry.Size)];
oldArchetype.BitSet.AsSpan(stack);
Expand Down
2 changes: 1 addition & 1 deletion src/Arch.SourceGen/Queries/AddWithQueryDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void AppendAddWithQueryDescription(this StringBuilder sb, int amou
public void Add<{{generics}}>(in QueryDescription queryDescription, {{parameters}})
{
// BitSet to stack/span bitset, size big enough to contain ALL registered components.
Span<uint> stack = stackalloc uint[BitSet.RequiredLength(ComponentRegistry.Size)];
Span<uint> stack = stackalloc uint[BitSet.RequiredLength(ComponentRegistry.Size + {{amount + 1}})];

var query = Query(in queryDescription);
foreach (var archetype in query.GetArchetypeIterator())
Expand Down
Loading