Exemplo n.º 1
0
 public void Run(EcsSystems systems)
 {
     if (_filter == null)
     {
         var world = GetWorld(systems);
         _pool1  = world.GetPool <T1> ();
         _filter = GetFilter(world);
         _thread = new TThread();
         _worker = _thread.Execute;
     }
     _thread.Init(
         _filter.GetRawEntities(),
         _pool1.GetRawDenseItems(), _pool1.GetRawSparseItems());
     SetData(systems, _thread);
     ThreadService.Run(_worker, _filter.GetEntitiesCount(), GetChunkSize(systems));
 }
Exemplo n.º 2
0
        public void Run(EcsSystems systems)
        {
            var physicsData   = systems.GetShared <PhysicsData>();
            var testersMatrix = physicsData.ContactTestersMatrix;
            var solversMatrix = physicsData.ContactSolversMatrix;

            SortBoundingBoxes();

            var bodiesEntities = bodies.GetRawEntities();
            var bodiesCount    = bodies.GetEntitiesCount();

            for (var i = 0; i < bodiesCount; ++i)
            {
                var     bodyA = bodiesEntities[i];
                ref var bboxA = ref boundingBoxes.Get(bodyA);

                for (var k = i + 1; k < bodiesCount; ++k)
                {
                    var     bodyB = bodiesEntities[k];
                    ref var bboxB = ref boundingBoxes.Get(bodyB);

                    // this bboxB and every next one cannot intersect with bboxA
                    if (bboxB.Min.X > bboxA.Max.X)
                    {
                        break;
                    }

                    // we already know that bboxes intersect on X axis, so test only Y axis
                    if (bboxA.Max.Y >= bboxB.Min.Y && bboxB.Max.Y >= bboxA.Min.Y)
                    {
                        var maskA           = bodyMasks.Get(bodyA);
                        var maskB           = bodyMasks.Get(bodyB);
                        var testerReference = testersMatrix[maskA.ShapeTypeId][maskB.ShapeTypeId];
                        var solverReference = solversMatrix[maskA.TagTypeId][maskB.TagTypeId];

                        // some shape pairs cannot be tested, some tag pairs cannot be solved
                        if (testerReference != null && solverReference != null)
                        {
                            testerReference.AddTask(bodyA, bodyB, maskA, maskB);
                        }
                    }
                }