예제 #1
0
        protected override void Execute(World world, LateUpdateMessage message)
        {
            var removeBullets = Task.Run(() =>
            {
                for (var i = 0; i < bullets.Length; i++)
                {
                    var pos = bullets.Positions[i].Vector;
                    if (pos.X < -1.2f || pos.X > 1.2f || pos.Y > 2.0f || pos.Y < -2.0f)
                    {
                        oobBullets.Add(bullets.Entities[i]);
                    }
                }
                deaths.AddRange(oobBullets);
                oobBullets.Clear();
            });

            var removeEnemies = Task.Run(() =>
            {
                for (var i = 0; i < enemies.Length; i++)
                {
                    var pos = enemies.Positions[i].Vector;
                    if (pos.Y < -2f)
                    {
                        oobEnemies.Add(enemies.Entities[i]);
                    }
                }
                deaths.AddRange(oobEnemies);
                oobEnemies.Clear();
            });

            Task.WaitAll(removeBullets, removeEnemies);
        }
예제 #2
0
        protected override void Execute(World world, UpdateMessage message)
        {
            if (data.Length == 0)
            {
                return;
            }
            var partitioner = Partitioner.Create(0, data.Length);

            Parallel.ForEach(partitioner, () => new List <Entity>(),
                             (partition, state, list) =>
            {
                for (var i = partition.Item1; i < partition.Item2; i++)
                {
                    data.Ttls[i].Value -= message.DeltaTime;
                    if (data.Ttls[i].Value <= 0)
                    {
                        list.Add(data.Entities[i]);
                    }
                }
                return(list);
            }, list => entitiesBag.Add(list));

            while (entitiesBag.TryTake(out var list))
            {
                deadEntities.AddRange(list);
            }
        }