Clean up.

This commit is contained in:
NathanSweet 2014-08-30 17:03:35 +02:00
parent ed55a831d7
commit e81806bb08
5 changed files with 25 additions and 24 deletions

View File

@ -145,7 +145,7 @@ public class Animation {
static public interface Timeline { static public interface Timeline {
/** Sets the value(s) for the specified time. /** Sets the value(s) for the specified time.
* @param events May be null. */ * @param events May be null to not collect fired events. */
public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha); public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha);
} }

View File

@ -91,7 +91,7 @@ public class IkConstraint {
static public void apply (Bone bone, float targetX, float targetY, float alpha) { static public void apply (Bone bone, float targetX, float targetY, float alpha) {
float parentRotation = (!bone.data.inheritRotation || bone.parent == null) ? 0 : bone.parent.worldRotation; float parentRotation = (!bone.data.inheritRotation || bone.parent == null) ? 0 : bone.parent.worldRotation;
float rotation = bone.rotation; float rotation = bone.rotation;
float rotationIK = (float)Math.atan2(targetY - bone.getWorldY(), targetX - bone.getWorldX()) * radDeg - parentRotation; float rotationIK = (float)Math.atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation;
bone.rotationIK = rotation + (rotationIK - rotation) * alpha; bone.rotationIK = rotation + (rotationIK - rotation) * alpha;
} }

View File

@ -39,9 +39,9 @@ public class Skeleton {
final SkeletonData data; final SkeletonData data;
final Array<Bone> bones; final Array<Bone> bones;
final Array<Slot> slots; final Array<Slot> slots;
Array<Slot> drawOrder;
final Array<IkConstraint> ikConstraints; final Array<IkConstraint> ikConstraints;
private final Array<Array<Bone>> updateBonesCache = new Array(); private final Array<Array<Bone>> updateBonesCache = new Array();
Array<Slot> drawOrder;
Skin skin; Skin skin;
final Color color; final Color color;
float time; float time;
@ -365,7 +365,7 @@ public class Skeleton {
} }
public void setFlipX (boolean flipX) { public void setFlipX (boolean flipX) {
// if (this.flipX == flipX) return; if (this.flipX == flipX) return;
this.flipX = flipX; this.flipX = flipX;
Array<Bone> bones = this.bones; Array<Bone> bones = this.bones;
for (int i = 0, n = bones.size; i < n; i++) for (int i = 0, n = bones.size; i < n; i++)
@ -385,6 +385,7 @@ public class Skeleton {
} }
public void setFlip (boolean flipX, boolean flipY) { public void setFlip (boolean flipX, boolean flipY) {
if (this.flipX == flipX && this.flipY == flipY) return;
Array<Bone> bones = this.bones; Array<Bone> bones = this.bones;
for (int i = 0, n = bones.size; i < n; i++) { for (int i = 0, n = bones.size; i < n; i++) {
Bone bone = bones.get(i); Bone bone = bones.get(i);

View File

@ -128,7 +128,7 @@ public class SkeletonBinary {
boneData.length = input.readFloat() * scale; boneData.length = input.readFloat() * scale;
boneData.inheritScale = input.readBoolean(); boneData.inheritScale = input.readBoolean();
boneData.inheritRotation = input.readBoolean(); boneData.inheritRotation = input.readBoolean();
if (nonessential) Color.rgba8888ToColor(boneData.getColor(), input.readInt()); if (nonessential) Color.rgba8888ToColor(boneData.color, input.readInt());
skeletonData.bones.add(boneData); skeletonData.bones.add(boneData);
} }
@ -148,22 +148,22 @@ public class SkeletonBinary {
String slotName = input.readString(); String slotName = input.readString();
BoneData boneData = skeletonData.bones.get(input.readInt(true)); BoneData boneData = skeletonData.bones.get(input.readInt(true));
SlotData slotData = new SlotData(slotName, boneData); SlotData slotData = new SlotData(slotName, boneData);
Color.rgba8888ToColor(slotData.getColor(), input.readInt()); Color.rgba8888ToColor(slotData.color, input.readInt());
slotData.attachmentName = input.readString(); slotData.attachmentName = input.readString();
slotData.additiveBlending = input.readBoolean(); slotData.additiveBlending = input.readBoolean();
skeletonData.getSlots().add(slotData); skeletonData.slots.add(slotData);
} }
// Default skin. // Default skin.
Skin defaultSkin = readSkin(input, "default", nonessential); Skin defaultSkin = readSkin(input, "default", nonessential);
if (defaultSkin != null) { if (defaultSkin != null) {
skeletonData.defaultSkin = defaultSkin; skeletonData.defaultSkin = defaultSkin;
skeletonData.getSkins().add(defaultSkin); skeletonData.skins.add(defaultSkin);
} }
// Skins. // Skins.
for (int i = 0, n = input.readInt(true); i < n; i++) for (int i = 0, n = input.readInt(true); i < n; i++)
skeletonData.getSkins().add(readSkin(input, input.readString(), nonessential)); skeletonData.skins.add(readSkin(input, input.readString(), nonessential));
// Events. // Events.
for (int i = 0, n = input.readInt(true); i < n; i++) { for (int i = 0, n = input.readInt(true); i < n; i++) {
@ -171,7 +171,7 @@ public class SkeletonBinary {
eventData.intValue = input.readInt(false); eventData.intValue = input.readInt(false);
eventData.floatValue = input.readFloat(); eventData.floatValue = input.readFloat();
eventData.stringValue = input.readString(); eventData.stringValue = input.readString();
skeletonData.getEvents().add(eventData); skeletonData.events.add(eventData);
} }
// Animations. // Animations.
@ -412,7 +412,7 @@ public class SkeletonBinary {
IkConstraintData ikConstraint = skeletonData.findIkConstraint(input.readString()); IkConstraintData ikConstraint = skeletonData.findIkConstraint(input.readString());
int frameCount = input.readInt(true); int frameCount = input.readInt(true);
IkConstraintTimeline timeline = new IkConstraintTimeline(frameCount); IkConstraintTimeline timeline = new IkConstraintTimeline(frameCount);
timeline.setIkConstraintIndex(skeletonData.getIkConstraints().indexOf(ikConstraint, true)); timeline.ikConstraintIndex = skeletonData.getIkConstraints().indexOf(ikConstraint, true);
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) { for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readByte()); timeline.setFrame(frameIndex, input.readFloat(), input.readFloat(), input.readByte());
if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
@ -528,7 +528,7 @@ public class SkeletonBinary {
} }
timelines.shrink(); timelines.shrink();
skeletonData.getAnimations().add(new Animation(name, timelines, duration)); skeletonData.animations.add(new Animation(name, timelines, duration));
} }
private void readCurve (DataInput input, int frameIndex, CurveTimeline timeline) throws IOException { private void readCurve (DataInput input, int frameIndex, CurveTimeline timeline) throws IOException {

View File

@ -120,7 +120,7 @@ public class SkeletonJson {
String color = boneMap.getString("color", null); String color = boneMap.getString("color", null);
if (color != null) boneData.getColor().set(Color.valueOf(color)); if (color != null) boneData.getColor().set(Color.valueOf(color));
skeletonData.getBones().add(boneData); skeletonData.bones.add(boneData);
} }
// IK constraints. // IK constraints.
@ -131,17 +131,17 @@ public class SkeletonJson {
String boneName = boneMap.asString(); String boneName = boneMap.asString();
BoneData bone = skeletonData.findBone(boneName); BoneData bone = skeletonData.findBone(boneName);
if (bone == null) throw new SerializationException("IK bone not found: " + boneName); if (bone == null) throw new SerializationException("IK bone not found: " + boneName);
ikConstraintData.getBones().add(bone); ikConstraintData.bones.add(bone);
} }
String targetName = ikMap.getString("target"); String targetName = ikMap.getString("target");
ikConstraintData.setTarget(skeletonData.findBone(targetName)); ikConstraintData.target = skeletonData.findBone(targetName);
if (ikConstraintData.getTarget() == null) throw new SerializationException("Target bone not found: " + targetName); if (ikConstraintData.target == null) throw new SerializationException("Target bone not found: " + targetName);
ikConstraintData.setBendDirection(ikMap.getBoolean("bendPositive", true) ? 1 : -1); ikConstraintData.bendDirection = ikMap.getBoolean("bendPositive", true) ? 1 : -1;
ikConstraintData.setMix(ikMap.getFloat("mix", 1)); ikConstraintData.mix = ikMap.getFloat("mix", 1);
skeletonData.getIkConstraints().add(ikConstraintData); skeletonData.ikConstraints.add(ikConstraintData);
} }
// Slots. // Slots.
@ -159,7 +159,7 @@ public class SkeletonJson {
slotData.additiveBlending = slotMap.getBoolean("additive", false); slotData.additiveBlending = slotMap.getBoolean("additive", false);
skeletonData.getSlots().add(slotData); skeletonData.slots.add(slotData);
} }
// Skins. // Skins.
@ -173,7 +173,7 @@ public class SkeletonJson {
if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment); if (attachment != null) skin.addAttachment(slotIndex, entry.name, attachment);
} }
} }
skeletonData.getSkins().add(skin); skeletonData.skins.add(skin);
if (skin.name.equals("default")) skeletonData.defaultSkin = skin; if (skin.name.equals("default")) skeletonData.defaultSkin = skin;
} }
@ -183,7 +183,7 @@ public class SkeletonJson {
eventData.intValue = eventMap.getInt("int", 0); eventData.intValue = eventMap.getInt("int", 0);
eventData.floatValue = eventMap.getFloat("float", 0f); eventData.floatValue = eventMap.getFloat("float", 0f);
eventData.stringValue = eventMap.getString("string", null); eventData.stringValue = eventMap.getString("string", null);
skeletonData.getEvents().add(eventData); skeletonData.events.add(eventData);
} }
// Animations. // Animations.
@ -385,7 +385,7 @@ public class SkeletonJson {
for (JsonValue ikMap = map.getChild("ik"); ikMap != null; ikMap = ikMap.next) { for (JsonValue ikMap = map.getChild("ik"); ikMap != null; ikMap = ikMap.next) {
IkConstraintData ikConstraint = skeletonData.findIkConstraint(ikMap.name); IkConstraintData ikConstraint = skeletonData.findIkConstraint(ikMap.name);
IkConstraintTimeline timeline = new IkConstraintTimeline(ikMap.size); IkConstraintTimeline timeline = new IkConstraintTimeline(ikMap.size);
timeline.setIkConstraintIndex(skeletonData.getIkConstraints().indexOf(ikConstraint, true)); timeline.ikConstraintIndex = skeletonData.getIkConstraints().indexOf(ikConstraint, true);
int frameIndex = 0; int frameIndex = 0;
for (JsonValue valueMap = ikMap.child; valueMap != null; valueMap = valueMap.next) { for (JsonValue valueMap = ikMap.child; valueMap != null; valueMap = valueMap.next) {
timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat("mix"), timeline.setFrame(frameIndex, valueMap.getFloat("time"), valueMap.getFloat("mix"),
@ -507,7 +507,7 @@ public class SkeletonJson {
} }
timelines.shrink(); timelines.shrink();
skeletonData.getAnimations().add(new Animation(name, timelines, duration)); skeletonData.animations.add(new Animation(name, timelines, duration));
} }
void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) { void readCurve (CurveTimeline timeline, int frameIndex, JsonValue valueMap) {