예제 #1
0
 public void Setup()
 {
     _world    = new World();
     _entity   = _world.CreateEntity();
     _set      = _world.GetEntities().With <bool>().With <int>().AsSet();
     _recorder = new EntityCommandRecorder(1024);
 }
        public void Shoud_throw_When_no_more_space()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(16);

            recorder.CreateEntity();

            Check.ThatCode(() => recorder.CreateEntity()).Throws <InvalidOperationException>();
        }
예제 #3
0
        public SoLoudStandardPlayerSystem(WorldCollection collection) : base(collection)
        {
            DependencyResolver.Add(() => ref playerManager);
            DependencyResolver.Add(() => ref resourceManager);
            DependencyResolver.Add(() => ref worldTime);

            AddDisposable(recorder      = new EntityCommandRecorder());
            AddDisposable(controllerSet = collection.Mgr.GetEntities()
                                          .With <StandardAudioPlayerComponent>()
                                          .AsSet());
        }
        public void Should_work_in_multithread()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(8, int.MaxValue);
            using World world = new World();

            Enumerable.Range(0, 100000).AsParallel().ForAll(_ => recorder.CreateEntity());

            recorder.Execute(world);

            Check.That(world.Count()).IsEqualTo(100000);
        }
        public void Clear_Should_clear_recorded_command()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder();
            using World world = new World();

            recorder.CreateEntity();
            recorder.Clear();
            recorder.Execute(world);

            Check.That(world.GetAllEntities().Count()).IsZero();
        }
예제 #6
0
        public VoxelGridMesher(EntityCommandRecorder commandRecorder, World world, VoxelTypes types, GraphicsDevice device, IParallelRunner runner) : base(world, runner)
        {
            _commandRecorder = commandRecorder;
            _types           = types;
            _device          = device;

            _vertices     = new ThreadLocal <PooledList <VertexPositionTextureNormal> >(() => new PooledList <VertexPositionTextureNormal>());
            _indices      = new ThreadLocal <PooledList <ushort> >(() => new PooledList <ushort>());
            _transIndices = new ThreadLocal <PooledList <ushort> >(() => new PooledList <ushort>());
            _lights       = new ThreadLocal <PooledList <float> >(() => new PooledList <float>());
        }
예제 #7
0
 public DialogScript(ITagContainer diContainer) : base(diContainer, CreateEntityContainer)
 {
     World.SetMaxCapacity <components.DialogState>(1);
     db       = diContainer.GetTag <MappedDB>();
     ui       = diContainer.GetTag <UI>();
     scene    = diContainer.GetTag <Scene>();
     game     = diContainer.GetTag <Game>();
     savegame = diContainer.GetTag <zzio.Savegame>();
     recorder = diContainer.GetTag <EntityCommandRecorder>();
     startDialogDisposable = World.Subscribe <messages.StartDialog>(HandleStartDialog);
     removedDisposable     = World.SubscribeComponentRemoved <components.DialogState>(HandleDialogStateRemoved);
 }
        public void Set_Should_set__blittable_component_on_created_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            EntityRecord record = recorder.CreateEntity();

            record.Set(true);

            recorder.Execute(world);

            Check.That(world.Single().Get <bool>()).IsTrue();
        }
        public void Dispose_Should_dispose_created_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            EntityRecord record = recorder.CreateEntity();

            record.Dispose();

            recorder.Execute(world);

            Check.That(world.Count()).IsEqualTo(0);
        }
        public void Disable_Should_disable_created_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            EntityRecord record = recorder.CreateEntity();

            record.Disable();

            recorder.Execute(world);

            Check.That(world.Single().IsEnabled()).IsFalse();
        }
        public void Execute_Should_clear_recorded_command_after_executing()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder();
            using World world = new World();

            recorder.CreateEntity();
            recorder.Execute(world);

            Check.That(world.GetAllEntities().Count()).IsEqualTo(1);

            recorder.Execute(world);

            Check.That(world.GetAllEntities().Count()).IsEqualTo(1);
        }
        public void Enable_Should_enable_created_entity()
        {
            using (EntityCommandRecorder recorder = new EntityCommandRecorder(1024))
                using (World world = new World())
                {
                    EntityRecord record = recorder.CreateEntity();
                    record.Disable();
                    record.Enable();

                    recorder.Execute(world);

                    Check.That(world.GetAllEntities().Single().IsEnabled()).IsTrue();
                }
        }
예제 #13
0
        public Scene(string name, World world, EntityCommandRecorder commandRecorder)
        {
            Name  = name;
            World = world;

            RendererSystems  = new List <ISystem <RenderingContext> >();
            PreLogicSystems  = new List <IPreSystem <double> >();
            LogicSystems     = new List <ISystem <double> >();
            PostLogicSystems = new List <IPostSystem <double> >();

            CommandRecorder = commandRecorder;

            _subscriptions = new List <IDisposable>();
        }
        public void DisableT_Should_disable_component_of_type_T_on_created_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            EntityRecord record = recorder.CreateEntity();

            record.Set(true);
            record.Disable <bool>();

            recorder.Execute(world);

            Check.That(world.Single().IsEnabled <bool>()).IsFalse();
        }
        public void Remove_Should_remove_component_on_created_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            EntityRecord record = recorder.CreateEntity();

            record.Set(true);
            record.Remove <bool>();

            recorder.Execute(world);

            Check.That(world.Single().Has <bool>()).IsFalse();
        }
        public void Set_Should_set__reference_component_on_created_entity()
        {
            object o = new object();

            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            EntityRecord record = recorder.CreateEntity();

            record.Set(o);

            recorder.Execute(world);

            Check.That(world.Single().Get <object>()).IsEqualTo(o);
        }
        public void Disable_Should_disable_recorded_entity()
        {
            using (EntityCommandRecorder recorder = new EntityCommandRecorder(1024))
                using (World world = new World())
                {
                    Entity entity = world.CreateEntity();

                    EntityRecord record = recorder.Record(entity);
                    record.Disable();

                    recorder.Execute(world);

                    Check.That(entity.IsEnabled()).IsFalse();
                }
        }
        public void CreateEntity_Should_create_an_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            recorder.CreateEntity(world);
            recorder.CreateEntity(world);
            recorder.CreateEntity(world);
            recorder.CreateEntity(world);
            recorder.CreateEntity(world);

            recorder.Execute();

            Check.That(world.Count()).IsEqualTo(5);
        }
        public void Shoud_throw_When_no_more_space()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(8, 16);

            Check.That(recorder.Size).IsZero();
            Check.That(recorder.Capacity).IsEqualTo(8);
            Check.That(recorder.MaxCapacity).IsEqualTo(16);

            recorder.CreateEntity();

            Check.That(recorder.Size).IsEqualTo(9);
            Check.That(recorder.Capacity).IsEqualTo(recorder.MaxCapacity);

            Check.ThatCode(() => recorder.CreateEntity()).Throws <InvalidOperationException>();
        }
        public void SetAsParentOf_Should_set_created_entity_as_child()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            Entity child = world.CreateEntity();

            EntityRecord record = recorder.CreateEntity();

            record.SetAsParentOf(recorder.Record(child));

            recorder.Execute(world);

            Check.That(world.Skip(1).Single().GetChildren()).Contains(child);
        }
        public void Set_Should_set__blittable_component_on_recorded_entity()
        {
            using (EntityCommandRecorder recorder = new EntityCommandRecorder(1024))
                using (World world = new World())
                {
                    Entity entity = world.CreateEntity();

                    EntityRecord record = recorder.Record(entity);
                    record.Set(true);

                    recorder.Execute(world);

                    Check.That(entity.Get <bool>()).IsTrue();
                }
        }
        public void SetAsChildOf_Should_set_created_entity_as_child()
        {
            using (EntityCommandRecorder recorder = new EntityCommandRecorder(1024))
                using (World world = new World())
                {
                    Entity parent = world.CreateEntity();

                    EntityRecord record = recorder.CreateEntity();
                    record.SetAsChildOf(recorder.Record(parent));

                    recorder.Execute(world);

                    Check.That(parent.GetChildren()).Contains(world.GetAllEntities().Skip(1).Single());
                }
        }
        public void Dispose_Should_dispose_recorded_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            Entity entity = world.CreateEntity();

            EntityRecord record = recorder.Record(entity);

            record.Dispose();

            recorder.Execute(world);

            Check.That(entity.IsAlive).IsFalse();
        }
        public void SetAsChildOf_Should_set_recorded_entity_as_child()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            Entity parent = world.CreateEntity();
            Entity entity = world.CreateEntity();

            EntityRecord record = recorder.Record(entity);

            record.SetAsChildOf(recorder.Record(parent));

            recorder.Execute(world);

            Check.That(parent.GetChildren()).Contains(entity);
        }
        public void DisableT_Should_disable_component_of_type_T_on_recorded_entity()
        {
            using (EntityCommandRecorder recorder = new EntityCommandRecorder(1024))
                using (World world = new World())
                {
                    Entity entity = world.CreateEntity();
                    entity.Set(true);

                    EntityRecord record = recorder.Record(entity);
                    record.Disable <bool>();

                    recorder.Execute(world);

                    Check.That(entity.IsEnabled <bool>()).IsFalse();
                }
        }
        public void Remove_Should_remove_component_on_recorded_entity()
        {
            using (EntityCommandRecorder recorder = new EntityCommandRecorder(1024))
                using (World world = new World())
                {
                    Entity entity = world.CreateEntity();
                    entity.Set(true);

                    EntityRecord record = recorder.Record(entity);
                    record.Remove <bool>();

                    recorder.Execute(world);

                    Check.That(entity.Has <bool>()).IsFalse();
                }
        }
        public void SetAsParentOf_Should_set_recorded_entity_as_parent()
        {
            using (EntityCommandRecorder recorder = new EntityCommandRecorder(1024))
                using (World world = new World())
                {
                    Entity child  = world.CreateEntity();
                    Entity entity = world.CreateEntity();

                    EntityRecord record = recorder.Record(entity);
                    record.SetAsParentOf(recorder.Record(child));

                    recorder.Execute(world);

                    Check.That(entity.GetChildren()).Contains(child);
                }
        }
        public void Set_Should_set__non_blittable_component_on_created_entity()
        {
            object o = new object();

            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            EntityRecord record = recorder.CreateEntity();

            record.Set(new NonBlittable(42, o));

            recorder.Execute(world);

            Check.That(world.Single().Get <NonBlittable>().Id).IsEqualTo(42);
            Check.That(world.Single().Get <NonBlittable>().Item).IsEqualTo(o);
        }
        public void Enable_Should_enable_recorded_entity()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            Entity entity = world.CreateEntity();

            entity.Disable();

            EntityRecord record = recorder.Record(entity);

            record.Enable();

            recorder.Execute(world);

            Check.That(entity.IsEnabled()).IsTrue();
        }
        public void RemoveFromChildrenOf_Should_set_created_entity_as_child()
        {
            using EntityCommandRecorder recorder = new EntityCommandRecorder(1024);
            using World world = new World();

            Entity parent = world.CreateEntity();

            EntityRecord parentRecord = recorder.Record(parent);
            EntityRecord record       = recorder.CreateEntity();

            record.SetAsChildOf(parentRecord);
            record.RemoveFromChildrenOf(parentRecord);

            recorder.Execute(world);

            Check.That(parent.GetChildren()).IsEmpty();
        }