Пример #1
0
        public void AddEntityDoesntAddToListBeforeCommit()
        {
            var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(), Mock.Of<ILogger>());

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

            e.Entities.Should().NotContain(entity);
            e.AddedEntities.Should().Contain(entity);
        }
Пример #2
0
        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();
        }
Пример #3
0
        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);
        }
Пример #4
0
        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();
        }
Пример #5
0
        public RuntimeEngine(RuntimeEntityService entityService, ISystemManager systemManager, EventQueue eventQueue, ILogger logger)
        {
            AddEntityAccessGate = new AccessGate();
            EventQueue = eventQueue;
            _logger = logger;
            EntityService = entityService;
            EntityService.AddEntityAccessGate = AddEntityAccessGate;
            SystemManager = systemManager;
            SystemUpdateScheduler = new SystemUpdateScheduler(SystemManager.Systems);

            foreach (var updateBurst in SystemUpdateScheduler.UpdateBursts)
            {
                _logger.Info($"Update Burst: {string.Join(", ", updateBurst.Systems.Select(p => p.System.Name))}");
            }

            // Add any entities that are already loaded into the engine.
            SystemManager.AddEntities(entityService.Entities);
        }
Пример #6
0
        public void RemoveEntityPostsEvent()
        {
            var mock = new Mock<IEventDispatcher>();
            
            var e = new RuntimeEntityService(mock.Object, Mock.Of<ILogger>());

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

            mock.Verify(p => p.Post(It.IsAny<EntityAdded>()));
        }
Пример #7
0
        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.");
        }
Пример #8
0
        public void CreatesEntityFromTemplateSetsCorrectPrototype()
        {
            var mock = new Mock<IEntityTemplateProvider>();
            mock.Setup((c) => c.Get("Test")).Returns(new EntityTemplate("Test", new IComponent[] {}));

            var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(),
                Mock.Of<ILogger>(), mock.Object);

            var entity = e.CreateEntity("Test");

            (entity as EngineEntity).Prototype.Should().Be("Test");
        }
Пример #9
0
        public void CreatesEntityFromTemplateWithCorrectComponents()
        {
            var mock = new Mock<IEntityTemplateProvider>();
            mock.Setup((c) => c.Get("Test")).Returns(new EntityTemplate("Test", new IComponent[]
            {
                new SimpleComponent(), new OtherSimpleComponent()
            }));

            var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(),
                Mock.Of<ILogger>(), mock.Object);

            var entity = e.CreateEntity("Test");

            entity.HasComponent<ISimpleComponent>().Should().BeTrue();
            entity.HasComponent<IOtherSimpleComponent>().Should().BeTrue();
        }
Пример #10
0
        public void ThrowsIfCreateEntityFromTemplateCalledWithNoTemplateProvider()
        {
            var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(),
                Mock.Of<ILogger>());

            Action act = () => e.CreateEntity("Test");
            act.ShouldThrow<InvalidOperationException>();
        }
Пример #11
0
        public void EnsureAddEntityThrowsWhenGateLocked()
        {
            var mock = new Mock<IAccessGate>();
            mock.Setup(gate => gate.TryEnter()).Returns(false);

            var e = new RuntimeEntityService(Mock.Of<IEventDispatcher>(),
                Mock.Of<ILogger>());
            e.AddEntityAccessGate = mock.Object;

            Action act = () => e.CreateEntity(new IComponent[0]);
            act.ShouldThrow<InvalidOperationException>();
        }