Beispiel #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;
        }
		public CCPhysicsJointInfo(CCPhysicsJoint joint)
		{
			_joints = new List<cpConstraint>();
			_map = new Dictionary<cpConstraint, CCPhysicsJointInfo>();


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

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

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

            if (it != null)
            {
                _joints.Remove(it);
            }
        }
Beispiel #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;
        }
Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #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;
                }
            }
        }
Beispiel #11
0
 public void SetCustomString(CCPhysicsJoint item, String propertyName, String val)
 {
     m_jointsWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_string.Add(propertyName, val);
 }
Beispiel #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);
 }
Beispiel #13
0
 public String GetJointName(CCPhysicsJoint joint)
 {
     if (m_jointToNameMap.ContainsKey(joint))
         return m_jointToNameMap[joint];
     return null;
 }
Beispiel #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"]);
                }
            }
        }
Beispiel #15
0
 protected int lookupJointIndex(CCPhysicsJoint joint)
 {
     int? val = m_jointToIndexMap[joint];
     if (null != val)
         return val.Value;
     else
         return -1;
 }
Beispiel #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);
			}
		}
Beispiel #17
0
		public virtual void DoRemoveJoint(CCPhysicsJoint joint)
		{
			_info.removeJoint(joint._info);
		}
Beispiel #18
0
		public virtual void DoAddJoint(CCPhysicsJoint joint)
		{
			if (joint == null || joint._info == null)
			{
				return;
			}

			_info.AddJoint(joint._info);
		}
Beispiel #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;
				}
			}
		}
Beispiel #20
0
		public void RemoveJoint(CCPhysicsJoint joint)
		{
			var it = _joints.Find((j) => j == joint);
			if (it != null)
				_joints.Remove(it);
		}
Beispiel #21
0
 public void SetCustomVector(CCPhysicsJoint item, String propertyName, cpVect val)
 {
     m_jointsWithCustomProperties.Add(item);
     GetCustomPropertiesForItem(item, true).m_customPropertyMap_cpVect.Add(propertyName, val);
 }
Beispiel #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);
			}
		}
Beispiel #23
0
 public virtual void DoRemoveJoint(CCPhysicsJoint joint)
 {
     _info.removeJoint(joint._info);
 }
Beispiel #24
0
 public void SetJointName(CCPhysicsJoint joint, String name)
 {
     m_jointToNameMap.Add(joint, name);
 }
Beispiel #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;
				}
			}
		}
Beispiel #26
0
		public void DrawJoint(CCPhysicsJoint joint)
		{
			foreach (cpConstraint item in joint._info.getJoints())
				DrawConstraint(item);
		}
Beispiel #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;
		}