Exemple #1
0
        public static void PrepareContacts()
        {
            for (int i = 0; i < _contactCount; i++)
            {
                PContactExport2D export = contactExports[i];

                //some
                if (export.id == 0)
                {
                    continue;
                }

                PContact2D c;

                if (contactDictionary.ContainsKey(export.id))
                {
                    c = contactDictionary[export.id];
                }
                else
                {
                    c = new PContact2D(export.id);
                    contactDictionary[export.id] = c;
                }

                c.Update(
                    contactPtrs[i],
                    export.count,
                    export.relativeVelocity,
                    export.isTrigger
                    );

                AddAllContactWrapper(c);
            }
        }
Exemple #2
0
        static void AddAllContactWrapper(PContact2D contact)
        {
            _allContactWrapperEnd.contact = contact;

            if (_allContactWrapperEnd.next == null)
            {
                _allContactWrapperEnd.next = new PContact2DWrapper();
            }
            _allContactWrapperEnd = _allContactWrapperEnd.next;

            _allContactCount++;
        }
Exemple #3
0
        static void AddExitContactWrapper(PContact2D contact)
        {
            _exitContactWrapperEnd.contact = contact;

            if (_exitContactWrapperEnd.next == null)
            {
                _exitContactWrapperEnd.next = new PContact2DWrapper();
            }
            _exitContactWrapperEnd = _exitContactWrapperEnd.next;

            _exitContactCount++;
        }
Exemple #4
0
        public static void OnContactExitCallBack(IntPtr contactPtr, UInt32 contactID)
        {
            PContact2D c;

            if (contactDictionary.ContainsKey(contactID))
            {
                //already has this contact
                //the native contact for this body pair was created and destroyed before
                c       = contactDictionary[contactID];
                c.state = ContactState.Exit;
            }
            else
            {
                //first time
                c       = new PContact2D(contactID);
                c.state = ContactState.Enter;
                contactDictionary[contactID] = c;
            }

            AddExitContactWrapper(c);
            //Debug.Log("Exit contact");
        }
Exemple #5
0
        public static void ExcuteUserCallbacks(Fix64 time)
        {
            //call contact exit callback

            PContact2DWrapper currentWrapper = _exitContactWrapperHead;

            for (int i = 0; i < _exitContactCount; i++)
            {
                PContact2D contact = currentWrapper.contact;

                PBody2D body1 = bodySortedList[contact.Body1ID];
                PBody2D body2 = bodySortedList[contact.Body2ID];

                if (contact.IsTrigger)
                {
                    body1.RigidBody.OnParallelTriggerExit(body2.RigidBody);
                    body2.RigidBody.OnParallelTriggerExit(body1.RigidBody);
                }
                else
                {
                    _tempCollision.SetContact(contact, body2.RigidBody);
                    body1.RigidBody.OnParallelCollisionExit(_tempCollision);

                    _tempCollision.SetContact(contact, body1.RigidBody);
                    body2.RigidBody.OnParallelCollisionExit(_tempCollision);
                }

                contact.state  = ContactState.Inactive;
                currentWrapper = currentWrapper.next;
            }

            //call contact stay callback
            currentWrapper = _allContactWrapperHead;

            for (int i = 0; i < _allContactCount; i++)
            {
                PContact2D contact = currentWrapper.contact;

                if (contact.state == ContactState.Active)
                {
                    PBody2D body1 = bodySortedList[contact.Body1ID];
                    PBody2D body2 = bodySortedList[contact.Body2ID];

                    if (contact.IsTrigger)
                    {
                        body1.RigidBody.OnParallelTriggerStay(body2.RigidBody);
                        body2.RigidBody.OnParallelTriggerStay(body1.RigidBody);
                    }
                    else
                    {
                        _tempCollision.SetContact(contact, body2.RigidBody);
                        body1.RigidBody.OnParallelCollisionStay(_tempCollision);

                        _tempCollision.SetContact(contact, body1.RigidBody);
                        body2.RigidBody.OnParallelCollisionStay(_tempCollision);
                    }
                }

                currentWrapper = currentWrapper.next;
            }

            //call contact enter callback
            currentWrapper = _enterContactWrapperHead;

            for (int i = 0; i < _enterContactCount; i++)
            {
                PContact2D contact = currentWrapper.contact;
                PBody2D    body1   = bodySortedList[contact.Body1ID];
                PBody2D    body2   = bodySortedList[contact.Body2ID];

                if (contact.IsTrigger)
                {
                    body1.RigidBody.OnParallelTriggerEnter(body2.RigidBody);
                    body2.RigidBody.OnParallelTriggerEnter(body1.RigidBody);
                }
                else
                {
                    _tempCollision.SetContact(contact, body2.RigidBody);
                    body1.RigidBody.OnParallelCollisionEnter(_tempCollision);

                    _tempCollision.SetContact(contact, body1.RigidBody);
                    body2.RigidBody.OnParallelCollisionEnter(_tempCollision);
                }

                contact.state  = ContactState.Active;
                currentWrapper = currentWrapper.next;
            }
        }
Exemple #6
0
 internal void SetContact(PContact2D contact, IParallelRigidbody2D rigidBody)
 {
     _contact       = contact;
     otherRigidbody = rigidBody;
 }