Skip to content

Commit

Permalink
Fixing sizes (#189)
Browse files Browse the repository at this point in the history
* Increased array size for when adding new components

* Maybe better
  • Loading branch information
RoyconSkylands authored Nov 28, 2023
1 parent af4c616 commit 0afd40a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit 0afd40a

Please sign in to comment.