public void Contains_Should_return_weither_an_entity_is_in_or_not() { using World world = new(); Entity entity = world.CreateEntity(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Check.That(map.Contains(entity)).IsFalse(); entity.Set(42); world.CreateEntity().Set(42); Check.That(map.Contains(entity)).IsTrue(); entity.Disable <int>(); Check.That(map.Contains(entity)).IsFalse(); entity.Enable <int>(); Check.That(map.Contains(entity)).IsTrue(); entity.Remove <int>(); Check.That(map.Contains(entity)).IsFalse(); }
public void Should_behave_correctly_when_key_changed() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Entity entity = world.CreateEntity(); entity.Set(42); Check.That(map.TryGetEntities(42, out ReadOnlySpan <Entity> result)).IsTrue(); Check.That(result.ToArray()).ContainsExactly(entity); entity.Set(1337); Check.That(map.TryGetEntities(42, out result)).IsFalse(); Check.That(map.TryGetEntities(1337, out result)).IsTrue(); Check.That(result.ToArray()).ContainsExactly(entity); entity.Get <int>() = 42; entity.NotifyChanged <int>(); Check.That(map.TryGetEntities(1337, out result)).IsFalse(); Check.That(map.TryGetEntities(42, out result)).IsTrue(); Check.That(result.ToArray()).ContainsExactly(entity); }
public void Keys_Should_return_keys() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Entity entity = world.CreateEntity(); entity.Set(42); Check.That(map.Keys as IEnumerable).ContainsExactly(42); entity.Remove <int>(); Check.That(map.Keys).IsEmpty(); entity.Set(42); using IEnumerator <int> enumerator = (map.Keys as IEnumerable <int>)?.GetEnumerator(); Check.That(enumerator.MoveNext()).IsTrue(); Check.That(enumerator.Current).IsEqualTo(42); enumerator.Reset(); Check.That(enumerator.MoveNext()).IsTrue(); Check.That(enumerator.Current).IsEqualTo(42); }
public void TryGetEntities_Should_return_weither_a_key_is_in_or_not() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Entity entity = world.CreateEntity(); Check.That(map.TryGetEntities(42, out ReadOnlySpan <Entity> result)).IsFalse(); entity.Set(42); Check.That(map.TryGetEntities(42, out result)).IsTrue(); Check.That(result.ToArray()).ContainsExactly(entity); entity.Disable <int>(); Check.That(map.TryGetEntities(42, out result)).IsFalse(); entity.Enable <int>(); Check.That(map.TryGetEntities(42, out result)).IsTrue(); Check.That(result.ToArray()).ContainsExactly(entity); entity.Remove <int>(); Check.That(map.TryGetEntities(42, out result)).IsFalse(); }
public void Optimize_Should_sort_inner_storages() { using World world = new(); using EntitySet set = world.GetEntities().With <int>().AsSet(); using EntityMultiMap <bool> map = world.GetEntities().With <int>().AsMultiMap <bool>(); Entity e1 = world.CreateEntity(); Entity e2 = world.CreateEntity(); Entity e3 = world.CreateEntity(); Entity e4 = world.CreateEntity(); e4.Set(true); e4.Set(4); e3.Set(true); e3.Set(3); e2.Set(true); e2.Set(2); e1.Set(true); e1.Set(1); Check.That(set.GetEntities().ToArray()).ContainsExactly(e4, e3, e2, e1); Check.That(world.Get <int>().ToArray()).ContainsExactly(4, 3, 2, 1); Check.That(map[true].ToArray()).ContainsExactly(e4, e3, e2, e1); world.Optimize(); Check.That(set.GetEntities().ToArray()).ContainsExactly(e1, e2, e3, e4); Check.That(world.Get <int>().ToArray()).ContainsExactly(1, 2, 3, 4); Check.That(map[true].ToArray()).ContainsExactly(e1, e2, e3, e4); }
internal KeyEnumerator(EntityMultiMap <TKey> map) { _map = map; _enumerator = map._entities.GetEnumerator(); Current = default; }
public void World_Should_return_world() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Check.That(map.World).IsEqualTo(world); }
public void Dispose_Should_not_throw_When_world_already_disposed() { World world = new World(4); EntityMultiMap <int> set = world.GetEntities().AsMultiMap <int>(); world.Dispose(); Check.ThatCode(set.Dispose).DoesNotThrow(); }
public void This_Should_return_entities() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Entity entity = world.CreateEntity(); entity.Set(42); Check.That(map[42].ToArray()).ContainsExactly(entity); }
public void TrimExcess_Should_fit_storage_to_number_of_entities() { using World world = new(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); world.CreateEntity().Set(42); Check.That(((Array)typeof(EntityMultiMap <int>).GetField("_mapping", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(map)).Length).IsNotEqualTo(2); map.TrimExcess(); Check.That(((Array)typeof(EntityMultiMap <int>).GetField("_mapping", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(map)).Length).IsEqualTo(2); }
public void ContainsKey_Should_return_weither_a_key_is_in_or_not() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Entity entity = world.CreateEntity(); Check.That(map.ContainsKey(42)).IsFalse(); entity.Set(42); Check.That(map.ContainsKey(42)).IsTrue(); }
public void Count_Should_return_the_number_of_entities() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().AsMultiMap <int>(); Entity entity = world.CreateEntity(); Check.That(map.Count(42)).IsZero(); entity.Set(42); Check.That(map.Count(42)).IsEqualTo(1); }
private HierarchyLevelSetter(World world) { _map = world.GetEntities().AsMultiMap <Parent>(); _addedSubscription = world.SubscribeComponentAdded <Parent>(OnAdded); _changedSubscription = world.SubscribeComponentChanged <Parent>(OnChanged); _removedSubscription = world.SubscribeComponentRemoved <Parent>(OnRemoved); using EntitySet entities = world.GetEntities().With <Parent>().AsSet(); foreach (ref readonly Entity entity in entities.GetEntities()) { OnAdded(entity, entity.Get <Parent>()); } }
public void EntityAdded_Should_be_called() { using World world = new(); using EntityMultiMap <int> set = world.GetEntities().AsMultiMap <int>(); Entity addedEntity = default; set.EntityAdded += (in Entity e) => addedEntity = e; Entity entity = world.CreateEntity(); entity.Set(42); Check.That(entity).IsEqualTo(addedEntity); }
public void Complete_Should_empty_When_reative() { using World world = new World(); using EntityMultiMap <int> map = world.GetEntities().WhenAddedEither <int>().AsMultiMap <int>(); Entity entity = world.CreateEntity(); entity.Set(42); Check.That(map.TryGetEntities(42, out ReadOnlySpan <Entity> result)).IsTrue(); Check.That(result.ToArray()).ContainsExactly(entity); map.Complete(); Check.That(map.TryGetEntities(42, out result)).IsFalse(); entity.Set(1337); Check.That(map.TryGetEntities(42, out result)).IsFalse(); }
internal KeyEnumerable(EntityMultiMap <TKey> map) { _map = map; }
public System(EntityMultiMap <T> map) : base(map) { }
public EntityMultiMapDebugView(EntityMultiMap <TKey> multiMap) { _multiMap = multiMap; }