Esempio n. 1
0
        public virtual void UpdateJoints()
        {
            if (_info.isLocked())
            {
                return;
            }

            CCPhysicsJoint[] addCopy = new CCPhysicsJoint[_delayAddJoints.Count];

            _delayAddJoints.CopyTo(addCopy);

            _delayAddJoints.Clear();

            foreach (var joint in addCopy)
            {
                DoAddJoint(joint);
            }

            CCPhysicsJoint[] removeCopy = new CCPhysicsJoint[_delayRemoveJoints.Count];
            _delayRemoveJoints.CopyTo(removeCopy);

            _delayRemoveJoints.Clear();
            foreach (var joint in removeCopy)
            {
                DoRemoveJoint(joint);

                if (joint._destoryMark)
                {
                    //delete joint;
                }
            }
        }
        public CCPhysicsJointInfo(CCPhysicsJoint joint)
        {
            _joints = new List <cpConstraint>();
            _map    = new Dictionary <cpConstraint, CCPhysicsJointInfo>();


            _joint = joint;
        }
Esempio n. 3
0
		public CCPhysicsJointInfo(CCPhysicsJoint joint)
		{
			_joints = new List<cpConstraint>();
			_map = new Dictionary<cpConstraint, CCPhysicsJointInfo>();


			_joint = joint;
		}
Esempio n. 4
0
        public virtual void DoAddJoint(CCPhysicsJoint joint)
        {
            if (joint == null || joint._info == null)
            {
                return;
            }

            _info.AddJoint(joint._info);
        }
Esempio n. 5
0
        public void RemoveJoint(CCPhysicsJoint joint)
        {
            int it = _joints.FindIndex((j) => j == joint);

            if (it != -1)
            {
                _joints.RemoveAt(it);
            }
        }
Esempio n. 6
0
        public void RemoveJoint(CCPhysicsJoint joint)
        {
            var it = _joints.Find((j) => j == joint);

            if (it != null)
            {
                _joints.Remove(it);
            }
        }
Esempio n. 7
0
        /** Adds a joint to the physics world.*/
        public virtual void AddJoint(CCPhysicsJoint joint)
        {
            if (joint.GetWorld() != null && joint.GetWorld() != this)
            {
                joint.RemoveFormWorld();
            }

            AddJointOrDelay(joint);
            _joints.Add(joint);
            joint._world = this;
        }
Esempio n. 8
0
        public virtual void RemoveJointOrDelay(CCPhysicsJoint joint)
        {
            var it = _delayAddJoints.Find(j => j == joint);

            if (it != null)
            {
                _delayAddJoints.Remove(it);
            }
            if (_info.isLocked())
            {
                if (!_delayAddJoints.Exists(j => j == joint))
                {
                    _delayRemoveJoints.Add(joint);
                    _delayDirty = true;
                }
            }
            else
            {
                DoRemoveJoint(joint);
            }
        }
Esempio n. 9
0
        public virtual void AddJointOrDelay(CCPhysicsJoint joint)
        {
            var it = DelayRemoveJoints.Find(j => j == joint);

            if (it != null)
            {
                DelayRemoveJoints.Remove(it);
                return;
            }

            if (Info.IsLocked())
            {
                if (!DelayAddJoints.Exists(j => j == joint))
                {
                    DelayAddJoints.Add(joint);
                    DelayDirty = true;
                }
            }
            else
            {
                DoAddJoint(joint);
            }
        }
Esempio n. 10
0
        /** Remove a joint from physics world.*/

        public virtual void RemoveJoint(CCPhysicsJoint joint, bool destroy = true)
        {
            if (joint.GetWorld() != this)
            {
                if (destroy)
                {
                    cp.AssertWarn("physics warnning: the joint is not in this world, it won't be destoried utill the body it conntect is destoried");
                }
                return;
            }

            RemoveJointOrDelay(joint);

            _joints.Remove(joint);
            joint._world = null;

            // clean the connection to this joint
            if (destroy)
            {
                if (joint.GetBodyA() != null)
                {
                    joint.GetBodyA().RemoveJoint(joint);
                }

                if (joint.GetBodyB() != null)
                {
                    joint.GetBodyB().RemoveJoint(joint);
                }

                // test the distraction is delaied or not
                if (_delayRemoveJoints.Exists(j => j == joint))
                {
                    joint._destoryMark = true;
                }
            }
        }
Esempio n. 11
0
 public void SetCustomString(CCPhysicsJoint item, String propertyName, String val)
 {
     m_jointsWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_string.Add(propertyName, val);
 }
Esempio n. 12
0
 public void SetCustomFloat(CCPhysicsJoint item, String propertyName, float val)
 {
     m_jointsWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_float.Add(propertyName, (float)val);
 }
Esempio n. 13
0
 public String GetJointName(CCPhysicsJoint joint)
 {
     if (m_jointToNameMap.ContainsKey(joint))
         return m_jointToNameMap[joint];
     return null;
 }
Esempio n. 14
0
        protected void readCustomPropertiesFromJson(CCPhysicsJoint item, JObject value)
        {
            if (null == item)
                return;

            if (value["customProperties"] != null)
                return;

            int i = 0;
            JArray propValues = (JArray)value["customProperties"];
            if (null != propValues)
            {
                int numPropValues = propValues.Count;
                for (i = 0; i < numPropValues; i++)
                {
                    JObject propValue = (JObject)propValues[i];
                    String propertyName = propValue["name"].ToString();
                    if (propValue["int"] != null)
                        SetCustomInt(item, propertyName, (int)propValue["int"]);
                    if (propValue["float"] != null)
                        SetCustomFloat(item, propertyName, (float)propValue["float"]);
                    if (propValue["string"] != null)
                        SetCustomString(item, propertyName, propValue["string"].ToString());
                    if (propValue["vec2"] != null)
                        SetCustomVector(item, propertyName, this.jsonToVec("vec2", propValue));
                    if (propValue["bool"] != null)
                        SetCustomBool(item, propertyName, (bool)propValue["bool"]);
                }
            }
        }
Esempio n. 15
0
 protected int lookupJointIndex(CCPhysicsJoint joint)
 {
     int? val = m_jointToIndexMap[joint];
     if (null != val)
         return val.Value;
     else
         return -1;
 }
Esempio n. 16
0
		public virtual void AddJointOrDelay(CCPhysicsJoint joint)
		{

			var it = _delayRemoveJoints.Find(j => j == joint);
			if (it != null)
			{
				_delayRemoveJoints.Remove(it);
				return;
			}

			if (_info.isLocked())
			{

				if (!_delayAddJoints.Exists(j => j == joint))
				{
					_delayAddJoints.Add(joint);
					_delayDirty = true;
				}

			}
			else
			{
				DoAddJoint(joint);
			}
		}
Esempio n. 17
0
		public virtual void DoRemoveJoint(CCPhysicsJoint joint)
		{
			_info.removeJoint(joint._info);
		}
Esempio n. 18
0
		public virtual void DoAddJoint(CCPhysicsJoint joint)
		{
			if (joint == null || joint._info == null)
			{
				return;
			}

			_info.AddJoint(joint._info);
		}
Esempio n. 19
0
		/** Remove a joint from physics world.*/

		public virtual void RemoveJoint(CCPhysicsJoint joint, bool destroy = true)
		{
			if (joint.GetWorld() != this)
			{
				if (destroy)
				{
					cp.AssertWarn("physics warnning: the joint is not in this world, it won't be destoried utill the body it conntect is destoried");
				}
				return;
			}

			RemoveJointOrDelay(joint);

			_joints.Remove(joint);
			joint._world = null;

			// clean the connection to this joint
			if (destroy)
			{
				if (joint.GetBodyA() != null)
				{
					joint.GetBodyA().RemoveJoint(joint);
				}

				if (joint.GetBodyB() != null)
				{
					joint.GetBodyB().RemoveJoint(joint);
				}

				// test the distraction is delaied or not
				if (_delayRemoveJoints.Exists(j => j == joint))
				{
					joint._destoryMark = true;
				}
			}
		}
Esempio n. 20
0
		public void RemoveJoint(CCPhysicsJoint joint)
		{
			var it = _joints.Find((j) => j == joint);
			if (it != null)
				_joints.Remove(it);
		}
Esempio n. 21
0
 public void SetCustomVector(CCPhysicsJoint item, String propertyName, cpVect val)
 {
     m_jointsWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_cpVect.Add(propertyName, val);
 }
Esempio n. 22
0
		public virtual void RemoveJointOrDelay(CCPhysicsJoint joint)
		{
			var it = DelayAddJoints.Find(j => j == joint);
			if (it != null)
			{
				DelayAddJoints.Remove(it);
			}
			if (Info.IsLocked())
			{

				if (!DelayAddJoints.Exists(j => j == joint))
				{
					DelayRemoveJoints.Add(joint);
					DelayDirty = true;
				}
			}
			else
			{
				DoRemoveJoint(joint);
			}
		}
Esempio n. 23
0
 public virtual void DoRemoveJoint(CCPhysicsJoint joint)
 {
     _info.removeJoint(joint._info);
 }
Esempio n. 24
0
 public void SetJointName(CCPhysicsJoint joint, String name)
 {
     m_jointToNameMap.Add(joint, name);
 }
Esempio n. 25
0
		public virtual void UpdateJoints()
		{
			if (_info.isLocked())
			{
				return;
			}

			CCPhysicsJoint[] addCopy = new CCPhysicsJoint[_delayAddJoints.Count];

			_delayAddJoints.CopyTo(addCopy);

			_delayAddJoints.Clear();

			foreach (var joint in addCopy)
			{
				DoAddJoint(joint);
			}

			CCPhysicsJoint[] removeCopy = new CCPhysicsJoint[_delayRemoveJoints.Count];
			_delayRemoveJoints.CopyTo(removeCopy);

			_delayRemoveJoints.Clear();
			foreach (var joint in removeCopy)
			{
				DoRemoveJoint(joint);

				if (joint._destoryMark)
				{
					//delete joint;
				}
			}
		}
Esempio n. 26
0
		public void DrawJoint(CCPhysicsJoint joint)
		{
			foreach (cpConstraint item in joint._info.getJoints())
				DrawConstraint(item);
		}
Esempio n. 27
0
		/** Adds a joint to the physics world.*/
		public virtual void AddJoint(CCPhysicsJoint joint)
		{
			if (joint.GetWorld() != null && joint.GetWorld() != this)
			{
				joint.RemoveFormWorld();
			}

			AddJointOrDelay(joint);
			_joints.Add(joint);
			joint._world = this;
		}