<commit_before>﻿//=======================================================================
// Copyright (c) 2015 <NAME>
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================
using UnityEngine;
using System.Collections;

namespace Lockstep
{
    public class CollisionPair
    {
        public LSBody Body1;
        public LSBody Body2;
        private long CacheSqrDistance;
        private CollisionType LeCollisionType;
        public bool IsColliding;
        private bool DoPhysics = true;
        public bool Active;
        public uint PartitionVersion;
        public static long DistX;
        public static long DistY;
        public static long PenetrationX;
        public static long PenetrationY;
        public static CollisionPair CurrentCollisionPair;

        bool IsValid { get; set; }

        public void Initialize(LSBody b1, LSBody b2)
        {

            if (b1 == b2)
            {
                Debug.Log("boom: " + b1.ID + ", " + b2.ID);
            }
            IsValid = PhysicsManager.RequireCollisionPair(b1, b2);

            PartitionVersion = 0;
            Body1 = b1;
            Body2 = b2;

            IsColliding = false;
            DistX = 0;
            DistY = 0;
            PenetrationX = 0;
            PenetrationY = 0;

            CacheSqrDistance = b1.Radius + b2.Radius;
            CacheSqrDistance *= CacheSqrDistance;
            if (!IsValid)
                return;

            LeCollisionType = CollisionType.None;
            if (Body1.Shape == ColliderType.None || Body2.Shape == ColliderType.None)
            {
            } else if (Body1.Shape == ColliderType.Circle)
            {
                if (Body2.Shape == ColliderType.Circle)
                {
                    LeCollisionType = CollisionType.Circle_Circle;
                } else if (Body2.Shape == ColliderType.AABox)
                {
                    LeCollisionType = CollisionType.Circle_AABox;

                } else if (Body2.Shape == ColliderType.Polygon)
                {
                    LeCollisionType = CollisionType.Circle_Polygon;
                }
            } else if (Body1.Shape == ColliderType.AABox)
            {
                if (Body2.Shape == ColliderType.Circle)
                {
                    LeCollisionType = CollisionType.Circle_AABox;
                } else if (Body2.Shape == ColliderType.AABox)
                {
                    LeCollisionType = CollisionType.AABox_AABox;
                } else if (Body2.Shape == ColliderType.Polygon)
                {
                    LeCollisionType = CollisionType.AABox_Polygon;
                }
            } else if (Body1.Shape == ColliderType.Polygon)
            {
                if (Body2.Shape == ColliderType.Circle)
                {
                    LeCollisionType = CollisionType.Circle_Polygon;
                } else if (Body2.Shape == ColliderType.AABox)
                {
                    LeCollisionType = CollisionType.AABox_Polygon;
                } else if (Body2.Shape == ColliderType.Polygon)
                {
                    LeCollisionType = CollisionType.Polygon_Polygon;
                }
            }

            DoPhysics = ((Body1.IsTrigger || Body2.IsTrigger) == false);
            if (DoPhysics)
            {

            }
            Active = true;
        }

        public void Deactivate()
        {
            Active = false;
        }

        static long dist, depth;

        private void DistributeCollision()
        {

            if (Body1.OnContact.IsNotNull())
            {
                Body1.OnContact(Body2);
            }
            if (Body2.OnContact.IsNotNull())
            {
                Body2.OnContact(Body1);
            }

			if (Body1.IsTrigger || Body2.IsTrigger)
				return;
			
            switch (LeCollisionType)
            {
                case CollisionType.Circle_Circle:
                    DistX = Body1._position.x - Body2._position.x;
                    DistY = Body1._position.y - Body2._position.y;
                    dist = FixedMath.Sqrt((DistX * DistX + DistY * DistY) >> FixedMath.SHIFT_AMOUNT);
                        
                    if (dist == 0)
                    {
                        const int randomMax = (int)((long)int.MaxValue % (FixedMath.One / 64));
                        Body1._position.x += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body1._position.y += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body1.PositionChanged = true;
                        Body2._position.x += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body2._position.y += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body2.PositionChanged = true;
                        return;
                    }


                    depth = (Body1.Radius + Body2.Radius - dist);

                    if (depth <= 0)
                    {
                        return;
                    }
                    DistX = (DistX * depth / dist) / 2L;
                    DistY = (DistY * depth / dist) / 2L;

                    const bool applyVelocity = false;
                    //Resolving collision
                    if (Body1.Immovable || (Body2.Immovable == false && Body1.Priority > Body2.Priority))
                    {
                        Body2._position.x -= DistX;
                        Body2._position.y -= DistY;
                        Body2.PositionChanged = true;
                        if (applyVelocity)
                        {
                            Body2._velocity.x -= DistX;
                            Body2.VelocityChanged = true;
                        }
                    } else if (Body2.Immovable || Body2.Priority > Body1.Priority)
                    {

                        Body1._position.x += DistX;
                        Body1._position.y += DistY;
                        Body1.PositionChanged = true;<commit_msg>Ignore collision of a destroyed immovable agent<commit_after>﻿//=======================================================================
// Copyright (c) 2015 <NAME>
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at
// http://opensource.org/licenses/MIT)
//=======================================================================
using UnityEngine;
using System.Collections;

namespace Lockstep
{
    public class CollisionPair
    {
        public LSBody Body1;
        public LSBody Body2;
        private long CacheSqrDistance;
        private CollisionType LeCollisionType;
        public bool IsColliding;
        private bool DoPhysics = true;
        public bool Active;
        public uint PartitionVersion;
        public static long DistX;
        public static long DistY;
        public static long PenetrationX;
        public static long PenetrationY;
        public static CollisionPair CurrentCollisionPair;

        bool IsValid { get; set; }

        public void Initialize(LSBody b1, LSBody b2)
        {

            if (b1 == b2)
            {
                Debug.Log("boom: " + b1.ID + ", " + b2.ID);
            }
            IsValid = PhysicsManager.RequireCollisionPair(b1, b2);

            PartitionVersion = 0;
            Body1 = b1;
            Body2 = b2;

            IsColliding = false;
            DistX = 0;
            DistY = 0;
            PenetrationX = 0;
            PenetrationY = 0;

            CacheSqrDistance = b1.Radius + b2.Radius;
            CacheSqrDistance *= CacheSqrDistance;
            if (!IsValid)
                return;

            LeCollisionType = CollisionType.None;
            if (Body1.Shape == ColliderType.None || Body2.Shape == ColliderType.None)
            {
            } else if (Body1.Shape == ColliderType.Circle)
            {
                if (Body2.Shape == ColliderType.Circle)
                {
                    LeCollisionType = CollisionType.Circle_Circle;
                } else if (Body2.Shape == ColliderType.AABox)
                {
                    LeCollisionType = CollisionType.Circle_AABox;

                } else if (Body2.Shape == ColliderType.Polygon)
                {
                    LeCollisionType = CollisionType.Circle_Polygon;
                }
            } else if (Body1.Shape == ColliderType.AABox)
            {
                if (Body2.Shape == ColliderType.Circle)
                {
                    LeCollisionType = CollisionType.Circle_AABox;
                } else if (Body2.Shape == ColliderType.AABox)
                {
                    LeCollisionType = CollisionType.AABox_AABox;
                } else if (Body2.Shape == ColliderType.Polygon)
                {
                    LeCollisionType = CollisionType.AABox_Polygon;
                }
            } else if (Body1.Shape == ColliderType.Polygon)
            {
                if (Body2.Shape == ColliderType.Circle)
                {
                    LeCollisionType = CollisionType.Circle_Polygon;
                } else if (Body2.Shape == ColliderType.AABox)
                {
                    LeCollisionType = CollisionType.AABox_Polygon;
                } else if (Body2.Shape == ColliderType.Polygon)
                {
                    LeCollisionType = CollisionType.Polygon_Polygon;
                }
            }

            DoPhysics = ((Body1.IsTrigger || Body2.IsTrigger) == false);
            if (DoPhysics)
            {

            }
            Active = true;
        }

        public void Deactivate()
        {
            Active = false;
        }

        static long dist, depth;

        private void DistributeCollision()
        {

            if (Body1.OnContact.IsNotNull())
            {
                Body1.OnContact(Body2);
            }
            if (Body2.OnContact.IsNotNull())
            {
                Body2.OnContact(Body1);
            }

			if (Body1.IsTrigger || Body2.IsTrigger)
				return;
			
            switch (LeCollisionType)
            {
                case CollisionType.Circle_Circle:
                    DistX = Body1._position.x - Body2._position.x;
                    DistY = Body1._position.y - Body2._position.y;
                    dist = FixedMath.Sqrt((DistX * DistX + DistY * DistY) >> FixedMath.SHIFT_AMOUNT);
                        
                    if (dist == 0)
                    {
                        const int randomMax = (int)((long)int.MaxValue % (FixedMath.One / 64));
                        Body1._position.x += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body1._position.y += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body1.PositionChanged = true;
                        Body2._position.x += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body2._position.y += LSUtility.GetRandom(randomMax) - randomMax / 2;
                        Body2.PositionChanged = true;
                        return;
                    }


                    depth = (Body1.Radius + Body2.Radius - dist);

                    if (depth <= 0)
                    {
                        return;
                    }
                    DistX = (DistX * depth / dist) / 2L;
                    DistY = (DistY * depth / dist) / 2L;

                    const bool applyVelocity = false;
                    //Resolving collision
                    if (Body1.Immovable && Body1.Agent.IsActive || (Body2.Immovable == false && Body1.Priority > Body2.Priority))
                    {
                        Body2._position.x -= DistX;
                        Body2._position.y -= DistY;
                        Body2.PositionChanged = true;
                        if (applyVelocity)
                        {
                            Body2._velocity.x -= DistX;
                            Body2.VelocityChanged = true;
                        }
                    } else if (Body2.Immovable || Body2.Priority > Body1.Priority)
                    {

                        Body1._position.x += DistX;
                        Body1._position.y += DistY;
                        Body1.PositionChanged = true;
{'fraction_non_alphanumeric': 0.1054504285945334, 'fraction_numerical': 0.013989972505256349, 'mean_word_length': 1.2198887093879016, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2357872', 'n_tokens_mistral': 3371, 'n_tokens_neox': 3069, 'n_words': 634}