public static void Create(EntityManager entityManager)
        {
            var table = Object.FindObjectOfType <TableAuthoring>().Table;

            foreach (var playable in table.Playables)
            {
                playable.Init(table);
            }

            // index hittables
            var hittables  = table.Hittables.Where(hittable => hittable.IsCollidable).ToArray();
            var hitObjects = new List <HitObject>();
            var id         = 0;

            foreach (var item in hittables)
            {
                foreach (var hitObject in item.GetHitShapes())
                {
                    hitObject.SetIndex(item.Index, item.Version);
                    hitObject.Id = id++;
                    hitObject.CalcHitBBox();
                    hitObjects.Add(hitObject);
                }
            }

            // construct quad tree
            var quadTree             = new Engine.Physics.QuadTree(hitObjects, table.BoundingBox);
            var quadTreeBlobAssetRef = QuadTreeBlob.CreateBlobAssetReference(
                quadTree,
                table.GeneratePlayfieldHit(),                 // todo use `null` if separate playfield mesh exists
                table.GenerateGlassHit()
                );

            // playfield and glass need special treatment, since not part of the quad tree
            var playfieldHitObject = table.GeneratePlayfieldHit();
            var glassHitObject     = table.GenerateGlassHit();

            playfieldHitObject.Id = id++;
            glassHitObject.Id     = id;
            hitObjects.Add(playfieldHitObject);
            hitObjects.Add(glassHitObject);

            // construct collider blob
            var colliderBlob = ColliderBlob.CreateBlobAssetReference(hitObjects, playfieldHitObject.Id, glassHitObject.Id);

            // save it to entity
            var collEntity = entityManager.CreateEntity(ComponentType.ReadOnly <QuadTreeData>(), ComponentType.ReadOnly <ColliderData>());

            //DstEntityManager.SetName(collEntity, "Collision Data Holder");
            entityManager.SetComponentData(collEntity, new QuadTreeData {
                Value = quadTreeBlobAssetRef
            });
            entityManager.SetComponentData(collEntity, new ColliderData {
                Value = colliderBlob
            });

            Logger.Info("Static QuadTree initialized.");
        }
Exemple #2
0
        public static void Create(Engine.Physics.QuadTree src, ref QuadTree dest, BlobBuilder builder)
        {
            var children = builder.Allocate(ref dest.Children, 4);

            for (var i = 0; i < 4; i++)
            {
                if (src.Children[i] != null)
                {
                    ref var child = ref builder.Allocate(ref children[i]);
                    Create(src.Children[i], ref child, builder);
                }
            }
Exemple #3
0
        public static BlobAssetReference <QuadTreeBlob> CreateBlobAssetReference(Engine.Physics.QuadTree quadTree, HitPlane playfield, HitPlane glass)
        {
            using (var builder = new BlobBuilder(Allocator.Temp)) {
                ref var rootQuadTree = ref builder.ConstructRoot <QuadTreeBlob>();
                QuadTree.Create(quadTree, ref rootQuadTree.QuadTree, builder);

                if (playfield != null)
                {
                    PlaneCollider.Create(builder, playfield, ref rootQuadTree.PlayfieldCollider);
                }
                else
                {
                    ref var playfieldCollider = ref builder.Allocate(ref rootQuadTree.PlayfieldCollider);
                    playfieldCollider.Header = new ColliderHeader {
                        Type = ColliderType.None
                    };
                }