Skip to content

Commit ffcf588

Browse files
[Entities] Fix ComponentVersionTracker use of arrays;
1 parent 0086120 commit ffcf588

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Engine/Staple.Core/Entities/ComponentVersionTracker.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Staple;
44

55
public class ComponentVersionTracker<T> where T: IComponent, IComponentVersion
66
{
7-
private ulong[] versions = [1024];
7+
private ulong[] versions = new ulong[1024];
88

99
public bool ShouldUpdateComponent(Entity entity, in T component)
1010
{
@@ -15,13 +15,21 @@ public bool ShouldUpdateComponent(Entity entity, in T component)
1515

1616
if(versions.Length < entity.Identifier.ID)
1717
{
18-
Array.Resize(ref versions, entity.Identifier.ID);
18+
Array.Resize(ref versions, versions.Length * 2);
1919
}
2020

21-
var version = versions[entity.Identifier.ID - 1];
21+
var componentVersion = component.Version;
22+
var index = entity.Identifier.ID - 1;
2223

23-
versions[entity.Identifier.ID - 1] = component.Version;
24+
var version = versions[index];
2425

25-
return version != component.Version;
26+
if(version != componentVersion)
27+
{
28+
versions[index] = componentVersion;
29+
30+
return true;
31+
}
32+
33+
return false;
2634
}
2735
}

0 commit comments

Comments
 (0)