protected override void OnUpdate()
        {
            var balls = GetComponentDataFromEntity <BallData>();
            var overlappingEntitiesBuffer = GetBufferFromEntity <OverlappingDynamicBufferElement>(true);
            var contactsBuffer            = GetBufferFromEntity <ContactBufferElement>();
            var marker = PerfMarker;

            Entities
            .WithName("DynamicNarrowPhaseJob")
            .WithNativeDisableParallelForRestriction(balls)
            .WithNativeDisableParallelForRestriction(contactsBuffer)
            .WithReadOnly(overlappingEntitiesBuffer)
            .ForEach((Entity entity, ref BallData ball, ref CollisionEventData collEvent) => {
                // don't play with frozen balls
                if (ball.IsFrozen)
                {
                    return;
                }

                marker.Begin();

                var contacts            = contactsBuffer[entity];
                var overlappingEntities = overlappingEntitiesBuffer[entity];
                for (var k = 0; k < overlappingEntities.Length; k++)
                {
                    var collBallEntity = overlappingEntities[k].Value;
                    var collBall       = balls[collBallEntity];

                    var newCollEvent = new CollisionEventData();
                    var newTime      = BallCollider.HitTest(ref newCollEvent, ref collBall, in ball, collEvent.HitTime);

                    SaveCollisions(ref collEvent, ref newCollEvent, ref contacts, in collBallEntity, newTime);

                    // write back
                    balls[collBallEntity] = collBall;
                }

                marker.End();
            }).Run();
        }
 private static void SaveCollisions(ref CollisionEventData collEvent, ref CollisionEventData newCollEvent,
                                    ref DynamicBuffer <ContactBufferElement> contacts, in Entity ballEntity, float newTime)
 public static void Collide(ref BallData ball, ref NativeQueue <EventData> .ParallelWriter events,
                            ref CollisionEventData collEvent, ref BumperRingAnimationData ringData, ref BumperSkirtAnimationData skirtData,
                            in Entity ballEntity, in Collider collider, in BumperStaticData data, ref Random random)
 /// <summary>
 /// Collides without triggering the animation, which is what the
 /// <see cref="Poly3DCollider"/> does.
 /// </summary>
 public static void Collide(ref BallData ball, ref NativeQueue <EventData> .ParallelWriter events,
                            ref CollisionEventData collEvent, ref DynamicBuffer <BallInsideOfBufferElement> insideOfs, in Collider coll)
Exemplo n.º 5
0
 public static unsafe float HitTest(ref Collider coll, ref CollisionEventData collEvent,
                                    ref DynamicBuffer <BallInsideOfBufferElement> insideOf, in BallData ball, float dTime)
 public ContactBufferElement(Entity colliderEntity, CollisionEventData collEvent)
 {
     CollisionEvent = collEvent;
     ColliderId     = -1;
     ColliderEntity = colliderEntity;
 }
 public ContactBufferElement(int colliderId, CollisionEventData collEvent)
 {
     CollisionEvent = collEvent;
     ColliderId     = colliderId;
     ColliderEntity = Entity.Null;
 }
Exemplo n.º 8
0
 public ContactBufferElement(Entity ballEntity, CollisionEventData collEvent)
 {
     BallEntity = ballEntity;
     CollEvent  = collEvent;
 }