Skip to content

Commit

Permalink
fixed World.Optimize breaking the component references when entities …
Browse files Browse the repository at this point in the history
…share a component (fixes #156)
  • Loading branch information
Doraku committed Jan 30, 2022
1 parent 84fd55c commit 860e0b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion documentation/NEXT_RELEASENOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Fixes

- fixed WorldRecord.Set (#148)
- fixed previous component value retrieval when a component is removed during a added/changed callback (#146)
- fixed previous component value retrieval when a component is removed during a added/changed callback (#146)
- fixed World.Optimize breaking the component references when entities share a component (#156 thanks to @iHell)
20 changes: 20 additions & 0 deletions source/DefaultEcs.Test/WorldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,26 @@ public void Optimize_Should_return_When_mainAction_is_done()
Check.That(world.GetAll<int>().ToArray().Select((v, i) => (i, v)).Any(t => t.i != t.v)).IsTrue();
}

[Fact]
public void Optimize_Should_sort_entities_sharing_components()
{
using World world = new();

Entity entity1 = world.CreateEntity();
Entity entity2 = world.CreateEntity();
Entity entity3 = world.CreateEntity();

entity3.Set("kikoo");
entity2.Set("lol");
entity1.SetSameAs<string>(entity2);

world.Optimize();

Check.That(entity1.Get<string>()).IsEqualTo("lol");
Check.That(entity2.Get<string>()).IsEqualTo("lol");
Check.That(entity3.Get<string>()).IsEqualTo("kikoo");
}

[Fact]
public void SubscribeWorldDisposed_Should_throw_When_action_is_null()
{
Expand Down
4 changes: 2 additions & 2 deletions source/DefaultEcs/Internal/ComponentPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ void ISortable.Sort(ref bool shouldContinue)
{
for (int i = 0; i < _mapping.Length; ++i)
{
if (_mapping[i] == minEntityId)
if (_mapping[i] == minIndex)
{
_mapping[i] = _sortedIndex;
}
else if (_mapping[i] == tempLink.EntityId)
else if (_mapping[i] == _sortedIndex)
{
_mapping[i] = minIndex;
}
Expand Down

0 comments on commit 860e0b6

Please sign in to comment.