public void RemoveEntityDoesntRemoveFromListBeforeCommit()
        {
            var e = new RuntimeEntityService(Mock.Of <IEventDispatcher>(), Mock.Of <ILogger>());

            var entity = e.CreateEntity(new IComponent[0]);

            e.CommitAdded();
            e.RemoveEntity(entity);

            e.Entities.Should().Contain(entity);
        }
        public void AddEntityAddsEntityToListAfterCommit()
        {
            var e = new RuntimeEntityService(Mock.Of <IEventDispatcher>(), Mock.Of <ILogger>());

            var entity = e.CreateEntity(new IComponent[0]);

            e.CommitAdded();

            e.Entities.Should().Contain(entity);
            e.AddedEntities.Should().NotContain(entity);
            e.GetEntity(entity.Id).Should().Be(entity);
        }
        public void RemoveEntityClearsListAfterCommit()
        {
            var e = new RuntimeEntityService(Mock.Of <IEventDispatcher>(), Mock.Of <ILogger>());

            var entity = e.CreateEntity(new IComponent[0]);

            e.CommitAdded();
            e.RemoveEntity(entity);
            e.CommitRemoved();

            e.RemovedEntities.Should().BeEmpty();
        }
        public void RemoveEntityRemovesFromListAfterCommit()
        {
            var e = new RuntimeEntityService(Mock.Of <IEventDispatcher>(), Mock.Of <ILogger>());

            var entity = e.CreateEntity(new IComponent[0]);

            e.CommitAdded();
            e.RemoveEntity(entity);
            e.CommitRemoved();

            e.Entities.Should().NotContain(entity);
            e.GetEntity(entity.Id).Should().BeNull();
        }
Exemplo n.º 5
0
        public void Synchronize()
        {
            if (_state != States.AwaitingSync)
            {
                throw new InvalidOperationException(
                          $"RuntimeEngine cannot Synchronize() while while in state `{_state}`");
            }

            // Add all the "Added" entities to the main entity list.
            EntityService.CommitAdded();

            // Commit all changes to entities.
            // TODO: We want to have the possibility of modifying a component multiple times during a frame
            EntityService.CommitDirty();

            _state = States.Idle;
        }
        public void CheckIdProviderDoesntOverrideExistingId()
        {
            var entityService = new RuntimeEntityService(Mock.Of <IEventDispatcher>(),
                                                         Mock.Of <ILogger>(),
                                                         new RuntimeEntityTemplateProvider(new[] { new EntityTemplate("Test", new IComponent[0]) }),
                                                         new[]
            {
                new EngineEntity(0, new IComponent[0], Mock.Of <IEventDispatcher>()),
                new EngineEntity(1, new IComponent[0], Mock.Of <IEventDispatcher>()),
                new EngineEntity(5, new IComponent[0], Mock.Of <IEventDispatcher>())
            });

            // Create new entity
            entityService.CreateEntity("Test");

            // Commit the added entities
            entityService.CommitAdded();

            entityService.Entities.Select(p => p.Id).Should().OnlyHaveUniqueItems("Entity IDs need to be unique.");
        }