public void GetEntities_Should_not_return_disabled_Entity() { using World world = new(); List <Entity> entities = new() { world.CreateEntity(), world.CreateEntity(), world.CreateEntity(), world.CreateEntity() }; for (int i = 0; i < entities.Count; ++i) { entities[i].Set(i); } using EntitySortedSet <int> sortedSet = world.GetEntities().AsSortedSet <int>(); Check.That(sortedSet.GetEntities().ToArray()).ContainsExactly(entities); entities[3].Disable(); Check.That(sortedSet.GetEntities().ToArray()).ContainsExactly(entities.Take(3)); entities[3].Enable(); Check.That(sortedSet.GetEntities().ToArray()).ContainsExactly(entities); }
public void GetEntities_Should_return_Entity_Sorted() { using World world = new(); List <Entity> entities = new() { world.CreateEntity(), world.CreateEntity(), world.CreateEntity(), world.CreateEntity() }; using EntitySortedSet <int> sortedSet = world.GetEntities().WithEither <int>().AsSortedSet <int>(); for (int i = 0; i < entities.Count; ++i) { entities[i].Set(-i); } Check.That(sortedSet.GetEntities().ToArray()).ContainsExactly(entities.AsEnumerable().Reverse()); for (int i = 0; i < entities.Count; ++i) { entities[i].Set(i); } Check.That(sortedSet.GetEntities().ToArray()).ContainsExactly(entities); }
public void World_Should_return_parent_world() { using World world = new(); using EntitySortedSet <int> sortedSet = world.GetEntities().AsSortedSet <int>(); Check.That(sortedSet.World).IsEqualTo(world); }
public void Dispose_Should_not_throw_When_world_already_disposed() { World world = new(); using EntitySortedSet <int> sortedSet = world.GetEntities().AsSortedSet <int>(); world.Dispose(); Check.ThatCode(sortedSet.Dispose).DoesNotThrow(); }
public void Contains_Should_return_true_When_containing_entity() { using World world = new(); Entity entity = world.CreateEntity(); entity.Set(0); using EntitySortedSet <int> sortedSet = world.GetEntities().AsSortedSet <int>(); Check.That(sortedSet.Contains(entity)).IsTrue(); }
public void Remove_While_Full_Should_Not_Crash() { using World world = new(); for (int i = 0; i < 8; i++) // choose count such that _entities is completly used { world.CreateEntity().Set(i); } using EntitySortedSet <int> set = world.GetEntities().AsSortedSet <int>(); set.GetEntities()[0].Remove <int>(); }
public void TrimExcess_Should_fit_storage_to_number_of_entities() { using World world = new(); using EntitySortedSet <int> sortedSet = world.GetEntities().AsSortedSet <int>(); world.CreateEntity().Set(0); Check.That(((Array)typeof(EntitySortedSet <int>).GetField("_mapping", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(sortedSet)).Length).IsNotEqualTo(sortedSet.Count + 1); Check.That(((Array)typeof(EntitySortedSet <int>).GetField("_entities", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(sortedSet)).Length).IsNotEqualTo(sortedSet.Count); sortedSet.TrimExcess(); Check.That(((Array)typeof(EntitySortedSet <int>).GetField("_mapping", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(sortedSet)).Length).IsEqualTo(sortedSet.Count + 1); Check.That(((Array)typeof(EntitySortedSet <int>).GetField("_entities", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(sortedSet)).Length).IsEqualTo(sortedSet.Count); }
public void EntityAdded_Should_be_called() { using World world = new(); using EntitySortedSet <int> set = world.GetEntities().AsSortedSet <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(); using EntitySortedSet <int> sortedSet = world.GetEntities().WhenAdded <int>().AsSortedSet <int>(); world.CreateEntity().Set(0); world.CreateEntity().Set(1); world.CreateEntity().Set(2); Check.That(sortedSet.Count).IsEqualTo(3); sortedSet.Complete(); Check.That(sortedSet.Count).IsZero(); }
/// <summary> /// Initialise a new instance of the <see cref="AEntitySortedSetSystem{TState, TComponent}"/> class with the given <see cref="EntitySortedSet{TComponent}"/>. /// </summary> /// <param name="sortedSet">The <see cref="EntitySet"/> on which to process the update.</param> /// <param name="useBuffer">Whether the entities should be copied before being processed.</param> /// <exception cref="ArgumentNullException"><paramref name="sortedSet"/> is null.</exception> protected AEntitySortedSetSystem(EntitySortedSet <TComponent> sortedSet, bool useBuffer = false) : this(sortedSet is null ? throw new ArgumentNullException(nameof(sortedSet)) : _ => sortedSet)
public System(EntitySortedSet <int> sortedSet, bool useBuffer = false) : base(sortedSet, useBuffer) { }
public EntitySortedSetDebugView(EntitySortedSet <TComponent> sortedSet) { _sortedSet = sortedSet; }