Эх сурвалжийг харах

[csharp] Port of commit 0c269a07: "Spring constraint -> physics constraint.", added missing documentation lines.

Harald Csaszar 2 жил өмнө
parent
commit
db39be9b89

+ 10 - 8
spine-csharp/src/SpringConstraint.cs → spine-csharp/src/PhysicsConstraint.cs

@@ -31,12 +31,12 @@ using System;
 
 namespace Spine {
 	/// <summary>
-	/// Stores the current pose for a spring constraint. A spring constraint applies physics to bones.
+	/// Stores the current pose for a physics constraint. A physics constraint applies physics to bones.
 	/// <para>
-	/// See <a href="http://esotericsoftware.com/spine-spring-constraints">Spring constraints</a> in the Spine User Guide.</para>
+	/// See <a href="http://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide.</para>
 	/// </summary>
-	public class SpringConstraint : IUpdatable {
-		internal readonly SpringConstraintData data;
+	public class PhysicsConstraint : IUpdatable {
+		internal readonly PhysicsConstraintData data;
 		internal readonly ExposedList<Bone> bones;
 		// BOZO! - stiffness -> strength. stiffness, damping, rope, stretch -> move to spring.
 		internal float mix, friction, gravity, wind, stiffness, damping;
@@ -44,7 +44,7 @@ namespace Spine {
 
 		internal bool active;
 
-		public SpringConstraint (SpringConstraintData data, Skeleton skeleton) {
+		public PhysicsConstraint (PhysicsConstraintData data, Skeleton skeleton) {
 			if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
 			if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
 			this.data = data;
@@ -63,7 +63,7 @@ namespace Spine {
 		}
 
 		/// <summary>Copy constructor.</summary>
-		public SpringConstraint (SpringConstraint constraint, Skeleton skeleton) {
+		public PhysicsConstraint (PhysicsConstraint constraint, Skeleton skeleton) {
 			if (constraint == null) throw new ArgumentNullException("constraint", "constraint cannot be null.");
 			if (skeleton == null) throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
 			data = constraint.data;
@@ -85,6 +85,8 @@ namespace Spine {
 
 		}
 
+		/// <summary>The bones that will be modified by this physics constraint.</summary>
+		public ExposedList<Bone> Bones { get { return bones; } }
 		/// <summary>A percentage (0-1) that controls the mix between the constrained and unconstrained poses.</summary>
 		public float Mix { get { return mix; } set { mix = value; } }
 		public float Friction { get { return friction; } set { friction = value; } }
@@ -95,8 +97,8 @@ namespace Spine {
 		public bool Rope { get { return rope; } set { rope = value; } }
 		public bool Stretch { get { return stretch; } set { stretch = value; } }
 		public bool Active { get { return active; } }
-		/// <summary>The spring constraint's setup pose data.</summary>
-		public SpringConstraintData Data { get { return data; } }
+		/// <summary>The physics constraint's setup pose data.</summary>
+		public PhysicsConstraintData Data { get { return data; } }
 
 		override public string ToString () {
 			return data.name;

+ 0 - 0
spine-csharp/src/SpringConstraint.cs.meta → spine-csharp/src/PhysicsConstraint.cs.meta


+ 5 - 5
spine-csharp/src/SpringConstraintData.cs → spine-csharp/src/PhysicsConstraintData.cs

@@ -31,19 +31,19 @@ using System;
 
 namespace Spine {
 	/// <summary>
-	/// Stores the setup pose for a <see cref="SpringConstraint"/>.
+	/// Stores the setup pose for a <see cref="PhysicsConstraint"/>.
 	/// <para>
-	/// See <a href="http://esotericsoftware.com/spine-spring-constraints">Spring constraints</a> in the Spine User Guide.</para>
+	/// See <a href="http://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide.</para>
 	/// </summary>
-	public class SpringConstraintData : ConstraintData {
+	public class PhysicsConstraintData : ConstraintData {
 		internal ExposedList<BoneData> bones = new ExposedList<BoneData>();
 		internal float mix, friction, gravity, wind, stiffness, damping;
 		internal bool rope, stretch;
 
-		public SpringConstraintData (string name) : base(name) {
+		public PhysicsConstraintData (string name) : base(name) {
 		}
 
-		/// <summary>The bones that are constrained by this spring constraint.</summary>
+		/// <summary>The bones that are constrained by this physics constraint.</summary>
 		public ExposedList<BoneData> Bones { get { return bones; } }
 
 		/// <summary>A percentage (0-1) that controls the mix between the constrained and unconstrained poses.</summary>

+ 0 - 0
spine-csharp/src/SpringConstraintData.cs.meta → spine-csharp/src/PhysicsConstraintData.cs.meta


+ 48 - 24
spine-csharp/src/Skeleton.cs

@@ -38,23 +38,35 @@ namespace Spine {
 		internal ExposedList<IkConstraint> ikConstraints;
 		internal ExposedList<TransformConstraint> transformConstraints;
 		internal ExposedList<PathConstraint> pathConstraints;
-		internal ExposedList<SpringConstraint> springConstraints;
+		internal ExposedList<PhysicsConstraint> physicsConstraints;
 		internal ExposedList<IUpdatable> updateCache = new ExposedList<IUpdatable>();
 		internal Skin skin;
 		internal float r = 1, g = 1, b = 1, a = 1;
 		internal float scaleX = 1, scaleY = 1;
 		internal float x, y;
 
+		/// <summary>The skeleton's setup pose data.</summary>
 		public SkeletonData Data { get { return data; } }
+		/// <summary>The skeleton's bones, sorted parent first. The root bone is always the first bone.</summary>
 		public ExposedList<Bone> Bones { get { return bones; } }
+		/// <summary>The list of bones and constraints, sorted in the order they should be updated,
+		/// as computed by <see cref="UpdateCache()"/>.</summary>
 		public ExposedList<IUpdatable> UpdateCacheList { get { return updateCache; } }
+		/// <summary>The skeleton's slots.</summary>
 		public ExposedList<Slot> Slots { get { return slots; } }
+		/// <summary>The skeleton's slots in the order they should be drawn.
+		/// The returned array may be modified to change the draw order.</summary>
 		public ExposedList<Slot> DrawOrder { get { return drawOrder; } }
+		/// <summary>The skeleton's IK constraints.</summary>
 		public ExposedList<IkConstraint> IkConstraints { get { return ikConstraints; } }
+		/// <summary>The skeleton's path constraints.</summary>
 		public ExposedList<PathConstraint> PathConstraints { get { return pathConstraints; } }
-		public ExposedList<SpringConstraint> SpringConstraints { get { return springConstraints; } }
+		/// <summary>The skeleton's physics constraints.</summary>
+		public ExposedList<PhysicsConstraint> PhysicsConstraints { get { return physicsConstraints; } }
+		/// <summary>The skeleton's transform constraints.</summary>
 		public ExposedList<TransformConstraint> TransformConstraints { get { return transformConstraints; } }
 
+		/// <summary>The skeleton's current skin.</summary>
 		public Skin Skin {
 			/// <summary>The skeleton's current skin. May be null.</summary>
 			get { return skin; }
@@ -65,9 +77,21 @@ namespace Spine {
 		public float G { get { return g; } set { g = value; } }
 		public float B { get { return b; } set { b = value; } }
 		public float A { get { return a; } set { a = value; } }
+		/// <summary><para>The skeleton X position, which is added to the root bone worldX position.</para>
+		/// <para>
+		/// Bones that do not inherit translation are still affected by this property.</para></summary>
 		public float X { get { return x; } set { x = value; } }
+		/// <summary><para>The skeleton Y position, which is added to the root bone worldY position.</para>
+		/// <para>
+		/// Bones that do not inherit translation are still affected by this property.</para></summary>
 		public float Y { get { return y; } set { y = value; } }
+		/// <summary><para> Scales the entire skeleton on the X axis.</para>
+		/// <para>
+		/// Bones that do not inherit scale are still affected by this property.</para></summary>
 		public float ScaleX { get { return scaleX; } set { scaleX = value; } }
+		/// <summary><para> Scales the entire skeleton on the Y axis.</para>
+		/// <para>
+		/// Bones that do not inherit scale are still affected by this property.</para></summary>
 		public float ScaleY { get { return scaleY * (Bone.yDown ? -1 : 1); } set { scaleY = value; } }
 
 		[Obsolete("Use ScaleX instead. FlipX is when ScaleX is negative.")]
@@ -120,9 +144,9 @@ namespace Spine {
 			foreach (PathConstraintData pathConstraintData in data.pathConstraints)
 				pathConstraints.Add(new PathConstraint(pathConstraintData, this));
 
-			springConstraints = new ExposedList<SpringConstraint>(data.springConstraints.Count);
-			foreach (SpringConstraintData springConstraintData in data.springConstraints)
-				springConstraints.Add(new SpringConstraint(springConstraintData, this));
+			physicsConstraints = new ExposedList<PhysicsConstraint>(data.physicsConstraints.Count);
+			foreach (PhysicsConstraintData physicsConstraintData in data.physicsConstraints)
+				physicsConstraints.Add(new PhysicsConstraint(physicsConstraintData, this));
 
 			UpdateCache();
 		}
@@ -169,9 +193,9 @@ namespace Spine {
 			foreach (PathConstraint pathConstraint in skeleton.pathConstraints)
 				pathConstraints.Add(new PathConstraint(pathConstraint, this));
 
-			springConstraints = new ExposedList<SpringConstraint>(skeleton.springConstraints.Count);
-			foreach (SpringConstraint springConstraint in skeleton.springConstraints)
-				springConstraints.Add(new SpringConstraint(springConstraint, this));
+			physicsConstraints = new ExposedList<PhysicsConstraint>(skeleton.physicsConstraints.Count);
+			foreach (PhysicsConstraint physicsConstraint in skeleton.physicsConstraints)
+				physicsConstraints.Add(new PhysicsConstraint(physicsConstraint, this));
 
 			skin = skeleton.skin;
 			r = skeleton.r;
@@ -210,12 +234,12 @@ namespace Spine {
 			}
 
 			int ikCount = this.ikConstraints.Count, transformCount = this.transformConstraints.Count, pathCount = this.pathConstraints.Count,
-				springCount = this.springConstraints.Count;
+				physicsCount = this.physicsConstraints.Count;
 			IkConstraint[] ikConstraints = this.ikConstraints.Items;
 			TransformConstraint[] transformConstraints = this.transformConstraints.Items;
 			PathConstraint[] pathConstraints = this.pathConstraints.Items;
-			SpringConstraint[] springConstraints = this.springConstraints.Items;
-			int constraintCount = ikCount + transformCount + pathCount + springCount;
+			PhysicsConstraint[] physicsConstraints = this.physicsConstraints.Items;
+			int constraintCount = ikCount + transformCount + pathCount + physicsCount;
 			for (int i = 0; i < constraintCount; i++) {
 				for (int ii = 0; ii < ikCount; ii++) {
 					IkConstraint constraint = ikConstraints[ii];
@@ -238,10 +262,10 @@ namespace Spine {
 						goto continue_outer;
 					}
 				}
-				for (int ii = 0; ii < springCount; ii++) {
-					SpringConstraint constraint = springConstraints[ii];
+				for (int ii = 0; ii < physicsCount; ii++) {
+					PhysicsConstraint constraint = physicsConstraints[ii];
 					if (constraint.data.order == i) {
-						SortSpringConstraint(constraint);
+						SortPhysicsConstraint(constraint);
 						goto continue_outer;
 					}
 				}
@@ -355,7 +379,7 @@ namespace Spine {
 			}
 		}
 
-		private void SortSpringConstraint (SpringConstraint constraint) {
+		private void SortPhysicsConstraint (PhysicsConstraint constraint) {
 			constraint.active = !constraint.data.skinRequired || (skin != null && skin.constraints.Contains(constraint.data));
 			if (!constraint.active) return;
 
@@ -491,10 +515,10 @@ namespace Spine {
 				constraint.mixY = data.mixY;
 			}
 
-			SpringConstraint[] springConstraints = this.springConstraints.Items;
-			for (int i = 0, n = this.springConstraints.Count; i < n; i++) {
-				SpringConstraint constraint = springConstraints[i];
-				SpringConstraintData data = constraint.data;
+			PhysicsConstraint[] physicsConstraints = this.physicsConstraints.Items;
+			for (int i = 0, n = this.physicsConstraints.Count; i < n; i++) {
+				PhysicsConstraint constraint = physicsConstraints[i];
+				PhysicsConstraintData data = constraint.data;
 				constraint.mix = data.mix;
 				constraint.friction = data.friction;
 				constraint.gravity = data.gravity;
@@ -657,14 +681,14 @@ namespace Spine {
 			return null;
 		}
 
-		/// <summary>Finds a spring constraint by comparing each spring constraint's name. It is more efficient to cache the results of this
+		/// <summary>Finds a physics constraint by comparing each physics constraint's name. It is more efficient to cache the results of this
 		/// method than to call it repeatedly.</summary>
 		/// <returns>May be null.</returns>
-		public SpringConstraint FindSpringConstraint (String constraintName) {
+		public PhysicsConstraint FindPhysicsConstraint (String constraintName) {
 			if (constraintName == null) throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
-			SpringConstraint[] springConstraints = this.springConstraints.Items;
-			for (int i = 0, n = this.springConstraints.Count; i < n; i++) {
-				SpringConstraint constraint = springConstraints[i];
+			PhysicsConstraint[] physicsConstraints = this.physicsConstraints.Items;
+			for (int i = 0, n = this.physicsConstraints.Count; i < n; i++) {
+				PhysicsConstraint constraint = physicsConstraints[i];
 				if (constraint.data.name.Equals(constraintName)) return constraint;
 			}
 			return null;

+ 14 - 8
spine-csharp/src/SkeletonData.cs

@@ -43,7 +43,7 @@ namespace Spine {
 		internal ExposedList<IkConstraintData> ikConstraints = new ExposedList<IkConstraintData>();
 		internal ExposedList<TransformConstraintData> transformConstraints = new ExposedList<TransformConstraintData>();
 		internal ExposedList<PathConstraintData> pathConstraints = new ExposedList<PathConstraintData>();
-		internal ExposedList<SpringConstraintData> springConstraints = new ExposedList<SpringConstraintData>();
+		internal ExposedList<PhysicsConstraintData> physicsConstraints = new ExposedList<PhysicsConstraintData>();
 		internal float x, y, width, height;
 		internal string version, hash;
 
@@ -70,12 +70,18 @@ namespace Spine {
 		/// <return>May be null.</return>
 		public Skin DefaultSkin { get { return defaultSkin; } set { defaultSkin = value; } }
 
+		/// <summary>The skeleton's events.</summary>
 		public ExposedList<EventData> Events { get { return events; } set { events = value; } }
+		/// <summary>The skeleton's animations.</summary>
 		public ExposedList<Animation> Animations { get { return animations; } set { animations = value; } }
+		/// <summary>The skeleton's IK constraints.</summary>
 		public ExposedList<IkConstraintData> IkConstraints { get { return ikConstraints; } set { ikConstraints = value; } }
+		/// <summary>The skeleton's transform constraints.</summary>
 		public ExposedList<TransformConstraintData> TransformConstraints { get { return transformConstraints; } set { transformConstraints = value; } }
+		/// <summary>The skeleton's path constraints.</summary>
 		public ExposedList<PathConstraintData> PathConstraints { get { return pathConstraints; } set { pathConstraints = value; } }
-		public ExposedList<SpringConstraintData> SpringConstraints { get { return springConstraints; } set { springConstraints = value; } }
+		/// <summary>The skeleton's physics constraints.</summary>
+		public ExposedList<PhysicsConstraintData> PhysicsConstraints { get { return physicsConstraints; } set { physicsConstraints = value; } }
 
 		public float X { get { return x; } set { x = value; } }
 		public float Y { get { return y; } set { y = value; } }
@@ -202,18 +208,18 @@ namespace Spine {
 			return null;
 		}
 
-		// --- Spring constraints
+		// --- Physics constraints
 
 		/// <summary>
-		/// Finds a spring constraint by comparing each spring constraint's name. It is more efficient to cache the results of this
+		/// Finds a physics constraint by comparing each physics constraint's name. It is more efficient to cache the results of this
 		/// method than to call it multiple times.
 		/// </summary>
 		/// <returns>May be null.</returns>
-		public SpringConstraintData FindSpringConstraint (String constraintName) {
+		public PhysicsConstraintData FindPhysicsConstraint (String constraintName) {
 			if (constraintName == null) throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
-			Object[] springConstraints = this.springConstraints.Items;
-			for (int i = 0, n = this.springConstraints.Count; i < n; i++) {
-				SpringConstraintData constraint = (SpringConstraintData)springConstraints[i];
+			Object[] physicsConstraints = this.physicsConstraints.Items;
+			for (int i = 0, n = this.physicsConstraints.Count; i < n; i++) {
+				PhysicsConstraintData constraint = (PhysicsConstraintData)physicsConstraints[i];
 				if (constraint.name.Equals(constraintName)) return constraint;
 			}
 			return null;