From 842dffbd8379b17e4d8a14d9fcac2bd6130b914c Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 27 Aug 2019 15:57:14 +0200 Subject: [PATCH] [all] Source clean up, formatting, and tabs for indentation. --- .../src/spine/animation/AnimationState.as | 76 +- .../src/spine/animation/DeformTimeline.as | 44 +- .../spine/animation/IkConstraintTimeline.as | 6 +- .../src/spine/animation/MixDirection.as | 2 +- .../src/spine/animation/RotateTimeline.as | 10 +- .../src/spine/animation/ScaleTimeline.as | 2 +- .../src/spine/animation/TrackEntry.as | 2 +- spine-c/spine-c-unit-tests/README.md | 2 +- spine-c/spine-c-unit-tests/main.cpp | 2 +- spine-c/spine-c/include/spine/Array.h | 4 +- .../spine-c/include/spine/AttachmentLoader.h | 6 +- spine-c/spine-c/include/spine/Skin.h | 2 +- spine-c/spine-c/include/spine/VertexEffect.h | 2 +- spine-c/spine-c/src/spine/Animation.c | 460 +++++------ spine-c/spine-c/src/spine/AnimationState.c | 33 +- spine-c/spine-c/src/spine/Atlas.c | 16 +- spine-c/spine-c/src/spine/AttachmentLoader.c | 3 +- spine-c/spine-c/src/spine/Bone.c | 142 ++-- spine-c/spine-c/src/spine/IkConstraint.c | 12 +- spine-c/spine-c/src/spine/Json.c | 39 +- spine-c/spine-c/src/spine/Json.h | 6 +- spine-c/spine-c/src/spine/MeshAttachment.c | 3 +- spine-c/spine-c/src/spine/PathConstraint.c | 7 +- spine-c/spine-c/src/spine/Skeleton.c | 3 +- spine-c/spine-c/src/spine/SkeletonBinary.c | 566 +++++++------- spine-c/spine-c/src/spine/SkeletonBounds.c | 7 +- spine-c/spine-c/src/spine/SkeletonJson.c | 102 ++- spine-c/spine-c/src/spine/Skin.c | 2 +- spine-c/spine-c/src/spine/Slot.c | 2 +- spine-c/spine-c/src/spine/Triangulator.c | 6 +- spine-cocos2d-objc/src/spine/GLUtils.c | 56 +- spine-cocos2d-objc/src/spine/GLUtils.h | 8 +- .../src/spine/SkeletonAnimation.h | 4 +- .../src/spine/SkeletonAnimation.m | 14 +- .../src/spine/SkeletonRenderer.h | 2 +- .../src/spine/SkeletonRenderer.m | 44 +- .../src/spine/SkeletonAnimation.cpp | 65 +- spine-cocos2dx/src/spine/SkeletonAnimation.h | 12 +- spine-cocos2dx/src/spine/SkeletonBatch.cpp | 22 +- spine-cocos2dx/src/spine/SkeletonBatch.h | 40 +- spine-cocos2dx/src/spine/SkeletonRenderer.cpp | 102 +-- spine-cocos2dx/src/spine/SkeletonRenderer.h | 20 +- .../src/spine/SkeletonTwoColorBatch.cpp | 62 +- .../src/spine/SkeletonTwoColorBatch.h | 74 +- spine-cocos2dx/src/spine/spine-cocos2dx.cpp | 8 +- spine-cocos2dx/src/spine/spine-cocos2dx.h | 10 +- spine-corona/spine-corona/spine.lua | 136 ++-- spine-cpp/spine-cpp/include/spine/Animation.h | 2 +- .../spine-cpp/include/spine/AnimationState.h | 713 +++++++++--------- .../include/spine/AnimationStateData.h | 82 +- spine-cpp/spine-cpp/include/spine/Atlas.h | 4 +- .../include/spine/AtlasAttachmentLoader.h | 54 +- .../include/spine/AttachmentLoader.h | 68 +- .../include/spine/AttachmentTimeline.h | 54 +- .../spine-cpp/include/spine/AttachmentType.h | 18 +- spine-cpp/spine-cpp/include/spine/Bone.h | 2 - .../include/spine/BoundingBoxAttachment.h | 12 +- .../include/spine/ClippingAttachment.h | 38 +- .../spine-cpp/include/spine/ColorTimeline.h | 2 +- .../spine-cpp/include/spine/ContainerUtil.h | 164 ++-- .../spine-cpp/include/spine/CurveTimeline.h | 72 +- .../spine-cpp/include/spine/DeformTimeline.h | 62 +- .../include/spine/DrawOrderTimeline.h | 50 +- .../spine-cpp/include/spine/EventTimeline.h | 52 +- spine-cpp/spine-cpp/include/spine/HashMap.h | 2 +- .../include/spine/IkConstraintData.h | 82 +- .../include/spine/IkConstraintTimeline.h | 44 +- .../spine-cpp/include/spine/MeshAttachment.h | 184 ++--- spine-cpp/spine-cpp/include/spine/MixBlend.h | 2 +- .../spine-cpp/include/spine/MixDirection.h | 3 +- .../spine-cpp/include/spine/PathAttachment.h | 40 +- .../spine-cpp/include/spine/PathConstraint.h | 140 ++-- .../include/spine/PathConstraintData.h | 106 +-- .../include/spine/PathConstraintMixTimeline.h | 46 +- .../spine/PathConstraintPositionTimeline.h | 50 +- .../spine/PathConstraintSpacingTimeline.h | 26 +- .../spine-cpp/include/spine/PointAttachment.h | 69 +- spine-cpp/spine-cpp/include/spine/Pool.h | 2 +- .../include/spine/RegionAttachment.h | 156 ++-- .../spine-cpp/include/spine/RotateTimeline.h | 62 +- .../spine-cpp/include/spine/ScaleTimeline.h | 26 +- .../spine-cpp/include/spine/ShearTimeline.h | 26 +- spine-cpp/spine-cpp/include/spine/Skeleton.h | 1 - .../spine-cpp/include/spine/SkeletonBinary.h | 168 ++--- .../spine-cpp/include/spine/SkeletonBounds.h | 127 ++-- .../include/spine/SkeletonClipping.h | 76 +- .../spine-cpp/include/spine/SkeletonData.h | 1 - .../spine-cpp/include/spine/TextureLoader.h | 24 +- spine-cpp/spine-cpp/include/spine/Timeline.h | 7 +- .../include/spine/TransformConstraint.h | 106 +-- .../include/spine/TransformConstraintData.h | 72 +- .../spine/TransformConstraintTimeline.h | 42 +- .../spine-cpp/include/spine/TransformMode.h | 14 +- .../include/spine/TranslateTimeline.h | 46 +- .../include/spine/TwoColorTimeline.h | 50 +- .../include/spine/VertexAttachment.h | 94 +-- spine-cpp/spine-cpp/src/spine/Animation.cpp | 25 +- .../spine-cpp/src/spine/AnimationState.cpp | 201 ++--- spine-cpp/spine-cpp/src/spine/Atlas.cpp | 88 +-- .../src/spine/AtlasAttachmentLoader.cpp | 2 +- .../src/spine/AttachmentTimeline.cpp | 3 +- spine-cpp/spine-cpp/src/spine/Bone.cpp | 202 ++--- .../spine-cpp/src/spine/ColorTimeline.cpp | 24 +- .../spine-cpp/src/spine/CurveTimeline.cpp | 1 - .../spine-cpp/src/spine/DeformTimeline.cpp | 146 ++-- .../spine-cpp/src/spine/DrawOrderTimeline.cpp | 18 +- .../spine-cpp/src/spine/EventTimeline.cpp | 18 +- .../spine-cpp/src/spine/IkConstraint.cpp | 51 +- .../src/spine/IkConstraintTimeline.cpp | 4 +- spine-cpp/spine-cpp/src/spine/Json.cpp | 142 ++-- .../spine-cpp/src/spine/MeshAttachment.cpp | 136 ++-- .../spine-cpp/src/spine/PathConstraint.cpp | 116 ++- .../src/spine/PathConstraintMixTimeline.cpp | 33 +- .../spine/PathConstraintPositionTimeline.cpp | 29 +- .../spine/PathConstraintSpacingTimeline.cpp | 26 +- spine-cpp/spine-cpp/src/spine/RTTI.cpp | 7 +- .../spine-cpp/src/spine/RegionAttachment.cpp | 39 +- .../spine-cpp/src/spine/RotateTimeline.cpp | 32 +- .../spine-cpp/src/spine/ScaleTimeline.cpp | 93 +-- .../spine-cpp/src/spine/ShearTimeline.cpp | 21 +- .../spine-cpp/src/spine/SkeletonBinary.cpp | 371 ++++----- .../spine-cpp/src/spine/SkeletonBounds.cpp | 43 +- .../spine-cpp/src/spine/SkeletonClipping.cpp | 31 +- .../spine-cpp/src/spine/SkeletonJson.cpp | 251 ++---- spine-cpp/spine-cpp/src/spine/Skin.cpp | 13 +- .../src/spine/TransformConstraint.cpp | 114 +-- .../src/spine/TransformConstraintTimeline.cpp | 39 +- .../spine-cpp/src/spine/TranslateTimeline.cpp | 45 +- .../spine-cpp/src/spine/Triangulator.cpp | 32 +- .../spine-cpp/src/spine/TwoColorTimeline.cpp | 6 +- .../spine-cpp/src/spine/VertexAttachment.cpp | 10 +- spine-csharp/src/Animation.cs | 22 +- spine-csharp/src/AnimationStateData.cs | 4 +- .../src/Attachments/AtlasAttachmentLoader.cs | 2 +- .../src/Attachments/ClippingAttachment.cs | 10 +- .../src/Attachments/MeshAttachment.cs | 8 +- .../src/Attachments/PathAttachment.cs | 2 +- .../src/Attachments/VertexAttachment.cs | 6 +- spine-csharp/src/Bone.cs | 4 +- .../src/Collections/OrderedDictionary.cs | 2 +- spine-csharp/src/Event.cs | 2 +- spine-csharp/src/ExposedList.cs | 6 +- spine-csharp/src/IkConstraintData.cs | 6 +- spine-csharp/src/Json.cs | 85 +-- spine-csharp/src/MathUtils.cs | 4 +- spine-csharp/src/PathConstraint.cs | 4 +- spine-csharp/src/PathConstraintData.cs | 6 +- spine-csharp/src/Skeleton.cs | 14 +- spine-csharp/src/SkeletonData.cs | 10 +- spine-csharp/src/SkeletonJson.cs | 16 +- spine-csharp/src/Skin.cs | 6 +- spine-csharp/src/TransformConstraint.cs | 2 +- spine-csharp/src/Triangulator.cs | 6 +- spine-js/README.md | 2 +- spine-love/spine-love/spine.lua | 170 ++--- spine-lua/Animation.lua | 116 ++- spine-lua/AnimationState.lua | 487 ++++++------ spine-lua/AttachmentLoader.lua | 4 +- spine-lua/Bone.lua | 2 +- spine-lua/BoneData.lua | 2 +- spine-lua/IkConstraint.lua | 64 +- spine-lua/IkConstraintData.lua | 4 +- spine-lua/PathConstraint.lua | 58 +- spine-lua/PathConstraintData.lua | 2 +- spine-lua/Skeleton.lua | 170 ++--- spine-lua/SkeletonBounds.lua | 36 +- spine-lua/SkeletonClipping.lua | 14 +- spine-lua/SkeletonJson.lua | 116 +-- spine-lua/Skin.lua | 194 ++--- spine-lua/Slot.lua | 4 +- spine-lua/TextureAtlas.lua | 2 +- spine-lua/TransformConstraint.lua | 12 +- spine-lua/TransformConstraintData.lua | 2 +- spine-lua/Triangulator.lua | 6 +- spine-lua/attachments/Attachment.lua | 2 +- .../attachments/BoundingBoxAttachment.lua | 8 +- spine-lua/attachments/ClippingAttachment.lua | 10 +- spine-lua/attachments/MeshAttachment.lua | 70 +- spine-lua/attachments/PathAttachment.lua | 18 +- spine-lua/attachments/PointAttachment.lua | 12 +- spine-lua/attachments/RegionAttachment.lua | 8 +- spine-lua/attachments/VertexAttachment.lua | 30 +- spine-lua/utils.lua | 52 +- spine-lua/vertexeffects/SwirlEffect.lua | 2 +- spine-sfml/c/src/spine/spine-sfml.cpp | 56 +- spine-sfml/cpp/src/spine/spine-sfml.cpp | 56 +- .../src/spine/starling/SkeletonSprite.as | 64 +- .../starling/StarlingAtlasAttachmentLoader.as | 20 +- .../src/spine/starling/TwoColorEffect.as | 32 +- spine-threejs/README.md | 2 +- spine-tk2d/README.md | 2 +- spine-ts/canvas/src/SkeletonRenderer.ts | 14 +- spine-ts/core/src/AnimationState.ts | 6 +- spine-ts/core/src/AssetManager.ts | 5 +- spine-ts/core/src/SharedAssetManager.ts | 2 +- spine-ts/player/src/Player.ts | 12 +- spine-ts/webgl/src/Matrix4.ts | 62 +- .../SpinePlugin/Private/SSpineWidget.cpp | 2 +- .../Source/SpineUE4/MySceneComponent.cpp | 2 +- spine-ue4/Source/SpineUE4/SpineboyCppPawn.cpp | 2 +- .../SpineAnimationTesterTool.cs | 10 +- .../BasicPlatformerController.cs | 10 +- .../Scripts/Getting Started Scripts/Raptor.cs | 2 +- .../Assets/Spine Examples/Scripts/Goblins.cs | 8 +- .../Spine Examples/Scripts/HurtFlashEffect.cs | 2 +- .../Scripts/MaterialPropertyBlockExample.cs | 2 +- .../DummyMecanimControllerExample.cs | 8 +- .../MecanimToAnimationHandleExample.cs | 2 +- .../SkeletonAnimationHandleExample.cs | 4 +- .../EquipButtonExample.cs | 2 +- .../EquipSystemExample.cs | 4 +- .../Spine Examples/Scripts/MixAndMatch.cs | 4 +- .../Scripts/MixAndMatchGraphic.cs | 6 +- .../Spine Examples/Scripts/RaggedySpineboy.cs | 4 +- .../Sample Components/BoneLocalOverride.cs | 2 +- .../Scripts/Sample Components/CombinedSkin.cs | 2 +- .../Sample Components/Ghost/SkeletonGhost.cs | 10 +- .../Ghost/SkeletonGhostRenderer.cs | 4 +- .../Legacy/SpriteAttacher.cs | 2 +- .../JitterEffectExample.cs | 2 +- .../SkeletonAnimationFixedTimestep.cs | 2 +- .../SkeletonAnimationMulti.cs | 4 +- .../SkeletonColorInitialize.cs | 2 +- .../Editor/SkeletonRagdollInspector.cs | 2 +- .../SkeletonRagdoll.cs | 12 +- .../SkeletonRagdoll2D.cs | 6 +- .../SkeletonUtilityGroundConstraint.cs | 2 +- .../SkeletonUtilityKinematicShadow.cs | 6 +- .../Scripts/SpawnSkeletonGraphicExample.cs | 2 +- .../Scripts/SpineboyFacialExpression.cs | 2 +- .../AnimationReferenceAssetEditor.cs | 4 +- .../Asset Types/SkeletonDataAssetInspector.cs | 36 +- .../Asset Types/SpineAtlasAssetInspector.cs | 10 +- .../BoneFollowerGraphicInspector.cs | 4 +- .../Components/SkeletonAnimationInspector.cs | 4 +- .../Components/SkeletonGraphicInspector.cs | 6 +- ...keletonRendererCustomMaterialsInspector.cs | 6 +- .../Components/SkeletonRendererInspector.cs | 12 +- .../SkeletonUtilityBoneInspector.cs | 2 +- .../Components/SkeletonUtilityInspector.cs | 6 +- .../Editor/Shaders/SpineSpriteShaderGUI.cs | 10 +- .../Editor/SpineAttributeDrawers.cs | 12 +- .../Editor/Utility/AssetUtility.cs | 12 +- .../Editor/Utility/DataReloadHandler.cs | 2 +- .../spine-unity/Editor/Utility/Preferences.cs | 2 +- .../Editor/Utility/SpineEditorUtilities.cs | 4 +- .../Editor/Utility/SpineHandles.cs | 2 +- .../Editor/Utility/SpineInspectorUtility.cs | 6 +- .../Editor/Windows/SkeletonBaker.cs | 22 +- .../Editor/Windows/SkeletonBakingWindow.cs | 12 +- .../Editor/Windows/SkeletonDebugWindow.cs | 14 +- .../Editor/Windows/SpinePreferences.cs | 8 +- .../Editor/SkeletonPartsRendererInspector.cs | 2 +- .../SkeletonRenderSeparatorInspector.cs | 10 +- .../Editor/SlotBlendModesEditor.cs | 2 +- .../Asset Types/AnimationReferenceAsset.cs | 4 +- .../Asset Types/SpineAtlasAsset.cs | 2 +- .../Following/BoneFollowerGraphic.cs | 2 +- .../Following/BoundingBoxFollower.cs | 10 +- .../Components/Following/PointFollower.cs | 2 +- .../Components/SkeletonAnimation.cs | 8 +- .../spine-unity/Components/SkeletonGraphic.cs | 16 +- .../spine-unity/Components/SkeletonMecanim.cs | 10 +- .../SkeletonRenderSeparator.cs | 8 +- .../Components/SkeletonRenderer.cs | 14 +- .../SkeletonRendererCustomMaterials.cs | 6 +- .../SkeletonUtility/SkeletonUtility.cs | 2 +- .../SkeletonUtility/SkeletonUtilityBone.cs | 4 +- .../SlotBlendModes/SlotBlendModes.cs | 4 +- .../Runtime/spine-unity/ISkeletonAnimation.cs | 2 +- .../Mesh Generation/MeshGenerator.cs | 30 +- .../Mesh Generation/MeshRendererBuffers.cs | 4 +- .../SkeletonRendererInstruction.cs | 8 +- .../spine-unity/Mesh Generation/SpineMesh.cs | 12 +- .../BlendModeMaterialsAsset.cs | 2 +- .../Runtime/spine-unity/SpineAttributes.cs | 2 +- .../spine-unity/Utility/AtlasUtilities.cs | 14 +- .../Utility/AttachmentCloneExtensions.cs | 2 +- .../Utility/AttachmentRegionExtensions.cs | 4 +- .../spine-unity/Utility/MaterialChecks.cs | 6 +- .../spine-unity/Utility/SkeletonExtensions.cs | 12 +- .../spine-unity/Utility/SkinUtilities.cs | 4 +- .../WaitForSpineAnimation.cs | 6 +- .../WaitForSpineAnimationComplete.cs | 6 +- .../WaitForSpineAnimationEnd.cs | 8 +- .../YieldInstructions/WaitForSpineEvent.cs | 10 +- .../WaitForSpineTrackEntryEnd.cs | 4 +- .../Editor/SpineSkeletonFlipDrawer.cs | 18 +- .../SpinePlayableHandleBase.cs | 2 +- .../SpineAnimationStateMixerBehaviour.cs | 4 +- .../SpineSkeletonFlipBehaviour.cs | 2 +- .../SpineSkeletonFlipTrack.cs | 2 +- spine-xna/src/ShapeRenderer.cs | 14 +- spine-xna/src/SkeletonDebugRenderer.cs | 2 +- spine-xna/src/SkeletonRenderer.cs | 4 +- spine-xna/src/Util.cs | 7 +- spine-xna/src/VertexEffect.cs | 6 +- 297 files changed, 5229 insertions(+), 5648 deletions(-) diff --git a/spine-as3/spine-as3/src/spine/animation/AnimationState.as b/spine-as3/spine-as3/src/spine/animation/AnimationState.as index 7428f77c4..9b654776d 100644 --- a/spine-as3/spine-as3/src/spine/animation/AnimationState.as +++ b/spine-as3/spine-as3/src/spine/animation/AnimationState.as @@ -54,7 +54,7 @@ package spine.animation { internal var queue : EventQueue; internal var propertyIDs : Dictionary = new Dictionary(); internal var mixingTo : Vector. = new Vector.(); - internal var animationsChanged : Boolean; + internal var animationsChanged : Boolean; public var timeScale : Number = 1; internal var trackEntryPool : Pool; @@ -131,7 +131,7 @@ package spine.animation { if (from == null) return true; var finished : Boolean = updateMixingFrom(from, delta); - + from.animationLast = from.nextAnimationLast; from.trackLast = from.nextTrackLast; @@ -142,11 +142,11 @@ package spine.animation { to.mixingFrom = from.mixingFrom; if (from.mixingFrom != null) from.mixingFrom.mixingTo = to; to.interruptAlpha = from.interruptAlpha; - queue.end(from); + queue.end(from); } return finished; } - + from.trackTime += delta * from.timeScale; to.mixTime += delta; return false; @@ -182,11 +182,11 @@ package spine.animation { Timeline(timelines[ii]).apply(skeleton, animationLast, animationTime, events, mix, blend, MixDirection.In); } else { var timelineMode : Vector. = current.timelineMode; - + var firstFrame : Boolean = current.timelinesRotation.length == 0; if (firstFrame) current.timelinesRotation.length = timelineCount << 1; var timelinesRotation : Vector. = current.timelinesRotation; - + for (ii = 0; ii < timelineCount; ii++) { var timeline : Timeline = timelines[ii]; var timelineBlend : MixBlend = (timelineMode[ii] & (NOT_LAST - 1)) == SUBSEQUENT ? blend : MixBlend.setup; @@ -234,11 +234,11 @@ package spine.animation { } else { var timelineMode : Vector. = from.timelineMode; var timelineHoldMix : Vector. = from.timelineHoldMix; - + var firstFrame : Boolean = from.timelinesRotation.length == 0; if (firstFrame) from.timelinesRotation.length = timelineCount << 1; var timelinesRotation : Vector. = from.timelinesRotation; - + from.totalAlpha = 0; for (i = 0; i < timelineCount; i++) { var timeline : Timeline = timelines[i]; @@ -264,7 +264,7 @@ package spine.animation { alpha = alphaHold; break; default: - timelineBlend = MixBlend.setup; + timelineBlend = MixBlend.setup; var holdMix : TrackEntry = timelineHoldMix[i]; alpha = alphaHold * Math.max(0, 1 - holdMix.mixTime / holdMix.mixDuration); break; @@ -272,7 +272,7 @@ package spine.animation { from.totalAlpha += alpha; if (timeline is RotateTimeline) applyRotateTimeline(timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i << 1, firstFrame); - else { + else { if (timelineBlend == MixBlend.setup) { if (timeline is AttachmentTimeline) { if (attachments || ((timelineMode[i] & NOT_LAST) == NOT_LAST)) direction = MixDirection.In; @@ -282,14 +282,14 @@ package spine.animation { } timeline.apply(skeleton, animationLast, animationTime, events, alpha, timelineBlend, direction); } - } - } - + } + } + if (to.mixDuration > 0) queueEvents(from, animationTime); this.events.length = 0; from.nextAnimationLast = animationTime; from.nextTrackLast = from.trackTime; - + return mix; } @@ -315,8 +315,8 @@ package spine.animation { case MixBlend.first: r1 = bone.rotation; r2 = bone.data.rotation; - } - } else { + } + } else { r1 = blend == MixBlend.setup ? bone.data.rotation : bone.rotation; if (time >= frames[frames.length - RotateTimeline.ENTRIES]) // Time is after last frame. r2 = bone.data.rotation + frames[frames.length + RotateTimeline.PREV_ROTATION]; @@ -326,7 +326,7 @@ package spine.animation { var prevRotation : Number = frames[frame + RotateTimeline.PREV_ROTATION]; var frameTime : Number = frames[frame]; var percent : Number = rotateTimeline.getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + RotateTimeline.PREV_TIME] - frameTime)); - + r2 = frames[frame + RotateTimeline.ROTATION] - prevRotation; r2 -= (16384 - int((16384.499999999996 - r2 / 360))) * 360; r2 = prevRotation + r2 * percent + bone.data.rotation; @@ -334,12 +334,12 @@ package spine.animation { } } - // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. + // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. var total : Number, diff : Number = r2 - r1; diff -= (16384 - int((16384.499999999996 - diff / 360))) * 360; if (diff == 0) { total = timelinesRotation[i]; - } else { + } else { var lastTotal : Number, lastDiff : Number; if (firstFrame) { lastTotal = 0; @@ -378,8 +378,8 @@ package spine.animation { if (event.time < trackLastWrapped) break; if (event.time > animationEnd) continue; // Discard events outside animation start/end. queue.event(entry, event); - } - + } + // Queue complete if completed a loop iteration or the animation. var complete:Boolean; if (entry.loop) @@ -433,20 +433,20 @@ package spine.animation { private function setCurrent(index : int, current : TrackEntry, interrupt : Boolean) : void { var from : TrackEntry = expandToIndex(index); tracks[index] = current; - + if (from != null) { if (interrupt) queue.interrupt(from); current.mixingFrom = from; from.mixingTo = current; current.mixTime = 0; - + // Store the interrupted mix percentage. if (from.mixingFrom != null && from.mixDuration > 0) current.interruptAlpha *= Math.min(1, from.mixTime / from.mixDuration); - + from.timelinesRotation.length = 0; // Reset rotation for mixing out, in case entry was mixed in. } - + queue.start(current); } @@ -504,9 +504,9 @@ package spine.animation { var duration : Number = last.animationEnd - last.animationStart; if (duration != 0) { if (last.loop) - delay += duration * (1 + (int)(last.trackTime / duration)); + delay += duration * (1 + (int)(last.trackTime / duration)); else - delay += Math.max(duration, last.trackTime); + delay += Math.max(duration, last.trackTime); } else delay = last.trackTime; } @@ -590,7 +590,7 @@ package spine.animation { private function _animationsChanged() : void { animationsChanged = false; - propertyIDs = new Dictionary(); + propertyIDs = new Dictionary(); var i : int = 0; var n: int = 0; var entry : TrackEntry = null; @@ -601,7 +601,7 @@ package spine.animation { entry = entry.mixingFrom; do { if (entry.mixingTo == null || entry.mixBlend != MixBlend.add) computeHold(entry); - entry = entry.mixingTo; + entry = entry.mixingTo; } while (entry != null); } @@ -614,7 +614,7 @@ package spine.animation { } } } - + private function computeNotLast (entry: TrackEntry) : void { var timelines : Vector. = entry.animation.timelines; var timelinesCount : int = entry.animation.timelines.length; @@ -636,19 +636,19 @@ package spine.animation { } private function computeHold (entry: TrackEntry) : void { - var to: TrackEntry = entry.mixingTo; + var to: TrackEntry = entry.mixingTo; var timelines : Vector. = entry.animation.timelines; var timelinesCount : int = entry.animation.timelines.length; var timelineMode : Vector. = entry.timelineMode; - timelineMode.length = timelinesCount; + timelineMode.length = timelinesCount; var timelineHoldMix : Vector. = entry.timelineHoldMix; timelineHoldMix.length = 0; var propertyIDs: Dictionary = this.propertyIDs; - + var i : int = 0; if (to != null && to.holdPrevious) { for (i = 0; i < timelinesCount; i++) { - propertyIDs[timelines[i].getPropertyId().toString()] = true; + propertyIDs[timelines[i].getPropertyId().toString()] = true; timelineMode[i] = HOLD; } return; @@ -658,7 +658,7 @@ package spine.animation { for (i = 0; i < timelinesCount; i++) { var timeline : Timeline = Timeline(timelines[i]); var intId : int = timeline.getPropertyId(); - var id : String = intId.toString(); + var id : String = intId.toString(); var contained: Object = propertyIDs[id]; propertyIDs[id] = true; if (contained != null) { @@ -666,11 +666,11 @@ package spine.animation { } else if (to == null || timeline is AttachmentTimeline || timeline is DrawOrderTimeline || timeline is EventTimeline || !hasTimeline(to, intId)) { timelineMode[i] = AnimationState.FIRST; - } else { + } else { for (var next : TrackEntry = to.mixingTo; next != null; next = next.mixingTo) { if (hasTimeline(next, intId)) continue; if (entry.mixDuration > 0) { - timelineMode[i] = AnimationState.HOLD_MIX; + timelineMode[i] = AnimationState.HOLD_MIX; timelineHoldMix[i] = entry; continue outer; } @@ -678,7 +678,7 @@ package spine.animation { } timelineMode[i] = AnimationState.HOLD; } - } + } } private static function hasTimeline (entry: TrackEntry, id : int) : Boolean { diff --git a/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as b/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as index 37f20b4be..ee1153871 100644 --- a/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/DeformTimeline.as @@ -34,7 +34,7 @@ package spine.animation { import spine.Skeleton; import spine.Slot; - public class DeformTimeline extends CurveTimeline { + public class DeformTimeline extends CurveTimeline { public var slotIndex : int; public var frames : Vector.; public var frameVertices : Vector.>; @@ -63,16 +63,16 @@ package spine.animation { if (!slot.bone.active) return; var slotAttachment : Attachment = slot.attachment; if (!(slotAttachment is VertexAttachment) || !(VertexAttachment(slotAttachment).deformAttachment == attachment)) return; - + var deformArray : Vector. = slot.deform; if (deformArray.length == 0) blend = MixBlend.setup; - + var frameVertices : Vector.> = this.frameVertices; var vertexCount : int = frameVertices[0].length; var deform : Vector.; var frames : Vector. = this.frames; - var i : int; + var i : int; if (time < frames[0]) { vertexAttachment = VertexAttachment(slotAttachment); switch (blend) { @@ -99,27 +99,27 @@ package spine.animation { } } return; - } + } deformArray.length = vertexCount; deform = deformArray; - var n : int; + var n : int; var setup : Number, prev : Number; if (time >= frames[frames.length - 1]) { // Time is after last frame. var lastVertices : Vector. = frameVertices[frames.length - 1]; if (alpha == 1) { if (blend == MixBlend.add) { vertexAttachment = VertexAttachment(slotAttachment); - if (vertexAttachment.bones == null) { + if (vertexAttachment.bones == null) { setupVertices = vertexAttachment.vertices; - for (i = 0; i < vertexCount; i++) { + for (i = 0; i < vertexCount; i++) { deform[i] += lastVertices[i] - setupVertices[i]; } - } else { + } else { for (i = 0; i < vertexCount; i++) deform[i] += lastVertices[i]; } - } else { + } else { for (i = 0, n = vertexCount; i < n; i++) deform[i] = lastVertices[i]; } @@ -146,16 +146,16 @@ package spine.animation { deform[i] += (lastVertices[i] - deform[i]) * alpha; case MixBlend.add: vertexAttachment = VertexAttachment(slotAttachment); - if (vertexAttachment.bones == null) { + if (vertexAttachment.bones == null) { setupVertices = vertexAttachment.vertices; - for (i = 0; i < vertexCount; i++) { + for (i = 0; i < vertexCount; i++) { deform[i] += (lastVertices[i] - setupVertices[i]) * alpha; } } else { for (i = 0; i < vertexCount; i++) deform[i] += lastVertices[i] * alpha; - } - } + } + } } return; } @@ -170,20 +170,20 @@ package spine.animation { if (alpha == 1) { if (blend == MixBlend.add) { vertexAttachment = VertexAttachment(slotAttachment); - if (vertexAttachment.bones == null) { + if (vertexAttachment.bones == null) { setupVertices = vertexAttachment.vertices; for (i = 0; i < vertexCount; i++) { prev = prevVertices[i]; deform[i] += prev + (nextVertices[i] - prev) * percent - setupVertices[i]; } - } else { + } else { for (i = 0; i < vertexCount; i++) { - prev = prevVertices[i]; + prev = prevVertices[i]; deform[i] += prev + (nextVertices[i] - prev) * percent; } } - } else { - for (i = 0; i < vertexCount; i++) { + } else { + for (i = 0; i < vertexCount; i++) { prev = prevVertices[i]; deform[i] = prev + (nextVertices[i] - prev) * percent; } @@ -216,19 +216,19 @@ package spine.animation { break; case MixBlend.add: vertexAttachment = VertexAttachment(slotAttachment); - if (vertexAttachment.bones == null) { + if (vertexAttachment.bones == null) { setupVertices = vertexAttachment.vertices; for (i = 0; i < vertexCount; i++) { prev = prevVertices[i], setup = setupVertices[i]; deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; } - } else { + } else { for (i = 0; i < vertexCount; i++) { prev = prevVertices[i]; deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; } } - } + } } } } diff --git a/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as b/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as index a2fd57c79..34609a801 100644 --- a/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/IkConstraintTimeline.as @@ -94,7 +94,7 @@ package spine.animation { constraint.bendDirection = int(frames[frames.length + PREV_BEND_DIRECTION]); constraint.compress = int(frames[frames.length + PREV_COMPRESS]) != 0; constraint.stretch = int(frames[frames.length + PREV_STRETCH]) != 0; - } + } } else { constraint.mix += (frames[frames.length + PREV_MIX] - constraint.mix) * alpha; constraint.softness += (frames[frames.length + PREV_SOFTNESS] - constraint.softness) * alpha; @@ -121,12 +121,12 @@ package spine.animation { if (direction == MixDirection.Out) { constraint.bendDirection = constraint.data.bendDirection; constraint.compress = constraint.data.compress; - constraint.stretch = constraint.data.stretch; + constraint.stretch = constraint.data.stretch; } else { constraint.bendDirection = int(frames[frame + PREV_BEND_DIRECTION]); constraint.compress = int(frames[frame + PREV_COMPRESS]) != 0; constraint.stretch = int(frames[frame + PREV_STRETCH]) != 0; - } + } } else { constraint.mix += (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha; constraint.softness += (softness + (frames[frame + SOFTNESS] - softness) * percent - constraint.softness) * alpha; diff --git a/spine-as3/spine-as3/src/spine/animation/MixDirection.as b/spine-as3/spine-as3/src/spine/animation/MixDirection.as index bb037f9bc..71d1d8995 100644 --- a/spine-as3/spine-as3/src/spine/animation/MixDirection.as +++ b/spine-as3/spine-as3/src/spine/animation/MixDirection.as @@ -36,6 +36,6 @@ package spine.animation { } public static const In : MixDirection = new MixDirection(0); - public static const Out : MixDirection = new MixDirection(1); + public static const Out : MixDirection = new MixDirection(1); } } diff --git a/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as b/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as index b0e23f006..a0a0749ff 100644 --- a/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/RotateTimeline.as @@ -85,7 +85,7 @@ package spine.animation { r -= (16384 - int((16384.499999999996 - r / 360))) * 360; // Wrap within -180 and 180. case MixBlend.add: bone.rotation += r * alpha; - } + } return; } @@ -96,16 +96,16 @@ package spine.animation { var percent : Number = getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); r = frames[frame + ROTATION] - prevRotation; - r = prevRotation + (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * percent; + r = prevRotation + (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * percent; switch (blend) { - case MixBlend.setup: + case MixBlend.setup: bone.rotation = bone.data.rotation + (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * alpha; break; case MixBlend.first: case MixBlend.replace: - r += bone.data.rotation - bone.rotation; + r += bone.data.rotation - bone.rotation; case MixBlend.add: - bone.rotation += (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * alpha; + bone.rotation += (r - (16384 - int((16384.499999999996 - r / 360))) * 360) * alpha; } } } diff --git a/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as b/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as index c874b0514..8a6dd6379 100644 --- a/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as +++ b/spine-as3/spine-as3/src/spine/animation/ScaleTimeline.as @@ -78,7 +78,7 @@ package spine.animation { if (alpha == 1) { if (blend == MixBlend.add) { bone.scaleX += x - bone.data.scaleX; - bone.scaleY += y - bone.data.scaleY; + bone.scaleY += y - bone.data.scaleY; } else { bone.scaleX = x; bone.scaleY = y; diff --git a/spine-as3/spine-as3/src/spine/animation/TrackEntry.as b/spine-as3/spine-as3/src/spine/animation/TrackEntry.as index 8bb872f90..8d03e88c5 100644 --- a/spine-as3/spine-as3/src/spine/animation/TrackEntry.as +++ b/spine-as3/spine-as3/src/spine/animation/TrackEntry.as @@ -77,7 +77,7 @@ package spine.animation { timelineMode.length = 0; timelineHoldMix.length = 0; timelinesRotation.length = 0; - } + } public function resetRotationDirection() : void { timelinesRotation.length = 0; diff --git a/spine-c/spine-c-unit-tests/README.md b/spine-c/spine-c-unit-tests/README.md index 825d7e1df..8c0f3626a 100755 --- a/spine-c/spine-c-unit-tests/README.md +++ b/spine-c/spine-c-unit-tests/README.md @@ -25,7 +25,7 @@ Depending on the test agent build environment, you should build the output solut ### Test Runner Build Step This build step should not execute if the previous step did not successfully complete. -Again, depending on the test agent build environment, you should have produced an executable. Run this executable. +Again, depending on the test agent build environment, you should have produced an executable. Run this executable. ## Usage diff --git a/spine-c/spine-c-unit-tests/main.cpp b/spine-c/spine-c-unit-tests/main.cpp index bd013f6ea..bfa78deb0 100755 --- a/spine-c/spine-c-unit-tests/main.cpp +++ b/spine-c/spine-c-unit-tests/main.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) -extern "C" { // probably unnecessary +extern "C" { // probably unnecessary void _spAtlasPage_createTexture(spAtlasPage* self, const char* path) { self->rendererObject = 0; diff --git a/spine-c/spine-c/include/spine/Array.h b/spine-c/spine-c/include/spine/Array.h index f98457a62..3b873b590 100644 --- a/spine-c/spine-c/include/spine/Array.h +++ b/spine-c/spine-c/include/spine/Array.h @@ -81,8 +81,8 @@ extern "C" { } \ void name##_add(name* self, itemType value) { \ if (self->size == self->capacity) { \ - self->capacity = MAX(8, (int)(self->size * 1.75f)); \ - self->items = REALLOC(self->items, itemType, self->capacity); \ + self->capacity = MAX(8, (int)(self->size * 1.75f)); \ + self->items = REALLOC(self->items, itemType, self->capacity); \ } \ self->items[self->size++] = value; \ } \ diff --git a/spine-c/spine-c/include/spine/AttachmentLoader.h b/spine-c/spine-c/include/spine/AttachmentLoader.h index 4effe88f1..e9bd5dbc2 100644 --- a/spine-c/spine-c/include/spine/AttachmentLoader.h +++ b/spine-c/spine-c/include/spine/AttachmentLoader.h @@ -45,9 +45,9 @@ typedef struct spAttachmentLoader { const void* const vtable; #ifdef __cplusplus spAttachmentLoader () : - error1(0), - error2(0), - vtable(0) { + error1(0), + error2(0), + vtable(0) { } #endif } spAttachmentLoader; diff --git a/spine-c/spine-c/include/spine/Skin.h b/spine-c/spine-c/include/spine/Skin.h index d4940beca..73e05f9e3 100644 --- a/spine-c/spine-c/include/spine/Skin.h +++ b/spine-c/spine-c/include/spine/Skin.h @@ -89,7 +89,7 @@ struct _SkinHashTableEntry { typedef struct { spSkin super; _Entry* entries; /* entries list stored for getting attachment name by attachment index */ - _SkinHashTableEntry* entriesHashTable[SKIN_ENTRIES_HASH_TABLE_SIZE]; /* hashtable for fast attachment lookup */ + _SkinHashTableEntry* entriesHashTable[SKIN_ENTRIES_HASH_TABLE_SIZE]; /* hashtable for fast attachment lookup */ } _spSkin; SP_API spSkin* spSkin_create (const char* name); diff --git a/spine-c/spine-c/include/spine/VertexEffect.h b/spine-c/spine-c/include/spine/VertexEffect.h index 3dfe246c4..148619676 100644 --- a/spine-c/spine-c/include/spine/VertexEffect.h +++ b/spine-c/spine-c/include/spine/VertexEffect.h @@ -43,7 +43,7 @@ struct spVertexEffect; typedef void (*spVertexEffectBegin)(struct spVertexEffect *self, spSkeleton *skeleton); typedef void (*spVertexEffectTransform)(struct spVertexEffect *self, float *x, float *y, float *u, float *v, - spColor *light, spColor *dark); + spColor *light, spColor *dark); typedef void (*spVertexEffectEnd)(struct spVertexEffect *self); diff --git a/spine-c/spine-c/src/spine/Animation.c b/spine-c/spine-c/src/spine/Animation.c index e7a38286c..35a80e5ff 100644 --- a/spine-c/spine-c/src/spine/Animation.c +++ b/spine-c/spine-c/src/spine/Animation.c @@ -50,7 +50,8 @@ void spAnimation_dispose (spAnimation* self) { } void spAnimation_apply (const spAnimation* self, spSkeleton* skeleton, float lastTime, float time, int loop, spEvent** events, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int i, n = self->timelinesCount; if (loop && self->duration) { @@ -66,15 +67,17 @@ void spAnimation_apply (const spAnimation* self, spSkeleton* skeleton, float las typedef struct _spTimelineVtable { void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction); + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction); int (*getPropertyId) (const spTimeline* self); void (*dispose) (spTimeline* self); } _spTimelineVtable; void _spTimeline_init (spTimeline* self, spTimelineType type, /**/ - void (*dispose) (spTimeline* self), /**/ - void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction), - int (*getPropertyId) (const spTimeline* self)) { + void (*dispose) (spTimeline* self), /**/ + void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction), + int (*getPropertyId) (const spTimeline* self) +) { CONST_CAST(spTimelineType, self->type) = type; CONST_CAST(_spTimelineVtable*, self->vtable) = NEW(_spTimelineVtable); VTABLE(spTimeline, self)->dispose = dispose; @@ -105,9 +108,11 @@ static const float CURVE_LINEAR = 0, CURVE_STEPPED = 1, CURVE_BEZIER = 2; static const int BEZIER_SIZE = 10 * 2 - 1; void _spCurveTimeline_init (spCurveTimeline* self, spTimelineType type, int framesCount, /**/ - void (*dispose) (spTimeline* self), /**/ - void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction), - int (*getPropertyId)(const spTimeline* self)) { + void (*dispose) (spTimeline* self), /**/ + void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction), + int (*getPropertyId)(const spTimeline* self) +) { _spTimeline_init(SUPER(self), type, dispose, apply, getPropertyId); self->curves = CALLOC(float, (framesCount - 1) * BEZIER_SIZE); } @@ -223,9 +228,10 @@ void _spBaseTimeline_dispose (spTimeline* timeline) { /* Many timelines have structure identical to struct spBaseTimeline and extend spCurveTimeline. **/ struct spBaseTimeline* _spBaseTimeline_create (int framesCount, spTimelineType type, int frameSize, /**/ - void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction), - int (*getPropertyId) (const spTimeline* self)) { + void (*apply) (const spTimeline* self, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction), + int (*getPropertyId) (const spTimeline* self) +) { struct spBaseTimeline* self = NEW(struct spBaseTimeline); _spCurveTimeline_init(SUPER(self), type, framesCount, _spBaseTimeline_dispose, apply, getPropertyId); @@ -238,7 +244,8 @@ struct spBaseTimeline* _spBaseTimeline_create (int framesCount, spTimelineType t /**/ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { spBone *bone; int frame; float prevRotation, frameTime, percent, r; @@ -248,16 +255,16 @@ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, if (!bone->active) return; if (time < self->frames[0]) { switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->rotation = bone->data->rotation; - return; - case SP_MIX_BLEND_FIRST: - r = bone->data->rotation - bone->rotation; - r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; - bone->rotation += r * alpha; - case SP_MIX_BLEND_REPLACE: - case SP_MIX_BLEND_ADD: - ; /* to appease compiler */ + case SP_MIX_BLEND_SETUP: + bone->rotation = bone->data->rotation; + return; + case SP_MIX_BLEND_FIRST: + r = bone->data->rotation - bone->rotation; + r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; + bone->rotation += r * alpha; + case SP_MIX_BLEND_REPLACE: + case SP_MIX_BLEND_ADD: + ; /* to appease compiler */ } return; } @@ -265,15 +272,15 @@ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, if (time >= self->frames[self->framesCount - ROTATE_ENTRIES]) { /* Time is after last frame. */ r = self->frames[self->framesCount + ROTATE_PREV_ROTATION]; switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->rotation = bone->data->rotation + r * alpha; - break; - case SP_MIX_BLEND_FIRST: - case SP_MIX_BLEND_REPLACE: - r += bone->data->rotation - bone->rotation; - r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; /* Wrap within -180 and 180. */ - case SP_MIX_BLEND_ADD: - bone->rotation += r * alpha; + case SP_MIX_BLEND_SETUP: + bone->rotation = bone->data->rotation + r * alpha; + break; + case SP_MIX_BLEND_FIRST: + case SP_MIX_BLEND_REPLACE: + r += bone->data->rotation - bone->rotation; + r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; /* Wrap within -180 and 180. */ + case SP_MIX_BLEND_ADD: + bone->rotation += r * alpha; } return; } @@ -287,14 +294,14 @@ void _spRotateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, r = self->frames[frame + ROTATE_ROTATION] - prevRotation; r = prevRotation + (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * percent; switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->rotation = bone->data->rotation + (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * alpha; - break; - case SP_MIX_BLEND_FIRST: - case SP_MIX_BLEND_REPLACE: - r += bone->data->rotation - bone->rotation; - case SP_MIX_BLEND_ADD: - bone->rotation += (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * alpha; + case SP_MIX_BLEND_SETUP: + bone->rotation = bone->data->rotation + (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * alpha; + break; + case SP_MIX_BLEND_FIRST: + case SP_MIX_BLEND_REPLACE: + r += bone->data->rotation - bone->rotation; + case SP_MIX_BLEND_ADD: + bone->rotation += (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * alpha; } UNUSED(lastTime); @@ -323,7 +330,8 @@ static const int TRANSLATE_PREV_TIME = -3, TRANSLATE_PREV_X = -2, TRANSLATE_PREV static const int TRANSLATE_X = 1, TRANSLATE_Y = 2; void _spTranslateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, - spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { spBone *bone; int frame; float frameTime, percent; @@ -337,16 +345,16 @@ void _spTranslateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleto if (!bone->active) return; if (time < self->frames[0]) { switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->x = bone->data->x; - bone->y = bone->data->y; - return; - case SP_MIX_BLEND_FIRST: - bone->x += (bone->data->x - bone->x) * alpha; - bone->y += (bone->data->y - bone->y) * alpha; - case SP_MIX_BLEND_REPLACE: - case SP_MIX_BLEND_ADD: - ; /* to appease compiler */ + case SP_MIX_BLEND_SETUP: + bone->x = bone->data->x; + bone->y = bone->data->y; + return; + case SP_MIX_BLEND_FIRST: + bone->x += (bone->data->x - bone->x) * alpha; + bone->y += (bone->data->y - bone->y) * alpha; + case SP_MIX_BLEND_REPLACE: + case SP_MIX_BLEND_ADD: + ; /* to appease compiler */ } return; } @@ -363,24 +371,24 @@ void _spTranslateTimeline_apply (const spTimeline* timeline, spSkeleton* skeleto y = frames[frame + TRANSLATE_PREV_Y]; frameTime = frames[frame]; percent = spCurveTimeline_getCurvePercent(SUPER(self), frame / TRANSLATE_ENTRIES - 1, - 1 - (time - frameTime) / (frames[frame + TRANSLATE_PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (frames[frame + TRANSLATE_PREV_TIME] - frameTime)); x += (frames[frame + TRANSLATE_X] - x) * percent; y += (frames[frame + TRANSLATE_Y] - y) * percent; } switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->x = bone->data->x + x * alpha; - bone->y = bone->data->y + y * alpha; - break; - case SP_MIX_BLEND_FIRST: - case SP_MIX_BLEND_REPLACE: - bone->x += (bone->data->x + x - bone->x) * alpha; - bone->y += (bone->data->y + y - bone->y) * alpha; - break; - case SP_MIX_BLEND_ADD: - bone->x += x * alpha; - bone->y += y * alpha; + case SP_MIX_BLEND_SETUP: + bone->x = bone->data->x + x * alpha; + bone->y = bone->data->y + y * alpha; + break; + case SP_MIX_BLEND_FIRST: + case SP_MIX_BLEND_REPLACE: + bone->x += (bone->data->x + x - bone->x) * alpha; + bone->y += (bone->data->y + y - bone->y) * alpha; + break; + case SP_MIX_BLEND_ADD: + bone->x += x * alpha; + bone->y += y * alpha; } UNUSED(lastTime); @@ -407,7 +415,8 @@ void spTranslateTimeline_setFrame (spTranslateTimeline* self, int frameIndex, fl /**/ void _spScaleTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { spBone *bone; int frame; float frameTime, percent, x, y; @@ -420,16 +429,16 @@ void _spScaleTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f if (!bone->active) return; if (time < self->frames[0]) { switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->scaleX = bone->data->scaleX; - bone->scaleY = bone->data->scaleY; - return; - case SP_MIX_BLEND_FIRST: - bone->scaleX += (bone->data->scaleX - bone->scaleX) * alpha; - bone->scaleY += (bone->data->scaleY - bone->scaleY) * alpha; - case SP_MIX_BLEND_REPLACE: - case SP_MIX_BLEND_ADD: - ; /* to appease compiler */ + case SP_MIX_BLEND_SETUP: + bone->scaleX = bone->data->scaleX; + bone->scaleY = bone->data->scaleY; + return; + case SP_MIX_BLEND_FIRST: + bone->scaleX += (bone->data->scaleX - bone->scaleX) * alpha; + bone->scaleY += (bone->data->scaleY - bone->scaleY) * alpha; + case SP_MIX_BLEND_REPLACE: + case SP_MIX_BLEND_ADD: + ; /* to appease compiler */ } return; } @@ -446,7 +455,7 @@ void _spScaleTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f y = frames[frame + TRANSLATE_PREV_Y]; frameTime = frames[frame]; percent = spCurveTimeline_getCurvePercent(SUPER(self), frame / TRANSLATE_ENTRIES - 1, - 1 - (time - frameTime) / (frames[frame + TRANSLATE_PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (frames[frame + TRANSLATE_PREV_TIME] - frameTime)); x = (x + (frames[frame + TRANSLATE_X] - x) * percent) * bone->data->scaleX; y = (y + (frames[frame + TRANSLATE_Y] - y) * percent) * bone->data->scaleY; @@ -463,45 +472,45 @@ void _spScaleTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f float bx, by; if (direction == SP_MIX_DIRECTION_OUT) { switch (blend) { - case SP_MIX_BLEND_SETUP: - bx = bone->data->scaleX; - by = bone->data->scaleY; - bone->scaleX = bx + (ABS(x) * SIGNUM(bx) - bx) * alpha; - bone->scaleY = by + (ABS(y) * SIGNUM(by) - by) * alpha; - break; - case SP_MIX_BLEND_FIRST: - case SP_MIX_BLEND_REPLACE: - bx = bone->scaleX; - by = bone->scaleY; - bone->scaleX = bx + (ABS(x) * SIGNUM(bx) - bx) * alpha; - bone->scaleY = by + (ABS(y) * SIGNUM(by) - by) * alpha; - break; - case SP_MIX_BLEND_ADD: - bx = bone->scaleX; - by = bone->scaleY; - bone->scaleX = bx + (ABS(x) * SIGNUM(bx) - bone->data->scaleX) * alpha; - bone->scaleY = by + (ABS(y) * SIGNUM(by) - bone->data->scaleY) * alpha; + case SP_MIX_BLEND_SETUP: + bx = bone->data->scaleX; + by = bone->data->scaleY; + bone->scaleX = bx + (ABS(x) * SIGNUM(bx) - bx) * alpha; + bone->scaleY = by + (ABS(y) * SIGNUM(by) - by) * alpha; + break; + case SP_MIX_BLEND_FIRST: + case SP_MIX_BLEND_REPLACE: + bx = bone->scaleX; + by = bone->scaleY; + bone->scaleX = bx + (ABS(x) * SIGNUM(bx) - bx) * alpha; + bone->scaleY = by + (ABS(y) * SIGNUM(by) - by) * alpha; + break; + case SP_MIX_BLEND_ADD: + bx = bone->scaleX; + by = bone->scaleY; + bone->scaleX = bx + (ABS(x) * SIGNUM(bx) - bone->data->scaleX) * alpha; + bone->scaleY = by + (ABS(y) * SIGNUM(by) - bone->data->scaleY) * alpha; } } else { switch (blend) { - case SP_MIX_BLEND_SETUP: - bx = ABS(bone->data->scaleX) * SIGNUM(x); - by = ABS(bone->data->scaleY) * SIGNUM(y); - bone->scaleX = bx + (x - bx) * alpha; - bone->scaleY = by + (y - by) * alpha; - break; - case SP_MIX_BLEND_FIRST: - case SP_MIX_BLEND_REPLACE: - bx = ABS(bone->scaleX) * SIGNUM(x); - by = ABS(bone->scaleY) * SIGNUM(y); - bone->scaleX = bx + (x - bx) * alpha; - bone->scaleY = by + (y - by) * alpha; - break; - case SP_MIX_BLEND_ADD: - bx = SIGNUM(x); - by = SIGNUM(y); - bone->scaleX = ABS(bone->scaleX) * bx + (x - ABS(bone->data->scaleX) * bx) * alpha; - bone->scaleY = ABS(bone->scaleY) * by + (y - ABS(bone->data->scaleY) * by) * alpha; + case SP_MIX_BLEND_SETUP: + bx = ABS(bone->data->scaleX) * SIGNUM(x); + by = ABS(bone->data->scaleY) * SIGNUM(y); + bone->scaleX = bx + (x - bx) * alpha; + bone->scaleY = by + (y - by) * alpha; + break; + case SP_MIX_BLEND_FIRST: + case SP_MIX_BLEND_REPLACE: + bx = ABS(bone->scaleX) * SIGNUM(x); + by = ABS(bone->scaleY) * SIGNUM(y); + bone->scaleX = bx + (x - bx) * alpha; + bone->scaleY = by + (y - by) * alpha; + break; + case SP_MIX_BLEND_ADD: + bx = SIGNUM(x); + by = SIGNUM(y); + bone->scaleX = ABS(bone->scaleX) * bx + (x - ABS(bone->data->scaleX) * bx) * alpha; + bone->scaleY = ABS(bone->scaleY) * by + (y - ABS(bone->data->scaleY) * by) * alpha; } } } @@ -526,7 +535,8 @@ void spScaleTimeline_setFrame (spScaleTimeline* self, int frameIndex, float time /**/ void _spShearTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { spBone *bone; int frame; float frameTime, percent, x, y; @@ -541,16 +551,16 @@ void _spShearTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f framesCount = self->framesCount; if (time < self->frames[0]) { switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->shearX = bone->data->shearX; - bone->shearY = bone->data->shearY; - return; - case SP_MIX_BLEND_FIRST: - bone->shearX += (bone->data->shearX - bone->shearX) * alpha; - bone->shearY += (bone->data->shearY - bone->shearY) * alpha; - case SP_MIX_BLEND_REPLACE: - case SP_MIX_BLEND_ADD: - ; /* to appease compiler */ + case SP_MIX_BLEND_SETUP: + bone->shearX = bone->data->shearX; + bone->shearY = bone->data->shearY; + return; + case SP_MIX_BLEND_FIRST: + bone->shearX += (bone->data->shearX - bone->shearX) * alpha; + bone->shearY += (bone->data->shearY - bone->shearY) * alpha; + case SP_MIX_BLEND_REPLACE: + case SP_MIX_BLEND_ADD: + ; /* to appease compiler */ } return; } @@ -565,24 +575,24 @@ void _spShearTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f y = frames[frame + TRANSLATE_PREV_Y]; frameTime = frames[frame]; percent = spCurveTimeline_getCurvePercent(SUPER(self), frame / TRANSLATE_ENTRIES - 1, - 1 - (time - frameTime) / (frames[frame + TRANSLATE_PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (frames[frame + TRANSLATE_PREV_TIME] - frameTime)); x = x + (frames[frame + TRANSLATE_X] - x) * percent; y = y + (frames[frame + TRANSLATE_Y] - y) * percent; } switch (blend) { - case SP_MIX_BLEND_SETUP: - bone->shearX = bone->data->shearX + x * alpha; - bone->shearY = bone->data->shearY + y * alpha; - break; - case SP_MIX_BLEND_FIRST: - case SP_MIX_BLEND_REPLACE: - bone->shearX += (bone->data->shearX + x - bone->shearX) * alpha; - bone->shearY += (bone->data->shearY + y - bone->shearY) * alpha; - break; - case SP_MIX_BLEND_ADD: - bone->shearX += x * alpha; - bone->shearY += y * alpha; + case SP_MIX_BLEND_SETUP: + bone->shearX = bone->data->shearX + x * alpha; + bone->shearY = bone->data->shearY + y * alpha; + break; + case SP_MIX_BLEND_FIRST: + case SP_MIX_BLEND_REPLACE: + bone->shearX += (bone->data->shearX + x - bone->shearX) * alpha; + bone->shearY += (bone->data->shearY + y - bone->shearY) * alpha; + break; + case SP_MIX_BLEND_ADD: + bone->shearX += x * alpha; + bone->shearY += y * alpha; } UNUSED(lastTime); @@ -609,7 +619,8 @@ static const int COLOR_PREV_TIME = -5, COLOR_PREV_R = -4, COLOR_PREV_G = -3, COL static const int COLOR_R = 1, COLOR_G = 2, COLOR_B = 3, COLOR_A = 4; void _spColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { spSlot *slot; int frame; float percent, frameTime; @@ -622,17 +633,17 @@ void _spColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f if (time < self->frames[0]) { switch (blend) { - case SP_MIX_BLEND_SETUP: - spColor_setFromColor(&slot->color, &slot->data->color); - return; - case SP_MIX_BLEND_FIRST: - color = &slot->color; - setup = &slot->data->color; - spColor_addFloats(color, (setup->r - color->r) * alpha, (setup->g - color->g) * alpha, (setup->b - color->b) * alpha, - (setup->a - color->a) * alpha); - case SP_MIX_BLEND_REPLACE: - case SP_MIX_BLEND_ADD: - ; /* to appease compiler */ + case SP_MIX_BLEND_SETUP: + spColor_setFromColor(&slot->color, &slot->data->color); + return; + case SP_MIX_BLEND_FIRST: + color = &slot->color; + setup = &slot->data->color; + spColor_addFloats(color, (setup->r - color->r) * alpha, (setup->g - color->g) * alpha, (setup->b - color->b) * alpha, + (setup->a - color->a) * alpha); + case SP_MIX_BLEND_REPLACE: + case SP_MIX_BLEND_ADD: + ; /* to appease compiler */ } return; } @@ -664,9 +675,7 @@ void _spColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f if (alpha == 1) { spColor_setFromFloats(&slot->color, r, g, b, a); } else { - if (blend == SP_MIX_BLEND_SETUP) { - spColor_setFromColor(&slot->color, &slot->data->color); - } + if (blend == SP_MIX_BLEND_SETUP) spColor_setFromColor(&slot->color, &slot->data->color); spColor_addFloats(&slot->color, (r - slot->color.r) * alpha, (g - slot->color.g) * alpha, (b - slot->color.b) * alpha, (a - slot->color.a) * alpha); } @@ -700,7 +709,8 @@ static const int TWOCOLOR_PREV_R2 = -3, TWOCOLOR_PREV_G2 = -2, TWOCOLOR_PREV_B2 static const int TWOCOLOR_R = 1, TWOCOLOR_G = 2, TWOCOLOR_B = 3, TWOCOLOR_A = 4, TWOCOLOR_R2 = 5, TWOCOLOR_G2 = 6, TWOCOLOR_B2 = 7; void _spTwoColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { spSlot *slot; int frame; float percent, frameTime; @@ -715,21 +725,21 @@ void _spTwoColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton if (time < self->frames[0]) { switch (blend) { - case SP_MIX_BLEND_SETUP: - spColor_setFromColor(&slot->color, &slot->data->color); - spColor_setFromColor(slot->darkColor, slot->data->darkColor); - return; - case SP_MIX_BLEND_FIRST: - light = &slot->color; - dark = slot->darkColor; - setupLight = &slot->data->color; - setupDark = slot->data->darkColor; - spColor_addFloats(light, (setupLight->r - light->r) * alpha, (setupLight->g - light->g) * alpha, (setupLight->b - light->b) * alpha, - (setupLight->a - light->a) * alpha); - spColor_addFloats(dark, (setupDark->r - dark->r) * alpha, (setupDark->g - dark->g) * alpha, (setupDark->b - dark->b) * alpha, 0); - case SP_MIX_BLEND_REPLACE: - case SP_MIX_BLEND_ADD: - ; /* to appease compiler */ + case SP_MIX_BLEND_SETUP: + spColor_setFromColor(&slot->color, &slot->data->color); + spColor_setFromColor(slot->darkColor, slot->data->darkColor); + return; + case SP_MIX_BLEND_FIRST: + light = &slot->color; + dark = slot->darkColor; + setupLight = &slot->data->color; + setupDark = slot->data->darkColor; + spColor_addFloats(light, (setupLight->r - light->r) * alpha, (setupLight->g - light->g) * alpha, (setupLight->b - light->b) * alpha, + (setupLight->a - light->a) * alpha); + spColor_addFloats(dark, (setupDark->r - dark->r) * alpha, (setupDark->g - dark->g) * alpha, (setupDark->b - dark->b) * alpha, 0); + case SP_MIX_BLEND_REPLACE: + case SP_MIX_BLEND_ADD: + ; /* to appease compiler */ } return; } @@ -757,7 +767,7 @@ void _spTwoColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton frameTime = self->frames[frame]; percent = spCurveTimeline_getCurvePercent(SUPER(self), frame / TWOCOLOR_ENTRIES - 1, - 1 - (time - frameTime) / (self->frames[frame + TWOCOLOR_PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (self->frames[frame + TWOCOLOR_PREV_TIME] - frameTime)); r += (self->frames[frame + TWOCOLOR_R] - r) * percent; g += (self->frames[frame + TWOCOLOR_G] - g) * percent; @@ -819,7 +829,7 @@ void _spAttachmentTimeline_apply (const spTimeline* timeline, spSkeleton* skelet if (direction == SP_MIX_DIRECTION_OUT && blend == SP_MIX_BLEND_SETUP) { attachmentName = slot->data->attachmentName; - spSlot_setAttachment(slot, attachmentName ? spSkeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0); + spSlot_setAttachment(slot, attachmentName ? spSkeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0); return; } @@ -827,7 +837,7 @@ void _spAttachmentTimeline_apply (const spTimeline* timeline, spSkeleton* skelet if (blend == SP_MIX_BLEND_SETUP || blend == SP_MIX_BLEND_FIRST) { attachmentName = slot->data->attachmentName; spSlot_setAttachment(skeleton->slots[self->slotIndex], - attachmentName ? spSkeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0); + attachmentName ? spSkeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0); } return; } @@ -839,7 +849,7 @@ void _spAttachmentTimeline_apply (const spTimeline* timeline, spSkeleton* skelet attachmentName = self->attachmentNames[frameIndex]; spSlot_setAttachment(skeleton->slots[self->slotIndex], - attachmentName ? spSkeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0); + attachmentName ? spSkeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0); UNUSED(lastTime); UNUSED(firedEvents); @@ -888,7 +898,8 @@ void spAttachmentTimeline_setFrame (spAttachmentTimeline* self, int frameIndex, /**/ void _spDeformTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int frame, i, vertexCount; float percent, frameTime; const float* prevVertices; @@ -1053,42 +1064,42 @@ void _spDeformTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, } else { spVertexAttachment* vertexAttachment; switch (blend) { - case SP_MIX_BLEND_SETUP: - vertexAttachment = SUB_CAST(spVertexAttachment, slot->attachment); - if (!vertexAttachment->bones) { - float *setupVertices = vertexAttachment->vertices; - for (i = 0; i < vertexCount; i++) { - float prev = prevVertices[i], setup = setupVertices[i]; - deformArray[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; - } - } else { - for (i = 0; i < vertexCount; i++) { - float prev = prevVertices[i]; - deformArray[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; - } + case SP_MIX_BLEND_SETUP: + vertexAttachment = SUB_CAST(spVertexAttachment, slot->attachment); + if (!vertexAttachment->bones) { + float *setupVertices = vertexAttachment->vertices; + for (i = 0; i < vertexCount; i++) { + float prev = prevVertices[i], setup = setupVertices[i]; + deformArray[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; } - break; - case SP_MIX_BLEND_FIRST: - case SP_MIX_BLEND_REPLACE: + } else { for (i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - deformArray[i] += (prev + (nextVertices[i] - prev) * percent - deformArray[i]) * alpha; + deformArray[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; } - break; - case SP_MIX_BLEND_ADD: - vertexAttachment = SUB_CAST(spVertexAttachment, slot->attachment); - if (!vertexAttachment->bones) { - float *setupVertices = vertexAttachment->vertices; - for (i = 0; i < vertexCount; i++) { - float prev = prevVertices[i]; - deformArray[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; - } - } else { - for (i = 0; i < vertexCount; i++) { - float prev = prevVertices[i]; - deformArray[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; - } + } + break; + case SP_MIX_BLEND_FIRST: + case SP_MIX_BLEND_REPLACE: + for (i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deformArray[i] += (prev + (nextVertices[i] - prev) * percent - deformArray[i]) * alpha; + } + break; + case SP_MIX_BLEND_ADD: + vertexAttachment = SUB_CAST(spVertexAttachment, slot->attachment); + if (!vertexAttachment->bones) { + float *setupVertices = vertexAttachment->vertices; + for (i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deformArray[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; } + } else { + for (i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deformArray[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; + } + } } } @@ -1142,7 +1153,8 @@ void spDeformTimeline_setFrame (spDeformTimeline* self, int frameIndex, float ti /** Fires events for frames > lastTime and <= time. */ void _spEventTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, - int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { spEventTimeline* self = (spEventTimeline*)timeline; int frame; if (!firedEvents) return; @@ -1211,7 +1223,8 @@ void spEventTimeline_setFrame (spEventTimeline* self, int frameIndex, spEvent* e /**/ void _spDrawOrderTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, - spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int i; int frame; const int* drawOrderToSetupIndex; @@ -1294,7 +1307,8 @@ static const int IKCONSTRAINT_PREV_TIME = -6, IKCONSTRAINT_PREV_MIX = -5, IKCONS static const int IKCONSTRAINT_MIX = 1, IKCONSTRAINT_SOFTNESS = 2, IKCONSTRAINT_BEND_DIRECTION = 3, IKCONSTRAINT_COMPRESS = 4, IKCONSTRAINT_STRETCH = 5; void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, - spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int frame; float frameTime, percent, mix, softness; float *frames; @@ -1333,7 +1347,7 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel if (blend == SP_MIX_BLEND_SETUP) { constraint->mix = constraint->data->mix + (frames[framesCount + IKCONSTRAINT_PREV_MIX] - constraint->data->mix) * alpha; constraint->softness = constraint->data->softness - + (frames[framesCount + IKCONSTRAINT_PREV_SOFTNESS] - constraint->data->softness) * alpha; + + (frames[framesCount + IKCONSTRAINT_PREV_SOFTNESS] - constraint->data->softness) * alpha; if (direction == SP_MIX_DIRECTION_OUT) { constraint->bendDirection = constraint->data->bendDirection; constraint->compress = constraint->data->compress; @@ -1365,7 +1379,7 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel if (blend == SP_MIX_BLEND_SETUP) { constraint->mix = constraint->data->mix + (mix + (frames[frame + IKCONSTRAINT_MIX] - mix) * percent - constraint->data->mix) * alpha; constraint->softness = constraint->data->softness - + (softness + (frames[frame + IKCONSTRAINT_SOFTNESS] - softness) * percent - constraint->data->softness) * alpha; + + (softness + (frames[frame + IKCONSTRAINT_SOFTNESS] - softness) * percent - constraint->data->softness) * alpha; if (direction == SP_MIX_DIRECTION_OUT) { constraint->bendDirection = constraint->data->bendDirection; constraint->compress = constraint->data->compress; @@ -1398,7 +1412,9 @@ spIkConstraintTimeline* spIkConstraintTimeline_create (int framesCount) { return (spIkConstraintTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_IKCONSTRAINT, IKCONSTRAINT_ENTRIES, _spIkConstraintTimeline_apply, _spIkConstraintTimeline_getPropertyId); } -void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameIndex, float time, float mix, float softness, int bendDirection, int /*boolean*/ compress, int /*boolean*/ stretch) { +void spIkConstraintTimeline_setFrame (spIkConstraintTimeline* self, int frameIndex, float time, float mix, float softness, + int bendDirection, int /*boolean*/ compress, int /*boolean*/ stretch +) { frameIndex *= IKCONSTRAINT_ENTRIES; self->frames[frameIndex] = time; self->frames[frameIndex + IKCONSTRAINT_MIX] = mix; @@ -1420,7 +1436,8 @@ static const int TRANSFORMCONSTRAINT_SCALE = 3; static const int TRANSFORMCONSTRAINT_SHEAR = 4; void _spTransformConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, - spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int frame; float frameTime, percent, rotate, translate, scale, shear; spTransformConstraint* constraint; @@ -1501,10 +1518,13 @@ int _spTransformConstraintTimeline_getPropertyId (const spTimeline* timeline) { } spTransformConstraintTimeline* spTransformConstraintTimeline_create (int framesCount) { - return (spTransformConstraintTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_TRANSFORMCONSTRAINT, TRANSFORMCONSTRAINT_ENTRIES, _spTransformConstraintTimeline_apply, _spTransformConstraintTimeline_getPropertyId); + return (spTransformConstraintTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_TRANSFORMCONSTRAINT, + TRANSFORMCONSTRAINT_ENTRIES, _spTransformConstraintTimeline_apply, _spTransformConstraintTimeline_getPropertyId); } -void spTransformConstraintTimeline_setFrame (spTransformConstraintTimeline* self, int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix) { +void spTransformConstraintTimeline_setFrame (spTransformConstraintTimeline* self, int frameIndex, float time, float rotateMix, + float translateMix, float scaleMix, float shearMix +) { frameIndex *= TRANSFORMCONSTRAINT_ENTRIES; self->frames[frameIndex] = time; self->frames[frameIndex + TRANSFORMCONSTRAINT_ROTATE] = rotateMix; @@ -1520,7 +1540,8 @@ static const int PATHCONSTRAINTPOSITION_PREV_VALUE = -1; static const int PATHCONSTRAINTPOSITION_VALUE = 1; void _spPathConstraintPositionTimeline_apply(const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, - spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int frame; float frameTime, percent, position; spPathConstraint* constraint; @@ -1575,7 +1596,8 @@ int _spPathConstraintPositionTimeline_getPropertyId (const spTimeline* timeline) } spPathConstraintPositionTimeline* spPathConstraintPositionTimeline_create (int framesCount) { - return (spPathConstraintPositionTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_PATHCONSTRAINTPOSITION, PATHCONSTRAINTPOSITION_ENTRIES, _spPathConstraintPositionTimeline_apply, _spPathConstraintPositionTimeline_getPropertyId); + return (spPathConstraintPositionTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_PATHCONSTRAINTPOSITION, + PATHCONSTRAINTPOSITION_ENTRIES, _spPathConstraintPositionTimeline_apply, _spPathConstraintPositionTimeline_getPropertyId); } void spPathConstraintPositionTimeline_setFrame (spPathConstraintPositionTimeline* self, int frameIndex, float time, float value) { @@ -1590,7 +1612,8 @@ static const int PATHCONSTRAINTSPACING_PREV_VALUE = -1; static const int PATHCONSTRAINTSPACING_VALUE = 1; void _spPathConstraintSpacingTimeline_apply(const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, - spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int frame; float frameTime, percent, spacing; spPathConstraint* constraint; @@ -1646,7 +1669,8 @@ int _spPathConstraintSpacingTimeline_getPropertyId (const spTimeline* timeline) } spPathConstraintSpacingTimeline* spPathConstraintSpacingTimeline_create (int framesCount) { - return (spPathConstraintSpacingTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_PATHCONSTRAINTSPACING, PATHCONSTRAINTSPACING_ENTRIES, _spPathConstraintSpacingTimeline_apply, _spPathConstraintSpacingTimeline_getPropertyId); + return (spPathConstraintSpacingTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_PATHCONSTRAINTSPACING, + PATHCONSTRAINTSPACING_ENTRIES, _spPathConstraintSpacingTimeline_apply, _spPathConstraintSpacingTimeline_getPropertyId); } void spPathConstraintSpacingTimeline_setFrame (spPathConstraintSpacingTimeline* self, int frameIndex, float time, float value) { @@ -1664,7 +1688,8 @@ static const int PATHCONSTRAINTMIX_ROTATE = 1; static const int PATHCONSTRAINTMIX_TRANSLATE = 2; void _spPathConstraintMixTimeline_apply(const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, - spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction) { + spEvent** firedEvents, int* eventsCount, float alpha, spMixBlend blend, spMixDirection direction +) { int frame; float frameTime, percent, rotate, translate; spPathConstraint* constraint; @@ -1728,7 +1753,8 @@ int _spPathConstraintMixTimeline_getPropertyId (const spTimeline* timeline) { } spPathConstraintMixTimeline* spPathConstraintMixTimeline_create (int framesCount) { - return (spPathConstraintMixTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_PATHCONSTRAINTMIX, PATHCONSTRAINTMIX_ENTRIES, _spPathConstraintMixTimeline_apply, _spPathConstraintMixTimeline_getPropertyId); + return (spPathConstraintMixTimeline*)_spBaseTimeline_create(framesCount, SP_TIMELINE_PATHCONSTRAINTMIX, + PATHCONSTRAINTMIX_ENTRIES, _spPathConstraintMixTimeline_apply, _spPathConstraintMixTimeline_getPropertyId); } void spPathConstraintMixTimeline_setFrame (spPathConstraintMixTimeline* self, int frameIndex, float time, float rotateMix, float translateMix) { diff --git a/spine-c/spine-c/src/spine/AnimationState.c b/spine-c/spine-c/src/spine/AnimationState.c index 03aabbffd..788da02f2 100644 --- a/spine-c/spine-c/src/spine/AnimationState.c +++ b/spine-c/spine-c/src/spine/AnimationState.c @@ -46,7 +46,7 @@ void spAnimationState_disposeStatics () { } /* Forward declaration of some "private" functions so we can keep - the same function order in C as we have method order in Java */ + the same function order in C as we have method order in Java. */ void _spAnimationState_disposeTrackEntry (spTrackEntry* entry); void _spAnimationState_disposeTrackEntries (spAnimationState* state, spTrackEntry* entry); int /*boolean*/ _spAnimationState_updateMixingFrom (spAnimationState* self, spTrackEntry* entry, float delta); @@ -65,7 +65,6 @@ int _spAnimationState_addPropertyID(spAnimationState* self, int id); void _spTrackEntry_computeHold(spTrackEntry* self, spAnimationState* state); void _spTrackEntry_computeNotLast(spTrackEntry* self, spAnimationState* state); - _spEventQueue* _spEventQueue_create (_spAnimationState* state) { _spEventQueue *self = CALLOC(_spEventQueue, 1); self->state = state; @@ -78,7 +77,7 @@ _spEventQueue* _spEventQueue_create (_spAnimationState* state) { void _spEventQueue_free (_spEventQueue* self) { FREE(self->objects); - FREE(self); + FREE(self); } void _spEventQueue_ensureCapacity (_spEventQueue* self, int newElements) { @@ -250,7 +249,7 @@ void spAnimationState_dispose (spAnimationState* self) { _spEventQueue_free(internal->queue); FREE(internal->events); FREE(internal->propertyIDs); - FREE(internal); + FREE(internal); } void spAnimationState_update (spAnimationState* self, float delta) { @@ -370,9 +369,9 @@ int spAnimationState_apply (spAnimationState* self, spSkeleton* skeleton) { /* Apply mixing from entries first. */ mix = current->alpha; if (current->mixingFrom) - mix *= _spAnimationState_applyMixingFrom(self, current, skeleton, blend); - else if (current->trackTime >= current->trackEnd && current->next == 0) - mix = 0; + mix *= _spAnimationState_applyMixingFrom(self, current, skeleton, blend); + else if (current->trackTime >= current->trackEnd && current->next == 0) + mix = 0; /* Apply current entry. */ animationLast = current->animationLast; animationTime = spTrackEntry_getAnimationTime(current); @@ -493,7 +492,7 @@ float _spAnimationState_applyMixingFrom (spAnimationState* self, spTrackEntry* t from->totalAlpha += alpha; if (timeline->type == SP_TIMELINE_ROTATE) _spAnimationState_applyRotateTimeline(self, timeline, skeleton, animationTime, alpha, timelineBlend, - timelinesRotation, i << 1, firstFrame); + timelinesRotation, i << 1, firstFrame); else { if (timelineBlend == SP_MIX_BLEND_SETUP) { if (timeline->type == SP_TIMELINE_ATTACHMENT) { @@ -504,7 +503,7 @@ float _spAnimationState_applyMixingFrom (spAnimationState* self, spTrackEntry* t } spTimeline_apply(timeline, skeleton, animationLast, animationTime, events, &internal->eventsCount, - alpha, timelineBlend, direction); + alpha, timelineBlend, direction); } } } @@ -518,7 +517,9 @@ float _spAnimationState_applyMixingFrom (spAnimationState* self, spTrackEntry* t return mix; } -void _spAnimationState_applyRotateTimeline (spAnimationState* self, spTimeline* timeline, spSkeleton* skeleton, float time, float alpha, spMixBlend blend, float* timelinesRotation, int i, int /*boolean*/ firstFrame) { +void _spAnimationState_applyRotateTimeline (spAnimationState* self, spTimeline* timeline, spSkeleton* skeleton, float time, + float alpha, spMixBlend blend, float* timelinesRotation, int i, int /*boolean*/ firstFrame +) { spRotateTimeline *rotateTimeline; float *frames; spBone* bone; @@ -562,8 +563,7 @@ void _spAnimationState_applyRotateTimeline (spAnimationState* self, spTimeline* prevRotation = frames[frame + ROTATE_PREV_ROTATION]; frameTime = frames[frame]; percent = spCurveTimeline_getCurvePercent(SUPER(rotateTimeline), (frame >> 1) - 1, - 1 - (time - frameTime) / - (frames[frame + ROTATE_PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (frames[frame + ROTATE_PREV_TIME] - frameTime)); r2 = frames[frame + ROTATE_ROTATION] - prevRotation; r2 -= (16384 - (int) (16384.499999999996 - r2 / 360)) * 360; @@ -698,8 +698,7 @@ void _spAnimationState_setCurrent (spAnimationState* self, int index, spTrackEnt } /** Set the current animation. Any queued animations are cleared. */ -spTrackEntry* spAnimationState_setAnimationByName (spAnimationState* self, int trackIndex, const char* animationName, - int/*bool*/loop) { +spTrackEntry* spAnimationState_setAnimationByName (spAnimationState* self, int trackIndex, const char* animationName, int/*bool*/loop) { spAnimation* animation = spSkeletonData_findAnimation(self->data->skeletonData, animationName); return spAnimationState_setAnimation(self, trackIndex, animation, loop); } @@ -730,13 +729,13 @@ spTrackEntry* spAnimationState_setAnimation (spAnimationState* self, int trackIn /** Adds an animation to be played delay seconds after the current or last queued animation, taking into account any mix * duration. */ spTrackEntry* spAnimationState_addAnimationByName (spAnimationState* self, int trackIndex, const char* animationName, - int/*bool*/loop, float delay) { + int/*bool*/loop, float delay +) { spAnimation* animation = spSkeletonData_findAnimation(self->data->skeletonData, animationName); return spAnimationState_addAnimation(self, trackIndex, animation, loop, delay); } -spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop, - float delay) { +spTrackEntry* spAnimationState_addAnimation (spAnimationState* self, int trackIndex, spAnimation* animation, int/*bool*/loop, float delay) { spTrackEntry* entry; _spAnimationState* internal = SUB_CAST(_spAnimationState, self); spTrackEntry* last = _spAnimationState_expandToIndex(self, trackIndex); diff --git a/spine-c/spine-c/src/spine/Atlas.c b/spine-c/spine-c/src/spine/Atlas.c index 0f9a8f2a6..ddf66a2e0 100644 --- a/spine-c/spine-c/src/spine/Atlas.c +++ b/spine-c/spine-c/src/spine/Atlas.c @@ -181,9 +181,8 @@ spAtlas* spAtlas_create(const char* begin, int length, const char* dir, void* re self->rendererObject = rendererObject; while (readLine(&begin, end, &str)) { - if (str.end - str.begin == 0) { + if (str.end - str.begin == 0) page = 0; - } else if (!page) { char* name = mallocString(&str); char* path = MALLOC(char, dirLength + needsSlash + strlen(name) + 1); @@ -232,8 +231,7 @@ spAtlas* spAtlas_create(const char* begin, int length, const char* dir, void* re _spAtlasPage_createTexture(page, path); FREE(path); - } - else { + } else { spAtlasRegion *region = spAtlasRegion_create(); if (lastRegion) lastRegion->next = region; @@ -245,13 +243,12 @@ spAtlas* spAtlas_create(const char* begin, int length, const char* dir, void* re region->name = mallocString(&str); if (!readValue(&begin, end, &str)) return abortAtlas(self); - if (equals(&str, "true")) { + if (equals(&str, "true")) region->degrees = 90; - } else if (equals(&str, "false")) { + else if (equals(&str, "false")) region->degrees = 0; - } else { + else region->degrees = toInt(&str); - } region->rotate = region->degrees == 90; if (readTuple(&begin, end, tuple) != 2) return abortAtlas(self); @@ -267,8 +264,7 @@ spAtlas* spAtlas_create(const char* begin, int length, const char* dir, void* re if (region->rotate) { region->u2 = (region->x + region->height) / (float)page->width; region->v2 = (region->y + region->width) / (float)page->height; - } - else { + } else { region->u2 = (region->x + region->width) / (float)page->width; region->v2 = (region->y + region->height) / (float)page->height; } diff --git a/spine-c/spine-c/src/spine/AttachmentLoader.c b/spine-c/spine-c/src/spine/AttachmentLoader.c index 0d4938e07..f692548d6 100644 --- a/spine-c/spine-c/src/spine/AttachmentLoader.c +++ b/spine-c/spine-c/src/spine/AttachmentLoader.c @@ -32,8 +32,7 @@ #include typedef struct _spAttachmentLoaderVtable { - spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name, - const char* path); + spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name, const char* path); void (*configureAttachment) (spAttachmentLoader* self, spAttachment*); void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*); void (*dispose) (spAttachmentLoader* self); diff --git a/spine-c/spine-c/src/spine/Bone.c b/spine-c/spine-c/src/spine/Bone.c index bfe153fdc..42fdc1400 100644 --- a/spine-c/spine-c/src/spine/Bone.c +++ b/spine-c/spine-c/src/spine/Bone.c @@ -96,78 +96,78 @@ void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rota CONST_CAST(float, self->worldY) = pc * x + pd * y + parent->worldY; switch (self->data->transformMode) { - case SP_TRANSFORMMODE_NORMAL: { - float rotationY = rotation + 90 + shearY; - float la = COS_DEG(rotation + shearX) * scaleX; - float lb = COS_DEG(rotationY) * scaleY; - float lc = SIN_DEG(rotation + shearX) * scaleX; - float ld = SIN_DEG(rotationY) * scaleY; - CONST_CAST(float, self->a) = pa * la + pb * lc; - CONST_CAST(float, self->b) = pa * lb + pb * ld; - CONST_CAST(float, self->c) = pc * la + pd * lc; - CONST_CAST(float, self->d) = pc * lb + pd * ld; - return; - } - case SP_TRANSFORMMODE_ONLYTRANSLATION: { - float rotationY = rotation + 90 + shearY; - CONST_CAST(float, self->a) = COS_DEG(rotation + shearX) * scaleX; - CONST_CAST(float, self->b) = COS_DEG(rotationY) * scaleY; - CONST_CAST(float, self->c) = SIN_DEG(rotation + shearX) * scaleX; - CONST_CAST(float, self->d) = SIN_DEG(rotationY) * scaleY; - break; - } - case SP_TRANSFORMMODE_NOROTATIONORREFLECTION: { - float s = pa * pa + pc * pc; - float prx, rx, ry, la, lb, lc, ld; - if (s > 0.0001f) { - s = ABS(pa * pd - pb * pc) / s; - pb = pc * s; - pd = pa * s; - prx = ATAN2(pc, pa) * RAD_DEG; - } else { - pa = 0; - pc = 0; - prx = 90 - ATAN2(pd, pb) * RAD_DEG; - } - rx = rotation + shearX - prx; - ry = rotation + shearY - prx + 90; - la = COS_DEG(rx) * scaleX; - lb = COS_DEG(ry) * scaleY; - lc = SIN_DEG(rx) * scaleX; - ld = SIN_DEG(ry) * scaleY; - CONST_CAST(float, self->a) = pa * la - pb * lc; - CONST_CAST(float, self->b) = pa * lb - pb * ld; - CONST_CAST(float, self->c) = pc * la + pd * lc; - CONST_CAST(float, self->d) = pc * lb + pd * ld; - break; - } - case SP_TRANSFORMMODE_NOSCALE: - case SP_TRANSFORMMODE_NOSCALEORREFLECTION: { - float za, zc, s; - float r, zb, zd, la, lb, lc, ld; - cosine = COS_DEG(rotation); sine = SIN_DEG(rotation); - za = (pa * cosine + pb * sine) / sx; - zc = (pc * cosine + pd * sine) / sy; - s = SQRT(za * za + zc * zc); - if (s > 0.00001f) s = 1 / s; - za *= s; - zc *= s; - s = SQRT(za * za + zc * zc); - if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0)) - s = -s; - r = PI / 2 + ATAN2(zc, za); - zb = COS(r) * s; - zd = SIN(r) * s; - la = COS_DEG(shearX) * scaleX; - lb = COS_DEG(90 + shearY) * scaleY; - lc = SIN_DEG(shearX) * scaleX; - ld = SIN_DEG(90 + shearY) * scaleY; - CONST_CAST(float, self->a) = za * la + zb * lc; - CONST_CAST(float, self->b) = za * lb + zb * ld; - CONST_CAST(float, self->c) = zc * la + zd * lc; - CONST_CAST(float, self->d) = zc * lb + zd * ld; - break; + case SP_TRANSFORMMODE_NORMAL: { + float rotationY = rotation + 90 + shearY; + float la = COS_DEG(rotation + shearX) * scaleX; + float lb = COS_DEG(rotationY) * scaleY; + float lc = SIN_DEG(rotation + shearX) * scaleX; + float ld = SIN_DEG(rotationY) * scaleY; + CONST_CAST(float, self->a) = pa * la + pb * lc; + CONST_CAST(float, self->b) = pa * lb + pb * ld; + CONST_CAST(float, self->c) = pc * la + pd * lc; + CONST_CAST(float, self->d) = pc * lb + pd * ld; + return; + } + case SP_TRANSFORMMODE_ONLYTRANSLATION: { + float rotationY = rotation + 90 + shearY; + CONST_CAST(float, self->a) = COS_DEG(rotation + shearX) * scaleX; + CONST_CAST(float, self->b) = COS_DEG(rotationY) * scaleY; + CONST_CAST(float, self->c) = SIN_DEG(rotation + shearX) * scaleX; + CONST_CAST(float, self->d) = SIN_DEG(rotationY) * scaleY; + break; + } + case SP_TRANSFORMMODE_NOROTATIONORREFLECTION: { + float s = pa * pa + pc * pc; + float prx, rx, ry, la, lb, lc, ld; + if (s > 0.0001f) { + s = ABS(pa * pd - pb * pc) / s; + pb = pc * s; + pd = pa * s; + prx = ATAN2(pc, pa) * RAD_DEG; + } else { + pa = 0; + pc = 0; + prx = 90 - ATAN2(pd, pb) * RAD_DEG; } + rx = rotation + shearX - prx; + ry = rotation + shearY - prx + 90; + la = COS_DEG(rx) * scaleX; + lb = COS_DEG(ry) * scaleY; + lc = SIN_DEG(rx) * scaleX; + ld = SIN_DEG(ry) * scaleY; + CONST_CAST(float, self->a) = pa * la - pb * lc; + CONST_CAST(float, self->b) = pa * lb - pb * ld; + CONST_CAST(float, self->c) = pc * la + pd * lc; + CONST_CAST(float, self->d) = pc * lb + pd * ld; + break; + } + case SP_TRANSFORMMODE_NOSCALE: + case SP_TRANSFORMMODE_NOSCALEORREFLECTION: { + float za, zc, s; + float r, zb, zd, la, lb, lc, ld; + cosine = COS_DEG(rotation); sine = SIN_DEG(rotation); + za = (pa * cosine + pb * sine) / sx; + zc = (pc * cosine + pd * sine) / sy; + s = SQRT(za * za + zc * zc); + if (s > 0.00001f) s = 1 / s; + za *= s; + zc *= s; + s = SQRT(za * za + zc * zc); + if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0)) + s = -s; + r = PI / 2 + ATAN2(zc, za); + zb = COS(r) * s; + zd = SIN(r) * s; + la = COS_DEG(shearX) * scaleX; + lb = COS_DEG(90 + shearY) * scaleY; + lc = SIN_DEG(shearX) * scaleX; + ld = SIN_DEG(90 + shearY) * scaleY; + CONST_CAST(float, self->a) = za * la + zb * lc; + CONST_CAST(float, self->b) = za * lb + zb * ld; + CONST_CAST(float, self->c) = zc * la + zd * lc; + CONST_CAST(float, self->d) = zc * lb + zd * ld; + break; + } } CONST_CAST(float, self->a) *= sx; diff --git a/spine-c/spine-c/src/spine/IkConstraint.c b/spine-c/spine-c/src/spine/IkConstraint.c index 8632fa00e..d5549d7e8 100644 --- a/spine-c/spine-c/src/spine/IkConstraint.c +++ b/spine-c/spine-c/src/spine/IkConstraint.c @@ -59,12 +59,12 @@ void spIkConstraint_dispose(spIkConstraint *self) { void spIkConstraint_apply(spIkConstraint *self) { switch (self->bonesCount) { - case 1: - spIkConstraint_apply1(self->bones[0], self->target->worldX, self->target->worldY, self->compress, self->stretch, self->data->uniform, self->mix); - break; - case 2: - spIkConstraint_apply2(self->bones[0], self->bones[1], self->target->worldX, self->target->worldY, self->bendDirection, self->stretch, self->softness, self->mix); - break; + case 1: + spIkConstraint_apply1(self->bones[0], self->target->worldX, self->target->worldY, self->compress, self->stretch, self->data->uniform, self->mix); + break; + case 2: + spIkConstraint_apply2(self->bones[0], self->bones[1], self->target->worldX, self->target->worldY, self->bendDirection, self->stretch, self->softness, self->mix); + break; } } diff --git a/spine-c/spine-c/src/spine/Json.c b/spine-c/spine-c/src/spine/Json.c index fc04c245d..852e76d25 100644 --- a/spine-c/spine-c/src/spine/Json.c +++ b/spine-c/spine-c/src/spine/Json.c @@ -1,25 +1,25 @@ /* - Copyright (c) 2009, Dave Gamble - Copyright (c) 2013, Esoteric Software +Copyright (c) 2009, Dave Gamble +Copyright (c) 2013, Esoteric Software - Permission is hereby granted, dispose of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: +Permission is hereby granted, dispose of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ /* Json */ /* JSON parser in C. */ @@ -54,8 +54,7 @@ const char* Json_getError (void) { static int Json_strcasecmp (const char* s1, const char* s2) { /* TODO we may be able to elide these NULL checks if we can prove - * the graph and input (only callsite is Json_getItem) should not have NULLs - */ + the graph and input (only callsite is Json_getItem) should not have NULLs */ if (s1 && s2) { #if defined(_WIN32) return _stricmp(s1, s2); diff --git a/spine-c/spine-c/src/spine/Json.h b/spine-c/spine-c/src/spine/Json.h index 078a5a715..1742525dd 100644 --- a/spine-c/spine-c/src/spine/Json.h +++ b/spine-c/spine-c/src/spine/Json.h @@ -1,16 +1,16 @@ /* Copyright (c) 2009 Dave Gamble - + Permission is hereby granted, dispose of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/spine-c/spine-c/src/spine/MeshAttachment.c b/spine-c/spine-c/src/spine/MeshAttachment.c index 59d940b06..ade598855 100644 --- a/spine-c/spine-c/src/spine/MeshAttachment.c +++ b/spine-c/spine-c/src/spine/MeshAttachment.c @@ -187,7 +187,6 @@ void spMeshAttachment_updateUVs (spMeshAttachment* self) { void spMeshAttachment_setParentMesh (spMeshAttachment* self, spMeshAttachment* parentMesh) { CONST_CAST(spMeshAttachment*, self->parentMesh) = parentMesh; if (parentMesh) { - self->super.bones = parentMesh->super.bones; self->super.bonesCount = parentMesh->super.bonesCount; @@ -200,7 +199,7 @@ void spMeshAttachment_setParentMesh (spMeshAttachment* self, spMeshAttachment* p self->trianglesCount = parentMesh->trianglesCount; self->hullLength = parentMesh->hullLength; - + self->super.worldVerticesLength = parentMesh->super.worldVerticesLength; self->edges = parentMesh->edges; diff --git a/spine-c/spine-c/src/spine/PathConstraint.c b/spine-c/spine-c/src/spine/PathConstraint.c index a0b7bf991..51cf11616 100644 --- a/spine-c/spine-c/src/spine/PathConstraint.c +++ b/spine-c/spine-c/src/spine/PathConstraint.c @@ -214,7 +214,7 @@ static void _addAfterPosition (float p, float* temp, int i, float* out, int o) { /* Need to pass 0 as an argument, so VC++ doesn't error with C2124 */ static int _isNan(float value, float zero) { - float _nan = (float)0.0 / zero; + float _nan = (float)0.0 / zero; return 0 == memcmp((void*)&value, (void*)&_nan, sizeof(value)); } @@ -235,11 +235,10 @@ static void _addCurvePosition (float p, float x1, float y1, float cx1, float cy1 out[o] = x; out[o + 1] = y; if (tangents) { - if (p < 0.001) { + if (p < 0.001) out[o + 2] = ATAN2(cy1 - y1, cx1 - x1); - } else { + else out[o + 2] = ATAN2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); - } } } diff --git a/spine-c/spine-c/src/spine/Skeleton.c b/spine-c/spine-c/src/spine/Skeleton.c index 676a4e4e1..52ebda2fb 100644 --- a/spine-c/spine-c/src/spine/Skeleton.c +++ b/spine-c/spine-c/src/spine/Skeleton.c @@ -251,8 +251,7 @@ static void _sortIkConstraint (_spSkeleton* const internal, spIkConstraint* cons break; } } - if (!contains) - _addToUpdateCacheReset(internal, child); + if (!contains) _addToUpdateCacheReset(internal, child); } _addToUpdateCache(internal, SP_UPDATE_IK_CONSTRAINT, constraint); diff --git a/spine-c/spine-c/src/spine/SkeletonBinary.c b/spine-c/spine-c/src/spine/SkeletonBinary.c index a6c594ebb..a5b24c39b 100644 --- a/spine-c/spine-c/src/spine/SkeletonBinary.c +++ b/spine-c/spine-c/src/spine/SkeletonBinary.c @@ -35,7 +35,7 @@ #include typedef struct { - const unsigned char* cursor; + const unsigned char* cursor; const unsigned char* end; } _dataInput; @@ -118,13 +118,13 @@ static int readVarint (_dataInput* input, int/*bool*/optimizePositive) { b = readByte(input); value |= (b & 0x7F) << 7; if (b & 0x80) { + b = readByte(input); + value |= (b & 0x7F) << 14; + if (b & 0x80) { b = readByte(input); - value |= (b & 0x7F) << 14; - if (b & 0x80) { - b = readByte(input); - value |= (b & 0x7F) << 21; - if (b & 0x80) value |= (readByte(input) & 0x7F) << 28; - } + value |= (b & 0x7F) << 21; + if (b & 0x80) value |= (readByte(input) & 0x7F) << 28; + } } } if (!optimizePositive) value = (((unsigned int)value >> 1) ^ -(value & 1)); @@ -206,18 +206,18 @@ static void readColor (_dataInput* input, float *r, float *g, float *b, float *a static void readCurve (_dataInput* input, spCurveTimeline* timeline, int frameIndex) { switch (readByte(input)) { - case CURVE_STEPPED: { - spCurveTimeline_setStepped(timeline, frameIndex); - break; - } - case CURVE_BEZIER: { - float cx1 = readFloat(input); - float cy1 = readFloat(input); - float cx2 = readFloat(input); - float cy2 = readFloat(input); - spCurveTimeline_setCurve(timeline, frameIndex, cx1, cy1, cx2, cy2); - break; - } + case CURVE_STEPPED: { + spCurveTimeline_setStepped(timeline, frameIndex); + break; + } + case CURVE_BEZIER: { + float cx1 = readFloat(input); + float cy1 = readFloat(input); + float cx2 = readFloat(input); + float cy2 = readFloat(input); + spCurveTimeline_setCurve(timeline, frameIndex, cx1, cy1, cx2, cy2); + break; + } } } @@ -264,56 +264,56 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con unsigned char timelineType = readByte(input); int frameCount = readVarint(input, 1); switch (timelineType) { - case SLOT_ATTACHMENT: { - spAttachmentTimeline* timeline = spAttachmentTimeline_create(frameCount); - timeline->slotIndex = slotIndex; - for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { - float time = readFloat(input); - const char* attachmentName = readStringRef(input, skeletonData); - /* TODO Avoid copying of attachmentName inside */ - spAttachmentTimeline_setFrame(timeline, frameIndex, time, attachmentName); - } - spTimelineArray_add(timelines, (spTimeline*)timeline); - duration = MAX(duration, timeline->frames[frameCount - 1]); - break; + case SLOT_ATTACHMENT: { + spAttachmentTimeline* timeline = spAttachmentTimeline_create(frameCount); + timeline->slotIndex = slotIndex; + for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { + float time = readFloat(input); + const char* attachmentName = readStringRef(input, skeletonData); + /* TODO Avoid copying of attachmentName inside */ + spAttachmentTimeline_setFrame(timeline, frameIndex, time, attachmentName); } - case SLOT_COLOR: { - spColorTimeline* timeline = spColorTimeline_create(frameCount); - timeline->slotIndex = slotIndex; - for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { - float time = readFloat(input); - float r, g, b, a; - readColor(input, &r, &g, &b, &a); - spColorTimeline_setFrame(timeline, frameIndex, time, r, g, b, a); - if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); - } - spTimelineArray_add(timelines, (spTimeline*)timeline); - duration = MAX(duration, timeline->frames[(frameCount - 1) * COLOR_ENTRIES]); - break; + spTimelineArray_add(timelines, (spTimeline*)timeline); + duration = MAX(duration, timeline->frames[frameCount - 1]); + break; + } + case SLOT_COLOR: { + spColorTimeline* timeline = spColorTimeline_create(frameCount); + timeline->slotIndex = slotIndex; + for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { + float time = readFloat(input); + float r, g, b, a; + readColor(input, &r, &g, &b, &a); + spColorTimeline_setFrame(timeline, frameIndex, time, r, g, b, a); + if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); } - case SLOT_TWO_COLOR: { - spTwoColorTimeline* timeline = spTwoColorTimeline_create(frameCount); - timeline->slotIndex = slotIndex; - for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { - float time = readFloat(input); - float r, g, b, a; - float r2, g2, b2, a2; - readColor(input, &r, &g, &b, &a); - readColor(input, &a2, &r2, &g2, &b2); - spTwoColorTimeline_setFrame(timeline, frameIndex, time, r, g, b, a, r2, g2, b2); - if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); - } - spTimelineArray_add(timelines, (spTimeline*)timeline); - duration = MAX(duration, timeline->frames[(frameCount - 1) * TWOCOLOR_ENTRIES]); - break; - } - default: { - for (iii = 0; iii < timelines->size; ++iii) - spTimeline_dispose(timelines->items[iii]); - spTimelineArray_dispose(timelines); - _spSkeletonBinary_setError(self, "Invalid timeline type for a slot: ", skeletonData->slots[slotIndex]->name); - return 0; + spTimelineArray_add(timelines, (spTimeline*)timeline); + duration = MAX(duration, timeline->frames[(frameCount - 1) * COLOR_ENTRIES]); + break; + } + case SLOT_TWO_COLOR: { + spTwoColorTimeline* timeline = spTwoColorTimeline_create(frameCount); + timeline->slotIndex = slotIndex; + for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { + float time = readFloat(input); + float r, g, b, a; + float r2, g2, b2, a2; + readColor(input, &r, &g, &b, &a); + readColor(input, &a2, &r2, &g2, &b2); + spTwoColorTimeline_setFrame(timeline, frameIndex, time, r, g, b, a, r2, g2, b2); + if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); } + spTimelineArray_add(timelines, (spTimeline*)timeline); + duration = MAX(duration, timeline->frames[(frameCount - 1) * TWOCOLOR_ENTRIES]); + break; + } + default: { + for (iii = 0; iii < timelines->size; ++iii) + spTimeline_dispose(timelines->items[iii]); + spTimelineArray_dispose(timelines); + _spSkeletonBinary_setError(self, "Invalid timeline type for a slot: ", skeletonData->slots[slotIndex]->name); + return 0; + } } } } @@ -325,57 +325,57 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con unsigned char timelineType = readByte(input); int frameCount = readVarint(input, 1); switch (timelineType) { - case BONE_ROTATE: { - spRotateTimeline *timeline = spRotateTimeline_create(frameCount); - timeline->boneIndex = boneIndex; - for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { - float time = readFloat(input); - float degrees = readFloat(input); - spRotateTimeline_setFrame(timeline, frameIndex, time, degrees); - if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); - } - spTimelineArray_add(timelines, (spTimeline*)timeline); - duration = MAX(duration, timeline->frames[(frameCount - 1) * ROTATE_ENTRIES]); - break; + case BONE_ROTATE: { + spRotateTimeline *timeline = spRotateTimeline_create(frameCount); + timeline->boneIndex = boneIndex; + for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { + float time = readFloat(input); + float degrees = readFloat(input); + spRotateTimeline_setFrame(timeline, frameIndex, time, degrees); + if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); } - case BONE_TRANSLATE: - case BONE_SCALE: - case BONE_SHEAR: { - float timelineScale = 1; - spTranslateTimeline *timeline = 0; - switch (timelineType) { - case BONE_SCALE: - timeline = spScaleTimeline_create(frameCount); - break; - case BONE_SHEAR: - timeline = spShearTimeline_create(frameCount); - break; - case BONE_TRANSLATE: - timeline = spTranslateTimeline_create(frameCount); - timelineScale = self->scale; - break; - default: - break; - } - timeline->boneIndex = boneIndex; - for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { - float time = readFloat(input); - float x = readFloat(input) * timelineScale; - float y = readFloat(input) * timelineScale; - spTranslateTimeline_setFrame(timeline, frameIndex, time, x, y); - if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); - } - spTimelineArray_add(timelines, (spTimeline*)timeline); - duration = MAX(duration, timeline->frames[(frameCount - 1) * TRANSLATE_ENTRIES]); - break; + spTimelineArray_add(timelines, (spTimeline*)timeline); + duration = MAX(duration, timeline->frames[(frameCount - 1) * ROTATE_ENTRIES]); + break; + } + case BONE_TRANSLATE: + case BONE_SCALE: + case BONE_SHEAR: { + float timelineScale = 1; + spTranslateTimeline *timeline = 0; + switch (timelineType) { + case BONE_SCALE: + timeline = spScaleTimeline_create(frameCount); + break; + case BONE_SHEAR: + timeline = spShearTimeline_create(frameCount); + break; + case BONE_TRANSLATE: + timeline = spTranslateTimeline_create(frameCount); + timelineScale = self->scale; + break; + default: + break; } - default: { - for (iii = 0; iii < timelines->size; ++iii) - spTimeline_dispose(timelines->items[iii]); - spTimelineArray_dispose(timelines); - _spSkeletonBinary_setError(self, "Invalid timeline type for a bone: ", skeletonData->bones[boneIndex]->name); - return 0; + timeline->boneIndex = boneIndex; + for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { + float time = readFloat(input); + float x = readFloat(input) * timelineScale; + float y = readFloat(input) * timelineScale; + spTranslateTimeline_setFrame(timeline, frameIndex, time, x, y); + if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); } + spTimelineArray_add(timelines, (spTimeline*)timeline); + duration = MAX(duration, timeline->frames[(frameCount - 1) * TRANSLATE_ENTRIES]); + break; + } + default: { + for (iii = 0; iii < timelines->size; ++iii) + spTimeline_dispose(timelines->items[iii]); + spTimelineArray_dispose(timelines); + _spSkeletonBinary_setError(self, "Invalid timeline type for a bone: ", skeletonData->bones[boneIndex]->name); + return 0; + } } } } @@ -413,7 +413,7 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con float scaleMix = readFloat(input); float shearMix = readFloat(input); spTransformConstraintTimeline_setFrame(timeline, frameIndex, time, rotateMix, translateMix, - scaleMix, shearMix); + scaleMix, shearMix); if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); } spTimelineArray_add(timelines, (spTimeline*)timeline); @@ -428,43 +428,43 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con unsigned char timelineType = readByte(input); int frameCount = readVarint(input, 1); switch (timelineType) { - case PATH_POSITION: - case PATH_SPACING: { - spPathConstraintPositionTimeline* timeline = 0; - float timelineScale = 1; - if (timelineType == PATH_SPACING) { - timeline = (spPathConstraintPositionTimeline*)spPathConstraintSpacingTimeline_create(frameCount); - if (data->spacingMode == SP_SPACING_MODE_LENGTH || data->spacingMode == SP_SPACING_MODE_FIXED) - timelineScale = self->scale; - } else { - timeline = spPathConstraintPositionTimeline_create(frameCount); - if (data->positionMode == SP_POSITION_MODE_FIXED) - timelineScale = self->scale; - } - timeline->pathConstraintIndex = index; - for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { - float time = readFloat(input); - float value = readFloat(input) * timelineScale; - spPathConstraintPositionTimeline_setFrame(timeline, frameIndex, time, value); - if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); - } - spTimelineArray_add(timelines, (spTimeline*)timeline); - duration = MAX(duration, timeline->frames[(frameCount - 1) * PATHCONSTRAINTPOSITION_ENTRIES]); - break; + case PATH_POSITION: + case PATH_SPACING: { + spPathConstraintPositionTimeline* timeline = 0; + float timelineScale = 1; + if (timelineType == PATH_SPACING) { + timeline = (spPathConstraintPositionTimeline*)spPathConstraintSpacingTimeline_create(frameCount); + if (data->spacingMode == SP_SPACING_MODE_LENGTH || data->spacingMode == SP_SPACING_MODE_FIXED) + timelineScale = self->scale; + } else { + timeline = spPathConstraintPositionTimeline_create(frameCount); + if (data->positionMode == SP_POSITION_MODE_FIXED) + timelineScale = self->scale; } - case PATH_MIX: { - spPathConstraintMixTimeline* timeline = spPathConstraintMixTimeline_create(frameCount); - timeline->pathConstraintIndex = index; - for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { - float time = readFloat(input); - float rotateMix = readFloat(input); - float translateMix = readFloat(input); - spPathConstraintMixTimeline_setFrame(timeline, frameIndex, time, rotateMix, translateMix); - if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); - } - spTimelineArray_add(timelines, (spTimeline*)timeline); - duration = MAX(duration, timeline->frames[(frameCount - 1) * PATHCONSTRAINTMIX_ENTRIES]); + timeline->pathConstraintIndex = index; + for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { + float time = readFloat(input); + float value = readFloat(input) * timelineScale; + spPathConstraintPositionTimeline_setFrame(timeline, frameIndex, time, value); + if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); } + spTimelineArray_add(timelines, (spTimeline*)timeline); + duration = MAX(duration, timeline->frames[(frameCount - 1) * PATHCONSTRAINTPOSITION_ENTRIES]); + break; + } + case PATH_MIX: { + spPathConstraintMixTimeline* timeline = spPathConstraintMixTimeline_create(frameCount); + timeline->pathConstraintIndex = index; + for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { + float time = readFloat(input); + float rotateMix = readFloat(input); + float translateMix = readFloat(input); + spPathConstraintMixTimeline_setFrame(timeline, frameIndex, time, rotateMix, translateMix); + if (frameIndex < frameCount - 1) readCurve(input, SUPER(timeline), frameIndex); + } + spTimelineArray_add(timelines, (spTimeline*)timeline); + duration = MAX(duration, timeline->frames[(frameCount - 1) * PATHCONSTRAINTMIX_ENTRIES]); + } } } } @@ -482,7 +482,7 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con int frameCount; spVertexAttachment* attachment = SUB_CAST(spVertexAttachment, - spSkin_getAttachment(skin, slotIndex, attachmentName)); + spSkin_getAttachment(skin, slotIndex, attachmentName)); if (!attachment) { for (i = 0; i < timelines->size; ++i) spTimeline_dispose(timelines->items[i]); @@ -684,140 +684,140 @@ spAttachment* spSkeletonBinary_readAttachment(spSkeletonBinary* self, _dataInput type = (spAttachmentType)readByte(input); switch (type) { - case SP_ATTACHMENT_REGION: { - const char* path = readStringRef(input, skeletonData); - spAttachment* attachment; - spRegionAttachment* region; - if (!path) MALLOC_STR(path, name); - else { - const char* tmp = 0; - MALLOC_STR(tmp, path); - path = tmp; - } - attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path); - region = SUB_CAST(spRegionAttachment, attachment); - region->path = path; - region->rotation = readFloat(input); - region->x = readFloat(input) * self->scale; - region->y = readFloat(input) * self->scale; - region->scaleX = readFloat(input); - region->scaleY = readFloat(input); - region->width = readFloat(input) * self->scale; - region->height = readFloat(input) * self->scale; - readColor(input, ®ion->color.r, ®ion->color.g, ®ion->color.b, ®ion->color.a); - spRegionAttachment_updateOffset(region); - spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); - return attachment; + case SP_ATTACHMENT_REGION: { + const char* path = readStringRef(input, skeletonData); + spAttachment* attachment; + spRegionAttachment* region; + if (!path) MALLOC_STR(path, name); + else { + const char* tmp = 0; + MALLOC_STR(tmp, path); + path = tmp; } - case SP_ATTACHMENT_BOUNDING_BOX: { - int vertexCount = readVarint(input, 1); - spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); - _readVertices(self, input, SUB_CAST(spVertexAttachment, attachment), vertexCount); - if (nonessential) readInt(input); /* Skip color. */ - spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); - return attachment; + attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path); + region = SUB_CAST(spRegionAttachment, attachment); + region->path = path; + region->rotation = readFloat(input); + region->x = readFloat(input) * self->scale; + region->y = readFloat(input) * self->scale; + region->scaleX = readFloat(input); + region->scaleY = readFloat(input); + region->width = readFloat(input) * self->scale; + region->height = readFloat(input) * self->scale; + readColor(input, ®ion->color.r, ®ion->color.g, ®ion->color.b, ®ion->color.a); + spRegionAttachment_updateOffset(region); + spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); + return attachment; + } + case SP_ATTACHMENT_BOUNDING_BOX: { + int vertexCount = readVarint(input, 1); + spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); + _readVertices(self, input, SUB_CAST(spVertexAttachment, attachment), vertexCount); + if (nonessential) readInt(input); /* Skip color. */ + spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); + return attachment; + } + case SP_ATTACHMENT_MESH: { + int vertexCount; + spAttachment* attachment; + spMeshAttachment* mesh; + const char* path = readStringRef(input, skeletonData); + if (!path) MALLOC_STR(path, name); + else { + const char* tmp = 0; + MALLOC_STR(tmp, path); + path = tmp; } - case SP_ATTACHMENT_MESH: { - int vertexCount; - spAttachment* attachment; - spMeshAttachment* mesh; - const char* path = readStringRef(input, skeletonData); - if (!path) MALLOC_STR(path, name); - else { - const char* tmp = 0; - MALLOC_STR(tmp, path); - path = tmp; - } - attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path); - mesh = SUB_CAST(spMeshAttachment, attachment); - mesh->path = path; - readColor(input, &mesh->color.r, &mesh->color.g, &mesh->color.b, &mesh->color.a); - vertexCount = readVarint(input, 1); - mesh->regionUVs = _readFloatArray(input, vertexCount << 1, 1); - mesh->triangles = (unsigned short*)_readShortArray(input, &mesh->trianglesCount); - _readVertices(self, input, SUPER(mesh), vertexCount); - spMeshAttachment_updateUVs(mesh); - mesh->hullLength = readVarint(input, 1) << 1; - if (nonessential) { - mesh->edges = (int*)_readShortArray(input, &mesh->edgesCount); - mesh->width = readFloat(input) * self->scale; - mesh->height = readFloat(input) * self->scale; - } else { - mesh->edges = 0; - mesh->width = 0; - mesh->height = 0; - } - spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); - return attachment; + attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path); + mesh = SUB_CAST(spMeshAttachment, attachment); + mesh->path = path; + readColor(input, &mesh->color.r, &mesh->color.g, &mesh->color.b, &mesh->color.a); + vertexCount = readVarint(input, 1); + mesh->regionUVs = _readFloatArray(input, vertexCount << 1, 1); + mesh->triangles = (unsigned short*)_readShortArray(input, &mesh->trianglesCount); + _readVertices(self, input, SUPER(mesh), vertexCount); + spMeshAttachment_updateUVs(mesh); + mesh->hullLength = readVarint(input, 1) << 1; + if (nonessential) { + mesh->edges = (int*)_readShortArray(input, &mesh->edgesCount); + mesh->width = readFloat(input) * self->scale; + mesh->height = readFloat(input) * self->scale; + } else { + mesh->edges = 0; + mesh->width = 0; + mesh->height = 0; } - case SP_ATTACHMENT_LINKED_MESH: { - const char* skinName; - const char* parent; - spAttachment* attachment; - spMeshAttachment* mesh; - int inheritDeform; - const char* path = readStringRef(input, skeletonData); - if (!path) MALLOC_STR(path, name); - else { - const char* tmp = 0; - MALLOC_STR(tmp, path); - path = tmp; - } - attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path); - mesh = SUB_CAST(spMeshAttachment, attachment); - mesh->path = path; - readColor(input, &mesh->color.r, &mesh->color.g, &mesh->color.b, &mesh->color.a); - skinName = readStringRef(input, skeletonData); - parent = readStringRef(input, skeletonData); - inheritDeform = readBoolean(input); - if (nonessential) { - mesh->width = readFloat(input) * self->scale; - mesh->height = readFloat(input) * self->scale; - } - _spSkeletonBinary_addLinkedMesh(self, mesh, skinName, slotIndex, parent, inheritDeform); - return attachment; + spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); + return attachment; + } + case SP_ATTACHMENT_LINKED_MESH: { + const char* skinName; + const char* parent; + spAttachment* attachment; + spMeshAttachment* mesh; + int inheritDeform; + const char* path = readStringRef(input, skeletonData); + if (!path) MALLOC_STR(path, name); + else { + const char* tmp = 0; + MALLOC_STR(tmp, path); + path = tmp; } - case SP_ATTACHMENT_PATH: { - spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); - spPathAttachment* path = SUB_CAST(spPathAttachment, attachment); - int vertexCount = 0; - path->closed = readBoolean(input); - path->constantSpeed = readBoolean(input); - vertexCount = readVarint(input, 1); - _readVertices(self, input, SUPER(path), vertexCount); - path->lengthsLength = vertexCount / 3; - path->lengths = MALLOC(float, path->lengthsLength); - for (i = 0; i < path->lengthsLength; ++i) { - path->lengths[i] = readFloat(input) * self->scale; - } - if (nonessential) readInt(input); /* Skip color. */ - spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); - return attachment; + attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, path); + mesh = SUB_CAST(spMeshAttachment, attachment); + mesh->path = path; + readColor(input, &mesh->color.r, &mesh->color.g, &mesh->color.b, &mesh->color.a); + skinName = readStringRef(input, skeletonData); + parent = readStringRef(input, skeletonData); + inheritDeform = readBoolean(input); + if (nonessential) { + mesh->width = readFloat(input) * self->scale; + mesh->height = readFloat(input) * self->scale; } - case SP_ATTACHMENT_POINT: { - spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); - spPointAttachment* point = SUB_CAST(spPointAttachment, attachment); - point->rotation = readFloat(input); - point->x = readFloat(input) * self->scale; - point->y = readFloat(input) * self->scale; + _spSkeletonBinary_addLinkedMesh(self, mesh, skinName, slotIndex, parent, inheritDeform); + return attachment; + } + case SP_ATTACHMENT_PATH: { + spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); + spPathAttachment* path = SUB_CAST(spPathAttachment, attachment); + int vertexCount = 0; + path->closed = readBoolean(input); + path->constantSpeed = readBoolean(input); + vertexCount = readVarint(input, 1); + _readVertices(self, input, SUPER(path), vertexCount); + path->lengthsLength = vertexCount / 3; + path->lengths = MALLOC(float, path->lengthsLength); + for (i = 0; i < path->lengthsLength; ++i) { + path->lengths[i] = readFloat(input) * self->scale; + } + if (nonessential) readInt(input); /* Skip color. */ + spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); + return attachment; + } + case SP_ATTACHMENT_POINT: { + spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); + spPointAttachment* point = SUB_CAST(spPointAttachment, attachment); + point->rotation = readFloat(input); + point->x = readFloat(input) * self->scale; + point->y = readFloat(input) * self->scale; - if (nonessential) { - readColor(input, &point->color.r, &point->color.g, &point->color.b, &point->color.a); - } - spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); - return attachment; - } - case SP_ATTACHMENT_CLIPPING: { - int endSlotIndex = readVarint(input, 1); - int vertexCount = readVarint(input, 1); - spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); - spClippingAttachment* clip = SUB_CAST(spClippingAttachment, attachment); - _readVertices(self, input, SUB_CAST(spVertexAttachment, attachment), vertexCount); - if (nonessential) readInt(input); /* Skip color. */ - clip->endSlot = skeletonData->slots[endSlotIndex]; - spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); - return attachment; + if (nonessential) { + readColor(input, &point->color.r, &point->color.g, &point->color.b, &point->color.a); } + spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); + return attachment; + } + case SP_ATTACHMENT_CLIPPING: { + int endSlotIndex = readVarint(input, 1); + int vertexCount = readVarint(input, 1); + spAttachment* attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, type, name, 0); + spClippingAttachment* clip = SUB_CAST(spClippingAttachment, attachment); + _readVertices(self, input, SUB_CAST(spVertexAttachment, attachment), vertexCount); + if (nonessential) readInt(input); /* Skip color. */ + clip->endSlot = skeletonData->slots[endSlotIndex]; + spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); + return attachment; + } } return 0; @@ -942,11 +942,11 @@ spSkeletonData* spSkeletonBinary_readSkeletonData (spSkeletonBinary* self, const data->length = readFloat(input) * self->scale; mode = readVarint(input, 1); switch (mode) { - case 0: data->transformMode = SP_TRANSFORMMODE_NORMAL; break; - case 1: data->transformMode = SP_TRANSFORMMODE_ONLYTRANSLATION; break; - case 2: data->transformMode = SP_TRANSFORMMODE_NOROTATIONORREFLECTION; break; - case 3: data->transformMode = SP_TRANSFORMMODE_NOSCALE; break; - case 4: data->transformMode = SP_TRANSFORMMODE_NOSCALEORREFLECTION; break; + case 0: data->transformMode = SP_TRANSFORMMODE_NORMAL; break; + case 1: data->transformMode = SP_TRANSFORMMODE_ONLYTRANSLATION; break; + case 2: data->transformMode = SP_TRANSFORMMODE_NOROTATIONORREFLECTION; break; + case 3: data->transformMode = SP_TRANSFORMMODE_NOSCALE; break; + case 4: data->transformMode = SP_TRANSFORMMODE_NOSCALEORREFLECTION; break; } data->skinRequired = readBoolean(input); if (nonessential) readInt(input); /* Skip bone color. */ diff --git a/spine-c/spine-c/src/spine/SkeletonBounds.c b/spine-c/spine-c/src/spine/SkeletonBounds.c index 2bb33ce46..8e686daf1 100644 --- a/spine-c/spine-c/src/spine/SkeletonBounds.c +++ b/spine-c/spine-c/src/spine/SkeletonBounds.c @@ -166,8 +166,11 @@ int/*bool*/spSkeletonBounds_aabbContainsPoint (spSkeletonBounds* self, float x, int/*bool*/spSkeletonBounds_aabbIntersectsSegment (spSkeletonBounds* self, float x1, float y1, float x2, float y2) { float m, x, y; - if ((x1 <= self->minX && x2 <= self->minX) || (y1 <= self->minY && y2 <= self->minY) || (x1 >= self->maxX && x2 >= self->maxX) - || (y1 >= self->maxY && y2 >= self->maxY)) return 0; + if ((x1 <= self->minX && x2 <= self->minX) + || (y1 <= self->minY && y2 <= self->minY) + || (x1 >= self->maxX && x2 >= self->maxX) + || (y1 >= self->maxY && y2 >= self->maxY) + ) return 0; m = (y2 - y1) / (x2 - x1); y = m * (self->minX - x1) + y1; if (y > self->minY && y < self->maxY) return 1; diff --git a/spine-c/spine-c/src/spine/SkeletonJson.c b/spine-c/spine-c/src/spine/SkeletonJson.c index a427ef1f0..b39bd3e0f 100644 --- a/spine-c/spine-c/src/spine/SkeletonJson.c +++ b/spine-c/spine-c/src/spine/SkeletonJson.c @@ -93,8 +93,7 @@ static float toColor (const char* value, int index) { char *error; int color; - if ((size_t)index >= strlen(value) / 2) - return -1; + if ((size_t)index >= strlen(value) / 2) return -1; value += index * 2; digits[0] = *value; @@ -120,7 +119,8 @@ static void readCurve (Json* frame, spCurveTimeline* timeline, int frameIndex) { } static void _spSkeletonJson_addLinkedMesh (spSkeletonJson* self, spMeshAttachment* mesh, const char* skin, int slotIndex, - const char* parent, int inheritDeform) { + const char* parent, int inheritDeform +) { _spLinkedMesh* linkedMesh; _spSkeletonJson* internal = SUB_CAST(_spSkeletonJson, self); @@ -195,7 +195,7 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r for (valueMap = timelineMap->child, frameIndex = 0; valueMap; valueMap = valueMap->next, ++frameIndex) { Json* name = Json_getItem(valueMap, "name"); spAttachmentTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), - name->type == Json_NULL ? 0 : name->valueString); + name->type == Json_NULL ? 0 : name->valueString); } animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline); animation->duration = MAX(animation->duration, timeline->frames[timelineMap->size - 1]); @@ -206,8 +206,8 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r for (valueMap = timelineMap->child, frameIndex = 0; valueMap; valueMap = valueMap->next, ++frameIndex) { const char* s = Json_getString(valueMap, "color", 0); - spColorTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), toColor(s, 2), - toColor(s, 3)); + spColorTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), + toColor(s, 2), toColor(s, 3)); readCurve(valueMap, SUPER(timeline), frameIndex); } animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline); @@ -221,7 +221,7 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r const char* s = Json_getString(valueMap, "light", 0); const char* ds = Json_getString(valueMap, "dark", 0); spTwoColorTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), toColor(s, 2), - toColor(s, 3), toColor(ds, 0), toColor(ds, 1), toColor(ds, 2)); + toColor(s, 3), toColor(ds, 0), toColor(ds, 1), toColor(ds, 2)); readCurve(valueMap, SUPER(timeline), frameIndex); } animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline); @@ -275,8 +275,9 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r timeline->boneIndex = boneIndex; for (valueMap = timelineMap->child, frameIndex = 0; valueMap; valueMap = valueMap->next, ++frameIndex) { - spTranslateTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), Json_getFloat(valueMap, "x", defaultValue) * timelineScale, - Json_getFloat(valueMap, "y", defaultValue) * timelineScale); + spTranslateTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), + Json_getFloat(valueMap, "x", defaultValue) * timelineScale, + Json_getFloat(valueMap, "y", defaultValue) * timelineScale); readCurve(valueMap, SUPER(timeline), frameIndex); } animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline); @@ -641,16 +642,11 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha data->shearY = Json_getFloat(boneMap, "shearY", 0); transformMode = Json_getString(boneMap, "transform", "normal"); data->transformMode = SP_TRANSFORMMODE_NORMAL; - if (strcmp(transformMode, "normal") == 0) - data->transformMode = SP_TRANSFORMMODE_NORMAL; - if (strcmp(transformMode, "onlyTranslation") == 0) - data->transformMode = SP_TRANSFORMMODE_ONLYTRANSLATION; - if (strcmp(transformMode, "noRotationOrReflection") == 0) - data->transformMode = SP_TRANSFORMMODE_NOROTATIONORREFLECTION; - if (strcmp(transformMode, "noScale") == 0) - data->transformMode = SP_TRANSFORMMODE_NOSCALE; - if (strcmp(transformMode, "noScaleOrReflection") == 0) - data->transformMode = SP_TRANSFORMMODE_NOSCALEORREFLECTION; + if (strcmp(transformMode, "normal") == 0) data->transformMode = SP_TRANSFORMMODE_NORMAL; + else if (strcmp(transformMode, "onlyTranslation") == 0) data->transformMode = SP_TRANSFORMMODE_ONLYTRANSLATION; + else if (strcmp(transformMode, "noRotationOrReflection") == 0) data->transformMode = SP_TRANSFORMMODE_NOROTATIONORREFLECTION; + else if (strcmp(transformMode, "noScale") == 0) data->transformMode = SP_TRANSFORMMODE_NOSCALE; + else if (strcmp(transformMode, "noScaleOrReflection") == 0) data->transformMode = SP_TRANSFORMMODE_NOSCALEORREFLECTION; data->skinRequired = Json_getInt(boneMap, "skin", 0) ? 1 : 0; skeletonData->bones[i] = data; @@ -682,20 +678,20 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha color = Json_getString(slotMap, "color", 0); if (color) { spColor_setFromFloats(&data->color, - toColor(color, 0), - toColor(color, 1), - toColor(color, 2), - toColor(color, 3)); + toColor(color, 0), + toColor(color, 1), + toColor(color, 2), + toColor(color, 3)); } dark = Json_getString(slotMap, "dark", 0); if (dark) { data->darkColor = spColor_create(); spColor_setFromFloats(data->darkColor, - toColor(dark, 0), - toColor(dark, 1), - toColor(dark, 2), - toColor(dark, 3)); + toColor(dark, 0), + toColor(dark, 1), + toColor(dark, 2), + toColor(dark, 3)); } item = Json_getItem(slotMap, "attachment"); @@ -950,20 +946,13 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha const char* typeString = Json_getString(attachmentMap, "type", "region"); spAttachmentType type; - if (strcmp(typeString, "region") == 0) - type = SP_ATTACHMENT_REGION; - else if (strcmp(typeString, "mesh") == 0) - type = SP_ATTACHMENT_MESH; - else if (strcmp(typeString, "linkedmesh") == 0) - type = SP_ATTACHMENT_LINKED_MESH; - else if (strcmp(typeString, "boundingbox") == 0) - type = SP_ATTACHMENT_BOUNDING_BOX; - else if (strcmp(typeString, "path") == 0) - type = SP_ATTACHMENT_PATH; - else if (strcmp(typeString, "clipping") == 0) - type = SP_ATTACHMENT_CLIPPING; - else if (strcmp(typeString, "point") == 0) - type = SP_ATTACHMENT_POINT; + if (strcmp(typeString, "region") == 0) type = SP_ATTACHMENT_REGION; + else if (strcmp(typeString, "mesh") == 0) type = SP_ATTACHMENT_MESH; + else if (strcmp(typeString, "linkedmesh") == 0) type = SP_ATTACHMENT_LINKED_MESH; + else if (strcmp(typeString, "boundingbox") == 0) type = SP_ATTACHMENT_BOUNDING_BOX; + else if (strcmp(typeString, "path") == 0) type = SP_ATTACHMENT_PATH; + else if (strcmp(typeString, "clipping") == 0) type = SP_ATTACHMENT_CLIPPING; + else if (strcmp(typeString, "point") == 0) type = SP_ATTACHMENT_POINT; else { spSkeletonData_dispose(skeletonData); _spSkeletonJson_setError(self, root, "Unknown attachment type: ", typeString); @@ -995,10 +984,10 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha color = Json_getString(attachmentMap, "color", 0); if (color) { spColor_setFromFloats(®ion->color, - toColor(color, 0), - toColor(color, 1), - toColor(color, 2), - toColor(color, 3)); + toColor(color, 0), + toColor(color, 1), + toColor(color, 2), + toColor(color, 3)); } spRegionAttachment_updateOffset(region); @@ -1015,10 +1004,10 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha color = Json_getString(attachmentMap, "color", 0); if (color) { spColor_setFromFloats(&mesh->color, - toColor(color, 0), - toColor(color, 1), - toColor(color, 2), - toColor(color, 3)); + toColor(color, 0), + toColor(color, 1), + toColor(color, 2), + toColor(color, 3)); } mesh->width = Json_getFloat(attachmentMap, "width", 32) * self->scale; @@ -1056,8 +1045,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); } else { int inheritDeform = Json_getInt(attachmentMap, "deform", 1); - _spSkeletonJson_addLinkedMesh(self, SUB_CAST(spMeshAttachment, attachment), Json_getString(attachmentMap, "skin", 0), slot->index, - entry->valueString, inheritDeform); + _spSkeletonJson_addLinkedMesh(self, SUB_CAST(spMeshAttachment, attachment), + Json_getString(attachmentMap, "skin", 0), slot->index, entry->valueString, inheritDeform); } break; } @@ -1081,9 +1070,8 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha pathAttachment->lengths = MALLOC(float, pathAttachment->lengthsLength); curves = Json_getItem(attachmentMap, "lengths"); - for (curves = curves->child, ii = 0; curves; curves = curves->next, ++ii) { + for (curves = curves->child, ii = 0; curves; curves = curves->next, ++ii) pathAttachment->lengths[ii] = curves->valueFloat * self->scale; - } break; } case SP_ATTACHMENT_POINT: { @@ -1095,10 +1083,10 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha color = Json_getString(attachmentMap, "color", 0); if (color) { spColor_setFromFloats(&point->color, - toColor(color, 0), - toColor(color, 1), - toColor(color, 2), - toColor(color, 3)); + toColor(color, 0), + toColor(color, 1), + toColor(color, 2), + toColor(color, 3)); } break; } diff --git a/spine-c/spine-c/src/spine/Skin.c b/spine-c/spine-c/src/spine/Skin.c index fc1047f65..669b8efbf 100644 --- a/spine-c/spine-c/src/spine/Skin.c +++ b/spine-c/spine-c/src/spine/Skin.c @@ -226,7 +226,7 @@ void spSkin_copySkin(spSkin* self, const spSkin* other) { entry = spSkin_getAttachments(other); while (entry) { - if (entry->attachment->type == SP_ATTACHMENT_MESH) { + if (entry->attachment->type == SP_ATTACHMENT_MESH) { spMeshAttachment* attachment = spMeshAttachment_newLinkedMesh(SUB_CAST(spMeshAttachment, entry->attachment)); spSkin_setAttachment(self, entry->slotIndex, entry->name, SUPER(SUPER(attachment))); } else { diff --git a/spine-c/spine-c/src/spine/Slot.c b/spine-c/spine-c/src/spine/Slot.c index 0e98414ea..9cd0ed0c4 100644 --- a/spine-c/spine-c/src/spine/Slot.c +++ b/spine-c/spine-c/src/spine/Slot.c @@ -74,7 +74,7 @@ void spSlot_setToSetupPose (spSlot* self) { spSlot_setAttachment(self, 0); else { spAttachment* attachment = spSkeleton_getAttachmentForSlotIndex( - self->bone->skeleton, self->data->index, self->data->attachmentName); + self->bone->skeleton, self->data->index, self->data->attachmentName); CONST_CAST(spAttachment*, self->attachment) = 0; spSlot_setAttachment(self, attachment); } diff --git a/spine-c/spine-c/src/spine/Triangulator.c b/spine-c/spine-c/src/spine/Triangulator.c index 51578c442..ac2fa6260 100644 --- a/spine-c/spine-c/src/spine/Triangulator.c +++ b/spine-c/spine-c/src/spine/Triangulator.c @@ -115,9 +115,9 @@ static int _isConcave(int index, int vertexCount, float* vertices, short* indice int previous = indices[(vertexCount + index - 1) % vertexCount] << 1; int current = indices[index] << 1; int next = indices[(index + 1) % vertexCount] << 1; - return !_positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], - vertices[next], - vertices[next + 1]); + return !_positiveArea(vertices[previous], vertices[previous + 1], + vertices[current], vertices[current + 1], + vertices[next], vertices[next + 1]); } static int _winding (float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { diff --git a/spine-cocos2d-objc/src/spine/GLUtils.c b/spine-cocos2d-objc/src/spine/GLUtils.c index 28475edba..3eafeaf61 100644 --- a/spine-cocos2d-objc/src/spine/GLUtils.c +++ b/spine-cocos2d-objc/src/spine/GLUtils.c @@ -44,7 +44,7 @@ #include -#define STRINGIFY(A) #A +#define STRINGIFY(A) #A #define MAX_VERTICES 64000 #define MAX_INDICES 64000 @@ -76,7 +76,7 @@ const char* TWO_COLOR_TINT_FRAGMENT_SHADER = STRINGIFY( \n#ifdef GL_ES\n precision lowp float; \n#endif\n - + uniform sampler2D texture; varying vec4 v_light; @@ -84,10 +84,10 @@ varying vec4 v_dark; varying vec2 v_texCoord; void main() { - vec4 texColor = texture2D(texture, v_texCoord); - float alpha = texColor.a * v_light.a; - gl_FragColor.a = alpha; - gl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb; + vec4 texColor = texture2D(texture, v_texCoord); + float alpha = texColor.a * v_light.a; + gl_FragColor.a = alpha; + gl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb; } ); @@ -111,7 +111,7 @@ void spMesh_allocatePart(spMesh* mesh, spMeshPart* part, uint32_t numVertices, u mesh->numIndices = mesh->numAllocatedIndices + numIndices; mesh->indices = REALLOC(mesh->indices, unsigned short, mesh->numIndices); } - + part->mesh = mesh; part->startVertex = mesh->numAllocatedVertices; part->numIndices = numIndices; @@ -120,7 +120,7 @@ void spMesh_allocatePart(spMesh* mesh, spMeshPart* part, uint32_t numVertices, u part->textureHandle = textureHandle; part->srcBlend = srcBlend; part->dstBlend = dstBlend; - + mesh->numAllocatedVertices += numVertices; mesh->numAllocatedIndices += numIndices; } @@ -161,19 +161,19 @@ GLuint compileShader(GLenum shaderType, const char* shaderSource) { spShader* spShader_create(const char* vertexShaderSource, const char* fragmentShaderSource) { GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexShaderSource); GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource); - + GLuint program = glCreateProgram(); glAttachShader(program, vertexShader); glAttachShader(program, fragmentShader); glLinkProgram(program); - + GLint status; glGetProgramiv(program, GL_LINK_STATUS, &status); if (!status) { printf("Unknown error while linking program\n"); exit(-1); } - + spShader* shader = MALLOC(spShader, 1); shader->program = program; shader->vertexShader = vertexShader; @@ -190,14 +190,14 @@ void spShader_dispose(spShader* shader) { spTwoColorBatcher* spTwoColorBatcher_create() { spTwoColorBatcher* batcher = MALLOC(spTwoColorBatcher, 1); - + batcher->shader = spShader_create(TWO_COLOR_TINT_VERTEX_SHADER, TWO_COLOR_TINT_FRAGMENT_SHADER); batcher->positionAttributeLocation = glGetAttribLocation(batcher->shader->program, "a_position"); batcher->colorAttributeLocation = glGetAttribLocation(batcher->shader->program, "a_color"); batcher->color2AttributeLocation = glGetAttribLocation(batcher->shader->program, "a_color2"); batcher->texCoordsAttributeLocation = glGetAttribLocation(batcher->shader->program, "a_texCoords"); batcher->textureUniformLocation = glGetUniformLocation(batcher->shader->program, "texture"); - + glGenBuffers(1, &batcher->vertexBufferHandle); glGenBuffers(1, &batcher->indexBufferHandle); batcher->verticesBuffer = MALLOC(spVertex, MAX_VERTICES); @@ -214,20 +214,20 @@ void spTwoColorBatcher_add(spTwoColorBatcher* batcher, spMeshPart mesh) { if (batcher->numVertices + mesh.numVertices > MAX_VERTICES || batcher->numIndices + mesh.numIndices > MAX_INDICES) { spTwoColorBatcher_flush(batcher); } - + if (batcher->lastTextureHandle != mesh.textureHandle || batcher->lastSrcBlend != mesh.srcBlend || batcher->lastDstBlend != mesh.dstBlend) { spTwoColorBatcher_flush(batcher); } - + spVertex* vertices = &batcher->verticesBuffer[batcher->numVertices]; unsigned short* indices = &batcher->indicesBuffer[batcher->numIndices]; - + memcpy(vertices, &mesh.mesh->vertices[mesh.startVertex], mesh.numVertices * sizeof(spVertex)); unsigned short offset = (unsigned short)batcher->numVertices; for (int i = 0, j = mesh.startIndex, n = mesh.numIndices; i < n; i++, j++) { indices[i] = mesh.mesh->indices[j] + offset; } - + batcher->numIndices += mesh.numIndices; batcher->numVertices += mesh.numVertices; batcher->lastSrcBlend = mesh.srcBlend; @@ -238,39 +238,39 @@ void spTwoColorBatcher_add(spTwoColorBatcher* batcher, spMeshPart mesh) { void spTwoColorBatcher_flush(spTwoColorBatcher* batcher) { if (batcher->numVertices == 0 || batcher->numIndices == 0) return; - + glUseProgram(batcher->shader->program); - + glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, batcher->lastTextureHandle); glUniform1i(batcher->textureUniformLocation, 0); - + glBlendFunc(batcher->lastSrcBlend, batcher->lastDstBlend); - + glBindBuffer(GL_ARRAY_BUFFER, batcher->vertexBufferHandle); glBufferData(GL_ARRAY_BUFFER, sizeof(spVertex) * batcher->numVertices , batcher->verticesBuffer, GL_DYNAMIC_DRAW); - + glEnableVertexAttribArray(batcher->positionAttributeLocation); glEnableVertexAttribArray(batcher->colorAttributeLocation); glEnableVertexAttribArray(batcher->color2AttributeLocation); glEnableVertexAttribArray(batcher->texCoordsAttributeLocation); - + glVertexAttribPointer(batcher->positionAttributeLocation, 4, GL_FLOAT, GL_FALSE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, x)); glVertexAttribPointer(batcher->colorAttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, color)); glVertexAttribPointer(batcher->color2AttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, color2)); glVertexAttribPointer(batcher->texCoordsAttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, u)); - + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batcher->indexBufferHandle); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * batcher->numIndices, batcher->indicesBuffer, GL_STATIC_DRAW); - + glDrawElements(GL_TRIANGLES, (GLsizei)batcher->numIndices, GL_UNSIGNED_SHORT, 0); - + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - + glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); - + batcher->numIndices = 0; batcher->numVertices = 0; batcher->lastSrcBlend = -1; diff --git a/spine-cocos2d-objc/src/spine/GLUtils.h b/spine-cocos2d-objc/src/spine/GLUtils.h index 5c5b5b71f..c3c62a959 100644 --- a/spine-cocos2d-objc/src/spine/GLUtils.h +++ b/spine-cocos2d-objc/src/spine/GLUtils.h @@ -75,21 +75,21 @@ void spShader_dispose(spShader* shader); typedef struct spTwoColorBatcher { spShader* shader; - + uint32_t vertexBufferHandle; spVertex* verticesBuffer; uint32_t numVertices; - + uint32_t indexBufferHandle; unsigned short* indicesBuffer; uint32_t numIndices; - + int32_t positionAttributeLocation; int32_t colorAttributeLocation; int32_t color2AttributeLocation; int32_t texCoordsAttributeLocation; int32_t textureUniformLocation; - + uint32_t lastTextureHandle; uint32_t lastSrcBlend; uint32_t lastDstBlend; diff --git a/spine-cocos2d-objc/src/spine/SkeletonAnimation.h b/spine-cocos2d-objc/src/spine/SkeletonAnimation.h index 6b31f31e7..3a99c0efe 100644 --- a/spine-cocos2d-objc/src/spine/SkeletonAnimation.h +++ b/spine-cocos2d-objc/src/spine/SkeletonAnimation.h @@ -48,9 +48,9 @@ typedef void(^spEventListener)(spTrackEntry* entry, spEvent* event); float _timeScale; spStartListener _startListener; - spInterruptListener _interruptListener; + spInterruptListener _interruptListener; spEndListener _endListener; - spDisposeListener _disposeListener; + spDisposeListener _disposeListener; spCompleteListener _completeListener; spEventListener _eventListener; } diff --git a/spine-cocos2d-objc/src/spine/SkeletonAnimation.m b/spine-cocos2d-objc/src/spine/SkeletonAnimation.m index 73cff8daa..7cf14db00 100644 --- a/spine-cocos2d-objc/src/spine/SkeletonAnimation.m +++ b/spine-cocos2d-objc/src/spine/SkeletonAnimation.m @@ -107,27 +107,27 @@ static _TrackEntryListeners* getListeners (spTrackEntry* entry) { - (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData { self = [super initWithData:skeletonData ownsSkeletonData:ownsSkeletonData]; if (!self) return nil; - + [self initialize]; - + return self; } - (id) initWithFile:(NSString*)skeletonDataFile atlas:(spAtlas*)atlas scale:(float)scale { self = [super initWithFile:skeletonDataFile atlas:atlas scale:scale]; if (!self) return nil; - + [self initialize]; - + return self; } - (id) initWithFile:(NSString*)skeletonDataFile atlasFile:(NSString*)atlasFile scale:(float)scale { self = [super initWithFile:skeletonDataFile atlasFile:atlasFile scale:scale]; if (!self) return nil; - + [self initialize]; - + return self; } @@ -155,7 +155,7 @@ static _TrackEntryListeners* getListeners (spTrackEntry* entry) { - (void) setAnimationStateData:(spAnimationStateData*)stateData { NSAssert(stateData, @"stateData cannot be null."); - + if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); spAnimationState_dispose(_state); diff --git a/spine-cocos2d-objc/src/spine/SkeletonRenderer.h b/spine-cocos2d-objc/src/spine/SkeletonRenderer.h index fdf467cad..0c670d0eb 100644 --- a/spine-cocos2d-objc/src/spine/SkeletonRenderer.h +++ b/spine-cocos2d-objc/src/spine/SkeletonRenderer.h @@ -38,7 +38,7 @@ bool _debugBones; bool _premultipliedAlpha; bool _twoColorTint; - bool _skipVisibilityCheck; + bool _skipVisibilityCheck; ccBlendFunc _blendFunc; CCDrawNode* _drawNode; bool _ownsSkeletonData; diff --git a/spine-cocos2d-objc/src/spine/SkeletonRenderer.m b/spine-cocos2d-objc/src/spine/SkeletonRenderer.m index 8e64e91a8..61e679448 100644 --- a/spine-cocos2d-objc/src/spine/SkeletonRenderer.m +++ b/spine-cocos2d-objc/src/spine/SkeletonRenderer.m @@ -68,7 +68,7 @@ static bool handlerQueued = false; batcher = spTwoColorBatcher_create(); mesh = spMesh_create(64000, 32000); } - + _ownsSkeletonData = ownsSkeletonData; _worldVertices = MALLOC(float, 1000); // Max number of vertices per mesh. @@ -81,7 +81,7 @@ static bool handlerQueued = false; _drawNode = [[CCDrawNode alloc] init]; [_drawNode setBlendMode: [CCBlendMode premultipliedAlphaMode]]; [self addChild:_drawNode]; - + [self setShader:[CCShader positionTextureColorShader]]; _premultipliedAlpha = true; @@ -89,7 +89,7 @@ static bool handlerQueued = false; CCBlendFuncSrcColor: @(GL_ONE), CCBlendFuncDstColor: @(GL_ONE_MINUS_SRC_COLOR)} ]; - + _clipper = spSkeletonClipping_create(); _effect = 0; } @@ -167,15 +167,15 @@ static bool handlerQueued = false; // notification system that may break if the block is called on a // separate thread. if (!handlerQueued) { - [[CCDirector sharedDirector] addFrameCompletionHandler: ^{ + [[CCDirector sharedDirector] addFrameCompletionHandler: ^{ spMesh_clearParts(mesh); handlerQueued = false; }]; handlerQueued = true; } - + if (_effect) _effect->begin(_effect, _skeleton); - + CCColor* nodeColor = self.color; _skeleton->color.r = nodeColor.red; _skeleton->color.g = nodeColor.green; @@ -232,7 +232,7 @@ static bool handlerQueued = false; } default: ; } - + if (texture) { if (slot->data->blendMode != blendMode) { blendMode = slot->data->blendMode; @@ -283,9 +283,9 @@ static bool handlerQueued = false; GLKVector2 extents = GLKVector2Make((maxX - minX) / 2, (maxY - minY) / 2); isVisible = CCRenderCheckVisbility(transform, center, extents); } - + if (isVisible) { - + if (spSkeletonClipping_isClipping(_clipper)) { spSkeletonClipping_clipTriangles(_clipper, vertices, verticesCount, triangles, trianglesCount, uvs, 2); vertices = _clipper->clippedVertices->items; @@ -294,7 +294,7 @@ static bool handlerQueued = false; triangles = _clipper->clippedTriangles->items; trianglesCount = _clipper->clippedTriangles->size; } - + if (trianglesCount > 0) { if (!self.twoColorTint) { CCRenderBuffer buffer = [renderer enqueueTriangles:(trianglesCount / 3) andVertexes:verticesCount withState:self.renderState globalSortOrder:0]; @@ -330,13 +330,13 @@ static bool handlerQueued = false; } else { dr = dg = db = 0; } - + spMeshPart meshPart; spMesh_allocatePart(mesh, &meshPart, verticesCount / 2, trianglesCount, self.texture.name, srcBlend, dstBlend); - + spVertex* verts = &meshPart.mesh->vertices[meshPart.startVertex]; unsigned short* indices = &meshPart.mesh->indices[meshPart.startIndex]; - + if (_effect) { spColor light; light.r = r; @@ -351,13 +351,13 @@ static bool handlerQueued = false; for (int i = 0; i * 2 < verticesCount; i++, verts++) { spColor lightCopy = light; spColor darkCopy = dark; - + CCVertex vertex; vertex.position = GLKVector4Make(vertices[i * 2], vertices[i * 2 + 1], 0.0, 1.0); verts->u = uvs[i * 2]; verts->v = 1 - uvs[i * 2 + 1]; _effect->transform(_effect, &vertex.position.x, &vertex.position.y, &verts->u, &verts->v, &lightCopy, &darkCopy); - + vertex = CCVertexApplyTransform(vertex, transform); verts->x = vertex.position.x; verts->y = vertex.position.y; @@ -365,7 +365,7 @@ static bool handlerQueued = false; verts->w = vertex.position.w; verts->color = ((unsigned short)(lightCopy.r * 255))| ((unsigned short)(lightCopy.g * 255)) << 8 | ((unsigned short)(lightCopy.b * 255)) <<16 | ((unsigned short)(lightCopy.a * 255)) << 24; verts->color2 = ((unsigned short)(darkCopy.r * 255)) | ((unsigned short)(darkCopy.g * 255)) << 8 | ((unsigned short)(darkCopy.b * 255)) << 16 | ((unsigned short)(darkCopy.a * 255)) << 24; - + } } else { for (int i = 0; i * 2 < verticesCount; i++, verts++) { @@ -382,11 +382,11 @@ static bool handlerQueued = false; verts->v = 1 - uvs[i * 2 + 1]; } } - + for (int j = 0; j < trianglesCount; j++, indices++) { *indices = triangles[j]; } - + [renderer enqueueBlock:^{ spTwoColorBatcher_add(batcher, meshPart); } globalSortOrder:0 debugLabel: nil threadSafe: false]; @@ -397,13 +397,13 @@ static bool handlerQueued = false; spSkeletonClipping_clipEnd(_clipper, slot); } spSkeletonClipping_clipEnd2(_clipper); - + if (self.twoColorTint) { [renderer enqueueBlock:^{ spTwoColorBatcher_flush(batcher); } globalSortOrder:0 debugLabel: nil threadSafe: false]; } - + [_drawNode clear]; if (_debugSlots) { // Slots. @@ -430,7 +430,7 @@ static bool handlerQueued = false; float y = bone->data->length * bone->c + bone->worldY; [_drawNode drawSegmentFrom:ccp(bone->worldX, bone->worldY) to: ccp(x, y)radius:2 color:[CCColor redColor]]; } - + // Bone origins. for (int i = 0, n = _skeleton->bonesCount; i < n; i++) { spBone *bone = _skeleton->bones[i]; @@ -439,7 +439,7 @@ static bool handlerQueued = false; if (i == 0) [_drawNode drawDot:ccp(bone->worldX, bone->worldY) radius:4 color:[CCColor blueColor]]; } } - + if (_effect) _effect->end(_effect); } diff --git a/spine-cocos2dx/src/spine/SkeletonAnimation.cpp b/spine-cocos2dx/src/spine/SkeletonAnimation.cpp index 78f0a4958..fae26293f 100644 --- a/spine-cocos2dx/src/spine/SkeletonAnimation.cpp +++ b/spine-cocos2dx/src/spine/SkeletonAnimation.cpp @@ -40,25 +40,26 @@ using std::vector; namespace spine { typedef struct _TrackEntryListeners { - StartListener startListener; - InterruptListener interruptListener; - EndListener endListener; - DisposeListener disposeListener; - CompleteListener completeListener; - EventListener eventListener; + StartListener startListener; + InterruptListener interruptListener; + EndListener endListener; + DisposeListener disposeListener; + CompleteListener completeListener; + EventListener eventListener; } _TrackEntryListeners; - + void animationCallback (AnimationState* state, EventType type, TrackEntry* entry, Event* event) { ((SkeletonAnimation*)state->getRendererObject())->onAnimationStateEvent(entry, type, event); } void trackEntryCallback (AnimationState* state, EventType type, TrackEntry* entry, Event* event) { ((SkeletonAnimation*)state->getRendererObject())->onTrackEntryEvent(entry, type, event); - if (type == EventType_Dispose) + if (type == EventType_Dispose) { if (entry->getRendererObject()) { delete (spine::_TrackEntryListeners*)entry->getRendererObject(); entry->setRendererObject(NULL); } + } } static _TrackEntryListeners* getListeners (TrackEntry* entry) { @@ -68,7 +69,7 @@ static _TrackEntryListeners* getListeners (TrackEntry* entry) { } return (_TrackEntryListeners*)entry->getRendererObject(); } - + // SkeletonAnimation* SkeletonAnimation::createWithData (SkeletonData* skeletonData, bool ownsSkeletonData) { @@ -150,7 +151,7 @@ void SkeletonAnimation::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &t void SkeletonAnimation::setAnimationStateData (AnimationStateData* stateData) { CCASSERT(stateData, "stateData cannot be null."); - if (_ownsAnimationStateData) delete _state->getData(); + if (_ownsAnimationStateData) delete _state->getData(); delete _state; _ownsAnimationStateData = false; @@ -180,7 +181,7 @@ TrackEntry* SkeletonAnimation::addAnimation (int trackIndex, const std::string& } return _state->addAnimation(trackIndex, animation, loop, delay); } - + TrackEntry* SkeletonAnimation::setEmptyAnimation (int trackIndex, float mixDuration) { return _state->setEmptyAnimation(trackIndex, mixDuration); } @@ -214,15 +215,15 @@ void SkeletonAnimation::onAnimationStateEvent (TrackEntry* entry, EventType type case EventType_Start: if (_startListener) _startListener(entry); break; - case EventType_Interrupt: - if (_interruptListener) _interruptListener(entry); - break; + case EventType_Interrupt: + if (_interruptListener) _interruptListener(entry); + break; case EventType_End: if (_endListener) _endListener(entry); break; - case EventType_Dispose: - if (_disposeListener) _disposeListener(entry); - break; + case EventType_Dispose: + if (_disposeListener) _disposeListener(entry); + break; case EventType_Complete: if (_completeListener) _completeListener(entry); break; @@ -239,15 +240,15 @@ void SkeletonAnimation::onTrackEntryEvent (TrackEntry* entry, EventType type, Ev case EventType_Start: if (listeners->startListener) listeners->startListener(entry); break; - case EventType_Interrupt: - if (listeners->interruptListener) listeners->interruptListener(entry); - break; + case EventType_Interrupt: + if (listeners->interruptListener) listeners->interruptListener(entry); + break; case EventType_End: if (listeners->endListener) listeners->endListener(entry); break; - case EventType_Dispose: - if (listeners->disposeListener) listeners->disposeListener(entry); - break; + case EventType_Dispose: + if (listeners->disposeListener) listeners->disposeListener(entry); + break; case EventType_Complete: if (listeners->completeListener) listeners->completeListener(entry); break; @@ -260,17 +261,17 @@ void SkeletonAnimation::onTrackEntryEvent (TrackEntry* entry, EventType type, Ev void SkeletonAnimation::setStartListener (const StartListener& listener) { _startListener = listener; } - + void SkeletonAnimation::setInterruptListener (const InterruptListener& listener) { - _interruptListener = listener; + _interruptListener = listener; } - + void SkeletonAnimation::setEndListener (const EndListener& listener) { _endListener = listener; } - + void SkeletonAnimation::setDisposeListener (const DisposeListener& listener) { - _disposeListener = listener; + _disposeListener = listener; } void SkeletonAnimation::setCompleteListener (const CompleteListener& listener) { @@ -284,17 +285,17 @@ void SkeletonAnimation::setEventListener (const EventListener& listener) { void SkeletonAnimation::setTrackStartListener (TrackEntry* entry, const StartListener& listener) { getListeners(entry)->startListener = listener; } - + void SkeletonAnimation::setTrackInterruptListener (TrackEntry* entry, const InterruptListener& listener) { - getListeners(entry)->interruptListener = listener; + getListeners(entry)->interruptListener = listener; } void SkeletonAnimation::setTrackEndListener (TrackEntry* entry, const EndListener& listener) { getListeners(entry)->endListener = listener; } - + void SkeletonAnimation::setTrackDisposeListener (TrackEntry* entry, const DisposeListener& listener) { - getListeners(entry)->disposeListener = listener; + getListeners(entry)->disposeListener = listener; } void SkeletonAnimation::setTrackCompleteListener (TrackEntry* entry, const CompleteListener& listener) { diff --git a/spine-cocos2dx/src/spine/SkeletonAnimation.h b/spine-cocos2dx/src/spine/SkeletonAnimation.h index 7db3dfba1..6e43feaed 100644 --- a/spine-cocos2dx/src/spine/SkeletonAnimation.h +++ b/spine-cocos2dx/src/spine/SkeletonAnimation.h @@ -82,16 +82,16 @@ public: void clearTrack (int trackIndex = 0); void setStartListener (const StartListener& listener); - void setInterruptListener (const InterruptListener& listener); + void setInterruptListener (const InterruptListener& listener); void setEndListener (const EndListener& listener); - void setDisposeListener (const DisposeListener& listener); + void setDisposeListener (const DisposeListener& listener); void setCompleteListener (const CompleteListener& listener); void setEventListener (const EventListener& listener); void setTrackStartListener (TrackEntry* entry, const StartListener& listener); - void setTrackInterruptListener (TrackEntry* entry, const InterruptListener& listener); + void setTrackInterruptListener (TrackEntry* entry, const InterruptListener& listener); void setTrackEndListener (TrackEntry* entry, const EndListener& listener); - void setTrackDisposeListener (TrackEntry* entry, const DisposeListener& listener); + void setTrackDisposeListener (TrackEntry* entry, const DisposeListener& listener); void setTrackCompleteListener (TrackEntry* entry, const CompleteListener& listener); void setTrackEventListener (TrackEntry* entry, const EventListener& listener); @@ -114,9 +114,9 @@ protected: bool _firstDraw; StartListener _startListener; - InterruptListener _interruptListener; + InterruptListener _interruptListener; EndListener _endListener; - DisposeListener _disposeListener; + DisposeListener _disposeListener; CompleteListener _completeListener; EventListener _eventListener; diff --git a/spine-cocos2dx/src/spine/SkeletonBatch.cpp b/spine-cocos2dx/src/spine/SkeletonBatch.cpp index 15ec32db3..e002f6de7 100644 --- a/spine-cocos2dx/src/spine/SkeletonBatch.cpp +++ b/spine-cocos2dx/src/spine/SkeletonBatch.cpp @@ -56,9 +56,9 @@ SkeletonBatch::SkeletonBatch () { for (unsigned int i = 0; i < INITIAL_SIZE; i++) { _commandsPool.push_back(new TrianglesCommand()); } - + reset (); - + // callback after drawing is finished so we can clear out the batch state // for the next frame Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_AFTER_DRAW_RESET_POSITION, [this](EventCustom* eventCustom){ @@ -68,7 +68,7 @@ SkeletonBatch::SkeletonBatch () { SkeletonBatch::~SkeletonBatch () { Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(EVENT_AFTER_DRAW_RESET_POSITION); - + for (unsigned int i = 0; i < _commandsPool.size(); i++) { delete _commandsPool[i]; _commandsPool[i] = nullptr; @@ -78,7 +78,7 @@ SkeletonBatch::~SkeletonBatch () { void SkeletonBatch::update (float delta) { reset(); } - + cocos2d::V3F_C4B_T2F* SkeletonBatch::allocateVertices(uint32_t numVertices) { if (_vertices.size() - _numVertices < numVertices) { cocos2d::V3F_C4B_T2F* oldData = _vertices.data(); @@ -90,18 +90,18 @@ cocos2d::V3F_C4B_T2F* SkeletonBatch::allocateVertices(uint32_t numVertices) { triangles.verts = newData + (triangles.verts - oldData); } } - + cocos2d::V3F_C4B_T2F* vertices = _vertices.data() + _numVertices; _numVertices += numVertices; return vertices; } - + void SkeletonBatch::deallocateVertices(uint32_t numVertices) { _numVertices -= numVertices; } - -unsigned short* SkeletonBatch::allocateIndices(uint32_t numIndices) { + +unsigned short* SkeletonBatch::allocateIndices(uint32_t numIndices) { if (_indices.getCapacity() - _indices.size() < numIndices) { unsigned short* oldData = _indices.buffer(); int oldSize = _indices.size(); @@ -115,7 +115,7 @@ unsigned short* SkeletonBatch::allocateIndices(uint32_t numIndices) { } } } - + unsigned short* indices = _indices.buffer() + _indices.size(); _indices.setSize(_indices.size() + numIndices, 0); return indices; @@ -125,7 +125,7 @@ void SkeletonBatch::deallocateIndices(uint32_t numIndices) { _indices.setSize(_indices.size() - numIndices, 0); } - + cocos2d::TrianglesCommand* SkeletonBatch::addCommand(cocos2d::Renderer* renderer, float globalOrder, cocos2d::Texture2D* texture, cocos2d::GLProgramState* glProgramState, cocos2d::BlendFunc blendType, const cocos2d::TrianglesCommand::Triangles& triangles, const cocos2d::Mat4& mv, uint32_t flags) { TrianglesCommand* command = nextFreeCommand(); command->init(globalOrder, texture, glProgramState, blendType, triangles, mv, flags); @@ -142,7 +142,7 @@ void SkeletonBatch::reset() { cocos2d::TrianglesCommand* SkeletonBatch::nextFreeCommand() { if (_commandsPool.size() <= _nextFreeCommand) { unsigned int newSize = _commandsPool.size() * 2 + 1; - for (int i = _commandsPool.size(); i < newSize; i++) { + for (int i = _commandsPool.size(); i < newSize; i++) { _commandsPool.push_back(new TrianglesCommand()); } } diff --git a/spine-cocos2dx/src/spine/SkeletonBatch.h b/spine-cocos2dx/src/spine/SkeletonBatch.h index 85fc18231..e8e8bfebf 100644 --- a/spine-cocos2dx/src/spine/SkeletonBatch.h +++ b/spine-cocos2dx/src/spine/SkeletonBatch.h @@ -35,41 +35,41 @@ #include namespace spine { - - class SkeletonBatch { - public: - static SkeletonBatch* getInstance (); - - static void destroyInstance (); - - void update (float delta); - + + class SkeletonBatch { + public: + static SkeletonBatch* getInstance (); + + static void destroyInstance (); + + void update (float delta); + cocos2d::V3F_C4B_T2F* allocateVertices(uint32_t numVertices); void deallocateVertices(uint32_t numVertices); unsigned short* allocateIndices(uint32_t numIndices); void deallocateIndices(uint32_t numVertices); cocos2d::TrianglesCommand* addCommand(cocos2d::Renderer* renderer, float globalOrder, cocos2d::Texture2D* texture, cocos2d::GLProgramState* glProgramState, cocos2d::BlendFunc blendType, const cocos2d::TrianglesCommand::Triangles& triangles, const cocos2d::Mat4& mv, uint32_t flags); - - protected: - SkeletonBatch (); - virtual ~SkeletonBatch (); - + + protected: + SkeletonBatch (); + virtual ~SkeletonBatch (); + void reset (); - + cocos2d::TrianglesCommand* nextFreeCommand (); - + // pool of commands std::vector _commandsPool; uint32_t _nextFreeCommand; - + // pool of vertices std::vector _vertices; uint32_t _numVertices; - + // pool of indices Vector _indices; - }; - + }; + } #endif // SPINE_SKELETONBATCH_H_ diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp index 64bf98a1e..0efacaf10 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp @@ -52,7 +52,7 @@ namespace spine { Color4B ColorToColor4B(const Color& color); bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex); } - + // C Variable length array #ifdef _MSC_VER // VLA not supported, use _malloca @@ -71,7 +71,7 @@ namespace spine { node->autorelease(); return node; } - + SkeletonRenderer* SkeletonRenderer::createWithData (SkeletonData* skeletonData, bool ownsSkeletonData) { SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData); node->autorelease(); @@ -101,13 +101,13 @@ namespace spine { _skeleton->setToSetupPose(); _skeleton->updateWorldTransform(); } - + void SkeletonRenderer::setupGLProgramState (bool twoColorTintEnabled) { if (twoColorTintEnabled) { setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState()); return; } - + Texture2D *texture = nullptr; for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) { Slot* slot = _skeleton->getDrawOrder()[i]; @@ -123,7 +123,7 @@ namespace spine { else { continue; } - + if (texture != nullptr) { break; } @@ -139,7 +139,7 @@ namespace spine { SkeletonRenderer::SkeletonRenderer () : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _timeScale(1), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { } - + SkeletonRenderer::SkeletonRenderer(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _timeScale(1), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData, ownsAtlas); @@ -164,7 +164,7 @@ namespace spine { if (_ownsSkeletonData) delete _skeleton->getData(); if (_ownsSkeleton) delete _skeleton; if (_ownsAtlas) delete _atlas; - delete _attachmentLoader; + delete _attachmentLoader; delete _clipper; } @@ -175,7 +175,7 @@ namespace spine { _ownsAtlas = ownsAtlas; initialize(); } - + void SkeletonRenderer::initWithData (SkeletonData* skeletonData, bool ownsSkeletonData) { _ownsSkeleton = true; setSkeletonData(skeletonData, ownsSkeletonData); @@ -207,34 +207,34 @@ namespace spine { json.setScale(scale); SkeletonData* skeletonData = json.readSkeletonDataFile(skeletonDataFile.c_str()); CCASSERT(skeletonData, !json.getError().isEmpty() ? json.getError().buffer() : "Error reading skeleton data."); - + _ownsSkeleton = true; _ownsAtlas = true; setSkeletonData(skeletonData, true); initialize(); } - + void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) { _atlas = atlas; _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); - + SkeletonBinary binary(_attachmentLoader); binary.setScale(scale); SkeletonData* skeletonData = binary.readSkeletonDataFile(skeletonDataFile.c_str()); CCASSERT(skeletonData, !binary.getError().isEmpty() ? binary.getError().buffer() : "Error reading skeleton data."); _ownsSkeleton = true; setSkeletonData(skeletonData, true); - + initialize(); } void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) { _atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true); CCASSERT(_atlas, "Error reading atlas file."); - + _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); - + SkeletonBinary binary(_attachmentLoader); binary.setScale(scale); SkeletonData* skeletonData = binary.readSkeletonDataFile(skeletonDataFile.c_str()); @@ -242,7 +242,7 @@ namespace spine { _ownsSkeleton = true; _ownsAtlas = true; setSkeletonData(skeletonData, true); - + initialize(); } @@ -295,7 +295,7 @@ namespace spine { nodeColor.g = displayedColor.g / 255.f; nodeColor.b = displayedColor.b / 255.f; nodeColor.a = getDisplayedOpacity() / 255.f; - + Color color; Color darkColor; const float darkPremultipliedAlpha = _premultipliedAlpha ? 1.f : 0; @@ -303,7 +303,7 @@ namespace spine { TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr; for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) { Slot* slot = _skeleton->getDrawOrder()[i];; - + if (slotIsOutRange(*slot, _startSlotIndex, _endSlotIndex)) { _clipper->clipEnd(*slot); continue; @@ -322,11 +322,11 @@ namespace spine { cocos2d::TrianglesCommand::Triangles triangles; TwoColorTriangles trianglesTwoColor; - + if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) { RegionAttachment* attachment = static_cast(slot->getAttachment()); attachmentVertices = static_cast(attachment->getRendererObject()); - + // Early exit if attachment is invisible if (attachment->getColor().a == 0) { _clipper->clipEnd(*slot); @@ -359,13 +359,13 @@ namespace spine { // Copy world vertices to triangle vertices interleaveCoordinates(dstTriangleVertices, worldCoordPtr, 4, dstStride); worldCoordPtr += 8; - + color = attachment->getColor(); } else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment* attachment = (MeshAttachment*)slot->getAttachment(); attachmentVertices = (AttachmentVertices*)attachment->getRendererObject(); - + float* dstTriangleVertices = nullptr; int dstStride = 0; // in floats int dstVertexCount = 0; @@ -390,12 +390,12 @@ namespace spine { dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float); dstVertexCount = trianglesTwoColor.vertCount; } - + // Copy world vertices to triangle vertices //assert(dstVertexCount * 2 == attachment->super.worldVerticesLength); interleaveCoordinates(dstTriangleVertices, worldCoordPtr, dstVertexCount, dstStride); worldCoordPtr += dstVertexCount * 2; - + color = attachment->getColor(); } else if (slot->getAttachment()->getRTTI().isExactly(ClippingAttachment::rtti)) { @@ -406,7 +406,7 @@ namespace spine { _clipper->clipEnd(*slot); continue; } - + if (slot->hasDarkColor()) { darkColor = slot->getDarkColor(); } else { @@ -415,7 +415,7 @@ namespace spine { darkColor.b = 0; } darkColor.a = darkPremultipliedAlpha; - + color.a *= nodeColor.a * _skeleton->getColor().a * slot->getColor().a; // skip rendering if the color of this attachment is 0 if (color.a == 0){ @@ -431,7 +431,7 @@ namespace spine { color.g *= color.a; color.b *= color.a; } - + const cocos2d::Color4B color4B = ColorToColor4B(color); const cocos2d::Color4B darkColor4B = ColorToColor4B(darkColor); const BlendFunc blendFunc = makeBlendFunc(slot->getData().getBlendMode(), _premultipliedAlpha); @@ -440,21 +440,21 @@ namespace spine { if (_clipper->isClipping()) { _clipper->clipTriangles((float*)&triangles.verts[0].vertices, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, sizeof(cocos2d::V3F_C4B_T2F) / 4); batch->deallocateVertices(triangles.vertCount); - + if (_clipper->getClippedTriangles().size() == 0){ _clipper->clipEnd(*slot); continue; } - + triangles.vertCount = _clipper->getClippedVertices().size() / 2; triangles.verts = batch->allocateVertices(triangles.vertCount); triangles.indexCount = _clipper->getClippedTriangles().size(); triangles.indices = batch->allocateIndices(triangles.indexCount); memcpy(triangles.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); - + cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags); - + const float* verts = _clipper->getClippedVertices().buffer(); const float* uvs = _clipper->getClippedUVs().buffer(); if (_effect) { @@ -481,9 +481,9 @@ namespace spine { } } else { // Not clipping - + cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags); - + if (_effect) { V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; Color darkTmp; @@ -501,27 +501,27 @@ namespace spine { } } else { // Two tints - + if (_clipper->isClipping()) { _clipper->clipTriangles((float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, sizeof(V3F_C4B_C4B_T2F) / 4); twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount); - + if (_clipper->getClippedTriangles().size() == 0){ _clipper->clipEnd(*slot); continue; } - + trianglesTwoColor.vertCount = _clipper->getClippedVertices().size() / 2; trianglesTwoColor.verts = twoColorBatch->allocateVertices(trianglesTwoColor.vertCount); trianglesTwoColor.indexCount = _clipper->getClippedTriangles().size(); trianglesTwoColor.indices = twoColorBatch->allocateIndices(trianglesTwoColor.indexCount); memcpy(trianglesTwoColor.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); - + TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags); - + const float* verts = _clipper->getClippedVertices().buffer(); const float* uvs = _clipper->getClippedUVs().buffer(); - + if (_effect) { V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2, ++vertex) { @@ -548,7 +548,7 @@ namespace spine { } } else { TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags); - + if (_effect) { V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { @@ -570,10 +570,10 @@ namespace spine { _clipper->clipEnd(*slot); } _clipper->clipEnd(); - + if (lastTwoColorTrianglesCommand) { Node* parent = this->getParent(); - + // We need to decide if we can postpone flushing the current // batch. We can postpone if the next sibling node is a // two color tinted skeleton with the same global-z. @@ -607,7 +607,7 @@ namespace spine { } } } - + if (_effect) _effect->end(); if (_debugBoundingRect || _debugSlots || _debugBones || _debugMeshes) { @@ -627,7 +627,7 @@ namespace spine { #endif DrawNode* drawNode = DrawNode::create(); - + // Draw bounding rectangle if (_debugBoundingRect) { glLineWidth(2); @@ -649,7 +649,7 @@ namespace spine { V3F_C4B_T2F_Quad quad; for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) { Slot* slot = _skeleton->getDrawOrder()[i]; - + if (!slot->getBone().isActive()) continue; if (!slot->getAttachment() || !slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) continue; @@ -670,7 +670,7 @@ namespace spine { drawNode->drawPoly(points, 4, true, Color4F::BLUE); } } - + if (_debugBones) { // Bone lengths. glLineWidth(2); @@ -690,7 +690,7 @@ namespace spine { if (i == 0) color = Color4F::GREEN; } } - + if (_debugMeshes) { // Meshes. glLineWidth(1); @@ -717,7 +717,7 @@ namespace spine { VLA_FREE(worldCoord); } } - + drawNode->draw(renderer, transform, transformFlags); #if !defined(USE_MATRIX_STACK_PROJECTION_ONLY) director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); @@ -768,7 +768,7 @@ namespace spine { bool SkeletonRenderer::setAttachment (const std::string& slotName, const char* attachmentName) { return _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false; } - + void SkeletonRenderer::setTwoColorTint(bool enabled) { setupGLProgramState(enabled); } @@ -776,11 +776,11 @@ namespace spine { bool SkeletonRenderer::isTwoColorTint() { return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState(); } - + void SkeletonRenderer::setVertexEffect(VertexEffect *effect) { this->_effect = effect; } - + void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) { _startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex; _endSlotIndex = endSlotIndex == -1 ? std::numeric_limits::max() : endSlotIndex; @@ -810,7 +810,7 @@ namespace spine { bool SkeletonRenderer::getDebugBonesEnabled () const { return _debugBones; } - + void SkeletonRenderer::setDebugMeshesEnabled (bool enabled) { _debugMeshes = enabled; } diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.h b/spine-cocos2dx/src/spine/SkeletonRenderer.h index 975cb1cdd..709e759bf 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.h +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.h @@ -63,10 +63,10 @@ namespace spine { void setDebugBonesEnabled(bool enabled); bool getDebugBonesEnabled() const; - + void setDebugMeshesEnabled(bool enabled); bool getDebugMeshesEnabled() const; - + void setDebugBoundingRectEnabled(bool enabled); bool getDebugBoundingRectEnabled() const; @@ -81,14 +81,14 @@ namespace spine { Bone* findBone (const std::string& boneName) const; /* Returns 0 if the slot was not found. */ Slot* findSlot (const std::string& slotName) const; - + /* Sets the skin used to look up attachments not found in the SkeletonData defaultSkin. Attachments from the new skin are * attached if the corresponding attachment from the old skin was attached. * @param skin May be empty string ("") for no skin.*/ void setSkin (const std::string& skinName); /** @param skin May be 0 for no skin.*/ void setSkin (const char* skinName); - + /* Returns 0 if the slot or attachment was not found. */ Attachment* getAttachment (const std::string& slotName, const std::string& attachmentName) const; /* Returns false if the slot or attachment was not found. @@ -96,15 +96,15 @@ namespace spine { bool setAttachment (const std::string& slotName, const std::string& attachmentName); /* @param attachmentName May be 0 for no attachment. */ bool setAttachment (const std::string& slotName, const char* attachmentName); - + /* Enables/disables two color tinting for this instance. May break batching */ void setTwoColorTint(bool enabled); /* Whether two color tinting is enabled */ bool isTwoColorTint(); - + /* Sets the vertex effect to be used, set to 0 to disable vertex effects */ void setVertexEffect(VertexEffect* effect); - + /* Sets the range of slots that should be rendered. Use -1, -1 to clear the range */ void setSlotsRange(int startSlotIndex, int endSlotIndex); @@ -113,7 +113,7 @@ namespace spine { const cocos2d::BlendFunc& getBlendFunc () const override; void setOpacityModifyRGB (bool value) override; bool isOpacityModifyRGB () const override; - + CC_CONSTRUCTOR_ACCESS: SkeletonRenderer (); SkeletonRenderer(Skeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false); @@ -131,7 +131,7 @@ namespace spine { void initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); virtual void initialize (); - + protected: void setSkeletonData (SkeletonData* skeletonData, bool ownsSkeletonData); void setupGLProgramState(bool twoColorTintEnabled); @@ -154,7 +154,7 @@ namespace spine { SkeletonClipping* _clipper; VertexEffect* _effect; cocos2d::Rect _boundingRect; - + int _startSlotIndex; int _endSlotIndex; }; diff --git a/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.cpp b/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.cpp index 7f4dd3e0a..f9df30c9f 100644 --- a/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.cpp +++ b/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.cpp @@ -83,7 +83,7 @@ void TwoColorTrianglesCommand::generateMaterialID() { setSkipBatching(true); } else { - int glProgram = (int)_glProgram->getProgram(); + int glProgram = (int)_glProgram->getProgram(); _materialID = glProgram + (int)_textureID + (int)_blendType.src + (int)_blendType.dst; } } @@ -91,17 +91,17 @@ void TwoColorTrianglesCommand::generateMaterialID() { void TwoColorTrianglesCommand::useMaterial() const { //Set texture GL::bindTexture2D(_textureID); - + if (_alphaTextureID > 0) { // ANDROID ETC1 ALPHA supports. GL::bindTexture2DN(1, _alphaTextureID); } //set blend mode GL::blendFunc(_blendType.src, _blendType.dst); - + _glProgramState->apply(_mv); } - + void TwoColorTrianglesCommand::draw() { SkeletonTwoColorBatch::getInstance()->batch(this); } @@ -143,7 +143,7 @@ varying vec2 v_texCoord; void main() { vec4 texColor = texture2D(CC_Texture0, v_texCoord); float alpha = texColor.a * v_light.a; - gl_FragColor.a = alpha; + gl_FragColor.a = alpha; gl_FragColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb; } ); @@ -167,19 +167,19 @@ SkeletonTwoColorBatch::SkeletonTwoColorBatch () : _vertexBuffer(0), _indexBuffer for (unsigned int i = 0; i < INITIAL_SIZE; i++) { _commandsPool.push_back(new TwoColorTrianglesCommand()); } - + reset (); - + // callback after drawing is finished so we can clear out the batch state // for the next frame Director::getInstance()->getEventDispatcher()->addCustomEventListener(EVENT_AFTER_DRAW_RESET_POSITION, [this](EventCustom* eventCustom){ this->update(0); }); - + _twoColorTintShader = cocos2d::GLProgram::createWithByteArrays(TWO_COLOR_TINT_VERTEX_SHADER, TWO_COLOR_TINT_FRAGMENT_SHADER); _twoColorTintShaderState = GLProgramState::getOrCreateWithGLProgram(_twoColorTintShader); _twoColorTintShaderState->retain(); - + glGenBuffers(1, &_vertexBufferHandle); _vertexBuffer = new V3F_C4B_C4B_T2F[MAX_VERTICES]; glGenBuffers(1, &_indexBufferHandle); @@ -192,7 +192,7 @@ SkeletonTwoColorBatch::SkeletonTwoColorBatch () : _vertexBuffer(0), _indexBuffer SkeletonTwoColorBatch::~SkeletonTwoColorBatch () { Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(EVENT_AFTER_DRAW_RESET_POSITION); - + for (unsigned int i = 0; i < _commandsPool.size(); i++) { delete _commandsPool[i]; _commandsPool[i] = nullptr; @@ -202,7 +202,7 @@ SkeletonTwoColorBatch::~SkeletonTwoColorBatch () { delete[] _indexBuffer; } -void SkeletonTwoColorBatch::update (float delta) { +void SkeletonTwoColorBatch::update (float delta) { reset(); } @@ -217,13 +217,13 @@ V3F_C4B_C4B_T2F* SkeletonTwoColorBatch::allocateVertices(uint32_t numVertices) { triangles.verts = newData + (triangles.verts - oldData); } } - + V3F_C4B_C4B_T2F* vertices = _vertices.data() + _numVertices; _numVertices += numVertices; return vertices; } - - + + void SkeletonTwoColorBatch::deallocateVertices(uint32_t numVertices) { _numVertices -= numVertices; } @@ -243,7 +243,7 @@ unsigned short* SkeletonTwoColorBatch::allocateIndices(uint32_t numIndices) { } } } - + unsigned short* indices = _indices.buffer() + _indices.size(); _indices.setSize(_indices.size() + numIndices, 0); return indices; @@ -256,68 +256,68 @@ void SkeletonTwoColorBatch::deallocateIndices(uint32_t numIndices) { TwoColorTrianglesCommand* SkeletonTwoColorBatch::addCommand(cocos2d::Renderer* renderer, float globalOrder, GLuint textureID, cocos2d::GLProgramState* glProgramState, cocos2d::BlendFunc blendType, const TwoColorTriangles& triangles, const cocos2d::Mat4& mv, uint32_t flags) { TwoColorTrianglesCommand* command = nextFreeCommand(); command->init(globalOrder, textureID, glProgramState, blendType, triangles, mv, flags); - renderer->addCommand(command); + renderer->addCommand(command); return command; } - + void SkeletonTwoColorBatch::batch (TwoColorTrianglesCommand* command) { if (_numVerticesBuffer + command->getTriangles().vertCount >= MAX_VERTICES || _numIndicesBuffer + command->getTriangles().indexCount >= MAX_INDICES) { flush(_lastCommand); } - + uint32_t materialID = command->getMaterialID(); if (_lastCommand && _lastCommand->getMaterialID() != materialID) { flush(_lastCommand); } - + memcpy(_vertexBuffer + _numVerticesBuffer, command->getTriangles().verts, sizeof(V3F_C4B_C4B_T2F) * command->getTriangles().vertCount); const Mat4& modelView = command->getModelView(); for (int i = _numVerticesBuffer; i < _numVerticesBuffer + command->getTriangles().vertCount; i++) { modelView.transformPoint(&_vertexBuffer[i].position); } - + unsigned short vertexOffset = (unsigned short)_numVerticesBuffer; unsigned short* indices = command->getTriangles().indices; for (int i = 0, j = _numIndicesBuffer; i < command->getTriangles().indexCount; i++, j++) { _indexBuffer[j] = indices[i] + vertexOffset; } - + _numVerticesBuffer += command->getTriangles().vertCount; _numIndicesBuffer += command->getTriangles().indexCount; - + if (command->isForceFlush()) { flush(command); } _lastCommand = command; } - + void SkeletonTwoColorBatch::flush (TwoColorTrianglesCommand* materialCommand) { if (!materialCommand) return; - + materialCommand->useMaterial(); - + glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferHandle); glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B_C4B_T2F) * _numVerticesBuffer , _vertexBuffer, GL_DYNAMIC_DRAW); - + glEnableVertexAttribArray(_positionAttributeLocation); glEnableVertexAttribArray(_colorAttributeLocation); glEnableVertexAttribArray(_color2AttributeLocation); glEnableVertexAttribArray(_texCoordsAttributeLocation); - + glVertexAttribPointer(_positionAttributeLocation, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_C4B_T2F, position)); glVertexAttribPointer(_colorAttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_C4B_T2F, color)); glVertexAttribPointer(_color2AttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_C4B_T2F, color2)); glVertexAttribPointer(_texCoordsAttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_C4B_T2F, texCoords)); - + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferHandle); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * _numIndicesBuffer, _indexBuffer, GL_STATIC_DRAW); - + glDrawElements(GL_TRIANGLES, (GLsizei)_numIndicesBuffer, GL_UNSIGNED_SHORT, 0); - + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - + _numVerticesBuffer = 0; _numIndicesBuffer = 0; _numBatches++; diff --git a/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.h b/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.h index 3140270a7..8a9782bf5 100644 --- a/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.h +++ b/spine-cocos2dx/src/spine/SkeletonTwoColorBatch.h @@ -41,50 +41,50 @@ namespace spine { cocos2d::Color4B color2; cocos2d::Tex2F texCoords; }; - + struct TwoColorTriangles { V3F_C4B_C4B_T2F* verts; unsigned short* indices; int vertCount; int indexCount; }; - + class TwoColorTrianglesCommand : public cocos2d::CustomCommand { public: TwoColorTrianglesCommand(); - + ~TwoColorTrianglesCommand(); - + void init(float globalOrder, GLuint textureID, cocos2d::GLProgramState* glProgramState, cocos2d::BlendFunc blendType, const TwoColorTriangles& triangles, const cocos2d::Mat4& mv, uint32_t flags); - + void useMaterial() const; - + inline uint32_t getMaterialID() const { return _materialID; } - + inline GLuint getTextureID() const { return _textureID; } - + inline const TwoColorTriangles& getTriangles() const { return _triangles; } - + inline ssize_t getVertexCount() const { return _triangles.vertCount; } - + inline ssize_t getIndexCount() const { return _triangles.indexCount; } - + inline const V3F_C4B_C4B_T2F* getVertices() const { return _triangles.verts; } - + inline const unsigned short* getIndices() const { return _triangles.indices; } - + inline cocos2d::GLProgramState* getGLProgramState() const { return _glProgramState; } - + inline cocos2d::BlendFunc getBlendType() const { return _blendType; } - + inline const cocos2d::Mat4& getModelView() const { return _mv; } - + void draw (); - + void setForceFlush (bool forceFlush) { _forceFlush = forceFlush; } - + bool isForceFlush () { return _forceFlush; }; - + protected: void generateMaterialID(); uint32_t _materialID; @@ -98,33 +98,33 @@ namespace spine { bool _forceFlush; }; - class SkeletonTwoColorBatch { - public: - static SkeletonTwoColorBatch* getInstance (); + class SkeletonTwoColorBatch { + public: + static SkeletonTwoColorBatch* getInstance (); - static void destroyInstance (); + static void destroyInstance (); - void update (float delta); + void update (float delta); V3F_C4B_C4B_T2F* allocateVertices(uint32_t numVertices); void deallocateVertices(uint32_t numVertices); - + unsigned short* allocateIndices(uint32_t numIndices); void deallocateIndices(uint32_t numIndices); TwoColorTrianglesCommand* addCommand(cocos2d::Renderer* renderer, float globalOrder, GLuint textureID, cocos2d::GLProgramState* glProgramState, cocos2d::BlendFunc blendType, const TwoColorTriangles& triangles, const cocos2d::Mat4& mv, uint32_t flags); cocos2d::GLProgramState* getTwoColorTintProgramState () { return _twoColorTintShaderState; } - + void batch (TwoColorTrianglesCommand* command); - + void flush (TwoColorTrianglesCommand* materialCommand); - + uint32_t getNumBatches () { return _numBatches; }; - - protected: - SkeletonTwoColorBatch (); - virtual ~SkeletonTwoColorBatch (); + + protected: + SkeletonTwoColorBatch (); + virtual ~SkeletonTwoColorBatch (); void reset (); @@ -137,14 +137,14 @@ namespace spine { // pool of vertices std::vector _vertices; uint32_t _numVertices; - + // pool of indices Vector _indices; - + // two color tint shader and state cocos2d::GLProgram* _twoColorTintShader; cocos2d::GLProgramState* _twoColorTintShaderState; - + // VBO handles & attribute locations GLuint _vertexBufferHandle; V3F_C4B_C4B_T2F* _vertexBuffer; @@ -156,10 +156,10 @@ namespace spine { GLint _colorAttributeLocation; GLint _color2AttributeLocation; GLint _texCoordsAttributeLocation; - + // last batched command, needed for flushing to set material TwoColorTrianglesCommand* _lastCommand; - + // number of batches in the last frame uint32_t _numBatches; }; diff --git a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp index bcd18de2e..eb8c96c4d 100644 --- a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp +++ b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp @@ -48,7 +48,7 @@ static void setAttachmentVertices(RegionAttachment* attachment) { vertices[i].texCoords.u = attachment->getUVs()[ii]; vertices[i].texCoords.v = attachment->getUVs()[ii + 1]; } - attachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); + attachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); } static void setAttachmentVertices(MeshAttachment* attachment) { @@ -63,7 +63,7 @@ static void setAttachmentVertices(MeshAttachment* attachment) { attachment->setRendererObject(attachmentVertices, deleteAttachmentVertices); } -Cocos2dAtlasAttachmentLoader::Cocos2dAtlasAttachmentLoader(Atlas* atlas): AtlasAttachmentLoader(atlas) { +Cocos2dAtlasAttachmentLoader::Cocos2dAtlasAttachmentLoader(Atlas* atlas): AtlasAttachmentLoader(atlas) { } void Cocos2dAtlasAttachmentLoader::configureAttachment(Attachment* attachment) { @@ -113,7 +113,7 @@ void Cocos2dTextureLoader::load(AtlasPage& page, const spine::String& path) { page.height = texture->getPixelsHigh(); } } - + void Cocos2dTextureLoader::unload(void* texture) { if (texture) { @@ -125,7 +125,7 @@ void Cocos2dTextureLoader::unload(void* texture) { char *Cocos2dExtension::_readFile(const spine::String &path, int *length) { Data data = FileUtils::getInstance()->getDataFromFile(FileUtils::getInstance()->fullPathForFilename(path.buffer())); if (data.isNull()) return nullptr; - + // avoid buffer overflow (int is shorter than ssize_t in certain platforms) #if COCOS2D_VERSION >= 0x00031200 ssize_t tmpLen; diff --git a/spine-cocos2dx/src/spine/spine-cocos2dx.h b/spine-cocos2dx/src/spine/spine-cocos2dx.h index 08f23d0f7..a249973db 100644 --- a/spine-cocos2dx/src/spine/spine-cocos2dx.h +++ b/spine-cocos2dx/src/spine/spine-cocos2dx.h @@ -43,18 +43,18 @@ namespace spine { Cocos2dAtlasAttachmentLoader(Atlas* atlas); virtual void configureAttachment(Attachment* attachment); }; - + class Cocos2dTextureLoader: public TextureLoader { public: - + virtual void load(AtlasPage& page, const String& path); - + virtual void unload(void* texture); }; - + class Cocos2dExtension: public DefaultSpineExtension { public: - + protected: virtual char *_readFile(const String &path, int *length); }; diff --git a/spine-corona/spine-corona/spine.lua b/spine-corona/spine-corona/spine.lua index de0d937f4..c5bf9860d 100644 --- a/spine-corona/spine-corona/spine.lua +++ b/spine-corona/spine-corona/spine.lua @@ -129,7 +129,7 @@ function spine.Skeleton:updateWorldTransform() local premultipliedAlpha = self.premultipliedAlpha self.batches = 0 - + if (self.vertexEffect) then self.vertexEffect:beginEffect(self) end -- Remove old drawing group, we will start anew @@ -154,94 +154,94 @@ function spine.Skeleton:updateWorldTransform() vertices = nil, uvs = nil } - + for _,slot in ipairs(drawOrder) do local attachment = slot.attachment local vertices = nil local uvs = nil local numVertices = 0 local indices = nil - - if slot.bone.active then - - if attachment then - if attachment.type == spine.AttachmentType.region then - numVertices = 4 - vertices = worldVertices - attachment:computeWorldVertices(slot.bone, vertices, 0, 2) - uvs = attachment.uvs - indices = QUAD_TRIANGLES - texture = attachment.region.renderObject.texture - blendMode = toCoronaBlendMode(slot.data.blendMode) - elseif attachment.type == spine.AttachmentType.mesh then - numVertices = attachment.worldVerticesLength / 2 - vertices = worldVertices - attachment:computeWorldVertices(slot, 0, attachment.worldVerticesLength, vertices, 0, 2) - uvs = attachment.uvs - indices = attachment.triangles - texture = attachment.region.renderObject.texture - blendMode = toCoronaBlendMode(slot.data.blendMode) - elseif attachment.type == spine.AttachmentType.clipping then - self.clipper:clipStart(slot, attachment) - end - if texture and vertices and indices then - local skeleton = slot.bone.skeleton - local skeletonColor = skeleton.color - local slotColor = slot.color - local attachmentColor = attachment.color - local alpha = skeletonColor.a * slotColor.a * attachmentColor.a - local multiplier = alpha - if premultipliedAlpha then multiplier = 1 end - color:set(skeletonColor.r * slotColor.r * attachmentColor.r * multiplier, - skeletonColor.g * slotColor.g * attachmentColor.g * multiplier, - skeletonColor.b * slotColor.b * attachmentColor.b * multiplier, - alpha) - - if not lastTexture then lastTexture = texture end - if lastColor.r == -1 then lastColor:setFrom(color) end - if not lastBlendMode then lastBlendMode = blendMode end + if slot.bone.active then - if (texture ~= lastTexture or not colorEquals(color, lastColor) or blendMode ~= lastBlendMode) then - self:flush(groupVertices, groupUvs, groupIndices, lastTexture, lastColor, lastBlendMode, drawingGroup) - lastTexture = texture - lastColor:setFrom(color) - lastBlendMode = blendMode - groupVertices = {} - groupUvs = {} - groupIndices = {} - end - - if self.clipper:isClipping() then - self.clipper:clipTriangles(vertices, uvs, indices, #indices) - vertices = self.clipper.clippedVertices - numVertices = #vertices / 2 - uvs = self.clipper.clippedUVs - indices = self.clipper.clippedTriangles - end + if attachment then + if attachment.type == spine.AttachmentType.region then + numVertices = 4 + vertices = worldVertices + attachment:computeWorldVertices(slot.bone, vertices, 0, 2) + uvs = attachment.uvs + indices = QUAD_TRIANGLES + texture = attachment.region.renderObject.texture + blendMode = toCoronaBlendMode(slot.data.blendMode) + elseif attachment.type == spine.AttachmentType.mesh then + numVertices = attachment.worldVerticesLength / 2 + vertices = worldVertices + attachment:computeWorldVertices(slot, 0, attachment.worldVerticesLength, vertices, 0, 2) + uvs = attachment.uvs + indices = attachment.triangles + texture = attachment.region.renderObject.texture + blendMode = toCoronaBlendMode(slot.data.blendMode) + elseif attachment.type == spine.AttachmentType.clipping then + self.clipper:clipStart(slot, attachment) + end - self:batch(vertices, uvs, numVertices, indices, groupVertices, groupUvs, groupIndices) - end - - self.clipper:clipEnd(slot) - end + if texture and vertices and indices then + local skeleton = slot.bone.skeleton + local skeletonColor = skeleton.color + local slotColor = slot.color + local attachmentColor = attachment.color + local alpha = skeletonColor.a * slotColor.a * attachmentColor.a + local multiplier = alpha + if premultipliedAlpha then multiplier = 1 end + color:set(skeletonColor.r * slotColor.r * attachmentColor.r * multiplier, + skeletonColor.g * slotColor.g * attachmentColor.g * multiplier, + skeletonColor.b * slotColor.b * attachmentColor.b * multiplier, + alpha) + + if not lastTexture then lastTexture = texture end + if lastColor.r == -1 then lastColor:setFrom(color) end + if not lastBlendMode then lastBlendMode = blendMode end + + if (texture ~= lastTexture or not colorEquals(color, lastColor) or blendMode ~= lastBlendMode) then + self:flush(groupVertices, groupUvs, groupIndices, lastTexture, lastColor, lastBlendMode, drawingGroup) + lastTexture = texture + lastColor:setFrom(color) + lastBlendMode = blendMode + groupVertices = {} + groupUvs = {} + groupIndices = {} + end + + if self.clipper:isClipping() then + self.clipper:clipTriangles(vertices, uvs, indices, #indices) + vertices = self.clipper.clippedVertices + numVertices = #vertices / 2 + uvs = self.clipper.clippedUVs + indices = self.clipper.clippedTriangles + end + + self:batch(vertices, uvs, numVertices, indices, groupVertices, groupUvs, groupIndices) + end + + self.clipper:clipEnd(slot) + end end end if #groupVertices > 0 then self:flush(groupVertices, groupUvs, groupIndices, texture, color, blendMode, drawingGroup) end - + self.clipper:clipEnd2() if (self.vertexEffect) then self.vertexEffect:endEffect() end end function spine.Skeleton:flush(groupVertices, groupUvs, groupIndices, texture, color, blendMode, drawingGroup) local mesh = display.newMesh(drawingGroup, 0, 0, { - mode = "indexed", - vertices = groupVertices, - uvs = groupUvs, - indices = groupIndices + mode = "indexed", + vertices = groupVertices, + uvs = groupUvs, + indices = groupIndices }) mesh.fill = texture mesh:setFillColor(color.r, color.g, color.b) diff --git a/spine-cpp/spine-cpp/include/spine/Animation.h b/spine-cpp/spine-cpp/include/spine/Animation.h index 684a324cd..11546b57e 100644 --- a/spine-cpp/spine-cpp/include/spine/Animation.h +++ b/spine-cpp/spine-cpp/include/spine/Animation.h @@ -88,7 +88,7 @@ public: /// Applies all the animation's timelines to the specified skeleton. /// See also Timeline::apply(Skeleton&, float, float, Vector, float, MixPose, MixDirection) void apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction); + MixBlend blend, MixDirection direction); const String &getName(); diff --git a/spine-cpp/spine-cpp/include/spine/AnimationState.h b/spine-cpp/spine-cpp/include/spine/AnimationState.h index 8aa46f31a..e4551f852 100644 --- a/spine-cpp/spine-cpp/include/spine/AnimationState.h +++ b/spine-cpp/spine-cpp/include/spine/AnimationState.h @@ -42,23 +42,23 @@ #endif namespace spine { - enum EventType { - EventType_Start, - EventType_Interrupt, - EventType_End, - EventType_Complete, - EventType_Dispose, - EventType_Event - }; - - class AnimationState; - class TrackEntry; + enum EventType { + EventType_Start, + EventType_Interrupt, + EventType_End, + EventType_Complete, + EventType_Dispose, + EventType_Event + }; - class Animation; - class Event; - class AnimationStateData; - class Skeleton; - class RotateTimeline; + class AnimationState; + class TrackEntry; + + class Animation; + class Event; + class AnimationStateData; + class Skeleton; + class RotateTimeline; #ifdef SPINE_USE_STD_FUNCTION typedef std::function AnimationStateListener; @@ -75,400 +75,363 @@ namespace spine { /// The callback function to be called virtual void callback(AnimationState* state, EventType type, TrackEntry* entry, Event* event) = 0; }; - - /// State for the playback of an animation - class SP_API TrackEntry : public SpineObject, public HasRendererObject { - friend class EventQueue; - friend class AnimationState; - - public: - TrackEntry(); - virtual ~TrackEntry(); - - /// The index of the track where this entry is either current or queued. - int getTrackIndex(); - - /// The animation to apply for this track entry. - Animation* getAnimation(); - - /// - /// If true, the animation will repeat. If false, it will not, instead its last frame is applied if played beyond its duration. - bool getLoop(); - void setLoop(bool inValue); + /// State for the playback of an animation + class SP_API TrackEntry : public SpineObject, public HasRendererObject { + friend class EventQueue; + friend class AnimationState; - /// - /// If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead - /// of being mixed out. - /// - /// When mixing between animations that key the same property, if a lower track also keys that property then the value will - /// briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0% - /// while the second animation mixes from 0% to 100%. Setting holdPrevious to true applies the first animation - /// at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which - /// keys the property, only when a higher track also keys the property. - /// - /// Snapping will occur if holdPrevious is true and this animation does not key all the same properties as the - /// previous animation. - bool getHoldPrevious(); - void setHoldPrevious(bool inValue); - - /// - /// Seconds to postpone playing the animation. When a track entry is the current track entry, delay postpones incrementing - /// the track time. When a track entry is queued, delay is the time from the start of the previous animation to when the - /// track entry will become the current track entry. - float getDelay(); - void setDelay(float inValue); - - /// - /// Current time in seconds this track entry has been the current track entry. The track time determines - /// TrackEntry.AnimationTime. The track time can be set to start the animation at a time other than 0, without affecting looping. - float getTrackTime(); - void setTrackTime(float inValue); - - /// - /// The track time in seconds when this animation will be removed from the track. Defaults to the animation duration for - /// non-looping animations and to int.MaxValue for looping animations. If the track end time is reached and no - /// other animations are queued for playback, and mixing from any previous animations is complete, properties keyed by the animation, - /// are set to the setup pose and the track is cleared. - /// - /// It may be desired to use AnimationState.addEmptyAnimation(int, float, float) to mix the properties back to the - /// setup pose over time, rather than have it happen instantly. - /// - float getTrackEnd(); - void setTrackEnd(float inValue); - - /// - /// Seconds when this animation starts, both initially and after looping. Defaults to 0. - /// - /// When changing the animation start time, it often makes sense to set TrackEntry.AnimationLast to the same value to - /// prevent timeline keys before the start time from triggering. - /// - float getAnimationStart(); - void setAnimationStart(float inValue); - - /// - /// Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will - /// loop back to TrackEntry.AnimationStart at this time. Defaults to the animation duration. - float getAnimationEnd(); - void setAnimationEnd(float inValue); - - /// - /// The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this - /// animation is applied, event timelines will fire all events between the animation last time (exclusive) and animation time - /// (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation is applied. - float getAnimationLast(); - void setAnimationLast(float inValue); - - /// - /// Uses TrackEntry.TrackTime to compute the animation time between TrackEntry.AnimationStart. and - /// TrackEntry.AnimationEnd. When the track time is 0, the animation time is equal to the animation start time. - /// - float getAnimationTime(); - - /// - /// Multiplier for the delta time when the animation state is updated, causing time for this animation to play slower or - /// faster. Defaults to 1. - /// - float getTimeScale(); - void setTimeScale(float inValue); - - /// - /// Values less than 1 mix this animation with the last skeleton pose. Defaults to 1, which overwrites the last skeleton pose with - /// this animation. - /// - /// Typically track 0 is used to completely pose the skeleton, then alpha can be used on higher tracks. It doesn't make sense - /// to use alpha on track 0 if the skeleton pose is from the last frame render. - /// - float getAlpha(); - void setAlpha(float inValue); - - /// - /// When the mix percentage (mix time / mix duration) is less than the event threshold, event timelines for the animation - /// being mixed out will be applied. Defaults to 0, so event timelines are not applied for an animation being mixed out. - float getEventThreshold(); - void setEventThreshold(float inValue); - - /// - /// When the mix percentage (mix time / mix duration) is less than the attachment threshold, attachment timelines for the - /// animation being mixed out will be applied. Defaults to 0, so attachment timelines are not applied for an animation being - /// mixed out. - float getAttachmentThreshold(); - void setAttachmentThreshold(float inValue); - - /// - /// When the mix percentage (mix time / mix duration) is less than the draw order threshold, draw order timelines for the - /// animation being mixed out will be applied. Defaults to 0, so draw order timelines are not applied for an animation being - /// mixed out. - /// - float getDrawOrderThreshold(); - void setDrawOrderThreshold(float inValue); - - /// - /// The animation queued to start after this animation, or NULL. - TrackEntry* getNext(); - - /// - /// Returns true if at least one loop has been completed. - bool isComplete(); - - /// - /// Seconds from 0 to the mix duration when mixing from the previous animation to this animation. May be slightly more than - /// TrackEntry.MixDuration when the mix is complete. - float getMixTime(); - void setMixTime(float inValue); - - /// - /// Seconds for mixing from the previous animation to this animation. Defaults to the value provided by - /// AnimationStateData based on the animation before this animation (if any). - /// - /// The mix duration can be set manually rather than use the value from AnimationStateData.GetMix. - /// In that case, the mixDuration must be set before AnimationState.update(float) is next called. - /// - /// When using AnimationState::addAnimation(int, Animation, bool, float) with a delay - /// less than or equal to 0, note the Delay is set using the mix duration from the AnimationStateData - /// - /// - /// - float getMixDuration(); - void setMixDuration(float inValue); + public: + TrackEntry(); + virtual ~TrackEntry(); - MixBlend getMixBlend(); - void setMixBlend(MixBlend blend); - - /// - /// The track entry for the previous animation when mixing from the previous animation to this animation, or NULL if no - /// mixing is currently occuring. When mixing from multiple animations, MixingFrom makes up a double linked list with MixingTo. - TrackEntry* getMixingFrom(); + /// The index of the track where this entry is either current or queued. + int getTrackIndex(); - /// - /// The track entry for the next animation when mixing from this animation, or NULL if no mixing is currently occuring. - /// When mixing from multiple animations, MixingTo makes up a double linked list with MixingFrom. - TrackEntry* getMixingTo(); - - /// - /// Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the - /// long way around when using alpha and starting animations on other tracks. - /// - /// Mixing involves finding a rotation between two others, which has two possible solutions: the short way or the long way around. - /// The two rotations likely change over time, so which direction is the short or long way also changes. - /// If the short way was always chosen, bones would flip to the other side when that direction became the long way. - /// TrackEntry chooses the short way the first time it is applied and remembers that direction. - void resetRotationDirections(); - - void setListener(AnimationStateListener listener); + /// The animation to apply for this track entry. + Animation* getAnimation(); + + /// If true, the animation will repeat. If false, it will not, instead its last frame is applied if played beyond its duration. + bool getLoop(); + void setLoop(bool inValue); + + /// If true, when mixing from the previous animation to this animation, the previous animation is applied as normal instead + /// of being mixed out. + /// + /// When mixing between animations that key the same property, if a lower track also keys that property then the value will + /// briefly dip toward the lower track value during the mix. This happens because the first animation mixes from 100% to 0% + /// while the second animation mixes from 0% to 100%. Setting holdPrevious to true applies the first animation + /// at 100% during the mix so the lower track value is overwritten. Such dipping does not occur on the lowest track which + /// keys the property, only when a higher track also keys the property. + /// + /// Snapping will occur if holdPrevious is true and this animation does not key all the same properties as the + /// previous animation. + bool getHoldPrevious(); + void setHoldPrevious(bool inValue); + + /// Seconds to postpone playing the animation. When a track entry is the current track entry, delay postpones incrementing + /// the track time. When a track entry is queued, delay is the time from the start of the previous animation to when the + /// track entry will become the current track entry. + float getDelay(); + void setDelay(float inValue); + + /// Current time in seconds this track entry has been the current track entry. The track time determines + /// TrackEntry.AnimationTime. The track time can be set to start the animation at a time other than 0, without affecting looping. + float getTrackTime(); + void setTrackTime(float inValue); + + /// The track time in seconds when this animation will be removed from the track. Defaults to the animation duration for + /// non-looping animations and to int.MaxValue for looping animations. If the track end time is reached and no + /// other animations are queued for playback, and mixing from any previous animations is complete, properties keyed by the animation, + /// are set to the setup pose and the track is cleared. + /// + /// It may be desired to use AnimationState.addEmptyAnimation(int, float, float) to mix the properties back to the + /// setup pose over time, rather than have it happen instantly. + float getTrackEnd(); + void setTrackEnd(float inValue); + + /// Seconds when this animation starts, both initially and after looping. Defaults to 0. + /// + /// When changing the animation start time, it often makes sense to set TrackEntry.AnimationLast to the same value to + /// prevent timeline keys before the start time from triggering. + float getAnimationStart(); + void setAnimationStart(float inValue); + + /// Seconds for the last frame of this animation. Non-looping animations won't play past this time. Looping animations will + /// loop back to TrackEntry.AnimationStart at this time. Defaults to the animation duration. + float getAnimationEnd(); + void setAnimationEnd(float inValue); + + /// The time in seconds this animation was last applied. Some timelines use this for one-time triggers. Eg, when this + /// animation is applied, event timelines will fire all events between the animation last time (exclusive) and animation time + /// (inclusive). Defaults to -1 to ensure triggers on frame 0 happen the first time this animation is applied. + float getAnimationLast(); + void setAnimationLast(float inValue); + + /// Uses TrackEntry.TrackTime to compute the animation time between TrackEntry.AnimationStart. and + /// TrackEntry.AnimationEnd. When the track time is 0, the animation time is equal to the animation start time. + float getAnimationTime(); + + /// Multiplier for the delta time when the animation state is updated, causing time for this animation to play slower or + /// faster. Defaults to 1. + float getTimeScale(); + void setTimeScale(float inValue); + + /// Values less than 1 mix this animation with the last skeleton pose. Defaults to 1, which overwrites the last skeleton pose with + /// this animation. + /// + /// Typically track 0 is used to completely pose the skeleton, then alpha can be used on higher tracks. It doesn't make sense + /// to use alpha on track 0 if the skeleton pose is from the last frame render. + float getAlpha(); + void setAlpha(float inValue); + + /// + /// When the mix percentage (mix time / mix duration) is less than the event threshold, event timelines for the animation + /// being mixed out will be applied. Defaults to 0, so event timelines are not applied for an animation being mixed out. + float getEventThreshold(); + void setEventThreshold(float inValue); + + /// When the mix percentage (mix time / mix duration) is less than the attachment threshold, attachment timelines for the + /// animation being mixed out will be applied. Defaults to 0, so attachment timelines are not applied for an animation being + /// mixed out. + float getAttachmentThreshold(); + void setAttachmentThreshold(float inValue); + + /// When the mix percentage (mix time / mix duration) is less than the draw order threshold, draw order timelines for the + /// animation being mixed out will be applied. Defaults to 0, so draw order timelines are not applied for an animation being + /// mixed out. + float getDrawOrderThreshold(); + void setDrawOrderThreshold(float inValue); + + /// The animation queued to start after this animation, or NULL. + TrackEntry* getNext(); + + /// Returns true if at least one loop has been completed. + bool isComplete(); + + /// Seconds from 0 to the mix duration when mixing from the previous animation to this animation. May be slightly more than + /// TrackEntry.MixDuration when the mix is complete. + float getMixTime(); + void setMixTime(float inValue); + + /// Seconds for mixing from the previous animation to this animation. Defaults to the value provided by + /// AnimationStateData based on the animation before this animation (if any). + /// + /// The mix duration can be set manually rather than use the value from AnimationStateData.GetMix. + /// In that case, the mixDuration must be set before AnimationState.update(float) is next called. + /// + /// When using AnimationState::addAnimation(int, Animation, bool, float) with a delay + /// less than or equal to 0, note the Delay is set using the mix duration from the AnimationStateData + float getMixDuration(); + void setMixDuration(float inValue); + + MixBlend getMixBlend(); + void setMixBlend(MixBlend blend); + + /// The track entry for the previous animation when mixing from the previous animation to this animation, or NULL if no + /// mixing is currently occuring. When mixing from multiple animations, MixingFrom makes up a double linked list with MixingTo. + TrackEntry* getMixingFrom(); + + /// The track entry for the next animation when mixing from this animation, or NULL if no mixing is currently occuring. + /// When mixing from multiple animations, MixingTo makes up a double linked list with MixingFrom. + TrackEntry* getMixingTo(); + + /// Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the + /// long way around when using alpha and starting animations on other tracks. + /// + /// Mixing involves finding a rotation between two others, which has two possible solutions: the short way or the long way around. + /// The two rotations likely change over time, so which direction is the short or long way also changes. + /// If the short way was always chosen, bones would flip to the other side when that direction became the long way. + /// TrackEntry chooses the short way the first time it is applied and remembers that direction. + void resetRotationDirections(); + + void setListener(AnimationStateListener listener); void setListener(AnimationStateListenerObject* listener); - private: - Animation* _animation; - - TrackEntry* _next; - TrackEntry* _mixingFrom; - TrackEntry* _mixingTo; - int _trackIndex; + private: + Animation* _animation; - bool _loop, _holdPrevious; - float _eventThreshold, _attachmentThreshold, _drawOrderThreshold; - float _animationStart, _animationEnd, _animationLast, _nextAnimationLast; - float _delay, _trackTime, _trackLast, _nextTrackLast, _trackEnd, _timeScale; - float _alpha, _mixTime, _mixDuration, _interruptAlpha, _totalAlpha; - MixBlend _mixBlend; - Vector _timelineMode; - Vector _timelineHoldMix; - Vector _timelinesRotation; - AnimationStateListener _listener; + TrackEntry* _next; + TrackEntry* _mixingFrom; + TrackEntry* _mixingTo; + int _trackIndex; + + bool _loop, _holdPrevious; + float _eventThreshold, _attachmentThreshold, _drawOrderThreshold; + float _animationStart, _animationEnd, _animationLast, _nextAnimationLast; + float _delay, _trackTime, _trackLast, _nextTrackLast, _trackEnd, _timeScale; + float _alpha, _mixTime, _mixDuration, _interruptAlpha, _totalAlpha; + MixBlend _mixBlend; + Vector _timelineMode; + Vector _timelineHoldMix; + Vector _timelinesRotation; + AnimationStateListener _listener; AnimationStateListenerObject* _listenerObject; - - void reset(); - }; - - class SP_API EventQueueEntry : public SpineObject { - friend class EventQueue; - - public: - EventType _type; - TrackEntry* _entry; - Event* _event; - - EventQueueEntry(EventType eventType, TrackEntry* trackEntry, Event* event = NULL); - }; - - class SP_API EventQueue : public SpineObject { - friend class AnimationState; - - private: - Vector _eventQueueEntries; - AnimationState& _state; - Pool& _trackEntryPool; - bool _drainDisabled; - - static EventQueue* newEventQueue(AnimationState& state, Pool& trackEntryPool); - static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry* entry, Event* event = NULL); - - EventQueue(AnimationState& state, Pool& trackEntryPool); - - ~EventQueue(); - - void start(TrackEntry* entry); + void reset(); + }; - void interrupt(TrackEntry* entry); + class SP_API EventQueueEntry : public SpineObject { + friend class EventQueue; - void end(TrackEntry* entry); + public: + EventType _type; + TrackEntry* _entry; + Event* _event; - void dispose(TrackEntry* entry); + EventQueueEntry(EventType eventType, TrackEntry* trackEntry, Event* event = NULL); + }; - void complete(TrackEntry* entry); + class SP_API EventQueue : public SpineObject { + friend class AnimationState; - void event(TrackEntry* entry, Event* event); + private: + Vector _eventQueueEntries; + AnimationState& _state; + Pool& _trackEntryPool; + bool _drainDisabled; - /// Raises all events in the queue and drains the queue. - void drain(); - }; - - class SP_API AnimationState : public SpineObject, public HasRendererObject { - friend class TrackEntry; - friend class EventQueue; - - public: - explicit AnimationState(AnimationStateData* data); - - ~AnimationState(); - - /// - /// Increments the track entry times, setting queued animations as current if needed - /// @param delta delta time - void update(float delta); - - /// - /// Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the - /// animation state can be applied to multiple skeletons to pose them identically. - bool apply(Skeleton& skeleton); - - /// - /// Removes all animations from all tracks, leaving skeletons in their previous pose. - /// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose, - /// rather than leaving them in their previous pose. - void clearTracks(); - - /// - /// Removes all animations from the tracks, leaving skeletons in their previous pose. - /// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose, - /// rather than leaving them in their previous pose. - void clearTrack(size_t trackIndex); - - /// Sets an animation by name. setAnimation(int, Animation, bool) - TrackEntry* setAnimation(size_t trackIndex, const String& animationName, bool loop); - - /// Sets the current animation for a track, discarding any queued animations. - /// @param loop If true, the animation will repeat. - /// If false, it will not, instead its last frame is applied if played beyond its duration. - /// In either case TrackEntry.TrackEnd determines when the track is cleared. - /// @return - /// A track entry to allow further customization of animation playback. References to the track entry must not be kept - /// after AnimationState.Dispose. - TrackEntry* setAnimation(size_t trackIndex, Animation* animation, bool loop); - - /// Queues an animation by name. - /// addAnimation(int, Animation, bool, float) - TrackEntry* addAnimation(size_t trackIndex, const String& animationName, bool loop, float delay); - - /// Adds an animation to be played delay seconds after the current or last queued animation - /// for a track. If the track is empty, it is equivalent to calling setAnimation. - /// @param delay - /// Seconds to begin this animation after the start of the previous animation. May be <= 0 to use the animation - /// duration of the previous track minus any mix duration plus the negative delay. - /// - /// @return A track entry to allow further customization of animation playback. References to the track entry must not be kept - /// after AnimationState.Dispose - TrackEntry* addAnimation(size_t trackIndex, Animation* animation, bool loop, float delay); - - /// - /// Sets an empty animation for a track, discarding any queued animations, and mixes to it over the specified mix duration. - TrackEntry* setEmptyAnimation(size_t trackIndex, float mixDuration); - - /// - /// Adds an empty animation to be played after the current or last queued animation for a track, and mixes to it over the - /// specified mix duration. - /// @return - /// A track entry to allow further customization of animation playback. References to the track entry must not be kept after AnimationState.Dispose. - /// - /// @param trackIndex Track number. - /// @param mixDuration Mix duration. - /// @param delay Seconds to begin this animation after the start of the previous animation. May be <= 0 to use the animation - /// duration of the previous track minus any mix duration plus the negative delay. - TrackEntry* addEmptyAnimation(size_t trackIndex, float mixDuration, float delay); - - /// - /// Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix duration. - void setEmptyAnimations(float mixDuration); - - /// @return The track entry for the animation currently playing on the track, or NULL if no animation is currently playing. - TrackEntry* getCurrent(size_t trackIndex); - - AnimationStateData* getData(); - - /// A list of tracks that have animations, which may contain NULLs. - Vector &getTracks(); + static EventQueue* newEventQueue(AnimationState& state, Pool& trackEntryPool); - float getTimeScale(); - void setTimeScale(float inValue); + static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry* entry, Event* event = NULL); - void setListener(AnimationStateListener listener); + EventQueue(AnimationState& state, Pool& trackEntryPool); + + ~EventQueue(); + + void start(TrackEntry* entry); + + void interrupt(TrackEntry* entry); + + void end(TrackEntry* entry); + + void dispose(TrackEntry* entry); + + void complete(TrackEntry* entry); + + void event(TrackEntry* entry, Event* event); + + /// Raises all events in the queue and drains the queue. + void drain(); + }; + + class SP_API AnimationState : public SpineObject, public HasRendererObject { + friend class TrackEntry; + friend class EventQueue; + + public: + explicit AnimationState(AnimationStateData* data); + + ~AnimationState(); + + /// Increments the track entry times, setting queued animations as current if needed + /// @param delta delta time + void update(float delta); + + /// Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the + /// animation state can be applied to multiple skeletons to pose them identically. + bool apply(Skeleton& skeleton); + + /// Removes all animations from all tracks, leaving skeletons in their previous pose. + /// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose, + /// rather than leaving them in their previous pose. + void clearTracks(); + + /// Removes all animations from the tracks, leaving skeletons in their previous pose. + /// It may be desired to use AnimationState.setEmptyAnimations(float) to mix the skeletons back to the setup pose, + /// rather than leaving them in their previous pose. + void clearTrack(size_t trackIndex); + + /// Sets an animation by name. setAnimation(int, Animation, bool) + TrackEntry* setAnimation(size_t trackIndex, const String& animationName, bool loop); + + /// Sets the current animation for a track, discarding any queued animations. + /// @param loop If true, the animation will repeat. + /// If false, it will not, instead its last frame is applied if played beyond its duration. + /// In either case TrackEntry.TrackEnd determines when the track is cleared. + /// @return + /// A track entry to allow further customization of animation playback. References to the track entry must not be kept + /// after AnimationState.Dispose. + TrackEntry* setAnimation(size_t trackIndex, Animation* animation, bool loop); + + /// Queues an animation by name. + /// addAnimation(int, Animation, bool, float) + TrackEntry* addAnimation(size_t trackIndex, const String& animationName, bool loop, float delay); + + /// Adds an animation to be played delay seconds after the current or last queued animation + /// for a track. If the track is empty, it is equivalent to calling setAnimation. + /// @param delay + /// Seconds to begin this animation after the start of the previous animation. May be <= 0 to use the animation + /// duration of the previous track minus any mix duration plus the negative delay. + /// + /// @return A track entry to allow further customization of animation playback. References to the track entry must not be kept + /// after AnimationState.Dispose + TrackEntry* addAnimation(size_t trackIndex, Animation* animation, bool loop, float delay); + + /// Sets an empty animation for a track, discarding any queued animations, and mixes to it over the specified mix duration. + TrackEntry* setEmptyAnimation(size_t trackIndex, float mixDuration); + + /// Adds an empty animation to be played after the current or last queued animation for a track, and mixes to it over the + /// specified mix duration. + /// @return + /// A track entry to allow further customization of animation playback. References to the track entry must not be kept after AnimationState.Dispose. + /// + /// @param trackIndex Track number. + /// @param mixDuration Mix duration. + /// @param delay Seconds to begin this animation after the start of the previous animation. May be <= 0 to use the animation + /// duration of the previous track minus any mix duration plus the negative delay. + TrackEntry* addEmptyAnimation(size_t trackIndex, float mixDuration, float delay); + + /// Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix duration. + void setEmptyAnimations(float mixDuration); + + /// @return The track entry for the animation currently playing on the track, or NULL if no animation is currently playing. + TrackEntry* getCurrent(size_t trackIndex); + + AnimationStateData* getData(); + + /// A list of tracks that have animations, which may contain NULLs. + Vector &getTracks(); + + float getTimeScale(); + void setTimeScale(float inValue); + + void setListener(AnimationStateListener listener); void setListener(AnimationStateListenerObject* listener); void disableQueue(); void enableQueue(); - - private: - - AnimationStateData* _data; - Pool _trackEntryPool; - Vector _tracks; - Vector _events; - EventQueue* _queue; + private: - Vector _propertyIDs; - bool _animationsChanged; + AnimationStateData* _data; - AnimationStateListener _listener; + Pool _trackEntryPool; + Vector _tracks; + Vector _events; + EventQueue* _queue; + + Vector _propertyIDs; + bool _animationsChanged; + + AnimationStateListener _listener; AnimationStateListenerObject* _listenerObject; - - float _timeScale; - static Animation* getEmptyAnimation(); - - static void applyRotateTimeline(RotateTimeline* rotateTimeline, Skeleton& skeleton, float time, float alpha, MixBlend pose, Vector& timelinesRotation, size_t i, bool firstFrame); - - /// Returns true when all mixing from entries are complete. - bool updateMixingFrom(TrackEntry* to, float delta); - - float applyMixingFrom(TrackEntry* to, Skeleton& skeleton, MixBlend currentPose); - - void queueEvents(TrackEntry* entry, float animationTime); - - /// Sets the active TrackEntry for a given track number. - void setCurrent(size_t index, TrackEntry *current, bool interrupt); + float _timeScale; - TrackEntry* expandToIndex(size_t index); + static Animation* getEmptyAnimation(); - /// Object-pooling version of new TrackEntry. Obtain an unused TrackEntry from the pool and clear/initialize its values. - /// @param last May be NULL. - TrackEntry* newTrackEntry(size_t trackIndex, Animation *animation, bool loop, TrackEntry *last); + static void applyRotateTimeline(RotateTimeline* rotateTimeline, Skeleton& skeleton, float time, float alpha, MixBlend pose, Vector& timelinesRotation, size_t i, bool firstFrame); - /// Dispose all track entries queued after the given TrackEntry. - void disposeNext(TrackEntry* entry); + /// Returns true when all mixing from entries are complete. + bool updateMixingFrom(TrackEntry* to, float delta); - void animationsChanged(); + float applyMixingFrom(TrackEntry* to, Skeleton& skeleton, MixBlend currentPose); - void computeHold(TrackEntry *entry); + void queueEvents(TrackEntry* entry, float animationTime); - void computeNotLast(TrackEntry *entry); + /// Sets the active TrackEntry for a given track number. + void setCurrent(size_t index, TrackEntry *current, bool interrupt); - bool hasTimeline(TrackEntry *entry, int inId); - }; + TrackEntry* expandToIndex(size_t index); + + /// Object-pooling version of new TrackEntry. Obtain an unused TrackEntry from the pool and clear/initialize its values. + /// @param last May be NULL. + TrackEntry* newTrackEntry(size_t trackIndex, Animation *animation, bool loop, TrackEntry *last); + + /// Dispose all track entries queued after the given TrackEntry. + void disposeNext(TrackEntry* entry); + + void animationsChanged(); + + void computeHold(TrackEntry *entry); + + void computeNotLast(TrackEntry *entry); + + bool hasTimeline(TrackEntry *entry, int inId); + }; } #endif /* Spine_AnimationState_h */ diff --git a/spine-cpp/spine-cpp/include/spine/AnimationStateData.h b/spine-cpp/spine-cpp/include/spine/AnimationStateData.h index d80a23ea8..38eaa2841 100644 --- a/spine-cpp/spine-cpp/include/spine/AnimationStateData.h +++ b/spine-cpp/spine-cpp/include/spine/AnimationStateData.h @@ -37,51 +37,49 @@ #include namespace spine { - class SkeletonData; - class Animation; - - /// Stores mix (crossfade) durations to be applied when AnimationState animations are changed. - class SP_API AnimationStateData : public SpineObject { - friend class AnimationState; - - public: + class SkeletonData; + class Animation; + + /// Stores mix (crossfade) durations to be applied when AnimationState animations are changed. + class SP_API AnimationStateData : public SpineObject { + friend class AnimationState; + + public: explicit AnimationStateData(SkeletonData* skeletonData); - - /// The SkeletonData to look up animations when they are specified by name. - SkeletonData* getSkeletonData(); - - /// The mix duration to use when no mix duration has been specifically defined between two animations. - float getDefaultMix(); - void setDefaultMix(float inValue); - - /// Sets a mix duration by animation names. - void setMix(const String& fromName, const String& toName, float duration); - - /// Sets a mix duration when changing from the specified animation to the other. - /// See TrackEntry.MixDuration. - void setMix(Animation* from, Animation* to, float duration); - - /// - /// The mix duration to use when changing from the specified animation to the other, - /// or the DefaultMix if no mix duration has been set. - /// - float getMix(Animation* from, Animation* to); - private: - class AnimationPair : public SpineObject { - public: - Animation* _a1; - Animation* _a2; + /// The SkeletonData to look up animations when they are specified by name. + SkeletonData* getSkeletonData(); - explicit AnimationPair(Animation* a1 = NULL, Animation* a2 = NULL); - - bool operator==(const AnimationPair &other) const; - }; - - SkeletonData* _skeletonData; - float _defaultMix; - HashMap _animationToMixTime; - }; + /// The mix duration to use when no mix duration has been specifically defined between two animations. + float getDefaultMix(); + void setDefaultMix(float inValue); + + /// Sets a mix duration by animation names. + void setMix(const String& fromName, const String& toName, float duration); + + /// Sets a mix duration when changing from the specified animation to the other. + /// See TrackEntry.MixDuration. + void setMix(Animation* from, Animation* to, float duration); + + /// The mix duration to use when changing from the specified animation to the other, + /// or the DefaultMix if no mix duration has been set. + float getMix(Animation* from, Animation* to); + + private: + class AnimationPair : public SpineObject { + public: + Animation* _a1; + Animation* _a2; + + explicit AnimationPair(Animation* a1 = NULL, Animation* a2 = NULL); + + bool operator==(const AnimationPair &other) const; + }; + + SkeletonData* _skeletonData; + float _defaultMix; + HashMap _animationToMixTime; + }; } #endif /* Spine_AnimationStateData_h */ diff --git a/spine-cpp/spine-cpp/include/spine/Atlas.h b/spine-cpp/spine-cpp/include/spine/Atlas.h index 9d0a35c95..15b140bc4 100644 --- a/spine-cpp/spine-cpp/include/spine/Atlas.h +++ b/spine-cpp/spine-cpp/include/spine/Atlas.h @@ -76,8 +76,8 @@ public: int width, height; explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888), minFilter(TextureFilter_Nearest), - magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge), - vWrap(TextureWrap_ClampToEdge), width(0), height(0) { + magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge), + vWrap(TextureWrap_ClampToEdge), width(0), height(0) { } }; diff --git a/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h b/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h index ff1c1208f..950803b5a 100644 --- a/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h +++ b/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h @@ -36,38 +36,36 @@ namespace spine { - class Atlas; - class AtlasRegion; - - /// - /// An AttachmentLoader that configures attachments using texture regions from an Atlas. - /// See http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data about Loading Skeleton Data in the Spine Runtimes Guide. - /// + class Atlas; + class AtlasRegion; + + /// An AttachmentLoader that configures attachments using texture regions from an Atlas. + /// See http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data about Loading Skeleton Data in the Spine Runtimes Guide. class SP_API AtlasAttachmentLoader : public AttachmentLoader { - public: + public: RTTI_DECL - - explicit AtlasAttachmentLoader(Atlas* atlas); - - virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path); - - virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path); - - virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name); - - virtual PathAttachment* newPathAttachment(Skin& skin, const String& name); - - virtual PointAttachment* newPointAttachment(Skin& skin, const String& name); - - virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name); + + explicit AtlasAttachmentLoader(Atlas* atlas); + + virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path); + + virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path); + + virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name); + + virtual PathAttachment* newPathAttachment(Skin& skin, const String& name); + + virtual PointAttachment* newPointAttachment(Skin& skin, const String& name); + + virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name); virtual void configureAttachment(Attachment* attachment); - - AtlasRegion* findRegion(const String& name); - - private: - Atlas* _atlas; - }; + + AtlasRegion* findRegion(const String& name); + + private: + Atlas* _atlas; + }; } #endif /* Spine_AtlasAttachmentLoader_h */ diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h b/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h index 6efe0c63a..2c99e338c 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h @@ -35,41 +35,41 @@ #include namespace spine { - class Skin; - class Attachment; - class RegionAttachment; - class MeshAttachment; - class BoundingBoxAttachment; - class PathAttachment; - class PointAttachment; - class ClippingAttachment; - - class SP_API AttachmentLoader : public SpineObject { - public: - RTTI_DECL - - AttachmentLoader(); - - virtual ~AttachmentLoader(); - - /// @return May be NULL to not load any attachment. - virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path) = 0; - - /// @return May be NULL to not load any attachment. - virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path) = 0; - - /// @return May be NULL to not load any attachment. - virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name) = 0; - - /// @return May be NULL to not load any attachment - virtual PathAttachment* newPathAttachment(Skin& skin, const String& name) = 0; - - virtual PointAttachment* newPointAttachment(Skin& skin, const String& name) = 0; - - virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name) = 0; + class Skin; + class Attachment; + class RegionAttachment; + class MeshAttachment; + class BoundingBoxAttachment; + class PathAttachment; + class PointAttachment; + class ClippingAttachment; - virtual void configureAttachment(Attachment* attachment) = 0; - }; + class SP_API AttachmentLoader : public SpineObject { + public: + RTTI_DECL + + AttachmentLoader(); + + virtual ~AttachmentLoader(); + + /// @return May be NULL to not load any attachment. + virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path) = 0; + + /// @return May be NULL to not load any attachment. + virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path) = 0; + + /// @return May be NULL to not load any attachment. + virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name) = 0; + + /// @return May be NULL to not load any attachment + virtual PathAttachment* newPathAttachment(Skin& skin, const String& name) = 0; + + virtual PointAttachment* newPointAttachment(Skin& skin, const String& name) = 0; + + virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name) = 0; + + virtual void configureAttachment(Attachment* attachment) = 0; + }; } #endif /* Spine_AttachmentLoader_h */ diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h b/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h index 4fb110be0..7c315ec26 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h @@ -39,35 +39,35 @@ namespace spine { - class Skeleton; - class Event; - - class SP_API AttachmentTimeline : public Timeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit AttachmentTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, const String& attachmentName); - + class Skeleton; + class Event; + + class SP_API AttachmentTimeline : public Timeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit AttachmentTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, const String& attachmentName); + size_t getSlotIndex(); - void setSlotIndex(size_t inValue); - const Vector& getFrames(); - const Vector& getAttachmentNames(); + void setSlotIndex(size_t inValue); + const Vector& getFrames(); + const Vector& getAttachmentNames(); size_t getFrameCount(); - private: - size_t _slotIndex; - Vector _frames; - Vector _attachmentNames; - }; + private: + size_t _slotIndex; + Vector _frames; + Vector _attachmentNames; + }; } #endif /* Spine_AttachmentTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentType.h b/spine-cpp/spine-cpp/include/spine/AttachmentType.h index 25681e334..4ec4ea2e7 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentType.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentType.h @@ -31,15 +31,15 @@ #define Spine_AttachmentType_h namespace spine { - enum AttachmentType { - AttachmentType_Region, - AttachmentType_Boundingbox, - AttachmentType_Mesh, - AttachmentType_Linkedmesh, - AttachmentType_Path, - AttachmentType_Point, - AttachmentType_Clipping - }; + enum AttachmentType { + AttachmentType_Region, + AttachmentType_Boundingbox, + AttachmentType_Mesh, + AttachmentType_Linkedmesh, + AttachmentType_Path, + AttachmentType_Point, + AttachmentType_Clipping + }; } #endif /* Spine_AttachmentType_h */ diff --git a/spine-cpp/spine-cpp/include/spine/Bone.h b/spine-cpp/spine-cpp/include/spine/Bone.h index 869a49e78..5dedc9242 100644 --- a/spine-cpp/spine-cpp/include/spine/Bone.h +++ b/spine-cpp/spine-cpp/include/spine/Bone.h @@ -98,9 +98,7 @@ public: float localToWorldRotation(float localRotation); - /// /// Rotates the world transform the specified amount and sets isAppliedValid to false. - /// /// @param degrees Degrees. void rotateWorld(float degrees); diff --git a/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h b/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h index 9fd8d3651..a65a99585 100644 --- a/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h @@ -34,14 +34,14 @@ #include namespace spine { - /// Attachment that has a polygon for bounds checking. - class SP_API BoundingBoxAttachment : public VertexAttachment { - RTTI_DECL - - explicit BoundingBoxAttachment(const String& name); + /// Attachment that has a polygon for bounds checking. + class SP_API BoundingBoxAttachment : public VertexAttachment { + RTTI_DECL + + explicit BoundingBoxAttachment(const String& name); virtual Attachment* copy(); - }; + }; } #endif /* Spine_BoundingBoxAttachment_h */ diff --git a/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h b/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h index 712948d36..c7490b228 100644 --- a/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h @@ -33,27 +33,27 @@ #include namespace spine { - class SlotData; - - class SP_API ClippingAttachment : public VertexAttachment { - friend class SkeletonBinary; - friend class SkeletonJson; - - friend class SkeletonClipping; - - RTTI_DECL - - public: - explicit ClippingAttachment(const String& name); - - SlotData* getEndSlot(); - void setEndSlot(SlotData* inValue); + class SlotData; + + class SP_API ClippingAttachment : public VertexAttachment { + friend class SkeletonBinary; + friend class SkeletonJson; + + friend class SkeletonClipping; + + RTTI_DECL + + public: + explicit ClippingAttachment(const String& name); + + SlotData* getEndSlot(); + void setEndSlot(SlotData* inValue); virtual Attachment* copy(); - - private: - SlotData* _endSlot; - }; + + private: + SlotData* _endSlot; + }; } #endif /* Spine_ClippingAttachment_h */ diff --git a/spine-cpp/spine-cpp/include/spine/ColorTimeline.h b/spine-cpp/spine-cpp/include/spine/ColorTimeline.h index e9b580bf6..9feb721d0 100644 --- a/spine-cpp/spine-cpp/include/spine/ColorTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ColorTimeline.h @@ -47,7 +47,7 @@ public: virtual void apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, - MixDirection direction); + MixDirection direction); virtual int getPropertyId(); diff --git a/spine-cpp/spine-cpp/include/spine/ContainerUtil.h b/spine-cpp/spine-cpp/include/spine/ContainerUtil.h index 015e970e2..0b6cde7f1 100644 --- a/spine-cpp/spine-cpp/include/spine/ContainerUtil.h +++ b/spine-cpp/spine-cpp/include/spine/ContainerUtil.h @@ -39,89 +39,89 @@ #include namespace spine { - class SP_API ContainerUtil : public SpineObject { - public: - /// Finds an item by comparing each item's name. - /// It is more efficient to cache the results of this method than to call it multiple times. - /// @return May be NULL. - template - static T* findWithName(Vector& items, const String& name) { - assert(name.length() > 0); - - for (size_t i = 0; i < items.size(); ++i) { - T* item = items[i]; - if (item->getName() == name) { - return item; - } - } - - return NULL; - } - - /// @return -1 if the item was not found. - template - static int findIndexWithName(Vector& items, const String& name) { - assert(name.length() > 0); - - for (size_t i = 0, len = items.size(); i < len; ++i) { - T* item = items[i]; - if (item->getName() == name) { - return static_cast(i); - } - } - - return -1; - } - - /// Finds an item by comparing each item's name. - /// It is more efficient to cache the results of this method than to call it multiple times. - /// @return May be NULL. - template - static T* findWithDataName(Vector& items, const String& name) { - assert(name.length() > 0); - - for (size_t i = 0; i < items.size(); ++i) { - T* item = items[i]; - if (item->getData().getName() == name) { - return item; - } - } - - return NULL; - } - - /// @return -1 if the item was not found. - template - static int findIndexWithDataName(Vector& items, const String& name) { - assert(name.length() > 0); - - for (size_t i = 0, len = items.size(); i < len; ++i) { - T* item = items[i]; - if (item->getData().getName() == name) { - return static_cast(i); - } - } - - return -1; - } - - template - static void cleanUpVectorOfPointers(Vector& items) { - for (int i = (int)items.size() - 1; i >= 0; i--) { - T* item = items[i]; - - delete item; + class SP_API ContainerUtil : public SpineObject { + public: + /// Finds an item by comparing each item's name. + /// It is more efficient to cache the results of this method than to call it multiple times. + /// @return May be NULL. + template + static T* findWithName(Vector& items, const String& name) { + assert(name.length() > 0); - items.removeAt(i); - } - } - - private: - // ctor, copy ctor, and assignment should be private in a Singleton - ContainerUtil(); - ContainerUtil(const ContainerUtil&); - ContainerUtil& operator=(const ContainerUtil&); - }; + for (size_t i = 0; i < items.size(); ++i) { + T* item = items[i]; + if (item->getName() == name) { + return item; + } + } + + return NULL; + } + + /// @return -1 if the item was not found. + template + static int findIndexWithName(Vector& items, const String& name) { + assert(name.length() > 0); + + for (size_t i = 0, len = items.size(); i < len; ++i) { + T* item = items[i]; + if (item->getName() == name) { + return static_cast(i); + } + } + + return -1; + } + + /// Finds an item by comparing each item's name. + /// It is more efficient to cache the results of this method than to call it multiple times. + /// @return May be NULL. + template + static T* findWithDataName(Vector& items, const String& name) { + assert(name.length() > 0); + + for (size_t i = 0; i < items.size(); ++i) { + T* item = items[i]; + if (item->getData().getName() == name) { + return item; + } + } + + return NULL; + } + + /// @return -1 if the item was not found. + template + static int findIndexWithDataName(Vector& items, const String& name) { + assert(name.length() > 0); + + for (size_t i = 0, len = items.size(); i < len; ++i) { + T* item = items[i]; + if (item->getData().getName() == name) { + return static_cast(i); + } + } + + return -1; + } + + template + static void cleanUpVectorOfPointers(Vector& items) { + for (int i = (int)items.size() - 1; i >= 0; i--) { + T* item = items[i]; + + delete item; + + items.removeAt(i); + } + } + + private: + // ctor, copy ctor, and assignment should be private in a Singleton + ContainerUtil(); + ContainerUtil(const ContainerUtil&); + ContainerUtil& operator=(const ContainerUtil&); + }; } #endif /* Spine_ContainerUtil_h */ diff --git a/spine-cpp/spine-cpp/include/spine/CurveTimeline.h b/spine-cpp/spine-cpp/include/spine/CurveTimeline.h index 0e2f32d5e..5ac886942 100644 --- a/spine-cpp/spine-cpp/include/spine/CurveTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/CurveTimeline.h @@ -34,43 +34,43 @@ #include namespace spine { - /// Base class for frames that use an interpolation bezier curve. - class SP_API CurveTimeline : public Timeline { - RTTI_DECL - - public: - explicit CurveTimeline(int frameCount); + /// Base class for frames that use an interpolation bezier curve. + class SP_API CurveTimeline : public Timeline { + RTTI_DECL - virtual ~CurveTimeline(); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction) = 0; - - virtual int getPropertyId() = 0; - - size_t getFrameCount(); - - void setLinear(size_t frameIndex); - - void setStepped(size_t frameIndex); - - /// Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. - /// cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of - /// the difference between the keyframe's values. - void setCurve(size_t frameIndex, float cx1, float cy1, float cx2, float cy2); - - float getCurvePercent(size_t frameIndex, float percent); - - float getCurveType(size_t frameIndex); - - protected: - static const float LINEAR; - static const float STEPPED; - static const float BEZIER; - static const int BEZIER_SIZE; - - private: - Vector _curves; // type, x, y, ... - }; + public: + explicit CurveTimeline(int frameCount); + + virtual ~CurveTimeline(); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction) = 0; + + virtual int getPropertyId() = 0; + + size_t getFrameCount(); + + void setLinear(size_t frameIndex); + + void setStepped(size_t frameIndex); + + /// Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. + /// cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of + /// the difference between the keyframe's values. + void setCurve(size_t frameIndex, float cx1, float cy1, float cx2, float cy2); + + float getCurvePercent(size_t frameIndex, float percent); + + float getCurveType(size_t frameIndex); + + protected: + static const float LINEAR; + static const float STEPPED; + static const float BEZIER; + static const int BEZIER_SIZE; + + private: + Vector _curves; // type, x, y, ... + }; } #endif /* Spine_CurveTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h index 12dd03f66..99305fbb5 100644 --- a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h @@ -33,37 +33,37 @@ #include namespace spine { - class VertexAttachment; - - class SP_API DeformTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit DeformTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, Vector& vertices); - - int getSlotIndex(); - void setSlotIndex(int inValue); - Vector& getFrames(); - Vector< Vector >& getVertices(); - VertexAttachment* getAttachment(); - void setAttachment(VertexAttachment* inValue); - - private: - int _slotIndex; - Vector _frames; - Vector< Vector > _frameVertices; - VertexAttachment* _attachment; - }; + class VertexAttachment; + + class SP_API DeformTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit DeformTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, Vector& vertices); + + int getSlotIndex(); + void setSlotIndex(int inValue); + Vector& getFrames(); + Vector< Vector >& getVertices(); + VertexAttachment* getAttachment(); + void setAttachment(VertexAttachment* inValue); + + private: + int _slotIndex; + Vector _frames; + Vector< Vector > _frameVertices; + VertexAttachment* _attachment; + }; } #endif /* Spine_DeformTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h index 73ff98cb3..ae508456a 100644 --- a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h @@ -33,31 +33,31 @@ #include namespace spine { - class SP_API DrawOrderTimeline : public Timeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit DrawOrderTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - /// @param drawOrder May be NULL to use bind pose draw order - void setFrame(size_t frameIndex, float time, Vector& drawOrder); - - Vector& getFrames(); - Vector< Vector >& getDrawOrders(); - size_t getFrameCount(); - - private: - Vector _frames; - Vector< Vector > _drawOrders; - }; + class SP_API DrawOrderTimeline : public Timeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit DrawOrderTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + /// @param drawOrder May be NULL to use bind pose draw order + void setFrame(size_t frameIndex, float time, Vector& drawOrder); + + Vector& getFrames(); + Vector< Vector >& getDrawOrders(); + size_t getFrameCount(); + + private: + Vector _frames; + Vector< Vector > _drawOrders; + }; } #endif /* Spine_DrawOrderTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/EventTimeline.h b/spine-cpp/spine-cpp/include/spine/EventTimeline.h index acde27f00..1611a4d69 100644 --- a/spine-cpp/spine-cpp/include/spine/EventTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/EventTimeline.h @@ -33,32 +33,32 @@ #include namespace spine { - class SP_API EventTimeline : public Timeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit EventTimeline(int frameCount); - - ~EventTimeline(); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(size_t frameIndex, Event* event); - - Vector getFrames(); - Vector& getEvents(); - size_t getFrameCount(); - - private: - Vector _frames; - Vector _events; - }; + class SP_API EventTimeline : public Timeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit EventTimeline(int frameCount); + + ~EventTimeline(); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(size_t frameIndex, Event* event); + + Vector getFrames(); + Vector& getEvents(); + size_t getFrameCount(); + + private: + Vector _frames; + Vector _events; + }; } #endif /* Spine_EventTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/HashMap.h b/spine-cpp/spine-cpp/include/spine/HashMap.h index bbac45bb0..6ab4f0e1a 100755 --- a/spine-cpp/spine-cpp/include/spine/HashMap.h +++ b/spine-cpp/spine-cpp/include/spine/HashMap.h @@ -34,7 +34,7 @@ #include #include - // Required for new with line number and file name in MSVC + // Required for new with line number and file name in MSVC #ifdef _MSC_VER #pragma warning(disable:4291) #endif diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraintData.h b/spine-cpp/spine-cpp/include/spine/IkConstraintData.h index b11018545..85fa0f05f 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraintData.h @@ -36,54 +36,54 @@ #include namespace spine { - class BoneData; - - class SP_API IkConstraintData : public ConstraintData { - friend class SkeletonBinary; - friend class SkeletonJson; - friend class IkConstraint; - friend class Skeleton; - friend class IkConstraintTimeline; - - public: - explicit IkConstraintData(const String& name); - - /// The bones that are constrained by this IK Constraint. - Vector& getBones(); - - /// The bone that is the IK target. - BoneData* getTarget(); - void setTarget(BoneData* inValue); - - /// Controls the bend direction of the IK bones, either 1 or -1. - int getBendDirection(); - void setBendDirection(int inValue); + class BoneData; - bool getCompress(); - void setCompress(bool inValue); + class SP_API IkConstraintData : public ConstraintData { + friend class SkeletonBinary; + friend class SkeletonJson; + friend class IkConstraint; + friend class Skeleton; + friend class IkConstraintTimeline; - bool getStretch(); - void setStretch(bool inValue); + public: + explicit IkConstraintData(const String& name); - bool getUniform(); - void setUniform(bool inValue); - - float getMix(); - void setMix(float inValue); + /// The bones that are constrained by this IK Constraint. + Vector& getBones(); + + /// The bone that is the IK target. + BoneData* getTarget(); + void setTarget(BoneData* inValue); + + /// Controls the bend direction of the IK bones, either 1 or -1. + int getBendDirection(); + void setBendDirection(int inValue); + + bool getCompress(); + void setCompress(bool inValue); + + bool getStretch(); + void setStretch(bool inValue); + + bool getUniform(); + void setUniform(bool inValue); + + float getMix(); + void setMix(float inValue); float getSoftness(); void setSoftness(float inValue); - private: - Vector _bones; - BoneData* _target; - int _bendDirection; - bool _compress; - bool _stretch; - bool _uniform; - float _mix; - float _softness; - }; + private: + Vector _bones; + BoneData* _target; + int _bendDirection; + bool _compress; + bool _stretch; + bool _uniform; + float _mix; + float _softness; + }; } #endif /* Spine_IkConstraintData_h */ diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h index e07a1b694..68fcd3ded 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h @@ -34,25 +34,25 @@ namespace spine { - class SP_API IkConstraintTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - static const int ENTRIES; - - explicit IkConstraintTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time, mix and bend direction of the specified keyframe. - void setFrame (int frameIndex, float time, float mix, float softness, int bendDirection, bool compress, bool stretch); - - private: + class SP_API IkConstraintTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + static const int ENTRIES; + + explicit IkConstraintTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time, mix and bend direction of the specified keyframe. + void setFrame (int frameIndex, float time, float mix, float softness, int bendDirection, bool compress, bool stretch); + + private: static const int PREV_TIME; static const int PREV_MIX; static const int PREV_SOFTNESS; @@ -65,9 +65,9 @@ namespace spine { static const int COMPRESS; static const int STRETCH; - Vector _frames; - int _ikConstraintIndex; - }; + Vector _frames; + int _ikConstraintIndex; + }; } #endif /* Spine_IkConstraintTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index 1bf05ec0e..dcea08202 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -36,105 +36,105 @@ #include namespace spine { - /// Attachment that displays a texture region using a mesh. - class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject { - friend class SkeletonBinary; - friend class SkeletonJson; - friend class AtlasAttachmentLoader; - - RTTI_DECL - - public: - explicit MeshAttachment(const String& name); + /// Attachment that displays a texture region using a mesh. + class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject { + friend class SkeletonBinary; + friend class SkeletonJson; + friend class AtlasAttachmentLoader; - virtual ~MeshAttachment(); + RTTI_DECL - void updateUVs(); - - int getHullLength(); - void setHullLength(int inValue); - - Vector& getRegionUVs(); - - /// The UV pair for each vertex, normalized within the entire texture. See also MeshAttachment::updateUVs - Vector& getUVs(); - - Vector& getTriangles(); - - Color& getColor(); - - const String& getPath(); - void setPath(const String& inValue); - - float getRegionU(); - void setRegionU(float inValue); - - float getRegionV(); - void setRegionV(float inValue); - - float getRegionU2(); - void setRegionU2(float inValue); - - float getRegionV2(); - void setRegionV2(float inValue); - - bool getRegionRotate(); - void setRegionRotate(bool inValue); - - float getRegionOffsetX(); - void setRegionOffsetX(float inValue); - - // Pixels stripped from the bottom left, unrotated. - float getRegionOffsetY(); - void setRegionOffsetY(float inValue); - - float getRegionWidth(); - void setRegionWidth(float inValue); - - // Unrotated, stripped size. - float getRegionHeight(); - void setRegionHeight(float inValue); - - float getRegionOriginalWidth(); - void setRegionOriginalWidth(float inValue); - - // Unrotated, unstripped size. - float getRegionOriginalHeight(); - void setRegionOriginalHeight(float inValue); - - MeshAttachment* getParentMesh(); - void setParentMesh(MeshAttachment* inValue); - - // Nonessential. - Vector& getEdges(); - float getWidth(); - void setWidth(float inValue); - float getHeight(); - void setHeight(float inValue); + public: + explicit MeshAttachment(const String& name); + + virtual ~MeshAttachment(); + + void updateUVs(); + + int getHullLength(); + void setHullLength(int inValue); + + Vector& getRegionUVs(); + + /// The UV pair for each vertex, normalized within the entire texture. See also MeshAttachment::updateUVs + Vector& getUVs(); + + Vector& getTriangles(); + + Color& getColor(); + + const String& getPath(); + void setPath(const String& inValue); + + float getRegionU(); + void setRegionU(float inValue); + + float getRegionV(); + void setRegionV(float inValue); + + float getRegionU2(); + void setRegionU2(float inValue); + + float getRegionV2(); + void setRegionV2(float inValue); + + bool getRegionRotate(); + void setRegionRotate(bool inValue); + + float getRegionOffsetX(); + void setRegionOffsetX(float inValue); + + // Pixels stripped from the bottom left, unrotated. + float getRegionOffsetY(); + void setRegionOffsetY(float inValue); + + float getRegionWidth(); + void setRegionWidth(float inValue); + + // Unrotated, stripped size. + float getRegionHeight(); + void setRegionHeight(float inValue); + + float getRegionOriginalWidth(); + void setRegionOriginalWidth(float inValue); + + // Unrotated, unstripped size. + float getRegionOriginalHeight(); + void setRegionOriginalHeight(float inValue); + + MeshAttachment* getParentMesh(); + void setParentMesh(MeshAttachment* inValue); + + // Nonessential. + Vector& getEdges(); + float getWidth(); + void setWidth(float inValue); + float getHeight(); + void setHeight(float inValue); virtual Attachment* copy(); MeshAttachment* newLinkedMesh(); - private: - float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; - MeshAttachment* _parentMesh; - Vector _uvs; - Vector _regionUVs; - Vector _triangles; - Vector _edges; - String _path; - float _regionU; - float _regionV; - float _regionU2; - float _regionV2; - float _width; - float _height; - Color _color; - int _hullLength; - bool _regionRotate; - int _regionDegrees; - }; + private: + float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; + MeshAttachment* _parentMesh; + Vector _uvs; + Vector _regionUVs; + Vector _triangles; + Vector _edges; + String _path; + float _regionU; + float _regionV; + float _regionU2; + float _regionV2; + float _width; + float _height; + Color _color; + int _hullLength; + bool _regionRotate; + int _regionDegrees; + }; } #endif /* Spine_MeshAttachment_h */ diff --git a/spine-cpp/spine-cpp/include/spine/MixBlend.h b/spine-cpp/spine-cpp/include/spine/MixBlend.h index fa9879d7b..41c22826b 100644 --- a/spine-cpp/spine-cpp/include/spine/MixBlend.h +++ b/spine-cpp/spine-cpp/include/spine/MixBlend.h @@ -31,7 +31,7 @@ #define Spine_MixPose_h namespace spine { -/// + /// Controls how a timeline is mixed with the setup or current pose. /// See also Timeline::apply(Skeleton&, float, float, Vector&, float, Blend, MixDirection) enum MixBlend { diff --git a/spine-cpp/spine-cpp/include/spine/MixDirection.h b/spine-cpp/spine-cpp/include/spine/MixDirection.h index 8a313a610..0aae33ece 100644 --- a/spine-cpp/spine-cpp/include/spine/MixDirection.h +++ b/spine-cpp/spine-cpp/include/spine/MixDirection.h @@ -31,13 +31,14 @@ #define Spine_MixDirection_h namespace spine { -/// + /// Indicates whether a timeline's alpha is mixing out over time toward 0 (the setup or current pose) or mixing in toward 1 (the timeline's pose). /// See also Timeline::apply(Skeleton&, float, float, Vector&, float, MixPose, MixDirection) enum MixDirection { MixDirection_In = 0, MixDirection_Out }; + } #endif /* Spine_MixDirection_h */ diff --git a/spine-cpp/spine-cpp/include/spine/PathAttachment.h b/spine-cpp/spine-cpp/include/spine/PathAttachment.h index 0bf389a21..4771d09cd 100644 --- a/spine-cpp/spine-cpp/include/spine/PathAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/PathAttachment.h @@ -33,28 +33,28 @@ #include namespace spine { - class SP_API PathAttachment : public VertexAttachment { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit PathAttachment(const String& name); - - /// The length in the setup pose from the start of the path to the end of each curve. - Vector& getLengths(); - bool isClosed(); - void setClosed(bool inValue); - bool isConstantSpeed(); - void setConstantSpeed(bool inValue); + class SP_API PathAttachment : public VertexAttachment { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PathAttachment(const String& name); + + /// The length in the setup pose from the start of the path to the end of each curve. + Vector& getLengths(); + bool isClosed(); + void setClosed(bool inValue); + bool isConstantSpeed(); + void setConstantSpeed(bool inValue); virtual Attachment* copy(); - private: - Vector _lengths; - bool _closed; - bool _constantSpeed; - }; + private: + Vector _lengths; + bool _closed; + bool _constantSpeed; + }; } #endif /* Spine_PathAttachment_h */ diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraint.h b/spine-cpp/spine-cpp/include/spine/PathConstraint.h index a791c5942..6967dec57 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraint.h @@ -35,81 +35,81 @@ #include namespace spine { - class PathConstraintData; - class Skeleton; - class PathAttachment; - class Bone; - class Slot; - - class SP_API PathConstraint : public Updatable { - friend class Skeleton; - friend class PathConstraintMixTimeline; - friend class PathConstraintPositionTimeline; - friend class PathConstraintSpacingTimeline; - - RTTI_DECL - - public: - PathConstraint(PathConstraintData& data, Skeleton& skeleton); - - /// Applies the constraint to the constrained bones. - void apply(); - - virtual void update(); - - virtual int getOrder(); - - float getPosition(); - void setPosition(float inValue); - - float getSpacing(); - void setSpacing(float inValue); - - float getRotateMix(); - void setRotateMix(float inValue); - - float getTranslateMix(); - void setTranslateMix(float inValue); - - Vector& getBones(); - - Slot* getTarget(); - void setTarget(Slot* inValue); - - PathConstraintData& getData(); + class PathConstraintData; + class Skeleton; + class PathAttachment; + class Bone; + class Slot; + + class SP_API PathConstraint : public Updatable { + friend class Skeleton; + friend class PathConstraintMixTimeline; + friend class PathConstraintPositionTimeline; + friend class PathConstraintSpacingTimeline; + + RTTI_DECL + + public: + PathConstraint(PathConstraintData& data, Skeleton& skeleton); + + /// Applies the constraint to the constrained bones. + void apply(); + + virtual void update(); + + virtual int getOrder(); + + float getPosition(); + void setPosition(float inValue); + + float getSpacing(); + void setSpacing(float inValue); + + float getRotateMix(); + void setRotateMix(float inValue); + + float getTranslateMix(); + void setTranslateMix(float inValue); + + Vector& getBones(); + + Slot* getTarget(); + void setTarget(Slot* inValue); + + PathConstraintData& getData(); bool isActive(); void setActive(bool inValue); - - private: - static const float EPSILON; - static const int NONE; - static const int BEFORE; - static const int AFTER; - - PathConstraintData& _data; - Vector _bones; - Slot* _target; - float _position, _spacing, _rotateMix, _translateMix; - - Vector _spaces; - Vector _positions; - Vector _world; - Vector _curves; - Vector _lengths; - Vector _segments; - bool _active; - - Vector& computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing); - - static void addBeforePosition(float p, Vector& temp, int i, Vector& output, int o); - - static void addAfterPosition(float p, Vector& temp, int i, Vector& output, int o); - - static void addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, Vector& output, int o, bool tangents); - }; + private: + static const float EPSILON; + static const int NONE; + static const int BEFORE; + static const int AFTER; + + PathConstraintData& _data; + Vector _bones; + Slot* _target; + float _position, _spacing, _rotateMix, _translateMix; + + Vector _spaces; + Vector _positions; + Vector _world; + Vector _curves; + Vector _lengths; + Vector _segments; + + bool _active; + + Vector& computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing); + + static void addBeforePosition(float p, Vector& temp, int i, Vector& output, int o); + + static void addAfterPosition(float p, Vector& temp, int i, Vector& output, int o); + + static void addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, Vector& output, int o, bool tangents); + }; } #endif /* Spine_PathConstraint_h */ diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintData.h b/spine-cpp/spine-cpp/include/spine/PathConstraintData.h index 0d26c24df..12720f41c 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintData.h @@ -39,60 +39,60 @@ #include namespace spine { - class BoneData; - class SlotData; - - class SP_API PathConstraintData : public ConstraintData { - friend class SkeletonBinary; - friend class SkeletonJson; - - friend class PathConstraint; - friend class Skeleton; - friend class PathConstraintMixTimeline; - friend class PathConstraintPositionTimeline; - friend class PathConstraintSpacingTimeline; - - public: - explicit PathConstraintData(const String& name); - - Vector& getBones(); - - SlotData* getTarget(); - void setTarget(SlotData* inValue); - - PositionMode getPositionMode(); - void setPositionMode(PositionMode inValue); - - SpacingMode getSpacingMode(); - void setSpacingMode(SpacingMode inValue); - - RotateMode getRotateMode(); - void setRotateMode(RotateMode inValue); - - float getOffsetRotation(); - void setOffsetRotation(float inValue); - - float getPosition(); - void setPosition(float inValue); - - float getSpacing(); - void setSpacing(float inValue); - - float getRotateMix(); - void setRotateMix(float inValue); - - float getTranslateMix(); - void setTranslateMix(float inValue); + class BoneData; + class SlotData; - private: - Vector _bones; - SlotData* _target; - PositionMode _positionMode; - SpacingMode _spacingMode; - RotateMode _rotateMode; - float _offsetRotation; - float _position, _spacing, _rotateMix, _translateMix; - }; + class SP_API PathConstraintData : public ConstraintData { + friend class SkeletonBinary; + friend class SkeletonJson; + + friend class PathConstraint; + friend class Skeleton; + friend class PathConstraintMixTimeline; + friend class PathConstraintPositionTimeline; + friend class PathConstraintSpacingTimeline; + + public: + explicit PathConstraintData(const String& name); + + Vector& getBones(); + + SlotData* getTarget(); + void setTarget(SlotData* inValue); + + PositionMode getPositionMode(); + void setPositionMode(PositionMode inValue); + + SpacingMode getSpacingMode(); + void setSpacingMode(SpacingMode inValue); + + RotateMode getRotateMode(); + void setRotateMode(RotateMode inValue); + + float getOffsetRotation(); + void setOffsetRotation(float inValue); + + float getPosition(); + void setPosition(float inValue); + + float getSpacing(); + void setSpacing(float inValue); + + float getRotateMix(); + void setRotateMix(float inValue); + + float getTranslateMix(); + void setTranslateMix(float inValue); + + private: + Vector _bones; + SlotData* _target; + PositionMode _positionMode; + SpacingMode _spacingMode; + RotateMode _rotateMode; + float _offsetRotation; + float _position, _spacing, _rotateMix, _translateMix; + }; } #endif /* Spine_PathConstraintData_h */ diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h index 8c5981f7f..03a6dade1 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h @@ -35,34 +35,34 @@ namespace spine { #define SP_PATHCONSTRAINTMIXTIMELINE_ENTRIES 5 - class SP_API PathConstraintMixTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - static const int ENTRIES; - - explicit PathConstraintMixTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - private: + class SP_API PathConstraintMixTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + static const int ENTRIES; + + explicit PathConstraintMixTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + private: static const int PREV_TIME; static const int PREV_ROTATE; static const int PREV_TRANSLATE; static const int ROTATE; static const int TRANSLATE; - - Vector _frames; - int _pathConstraintIndex; - - /// Sets the time and mixes of the specified keyframe. - void setFrame(int frameIndex, float time, float rotateMix, float translateMix); - }; + + Vector _frames; + int _pathConstraintIndex; + + /// Sets the time and mixes of the specified keyframe. + void setFrame(int frameIndex, float time, float rotateMix, float translateMix); + }; } #endif /* Spine_PathConstraintMixTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h index 4e4131189..e00400e0c 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h @@ -34,34 +34,34 @@ namespace spine { - class SP_API PathConstraintPositionTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - static const int ENTRIES; - - explicit PathConstraintPositionTimeline(int frameCount); + class SP_API PathConstraintPositionTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; - virtual ~PathConstraintPositionTimeline(); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, float value); - - protected: + RTTI_DECL + + public: + static const int ENTRIES; + + explicit PathConstraintPositionTimeline(int frameCount); + + virtual ~PathConstraintPositionTimeline(); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float value); + + protected: static const int PREV_TIME; static const int PREV_VALUE; - static const int VALUE; - - Vector _frames; - int _pathConstraintIndex; - }; + static const int VALUE; + + Vector _frames; + int _pathConstraintIndex; + }; } #endif /* Spine_PathConstraintPositionTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h index eaca67628..1191b2a10 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h @@ -33,19 +33,19 @@ #include namespace spine { - class SP_API PathConstraintSpacingTimeline : public PathConstraintPositionTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit PathConstraintSpacingTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - }; + class SP_API PathConstraintSpacingTimeline : public PathConstraintPositionTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PathConstraintSpacingTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + }; } #endif /* Spine_PathConstraintSpacingTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/PointAttachment.h b/spine-cpp/spine-cpp/include/spine/PointAttachment.h index 92f645f37..4cc06814f 100644 --- a/spine-cpp/spine-cpp/include/spine/PointAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/PointAttachment.h @@ -33,42 +33,41 @@ #include namespace spine { - class Bone; - - /// - /// An attachment which is a single point and a rotation. This can be used to spawn projectiles, particles, etc. A bone can be - /// used in similar ways, but a PointAttachment is slightly less expensive to compute and can be hidden, shown, and placed in a - /// skin. - /// - /// See http://esotericsoftware.com/spine-point-attachments for Point Attachments in the Spine User Guide. - /// - class SP_API PointAttachment : public Attachment { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit PointAttachment(const String& name); - - void computeWorldPosition(Bone& bone, float& ox, float& oy); - - float computeWorldRotation(Bone& bone); - - float getX(); - void setX(float inValue); - - float getY(); - void setY(float inValue); - - float getRotation(); - void setRotation(float inValue); + class Bone; - virtual Attachment* copy(); - - private: - float _x, _y, _rotation; - }; + /// An attachment which is a single point and a rotation. This can be used to spawn projectiles, particles, etc. A bone can be + /// used in similar ways, but a PointAttachment is slightly less expensive to compute and can be hidden, shown, and placed in a + /// skin. + /// + /// See http://esotericsoftware.com/spine-point-attachments for Point Attachments in the Spine User Guide. + /// + class SP_API PointAttachment : public Attachment { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit PointAttachment(const String& name); + + void computeWorldPosition(Bone& bone, float& ox, float& oy); + + float computeWorldRotation(Bone& bone); + + float getX(); + void setX(float inValue); + + float getY(); + void setY(float inValue); + + float getRotation(); + void setRotation(float inValue); + + virtual Attachment* copy(); + + private: + float _x, _y, _rotation; + }; } #endif /* Spine_PointAttachment_h */ diff --git a/spine-cpp/spine-cpp/include/spine/Pool.h b/spine-cpp/spine-cpp/include/spine/Pool.h index 9ab5a7497..2bc5849a3 100644 --- a/spine-cpp/spine-cpp/include/spine/Pool.h +++ b/spine-cpp/spine-cpp/include/spine/Pool.h @@ -54,7 +54,7 @@ public: return ret; } else { - T *ret = new(__FILE__, __LINE__) T(); + T *ret = new(__FILE__, __LINE__) T(); return ret; } diff --git a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h index 4ca28fab7..f90989e2a 100644 --- a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h @@ -40,95 +40,95 @@ #define NUM_UVS 8 namespace spine { - class Bone; - - /// Attachment that displays a texture region. - class SP_API RegionAttachment : public Attachment, public HasRendererObject { - friend class SkeletonBinary; - friend class SkeletonJson; - friend class AtlasAttachmentLoader; - - RTTI_DECL - - public: - explicit RegionAttachment(const String& name); + class Bone; - void updateOffset(); - - void setUVs(float u, float v, float u2, float v2, bool rotate); - - /// Transforms the attachment's four vertices to world coordinates. - /// @param bone The parent bone. - /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8. - /// @param offset The worldVertices index to begin writing values. - /// @param stride The number of worldVertices entries between the value pairs written. + /// Attachment that displays a texture region. + class SP_API RegionAttachment : public Attachment, public HasRendererObject { + friend class SkeletonBinary; + friend class SkeletonJson; + friend class AtlasAttachmentLoader; + + RTTI_DECL + + public: + explicit RegionAttachment(const String& name); + + void updateOffset(); + + void setUVs(float u, float v, float u2, float v2, bool rotate); + + /// Transforms the attachment's four vertices to world coordinates. + /// @param bone The parent bone. + /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8. + /// @param offset The worldVertices index to begin writing values. + /// @param stride The number of worldVertices entries between the value pairs written. void computeWorldVertices(Bone& bone, float *worldVertices, size_t offset, size_t stride = 2); - void computeWorldVertices(Bone& bone, Vector& worldVertices, size_t offset, size_t stride = 2); - - float getX(); - void setX(float inValue); - float getY(); - void setY(float inValue); - float getRotation(); - void setRotation(float inValue); - float getScaleX(); - void setScaleX(float inValue); - float getScaleY(); - void setScaleY(float inValue); - float getWidth(); - void setWidth(float inValue); - float getHeight(); - void setHeight(float inValue); + void computeWorldVertices(Bone& bone, Vector& worldVertices, size_t offset, size_t stride = 2); - Color& getColor(); + float getX(); + void setX(float inValue); + float getY(); + void setY(float inValue); + float getRotation(); + void setRotation(float inValue); + float getScaleX(); + void setScaleX(float inValue); + float getScaleY(); + void setScaleY(float inValue); + float getWidth(); + void setWidth(float inValue); + float getHeight(); + void setHeight(float inValue); - const String& getPath(); - void setPath(const String& inValue); + Color& getColor(); - float getRegionOffsetX(); - void setRegionOffsetX(float inValue); + const String& getPath(); + void setPath(const String& inValue); - float getRegionOffsetY(); - void setRegionOffsetY(float inValue); + float getRegionOffsetX(); + void setRegionOffsetX(float inValue); - float getRegionWidth(); - void setRegionWidth(float inValue); + float getRegionOffsetY(); + void setRegionOffsetY(float inValue); - float getRegionHeight(); - void setRegionHeight(float inValue); + float getRegionWidth(); + void setRegionWidth(float inValue); - float getRegionOriginalWidth(); - void setRegionOriginalWidth(float inValue); + float getRegionHeight(); + void setRegionHeight(float inValue); - float getRegionOriginalHeight(); - void setRegionOriginalHeight(float inValue); - - Vector& getOffset(); - Vector& getUVs(); + float getRegionOriginalWidth(); + void setRegionOriginalWidth(float inValue); - virtual Attachment* copy(); - - private: - static const int BLX; - static const int BLY; - static const int ULX; - static const int ULY; - static const int URX; - static const int URY; - static const int BRX; - static const int BRY; - - float _x, _y, _rotation, _scaleX, _scaleY, _width, _height; - float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; - Vector _vertexOffset; - Vector _uvs; - String _path; - float _regionU; - float _regionV; - float _regionU2; - float _regionV2; - Color _color; - }; + float getRegionOriginalHeight(); + void setRegionOriginalHeight(float inValue); + + Vector& getOffset(); + Vector& getUVs(); + + virtual Attachment* copy(); + + private: + static const int BLX; + static const int BLY; + static const int ULX; + static const int ULY; + static const int URX; + static const int URY; + static const int BRX; + static const int BRY; + + float _x, _y, _rotation, _scaleX, _scaleY, _width, _height; + float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight; + Vector _vertexOffset; + Vector _uvs; + String _path; + float _regionU; + float _regionV; + float _regionU2; + float _regionV2; + Color _color; + }; } #endif /* Spine_RegionAttachment_h */ diff --git a/spine-cpp/spine-cpp/include/spine/RotateTimeline.h b/spine-cpp/spine-cpp/include/spine/RotateTimeline.h index 54a9fe1c3..858e01b6d 100644 --- a/spine-cpp/spine-cpp/include/spine/RotateTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/RotateTimeline.h @@ -33,38 +33,38 @@ #include namespace spine { - class SP_API RotateTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - friend class AnimationState; - - RTTI_DECL - - public: - static const int ENTRIES = 2; + class SP_API RotateTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + friend class AnimationState; - explicit RotateTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, float degrees); - - int getBoneIndex(); - void setBoneIndex(int inValue); - - Vector& getFrames(); - - private: - static const int PREV_TIME = -2; - static const int PREV_ROTATION = -1; - static const int ROTATION = 1; - - int _boneIndex; - Vector _frames; // time, angle, ... - }; + RTTI_DECL + + public: + static const int ENTRIES = 2; + + explicit RotateTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float degrees); + + int getBoneIndex(); + void setBoneIndex(int inValue); + + Vector& getFrames(); + + private: + static const int PREV_TIME = -2; + static const int PREV_ROTATION = -1; + static const int ROTATION = 1; + + int _boneIndex; + Vector _frames; // time, angle, ... + }; } #endif /* Spine_RotateTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h index dab19a7ad..8ce462085 100644 --- a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h @@ -33,19 +33,19 @@ #include namespace spine { - class SP_API ScaleTimeline : public TranslateTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit ScaleTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - }; + class SP_API ScaleTimeline : public TranslateTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ScaleTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + }; } #endif /* Spine_ScaleTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h index cf0562da0..69373d18e 100644 --- a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h @@ -33,19 +33,19 @@ #include namespace spine { - class SP_API ShearTimeline : public TranslateTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - explicit ShearTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - }; + class SP_API ShearTimeline : public TranslateTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; + + RTTI_DECL + + public: + explicit ShearTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + }; } #endif /* Spine_ShearTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/Skeleton.h b/spine-cpp/spine-cpp/include/spine/Skeleton.h index adf2f3335..6bb090722 100644 --- a/spine-cpp/spine-cpp/include/spine/Skeleton.h +++ b/spine-cpp/spine-cpp/include/spine/Skeleton.h @@ -135,7 +135,6 @@ public: /// See Skeleton::setSlotsToSetupPose() /// Also, often AnimationState::apply(Skeleton&) is called before the next time the /// skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin. - /// /// @param newSkin May be NULL. void setSkin(Skin *newSkin); diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h b/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h index 53f92c432..cc827e683 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h @@ -37,95 +37,95 @@ #include namespace spine { - class SkeletonData; - class Atlas; - class AttachmentLoader; - class LinkedMesh; - class Skin; - class Attachment; - class VertexAttachment; - class Animation; - class CurveTimeline; - - class SP_API SkeletonBinary : public SpineObject { - public: - static const int BONE_ROTATE; - static const int BONE_TRANSLATE; - static const int BONE_SCALE; - static const int BONE_SHEAR; - - static const int SLOT_ATTACHMENT; - static const int SLOT_COLOR; - static const int SLOT_TWO_COLOR; - - static const int PATH_POSITION; - static const int PATH_SPACING; - static const int PATH_MIX; - - static const int CURVE_LINEAR; - static const int CURVE_STEPPED; - static const int CURVE_BEZIER; + class SkeletonData; + class Atlas; + class AttachmentLoader; + class LinkedMesh; + class Skin; + class Attachment; + class VertexAttachment; + class Animation; + class CurveTimeline; - explicit SkeletonBinary(Atlas* atlasArray); + class SP_API SkeletonBinary : public SpineObject { + public: + static const int BONE_ROTATE; + static const int BONE_TRANSLATE; + static const int BONE_SCALE; + static const int BONE_SHEAR; - explicit SkeletonBinary(AttachmentLoader* attachmentLoader); - - ~SkeletonBinary(); - - SkeletonData* readSkeletonData(const unsigned char* binary, int length); - - SkeletonData* readSkeletonDataFile(const String& path); + static const int SLOT_ATTACHMENT; + static const int SLOT_COLOR; + static const int SLOT_TWO_COLOR; - void setScale(float scale) { _scale = scale; } + static const int PATH_POSITION; + static const int PATH_SPACING; + static const int PATH_MIX; - String& getError() { return _error; } - - private: - struct DataInput : public SpineObject { - const unsigned char* cursor; - const unsigned char* end; - }; - - AttachmentLoader* _attachmentLoader; - Vector _linkedMeshes; - String _error; - float _scale; - const bool _ownsLoader; - - void setError(const char* value1, const char* value2); - - char* readString(DataInput* input); + static const int CURVE_LINEAR; + static const int CURVE_STEPPED; + static const int CURVE_BEZIER; - char* readStringRef(DataInput* input, SkeletonData* skeletonData); - - float readFloat(DataInput* input); - - unsigned char readByte(DataInput* input); - - signed char readSByte(DataInput* input); - - bool readBoolean(DataInput* input); - - int readInt(DataInput* input); - - void readColor(DataInput* input, Color& color); - - int readVarint(DataInput* input, bool optimizePositive); - - Skin* readSkin(DataInput* input, bool defaultSkin, SkeletonData* skeletonData, bool nonessential); - - Attachment* readAttachment(DataInput* input, Skin* skin, int slotIndex, const String& attachmentName, SkeletonData* skeletonData, bool nonessential); - - void readVertices(DataInput* input, VertexAttachment* attachment, int vertexCount); - - void readFloatArray(DataInput *input, int n, float scale, Vector& array); - - void readShortArray(DataInput *input, Vector& array); - - Animation* readAnimation(const String& name, DataInput* input, SkeletonData *skeletonData); - - void readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline); - }; + explicit SkeletonBinary(Atlas* atlasArray); + + explicit SkeletonBinary(AttachmentLoader* attachmentLoader); + + ~SkeletonBinary(); + + SkeletonData* readSkeletonData(const unsigned char* binary, int length); + + SkeletonData* readSkeletonDataFile(const String& path); + + void setScale(float scale) { _scale = scale; } + + String& getError() { return _error; } + + private: + struct DataInput : public SpineObject { + const unsigned char* cursor; + const unsigned char* end; + }; + + AttachmentLoader* _attachmentLoader; + Vector _linkedMeshes; + String _error; + float _scale; + const bool _ownsLoader; + + void setError(const char* value1, const char* value2); + + char* readString(DataInput* input); + + char* readStringRef(DataInput* input, SkeletonData* skeletonData); + + float readFloat(DataInput* input); + + unsigned char readByte(DataInput* input); + + signed char readSByte(DataInput* input); + + bool readBoolean(DataInput* input); + + int readInt(DataInput* input); + + void readColor(DataInput* input, Color& color); + + int readVarint(DataInput* input, bool optimizePositive); + + Skin* readSkin(DataInput* input, bool defaultSkin, SkeletonData* skeletonData, bool nonessential); + + Attachment* readAttachment(DataInput* input, Skin* skin, int slotIndex, const String& attachmentName, SkeletonData* skeletonData, bool nonessential); + + void readVertices(DataInput* input, VertexAttachment* attachment, int vertexCount); + + void readFloatArray(DataInput *input, int n, float scale, Vector& array); + + void readShortArray(DataInput *input, Vector& array); + + Animation* readAnimation(const String& name, DataInput* input, SkeletonData *skeletonData); + + void readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline); + }; } #endif /* Spine_SkeletonBinary_h */ diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h b/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h index 5b1068304..7dd50b08f 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h @@ -34,74 +34,71 @@ #include namespace spine { - class Skeleton; - class BoundingBoxAttachment; - class Polygon; - - /// - /// Collects each BoundingBoxAttachment that is visible and computes the world vertices for its polygon. - /// The polygon vertices are provided along with convenience methods for doing hit detection. - /// - class SP_API SkeletonBounds : public SpineObject { - public: - SkeletonBounds(); - - /// - /// Clears any previous polygons, finds all visible bounding box attachments, - /// and computes the world vertices for each bounding box's polygon. - /// @param skeleton The skeleton. - /// @param updateAabb - /// If true, the axis aligned bounding box containing all the polygons is computed. - /// If false, the SkeletonBounds AABB methods will always return true. - /// - void update(Skeleton& skeleton, bool updateAabb); - - /// Returns true if the axis aligned bounding box contains the point. - bool aabbcontainsPoint(float x, float y); - - /// Returns true if the axis aligned bounding box intersects the line segment. - bool aabbintersectsSegment(float x1, float y1, float x2, float y2); - - /// Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. - bool aabbIntersectsSkeleton(SkeletonBounds bounds); - - /// Returns true if the polygon contains the point. - bool containsPoint(Polygon* polygon, float x, float y); - - /// Returns the first bounding box attachment that contains the point, or NULL. When doing many checks, it is usually more - /// efficient to only call this method if {@link #aabbcontainsPoint(float, float)} returns true. - BoundingBoxAttachment* containsPoint(float x, float y); - - /// Returns the first bounding box attachment that contains the line segment, or NULL. When doing many checks, it is usually - /// more efficient to only call this method if {@link #aabbintersectsSegment(float, float, float, float)} returns true. - BoundingBoxAttachment* intersectsSegment(float x1, float y1, float x2, float y2); - - /// Returns true if the polygon contains the line segment. - bool intersectsSegment(Polygon* polygon, float x1, float y1, float x2, float y2); - - Polygon* getPolygon(BoundingBoxAttachment* attachment); + class Skeleton; + class BoundingBoxAttachment; + class Polygon; - float getWidth(); - float getHeight(); + /// Collects each BoundingBoxAttachment that is visible and computes the world vertices for its polygon. + /// The polygon vertices are provided along with convenience methods for doing hit detection. + class SP_API SkeletonBounds : public SpineObject { + public: + SkeletonBounds(); - private: - Vector _polygonPool; - Vector _boundingBoxes; - Vector _polygons; - float _minX, _minY, _maxX, _maxY; - - void aabbCompute(); - }; - - class Polygon : public SpineObject { - public: - Vector _vertices; - int _count; - - Polygon() : _count(0) { + /// Clears any previous polygons, finds all visible bounding box attachments, + /// and computes the world vertices for each bounding box's polygon. + /// @param skeleton The skeleton. + /// @param updateAabb + /// If true, the axis aligned bounding box containing all the polygons is computed. + /// If false, the SkeletonBounds AABB methods will always return true. + /// + void update(Skeleton& skeleton, bool updateAabb); + + /// Returns true if the axis aligned bounding box contains the point. + bool aabbcontainsPoint(float x, float y); + + /// Returns true if the axis aligned bounding box intersects the line segment. + bool aabbintersectsSegment(float x1, float y1, float x2, float y2); + + /// Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. + bool aabbIntersectsSkeleton(SkeletonBounds bounds); + + /// Returns true if the polygon contains the point. + bool containsPoint(Polygon* polygon, float x, float y); + + /// Returns the first bounding box attachment that contains the point, or NULL. When doing many checks, it is usually more + /// efficient to only call this method if {@link #aabbcontainsPoint(float, float)} returns true. + BoundingBoxAttachment* containsPoint(float x, float y); + + /// Returns the first bounding box attachment that contains the line segment, or NULL. When doing many checks, it is usually + /// more efficient to only call this method if {@link #aabbintersectsSegment(float, float, float, float)} returns true. + BoundingBoxAttachment* intersectsSegment(float x1, float y1, float x2, float y2); + + /// Returns true if the polygon contains the line segment. + bool intersectsSegment(Polygon* polygon, float x1, float y1, float x2, float y2); + + Polygon* getPolygon(BoundingBoxAttachment* attachment); + + float getWidth(); + float getHeight(); + + private: + Vector _polygonPool; + Vector _boundingBoxes; + Vector _polygons; + float _minX, _minY, _maxX, _maxY; + + void aabbCompute(); + }; + + class Polygon : public SpineObject { + public: + Vector _vertices; + int _count; + + Polygon() : _count(0) { _vertices.ensureCapacity(16); - } - }; + } + }; } #endif /* Spine_SkeletonBounds_h */ diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h b/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h index 3ed6138ee..05f661217 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h @@ -34,46 +34,46 @@ #include namespace spine { - class Slot; - class ClippingAttachment; - - class SP_API SkeletonClipping : public SpineObject { - public: - SkeletonClipping(); + class Slot; + class ClippingAttachment; + + class SP_API SkeletonClipping : public SpineObject { + public: + SkeletonClipping(); + + size_t clipStart(Slot& slot, ClippingAttachment* clip); + + void clipEnd(Slot& slot); + + void clipEnd(); - size_t clipStart(Slot& slot, ClippingAttachment* clip); - - void clipEnd(Slot& slot); - - void clipEnd(); - void clipTriangles(float* vertices, unsigned short* triangles, size_t trianglesLength, float* uvs, size_t stride); - - void clipTriangles(Vector& vertices, Vector& triangles, Vector& uvs, size_t stride); - - bool isClipping(); - - Vector& getClippedVertices(); - Vector& getClippedTriangles(); - Vector& getClippedUVs(); - - private: - Triangulator _triangulator; - Vector _clippingPolygon; - Vector _clipOutput; - Vector _clippedVertices; - Vector _clippedTriangles; - Vector _clippedUVs; - Vector _scratch; - ClippingAttachment* _clipAttachment; - Vector< Vector* > *_clippingPolygons; - - /** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping - * area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */ - bool clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector* clippingArea, Vector* output); - - static void makeClockwise(Vector& polygon); - }; + + void clipTriangles(Vector& vertices, Vector& triangles, Vector& uvs, size_t stride); + + bool isClipping(); + + Vector& getClippedVertices(); + Vector& getClippedTriangles(); + Vector& getClippedUVs(); + + private: + Triangulator _triangulator; + Vector _clippingPolygon; + Vector _clipOutput; + Vector _clippedVertices; + Vector _clippedTriangles; + Vector _clippedUVs; + Vector _scratch; + ClippingAttachment* _clipAttachment; + Vector< Vector* > *_clippingPolygons; + + /** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping + * area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */ + bool clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector* clippingArea, Vector* output); + + static void makeClockwise(Vector& polygon); + }; } #endif /* Spine_SkeletonClipping_h */ diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonData.h b/spine-cpp/spine-cpp/include/spine/SkeletonData.h index b4f626cdd..1947fd273 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonData.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonData.h @@ -112,7 +112,6 @@ public: /// The skeleton's default skin. /// By default this skin contains all attachments that were not in a skin in Spine. - /// /// @return May be NULL. Skin *getDefaultSkin(); diff --git a/spine-cpp/spine-cpp/include/spine/TextureLoader.h b/spine-cpp/spine-cpp/include/spine/TextureLoader.h index 644c2b4bd..5494cde5b 100644 --- a/spine-cpp/spine-cpp/include/spine/TextureLoader.h +++ b/spine-cpp/spine-cpp/include/spine/TextureLoader.h @@ -34,18 +34,18 @@ #include namespace spine { - class AtlasPage; - - class SP_API TextureLoader : public SpineObject { - public: - TextureLoader(); - - virtual ~TextureLoader(); - - virtual void load(AtlasPage& page, const String& path) = 0; - - virtual void unload(void* texture) = 0; - }; + class AtlasPage; + + class SP_API TextureLoader : public SpineObject { + public: + TextureLoader(); + + virtual ~TextureLoader(); + + virtual void load(AtlasPage& page, const String& path) = 0; + + virtual void unload(void* texture) = 0; + }; } #endif /* Spine_TextureLoader_h */ diff --git a/spine-cpp/spine-cpp/include/spine/Timeline.h b/spine-cpp/spine-cpp/include/spine/Timeline.h index 311108c3c..8be7b5ebe 100644 --- a/spine-cpp/spine-cpp/include/spine/Timeline.h +++ b/spine-cpp/spine-cpp/include/spine/Timeline.h @@ -55,14 +55,13 @@ public: /// @param time The time within the animation. Most timelines find the key before and the key after this time so they can interpolate between the keys. /// @param pEvents If any events are fired, they are added to this array. Can be NULL to ignore firing events or if the timeline does not fire events. May be NULL. /// @param alpha alpha 0 applies the current or setup pose value (depending on pose parameter). 1 applies the timeline - /// value. Between 0 and 1 applies a value between the current or setup pose and the timeline value. By adjusting - /// alpha over time, an animation can be mixed in or out. alpha can also be useful to - /// apply animations on top of each other (layered). + /// value. Between 0 and 1 applies a value between the current or setup pose and the timeline value. By adjusting alpha over + /// time, an animation can be mixed in or out. alpha can also be useful to apply animations on top of each other (layered). /// @param blend Controls how mixing is applied when alpha is than 1. /// @param direction Indicates whether the timeline is mixing in or out. Used by timelines which perform instant transitions such as DrawOrderTimeline and AttachmentTimeline. virtual void apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, MixBlend blend, - MixDirection direction) = 0; + MixDirection direction) = 0; virtual int getPropertyId() = 0; }; diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraint.h b/spine-cpp/spine-cpp/include/spine/TransformConstraint.h index cc39c0e83..fdcdbcfbb 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraint.h @@ -35,63 +35,63 @@ #include namespace spine { - class TransformConstraintData; - class Skeleton; - class Bone; - - class SP_API TransformConstraint : public Updatable { - friend class Skeleton; - friend class TransformConstraintTimeline; - - RTTI_DECL - - public: - TransformConstraint(TransformConstraintData& data, Skeleton& skeleton); - - void apply(); - - virtual void update(); - - virtual int getOrder(); - - TransformConstraintData& getData(); - - Vector& getBones(); - - Bone* getTarget(); - void setTarget(Bone* inValue); - - float getRotateMix(); - void setRotateMix(float inValue); - - float getTranslateMix(); - void setTranslateMix(float inValue); - - float getScaleMix(); - void setScaleMix(float inValue); - - float getShearMix(); - void setShearMix(float inValue); + class TransformConstraintData; + class Skeleton; + class Bone; + + class SP_API TransformConstraint : public Updatable { + friend class Skeleton; + friend class TransformConstraintTimeline; + + RTTI_DECL + + public: + TransformConstraint(TransformConstraintData& data, Skeleton& skeleton); + + void apply(); + + virtual void update(); + + virtual int getOrder(); + + TransformConstraintData& getData(); + + Vector& getBones(); + + Bone* getTarget(); + void setTarget(Bone* inValue); + + float getRotateMix(); + void setRotateMix(float inValue); + + float getTranslateMix(); + void setTranslateMix(float inValue); + + float getScaleMix(); + void setScaleMix(float inValue); + + float getShearMix(); + void setShearMix(float inValue); bool isActive(); void setActive(bool inValue); - - private: - TransformConstraintData& _data; - Vector _bones; - Bone* _target; - float _rotateMix, _translateMix, _scaleMix, _shearMix; - bool _active; - - void applyAbsoluteWorld(); - - void applyRelativeWorld(); - - void applyAbsoluteLocal(); - - void applyRelativeLocal(); - }; + + private: + TransformConstraintData& _data; + Vector _bones; + Bone* _target; + float _rotateMix, _translateMix, _scaleMix, _shearMix; + bool _active; + + void applyAbsoluteWorld(); + + void applyRelativeWorld(); + + void applyAbsoluteLocal(); + + void applyRelativeLocal(); + }; } #endif /* Spine_TransformConstraint_h */ diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h b/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h index edded866e..d6f2698bc 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h @@ -36,43 +36,43 @@ #include namespace spine { - class BoneData; - - class SP_API TransformConstraintData : public ConstraintData { - friend class SkeletonBinary; - friend class SkeletonJson; - - friend class TransformConstraint; - friend class Skeleton; - friend class TransformConstraintTimeline; - - public: - explicit TransformConstraintData(const String& name); + class BoneData; - Vector& getBones(); - BoneData* getTarget(); - float getRotateMix(); - float getTranslateMix(); - float getScaleMix(); - float getShearMix(); - - float getOffsetRotation(); - float getOffsetX(); - float getOffsetY(); - float getOffsetScaleX(); - float getOffsetScaleY(); - float getOffsetShearY(); - - bool isRelative(); - bool isLocal(); - - private: - Vector _bones; - BoneData* _target; - float _rotateMix, _translateMix, _scaleMix, _shearMix; - float _offsetRotation, _offsetX, _offsetY, _offsetScaleX, _offsetScaleY, _offsetShearY; - bool _relative, _local; - }; + class SP_API TransformConstraintData : public ConstraintData { + friend class SkeletonBinary; + friend class SkeletonJson; + + friend class TransformConstraint; + friend class Skeleton; + friend class TransformConstraintTimeline; + + public: + explicit TransformConstraintData(const String& name); + + Vector& getBones(); + BoneData* getTarget(); + float getRotateMix(); + float getTranslateMix(); + float getScaleMix(); + float getShearMix(); + + float getOffsetRotation(); + float getOffsetX(); + float getOffsetY(); + float getOffsetScaleX(); + float getOffsetScaleY(); + float getOffsetShearY(); + + bool isRelative(); + bool isLocal(); + + private: + Vector _bones; + BoneData* _target; + float _rotateMix, _translateMix, _scaleMix, _shearMix; + float _offsetRotation, _offsetX, _offsetY, _offsetScaleX, _offsetScaleY, _offsetShearY; + bool _relative, _local; + }; } #endif /* Spine_TransformConstraintData_h */ diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h index 18390f418..df6c2545d 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h @@ -34,24 +34,24 @@ namespace spine { - class SP_API TransformConstraintTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - static const int ENTRIES; + class SP_API TransformConstraintTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; - explicit TransformConstraintTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - void setFrame(size_t frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix); - - private: + RTTI_DECL + + public: + static const int ENTRIES; + + explicit TransformConstraintTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + void setFrame(size_t frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix); + + private: static const int PREV_TIME; static const int PREV_ROTATE; static const int PREV_TRANSLATE; @@ -61,10 +61,10 @@ namespace spine { static const int TRANSLATE; static const int SCALE; static const int SHEAR; - - Vector _frames; - int _transformConstraintIndex; - }; + + Vector _frames; + int _transformConstraintIndex; + }; } #endif /* Spine_TransformConstraintTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/TransformMode.h b/spine-cpp/spine-cpp/include/spine/TransformMode.h index 7990bc878..b0e2cef69 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformMode.h +++ b/spine-cpp/spine-cpp/include/spine/TransformMode.h @@ -31,13 +31,13 @@ #define Spine_TransformMode_h namespace spine { - enum TransformMode { - TransformMode_Normal = 0, - TransformMode_OnlyTranslation, - TransformMode_NoRotationOrReflection, - TransformMode_NoScale, - TransformMode_NoScaleOrReflection - }; + enum TransformMode { + TransformMode_Normal = 0, + TransformMode_OnlyTranslation, + TransformMode_NoRotationOrReflection, + TransformMode_NoScale, + TransformMode_NoScaleOrReflection + }; } #endif /* Spine_TransformMode_h */ diff --git a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h index 8e4d2cdb6..150ffb45a 100644 --- a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h @@ -37,36 +37,36 @@ namespace spine { - class SP_API TranslateTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - static const int ENTRIES; + class SP_API TranslateTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; - explicit TranslateTimeline(int frameCount); + RTTI_DECL - virtual ~TranslateTimeline(); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, float x, float y); - - protected: + public: + static const int ENTRIES; + + explicit TranslateTimeline(int frameCount); + + virtual ~TranslateTimeline(); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float x, float y); + + protected: static const int PREV_TIME; static const int PREV_X; static const int PREV_Y; static const int X; static const int Y; - - Vector _frames; - int _boneIndex; - }; + + Vector _frames; + int _boneIndex; + }; } #endif /* Spine_TranslateTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h index 0b852bd5f..b0e428a04 100644 --- a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h @@ -34,28 +34,28 @@ namespace spine { - class SP_API TwoColorTimeline : public CurveTimeline { - friend class SkeletonBinary; - friend class SkeletonJson; - - RTTI_DECL - - public: - static const int ENTRIES; + class SP_API TwoColorTimeline : public CurveTimeline { + friend class SkeletonBinary; + friend class SkeletonJson; - explicit TwoColorTimeline(int frameCount); - - virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); - - virtual int getPropertyId(); - - /// Sets the time and value of the specified keyframe. - void setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2); - - int getSlotIndex(); - void setSlotIndex(int inValue); - - private: + RTTI_DECL + + public: + static const int ENTRIES; + + explicit TwoColorTimeline(int frameCount); + + virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixBlend blend, MixDirection direction); + + virtual int getPropertyId(); + + /// Sets the time and value of the specified keyframe. + void setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2); + + int getSlotIndex(); + void setSlotIndex(int inValue); + + private: static const int PREV_TIME; static const int PREV_R; static const int PREV_G; @@ -71,10 +71,10 @@ namespace spine { static const int R2; static const int G2; static const int B2; - - Vector _frames; // time, r, g, b, a, r2, g2, b2, ... - int _slotIndex; - }; + + Vector _frames; // time, r, g, b, a, r2, g2, b2, ... + int _slotIndex; + }; } #endif /* Spine_TwoColorTimeline_h */ diff --git a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h index 015ae02e9..94d84f615 100644 --- a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h @@ -35,59 +35,59 @@ #include namespace spine { - class Slot; - - /// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices. - class SP_API VertexAttachment : public Attachment { - friend class SkeletonBinary; - friend class SkeletonJson; - friend class DeformTimeline; - - RTTI_DECL - - public: - explicit VertexAttachment(const String& name); + class Slot; + + /// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices. + class SP_API VertexAttachment : public Attachment { + friend class SkeletonBinary; + friend class SkeletonJson; + friend class DeformTimeline; + + RTTI_DECL + + public: + explicit VertexAttachment(const String& name); + + virtual ~VertexAttachment(); - virtual ~VertexAttachment(); - void computeWorldVertices(Slot& slot, float* worldVertices); - void computeWorldVertices(Slot& slot, Vector& worldVertices); - - /// Transforms local vertices to world coordinates. - /// @param start The index of the first Vertices value to transform. Each vertex has 2 values, x and y. - /// @param count The number of world vertex values to output. Must be less than or equal to WorldVerticesLength - start. - /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + count. - /// @param offset The worldVertices index to begin writing values. - /// @param stride The number of worldVertices entries between the value pairs written. - void computeWorldVertices(Slot& slot, size_t start, size_t count, float* worldVertices, size_t offset, size_t stride = 2); - void computeWorldVertices(Slot& slot, size_t start, size_t count, Vector& worldVertices, size_t offset, size_t stride = 2); - - /// Gets a unique ID for this attachment. - int getId(); - - Vector& getBones(); - - Vector& getVertices(); - - size_t getWorldVerticesLength(); - void setWorldVerticesLength(size_t inValue); + void computeWorldVertices(Slot& slot, Vector& worldVertices); - VertexAttachment* getDeformAttachment(); + /// Transforms local vertices to world coordinates. + /// @param start The index of the first Vertices value to transform. Each vertex has 2 values, x and y. + /// @param count The number of world vertex values to output. Must be less than or equal to WorldVerticesLength - start. + /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + count. + /// @param offset The worldVertices index to begin writing values. + /// @param stride The number of worldVertices entries between the value pairs written. + void computeWorldVertices(Slot& slot, size_t start, size_t count, float* worldVertices, size_t offset, size_t stride = 2); + void computeWorldVertices(Slot& slot, size_t start, size_t count, Vector& worldVertices, size_t offset, size_t stride = 2); + + /// Gets a unique ID for this attachment. + int getId(); + + Vector& getBones(); + + Vector& getVertices(); + + size_t getWorldVerticesLength(); + void setWorldVerticesLength(size_t inValue); + + VertexAttachment* getDeformAttachment(); void setDeformAttachment(VertexAttachment* attachment); void copyTo(VertexAttachment* other); - - protected: - Vector _bones; - Vector _vertices; - size_t _worldVerticesLength; - VertexAttachment* _deformAttachment; - - private: - const int _id; - - static int getNextID(); - }; + + protected: + Vector _bones; + Vector _vertices; + size_t _worldVerticesLength; + VertexAttachment* _deformAttachment; + + private: + const int _id; + + static int getNextID(); + }; } #endif /* Spine_VertexAttachment_h */ diff --git a/spine-cpp/spine-cpp/src/spine/Animation.cpp b/spine-cpp/spine-cpp/src/spine/Animation.cpp index 359dda81e..d94579510 100644 --- a/spine-cpp/spine-cpp/src/spine/Animation.cpp +++ b/spine-cpp/spine-cpp/src/spine/Animation.cpp @@ -52,7 +52,8 @@ Animation::~Animation() { } void Animation::apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { if (loop && _duration != 0) { time = MathUtil::fmod(time, _duration); if (lastTime > 0) { @@ -91,15 +92,12 @@ int Animation::binarySearch(Vector &values, float target, int step) { int current = (int) (static_cast(high) >> 1); while (true) { - if (values[(current + 1) * step] <= target) { + if (values[(current + 1) * step] <= target) low = current + 1; - } else { + else high = current; - } - if (low == high) { - return (low + 1) * step; - } + if (low == high) return (low + 1) * step; current = (int) (static_cast(low + high) >> 1); } @@ -109,21 +107,16 @@ int Animation::binarySearch(Vector &values, float target) { int low = 0; int size = (int)values.size(); int high = size - 2; - if (high == 0) { - return 1; - } + if (high == 0) return 1; int current = (int) (static_cast(high) >> 1); while (true) { - if (values[(current + 1)] <= target) { + if (values[(current + 1)] <= target) low = current + 1; - } else { + else high = current; - } - if (low == high) { - return (low + 1); - } + if (low == high) return (low + 1); current = (int) (static_cast(low + high) >> 1); } diff --git a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp index c787a83dd..7beb1e48d 100644 --- a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp +++ b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp @@ -54,11 +54,11 @@ void dummyOnAnimationEventFunc(AnimationState *state, spine::EventType type, Tra } TrackEntry::TrackEntry() : _animation(NULL), _next(NULL), _mixingFrom(NULL), _mixingTo(0), _trackIndex(0), _loop(false), _holdPrevious(false), - _eventThreshold(0), _attachmentThreshold(0), _drawOrderThreshold(0), _animationStart(0), - _animationEnd(0), _animationLast(0), _nextAnimationLast(0), _delay(0), _trackTime(0), - _trackLast(0), _nextTrackLast(0), _trackEnd(0), _timeScale(1.0f), _alpha(0), _mixTime(0), - _mixDuration(0), _interruptAlpha(0), _totalAlpha(0), _mixBlend(MixBlend_Replace), - _listener(dummyOnAnimationEventFunc), _listenerObject(NULL) { + _eventThreshold(0), _attachmentThreshold(0), _drawOrderThreshold(0), _animationStart(0), + _animationEnd(0), _animationLast(0), _nextAnimationLast(0), _delay(0), _trackTime(0), + _trackLast(0), _nextTrackLast(0), _trackEnd(0), _timeScale(1.0f), _alpha(0), _mixTime(0), + _mixDuration(0), _interruptAlpha(0), _totalAlpha(0), _mixBlend(MixBlend_Replace), + _listener(dummyOnAnimationEventFunc), _listenerObject(NULL) { } TrackEntry::~TrackEntry() { } @@ -105,10 +105,7 @@ void TrackEntry::setAnimationLast(float inValue) { float TrackEntry::getAnimationTime() { if (_loop) { float duration = _animationEnd - _animationStart; - if (duration == 0) { - return _animationStart; - } - + if (duration == 0) return _animationStart; return MathUtil::fmod(_trackTime, duration) + _animationStart; } @@ -202,8 +199,8 @@ EventQueueEntry EventQueue::newEventQueueEntry(EventType eventType, TrackEntry * } EventQueue::EventQueue(AnimationState &state, Pool &trackEntryPool) : _state(state), - _trackEntryPool(trackEntryPool), - _drainDisabled(false) { + _trackEntryPool(trackEntryPool), + _drainDisabled(false) { } EventQueue::~EventQueue() { @@ -251,36 +248,35 @@ void EventQueue::drain() { TrackEntry *trackEntry = queueEntry->_entry; switch (queueEntry->_type) { - case EventType_Start: - case EventType_Interrupt: - case EventType_Complete: - if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL); - else trackEntry->_listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); - if(!state._listenerObject) state._listener(&state, queueEntry->_type, trackEntry, NULL); - else state._listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); - break; - case EventType_End: - if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL); - else trackEntry->_listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); - if (!state._listenerObject) state._listener(&state, queueEntry->_type, trackEntry, NULL); - else state._listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); - /* Yes, we want to fall through here */ - case EventType_Dispose: + case EventType_Start: + case EventType_Interrupt: + case EventType_Complete: + if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL); + else trackEntry->_listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); + if(!state._listenerObject) state._listener(&state, queueEntry->_type, trackEntry, NULL); + else state._listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); + break; + case EventType_End: + if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry->_type, trackEntry, NULL); + else trackEntry->_listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); + if (!state._listenerObject) state._listener(&state, queueEntry->_type, trackEntry, NULL); + else state._listenerObject->callback(&state, queueEntry->_type, trackEntry, NULL); + /* Fall through. */ + case EventType_Dispose: + if (!trackEntry->_listenerObject) trackEntry->_listener(&state, EventType_Dispose, trackEntry, NULL); + else trackEntry->_listenerObject->callback(&state, EventType_Dispose, trackEntry, NULL); + if (!state._listenerObject) state._listener(&state, EventType_Dispose, trackEntry, NULL); + else state._listenerObject->callback(&state, EventType_Dispose, trackEntry, NULL); - if (!trackEntry->_listenerObject) trackEntry->_listener(&state, EventType_Dispose, trackEntry, NULL); - else trackEntry->_listenerObject->callback(&state, EventType_Dispose, trackEntry, NULL); - if (!state._listenerObject) state._listener(&state, EventType_Dispose, trackEntry, NULL); - else state._listenerObject->callback(&state, EventType_Dispose, trackEntry, NULL); - - trackEntry->reset(); - _trackEntryPool.free(trackEntry); - break; - case EventType_Event: - if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry->_type, trackEntry, queueEntry->_event); - else trackEntry->_listenerObject->callback(&state, queueEntry->_type, trackEntry, queueEntry->_event); - if (!state._listenerObject) state._listener(&state, queueEntry->_type, trackEntry, queueEntry->_event); - else state._listenerObject->callback(&state, queueEntry->_type, trackEntry, queueEntry->_event); - break; + trackEntry->reset(); + _trackEntryPool.free(trackEntry); + break; + case EventType_Event: + if (!trackEntry->_listenerObject) trackEntry->_listener(&state, queueEntry->_type, trackEntry, queueEntry->_event); + else trackEntry->_listenerObject->callback(&state, queueEntry->_type, trackEntry, queueEntry->_event); + if (!state._listenerObject) state._listener(&state, queueEntry->_type, trackEntry, queueEntry->_event); + else state._listenerObject->callback(&state, queueEntry->_type, trackEntry, queueEntry->_event); + break; } } _eventQueueEntries.clear(); @@ -420,17 +416,13 @@ bool AnimationState::apply(Skeleton &skeleton) { size_t timelineCount = current._animation->_timelines.size(); Vector &timelines = current._animation->_timelines; if ((i == 0 && mix == 1) || blend == MixBlend_Add) { - for (size_t ii = 0; ii < timelineCount; ++ii) { - timelines[ii]->apply(skeleton, animationLast, animationTime, &_events, mix, blend, - MixDirection_In); - } + for (size_t ii = 0; ii < timelineCount; ++ii) + timelines[ii]->apply(skeleton, animationLast, animationTime, &_events, mix, blend, MixDirection_In); } else { Vector &timelineMode = current._timelineMode; bool firstFrame = current._timelinesRotation.size() == 0; - if (firstFrame) { - current._timelinesRotation.setSize(timelines.size() << 1, 0); - } + if (firstFrame) current._timelinesRotation.setSize(timelines.size() << 1, 0); Vector &timelinesRotation = current._timelinesRotation; for (size_t ii = 0; ii < timelineCount; ++ii) { @@ -440,16 +432,12 @@ bool AnimationState::apply(Skeleton &skeleton) { MixBlend timelineBlend = (timelineMode[ii] & (NotLast - 1)) == Subsequent ? blend : MixBlend_Setup; RotateTimeline *rotateTimeline = NULL; - if (timeline->getRTTI().isExactly(RotateTimeline::rtti)) { - rotateTimeline = static_cast(timeline); - } + if (timeline->getRTTI().isExactly(RotateTimeline::rtti)) rotateTimeline = static_cast(timeline); - if (rotateTimeline != NULL) { - applyRotateTimeline(rotateTimeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, - firstFrame); - } else { + if (rotateTimeline != NULL) + applyRotateTimeline(rotateTimeline, skeleton, animationTime, mix, timelineBlend, timelinesRotation, ii << 1, firstFrame); + else timeline->apply(skeleton, animationLast, animationTime, &_events, mix, timelineBlend, MixDirection_In); - } } } @@ -466,23 +454,18 @@ bool AnimationState::apply(Skeleton &skeleton) { void AnimationState::clearTracks() { bool oldDrainDisabled = _queue->_drainDisabled; _queue->_drainDisabled = true; - for (size_t i = 0, n = _tracks.size(); i < n; ++i) { + for (size_t i = 0, n = _tracks.size(); i < n; ++i) clearTrack(i); - } _tracks.clear(); _queue->_drainDisabled = oldDrainDisabled; _queue->drain(); } void AnimationState::clearTrack(size_t trackIndex) { - if (trackIndex >= _tracks.size()) { - return; - } + if (trackIndex >= _tracks.size()) return; TrackEntry *current = _tracks[trackIndex]; - if (current == NULL) { - return; - } + if (current == NULL) return; _queue->end(current); @@ -491,9 +474,7 @@ void AnimationState::clearTrack(size_t trackIndex) { TrackEntry *entry = current; while (true) { TrackEntry *from = entry->_mixingFrom; - if (from == NULL) { - break; - } + if (from == NULL) break; _queue->end(from); entry->_mixingFrom = NULL; @@ -509,7 +490,6 @@ void AnimationState::clearTrack(size_t trackIndex) { TrackEntry *AnimationState::setAnimation(size_t trackIndex, const String &animationName, bool loop) { Animation *animation = _data->_skeletonData->findAnimation(animationName); assert(animation != NULL); - return setAnimation(trackIndex, animation, loop); } @@ -542,7 +522,6 @@ TrackEntry *AnimationState::setAnimation(size_t trackIndex, Animation *animation TrackEntry *AnimationState::addAnimation(size_t trackIndex, const String &animationName, bool loop, float delay) { Animation *animation = _data->_skeletonData->findAnimation(animationName); assert(animation != NULL); - return addAnimation(trackIndex, animation, loop, delay); } @@ -551,9 +530,8 @@ TrackEntry *AnimationState::addAnimation(size_t trackIndex, Animation *animation TrackEntry *last = expandToIndex(trackIndex); if (last != NULL) { - while (last->_next != NULL) { + while (last->_next != NULL) last = last->_next; - } } TrackEntry *entry = newTrackEntry(trackIndex, animation, loop, last); @@ -657,10 +635,9 @@ Animation *AnimationState::getEmptyAnimation() { } void AnimationState::applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleton &skeleton, float time, float alpha, - MixBlend blend, Vector &timelinesRotation, size_t i, bool firstFrame) { - if (firstFrame) { - timelinesRotation[i] = 0; - } + MixBlend blend, Vector &timelinesRotation, size_t i, bool firstFrame +) { + if (firstFrame) timelinesRotation[i] = 0; if (alpha == 1) { rotateTimeline->apply(skeleton, 0, time, NULL, 1, blend, MixDirection_In); @@ -673,13 +650,13 @@ void AnimationState::applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleto float r1, r2; if (time < frames[0]) { switch (blend) { - case MixBlend_Setup: - bone->_rotation = bone->_data._rotation; - default: - return; - case MixBlend_First: - r1 = bone->_rotation; - r2 = bone->_data._rotation; + case MixBlend_Setup: + bone->_rotation = bone->_data._rotation; + default: + return; + case MixBlend_First: + r1 = bone->_rotation; + r2 = bone->_data._rotation; } } else { r1 = blend == MixBlend_Setup ? bone->_data._rotation : bone->_rotation; @@ -692,9 +669,7 @@ void AnimationState::applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleto float prevRotation = frames[frame + RotateTimeline::PREV_ROTATION]; float frameTime = frames[frame]; float percent = rotateTimeline->getCurvePercent((frame >> 1) - 1, 1 - (time - frameTime) / (frames[frame + - RotateTimeline::PREV_TIME] - - frameTime)); - + RotateTimeline::PREV_TIME] - frameTime)); r2 = frames[frame + RotateTimeline::ROTATION] - prevRotation; r2 -= (16384 - (int) (16384.499999999996 - r2 / 360)) * 360; r2 = prevRotation + r2 * percent + bone->_data._rotation; @@ -721,9 +696,7 @@ void AnimationState::applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleto // Detect cross at 0 (not 180). if (MathUtil::sign(lastDiff) != MathUtil::sign(diff) && MathUtil::abs(lastDiff) <= 90) { // A cross after a 360 rotation is a loop. - if (MathUtil::abs(lastTotal) > 180) { - lastTotal += 360 * MathUtil::sign(lastTotal); - } + if (MathUtil::abs(lastTotal) > 180) lastTotal += 360 * MathUtil::sign(lastTotal); dir = current; } @@ -769,9 +742,7 @@ bool AnimationState::updateMixingFrom(TrackEntry *to, float delta) { float AnimationState::applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBlend blend) { TrackEntry *from = to->_mixingFrom; - if (from->_mixingFrom != NULL) { - applyMixingFrom(from, skeleton, blend); - } + if (from->_mixingFrom != NULL) applyMixingFrom(from, skeleton, blend); float mix; if (to->_mixDuration == 0) { @@ -801,9 +772,7 @@ float AnimationState::applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBle Vector &timelineHoldMix = from->_timelineHoldMix; bool firstFrame = from->_timelinesRotation.size() == 0; - if (firstFrame) { - from->_timelinesRotation.setSize(timelines.size() << 1, 0); - } + if (firstFrame) from->_timelinesRotation.setSize(timelines.size() << 1, 0); Vector &timelinesRotation = from->_timelinesRotation; @@ -839,8 +808,7 @@ float AnimationState::applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBle } from->_totalAlpha += alpha; if ((timeline->getRTTI().isExactly(RotateTimeline::rtti))) { - applyRotateTimeline((RotateTimeline*)timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i << 1, - firstFrame); + applyRotateTimeline((RotateTimeline*)timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i << 1, firstFrame); } else { if (timelineBlend == MixBlend_Setup) { if (timeline->getRTTI().isExactly(AttachmentTimeline::rtti)) { @@ -849,8 +817,7 @@ float AnimationState::applyMixingFrom(TrackEntry *to, Skeleton &skeleton, MixBle if (drawOrder) direction = MixDirection_In; } } - timeline->apply(skeleton, animationLast, animationTime, eventBuffer, alpha, timelineBlend, - direction); + timeline->apply(skeleton, animationLast, animationTime, eventBuffer, alpha, timelineBlend, direction); } } } @@ -875,13 +842,8 @@ void AnimationState::queueEvents(TrackEntry *entry, float animationTime) { size_t i = 0, n = _events.size(); for (; i < n; ++i) { Event *e = _events[i]; - if (e->_time < trackLastWrapped) { - break; - } - if (e->_time > animationEnd) { - // Discard events outside animation start/end. - continue; - } + if (e->_time < trackLastWrapped) break; + if (e->_time > animationEnd) continue; // Discard events outside animation start/end. _queue->event(entry, e); } @@ -896,10 +858,7 @@ void AnimationState::queueEvents(TrackEntry *entry, float animationTime) { // Queue events after complete. for (; i < n; ++i) { Event *e = _events[i]; - if (e->_time < animationStart) { - // Discard events outside animation start/end. - continue; - } + if (e->_time < animationStart) continue; // Discard events outside animation start/end. _queue->event(entry, _events[i]); } } @@ -909,9 +868,7 @@ void AnimationState::setCurrent(size_t index, TrackEntry *current, bool interrup _tracks[index] = current; if (from != NULL) { - if (interrupt) { - _queue->interrupt(from); - } + if (interrupt) _queue->interrupt(from); current->_mixingFrom = from; from->_mixingTo = current; @@ -929,14 +886,9 @@ void AnimationState::setCurrent(size_t index, TrackEntry *current, bool interrup } TrackEntry *AnimationState::expandToIndex(size_t index) { - if (index < _tracks.size()) { - return _tracks[index]; - } - - while (index >= _tracks.size()) { + if (index < _tracks.size()) return _tracks[index]; + while (index >= _tracks.size()) _tracks.add(NULL); - } - return NULL; } @@ -989,7 +941,6 @@ void AnimationState::animationsChanged() { for (size_t i = 0, n = _tracks.size(); i < n; ++i) { TrackEntry *entry = _tracks[i]; - if (!entry) continue; while (entry->_mixingFrom != NULL) @@ -1069,21 +1020,17 @@ void AnimationState::computeNotLast(TrackEntry *entry) { for (size_t i = 0; i < timelinesCount; i++) { if (timelines[i]->getRTTI().isExactly(AttachmentTimeline::rtti)) { AttachmentTimeline *timeline = static_cast(timelines[i]); - if (!_propertyIDs.contains(timeline->getSlotIndex())) { + if (!_propertyIDs.contains(timeline->getSlotIndex())) _propertyIDs.add(timeline->getSlotIndex()); - } else { + else timelineMode[i] |= NotLast; - } } } } bool AnimationState::hasTimeline(TrackEntry* entry, int inId) { Vector &timelines = entry->_animation->_timelines; - for (size_t i = 0, n = timelines.size(); i < n; ++i) { - if (timelines[i]->getPropertyId() == inId) { - return true; - } - } + for (size_t i = 0, n = timelines.size(); i < n; ++i) + if (timelines[i]->getPropertyId() == inId) return true; return false; } diff --git a/spine-cpp/spine-cpp/src/spine/Atlas.cpp b/spine-cpp/spine-cpp/src/spine/Atlas.cpp index 1190670ae..a01012a01 100644 --- a/spine-cpp/spine-cpp/src/spine/Atlas.cpp +++ b/spine-cpp/spine-cpp/src/spine/Atlas.cpp @@ -89,12 +89,8 @@ void Atlas::flipV() { } AtlasRegion *Atlas::findRegion(const String &name) { - for (size_t i = 0, n = _regions.size(); i < n; ++i) { - if (_regions[i]->name == name) { - return _regions[i]; - } - } - + for (size_t i = 0, n = _regions.size(); i < n; ++i) + if (_regions[i]->name == name) return _regions[i]; return NULL; } @@ -103,11 +99,9 @@ Vector &Atlas::getPages() { } void Atlas::load(const char *begin, int length, const char *dir, bool createTexture) { - static const char *formatNames[] = {"", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", - "RGBA8888"}; - static const char *textureFilterNames[] = {"", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", - "MipMapLinearNearest", - "MipMapNearestLinear", "MipMapLinearLinear"}; + static const char *formatNames[] = {"", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", "RGBA8888"}; + static const char *textureFilterNames[] = {"", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", + "MipMapNearestLinear", "MipMapLinearLinear"}; int count; const char *end = begin + length; @@ -125,9 +119,7 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText char *name = mallocString(&str); char *path = SpineExtension::calloc(dirLength + needsSlash + strlen(name) + 1, __FILE__, __LINE__); memcpy(path, dir, dirLength); - if (needsSlash) { - path[dirLength] = '/'; - } + if (needsSlash) path[dirLength] = '/'; strcpy(path + dirLength + needsSlash, name); page = new(__FILE__, __LINE__) AtlasPage(String(name, true)); @@ -163,15 +155,11 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText } } - if (createTexture) - { + if (createTexture) { if (_textureLoader) _textureLoader->load(*page, String(path)); SpineExtension::free(path, __FILE__, __LINE__); - } - else - { + } else page->texturePath = String(path, true); - } _pages.add(page); } else { @@ -181,13 +169,9 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText region->name = String(mallocString(&str), true); readValue(&begin, end, &str); - if (equals(&str, "true")) { - region->degrees = 90; - } else if (equals(&str, "false")) { - region->degrees = 0; - } else { - region->degrees = toInt(&str); - } + if (equals(&str, "true")) region->degrees = 90; + else if (equals(&str, "false")) region->degrees = 0; + else region->degrees = toInt(&str); region->rotate = region->degrees == 90; readTuple(&begin, end, tuple); @@ -251,41 +235,32 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText } void Atlas::trim(Str *str) { - while (isspace((unsigned char) *str->begin) && str->begin < str->end) { + while (isspace((unsigned char) *str->begin) && str->begin < str->end) (str->begin)++; - } - if (str->begin == str->end) { - return; - } + if (str->begin == str->end) return; str->end--; - while (((unsigned char)*str->end == '\r') && str->end >= str->begin) { + while (((unsigned char)*str->end == '\r') && str->end >= str->begin) str->end--; - } str->end++; } int Atlas::readLine(const char **begin, const char *end, Str *str) { - if (*begin == end) { - return 0; - } + if (*begin == end) return 0; str->begin = *begin; /* Find next delimiter. */ - while (*begin != end && **begin != '\n') { + while (*begin != end && **begin != '\n') (*begin)++; - } str->end = *begin; trim(str); - if (*begin != end) { - (*begin)++; - } + if (*begin != end) (*begin)++; return 1; } @@ -294,13 +269,9 @@ int Atlas::beginPast(Str *str, char c) { const char *begin = str->begin; while (true) { char lastSkippedChar = *begin; - if (begin == str->end) { - return 0; - } + if (begin == str->end) return 0; begin++; - if (lastSkippedChar == c) { - break; - } + if (lastSkippedChar == c) break; } str->begin = begin; return 1; @@ -308,10 +279,7 @@ int Atlas::beginPast(Str *str, char c) { int Atlas::readValue(const char **begin, const char *end, Str *str) { readLine(begin, end, str); - if (!beginPast(str, ':')) { - return 0; - } - + if (!beginPast(str, ':')) return 0; trim(str); return 1; } @@ -320,16 +288,11 @@ int Atlas::readTuple(const char **begin, const char *end, Str tuple[]) { int i; Str str = {NULL, NULL}; readLine(begin, end, &str); - if (!beginPast(&str, ':')) { - return 0; - } + if (!beginPast(&str, ':')) return 0; for (i = 0; i < 3; ++i) { tuple[i].begin = str.begin; - if (!beginPast(&str, ',')) { - break; - } - + if (!beginPast(&str, ',')) break; tuple[i].end = str.begin - 2; trim(&tuple[i]); } @@ -352,11 +315,8 @@ char *Atlas::mallocString(Str *str) { int Atlas::indexOf(const char **array, int count, Str *str) { int length = (int) (str->end - str->begin); int i; - for (i = count - 1; i >= 0; i--) { - if (strncmp(array[i], str->begin, length) == 0) { - return i; - } - } + for (i = count - 1; i >= 0; i--) + if (strncmp(array[i], str->begin, length) == 0) return i; return 0; } diff --git a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp index 48dcfc36e..b0ca2d9be 100644 --- a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp @@ -100,7 +100,7 @@ MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const Strin BoundingBoxAttachment *AtlasAttachmentLoader::newBoundingBoxAttachment(Skin &skin, const String &name) { SP_UNUSED(skin); - return new(__FILE__, __LINE__) BoundingBoxAttachment(name); + return new(__FILE__, __LINE__) BoundingBoxAttachment(name); } PathAttachment *AtlasAttachmentLoader::newPathAttachment(Skin &skin, const String &name) { diff --git a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp index 23f27240b..b6e03be72 100644 --- a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp @@ -58,7 +58,8 @@ AttachmentTimeline::AttachmentTimeline(int frameCount) : Timeline(), _slotIndex( } void AttachmentTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(alpha); diff --git a/spine-cpp/spine-cpp/src/spine/Bone.cpp b/spine-cpp/spine-cpp/src/spine/Bone.cpp index a4dfe2f67..d103f718b 100644 --- a/spine-cpp/spine-cpp/src/spine/Bone.cpp +++ b/spine-cpp/spine-cpp/src/spine/Bone.cpp @@ -51,32 +51,33 @@ bool Bone::isYDown() { } Bone::Bone(BoneData &data, Skeleton &skeleton, Bone *parent) : Updatable(), - _data(data), - _skeleton(skeleton), - _parent(parent), - _x(0), - _y(0), - _rotation(0), - _scaleX(0), - _scaleY(0), - _shearX(0), - _shearY(0), - _ax(0), - _ay(0), - _arotation(0), - _ascaleX(0), - _ascaleY(0), - _ashearX(0), - _ashearY(0), - _appliedValid(false), - _a(1), - _b(0), - _worldX(0), - _c(0), - _d(1), - _worldY(0), - _sorted(false), - _active(false) { + _data(data), + _skeleton(skeleton), + _parent(parent), + _x(0), + _y(0), + _rotation(0), + _scaleX(0), + _scaleY(0), + _shearX(0), + _shearY(0), + _ax(0), + _ay(0), + _arotation(0), + _ascaleX(0), + _ascaleY(0), + _ashearX(0), + _ashearY(0), + _appliedValid(false), + _a(1), + _b(0), + _worldX(0), + _c(0), + _d(1), + _worldY(0), + _sorted(false), + _active(false) +{ setToSetupPose(); } @@ -88,8 +89,7 @@ void Bone::updateWorldTransform() { updateWorldTransform(_x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY); } -void -Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) { +void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) { float cosine, sine; float pa, pb, pc, pd; Bone *parent = _parent; @@ -125,80 +125,80 @@ Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float _worldY = pc * x + pd * y + parent->_worldY; switch (_data.getTransformMode()) { - case TransformMode_Normal: { - float rotationY = rotation + 90 + shearY; - float la = MathUtil::cosDeg(rotation + shearX) * scaleX; - float lb = MathUtil::cosDeg(rotationY) * scaleY; - float lc = MathUtil::sinDeg(rotation + shearX) * scaleX; - float ld = MathUtil::sinDeg(rotationY) * scaleY; - _a = pa * la + pb * lc; - _b = pa * lb + pb * ld; - _c = pc * la + pd * lc; - _d = pc * lb + pd * ld; - return; - } - case TransformMode_OnlyTranslation: { - float rotationY = rotation + 90 + shearY; - _a = MathUtil::cosDeg(rotation + shearX) * scaleX; - _b = MathUtil::cosDeg(rotationY) * scaleY; - _c = MathUtil::sinDeg(rotation + shearX) * scaleX; - _d = MathUtil::sinDeg(rotationY) * scaleY; - break; - } - case TransformMode_NoRotationOrReflection: { - float s = pa * pa + pc * pc; - float prx, rx, ry, la, lb, lc, ld; - if (s > 0.0001f) { - s = MathUtil::abs(pa * pd - pb * pc) / s; - pb = pc * s; - pd = pa * s; - prx = MathUtil::atan2(pc, pa) * MathUtil::Rad_Deg; - } else { - pa = 0; - pc = 0; - prx = 90 - MathUtil::atan2(pd, pb) * MathUtil::Rad_Deg; - } - rx = rotation + shearX - prx; - ry = rotation + shearY - prx + 90; - la = MathUtil::cosDeg(rx) * scaleX; - lb = MathUtil::cosDeg(ry) * scaleY; - lc = MathUtil::sinDeg(rx) * scaleX; - ld = MathUtil::sinDeg(ry) * scaleY; - _a = pa * la - pb * lc; - _b = pa * lb - pb * ld; - _c = pc * la + pd * lc; - _d = pc * lb + pd * ld; - break; - } - case TransformMode_NoScale: - case TransformMode_NoScaleOrReflection: { - float za, zc, s; - float r, zb, zd, la, lb, lc, ld; - cosine = MathUtil::cosDeg(rotation); - sine = MathUtil::sinDeg(rotation); - za = (pa * cosine + pb * sine) / _skeleton.getScaleX(); - zc = (pc * cosine + pd * sine) / _skeleton.getScaleY(); - s = MathUtil::sqrt(za * za + zc * zc); - if (s > 0.00001f) s = 1 / s; - za *= s; - zc *= s; - s = MathUtil::sqrt(za * za + zc * zc); - if (_data.getTransformMode() == TransformMode_NoScale - && (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) - s = -s; - r = MathUtil::Pi / 2 + MathUtil::atan2(zc, za); - zb = MathUtil::cos(r) * s; - zd = MathUtil::sin(r) * s; - la = MathUtil::cosDeg(shearX) * scaleX; - lb = MathUtil::cosDeg(90 + shearY) * scaleY; - lc = MathUtil::sinDeg(shearX) * scaleX; - ld = MathUtil::sinDeg(90 + shearY) * scaleY; - _a = za * la + zb * lc; - _b = za * lb + zb * ld; - _c = zc * la + zd * lc; - _d = zc * lb + zd * ld; - break; + case TransformMode_Normal: { + float rotationY = rotation + 90 + shearY; + float la = MathUtil::cosDeg(rotation + shearX) * scaleX; + float lb = MathUtil::cosDeg(rotationY) * scaleY; + float lc = MathUtil::sinDeg(rotation + shearX) * scaleX; + float ld = MathUtil::sinDeg(rotationY) * scaleY; + _a = pa * la + pb * lc; + _b = pa * lb + pb * ld; + _c = pc * la + pd * lc; + _d = pc * lb + pd * ld; + return; + } + case TransformMode_OnlyTranslation: { + float rotationY = rotation + 90 + shearY; + _a = MathUtil::cosDeg(rotation + shearX) * scaleX; + _b = MathUtil::cosDeg(rotationY) * scaleY; + _c = MathUtil::sinDeg(rotation + shearX) * scaleX; + _d = MathUtil::sinDeg(rotationY) * scaleY; + break; + } + case TransformMode_NoRotationOrReflection: { + float s = pa * pa + pc * pc; + float prx, rx, ry, la, lb, lc, ld; + if (s > 0.0001f) { + s = MathUtil::abs(pa * pd - pb * pc) / s; + pb = pc * s; + pd = pa * s; + prx = MathUtil::atan2(pc, pa) * MathUtil::Rad_Deg; + } else { + pa = 0; + pc = 0; + prx = 90 - MathUtil::atan2(pd, pb) * MathUtil::Rad_Deg; } + rx = rotation + shearX - prx; + ry = rotation + shearY - prx + 90; + la = MathUtil::cosDeg(rx) * scaleX; + lb = MathUtil::cosDeg(ry) * scaleY; + lc = MathUtil::sinDeg(rx) * scaleX; + ld = MathUtil::sinDeg(ry) * scaleY; + _a = pa * la - pb * lc; + _b = pa * lb - pb * ld; + _c = pc * la + pd * lc; + _d = pc * lb + pd * ld; + break; + } + case TransformMode_NoScale: + case TransformMode_NoScaleOrReflection: { + float za, zc, s; + float r, zb, zd, la, lb, lc, ld; + cosine = MathUtil::cosDeg(rotation); + sine = MathUtil::sinDeg(rotation); + za = (pa * cosine + pb * sine) / _skeleton.getScaleX(); + zc = (pc * cosine + pd * sine) / _skeleton.getScaleY(); + s = MathUtil::sqrt(za * za + zc * zc); + if (s > 0.00001f) s = 1 / s; + za *= s; + zc *= s; + s = MathUtil::sqrt(za * za + zc * zc); + if (_data.getTransformMode() == TransformMode_NoScale + && (pa * pd - pb * pc < 0) != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) + s = -s; + r = MathUtil::Pi / 2 + MathUtil::atan2(zc, za); + zb = MathUtil::cos(r) * s; + zd = MathUtil::sin(r) * s; + la = MathUtil::cosDeg(shearX) * scaleX; + lb = MathUtil::cosDeg(90 + shearY) * scaleY; + lc = MathUtil::sinDeg(shearX) * scaleX; + ld = MathUtil::sinDeg(90 + shearY) * scaleY; + _a = za * la + zb * lc; + _b = za * lb + zb * ld; + _c = zc * la + zd * lc; + _d = zc * lb + zd * ld; + break; + } } _a *= _skeleton.getScaleX(); _b *= _skeleton.getScaleX(); diff --git a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp index 3ec53251c..950855fb4 100644 --- a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp @@ -62,7 +62,8 @@ ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotI } void ColorTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -72,15 +73,15 @@ void ColorTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector if (!slot._bone.isActive()) return; if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - slot._color.set(slot._data._color); - return; - case MixBlend_First: { - Color &color = slot._color, setup = slot._data._color; - color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, - (setup.a - color.a) * alpha); - } - default: ; + case MixBlend_Setup: + slot._color.set(slot._data._color); + return; + case MixBlend_First: { + Color &color = slot._color, setup = slot._data._color; + color.add((setup.r - color.r) * alpha, (setup.g - color.g) * alpha, (setup.b - color.b) * alpha, + (setup.a - color.a) * alpha); + } + default: ; } return; } @@ -101,8 +102,7 @@ void ColorTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector b = _frames[frame + PREV_B]; a = _frames[frame + PREV_A]; float frameTime = _frames[frame]; - float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + float percent = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); r += (_frames[frame + R] - r) * percent; g += (_frames[frame + G] - g) * percent; diff --git a/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp b/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp index 57f45f0ac..c10f247f4 100644 --- a/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp @@ -113,7 +113,6 @@ float CurveTimeline::getCurvePercent(size_t frameIndex, float percent) { prevX = _curves[i - 2]; prevY = _curves[i - 1]; } - return prevY + (_curves[i + 1] - prevY) * (percent - prevX) / (x - prevX); } } diff --git a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp index 73ebb48e5..a45ae45fe 100644 --- a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp @@ -61,7 +61,8 @@ DeformTimeline::DeformTimeline(int frameCount) : CurveTimeline(frameCount), _slo } void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -143,40 +144,40 @@ void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto } } else { switch (blend) { - case MixBlend_Setup: { - VertexAttachment *vertexAttachment = static_cast(slotAttachment); - if (vertexAttachment->getBones().size() == 0) { - // Unweighted vertex positions, with alpha. - Vector &setupVertices = vertexAttachment->getVertices(); - for (size_t i = 0; i < vertexCount; i++) { - float setup = setupVertices[i]; - deform[i] = setup + (lastVertices[i] - setup) * alpha; - } - } else { - // Weighted deform offsets, with alpha. - for (size_t i = 0; i < vertexCount; i++) - deform[i] = lastVertices[i] * alpha; + case MixBlend_Setup: { + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, with alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) { + float setup = setupVertices[i]; + deform[i] = setup + (lastVertices[i] - setup) * alpha; } - break; - } - case MixBlend_First: - case MixBlend_Replace: - // Vertex positions or deform offsets, with alpha. + } else { + // Weighted deform offsets, with alpha. for (size_t i = 0; i < vertexCount; i++) - deform[i] += (lastVertices[i] - deform[i]) * alpha; - break; - case MixBlend_Add: - VertexAttachment *vertexAttachment = static_cast(slotAttachment); - if (vertexAttachment->getBones().size() == 0) { - // Unweighted vertex positions, no alpha. - Vector &setupVertices = vertexAttachment->getVertices(); - for (size_t i = 0; i < vertexCount; i++) - deform[i] += (lastVertices[i] - setupVertices[i]) * alpha; - } else { - // Weighted deform offsets, alpha. - for (size_t i = 0; i < vertexCount; i++) - deform[i] += lastVertices[i] * alpha; - } + deform[i] = lastVertices[i] * alpha; + } + break; + } + case MixBlend_First: + case MixBlend_Replace: + // Vertex positions or deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) + deform[i] += (lastVertices[i] - deform[i]) * alpha; + break; + case MixBlend_Add: + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, no alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) + deform[i] += (lastVertices[i] - setupVertices[i]) * alpha; + } else { + // Weighted deform offsets, alpha. + for (size_t i = 0; i < vertexCount; i++) + deform[i] += lastVertices[i] * alpha; + } } } return; @@ -184,8 +185,8 @@ void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(frames, time); - Vector &prevVertices = frameVertices[frame - 1]; - Vector &nextVertices = frameVertices[frame]; + Vector &prevVertices = frameVertices[frame - 1]; + Vector &nextVertices = frameVertices[frame]; float frameTime = frames[frame]; float percent = getCurvePercent(frame - 1, 1 - (time - frameTime) / (frames[frame - 1] - frameTime)); @@ -215,55 +216,54 @@ void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto } } else { switch (blend) { - case MixBlend_Setup: { - VertexAttachment *vertexAttachment = static_cast(slotAttachment); - if (vertexAttachment->getBones().size() == 0) { - // Unweighted vertex positions, with alpha. - Vector &setupVertices = vertexAttachment->getVertices(); - for (size_t i = 0; i < vertexCount; i++) { - float prev = prevVertices[i], setup = setupVertices[i]; - deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; - } - } else { - // Weighted deform offsets, with alpha. - for (size_t i = 0; i < vertexCount; i++) { - float prev = prevVertices[i]; - deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; - } + case MixBlend_Setup: { + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, with alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i], setup = setupVertices[i]; + deform[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha; } - break; - } - case MixBlend_First: - case MixBlend_Replace: - // Vertex positions or deform offsets, with alpha. + } else { + // Weighted deform offsets, with alpha. for (size_t i = 0; i < vertexCount; i++) { float prev = prevVertices[i]; - deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha; + deform[i] = (prev + (nextVertices[i] - prev) * percent) * alpha; } - break; - case MixBlend_Add: - VertexAttachment *vertexAttachment = static_cast(slotAttachment); - if (vertexAttachment->getBones().size() == 0) { - // Unweighted vertex positions, with alpha. - Vector &setupVertices = vertexAttachment->getVertices(); - for (size_t i = 0; i < vertexCount; i++) { - float prev = prevVertices[i]; - deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; - } - } else { - // Weighted deform offsets, with alpha. - for (size_t i = 0; i < vertexCount; i++) { - float prev = prevVertices[i]; - deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; - } + } + break; + } + case MixBlend_First: + case MixBlend_Replace: + // Vertex positions or deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += (prev + (nextVertices[i] - prev) * percent - deform[i]) * alpha; + } + break; + case MixBlend_Add: + VertexAttachment *vertexAttachment = static_cast(slotAttachment); + if (vertexAttachment->getBones().size() == 0) { + // Unweighted vertex positions, with alpha. + Vector &setupVertices = vertexAttachment->getVertices(); + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += (prev + (nextVertices[i] - prev) * percent - setupVertices[i]) * alpha; } + } else { + // Weighted deform offsets, with alpha. + for (size_t i = 0; i < vertexCount; i++) { + float prev = prevVertices[i]; + deform[i] += (prev + (nextVertices[i] - prev) * percent) * alpha; + } + } } } } int DeformTimeline::getPropertyId() { assert(_attachment != NULL); - return ((int) TimelineType_Deform << 24) + _attachment->_id + _slotIndex; } diff --git a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp index d5f192ed6..9f6c705dd 100644 --- a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp @@ -57,7 +57,8 @@ DrawOrderTimeline::DrawOrderTimeline(int frameCount) : Timeline() { } void DrawOrderTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(alpha); @@ -67,9 +68,8 @@ void DrawOrderTimeline::apply(Skeleton &skeleton, float lastTime, float time, Ve if (direction == MixDirection_Out && blend == MixBlend_Setup) { drawOrder.clear(); drawOrder.ensureCapacity(slots.size()); - for (size_t i = 0, n = slots.size(); i < n; ++i) { + for (size_t i = 0, n = slots.size(); i < n; ++i) drawOrder.add(slots[i]); - } return; } @@ -77,9 +77,8 @@ void DrawOrderTimeline::apply(Skeleton &skeleton, float lastTime, float time, Ve if (blend == MixBlend_Setup || blend == MixBlend_First) { drawOrder.clear(); drawOrder.ensureCapacity(slots.size()); - for (size_t i = 0, n = slots.size(); i < n; ++i) { + for (size_t i = 0, n = slots.size(); i < n; ++i) drawOrder.add(slots[i]); - } } return; } @@ -88,20 +87,17 @@ void DrawOrderTimeline::apply(Skeleton &skeleton, float lastTime, float time, Ve if (time >= _frames[_frames.size() - 1]) { // Time is after last frame. frame = _frames.size() - 1; - } else { + } else frame = (size_t)Animation::binarySearch(_frames, time) - 1; - } Vector &drawOrderToSetupIndex = _drawOrders[frame]; if (drawOrderToSetupIndex.size() == 0) { drawOrder.clear(); - for (size_t i = 0, n = slots.size(); i < n; ++i) { + for (size_t i = 0, n = slots.size(); i < n; ++i) drawOrder.add(slots[i]); - } } else { - for (size_t i = 0, n = drawOrderToSetupIndex.size(); i < n; ++i) { + for (size_t i = 0, n = drawOrderToSetupIndex.size(); i < n; ++i) drawOrder[i] = slots[drawOrderToSetupIndex[i]]; - } } } diff --git a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp index 05f17890c..3dcb96039 100644 --- a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp @@ -57,10 +57,9 @@ EventTimeline::~EventTimeline() { } void EventTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { - if (pEvents == NULL) { - return; - } + MixBlend blend, MixDirection direction +) { + if (pEvents == NULL) return; Vector &events = *pEvents; @@ -75,9 +74,7 @@ void EventTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector return; } - if (time < _frames[0]) { - return; // Time is before first frame. - } + if (time < _frames[0]) return; // Time is before first frame. int frame; if (lastTime < _frames[0]) { @@ -87,16 +84,13 @@ void EventTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector float frameTime = _frames[frame]; while (frame > 0) { // Fire multiple events with the same frame. - if (_frames[frame - 1] != frameTime) { - break; - } + if (_frames[frame - 1] != frameTime) break; frame--; } } - for (; (size_t)frame < frameCount && time >= _frames[frame]; ++frame) { + for (; (size_t)frame < frameCount && time >= _frames[frame]; ++frame) events.add(_events[frame]); - } } int EventTimeline::getPropertyId() { diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 72a670b80..2e9d565ae 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -65,8 +65,7 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress if (uniform) sy *= s; } } - bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, - sy, bone._ashearX, bone._ashearY); + bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx, sy, bone._ashearX, bone._ashearY); } void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY, int bendDir, bool stretch, float softness, float alpha) { @@ -222,21 +221,21 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY a2 = ((a2 + os) * MathUtil::Rad_Deg - child._ashearX) * s2 + o2 - child._arotation; if (a2 > 180) a2 -= 360; else if (a2 < -180) a2 += 360; - child.updateWorldTransform(cx, cy, child._arotation + a2 * alpha, child._ascaleX, child._ascaleY, - child._ashearX, child._ashearY); + child.updateWorldTransform(cx, cy, child._arotation + a2 * alpha, child._ascaleX, child._ascaleY, child._ashearX, child._ashearY); } } IkConstraint::IkConstraint(IkConstraintData &data, Skeleton &skeleton) : Updatable(), - _data(data), - _bendDirection(data.getBendDirection()), - _compress(data.getCompress()), - _stretch(data.getStretch()), - _mix(data.getMix()), - _softness(data.getSoftness()), - _target(skeleton.findBone( - data.getTarget()->getName())), - _active(false) { + _data(data), + _bendDirection(data.getBendDirection()), + _compress(data.getCompress()), + _stretch(data.getStretch()), + _mix(data.getMix()), + _softness(data.getSoftness()), + _target(skeleton.findBone( + data.getTarget()->getName())), + _active(false) +{ _bones.ensureCapacity(_data.getBones().size()); for (size_t i = 0; i < _data.getBones().size(); i++) { BoneData *boneData = _data.getBones()[i]; @@ -251,17 +250,17 @@ void IkConstraint::apply() { void IkConstraint::update() { switch (_bones.size()) { - case 1: { - Bone *bone0 = _bones[0]; - apply(*bone0, _target->getWorldX(), _target->getWorldY(), _compress, _stretch, _data._uniform, _mix); - } - break; - case 2: { - Bone *bone0 = _bones[0]; - Bone *bone1 = _bones[1]; - apply(*bone0, *bone1, _target->getWorldX(), _target->getWorldY(), _bendDirection, _stretch, _softness, _mix); - } - break; + case 1: { + Bone *bone0 = _bones[0]; + apply(*bone0, _target->getWorldX(), _target->getWorldY(), _compress, _stretch, _data._uniform, _mix); + } + break; + case 2: { + Bone *bone0 = _bones[0]; + Bone *bone1 = _bones[1]; + apply(*bone0, *bone1, _target->getWorldX(), _target->getWorldY(), _bendDirection, _stretch, _softness, _mix); + } + break; } } @@ -326,10 +325,10 @@ void IkConstraint::setActive(bool inValue) { } float IkConstraint::getSoftness() { - return _softness; + return _softness; } void IkConstraint::setSoftness(float inValue) { - _softness = inValue; + _softness = inValue; } diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp index 158819760..911a91d1a 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp @@ -100,7 +100,7 @@ void IkConstraintTimeline::apply(Skeleton &skeleton, float lastTime, float time, constraint._mix = constraint._data._mix + (_frames[_frames.size() + PREV_MIX] - constraint._data._mix) * alpha; constraint._softness = constraint._data._softness - + (_frames[_frames.size() + PREV_SOFTNESS] - constraint._data._softness) * alpha; + + (_frames[_frames.size() + PREV_SOFTNESS] - constraint._data._softness) * alpha; if (direction == MixDirection_Out) { constraint._bendDirection = constraint._data._bendDirection; constraint._compress = constraint._data._compress; @@ -134,7 +134,7 @@ void IkConstraintTimeline::apply(Skeleton &skeleton, float lastTime, float time, constraint._mix = constraint._data._mix + (mix + (_frames[frame + MIX] - mix) * percent - constraint._data._mix) * alpha; constraint._softness = constraint._data._softness - + (softness + (_frames[frame + SOFTNESS] - softness) * percent - constraint._data._softness) * alpha; + + (softness + (_frames[frame + SOFTNESS] - softness) * percent - constraint._data._softness) * alpha; if (direction == MixDirection_Out) { constraint._bendDirection = constraint._data._bendDirection; constraint._compress = constraint._data._compress; diff --git a/spine-cpp/spine-cpp/src/spine/Json.cpp b/spine-cpp/spine-cpp/src/spine/Json.cpp index b7721e604..dc97aba77 100644 --- a/spine-cpp/spine-cpp/src/spine/Json.cpp +++ b/spine-cpp/spine-cpp/src/spine/Json.cpp @@ -1,38 +1,32 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. - * - * Copyright (c) 2013-2019, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN - * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS - * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ +/* +Copyright (c) 2009, Dave Gamble +Copyright (c) 2013, Esoteric Software + +Permission is hereby granted, dispose of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ #ifdef SPINE_UE4 #include "SpinePluginPrivatePCH.h" #endif /* Json */ -/* JSON parser in CPP, shamelessly ripped from json.c in the spine-c runtime */ +/* JSON parser in CPP, from json.c in the spine-c runtime */ #ifndef _DEFAULT_SOURCE /* Bring strings.h definitions into string.h, where appropriate */ @@ -163,49 +157,49 @@ const char *Json::parseValue(Json *item, const char *value) { #endif switch (*value) { - case 'n': { - if (!strncmp(value + 1, "ull", 3)) { - item->_type = JSON_NULL; - return value + 4; - } - break; + case 'n': { + if (!strncmp(value + 1, "ull", 3)) { + item->_type = JSON_NULL; + return value + 4; } - case 'f': { - if (!strncmp(value + 1, "alse", 4)) { - item->_type = JSON_FALSE; - /* calloc prevents us needing item->_type = JSON_FALSE or valueInt = 0 here */ - return value + 5; - } - break; + break; + } + case 'f': { + if (!strncmp(value + 1, "alse", 4)) { + item->_type = JSON_FALSE; + /* calloc prevents us needing item->_type = JSON_FALSE or valueInt = 0 here */ + return value + 5; } - case 't': { - if (!strncmp(value + 1, "rue", 3)) { - item->_type = JSON_TRUE; - item->_valueInt = 1; - return value + 4; - } - break; + break; + } + case 't': { + if (!strncmp(value + 1, "rue", 3)) { + item->_type = JSON_TRUE; + item->_valueInt = 1; + return value + 4; } - case '\"': - return parseString(item, value); - case '[': - return parseArray(item, value); - case '{': - return parseObject(item, value); - case '-': /* fallthrough */ - case '0': /* fallthrough */ - case '1': /* fallthrough */ - case '2': /* fallthrough */ - case '3': /* fallthrough */ - case '4': /* fallthrough */ - case '5': /* fallthrough */ - case '6': /* fallthrough */ - case '7': /* fallthrough */ - case '8': /* fallthrough */ - case '9': - return parseNumber(item, value); - default: - break; + break; + } + case '\"': + return parseString(item, value); + case '[': + return parseArray(item, value); + case '{': + return parseObject(item, value); + case '-': /* fallthrough */ + case '0': /* fallthrough */ + case '1': /* fallthrough */ + case '2': /* fallthrough */ + case '3': /* fallthrough */ + case '4': /* fallthrough */ + case '5': /* fallthrough */ + case '6': /* fallthrough */ + case '7': /* fallthrough */ + case '8': /* fallthrough */ + case '9': + return parseNumber(item, value); + default: + break; } _error = value; @@ -266,18 +260,18 @@ const char *Json::parseString(Json *item, const char *str) { ptr += 4; /* get the unicode char. */ if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0) { - break; /* check for invalid. */ + break; /* check for invalid. */ } /* TODO provide an option to ignore surrogates, use unicode replacement character? */ - if (uc >= 0xD800 && uc <= 0xDBFF) /* UTF16 surrogate pairs. */ { + if (uc >= 0xD800 && uc <= 0xDBFF) /* UTF16 surrogate pairs. */ { if (ptr[1] != '\\' || ptr[2] != 'u') { - break; /* missing second-half of surrogate. */ + break; /* missing second-half of surrogate. */ } sscanf(ptr + 3, "%4x", &uc2); ptr += 6; if (uc2 < 0xDC00 || uc2 > 0xDFFF) { - break; /* invalid second-half of surrogate. */ + break; /* invalid second-half of surrogate. */ } uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF)); } @@ -549,7 +543,7 @@ int Json::json_strcasecmp(const char *s1, const char *s2) { } else if (s1 == s2) { return 0; /* both are null */ } else { - return 1; /* s2 is nul s1 is not */ + return 1; /* s2 is nul s1 is not */ } } } diff --git a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp index b08610954..f6b7d185c 100644 --- a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp @@ -39,25 +39,25 @@ using namespace spine; RTTI_IMPL(MeshAttachment, VertexAttachment) MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), HasRendererObject(), - _regionOffsetX(0), - _regionOffsetY(0), - _regionWidth(0), - _regionHeight(0), - _regionOriginalWidth(0), - _regionOriginalHeight(0), - _parentMesh(NULL), - _path(), - _regionU(0), - _regionV(0), - _regionU2(0), - _regionV2(0), - _width(0), - _height(0), - _color(1, 1, 1, 1), - _hullLength(0), - _regionRotate(false), - _regionDegrees(0) { -} + _regionOffsetX(0), + _regionOffsetY(0), + _regionWidth(0), + _regionHeight(0), + _regionOriginalWidth(0), + _regionOriginalHeight(0), + _parentMesh(NULL), + _path(), + _regionU(0), + _regionV(0), + _regionU2(0), + _regionV2(0), + _width(0), + _height(0), + _color(1, 1, 1, 1), + _hullLength(0), + _regionRotate(false), + _regionDegrees(0) +{} MeshAttachment::~MeshAttachment() {} @@ -71,58 +71,58 @@ void MeshAttachment::updateUVs() { float width = 0, height = 0; switch (_regionDegrees) { - case 90: { - float textureWidth = _regionHeight / (_regionU2 - _regionU); - float textureHeight = _regionWidth / (_regionV2 - _regionV); - u -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureWidth; - v -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureHeight; - width = _regionOriginalHeight / textureWidth; - height = _regionOriginalWidth / textureHeight; - for (i = 0; i < n; i += 2) { - _uvs[i] = u + _regionUVs[i + 1] * width; - _uvs[i + 1] = v + (1 - _regionUVs[i]) * height; - } - return; + case 90: { + float textureWidth = _regionHeight / (_regionU2 - _regionU); + float textureHeight = _regionWidth / (_regionV2 - _regionV); + u -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureWidth; + v -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureHeight; + width = _regionOriginalHeight / textureWidth; + height = _regionOriginalWidth / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + _regionUVs[i + 1] * width; + _uvs[i + 1] = v + (1 - _regionUVs[i]) * height; } - case 180: { - float textureWidth = _regionWidth / (_regionU2 - _regionU); - float textureHeight = _regionHeight / (_regionV2 - _regionV); - u -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureWidth; - v -= _regionOffsetY / textureHeight; - width = _regionOriginalWidth / textureWidth; - height = _regionOriginalHeight / textureHeight; - for (i = 0; i < n; i += 2) { - _uvs[i] = u + (1 - _regionUVs[i]) * width; - _uvs[i + 1] = v + (1 - _regionUVs[i + 1]) * height; - } - return; + return; + } + case 180: { + float textureWidth = _regionWidth / (_regionU2 - _regionU); + float textureHeight = _regionHeight / (_regionV2 - _regionV); + u -= (_regionOriginalWidth - _regionOffsetX - _regionWidth) / textureWidth; + v -= _regionOffsetY / textureHeight; + width = _regionOriginalWidth / textureWidth; + height = _regionOriginalHeight / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + (1 - _regionUVs[i]) * width; + _uvs[i + 1] = v + (1 - _regionUVs[i + 1]) * height; } - case 270: { - float textureHeight = _regionHeight / (_regionV2 - _regionV); - float textureWidth = _regionWidth / (_regionU2 - _regionU); - u -= _regionOffsetY / textureWidth; - v -= _regionOffsetX / textureHeight; - width = _regionOriginalHeight / textureWidth; - height = _regionOriginalWidth / textureHeight; - for (i = 0; i < n; i += 2) { - _uvs[i] = u + (1 - _regionUVs[i + 1]) * width; - _uvs[i + 1] = v + _regionUVs[i] * height; - } - return; + return; + } + case 270: { + float textureHeight = _regionHeight / (_regionV2 - _regionV); + float textureWidth = _regionWidth / (_regionU2 - _regionU); + u -= _regionOffsetY / textureWidth; + v -= _regionOffsetX / textureHeight; + width = _regionOriginalHeight / textureWidth; + height = _regionOriginalWidth / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + (1 - _regionUVs[i + 1]) * width; + _uvs[i + 1] = v + _regionUVs[i] * height; } - default: { - float textureWidth = _regionWidth / (_regionU2 - _regionU); - float textureHeight = _regionHeight / (_regionV2 - _regionV); - u -= _regionOffsetX / textureWidth; - v -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureHeight; - width = _regionOriginalWidth / textureWidth; - height = _regionOriginalHeight / textureHeight; - for (i = 0; i < n; i += 2) { - _uvs[i] = u + _regionUVs[i] * width; - _uvs[i + 1] = v + _regionUVs[i + 1] * height; - } + return; + } + default: { + float textureWidth = _regionWidth / (_regionU2 - _regionU); + float textureHeight = _regionHeight / (_regionV2 - _regionV); + u -= _regionOffsetX / textureWidth; + v -= (_regionOriginalHeight - _regionOffsetY - _regionHeight) / textureHeight; + width = _regionOriginalWidth / textureWidth; + height = _regionOriginalHeight / textureHeight; + for (i = 0; i < n; i += 2) { + _uvs[i] = u + _regionUVs[i] * width; + _uvs[i + 1] = v + _regionUVs[i + 1] * height; } } + } } int MeshAttachment::getHullLength() { @@ -295,7 +295,7 @@ Attachment* MeshAttachment::copy() { copy->_regionV2 = _regionV2; copy->_regionRotate = _regionRotate; copy->_regionDegrees = _regionDegrees; - copy->_regionOffsetX = _regionOffsetX; + copy->_regionOffsetX = _regionOffsetX; copy->_regionOffsetY = _regionOffsetY; copy->_regionWidth = _regionWidth; copy->_regionHeight = _regionHeight; @@ -326,7 +326,7 @@ MeshAttachment* MeshAttachment::newLinkedMesh() { copy->_regionV2 = _regionV2; copy->_regionRotate = _regionRotate; copy->_regionDegrees = _regionDegrees; - copy->_regionOffsetX = _regionOffsetX; + copy->_regionOffsetX = _regionOffsetX; copy->_regionOffsetY = _regionOffsetY; copy->_regionWidth = _regionWidth; copy->_regionHeight = _regionHeight; diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp index 5aad493a0..bc5fc6138 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp @@ -52,14 +52,15 @@ const int PathConstraint::BEFORE = -2; const int PathConstraint::AFTER = -3; PathConstraint::PathConstraint(PathConstraintData &data, Skeleton &skeleton) : Updatable(), - _data(data), - _target(skeleton.findSlot( - data.getTarget()->getName())), - _position(data.getPosition()), - _spacing(data.getSpacing()), - _rotateMix(data.getRotateMix()), - _translateMix(data.getTranslateMix()), - _active(false) { + _data(data), + _target(skeleton.findSlot( + data.getTarget()->getName())), + _position(data.getPosition()), + _spacing(data.getSpacing()), + _rotateMix(data.getRotateMix()), + _translateMix(data.getTranslateMix()), + _active(false) +{ _bones.ensureCapacity(_data.getBones().size()); for (size_t i = 0; i < _data.getBones().size(); i++) { BoneData *boneData = _data.getBones()[i]; @@ -98,9 +99,7 @@ void PathConstraint::update() { _spaces.setSize(spacesCount, 0); float spacing = _spacing; if (scale || !percentSpacing) { - if (scale) { - _lengths.setSize(boneCount, 0); - } + if (scale) _lengths.setSize(boneCount, 0); bool lengthSpacing = data._spacingMode == SpacingMode_Length; for (size_t i = 0, n = spacesCount - 1; i < n;) { @@ -108,9 +107,7 @@ void PathConstraint::update() { Bone &bone = *boneP; float setupLength = bone._data.getLength(); if (setupLength < PathConstraint::EPSILON) { - if (scale) { - _lengths[i] = 0; - } + if (scale) _lengths[i] = 0; _spaces[++i] = 0; } else if (percentSpacing) { if (scale) { @@ -137,8 +134,7 @@ void PathConstraint::update() { } Vector& positions = computeWorldPositions(*attachment, spacesCount, tangents, - data.getPositionMode() == PositionMode_Percent, - percentSpacing); + data.getPositionMode() == PositionMode_Percent, percentSpacing); float boneX = positions[0]; float boneY = positions[1]; float offsetRotation = data.getOffsetRotation(); @@ -174,13 +170,12 @@ void PathConstraint::update() { if (rotate) { float a = bone._a, b = bone._b, c = bone._c, d = bone._d, r, cos, sin; - if (tangents) { + if (tangents) r = positions[p - 1]; - } else if (_spaces[i + 1] < PathConstraint::EPSILON) { + else if (_spaces[i + 1] < PathConstraint::EPSILON) r = positions[p + 2]; - } else { + else r = MathUtil::atan2(dy, dx); - } r -= MathUtil::atan2(c, a); @@ -190,15 +185,13 @@ void PathConstraint::update() { float length = bone._data.getLength(); boneX += (length * (cos * a - sin * c) - dx) * rotateMix; boneY += (length * (sin * a + cos * c) - dy) * rotateMix; - } else { + } else r += offsetRotation; - } - if (r > MathUtil::Pi) { + if (r > MathUtil::Pi) r -= MathUtil::Pi_2; - } else if (r < -MathUtil::Pi) { + else if (r < -MathUtil::Pi) r += MathUtil::Pi_2; - } r *= rotateMix; cos = MathUtil::cos(r); @@ -266,8 +259,7 @@ PathConstraintData &PathConstraint::getData() { } Vector& -PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, bool tangents, bool percentPosition, - bool percentSpacing) { +PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing) { Slot &target = *_target; float position = _position; _positions.setSize(spacesCount * 3 + 2, 0); @@ -283,14 +275,11 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo Vector &lengths = path.getLengths(); curveCount -= closed ? 1 : 2; pathLength = lengths[curveCount]; - if (percentPosition) { - position *= pathLength; - } + if (percentPosition) position *= pathLength; if (percentSpacing) { - for (int i = 1; i < spacesCount; ++i) { + for (int i = 1; i < spacesCount; ++i) _spaces[i] *= pathLength; - } } world.setSize(8, 0); @@ -301,10 +290,7 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo if (closed) { p = MathUtil::fmod(p, pathLength); - - if (p < 0) { - p += pathLength; - } + if (p < 0) p += pathLength; curve = 0; } else if (p < 0) { if (prevCurve != BEFORE) { @@ -329,13 +315,11 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo // Determine curve containing position. for (;; curve++) { float length = lengths[curve]; - if (p > length) { - continue; - } + if (p > length) continue; - if (curve == 0) { + if (curve == 0) p /= length; - } else { + else { float prev = lengths[curve - 1]; p = (p - prev) / (length - prev); } @@ -347,13 +331,12 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo if (closed && curve == curveCount) { path.computeWorldVertices(target, verticesLength - 4, 4, world, 0); path.computeWorldVertices(target, 0, 4, world, 4); - } else { + } else path.computeWorldVertices(target, curve * 6 + 2, 8, world, 0); - } } addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], - out, o, tangents || (i > 0 && space < EPSILON)); + out, o, tangents || (i > 0 && space < EPSILON)); } return out; } @@ -410,16 +393,14 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo y1 = y2; } - if (percentPosition) { + if (percentPosition) position *= pathLength; - } else { + else position *= pathLength / path.getLengths()[curveCount - 1]; - } if (percentSpacing) { - for (int i = 1; i < spacesCount; ++i) { + for (int i = 1; i < spacesCount; ++i) _spaces[i] *= pathLength; - } } float curveLength = 0; @@ -430,10 +411,7 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo if (closed) { p = MathUtil::fmod(p, pathLength); - - if (p < 0) { - p += pathLength; - } + if (p < 0) p += pathLength; curve = 0; } else if (p < 0) { addBeforePosition(p, world, 0, out, o); @@ -446,13 +424,10 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo // Determine curve containing position. for (;; curve++) { float length = _curves[curve]; - if (p > length) { - continue; - } - - if (curve == 0) { + if (p > length) continue; + if (curve == 0) p /= length; - } else { + else { float prev = _curves[curve - 1]; p = (p - prev) / (length - prev); } @@ -504,20 +479,17 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo p *= curveLength; for (;; segment++) { float length = _segments[segment]; - if (p > length) { - continue; - } - - if (segment == 0) { + if (p > length) continue; + if (segment == 0) p /= length; - } else { + else { float prev = _segments[segment - 1]; p = segment + (p - prev) / (length - prev); } break; } addCurvePosition(p * 0.1f, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, - tangents || (i > 0 && space < EPSILON)); + tangents || (i > 0 && space < EPSILON)); } return out; @@ -529,7 +501,6 @@ void PathConstraint::addBeforePosition(float p, Vector &temp, int i, Vect float dx = temp[i + 2] - x1; float dy = temp[i + 3] - y1; float r = MathUtil::atan2(dy, dx); - output[o] = x1 + p * MathUtil::cos(r); output[o + 1] = y1 + p * MathUtil::sin(r); output[o + 2] = r; @@ -547,7 +518,8 @@ void PathConstraint::addAfterPosition(float p, Vector &temp, int i, Vecto } void PathConstraint::addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, - float y2, Vector &output, int o, bool tangents) { + float y2, Vector &output, int o, bool tangents +) { if (p < EPSILON || MathUtil::isNan(p)) { output[o] = x1; output[o + 1] = y1; @@ -561,12 +533,10 @@ void PathConstraint::addCurvePosition(float p, float x1, float y1, float cx1, fl output[o] = x; output[o + 1] = y; if (tangents) { - if (p < 0.001) { + if (p < 0.001) output[o + 2] = MathUtil::atan2(cy1 - y1, cx1 - x1); - } else { - output[o + 2] = MathUtil::atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), - x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); - } + else + output[o + 2] = MathUtil::atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp index 45f47fc8e..a8b8bdf05 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp @@ -55,13 +55,14 @@ const int PathConstraintMixTimeline::ROTATE = 1; const int PathConstraintMixTimeline::TRANSLATE = 2; PathConstraintMixTimeline::PathConstraintMixTimeline(int frameCount) : CurveTimeline(frameCount), - _pathConstraintIndex(0) { + _pathConstraintIndex(0) +{ _frames.setSize(frameCount * ENTRIES, 0); } -void -PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { +void PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -72,16 +73,16 @@ PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float time, if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - constraint._rotateMix = constraint._data._rotateMix; - constraint._translateMix = constraint._data._translateMix; - return; - case MixBlend_First: - constraint._rotateMix += (constraint._data._rotateMix - constraint._rotateMix) * alpha; - constraint._translateMix += (constraint._data._translateMix - constraint._translateMix) * alpha; - return; - default: - return; + case MixBlend_Setup: + constraint._rotateMix = constraint._data._rotateMix; + constraint._translateMix = constraint._data._translateMix; + return; + case MixBlend_First: + constraint._rotateMix += (constraint._data._rotateMix - constraint._rotateMix) * alpha; + constraint._translateMix += (constraint._data._translateMix - constraint._translateMix) * alpha; + return; + default: + return; } } @@ -97,7 +98,7 @@ PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float time, translate = _frames[frame + PREV_TRANSLATE]; float frameTime = _frames[frame]; float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); rotate += (_frames[frame + ROTATE] - rotate) * percent; translate += (_frames[frame + TRANSLATE] - translate) * percent; @@ -106,7 +107,7 @@ PathConstraintMixTimeline::apply(Skeleton &skeleton, float lastTime, float time, if (blend == MixBlend_Setup) { constraint._rotateMix = constraint._data._rotateMix + (rotate - constraint._data._rotateMix) * alpha; constraint._translateMix = - constraint._data._translateMix + (translate - constraint._data._translateMix) * alpha; + constraint._data._translateMix + (translate - constraint._data._translateMix) * alpha; } else { constraint._rotateMix += (rotate - constraint._rotateMix) * alpha; constraint._translateMix += (translate - constraint._translateMix) * alpha; diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp index 4c5388fc0..d832df696 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp @@ -53,7 +53,8 @@ const int PathConstraintPositionTimeline::PREV_VALUE = -1; const int PathConstraintPositionTimeline::VALUE = 1; PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount), - _pathConstraintIndex(0) { + _pathConstraintIndex(0) +{ _frames.setSize(frameCount * ENTRIES, 0); } @@ -61,7 +62,8 @@ PathConstraintPositionTimeline::~PathConstraintPositionTimeline() { } void PathConstraintPositionTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, - float alpha, MixBlend blend, MixDirection direction) { + float alpha, MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -72,14 +74,14 @@ void PathConstraintPositionTimeline::apply(Skeleton &skeleton, float lastTime, f if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - constraint._position = constraint._data._position; - return; - case MixBlend_First: - constraint._position += (constraint._data._position - constraint._position) * alpha; - return; - default: - return; + case MixBlend_Setup: + constraint._position = constraint._data._position; + return; + case MixBlend_First: + constraint._position += (constraint._data._position - constraint._position) * alpha; + return; + default: + return; } } @@ -93,15 +95,14 @@ void PathConstraintPositionTimeline::apply(Skeleton &skeleton, float lastTime, f position = _frames[frame + PREV_VALUE]; float frameTime = _frames[frame]; float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); position += (_frames[frame + VALUE] - position) * percent; } - if (blend == MixBlend_Setup) { + if (blend == MixBlend_Setup) constraint._position = constraint._data._position + (position - constraint._data._position) * alpha; - } else { + else constraint._position += (position - constraint._position) * alpha; - } } int PathConstraintPositionTimeline::getPropertyId() { diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp index 92da76576..0e0135dad 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp @@ -52,7 +52,8 @@ PathConstraintSpacingTimeline::PathConstraintSpacingTimeline(int frameCount) : P } void PathConstraintSpacingTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, - float alpha, MixBlend blend, MixDirection direction) { + float alpha, MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -63,14 +64,14 @@ void PathConstraintSpacingTimeline::apply(Skeleton &skeleton, float lastTime, fl if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - constraint._spacing = constraint._data._spacing; - return; - case MixBlend_First: - constraint._spacing += (constraint._data._spacing - constraint._spacing) * alpha; - return; - default: - return; + case MixBlend_Setup: + constraint._spacing = constraint._data._spacing; + return; + case MixBlend_First: + constraint._spacing += (constraint._data._spacing - constraint._spacing) * alpha; + return; + default: + return; } } @@ -84,16 +85,15 @@ void PathConstraintSpacingTimeline::apply(Skeleton &skeleton, float lastTime, fl spacing = _frames[frame + PREV_VALUE]; float frameTime = _frames[frame]; float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); spacing += (_frames[frame + VALUE] - spacing) * percent; } - if (blend == MixBlend_Setup) { + if (blend == MixBlend_Setup) constraint._spacing = constraint._data._spacing + (spacing - constraint._data._spacing) * alpha; - } else { + else constraint._spacing += (spacing - constraint._spacing) * alpha; - } } int PathConstraintSpacingTimeline::getPropertyId() { diff --git a/spine-cpp/spine-cpp/src/spine/RTTI.cpp b/spine-cpp/spine-cpp/src/spine/RTTI.cpp index 727c2b08d..90da108b1 100644 --- a/spine-cpp/spine-cpp/src/spine/RTTI.cpp +++ b/spine-cpp/spine-cpp/src/spine/RTTI.cpp @@ -52,14 +52,9 @@ bool RTTI::isExactly(const RTTI &rtti) const { bool RTTI::instanceOf(const RTTI &rtti) const { const RTTI *pCompare = this; - while (pCompare) { - if (pCompare->_className == rtti._className) { - return true; - } - + if (pCompare->_className == rtti._className) return true; pCompare = pCompare->_pBaseRTTI; } - return false; } diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index 20f5d9952..8a4106928 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -51,25 +51,26 @@ const int RegionAttachment::BRX = 6; const int RegionAttachment::BRY = 7; RegionAttachment::RegionAttachment(const String &name) : Attachment(name), HasRendererObject(), - _x(0), - _y(0), - _rotation(0), - _scaleX(1), - _scaleY(1), - _width(0), - _height(0), - _regionOffsetX(0), - _regionOffsetY(0), - _regionWidth(0), - _regionHeight(0), - _regionOriginalWidth(0), - _regionOriginalHeight(0), - _path(), - _regionU(0), - _regionV(0), - _regionU2(0), - _regionV2(0), - _color(1, 1, 1, 1) { + _x(0), + _y(0), + _rotation(0), + _scaleX(1), + _scaleY(1), + _width(0), + _height(0), + _regionOffsetX(0), + _regionOffsetY(0), + _regionWidth(0), + _regionHeight(0), + _regionOriginalWidth(0), + _regionOriginalHeight(0), + _path(), + _regionU(0), + _regionV(0), + _regionU2(0), + _regionV2(0), + _color(1, 1, 1, 1) +{ _vertexOffset.setSize(NUM_UVS, 0); _uvs.setSize(NUM_UVS, 0); } diff --git a/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp b/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp index 8b4af88d1..f0616b104 100644 --- a/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp @@ -50,7 +50,8 @@ RotateTimeline::RotateTimeline(int frameCount) : CurveTimeline(frameCount), _bon } void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -60,21 +61,20 @@ void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: { - bone->_rotation = bone->_data._rotation; - break; - } - case MixBlend_First: { - float r = bone->_data._rotation - bone->_rotation; - bone->_rotation += (r - (16384 - (int) (16384.499999999996 - r / 360)) * 360) * alpha; - break; - } - default: { - // TODO? - break; - } + case MixBlend_Setup: { + bone->_rotation = bone->_data._rotation; + break; + } + case MixBlend_First: { + float r = bone->_data._rotation - bone->_rotation; + bone->_rotation += (r - (16384 - (int) (16384.499999999996 - r / 360)) * 360) * alpha; + break; + } + default: { + // TODO? + break; + } } - return; } @@ -100,7 +100,7 @@ void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto float prevRotation = _frames[frame + PREV_ROTATION]; float frameTime = _frames[frame]; float percent = getCurvePercent((frame >> 1) - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); float r = _frames[frame + ROTATION] - prevRotation; r = prevRotation + (r - (16384 - (int)(16384.499999999996 - r / 360)) * 360) * percent; switch (blend) { diff --git a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp index 6431ba748..cd88d1288 100644 --- a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp @@ -48,7 +48,8 @@ ScaleTimeline::ScaleTimeline(int frameCount) : TranslateTimeline(frameCount) { } void ScaleTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); @@ -59,14 +60,14 @@ void ScaleTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - bone._scaleX = bone._data._scaleX; - bone._scaleY = bone._data._scaleY; - return; - case MixBlend_First: - bone._scaleX += (bone._data._scaleX - bone._scaleX) * alpha; - bone._scaleY += (bone._data._scaleY - bone._scaleY) * alpha; - default: {} + case MixBlend_Setup: + bone._scaleX = bone._data._scaleX; + bone._scaleY = bone._data._scaleY; + return; + case MixBlend_First: + bone._scaleX += (bone._data._scaleX - bone._scaleX) * alpha; + bone._scaleY += (bone._data._scaleY - bone._scaleY) * alpha; + default: {} } return; } @@ -83,7 +84,7 @@ void ScaleTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector y = _frames[frame + PREV_Y]; float frameTime = _frames[frame]; float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); x = (x + (_frames[frame + X] - x) * percent) * bone._data._scaleX; y = (y + (_frames[frame + Y] - y) * percent) * bone._data._scaleY; @@ -102,45 +103,45 @@ void ScaleTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector float bx, by; if (direction == MixDirection_Out) { switch (blend) { - case MixBlend_Setup: - bx = bone._data._scaleX; - by = bone._data._scaleY; - bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha; - bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha; - break; - case MixBlend_First: - case MixBlend_Replace: - bx = bone._scaleX; - by = bone._scaleY; - bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha; - bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha; - break; - case MixBlend_Add: - bx = bone._scaleX; - by = bone._scaleY; - bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bone._data._scaleX) * alpha; - bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - bone._data._scaleY) * alpha; + case MixBlend_Setup: + bx = bone._data._scaleX; + by = bone._data._scaleY; + bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha; + bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha; + break; + case MixBlend_First: + case MixBlend_Replace: + bx = bone._scaleX; + by = bone._scaleY; + bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bx) * alpha; + bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - by) * alpha; + break; + case MixBlend_Add: + bx = bone._scaleX; + by = bone._scaleY; + bone._scaleX = bx + (MathUtil::abs(x) * MathUtil::sign(bx) - bone._data._scaleX) * alpha; + bone._scaleY = by + (MathUtil::abs(y) * MathUtil::sign(by) - bone._data._scaleY) * alpha; } } else { switch (blend) { - case MixBlend_Setup: - bx = MathUtil::abs(bone._data._scaleX) * MathUtil::sign(x); - by = MathUtil::abs(bone._data._scaleY) * MathUtil::sign(y); - bone._scaleX = bx + (x - bx) * alpha; - bone._scaleY = by + (y - by) * alpha; - break; - case MixBlend_First: - case MixBlend_Replace: - bx = MathUtil::abs(bone._scaleX) * MathUtil::sign(x); - by = MathUtil::abs(bone._scaleY) * MathUtil::sign(y); - bone._scaleX = bx + (x - bx) * alpha; - bone._scaleY = by + (y - by) * alpha; - break; - case MixBlend_Add: - bx = MathUtil::sign(x); - by = MathUtil::sign(y); - bone._scaleX = MathUtil::abs(bone._scaleX) * bx + (x - MathUtil::abs(bone._data._scaleX) * bx) * alpha; - bone._scaleY = MathUtil::abs(bone._scaleY) * by + (y - MathUtil::abs(bone._data._scaleY) * by) * alpha; + case MixBlend_Setup: + bx = MathUtil::abs(bone._data._scaleX) * MathUtil::sign(x); + by = MathUtil::abs(bone._data._scaleY) * MathUtil::sign(y); + bone._scaleX = bx + (x - bx) * alpha; + bone._scaleY = by + (y - by) * alpha; + break; + case MixBlend_First: + case MixBlend_Replace: + bx = MathUtil::abs(bone._scaleX) * MathUtil::sign(x); + by = MathUtil::abs(bone._scaleY) * MathUtil::sign(y); + bone._scaleX = bx + (x - bx) * alpha; + bone._scaleY = by + (y - by) * alpha; + break; + case MixBlend_Add: + bx = MathUtil::sign(x); + by = MathUtil::sign(y); + bone._scaleX = MathUtil::abs(bone._scaleX) * bx + (x - MathUtil::abs(bone._data._scaleX) * bx) * alpha; + bone._scaleY = MathUtil::abs(bone._scaleY) * by + (y - MathUtil::abs(bone._data._scaleY) * by) * alpha; } } } diff --git a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp index 870c16d4b..6ab4723ee 100644 --- a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp @@ -49,7 +49,8 @@ ShearTimeline::ShearTimeline(int frameCount) : TranslateTimeline(frameCount) { } void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -60,14 +61,14 @@ void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - bone._shearX = bone._data._shearX; - bone._shearY = bone._data._shearY; - return; - case MixBlend_First: - bone._shearX += (bone._data._shearX - bone._shearX) * alpha; - bone._shearY += (bone._data._shearY - bone._shearY) * alpha; - default: {} + case MixBlend_Setup: + bone._shearX = bone._data._shearX; + bone._shearY = bone._data._shearY; + return; + case MixBlend_First: + bone._shearX += (bone._data._shearX - bone._shearX) * alpha; + bone._shearY += (bone._data._shearY - bone._shearY) * alpha; + default: {} } return; } @@ -84,7 +85,7 @@ void ShearTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector y = _frames[frame + PREV_Y]; float frameTime = _frames[frame]; float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); x = x + (_frames[frame + X] - x) * percent; y = y + (_frames[frame + Y] - y) * percent; diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp index a0f6af924..dbf530134 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp @@ -99,7 +99,8 @@ SkeletonBinary::SkeletonBinary(Atlas *atlasArray) : _attachmentLoader( } SkeletonBinary::SkeletonBinary(AttachmentLoader *attachmentLoader) : _attachmentLoader(attachmentLoader), _error(), - _scale(1), _ownsLoader(false) { + _scale(1), _ownsLoader(false) +{ assert(_attachmentLoader != NULL); } @@ -107,9 +108,7 @@ SkeletonBinary::~SkeletonBinary() { ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); _linkedMeshes.clear(); - if (_ownsLoader) { - delete _attachmentLoader; - } + if (_ownsLoader) delete _attachmentLoader; } SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, const int length) { @@ -165,10 +164,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons data->_length = readFloat(input) * _scale; data->_transformMode = static_cast(readVarint(input, true)); data->_skinRequired = readBoolean(input); - if (nonessential) { - /* Skip bone color. */ - readInt(input); - } + if (nonessential) readInt(input); /* Skip bone color. */ skeletonData->_bones[i] = data; } @@ -204,9 +200,8 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons data->setSkinRequired(readBoolean(input)); int bonesCount = readVarint(input, true); data->_bones.setSize(bonesCount, 0); - for (int ii = 0; ii < bonesCount; ++ii) { + for (int ii = 0; ii < bonesCount; ++ii) data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; - } data->_target = skeletonData->_bones[readVarint(input, true)]; data->_mix = readFloat(input); data->_softness = readFloat(input) * _scale; @@ -227,9 +222,8 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons data->setSkinRequired(readBoolean(input)); int bonesCount = readVarint(input, true); data->_bones.setSize(bonesCount, 0); - for (int ii = 0; ii < bonesCount; ++ii) { + for (int ii = 0; ii < bonesCount; ++ii) data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; - } data->_target = skeletonData->_bones[readVarint(input, true)]; data->_local = readBoolean(input); data->_relative = readBoolean(input); @@ -256,9 +250,8 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons data->setSkinRequired(readBoolean(input)); int bonesCount = readVarint(input, true); data->_bones.setSize(bonesCount, 0); - for (int ii = 0; ii < bonesCount; ++ii) { + for (int ii = 0; ii < bonesCount; ++ii) data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; - } data->_target = skeletonData->_slots[readVarint(input, true)]; data->_positionMode = static_cast(readVarint(input, true)); data->_spacingMode = static_cast(readVarint(input, true)); @@ -282,15 +275,14 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons } /* Skins. */ - for (size_t i = 0, n = (size_t)readVarint(input, true); i < n; ++i) { + for (size_t i = 0, n = (size_t)readVarint(input, true); i < n; ++i) skeletonData->_skins.add(readSkin(input, false, skeletonData, nonessential)); - } /* Linked meshes. */ for (int i = 0, n = _linkedMeshes.size(); i < n; ++i) { LinkedMesh *linkedMesh = _linkedMeshes[i]; Skin *skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin( - linkedMesh->_skin); + linkedMesh->_skin); if (skin == NULL) { delete input; delete skeletonData; @@ -365,19 +357,14 @@ void SkeletonBinary::setError(const char *value1, const char *value2) { int length; strcpy(message, value1); length = (int) strlen(value1); - if (value2) { - strncat(message + length, value2, 255 - length); - } - + if (value2) strncat(message + length, value2, 255 - length); _error = String(message); } char *SkeletonBinary::readString(DataInput *input) { int length = readVarint(input, true); char *string; - if (length == 0) { - return NULL; - } + if (length == 0) return NULL; string = SpineExtension::alloc(length, __FILE__, __LINE__); memcpy(string, input->cursor, length - 1); input->cursor += length - 1; @@ -395,9 +382,7 @@ float SkeletonBinary::readFloat(DataInput *input) { int intValue; float floatValue; } intToFloat; - intToFloat.intValue = readInt(input); - return intToFloat.floatValue; } @@ -447,16 +432,11 @@ int SkeletonBinary::readVarint(DataInput *input, bool optimizePositive) { } } } - - if (!optimizePositive) { - value = (((unsigned int) value >> 1) ^ -(value & 1)); - } - + if (!optimizePositive) value = (((unsigned int) value >> 1) ^ -(value & 1)); return value; } -Skin * -SkeletonBinary::readSkin(DataInput *input, bool defaultSkin, SkeletonData *skeletonData, bool nonessential) { +Skin *SkeletonBinary::readSkin(DataInput *input, bool defaultSkin, SkeletonData *skeletonData, bool nonessential) { Skin *skin; int slotCount = 0; if (defaultSkin) { @@ -491,130 +471,131 @@ SkeletonBinary::readSkin(DataInput *input, bool defaultSkin, SkeletonData *skele } Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slotIndex, const String &attachmentName, - SkeletonData *skeletonData, bool nonessential) { + SkeletonData *skeletonData, bool nonessential +) { String name(readStringRef(input, skeletonData)); if (name.isEmpty()) name = attachmentName; AttachmentType type = static_cast(readByte(input)); switch (type) { - case AttachmentType_Region: { - String path(readStringRef(input, skeletonData)); - if (path.isEmpty()) path = name; - RegionAttachment *region = _attachmentLoader->newRegionAttachment(*skin, String(name), String(path)); - region->_path = path; - region->_rotation = readFloat(input); - region->_x = readFloat(input) * _scale; - region->_y = readFloat(input) * _scale; - region->_scaleX = readFloat(input); - region->_scaleY = readFloat(input); - region->_width = readFloat(input) * _scale; - region->_height = readFloat(input) * _scale; - readColor(input, region->getColor()); - region->updateOffset(); - _attachmentLoader->configureAttachment(region); - return region; + case AttachmentType_Region: { + String path(readStringRef(input, skeletonData)); + if (path.isEmpty()) path = name; + RegionAttachment *region = _attachmentLoader->newRegionAttachment(*skin, String(name), String(path)); + region->_path = path; + region->_rotation = readFloat(input); + region->_x = readFloat(input) * _scale; + region->_y = readFloat(input) * _scale; + region->_scaleX = readFloat(input); + region->_scaleY = readFloat(input); + region->_width = readFloat(input) * _scale; + region->_height = readFloat(input) * _scale; + readColor(input, region->getColor()); + region->updateOffset(); + _attachmentLoader->configureAttachment(region); + return region; + } + case AttachmentType_Boundingbox: { + int vertexCount = readVarint(input, true); + BoundingBoxAttachment *box = _attachmentLoader->newBoundingBoxAttachment(*skin, String(name)); + readVertices(input, static_cast(box), vertexCount); + if (nonessential) { + /* Skip color. */ + readInt(input); } - case AttachmentType_Boundingbox: { - int vertexCount = readVarint(input, true); - BoundingBoxAttachment *box = _attachmentLoader->newBoundingBoxAttachment(*skin, String(name)); - readVertices(input, static_cast(box), vertexCount); - if (nonessential) { - /* Skip color. */ - readInt(input); - } - _attachmentLoader->configureAttachment(box); - return box; - } - case AttachmentType_Mesh: { - int vertexCount; - MeshAttachment *mesh; - String path(readStringRef(input, skeletonData)); - if (path.isEmpty()) path = name; + _attachmentLoader->configureAttachment(box); + return box; + } + case AttachmentType_Mesh: { + int vertexCount; + MeshAttachment *mesh; + String path(readStringRef(input, skeletonData)); + if (path.isEmpty()) path = name; - mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path)); - mesh->_path = path; - readColor(input, mesh->getColor()); - vertexCount = readVarint(input, true); - readFloatArray(input, vertexCount << 1, 1, mesh->getRegionUVs()); - readShortArray(input, mesh->getTriangles()); - readVertices(input, static_cast(mesh), vertexCount); - mesh->updateUVs(); - mesh->_hullLength = readVarint(input, true) << 1; - if (nonessential) { - readShortArray(input, mesh->getEdges()); - mesh->_width = readFloat(input) * _scale; - mesh->_height = readFloat(input) * _scale; - } else { - mesh->_width = 0; - mesh->_height = 0; - } - _attachmentLoader->configureAttachment(mesh); - return mesh; + mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path)); + mesh->_path = path; + readColor(input, mesh->getColor()); + vertexCount = readVarint(input, true); + readFloatArray(input, vertexCount << 1, 1, mesh->getRegionUVs()); + readShortArray(input, mesh->getTriangles()); + readVertices(input, static_cast(mesh), vertexCount); + mesh->updateUVs(); + mesh->_hullLength = readVarint(input, true) << 1; + if (nonessential) { + readShortArray(input, mesh->getEdges()); + mesh->_width = readFloat(input) * _scale; + mesh->_height = readFloat(input) * _scale; + } else { + mesh->_width = 0; + mesh->_height = 0; } - case AttachmentType_Linkedmesh: { - String path(readStringRef(input, skeletonData)); - if (path.isEmpty()) path = name; + _attachmentLoader->configureAttachment(mesh); + return mesh; + } + case AttachmentType_Linkedmesh: { + String path(readStringRef(input, skeletonData)); + if (path.isEmpty()) path = name; - MeshAttachment *mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path)); - mesh->_path = path; - readColor(input, mesh->getColor()); - String skinName(readStringRef(input, skeletonData)); - String parent(readStringRef(input, skeletonData)); - bool inheritDeform = readBoolean(input); - if (nonessential) { - mesh->_width = readFloat(input) * _scale; - mesh->_height = readFloat(input) * _scale; - } + MeshAttachment *mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path)); + mesh->_path = path; + readColor(input, mesh->getColor()); + String skinName(readStringRef(input, skeletonData)); + String parent(readStringRef(input, skeletonData)); + bool inheritDeform = readBoolean(input); + if (nonessential) { + mesh->_width = readFloat(input) * _scale; + mesh->_height = readFloat(input) * _scale; + } - LinkedMesh *linkedMesh = new(__FILE__, __LINE__) LinkedMesh(mesh, String(skinName), slotIndex, - String(parent), inheritDeform); - _linkedMeshes.add(linkedMesh); - return mesh; + LinkedMesh *linkedMesh = new(__FILE__, __LINE__) LinkedMesh(mesh, String(skinName), slotIndex, + String(parent), inheritDeform); + _linkedMeshes.add(linkedMesh); + return mesh; + } + case AttachmentType_Path: { + PathAttachment *path = _attachmentLoader->newPathAttachment(*skin, String(name)); + path->_closed = readBoolean(input); + path->_constantSpeed = readBoolean(input); + int vertexCount = readVarint(input, true); + readVertices(input, static_cast(path), vertexCount); + int lengthsLength = vertexCount / 3; + path->_lengths.setSize(lengthsLength, 0); + for (int i = 0; i < lengthsLength; ++i) { + path->_lengths[i] = readFloat(input) * _scale; } - case AttachmentType_Path: { - PathAttachment *path = _attachmentLoader->newPathAttachment(*skin, String(name)); - path->_closed = readBoolean(input); - path->_constantSpeed = readBoolean(input); - int vertexCount = readVarint(input, true); - readVertices(input, static_cast(path), vertexCount); - int lengthsLength = vertexCount / 3; - path->_lengths.setSize(lengthsLength, 0); - for (int i = 0; i < lengthsLength; ++i) { - path->_lengths[i] = readFloat(input) * _scale; - } - if (nonessential) { - /* Skip color. */ - readInt(input); - } - _attachmentLoader->configureAttachment(path); - return path; + if (nonessential) { + /* Skip color. */ + readInt(input); } - case AttachmentType_Point: { - PointAttachment *point = _attachmentLoader->newPointAttachment(*skin, String(name)); - point->_rotation = readFloat(input); - point->_x = readFloat(input) * _scale; - point->_y = readFloat(input) * _scale; + _attachmentLoader->configureAttachment(path); + return path; + } + case AttachmentType_Point: { + PointAttachment *point = _attachmentLoader->newPointAttachment(*skin, String(name)); + point->_rotation = readFloat(input); + point->_x = readFloat(input) * _scale; + point->_y = readFloat(input) * _scale; - if (nonessential) { - /* Skip color. */ - readInt(input); - } - _attachmentLoader->configureAttachment(point); - return point; + if (nonessential) { + /* Skip color. */ + readInt(input); } - case AttachmentType_Clipping: { - int endSlotIndex = readVarint(input, true); - int vertexCount = readVarint(input, true); - ClippingAttachment *clip = _attachmentLoader->newClippingAttachment(*skin, name); - readVertices(input, static_cast(clip), vertexCount); - clip->_endSlot = skeletonData->_slots[endSlotIndex]; - if (nonessential) { - /* Skip color. */ - readInt(input); - } - _attachmentLoader->configureAttachment(clip); - return clip; + _attachmentLoader->configureAttachment(point); + return point; + } + case AttachmentType_Clipping: { + int endSlotIndex = readVarint(input, true); + int vertexCount = readVarint(input, true); + ClippingAttachment *clip = _attachmentLoader->newClippingAttachment(*skin, name); + readVertices(input, static_cast(clip), vertexCount); + clip->_endSlot = skeletonData->_slots[endSlotIndex]; + if (nonessential) { + /* Skip color. */ + readInt(input); } + _attachmentLoader->configureAttachment(clip); + return clip; + } } return NULL; } @@ -707,9 +688,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S float b = ((color & 0x0000ff00) >> 8) / 255.0f; float a = ((color & 0x000000ff)) / 255.0f; timeline->setFrame(frameIndex, time, r, g, b, a); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * ColorTimeline::ENTRIES]); @@ -731,9 +710,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S float b2 = ((color2 & 0x000000ff)) / 255.0f; timeline->setFrame(frameIndex, time, r, g, b, a, r2, g2, b2); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * TwoColorTimeline::ENTRIES]); @@ -762,9 +739,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S float time = readFloat(input); float degrees = readFloat(input); timeline->setFrame(frameIndex, time, degrees); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * RotateTimeline::ENTRIES]); @@ -794,8 +769,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S } } timelines.add(timeline); - duration = MathUtil::max(duration, - timeline->_frames[(frameCount - 1) * TranslateTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * TranslateTimeline::ENTRIES]); break; } default: { @@ -821,9 +795,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S bool compress = readBoolean(input); bool stretch = readBoolean(input); timeline->setFrame(frameIndex, time, mix, softness, bendDirection, compress, stretch); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * IkConstraintTimeline::ENTRIES]); @@ -842,9 +814,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S float scaleMix = readFloat(input); float shearMix = readFloat(input); timeline->setFrame(frameIndex, time, rotateMix, translateMix, scaleMix, shearMix); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * TransformConstraintTimeline::ENTRIES]); @@ -865,28 +835,21 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S if (timelineType == PATH_SPACING) { timeline = new(__FILE__, __LINE__) PathConstraintSpacingTimeline(frameCount); - if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) { - timelineScale = scale; - } + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) timelineScale = scale; } else { timeline = new(__FILE__, __LINE__) PathConstraintPositionTimeline(frameCount); - if (data->_positionMode == PositionMode_Fixed) { - timelineScale = scale; - } + if (data->_positionMode == PositionMode_Fixed) timelineScale = scale; } timeline->_pathConstraintIndex = index; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); float value = readFloat(input) * timelineScale; timeline->setFrame(frameIndex, time, value); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); - duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * - PathConstraintPositionTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * PathConstraintPositionTimeline::ENTRIES]); break; } case PATH_MIX: { @@ -898,13 +861,10 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S float rotateMix = readFloat(input); float translateMix = readFloat(input); timeline->setFrame(frameIndex, time, rotateMix, translateMix); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); - duration = MathUtil::max(duration, - timeline->_frames[(frameCount - 1) * PathConstraintMixTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * PathConstraintMixTimeline::ENTRIES]); break; } } @@ -930,13 +890,11 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S bool weighted = attachment->_bones.size() > 0; Vector &vertices = attachment->_vertices; - size_t deformLength = weighted ? vertices.size() / 3 * 2 - : vertices.size(); + size_t deformLength = weighted ? vertices.size() / 3 * 2 : vertices.size(); size_t frameCount = (size_t)readVarint(input, true); DeformTimeline *timeline = new(__FILE__, __LINE__) DeformTimeline(frameCount); - timeline->_slotIndex = slotIndex; timeline->_attachment = attachment; @@ -947,9 +905,8 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S if (end == 0) { if (weighted) { deform.setSize(deformLength, 0); - for (size_t iiii = 0; iiii < deformLength; ++iiii) { + for (size_t iiii = 0; iiii < deformLength; ++iiii) deform[iiii] = 0; - } } else { deform.clearAndAddAll(vertices); } @@ -958,26 +915,21 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S size_t start = (size_t)readVarint(input, true); end += start; if (scale == 1) { - for (size_t v = start; v < end; ++v) { + for (size_t v = start; v < end; ++v) deform[v] = readFloat(input); - } } else { - for (size_t v = start; v < end; ++v) { + for (size_t v = start; v < end; ++v) deform[v] = readFloat(input) * scale; - } } if (!weighted) { - for (size_t v = 0, vn = deform.size(); v < vn; ++v) { + for (size_t v = 0, vn = deform.size(); v < vn; ++v) deform[v] += vertices[v]; - } } } timeline->setFrame(frameIndex, time, deform); - if (frameIndex < frameCount - 1) { - readCurve(input, frameIndex, timeline); - } + if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline); } timelines.add(timeline); @@ -998,9 +950,8 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S Vector drawOrder; drawOrder.setSize(slotCount, 0); - for (int ii = (int)slotCount - 1; ii >= 0; --ii) { + for (int ii = (int)slotCount - 1; ii >= 0; --ii) drawOrder[ii] = -1; - } Vector unchanged; unchanged.setSize(slotCount - offsetCount, 0); @@ -1008,9 +959,8 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S for (size_t ii = 0; ii < offsetCount; ++ii) { size_t slotIndex = (size_t)readVarint(input, true); // Collect unchanged items. - while (originalIndex != slotIndex) { + while (originalIndex != slotIndex) unchanged[unchangedIndex++] = originalIndex++; - } // Set changed items. size_t index = originalIndex; drawOrder[index + (size_t)readVarint(input, true)] = originalIndex++; @@ -1022,11 +972,8 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S } // Fill in unchanged items. - for (int ii = (int)slotCount - 1; ii >= 0; --ii) { - if (drawOrder[ii] == -1) { - drawOrder[ii] = unchanged[--unchangedIndex]; - } - } + for (int ii = (int)slotCount - 1; ii >= 0; --ii) + if (drawOrder[ii] == -1) drawOrder[ii] = unchanged[--unchangedIndex]; timeline->setFrame(i, time, drawOrder); } timelines.add(timeline); @@ -1048,9 +995,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S bool freeString = readBoolean(input); const char *event_stringValue = freeString ? readString(input) : eventData->_stringValue.buffer(); event->_stringValue = String(event_stringValue); - if (freeString) { - SpineExtension::free(event_stringValue, __FILE__, __LINE__); - } + if (freeString) SpineExtension::free(event_stringValue, __FILE__, __LINE__); if (!eventData->_audioPath.isEmpty()) { event->_volume = readFloat(input); @@ -1068,17 +1013,17 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S void SkeletonBinary::readCurve(DataInput *input, int frameIndex, CurveTimeline *timeline) { switch (readByte(input)) { - case CURVE_STEPPED: { - timeline->setStepped(frameIndex); - break; - } - case CURVE_BEZIER: { - float cx1 = readFloat(input); - float cy1 = readFloat(input); - float cx2 = readFloat(input); - float cy2 = readFloat(input); - timeline->setCurve(frameIndex, cx1, cy1, cx2, cy2); - break; - } + case CURVE_STEPPED: { + timeline->setStepped(frameIndex); + break; + } + case CURVE_BEZIER: { + float cx1 = readFloat(input); + float cy1 = readFloat(input); + float cx2 = readFloat(input); + float cy2 = readFloat(input); + timeline->setCurve(frameIndex, cx1, cy1, cx2, cy2); + break; + } } } diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp index 5ca383e5a..a01547bee 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp @@ -60,9 +60,7 @@ void SkeletonBounds::update(Skeleton &skeleton, bool updateAabb) { if (!slot->getBone().isActive()) continue; Attachment *attachment = slot->getAttachment(); - if (attachment == NULL || !attachment->getRTTI().instanceOf(BoundingBoxAttachment::rtti)) { - continue; - } + if (attachment == NULL || !attachment->getRTTI().instanceOf(BoundingBoxAttachment::rtti)) continue; BoundingBoxAttachment *boundingBox = static_cast(attachment); _boundingBoxes.add(boundingBox); @@ -71,9 +69,8 @@ void SkeletonBounds::update(Skeleton &skeleton, bool updateAabb) { if (poolCount > 0) { polygonP = _polygonPool[poolCount - 1]; _polygonPool.removeAt(poolCount - 1); - } else { + } else polygonP = new(__FILE__, __LINE__) Polygon(); - } _polygons.add(polygonP); @@ -87,9 +84,9 @@ void SkeletonBounds::update(Skeleton &skeleton, bool updateAabb) { boundingBox->computeWorldVertices(*slot, polygon._vertices); } - if (updateAabb) { + if (updateAabb) aabbCompute(); - } else { + else { _minX = std::numeric_limits::min(); _minY = std::numeric_limits::min(); _maxX = std::numeric_limits::max(); @@ -114,21 +111,13 @@ bool SkeletonBounds::aabbintersectsSegment(float x1, float y1, float x2, float y float m = (y2 - y1) / (x2 - x1); float y = m * (minX - x1) + y1; - if (y > minY && y < maxY) { - return true; - } + if (y > minY && y < maxY) return true; y = m * (maxX - x1) + y1; - if (y > minY && y < maxY) { - return true; - } + if (y > minY && y < maxY) return true; float x = (minY - y1) / m + x1; - if (x > minX && x < maxX) { - return true; - } + if (x > minX && x < maxX) return true; x = (maxY - y1) / m + x1; - if (x > minX && x < maxX) { - return true; - } + if (x > minX && x < maxX) return true; return false; } @@ -157,21 +146,14 @@ bool SkeletonBounds::containsPoint(Polygon *polygon, float x, float y) { } BoundingBoxAttachment *SkeletonBounds::containsPoint(float x, float y) { - for (size_t i = 0, n = _polygons.size(); i < n; ++i) { - if (containsPoint(_polygons[i], x, y)) { - return _boundingBoxes[i]; - } - } - + for (size_t i = 0, n = _polygons.size(); i < n; ++i) + if (containsPoint(_polygons[i], x, y)) return _boundingBoxes[i]; return NULL; } BoundingBoxAttachment *SkeletonBounds::intersectsSegment(float x1, float y1, float x2, float y2) { - for (size_t i = 0, n = _polygons.size(); i < n; ++i) { - if (intersectsSegment(_polygons[i], x1, y1, x2, y2)) { - return _boundingBoxes[i]; - } - } + for (size_t i = 0, n = _polygons.size(); i < n; ++i) + if (intersectsSegment(_polygons[i], x1, y1, x2, y2)) return _boundingBoxes[i]; return NULL; } @@ -203,7 +185,6 @@ bool SkeletonBounds::intersectsSegment(Polygon *polygon, float x1, float y1, flo spine::Polygon *SkeletonBounds::getPolygon(BoundingBoxAttachment *attachment) { int index = _boundingBoxes.indexOf(attachment); - return index == -1 ? NULL : _polygons[index]; } diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp index d6cd1ad2c..f9363b143 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp @@ -76,9 +76,7 @@ void SkeletonClipping::clipEnd(Slot &slot) { } void SkeletonClipping::clipEnd() { - if (_clipAttachment == NULL) { - return; - } + if (_clipAttachment == NULL) return; _clipAttachment = NULL; _clippingPolygons = NULL; @@ -93,7 +91,8 @@ void SkeletonClipping::clipTriangles(Vector &vertices, Vector &clipOutput = _clipOutput; Vector &clippedVertices = _clippedVertices; Vector &clippedTriangles = _clippedTriangles; @@ -124,9 +123,7 @@ void SkeletonClipping::clipTriangles(float *vertices, unsigned short *triangles, size_t s = clippedVertices.size(); if (clip(x1, y1, x2, y2, x3, y3, &(*polygons[p]), &clipOutput)) { size_t clipOutputLength = clipOutput.size(); - if (clipOutputLength == 0) { - continue; - } + if (clipOutputLength == 0) continue; float d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1; float d = 1 / (d0 * d2 + d1 * (y1 - y3)); @@ -203,7 +200,8 @@ Vector &SkeletonClipping::getClippedUVs() { } bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector *clippingArea, - Vector *output) { + Vector *output +) { Vector *originalOutput = output; bool clipped = false; @@ -212,9 +210,8 @@ bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, fl if (clippingArea->size() % 4 >= 2) { input = output; output = &_scratch; - } else { + } else input = &_scratch; - } input->clear(); input->add(x1); @@ -296,12 +293,10 @@ bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, fl if (originalOutput != output) { originalOutput->clear(); - for (size_t i = 0, n = output->size() - 2; i < n; ++i) { + for (size_t i = 0, n = output->size() - 2; i < n; ++i) originalOutput->add((*output)[i]); - } - } else { + } else originalOutput->setSize(originalOutput->size() - 2, 0); - } return clipped; } @@ -309,8 +304,8 @@ bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, fl void SkeletonClipping::makeClockwise(Vector &polygon) { size_t verticeslength = polygon.size(); - float area = - polygon[verticeslength - 2] * polygon[1] - polygon[0] * polygon[verticeslength - 1], p1x, p1y, p2x, p2y; + float area = polygon[verticeslength - 2] * polygon[1] - polygon[0] * polygon[verticeslength - 1]; + float p1x, p1y, p2x, p2y; for (size_t i = 0, n = verticeslength - 3; i < n; i += 2) { p1x = polygon[i]; @@ -320,9 +315,7 @@ void SkeletonClipping::makeClockwise(Vector &polygon) { area += p1x * p2y - p2x * p1y; } - if (area < 0) { - return; - } + if (area < 0) return; for (size_t i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) { float x = polygon[i], y = polygon[i + 1]; diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp index dcc472ba0..5cc9b76a6 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp @@ -81,20 +81,19 @@ using namespace spine; SkeletonJson::SkeletonJson(Atlas *atlas) : _attachmentLoader(new(__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), - _scale(1), _ownsLoader(true) { -} + _scale(1), _ownsLoader(true) +{} SkeletonJson::SkeletonJson(AttachmentLoader *attachmentLoader) : _attachmentLoader(attachmentLoader), _scale(1), - _ownsLoader(false) { + _ownsLoader(false) +{ assert(_attachmentLoader != NULL); } SkeletonJson::~SkeletonJson() { ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); - if (_ownsLoader) { - delete _attachmentLoader; - } + if (_ownsLoader) delete _attachmentLoader; } SkeletonData *SkeletonJson::readSkeletonDataFile(const String &path) { @@ -174,21 +173,11 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { data->_shearY = Json::getFloat(boneMap, "shearY", 0); transformMode = Json::getString(boneMap, "transform", "normal"); data->_transformMode = TransformMode_Normal; - if (strcmp(transformMode, "normal") == 0) { - data->_transformMode = TransformMode_Normal; - } - if (strcmp(transformMode, "onlyTranslation") == 0) { - data->_transformMode = TransformMode_OnlyTranslation; - } - if (strcmp(transformMode, "noRotationOrReflection") == 0) { - data->_transformMode = TransformMode_NoRotationOrReflection; - } - if (strcmp(transformMode, "noScale") == 0) { - data->_transformMode = TransformMode_NoScale; - } - if (strcmp(transformMode, "noScaleOrReflection") == 0) { - data->_transformMode = TransformMode_NoScaleOrReflection; - } + if (strcmp(transformMode, "normal") == 0) data->_transformMode = TransformMode_Normal; + else if (strcmp(transformMode, "onlyTranslation") == 0) data->_transformMode = TransformMode_OnlyTranslation; + else if (strcmp(transformMode, "noRotationOrReflection") == 0) data->_transformMode = TransformMode_NoRotationOrReflection; + else if (strcmp(transformMode, "noScale") == 0) data->_transformMode = TransformMode_NoScale; + else if (strcmp(transformMode, "noScaleOrReflection") == 0) data->_transformMode = TransformMode_NoScaleOrReflection; data->_skinRequired = Json::getBoolean(boneMap, "skin", false); skeletonData->_bones[i] = data; @@ -237,19 +226,13 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { } item = Json::getItem(slotMap, "attachment"); - if (item) { - data->setAttachmentName(item->_valueString); - } + if (item) data->setAttachmentName(item->_valueString); item = Json::getItem(slotMap, "blend"); if (item) { - if (strcmp(item->_valueString, "additive") == 0) { - data->_blendMode = BlendMode_Additive; - } else if (strcmp(item->_valueString, "multiply") == 0) { - data->_blendMode = BlendMode_Multiply; - } else if (strcmp(item->_valueString, "screen") == 0) { - data->_blendMode = BlendMode_Screen; - } + if (strcmp(item->_valueString, "additive") == 0) data->_blendMode = BlendMode_Additive; + else if (strcmp(item->_valueString, "multiply") == 0) data->_blendMode = BlendMode_Multiply; + else if (strcmp(item->_valueString, "screen") == 0) data->_blendMode = BlendMode_Screen; } skeletonData->_slots[i] = data; @@ -265,9 +248,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { for (constraintMap = ik->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { const char *targetName; - IkConstraintData *data = new(__FILE__, __LINE__) IkConstraintData( - Json::getString(constraintMap, "name", 0)); - + IkConstraintData *data = new(__FILE__, __LINE__) IkConstraintData(Json::getString(constraintMap, "name", 0)); data->setOrder(Json::getInt(constraintMap, "order", 0)); data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); @@ -311,9 +292,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { for (constraintMap = transform->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { const char *name; - TransformConstraintData *data = new(__FILE__, __LINE__) TransformConstraintData( - Json::getString(constraintMap, "name", 0)); - + TransformConstraintData *data = new(__FILE__, __LINE__) TransformConstraintData(Json::getString(constraintMap, "name", 0)); data->setOrder(Json::getInt(constraintMap, "order", 0)); data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); @@ -365,9 +344,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { const char *name; const char *item; - PathConstraintData *data = new(__FILE__, __LINE__) PathConstraintData( - Json::getString(constraintMap, "name", 0)); - + PathConstraintData *data = new(__FILE__, __LINE__) PathConstraintData(Json::getString(constraintMap, "name", 0)); data->setOrder(Json::getInt(constraintMap, "order", 0)); data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); @@ -399,32 +376,20 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { } item = Json::getString(constraintMap, "spacingMode", "length"); - if (strcmp(item, "length") == 0) { - data->_spacingMode = SpacingMode_Length; - } else if (strcmp(item, "fixed") == 0) { - data->_spacingMode = SpacingMode_Fixed; - } else if (strcmp(item, "percent") == 0) { - data->_spacingMode = SpacingMode_Percent; - } + if (strcmp(item, "length") == 0) data->_spacingMode = SpacingMode_Length; + else if (strcmp(item, "fixed") == 0) data->_spacingMode = SpacingMode_Fixed; + else if (strcmp(item, "percent") == 0) data->_spacingMode = SpacingMode_Percent; item = Json::getString(constraintMap, "rotateMode", "tangent"); - if (strcmp(item, "tangent") == 0) { - data->_rotateMode = RotateMode_Tangent; - } else if (strcmp(item, "chain") == 0) { - data->_rotateMode = RotateMode_Chain; - } else if (strcmp(item, "chainScale") == 0) { - data->_rotateMode = RotateMode_ChainScale; - } + if (strcmp(item, "tangent") == 0) data->_rotateMode = RotateMode_Tangent; + else if (strcmp(item, "chain") == 0) data->_rotateMode = RotateMode_Chain; + else if (strcmp(item, "chainScale") == 0) data->_rotateMode = RotateMode_ChainScale; data->_offsetRotation = Json::getFloat(constraintMap, "rotation", 0); data->_position = Json::getFloat(constraintMap, "position", 0); - if (data->_positionMode == PositionMode_Fixed) { - data->_position *= _scale; - } + if (data->_positionMode == PositionMode_Fixed) data->_position *= _scale; data->_spacing = Json::getFloat(constraintMap, "spacing", 0); - if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) { - data->_spacing *= _scale; - } + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) data->_spacing *= _scale; data->_rotateMix = Json::getFloat(constraintMap, "rotateMix", 1); data->_translateMix = Json::getFloat(constraintMap, "translateMix", 1); @@ -516,21 +481,14 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { const char *typeString = Json::getString(attachmentMap, "type", "region"); AttachmentType type; - if (strcmp(typeString, "region") == 0) { - type = AttachmentType_Region; - } else if (strcmp(typeString, "mesh") == 0) { - type = AttachmentType_Mesh; - } else if (strcmp(typeString, "linkedmesh") == 0) { - type = AttachmentType_Linkedmesh; - } else if (strcmp(typeString, "boundingbox") == 0) { - type = AttachmentType_Boundingbox; - } else if (strcmp(typeString, "path") == 0) { - type = AttachmentType_Path; - } else if (strcmp(typeString, "clipping") == 0) { - type = AttachmentType_Clipping; - } else if (strcmp(typeString, "point") == 0) { - type = AttachmentType_Point; - }else { + if (strcmp(typeString, "region") == 0) type = AttachmentType_Region; + else if (strcmp(typeString, "mesh") == 0) type = AttachmentType_Mesh; + else if (strcmp(typeString, "linkedmesh") == 0) type = AttachmentType_Linkedmesh; + else if (strcmp(typeString, "boundingbox") == 0) type = AttachmentType_Boundingbox; + else if (strcmp(typeString, "path") == 0) type = AttachmentType_Path; + else if (strcmp(typeString, "clipping") == 0) type = AttachmentType_Clipping; + else if (strcmp(typeString, "point") == 0) type = AttachmentType_Point; + else { delete skeletonData; setError(root, "Unknown attachment type: ", typeString); return NULL; @@ -598,17 +556,15 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { entry = Json::getItem(attachmentMap, "triangles"); mesh->_triangles.ensureCapacity(entry->_size); mesh->_triangles.setSize(entry->_size, 0); - for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) { + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) mesh->_triangles[ii] = (unsigned short) entry->_valueInt; - } entry = Json::getItem(attachmentMap, "uvs"); verticesLength = entry->_size; mesh->_regionUVs.ensureCapacity(verticesLength); mesh->_regionUVs.setSize(verticesLength, 0); - for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) { + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) mesh->_regionUVs[ii] = entry->_valueFloat; - } readVertices(attachmentMap, mesh, verticesLength); @@ -620,19 +576,15 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { if (entry) { mesh->_edges.ensureCapacity(entry->_size); mesh->_edges.setSize(entry->_size, 0); - for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) { + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) mesh->_edges[ii] = entry->_valueInt; - } } _attachmentLoader->configureAttachment(mesh); } else { bool inheritDeform = Json::getInt(attachmentMap, "deform", 1) ? true : false; LinkedMesh *linkedMesh = new(__FILE__, __LINE__) LinkedMesh(mesh, - String(Json::getString( - attachmentMap, - "skin", 0)), - slot->getIndex(), - String(entry->_valueString), inheritDeform); + String(Json::getString(attachmentMap, "skin", 0)), slot->getIndex(), String(entry->_valueString), + inheritDeform); _linkedMeshes.add(linkedMesh); } break; @@ -662,9 +614,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { pathAttatchment->_lengths.setSize(vertexCount / 3, 0); curves = Json::getItem(attachmentMap, "lengths"); - for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii) { + for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii) pathAttatchment->_lengths[ii] = curves->_valueFloat * _scale; - } _attachmentLoader->configureAttachment(attachment); break; } @@ -686,9 +637,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { int vertexCount = 0; const char *end = Json::getString(attachmentMap, "end", 0); - if (end) { - clip->_endSlot = skeletonData->findSlot(end); - } + if (end) clip->_endSlot = skeletonData->findSlot(end); vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1; readVertices(attachmentMap, clip, vertexCount); _attachmentLoader->configureAttachment(attachment); @@ -706,8 +655,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { int n = _linkedMeshes.size(); for (i = 0; i < n; ++i) { LinkedMesh *linkedMesh = _linkedMeshes[i]; - Skin *skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin( - linkedMesh->_skin); + Skin *skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin); if (skin == NULL) { delete skeletonData; setError(root, "Skin not found: ", linkedMesh->_skin.buffer()); @@ -778,9 +726,7 @@ float SkeletonJson::toColor(const char *value, size_t index) { char *error; int color; - if (index >= strlen(value) / 2) { - return -1; - } + if (index >= strlen(value) / 2) return -1; value += index * 2; @@ -788,21 +734,17 @@ float SkeletonJson::toColor(const char *value, size_t index) { digits[1] = *(value + 1); digits[2] = '\0'; color = (int) strtoul(digits, &error, 16); - if (*error != 0) { - return -1; - } + if (*error != 0) return -1; return color / (float) 255; } void SkeletonJson::readCurve(Json *frame, CurveTimeline *timeline, size_t frameIndex) { Json *curve = Json::getItem(frame, "curve"); - if (!curve) { - return; - } - if (curve->_type == Json::JSON_STRING && strcmp(curve->_valueString, "stepped") == 0) { + if (!curve) return; + if (curve->_type == Json::JSON_STRING && strcmp(curve->_valueString, "stepped") == 0) timeline->setStepped(frameIndex); - } else { + else { float c1 = Json::getFloat(frame, "curve", 0); float c2 = Json::getFloat(frame, "c2", 0); float c3 = Json::getFloat(frame, "c3", 1); @@ -828,38 +770,27 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { Json *drawOrder = Json::getItem(root, "drawOrder"); Json *events = Json::getItem(root, "events"); Json *boneMap, *slotMap, *constraintMap; - if (!drawOrder) { - drawOrder = Json::getItem(root, "draworder"); - } + if (!drawOrder) drawOrder = Json::getItem(root, "draworder"); - for (boneMap = bones ? bones->_child : NULL; boneMap; boneMap = boneMap->_next) { + for (boneMap = bones ? bones->_child : NULL; boneMap; boneMap = boneMap->_next) timelinesCount += boneMap->_size; - } - for (slotMap = slots ? slots->_child : NULL; slotMap; slotMap = slotMap->_next) { + for (slotMap = slots ? slots->_child : NULL; slotMap; slotMap = slotMap->_next) timelinesCount += slotMap->_size; - } timelinesCount += ik ? ik->_size : 0; timelinesCount += transform ? transform->_size : 0; - for (constraintMap = paths ? paths->_child : NULL; constraintMap; constraintMap = constraintMap->_next) { + for (constraintMap = paths ? paths->_child : NULL; constraintMap; constraintMap = constraintMap->_next) timelinesCount += constraintMap->_size; - } - for (constraintMap = deform ? deform->_child : NULL; constraintMap; constraintMap = constraintMap->_next) { - for (slotMap = constraintMap->_child; slotMap; slotMap = slotMap->_next) { + for (constraintMap = deform ? deform->_child : NULL; constraintMap; constraintMap = constraintMap->_next) + for (slotMap = constraintMap->_child; slotMap; slotMap = slotMap->_next) timelinesCount += slotMap->_size; - } - } - if (drawOrder) { - ++timelinesCount; - } + if (drawOrder) ++timelinesCount; - if (events) { - ++timelinesCount; - } + if (events) ++timelinesCount; /** Slot timelines. */ for (slotMap = slots ? slots->_child : 0; slotMap; slotMap = slotMap->_next) { @@ -895,13 +826,12 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { const char *s = Json::getString(valueMap, "color", 0); timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), - toColor(s, 2), toColor(s, 3)); + toColor(s, 2), toColor(s, 3)); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); timelinesCount++; - duration = MathUtil::max(duration, - timeline->_frames[(timelineMap->_size - 1) * ColorTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * ColorTimeline::ENTRIES]); } else if (strcmp(timelineMap->_name, "twoColor") == 0) { TwoColorTimeline *timeline = new(__FILE__, __LINE__) TwoColorTimeline(timelineMap->_size); @@ -912,8 +842,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { const char *s = Json::getString(valueMap, "light", 0); const char *ds = Json::getString(valueMap, "dark", 0); timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), - toColor(s, 2), - toColor(s, 3), toColor(ds, 0), toColor(ds, 1), toColor(ds, 2)); + toColor(s, 2), toColor(s, 3), toColor(ds, 0), toColor(ds, 1), toColor(ds, 2)); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); @@ -946,14 +875,12 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { timeline->_boneIndex = boneIndex; for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { - timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), - Json::getFloat(valueMap, "angle", 0)); + timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "angle", 0)); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); timelinesCount++; - duration = MathUtil::max(duration, - timeline->_frames[(timelineMap->_size - 1) * RotateTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * RotateTimeline::ENTRIES]); } else { int isScale = strcmp(timelineMap->_name, "scale") == 0; int isTranslate = strcmp(timelineMap->_name, "translate") == 0; @@ -974,15 +901,14 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), - Json::getFloat(valueMap, "x", defaultValue) * timelineScale, - Json::getFloat(valueMap, "y", defaultValue) * timelineScale); + Json::getFloat(valueMap, "x", defaultValue) * timelineScale, + Json::getFloat(valueMap, "y", defaultValue) * timelineScale); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); timelinesCount++; - duration = MathUtil::max(duration, - timeline->_frames[(timelineMap->_size - 1) * TranslateTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * TranslateTimeline::ENTRIES]); } else { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Invalid timeline type for a bone: ", timelineMap->_name); @@ -1004,21 +930,20 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { } } for (valueMap = constraintMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { - timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "mix", 1), Json::getFloat(valueMap, "softness", 0) * _scale, - Json::getInt(valueMap, "bendPositive", 1) ? 1 : -1, Json::getInt(valueMap, "compress", 0) ? true : false, Json::getInt(valueMap, "stretch", 0) ? true : false); + timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "mix", 1), + Json::getFloat(valueMap, "softness", 0) * _scale, Json::getInt(valueMap, "bendPositive", 1) ? 1 : -1, + Json::getInt(valueMap, "compress", 0) ? true : false, Json::getInt(valueMap, "stretch", 0) ? true : false); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); timelinesCount++; - duration = MathUtil::max(duration, - timeline->_frames[(constraintMap->_size - 1) * IkConstraintTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(constraintMap->_size - 1) * IkConstraintTimeline::ENTRIES]); } /** Transform constraint timelines. */ for (constraintMap = transform ? transform->_child : 0; constraintMap; constraintMap = constraintMap->_next) { TransformConstraintData *constraint = skeletonData->findTransformConstraint(constraintMap->_name); - TransformConstraintTimeline *timeline = new(__FILE__, __LINE__) TransformConstraintTimeline( - constraintMap->_size); + TransformConstraintTimeline *timeline = new(__FILE__, __LINE__) TransformConstraintTimeline(constraintMap->_size); for (frameIndex = 0; frameIndex < skeletonData->_transformConstraints.size(); ++frameIndex) { if (constraint == skeletonData->_transformConstraints[frameIndex]) { @@ -1028,14 +953,13 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { } for (valueMap = constraintMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), - Json::getFloat(valueMap, "rotateMix", 1), Json::getFloat(valueMap, "translateMix", 1), - Json::getFloat(valueMap, "scaleMix", 1), Json::getFloat(valueMap, "shearMix", 1)); + Json::getFloat(valueMap, "rotateMix", 1), Json::getFloat(valueMap, "translateMix", 1), + Json::getFloat(valueMap, "scaleMix", 1), Json::getFloat(valueMap, "shearMix", 1)); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); timelinesCount++; - duration = MathUtil::max(duration, - timeline->_frames[(constraintMap->_size - 1) * TransformConstraintTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(constraintMap->_size - 1) * TransformConstraintTimeline::ENTRIES]); } /** Path constraint timelines. */ @@ -1079,7 +1003,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { timeline->_pathConstraintIndex = constraintIndex; for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), - Json::getFloat(valueMap, timelineName, 0) * timelineScale); + Json::getFloat(valueMap, timelineName, 0) * timelineScale); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); @@ -1087,19 +1011,17 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintPositionTimeline::ENTRIES]); } else if (strcmp(timelineName, "mix") == 0) { - PathConstraintMixTimeline *timeline = new(__FILE__, __LINE__) PathConstraintMixTimeline( - timelineMap->_size); + PathConstraintMixTimeline *timeline = new(__FILE__, __LINE__) PathConstraintMixTimeline(timelineMap->_size); timeline->_pathConstraintIndex = constraintIndex; for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), - Json::getFloat(valueMap, "rotateMix", 1), - Json::getFloat(valueMap, "translateMix", 1)); + Json::getFloat(valueMap, "rotateMix", 1), + Json::getFloat(valueMap, "translateMix", 1)); readCurve(valueMap, timeline, frameIndex); } timelines.add(timeline); timelinesCount++; - duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * - PathConstraintMixTimeline::ENTRIES]); + duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintMixTimeline::ENTRIES]); } } } @@ -1190,9 +1112,8 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { drawOrder2.ensureCapacity(skeletonData->_slots.size()); drawOrder2.setSize(skeletonData->_slots.size(), 0); - for (ii = (int)skeletonData->_slots.size() - 1; ii >= 0; --ii) { + for (ii = (int)skeletonData->_slots.size() - 1; ii >= 0; --ii) drawOrder2[ii] = -1; - } for (offsetMap = offsets->_child; offsetMap; offsetMap = offsetMap->_next) { int slotIndex = skeletonData->findSlotIndex(Json::getString(offsetMap, "slot", 0)); @@ -1202,23 +1123,18 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { return NULL; } /* Collect unchanged items. */ - while (originalIndex != (size_t)slotIndex) { + while (originalIndex != (size_t)slotIndex) unchanged[unchangedIndex++] = originalIndex++; - } /* Set changed items. */ drawOrder2[originalIndex + Json::getInt(offsetMap, "offset", 0)] = originalIndex; originalIndex++; } /* Collect remaining unchanged items. */ - while (originalIndex < skeletonData->_slots.size()) { + while (originalIndex < skeletonData->_slots.size()) unchanged[unchangedIndex++] = originalIndex++; - } /* Fill in unchanged items. */ - for (ii = (int)skeletonData->_slots.size() - 1; ii >= 0; ii--) { - if (drawOrder2[ii] == -1) { - drawOrder2[ii] = unchanged[--unchangedIndex]; - } - } + for (ii = (int)skeletonData->_slots.size() - 1; ii >= 0; ii--) + if (drawOrder2[ii] == -1) drawOrder2[ii] = unchanged[--unchangedIndex]; } timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), drawOrder2); } @@ -1269,15 +1185,13 @@ void SkeletonJson::readVertices(Json *attachmentMap, VertexAttachment *attachmen entrySize = entry->_size; vertices.ensureCapacity(entrySize); vertices.setSize(entrySize, 0); - for (entry = entry->_child, i = 0; entry; entry = entry->_next, ++i) { + for (entry = entry->_child, i = 0; entry; entry = entry->_next, ++i) vertices[i] = entry->_valueFloat; - } if (verticesLength == entrySize) { if (_scale != 1) { - for (i = 0; i < entrySize; ++i) { + for (i = 0; i < entrySize; ++i) vertices[i] *= _scale; - } } attachment->getVertices().clearAndAddAll(vertices); @@ -1305,6 +1219,5 @@ void SkeletonJson::readVertices(Json *attachmentMap, VertexAttachment *attachmen void SkeletonJson::setError(Json *root, const String &value1, const String &value2) { _error = String(value1).append(value2); - delete root; } diff --git a/spine-cpp/spine-cpp/src/spine/Skin.cpp b/spine-cpp/spine-cpp/src/spine/Skin.cpp index aa8548040..17cdc6222 100644 --- a/spine-cpp/spine-cpp/src/spine/Skin.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skin.cpp @@ -130,9 +130,7 @@ void Skin::findAttachmentsForSlot(size_t slotIndex, Vector &attach Skin::AttachmentMap::Entries entries = _attachments.getEntries(); while (entries.hasNext()) { Skin::AttachmentMap::Entry &entry = entries.next(); - if (entry._slotIndex == slotIndex) { - attachments.add(entry._attachment); - } + if (entry._slotIndex == slotIndex) attachments.add(entry._attachment); } } @@ -154,9 +152,7 @@ void Skin::attachAll(Skeleton &skeleton, Skin &oldSkin) { if (slot->getAttachment() == entry._attachment) { Attachment *attachment = getAttachment(slotIndex, entry._name); - if (attachment) { - slot->setAttachment(attachment); - } + if (attachment) slot->setAttachment(attachment); } } } @@ -185,11 +181,10 @@ void Skin::copySkin(Skin* other) { AttachmentMap::Entries entries = other->getAttachments(); while(entries.hasNext()) { AttachmentMap::Entry& entry = entries.next(); - if (entry._attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + if (entry._attachment->getRTTI().isExactly(MeshAttachment::rtti)) setAttachment(entry._slotIndex, entry._name, static_cast(entry._attachment)->newLinkedMesh()); - } else { + else setAttachment(entry._slotIndex, entry._name, entry._attachment->copy()); - } } } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp index 79a493dbb..69a2a3d9e 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp @@ -44,22 +44,22 @@ using namespace spine; RTTI_IMPL(TransformConstraint, Updatable) TransformConstraint::TransformConstraint(TransformConstraintData &data, Skeleton &skeleton) : Updatable(), - _data(data), - _target(skeleton.findBone( - data.getTarget()->getName())), - _rotateMix( - data.getRotateMix()), - _translateMix( - data.getTranslateMix()), - _scaleMix( - data.getScaleMix()), - _shearMix( - data.getShearMix()), - _active(false) { + _data(data), + _target(skeleton.findBone( + data.getTarget()->getName())), + _rotateMix( + data.getRotateMix()), + _translateMix( + data.getTranslateMix()), + _scaleMix( + data.getScaleMix()), + _shearMix( + data.getShearMix()), + _active(false) +{ _bones.ensureCapacity(_data.getBones().size()); for (size_t i = 0; i < _data.getBones().size(); ++i) { BoneData *boneData = _data.getBones()[i]; - _bones.add(skeleton.findBone(boneData->getName())); } } @@ -70,17 +70,15 @@ void TransformConstraint::apply() { void TransformConstraint::update() { if (_data.isLocal()) { - if (_data.isRelative()) { + if (_data.isRelative()) applyRelativeLocal(); - } else { + else applyAbsoluteLocal(); - } } else { - if (_data.isRelative()) { + if (_data.isRelative()) applyRelativeWorld(); - } else { + else applyAbsoluteWorld(); - } } } @@ -152,11 +150,10 @@ void TransformConstraint::applyAbsoluteWorld() { if (rotateMix != 0) { float a = bone._a, b = bone._b, c = bone._c, d = bone._d; float r = MathUtil::atan2(tc, ta) - MathUtil::atan2(c, a) + offsetRotation; - if (r > MathUtil::Pi) { + if (r > MathUtil::Pi) r -= MathUtil::Pi_2; - } else if (r < -MathUtil::Pi) { + else if (r < -MathUtil::Pi) r += MathUtil::Pi_2; - } r *= rotateMix; float cos = MathUtil::cos(r), sin = MathUtil::sin(r); @@ -178,16 +175,12 @@ void TransformConstraint::applyAbsoluteWorld() { if (scaleMix > 0) { float s = MathUtil::sqrt(bone._a * bone._a + bone._c * bone._c); - if (s > 0.00001f) { - s = (s + (MathUtil::sqrt(ta * ta + tc * tc) - s + _data._offsetScaleX) * scaleMix) / s; - } + if (s > 0.00001f) s = (s + (MathUtil::sqrt(ta * ta + tc * tc) - s + _data._offsetScaleX) * scaleMix) / s; bone._a *= s; bone._c *= s; s = MathUtil::sqrt(bone._b * bone._b + bone._d * bone._d); - if (s > 0.00001f) { - s = (s + (MathUtil::sqrt(tb * tb + td * td) - s + _data._offsetScaleY) * scaleMix) / s; - } + if (s > 0.00001f) s = (s + (MathUtil::sqrt(tb * tb + td * td) - s + _data._offsetScaleY) * scaleMix) / s; bone._b *= s; bone._d *= s; modified = true; @@ -197,11 +190,10 @@ void TransformConstraint::applyAbsoluteWorld() { float b = bone._b, d = bone._d; float by = MathUtil::atan2(d, b); float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta) - (by - MathUtil::atan2(bone._c, bone._a)); - if (r > MathUtil::Pi) { + if (r > MathUtil::Pi) r -= MathUtil::Pi_2; - } else if (r < -MathUtil::Pi) { + else if (r < -MathUtil::Pi) r += MathUtil::Pi_2; - } r = by + (r + offsetShearY) * shearMix; float s = MathUtil::sqrt(b * b + d * d); @@ -210,9 +202,7 @@ void TransformConstraint::applyAbsoluteWorld() { modified = true; } - if (modified) { - bone._appliedValid = false; - } + if (modified) bone._appliedValid = false; } } @@ -231,11 +221,10 @@ void TransformConstraint::applyRelativeWorld() { if (rotateMix != 0) { float a = bone._a, b = bone._b, c = bone._c, d = bone._d; float r = MathUtil::atan2(tc, ta) + offsetRotation; - if (r > MathUtil::Pi) { + if (r > MathUtil::Pi) r -= MathUtil::Pi_2; - } else if (r < -MathUtil::Pi) { + else if (r < -MathUtil::Pi) r += MathUtil::Pi_2; - } r *= rotateMix; float cos = MathUtil::cos(r), sin = MathUtil::sin(r); @@ -266,11 +255,10 @@ void TransformConstraint::applyRelativeWorld() { if (shearMix > 0) { float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta); - if (r > MathUtil::Pi) { + if (r > MathUtil::Pi) r -= MathUtil::Pi_2; - } else if (r < -MathUtil::Pi) { + else if (r < -MathUtil::Pi) r += MathUtil::Pi_2; - } float b = bone._b, d = bone._d; r = MathUtil::atan2(d, b) + (r - MathUtil::Pi / 2 + offsetShearY) * shearMix; @@ -280,26 +268,20 @@ void TransformConstraint::applyRelativeWorld() { modified = true; } - if (modified) { - bone._appliedValid = false; - } + if (modified) bone._appliedValid = false; } } void TransformConstraint::applyAbsoluteLocal() { float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix; Bone &target = *_target; - if (!target._appliedValid) { - target.updateAppliedTransform(); - } + if (!target._appliedValid) target.updateAppliedTransform(); for (size_t i = 0; i < _bones.size(); ++i) { Bone *item = _bones[i]; Bone &bone = *item; - if (!bone._appliedValid) { - bone.updateAppliedTransform(); - } + if (!bone._appliedValid) bone.updateAppliedTransform(); float rotation = bone._arotation; if (rotateMix != 0) { @@ -316,13 +298,8 @@ void TransformConstraint::applyAbsoluteLocal() { float scaleX = bone._ascaleX, scaleY = bone._ascaleY; if (scaleMix != 0) { - if (scaleX > 0.00001f) { - scaleX = (scaleX + (target._ascaleX - scaleX + _data._offsetScaleX) * scaleMix) / scaleX; - } - - if (scaleY > 0.00001f) { - scaleY = (scaleY + (target._ascaleY - scaleY + _data._offsetScaleY) * scaleMix) / scaleY; - } + if (scaleX > 0.00001f) scaleX = (scaleX + (target._ascaleX - scaleX + _data._offsetScaleX) * scaleMix) / scaleX; + if (scaleY > 0.00001f) scaleY = (scaleY + (target._ascaleY - scaleY + _data._offsetScaleY) * scaleMix) / scaleY; } float shearY = bone._ashearY; @@ -339,22 +316,16 @@ void TransformConstraint::applyAbsoluteLocal() { void TransformConstraint::applyRelativeLocal() { float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix; Bone &target = *_target; - if (!target._appliedValid) { - target.updateAppliedTransform(); - } + if (!target._appliedValid) target.updateAppliedTransform(); for (size_t i = 0; i < _bones.size(); ++i) { Bone *item = _bones[i]; Bone &bone = *item; - if (!bone._appliedValid) { - bone.updateAppliedTransform(); - } + if (!bone._appliedValid) bone.updateAppliedTransform(); float rotation = bone._arotation; - if (rotateMix != 0) { - rotation += (target._arotation + _data._offsetRotation) * rotateMix; - } + if (rotateMix != 0) rotation += (target._arotation + _data._offsetRotation) * rotateMix; float x = bone._ax, y = bone._ay; if (translateMix != 0) { @@ -364,19 +335,12 @@ void TransformConstraint::applyRelativeLocal() { float scaleX = bone._ascaleX, scaleY = bone._ascaleY; if (scaleMix != 0) { - if (scaleX > 0.00001f) { - scaleX *= ((target._ascaleX - 1 + _data._offsetScaleX) * scaleMix) + 1; - } - - if (scaleY > 0.00001f) { - scaleY *= ((target._ascaleY - 1 + _data._offsetScaleY) * scaleMix) + 1; - } + if (scaleX > 0.00001f) scaleX *= ((target._ascaleX - 1 + _data._offsetScaleX) * scaleMix) + 1; + if (scaleY > 0.00001f) scaleY *= ((target._ascaleY - 1 + _data._offsetScaleY) * scaleMix) + 1; } float shearY = bone._ashearY; - if (shearMix != 0) { - shearY += (target._ashearY + _data._offsetShearY) * shearMix; - } + if (shearMix != 0) shearY += (target._ashearY + _data._offsetShearY) * shearMix; bone.updateWorldTransform(x, y, rotation, scaleX, scaleY, bone._ashearX, shearY); } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp index 147b4bdf5..5d00fc6d6 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp @@ -59,7 +59,8 @@ const int TransformConstraintTimeline::SCALE = 3; const int TransformConstraintTimeline::SHEAR = 4; TransformConstraintTimeline::TransformConstraintTimeline(int frameCount) : CurveTimeline(frameCount), - _transformConstraintIndex(0) { + _transformConstraintIndex(0) +{ _frames.setSize(frameCount * ENTRIES, 0); } @@ -75,20 +76,20 @@ void TransformConstraintTimeline::apply(Skeleton &skeleton, float lastTime, floa if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - constraint._rotateMix = constraint._data._rotateMix; - constraint._translateMix = constraint._data._translateMix; - constraint._scaleMix = constraint._data._scaleMix; - constraint._shearMix = constraint._data._shearMix; - return; - case MixBlend_First: - constraint._rotateMix += (constraint._data._rotateMix - constraint._rotateMix) * alpha; - constraint._translateMix += (constraint._data._translateMix - constraint._translateMix) * alpha; - constraint._scaleMix += (constraint._data._scaleMix - constraint._scaleMix) * alpha; - constraint._shearMix += (constraint._data._shearMix - constraint._shearMix) * alpha; - return; - default: - return; + case MixBlend_Setup: + constraint._rotateMix = constraint._data._rotateMix; + constraint._translateMix = constraint._data._translateMix; + constraint._scaleMix = constraint._data._scaleMix; + constraint._shearMix = constraint._data._shearMix; + return; + case MixBlend_First: + constraint._rotateMix += (constraint._data._rotateMix - constraint._rotateMix) * alpha; + constraint._translateMix += (constraint._data._translateMix - constraint._translateMix) * alpha; + constraint._scaleMix += (constraint._data._scaleMix - constraint._scaleMix) * alpha; + constraint._shearMix += (constraint._data._shearMix - constraint._shearMix) * alpha; + return; + default: + return; } } @@ -109,7 +110,7 @@ void TransformConstraintTimeline::apply(Skeleton &skeleton, float lastTime, floa shear = _frames[frame + PREV_SHEAR]; float frameTime = _frames[frame]; float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); rotate += (_frames[frame + ROTATE] - rotate) * percent; translate += (_frames[frame + TRANSLATE] - translate) * percent; @@ -135,9 +136,9 @@ int TransformConstraintTimeline::getPropertyId() { return ((int) TimelineType_TransformConstraint << 24) + _transformConstraintIndex; } -void -TransformConstraintTimeline::setFrame(size_t frameIndex, float time, float rotateMix, float translateMix, float scaleMix, - float shearMix) { +void TransformConstraintTimeline::setFrame(size_t frameIndex, float time, float rotateMix, float translateMix, float scaleMix, + float shearMix +) { frameIndex *= ENTRIES; _frames[frameIndex] = time; _frames[frameIndex + ROTATE] = rotateMix; diff --git a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp index 1fcfdefff..ae92e6d23 100644 --- a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp @@ -61,7 +61,8 @@ TranslateTimeline::~TranslateTimeline() { } void TranslateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -72,14 +73,14 @@ void TranslateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Ve if (time < _frames[0]) { switch (blend) { - case MixBlend_Setup: - bone._x = bone._data._x; - bone._y = bone._data._y; - return; - case MixBlend_First: - bone._x += (bone._data._x - bone._x) * alpha; - bone._y += (bone._data._y - bone._y) * alpha; - default: {} + case MixBlend_Setup: + bone._x = bone._data._x; + bone._y = bone._data._y; + return; + case MixBlend_First: + bone._x += (bone._data._x - bone._x) * alpha; + bone._y += (bone._data._y - bone._y) * alpha; + default: {} } return; } @@ -96,25 +97,25 @@ void TranslateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Ve y = _frames[frame + PREV_Y]; float frameTime = _frames[frame]; float percent = getCurvePercent(frame / ENTRIES - 1, - 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); + 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime)); x += (_frames[frame + X] - x) * percent; y += (_frames[frame + Y] - y) * percent; } switch (blend) { - case MixBlend_Setup: - bone._x = bone._data._x + x * alpha; - bone._y = bone._data._y + y * alpha; - break; - case MixBlend_First: - case MixBlend_Replace: - bone._x += (bone._data._x + x - bone._x) * alpha; - bone._y += (bone._data._y + y - bone._y) * alpha; - break; - case MixBlend_Add: - bone._x += x * alpha; - bone._y += y * alpha; + case MixBlend_Setup: + bone._x = bone._data._x + x * alpha; + bone._y = bone._data._y + y * alpha; + break; + case MixBlend_First: + case MixBlend_Replace: + bone._x += (bone._data._x + x - bone._x) * alpha; + bone._y += (bone._data._y + y - bone._y) * alpha; + break; + case MixBlend_Add: + bone._x += x * alpha; + bone._y += y * alpha; } } diff --git a/spine-cpp/spine-cpp/src/spine/Triangulator.cpp b/spine-cpp/spine-cpp/src/spine/Triangulator.cpp index e456d454d..5c124a95e 100644 --- a/spine-cpp/spine-cpp/src/spine/Triangulator.cpp +++ b/spine-cpp/spine-cpp/src/spine/Triangulator.cpp @@ -75,9 +75,7 @@ Vector &Triangulator::triangulate(Vector &vertices) { float p2x = vertices[p2], p2y = vertices[p2 + 1]; float p3x = vertices[p3], p3y = vertices[p3 + 1]; for (size_t ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) { - if (!isConcaveArray[ii]) { - continue; - } + if (!isConcaveArray[ii]) continue; int v = indices[ii] << 1; float &vx = vertices[v], vy = vertices[v + 1]; @@ -95,9 +93,7 @@ Vector &Triangulator::triangulate(Vector &vertices) { if (next == 0) { do { - if (!isConcaveArray[i]) { - break; - } + if (!isConcaveArray[i]) break; i--; } while (i > 0); break; @@ -133,15 +129,13 @@ Vector &Triangulator::triangulate(Vector &vertices) { Vector *> &Triangulator::decompose(Vector &vertices, Vector &triangles) { Vector *> &convexPolygons = _convexPolygons; - for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) { + for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) _polygonPool.free(convexPolygons[i]); - } convexPolygons.clear(); Vector *> &convexPolygonsIndices = _convexPolygonsIndices; - for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i) { + for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i) _polygonIndicesPool.free(convexPolygonsIndices[i]); - } convexPolygonsIndices.clear(); Vector *polygonIndices = _polygonIndicesPool.obtain(); @@ -224,16 +218,12 @@ Vector *> &Triangulator::decompose(Vector &vertices, Vector int winding0 = winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); for (size_t ii = 0; ii < n; ++ii) { - if (ii == i) { - continue; - } + if (ii == i) continue; Vector *otherIndicesP = convexPolygonsIndices[ii]; Vector &otherIndices = *otherIndicesP; - if (otherIndices.size() != 3) { - continue; - } + if (otherIndices.size() != 3) continue; int otherFirstIndex = otherIndices[0]; int otherSecondIndex = otherIndices[1]; @@ -244,9 +234,7 @@ Vector *> &Triangulator::decompose(Vector &vertices, Vector float x3 = otherPoly[otherPoly.size() - 2], y3 = otherPoly[otherPoly.size() - 1]; - if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) { - continue; - } + if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) continue; int winding1 = winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); int winding2 = winding(x3, y3, firstX, firstY, secondX, secondY); @@ -285,8 +273,9 @@ bool Triangulator::isConcave(int index, int vertexCount, Vector &vertices int current = indices[index] << 1; int next = indices[(index + 1) % vertexCount] << 1; - return !positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], - vertices[next], vertices[next + 1]); + return !positiveArea(vertices[previous], vertices[previous + 1], + vertices[current], vertices[current + 1], + vertices[next], vertices[next + 1]); } bool Triangulator::positiveArea(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { @@ -295,6 +284,5 @@ bool Triangulator::positiveArea(float p1x, float p1y, float p2x, float p2y, floa int Triangulator::winding(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { float px = p2x - p1x, py = p2y - p1y; - return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1; } diff --git a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp index 799828869..6b3d61717 100644 --- a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp @@ -69,7 +69,8 @@ TwoColorTimeline::TwoColorTimeline(int frameCount) : CurveTimeline(frameCount), } void TwoColorTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector *pEvents, float alpha, - MixBlend blend, MixDirection direction) { + MixBlend blend, MixDirection direction +) { SP_UNUSED(lastTime); SP_UNUSED(pEvents); SP_UNUSED(direction); @@ -159,8 +160,7 @@ int TwoColorTimeline::getPropertyId() { return ((int) TimelineType_TwoColor << 24) + _slotIndex; } -void TwoColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, - float b2) { +void TwoColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2) { frameIndex *= ENTRIES; _frames[frameIndex] = time; _frames[frameIndex + R] = r; diff --git a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp index 539b75a97..a2d702c84 100644 --- a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp @@ -56,22 +56,18 @@ void VertexAttachment::computeWorldVertices(Slot &slot, float *worldVertices) { computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0); } -void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, Vector &worldVertices, size_t offset, - size_t stride) { +void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, Vector &worldVertices, size_t offset, size_t stride) { computeWorldVertices(slot, start, count, worldVertices.buffer(), offset, stride); } -void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, - size_t stride) { +void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, size_t stride) { count = offset + (count >> 1) * stride; Skeleton &skeleton = slot._bone._skeleton; Vector *deformArray = &slot.getDeform(); Vector *vertices = &_vertices; Vector &bones = _bones; if (bones.size() == 0) { - if (deformArray->size() > 0) { - vertices = deformArray; - } + if (deformArray->size() > 0) vertices = deformArray; Bone &bone = slot._bone; float x = bone._worldX; diff --git a/spine-csharp/src/Animation.cs b/spine-csharp/src/Animation.cs index 631ebbca2..583a300fe 100644 --- a/spine-csharp/src/Animation.cs +++ b/spine-csharp/src/Animation.cs @@ -426,7 +426,7 @@ namespace Spine { /// The time in seconds, x, and y values for each key frame. public float[] Frames { get { return frames; } set { frames = value; } } - + /// Sets the time in seconds, x, and y values for the specified key frame. public void SetFrame (int frameIndex, float time, float x, float y) { frameIndex *= ENTRIES; @@ -493,11 +493,11 @@ namespace Spine { public ScaleTimeline (int frameCount) : base(frameCount) { } - + override public int PropertyId { get { return ((int)TimelineType.Scale << 24) + boneIndex; } } - + override public void Apply (Skeleton skeleton, float lastTime, float time, ExposedList firedEvents, float alpha, MixBlend blend, MixDirection direction) { Bone bone = skeleton.bones.Items[boneIndex]; @@ -598,7 +598,7 @@ namespace Spine { public ShearTimeline (int frameCount) : base(frameCount) { } - + override public int PropertyId { get { return ((int)TimelineType.Shear << 24) + boneIndex; } } @@ -952,7 +952,7 @@ namespace Spine { /// The attachment name for each key frame. May contain null values to clear the attachment. public string[] AttachmentNames { get { return attachmentNames; } set { attachmentNames = value; } } - + /// Sets the time in seconds and the attachment name for the specified key frame. public void SetFrame (int frameIndex, float time, String attachmentName) { frames[frameIndex] = time; @@ -1019,13 +1019,13 @@ namespace Spine { } /// The attachment that will be deformed. public VertexAttachment Attachment { get { return attachment; } set { attachment = value; } } - + /// The time in seconds for each key frame. public float[] Frames { get { return frames; } set { frames = value; } } /// The vertices for each key frame. public float[][] Vertices { get { return frameVertices; } set { frameVertices = value; } } - + /// Sets the time in seconds and the vertices for the specified key frame. /// Vertex positions for an unweighted VertexAttachment, or deform offsets if it has weights. @@ -1050,7 +1050,7 @@ namespace Spine { float[] deform; if (time < frames[0]) { // Time is before first frame. - + switch (blend) { case MixBlend.Setup: deformArray.Clear(); @@ -1250,7 +1250,7 @@ namespace Spine { /// The event for each key frame. public Event[] Events { get { return events; } set { events = value; } } - + /// Sets the time in seconds and the event for the specified key frame. public void SetFrame (int frameIndex, Event e) { frames[frameIndex] = e.Time; @@ -1339,7 +1339,7 @@ namespace Spine { frame = frames.Length - 1; else frame = Animation.BinarySearch(frames, time) - 1; - + int[] drawOrderToSetupIndex = drawOrders[frame]; if (drawOrderToSetupIndex == null) { Array.Copy(slots.Items, 0, drawOrder.Items, 0, slots.Count); @@ -1367,7 +1367,7 @@ namespace Spine { : base(frameCount) { frames = new float[frameCount * ENTRIES]; } - + override public int PropertyId { get { return ((int)TimelineType.IkConstraint << 24) + ikConstraintIndex; } } diff --git a/spine-csharp/src/AnimationStateData.cs b/spine-csharp/src/AnimationStateData.cs index 84dcb320f..f8fcb9d95 100644 --- a/spine-csharp/src/AnimationStateData.cs +++ b/spine-csharp/src/AnimationStateData.cs @@ -59,7 +59,7 @@ namespace Spine { SetMix(from, to, duration); } - /// Sets a mix duration when changing from the specified animation to the other. + /// Sets a mix duration when changing from the specified animation to the other. /// See TrackEntry.MixDuration. public void SetMix (Animation from, Animation to, float duration) { if (from == null) throw new ArgumentNullException("from", "from cannot be null."); @@ -70,7 +70,7 @@ namespace Spine { } /// - /// The mix duration to use when changing from the specified animation to the other, + /// The mix duration to use when changing from the specified animation to the other, /// or the DefaultMix if no mix duration has been set. /// public float GetMix (Animation from, Animation to) { diff --git a/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs b/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs index 2ac233658..4b0541189 100644 --- a/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs +++ b/spine-csharp/src/Attachments/AtlasAttachmentLoader.cs @@ -76,7 +76,7 @@ namespace Spine { attachment.regionOriginalWidth = region.originalWidth; attachment.regionOriginalHeight = region.originalHeight; return attachment; - } + } public BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, string name) { return new BoundingBoxAttachment(name); diff --git a/spine-csharp/src/Attachments/ClippingAttachment.cs b/spine-csharp/src/Attachments/ClippingAttachment.cs index 8c8e857c2..2d64e53e2 100644 --- a/spine-csharp/src/Attachments/ClippingAttachment.cs +++ b/spine-csharp/src/Attachments/ClippingAttachment.cs @@ -30,13 +30,13 @@ using System; namespace Spine { - public class ClippingAttachment : VertexAttachment { - internal SlotData endSlot; + public class ClippingAttachment : VertexAttachment { + internal SlotData endSlot; - public SlotData EndSlot { get { return endSlot; } set { endSlot = value; } } + public SlotData EndSlot { get { return endSlot; } set { endSlot = value; } } - public ClippingAttachment(string name) : base(name) { - } + public ClippingAttachment(string name) : base(name) { + } public override Attachment Copy () { ClippingAttachment copy = new ClippingAttachment(this.Name); diff --git a/spine-csharp/src/Attachments/MeshAttachment.cs b/spine-csharp/src/Attachments/MeshAttachment.cs index 1341aacf7..c01d1fb62 100644 --- a/spine-csharp/src/Attachments/MeshAttachment.cs +++ b/spine-csharp/src/Attachments/MeshAttachment.cs @@ -38,7 +38,7 @@ namespace Spine { internal int[] triangles; internal float r = 1, g = 1, b = 1, a = 1; internal int hulllength; - + public int HullLength { get { return hulllength; } set { hulllength = value; } } public float[] RegionUVs { get { return regionUVs; } set { regionUVs = value; } } /// The UV pair for each vertex, normalized within the entire texture. @@ -96,7 +96,7 @@ namespace Spine { float[] regionUVs = this.regionUVs; if (this.uvs == null || this.uvs.Length != regionUVs.Length) this.uvs = new float[regionUVs.Length]; float[] uvs = this.uvs; - float u = RegionU, v = RegionV, width = 0, height = 0; + float u = RegionU, v = RegionV, width = 0, height = 0; if (RegionDegrees == 90) { float textureHeight = this.regionWidth / (RegionV2 - RegionV); @@ -167,7 +167,7 @@ namespace Spine { copy.g = g; copy.b = b; copy.a = a; - + CopyTo(copy); copy.regionUVs = new float[regionUVs.Length]; Array.Copy(regionUVs, 0, copy.regionUVs, 0, regionUVs.Length); @@ -176,7 +176,7 @@ namespace Spine { copy.triangles = new int[triangles.Length]; Array.Copy(triangles, 0, copy.triangles, 0, triangles.Length); copy.HullLength = HullLength; - + // Nonessential. if (Edges != null) { copy.Edges = new int[Edges.Length]; diff --git a/spine-csharp/src/Attachments/PathAttachment.cs b/spine-csharp/src/Attachments/PathAttachment.cs index 4ed81df55..20765871b 100644 --- a/spine-csharp/src/Attachments/PathAttachment.cs +++ b/spine-csharp/src/Attachments/PathAttachment.cs @@ -51,7 +51,7 @@ namespace Spine { Array.Copy(lengths, 0, copy.lengths, 0, lengths.Length); copy.closed = closed; copy.constantSpeed = constantSpeed; - return copy; + return copy; } } } diff --git a/spine-csharp/src/Attachments/VertexAttachment.cs b/spine-csharp/src/Attachments/VertexAttachment.cs index 3f7a4e390..5bbfcb9ad 100644 --- a/spine-csharp/src/Attachments/VertexAttachment.cs +++ b/spine-csharp/src/Attachments/VertexAttachment.cs @@ -31,7 +31,7 @@ using System; namespace Spine { /// >An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's - /// . + /// . public abstract class VertexAttachment : Attachment { static int nextID = 0; static readonly Object nextIdLock = new Object(); @@ -141,14 +141,14 @@ namespace Spine { } else attachment.bones = null; - + if (vertices != null) { attachment.vertices = new float[vertices.Length]; Array.Copy(vertices, 0, attachment.vertices, 0, vertices.Length); } else attachment.vertices = null; - + attachment.worldVerticesLength = worldVerticesLength; attachment.deformAttachment = deformAttachment; } diff --git a/spine-csharp/src/Bone.cs b/spine-csharp/src/Bone.cs index b48b1a45c..c60c05938 100644 --- a/spine-csharp/src/Bone.cs +++ b/spine-csharp/src/Bone.cs @@ -257,7 +257,7 @@ namespace Spine { /// /// Computes the individual applied transform values from the world transform. This can be useful to perform processing using /// the applied transform after the world transform has been modified directly (eg, by a constraint).. - /// + /// /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. /// internal void UpdateAppliedTransform () { @@ -301,7 +301,7 @@ namespace Spine { } } - public void WorldToLocal (float worldX, float worldY, out float localX, out float localY) { + public void WorldToLocal (float worldX, float worldY, out float localX, out float localY) { float a = this.a, b = this.b, c = this.c, d = this.d; float invDet = 1 / (a * d - b * c); float x = worldX - this.worldX, y = worldY - this.worldY; diff --git a/spine-csharp/src/Collections/OrderedDictionary.cs b/spine-csharp/src/Collections/OrderedDictionary.cs index 88c59d57e..f98e25059 100644 --- a/spine-csharp/src/Collections/OrderedDictionary.cs +++ b/spine-csharp/src/Collections/OrderedDictionary.cs @@ -344,7 +344,7 @@ namespace Spine.Collections dictionary[value.Key] = index; } else { - dictionary.Add(value.Key, index); // will throw if key already exists + dictionary.Add(value.Key, index); // will throw if key already exists dictionary.Remove(key); } keys[index] = value.Key; diff --git a/spine-csharp/src/Event.cs b/spine-csharp/src/Event.cs index 226c4cb2e..50a2632f9 100644 --- a/spine-csharp/src/Event.cs +++ b/spine-csharp/src/Event.cs @@ -38,7 +38,7 @@ namespace Spine { internal float floatValue; internal string stringValue; internal float volume; - internal float balance; + internal float balance; public EventData Data { get { return data; } } /// The animation time this event was keyed. diff --git a/spine-csharp/src/ExposedList.cs b/spine-csharp/src/ExposedList.cs index 7a0d8f62b..9bec2297a 100644 --- a/spine-csharp/src/ExposedList.cs +++ b/spine-csharp/src/ExposedList.cs @@ -17,10 +17,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -466,7 +466,7 @@ namespace Spine { public T Pop () { if (Count == 0) throw new InvalidOperationException("List is empty. Nothing to pop."); - + int i = Count - 1; T item = Items[i]; Items[i] = default(T); diff --git a/spine-csharp/src/IkConstraintData.cs b/spine-csharp/src/IkConstraintData.cs index cd0c4a717..8e89c7235 100644 --- a/spine-csharp/src/IkConstraintData.cs +++ b/spine-csharp/src/IkConstraintData.cs @@ -73,7 +73,7 @@ namespace Spine { } /// - /// When true, and only a single bone is being constrained, + /// When true, and only a single bone is being constrained, /// if the target is too close, the bone is scaled to reach it. public bool Compress { get { return compress; } @@ -81,7 +81,7 @@ namespace Spine { } /// - /// When true, if the target is out of range, the parent bone is scaled on the X axis to reach it. + /// When true, if the target is out of range, the parent bone is scaled on the X axis to reach it. /// If the bone has local nonuniform scale, stretching is not applied. public bool Stretch { get { return stretch; } @@ -89,7 +89,7 @@ namespace Spine { } /// - /// When true, only a single bone is being constrained and Compress or Stretch is used, + /// When true, only a single bone is being constrained and Compress or Stretch is used, /// the bone is scaled both on the X and Y axes. public bool Uniform { get { return uniform; } diff --git a/spine-csharp/src/Json.cs b/spine-csharp/src/Json.cs index 667a56694..878a4e77a 100644 --- a/spine-csharp/src/Json.cs +++ b/spine-csharp/src/Json.cs @@ -45,19 +45,17 @@ namespace Spine { } /** - * * Copyright (c) 2016 Adriano Tinoco d'Oliveira Rezende - * + * * Based on the JSON parser by Patrick van Bergen * http://techblog.procurios.nl/k/news/view/14605/14863/how-do-i-write-my-own-parser-(for-json).html * * Changes made: - * - * - Optimized parser speed (deserialize roughly near 3x faster than original) - * - Added support to handle lexer/parser error messages with line numbers - * - Added more fine grained control over type conversions during the parsing - * - Refactory API (Separate Lexer code from Parser code and the Encoder from Decoder) * + * - Optimized parser speed (deserialize roughly near 3x faster than original) + * - Added support to handle lexer/parser error messages with line numbers + * - Added more fine grained control over type conversions during the parsing + * - Refactory API (Separate Lexer code from Parser code and the Encoder from Decoder) * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -71,7 +69,6 @@ namespace Spine { * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * */ namespace SharpJson { @@ -132,19 +129,19 @@ namespace SharpJson { int idx = 0; StringBuilder builder = null; - + SkipWhiteSpaces(); - + // " char c = json[index++]; - + bool failed = false; bool complete = false; - + while (!complete && !failed) { if (index == json.Length) break; - + c = json[index++]; if (c == '"') { complete = true; @@ -152,9 +149,9 @@ namespace SharpJson } else if (c == '\\') { if (index == json.Length) break; - + c = json[index++]; - + switch (c) { case '"': stringBuffer[idx++] = '"'; @@ -184,10 +181,10 @@ namespace SharpJson int remainingLength = json.Length - index; if (remainingLength >= 4) { var hex = new string(json, index, 4); - + // XXX: handle UTF stringBuffer[idx++] = (char) Convert.ToInt32(hex, 16); - + // skip 4 chars index += 4; } else { @@ -198,38 +195,38 @@ namespace SharpJson } else { stringBuffer[idx++] = c; } - + if (idx >= stringBuffer.Length) { if (builder == null) builder = new StringBuilder(); - + builder.Append(stringBuffer, 0, idx); idx = 0; } } - + if (!complete) { success = false; return null; } - + if (builder != null) return builder.ToString (); else return new string (stringBuffer, 0, idx); } - + string GetNumberString() { SkipWhiteSpaces(); int lastIndex = GetLastIndexOfNumber(index); int charLength = (lastIndex - index) + 1; - + var result = new string (json, index, charLength); - + index = lastIndex + 1; - + return result; } @@ -237,10 +234,10 @@ namespace SharpJson { float number; var str = GetNumberString (); - + if (!float.TryParse (str, NumberStyles.Float, CultureInfo.InvariantCulture, out number)) return 0; - + return number; } @@ -248,25 +245,25 @@ namespace SharpJson { double number; var str = GetNumberString (); - + if (!double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out number)) return 0; - + return number; } - + int GetLastIndexOfNumber(int index) { int lastIndex; - + for (lastIndex = index; lastIndex < json.Length; lastIndex++) { char ch = json[lastIndex]; - + if ((ch < '0' || ch > '9') && ch != '+' && ch != '-' && ch != '.' && ch != 'e' && ch != 'E') break; } - + return lastIndex - 1; } @@ -301,9 +298,9 @@ namespace SharpJson { if (index == json.Length) return Token.None; - + char c = json[index++]; - + switch (c) { case '{': return Token.CurlyOpen; @@ -326,9 +323,9 @@ namespace SharpJson } index--; - + int remainingLength = json.Length - index; - + // false if (remainingLength >= 5) { if (json[index] == 'f' && @@ -340,7 +337,7 @@ namespace SharpJson return Token.False; } } - + // true if (remainingLength >= 4) { if (json[index] == 't' && @@ -351,7 +348,7 @@ namespace SharpJson return Token.True; } } - + // null if (remainingLength >= 4) { if (json[index] == 'n' && @@ -437,25 +434,25 @@ namespace SharpJson TriggerError("Invalid token; expected ':'"); return null; } - + // value object value = ParseValue(); if (errorMessage != null) return null; - + table[name] = value; break; } } - + //return null; // Unreachable code } IList ParseArray() { var array = new List(); - + // [ lexer.NextToken(); @@ -482,7 +479,7 @@ namespace SharpJson break; } } - + //return null; // Unreachable code } diff --git a/spine-csharp/src/MathUtils.cs b/spine-csharp/src/MathUtils.cs index 5ff19d3af..24feb8914 100644 --- a/spine-csharp/src/MathUtils.cs +++ b/spine-csharp/src/MathUtils.cs @@ -63,12 +63,12 @@ namespace Spine { static public float Cos (float radians) { return sin[(int)((radians + PI / 2) * RadToIndex) & SIN_MASK]; } - + /// Returns the sine in radians from a lookup table. static public float SinDeg (float degrees) { return sin[(int)(degrees * DegToIndex) & SIN_MASK]; } - + /// Returns the cosine in radians from a lookup table. static public float CosDeg (float degrees) { return sin[(int)((degrees + 90) * DegToIndex) & SIN_MASK]; diff --git a/spine-csharp/src/PathConstraint.cs b/spine-csharp/src/PathConstraint.cs index 268e3c098..ef32ffd7f 100644 --- a/spine-csharp/src/PathConstraint.cs +++ b/spine-csharp/src/PathConstraint.cs @@ -86,7 +86,7 @@ namespace Spine { public void Apply () { Update(); } - + public void Update () { PathAttachment attachment = target.Attachment as PathAttachment; if (attachment == null) return; @@ -447,7 +447,7 @@ namespace Spine { output[o + 2] = (float)Math.Atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); } } - + /// The position along the path. public float Position { get { return position; } set { position = value; } } /// The spacing between bones. diff --git a/spine-csharp/src/PathConstraintData.cs b/spine-csharp/src/PathConstraintData.cs index a8f5a4e44..3b43c14c9 100644 --- a/spine-csharp/src/PathConstraintData.cs +++ b/spine-csharp/src/PathConstraintData.cs @@ -43,7 +43,7 @@ namespace Spine { } public ExposedList Bones { get { return bones; } } - public SlotData Target { get { return target; } set { target = value; } } + public SlotData Target { get { return target; } set { target = value; } } public PositionMode PositionMode { get { return positionMode; } set { positionMode = value; } } public SpacingMode SpacingMode { get { return spacingMode; } set { spacingMode = value; } } public RotateMode RotateMode { get { return rotateMode; } set { rotateMode = value; } } @@ -53,9 +53,9 @@ namespace Spine { public float RotateMix { get { return rotateMix; } set { rotateMix = value; } } public float TranslateMix { get { return translateMix; } set { translateMix = value; } } } - + public enum PositionMode { - Fixed, Percent + Fixed, Percent } public enum SpacingMode { diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index 107a4e98a..846b1dd8f 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -84,7 +84,7 @@ namespace Spine { foreach (BoneData boneData in data.bones) { Bone bone; if (boneData.parent == null) { - bone = new Bone(boneData, this, null); + bone = new Bone(boneData, this, null); } else { Bone parent = bones.Items[boneData.parent.index]; bone = new Bone(boneData, this, parent); @@ -214,7 +214,7 @@ namespace Spine { if (skin != null) SortPathConstraintAttachment(skin, slotIndex, slotBone); if (data.defaultSkin != null && data.defaultSkin != skin) SortPathConstraintAttachment(data.defaultSkin, slotIndex, slotBone); - + Attachment attachment = slot.attachment; if (attachment is PathAttachment) SortPathConstraintAttachment(attachment, slotBone); @@ -477,12 +477,12 @@ namespace Spine { /// Sets the skin used to look up attachments before looking in the . If the /// skin is changed, is called. /// - /// Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. + /// Attachments from the new skin are attached if the corresponding attachment from the old skin was attached. /// If there was no old skin, each slot's setup mode attachment is attached from the new skin. /// - /// After changing the skin, the visible attachments can be reset to those attached in the setup pose by calling - /// . - /// Also, often is called before the next time the + /// After changing the skin, the visible attachments can be reset to those attached in the setup pose by calling + /// . + /// Also, often is called before the next time the /// skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin. /// /// May be null. @@ -543,7 +543,7 @@ namespace Spine { } throw new Exception("Slot not found: " + slotName); } - + /// May be null. public IkConstraint FindIkConstraint (string constraintName) { if (constraintName == null) throw new ArgumentNullException("constraintName", "constraintName cannot be null."); diff --git a/spine-csharp/src/SkeletonData.cs b/spine-csharp/src/SkeletonData.cs index 282adde7c..0a51afc77 100644 --- a/spine-csharp/src/SkeletonData.cs +++ b/spine-csharp/src/SkeletonData.cs @@ -30,7 +30,7 @@ using System; namespace Spine { - + /// Stores the setup pose and all of the stateless data for a skeleton. public class SkeletonData { internal string name; @@ -73,9 +73,9 @@ namespace Spine { public ExposedList TransformConstraints { get { return transformConstraints; } set { transformConstraints = value; } } public ExposedList PathConstraints { get { return pathConstraints; } set { pathConstraints = value; } } - public float X { get { return x; } set { x = value; } } - public float Y { get { return y; } set { y = value; } } - public float Width { get { return width; } set { width = value; } } + public float X { get { return x; } set { x = value; } } + public float Y { get { return y; } set { y = value; } } + public float Width { get { return width; } set { width = value; } } public float Height { get { return height; } set { height = value; } } /// The Spine version used to export this data, or null. public string Version { get { return version; } set { version = value; } } @@ -83,7 +83,7 @@ namespace Spine { /// The path to the images directory as defined in Spine. Available only when nonessential data was exported. May be null public string ImagesPath { get { return imagesPath; } set { imagesPath = value; } } - + /// The path to the audio directory defined in Spine. Available only when nonessential data was exported. May be null. public string AudioPath { get { return audioPath; } set { audioPath = value; } } diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index 10d4ca42d..06a398d1f 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -99,9 +99,9 @@ namespace Spine { var skeletonMap = (Dictionary)root["skeleton"]; skeletonData.hash = (string)skeletonMap["hash"]; skeletonData.version = (string)skeletonMap["spine"]; - skeletonData.x = GetFloat(skeletonMap, "x", 0); - skeletonData.y = GetFloat(skeletonMap, "y", 0); - skeletonData.width = GetFloat(skeletonMap, "width", 0); + skeletonData.x = GetFloat(skeletonMap, "x", 0); + skeletonData.y = GetFloat(skeletonMap, "y", 0); + skeletonData.width = GetFloat(skeletonMap, "width", 0); skeletonData.height = GetFloat(skeletonMap, "height", 0); skeletonData.fps = GetFloat(skeletonMap, "fps", 30); skeletonData.imagesPath = GetString(skeletonMap, "images", null); @@ -159,7 +159,7 @@ namespace Spine { data.b2 = ToColor(color2, 2, 6); data.hasSecondColor = true; } - + data.attachmentName = GetString(slotMap, "attachment", null); if (slotMap.ContainsKey("blend")) data.blendMode = (BlendMode)Enum.Parse(typeof(BlendMode), (string)slotMap["blend"], true); @@ -272,7 +272,7 @@ namespace Spine { // Skins. if (root.ContainsKey("skins")) { - foreach (Dictionary skinMap in (List)root["skins"]) { + foreach (Dictionary skinMap in (List)root["skins"]) { Skin skin = new Skin((string)skinMap["name"]); if (skinMap.ContainsKey("bones")) { foreach (string entryName in (List)skinMap["bones"]) { @@ -312,7 +312,7 @@ namespace Spine { } catch (Exception e) { throw new Exception("Error reading attachment: " + entry.Key + ", skin: " + skin, e); } - } + } } } skeletonData.skins.Add(skin); @@ -358,7 +358,7 @@ namespace Spine { } catch (Exception e) { throw new Exception("Error reading animation: " + entry.Key, e); } - } + } } skeletonData.bones.TrimExcess(); @@ -739,7 +739,7 @@ namespace Spine { var timeline = new DeformTimeline(values.Count); timeline.slotIndex = slotIndex; timeline.attachment = attachment; - + int frameIndex = 0; foreach (Dictionary valueMap in values) { float[] deform; diff --git a/spine-csharp/src/Skin.cs b/spine-csharp/src/Skin.cs index bbaba5cb0..c21190499 100644 --- a/spine-csharp/src/Skin.cs +++ b/spine-csharp/src/Skin.cs @@ -34,7 +34,7 @@ using Spine.Collections; namespace Spine { /// Stores attachments by slot index and attachment name. - /// See SkeletonData , Skeleton , and + /// See SkeletonData , Skeleton , and /// Runtime skins in the Spine Runtimes Guide. /// public class Skin { @@ -47,7 +47,7 @@ namespace Spine { public OrderedDictionary Attachments { get { return attachments; } } public ExposedList Bones { get { return bones; } } public ExposedList Constraints { get { return constraints; } } - + public Skin (string name) { if (name == null) throw new ArgumentNullException("name", "name cannot be null."); this.name = name; @@ -174,7 +174,7 @@ namespace Spine { } } } - + // Avoids boxing in the dictionary and is necessary to omit entry.attachment in the comparison. class SkinEntryComparer : IEqualityComparer { internal static readonly SkinEntryComparer Instance = new SkinEntryComparer(); diff --git a/spine-csharp/src/TransformConstraint.cs b/spine-csharp/src/TransformConstraint.cs index 9fdd7a3c7..1da70e2d6 100644 --- a/spine-csharp/src/TransformConstraint.cs +++ b/spine-csharp/src/TransformConstraint.cs @@ -42,7 +42,7 @@ namespace Spine { internal ExposedList bones; internal Bone target; internal float rotateMix, translateMix, scaleMix, shearMix; - + internal bool active; public TransformConstraint (TransformConstraintData data, Skeleton skeleton) { diff --git a/spine-csharp/src/Triangulator.cs b/spine-csharp/src/Triangulator.cs index 4591bc639..a7ee54988 100644 --- a/spine-csharp/src/Triangulator.cs +++ b/spine-csharp/src/Triangulator.cs @@ -126,13 +126,13 @@ namespace Spine { var convexPolygons = this.convexPolygons; for (int i = 0, n = convexPolygons.Count; i < n; i++) { polygonPool.Free(convexPolygons.Items[i]); - } + } convexPolygons.Clear(); var convexPolygonsIndices = this.convexPolygonsIndices; for (int i = 0, n = convexPolygonsIndices.Count; i < n; i++) { polygonIndicesPool.Free(convexPolygonsIndices.Items[i]); - } + } convexPolygonsIndices.Clear(); var polygonIndices = polygonIndicesPool.Obtain(); @@ -173,7 +173,7 @@ namespace Spine { } else { polygonPool.Free(polygon); polygonIndicesPool.Free(polygonIndices); - } + } polygon = polygonPool.Obtain(); polygon.Clear(); polygon.Add(x1); diff --git a/spine-js/README.md b/spine-js/README.md index 369df50a5..2e290742b 100644 --- a/spine-js/README.md +++ b/spine-js/README.md @@ -1,3 +1,3 @@ # spine-js -spine-js has been deprecated and is superseded by [spine-ts](../spine-ts). +spine-js has been replaced by [spine-ts](../spine-ts). diff --git a/spine-love/spine-love/spine.lua b/spine-love/spine-love/spine.lua index 9e2002631..e6acd381e 100644 --- a/spine-love/spine-love/spine.lua +++ b/spine-love/spine-love/spine.lua @@ -86,10 +86,10 @@ PolygonBatcher.__index = PolygonBatcher function PolygonBatcher.new(vertexCount, useTwoColorTint) if useTwoColorTint == nil then useTwoColorTint = false end - + local vertexFormat local twoColorTintShader = nil - + if useTwoColorTint then vertexFormat = { {"VertexPosition", "float", 2}, -- The x,y position of each vertex. @@ -100,16 +100,16 @@ function PolygonBatcher.new(vertexCount, useTwoColorTint) local vertexcode = [[ attribute vec4 VertexColor2; varying vec4 color2; - + vec4 position(mat4 transform_projection, vec4 vertex_position) { color2 = VertexColor2; return transform_projection * vertex_position; } - ]] - + ]] + local pixelcode = [[ varying vec4 color2; - + vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) { vec4 texColor = Texel(texture, texture_coords); float alpha = texColor.a * color.a; @@ -118,8 +118,8 @@ function PolygonBatcher.new(vertexCount, useTwoColorTint) outputColor.rgb = (1.0 - texColor.rgb) * color2.rgb * alpha + texColor.rgb * color.rgb; return outputColor; } - ]] - + ]] + twoColorTintShader = love.graphics.newShader(pixelcode, vertexcode) else vertexFormat = { @@ -127,8 +127,8 @@ function PolygonBatcher.new(vertexCount, useTwoColorTint) {"VertexTexCoord", "float", 2}, -- The u,v texture coordinates of each vertex. {"VertexColor", "byte", 4} -- The r,g,b,a light color of each vertex. } - end - + end + local self = { mesh = love.graphics.newMesh(vertexFormat, vertexCount, "triangles", "dynamic"), maxVerticesLength = vertexCount, @@ -195,13 +195,13 @@ function PolygonBatcher:draw (texture, vertices, uvs, numVertices, indices, colo indexStart = indexStart + 1 i = i + 1 end - self.indicesLength = self.indicesLength + numIndices + self.indicesLength = self.indicesLength + numIndices local vertexStart = self.verticesLength + 1 local vertexEnd = vertexStart + numVertices local vertex = self.vertex - local colorScalar = 1; - if love._version_major <= 10 then colorScalar = 255 end + local colorScalar = 1; + if love._version_major <= 10 then colorScalar = 255 end if not self.useTwoColorTint then vertex[5] = color.r * colorScalar vertex[6] = color.g * colorScalar @@ -217,7 +217,7 @@ function PolygonBatcher:draw (texture, vertices, uvs, numVertices, indices, colo vertex[11] = darkColor.b * colorScalar vertex[12] = darkColor.a * colorScalar end - + local v = 1 if (vertexEffect) then local tempVertex = self.tempVertex @@ -322,78 +322,78 @@ function SkeletonRenderer:draw (skeleton) local drawOrder = skeleton.drawOrder for i, slot in ipairs(drawOrder) do - if slot.bone.active then - local attachment = slot.attachment - local vertices = worldVertices - local uvs = nil - local indices = nil - local texture = nil - local color = tmpColor - if attachment then - if attachment.type == spine.AttachmentType.region then - numVertices = 4 - attachment:computeWorldVertices(slot.bone, vertices, 0, 2) - uvs = attachment.uvs - indices = SkeletonRenderer.QUAD_TRIANGLES - texture = attachment.region.renderObject.texture - elseif attachment.type == spine.AttachmentType.mesh then - numVertices = attachment.worldVerticesLength / 2 - attachment:computeWorldVertices(slot, 0, attachment.worldVerticesLength, vertices, 0, 2) - uvs = attachment.uvs - indices = attachment.triangles - texture = attachment.region.renderObject.texture - elseif attachment.type == spine.AttachmentType.clipping then - self.clipper:clipStart(slot, attachment) - end + if slot.bone.active then + local attachment = slot.attachment + local vertices = worldVertices + local uvs = nil + local indices = nil + local texture = nil + local color = tmpColor + if attachment then + if attachment.type == spine.AttachmentType.region then + numVertices = 4 + attachment:computeWorldVertices(slot.bone, vertices, 0, 2) + uvs = attachment.uvs + indices = SkeletonRenderer.QUAD_TRIANGLES + texture = attachment.region.renderObject.texture + elseif attachment.type == spine.AttachmentType.mesh then + numVertices = attachment.worldVerticesLength / 2 + attachment:computeWorldVertices(slot, 0, attachment.worldVerticesLength, vertices, 0, 2) + uvs = attachment.uvs + indices = attachment.triangles + texture = attachment.region.renderObject.texture + elseif attachment.type == spine.AttachmentType.clipping then + self.clipper:clipStart(slot, attachment) + end - if texture then - local slotBlendMode = slot.data.blendMode - if lastBlendMode ~= slotBlendMode then - batcher:stop() - batcher:begin() - - if slotBlendMode == spine.BlendMode.normal then - love.graphics.setBlendMode("alpha") - elseif slotBlendMode == spine.BlendMode.additive then - love.graphics.setBlendMode("add") - elseif slotBlendMode == spine.BlendMode.multiply then - love.graphics.setBlendMode("multiply", "premultiplied") - elseif slotBlendMode == spine.BlendMode.screen then - love.graphics.setBlendMode("screen") - end - lastBlendMode = slotBlendMode - end - - local skeleton = slot.bone.skeleton - local skeletonColor = skeleton.color - local slotColor = slot.color - local attachmentColor = attachment.color - local alpha = skeletonColor.a * slotColor.a * attachmentColor.a - local multiplier = alpha - if premultipliedAlpha then multiplier = 1 end - color:set(skeletonColor.r * slotColor.r * attachmentColor.r * multiplier, - skeletonColor.g * slotColor.g * attachmentColor.g * multiplier, - skeletonColor.b * slotColor.b * attachmentColor.b * multiplier, - alpha) - - local dark = tmpColor2 - if slot.darkColor then dark = slot.darkColor - else dark:set(0, 0, 0, 0) end - - if self.clipper:isClipping() then - self.clipper:clipTriangles(vertices, attachment.uvs, indices, #indices) - vertices = self.clipper.clippedVertices - numVertices = #vertices / 2 - uvs = self.clipper.clippedUVs - indices = self.clipper.clippedTriangles - end - - batcher:draw(texture, vertices, uvs, numVertices, indices, color, dark, self.vertexEffect) - end - - self.clipper:clipEnd(slot) - end - end + if texture then + local slotBlendMode = slot.data.blendMode + if lastBlendMode ~= slotBlendMode then + batcher:stop() + batcher:begin() + + if slotBlendMode == spine.BlendMode.normal then + love.graphics.setBlendMode("alpha") + elseif slotBlendMode == spine.BlendMode.additive then + love.graphics.setBlendMode("add") + elseif slotBlendMode == spine.BlendMode.multiply then + love.graphics.setBlendMode("multiply", "premultiplied") + elseif slotBlendMode == spine.BlendMode.screen then + love.graphics.setBlendMode("screen") + end + lastBlendMode = slotBlendMode + end + + local skeleton = slot.bone.skeleton + local skeletonColor = skeleton.color + local slotColor = slot.color + local attachmentColor = attachment.color + local alpha = skeletonColor.a * slotColor.a * attachmentColor.a + local multiplier = alpha + if premultipliedAlpha then multiplier = 1 end + color:set(skeletonColor.r * slotColor.r * attachmentColor.r * multiplier, + skeletonColor.g * slotColor.g * attachmentColor.g * multiplier, + skeletonColor.b * slotColor.b * attachmentColor.b * multiplier, + alpha) + + local dark = tmpColor2 + if slot.darkColor then dark = slot.darkColor + else dark:set(0, 0, 0, 0) end + + if self.clipper:isClipping() then + self.clipper:clipTriangles(vertices, attachment.uvs, indices, #indices) + vertices = self.clipper.clippedVertices + numVertices = #vertices / 2 + uvs = self.clipper.clippedUVs + indices = self.clipper.clippedTriangles + end + + batcher:draw(texture, vertices, uvs, numVertices, indices, color, dark, self.vertexEffect) + end + + self.clipper:clipEnd(slot) + end + end end batcher:stop() diff --git a/spine-lua/Animation.lua b/spine-lua/Animation.lua index 8b93b2b48..cd1287280 100644 --- a/spine-lua/Animation.lua +++ b/spine-lua/Animation.lua @@ -259,7 +259,7 @@ function Animation.RotateTimeline.new (frameCount) local frames = self.frames local bone = skeleton.bones[self.boneIndex] - if not bone.active then return end + if not bone.active then return end if time < frames[0] then if blend == MixBlend.setup then bone.rotation = bone.data.rotation @@ -335,8 +335,8 @@ function Animation.TranslateTimeline.new (frameCount) local frames = self.frames local bone = skeleton.bones[self.boneIndex] - if not bone.active then return end - + if not bone.active then return end + if time < frames[0] then if blend == MixBlend.setup then bone.x = bone.data.x @@ -401,8 +401,8 @@ function Animation.ScaleTimeline.new (frameCount) local frames = self.frames local bone = skeleton.bones[self.boneIndex] - if not bone.active then return end - + if not bone.active then return end + if time < frames[0] then if blend == MixBlend.setup then bone.scaleX = bone.data.scaleX @@ -504,8 +504,8 @@ function Animation.ShearTimeline.new (frameCount) local frames = self.frames local bone = skeleton.bones[self.boneIndex] - if not bone.active then return end - + if not bone.active then return end + if time < frames[0] then if blend == MixBlend.setup then bone.shearX = bone.data.shearX @@ -584,7 +584,7 @@ function Animation.ColorTimeline.new (frameCount) function self:apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) local frames = self.frames local slot = skeleton.slots[self.slotIndex] - if not slot.bone.active then return end + if not slot.bone.active then return end if time < frames[0] then if blend == MixBlend.setup then slot.color:setFrom(slot.data.color) @@ -676,8 +676,8 @@ function Animation.TwoColorTimeline.new (frameCount) function self:apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) local frames = self.frames local slot = skeleton.slots[self.slotIndex] - if not slot.bone.active then return end - + if not slot.bone.active then return end + if time < frames[0] then if blend == MixBlend.setup then slot.color:setFrom(slot.data.color) @@ -768,7 +768,7 @@ function Animation.AttachmentTimeline.new (frameCount) function self:apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) local slot = skeleton.slots[self.slotIndex] - if not slot.bone.active then return end + if not slot.bone.active then return end local attachmentName if direction == MixDirection.out and blend == MixBlend.setup then attachmentName = slot.data.attachmentName @@ -831,8 +831,8 @@ function Animation.DeformTimeline.new (frameCount) function self:apply (skeleton, lastTime, time, firedEvents, alpha, blend, direction) local slot = skeleton.slots[self.slotIndex] - if not slot.bone.active then return end - + if not slot.bone.active then return end + local slotAttachment = slot.attachment if not slotAttachment then return end if not (slotAttachment.type == AttachmentType.mesh or slotAttachment.type == AttachmentType.linkedmesh or slotAttachment.type == AttachmentType.path or slotAttachment.type == AttachmentType.boundingbox) then return end @@ -840,7 +840,7 @@ function Animation.DeformTimeline.new (frameCount) local frames = self.frames local deformArray = slot.deform - if #(deformArray) == 0 then blend = MixBlend.setup end + if #(deformArray) == 0 then blend = MixBlend.setup end local frameVertices = self.frameVertices local vertexCount = #(frameVertices[0]) @@ -848,35 +848,35 @@ function Animation.DeformTimeline.new (frameCount) if time < frames[0] then local vertexAttachment = slotAttachment; if blend == MixBlend.setup then - slot.deform = {} - return; + slot.deform = {} + return; elseif blend == MixBlend.first then - if (alpha == 1) then - slot.deform = {} - return; - end + if (alpha == 1) then + slot.deform = {} + return; + end - local deform = utils.setArraySize(deformArray, vertexCount) - if (vertexAttachment.bones == nil) then - local setupVertices = vertexAttachment.vertices - local i = 1 - while i <= vertexCount do - deform[i] = deform[i] + (setupVertices[i] - deform[i]) * alpha - i = i + 1 - end - else - alpha = 1 - alpha - local i = 1 - while i <= vertexCount do - deform[i] = deform[i] * alpha - i = i + 1 - end - end + local deform = utils.setArraySize(deformArray, vertexCount) + if (vertexAttachment.bones == nil) then + local setupVertices = vertexAttachment.vertices + local i = 1 + while i <= vertexCount do + deform[i] = deform[i] + (setupVertices[i] - deform[i]) * alpha + i = i + 1 + end + else + alpha = 1 - alpha + local i = 1 + while i <= vertexCount do + deform[i] = deform[i] * alpha + i = i + 1 + end + end end return end - local deform = utils.setArraySize(deformArray, vertexCount) + local deform = utils.setArraySize(deformArray, vertexCount) if time >= frames[zlen(frames) - 1] then -- Time is after last frame. local lastVertices = frameVertices[zlen(frames) - 1] if alpha == 1 then @@ -1186,12 +1186,12 @@ function Animation.IkConstraintTimeline.new (frameCount) local ENTRIES = Animation.IkConstraintTimeline.ENTRIES local PREV_TIME = -6 local PREV_MIX = -5 - local PREV_SOFTNESS = -4 + local PREV_SOFTNESS = -4 local PREV_BEND_DIRECTION = -3 local PREV_COMPRESS = -2 local PREV_STRETCH = -1 local MIX = 1 - local SOFTNESS = 2 + local SOFTNESS = 2 local BEND_DIRECTION = 3 local COMPRESS = 4 local STRETCH = 5 @@ -1209,7 +1209,7 @@ function Animation.IkConstraintTimeline.new (frameCount) frameIndex = frameIndex * ENTRIES self.frames[frameIndex] = time self.frames[frameIndex + MIX] = mix - self.frames[frameIndex + SOFTNESS] = softness + self.frames[frameIndex + SOFTNESS] = softness self.frames[frameIndex + BEND_DIRECTION] = bendDirection if (compress) then self.frames[frameIndex + COMPRESS] = 1 @@ -1227,17 +1227,17 @@ function Animation.IkConstraintTimeline.new (frameCount) local frames = self.frames local constraint = skeleton.ikConstraints[self.ikConstraintIndex] - if not constraint.active then return end + if not constraint.active then return end if time < frames[0] then if blend == MixBlend.setup then constraint.mix = constraint.data.mix - constraint.softness = constraint.data.softness + constraint.softness = constraint.data.softness constraint.bendDirection = constraint.data.bendDirection constraint.compress = constraint.data.compress constraint.stretch = constraint.data.stretch elseif blend == MixBlend.first then constraint.mix = constraint.mix + (constraint.data.mix - constraint.mix) * alpha - constraint.softness = constraint.softness + (constraint.data.softness - constraint.softness) * alpha + constraint.softness = constraint.softness + (constraint.data.softness - constraint.softness) * alpha constraint.bendDirection = constraint.data.bendDirection constraint.compress = constraint.data.compress constraint.stretch = constraint.data.stretch @@ -1248,8 +1248,7 @@ function Animation.IkConstraintTimeline.new (frameCount) if time >= frames[zlen(frames) - ENTRIES] then -- Time is after last frame. if blend == MixBlend.setup then constraint.mix = constraint.data.mix + (frames[zlen(frames) + PREV_MIX] - constraint.data.mix) * alpha - constraint.softness = constraint.data.softness - + (frames[zlen(frames) + PREV_SOFTNESS] - constraint.data.softness) * alpha + constraint.softness = constraint.data.softness + (frames[zlen(frames) + PREV_SOFTNESS] - constraint.data.softness) * alpha if direction == MixDirection.out then constraint.bendDirection = constraint.data.bendDirection constraint.compress = constraint.data.compress @@ -1260,8 +1259,8 @@ function Animation.IkConstraintTimeline.new (frameCount) if (math_floor(frames[zlen(frames) + PREV_STRETCH]) == 1) then constraint.stretch = true else constraint.stretch = false end end else - constraint.mix = constraint.mix + (frames[zlen(frames) + PREV_MIX] - constraint.mix) * alpha - constraint.softness = constraint.softness + (frames[zlen(frames) + PREV_SOFTNESS] - constraint.softness) * alpha + constraint.mix = constraint.mix + (frames[zlen(frames) + PREV_MIX] - constraint.mix) * alpha + constraint.softness = constraint.softness + (frames[zlen(frames) + PREV_SOFTNESS] - constraint.softness) * alpha if direction == MixDirection._in then constraint.bendDirection = math_floor(frames[zlen(frames) + PREV_BEND_DIRECTION]) if (math_floor(frames[zlen(frames) + PREV_COMPRESS]) == 1) then constraint.compress = true else constraint.compress = false end @@ -1274,15 +1273,14 @@ function Animation.IkConstraintTimeline.new (frameCount) -- Interpolate between the previous frame and the current frame. local frame = binarySearch(frames, time, ENTRIES) local mix = frames[frame + PREV_MIX] - local softness = frames[frame + PREV_SOFTNESS] + local softness = frames[frame + PREV_SOFTNESS] local frameTime = frames[frame] local percent = self:getCurvePercent(math.floor(frame / ENTRIES) - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)) if blend == MixBlend.setup then constraint.mix = constraint.data.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.data.mix) * alpha - constraint.softness = constraint.data.softness - + (softness + (frames[frame + SOFTNESS] - softness) * percent - constraint.data.softness) * alpha + constraint.softness = constraint.data.softness + (softness + (frames[frame + SOFTNESS] - softness) * percent - constraint.data.softness) * alpha if direction == MixDirection.out then constraint.bendDirection = constraint.data.bendDirection constraint.compress = constraint.data.compress @@ -1294,7 +1292,7 @@ function Animation.IkConstraintTimeline.new (frameCount) end else constraint.mix = constraint.mix + (mix + (frames[frame + MIX] - mix) * percent - constraint.mix) * alpha - constraint.softness = constraint.softness + (softness + (frames[frame + SOFTNESS] - softness) * percent - constraint.softness) * alpha + constraint.softness = constraint.softness + (softness + (frames[frame + SOFTNESS] - softness) * percent - constraint.softness) * alpha if direction == MixDirection._in then constraint.bendDirection = math_floor(frames[frame + PREV_BEND_DIRECTION]) if (math_floor(frames[frame + PREV_COMPRESS]) == 1) then constraint.compress = true else constraint.compress = false end @@ -1342,8 +1340,8 @@ function Animation.TransformConstraintTimeline.new (frameCount) local frames = self.frames local constraint = skeleton.transformConstraints[self.transformConstraintIndex] - if not constraint.active then return end - + if not constraint.active then return end + if time < frames[0] then local data = constraint.data if blend == MixBlend.setup then @@ -1430,8 +1428,8 @@ function Animation.PathConstraintPositionTimeline.new (frameCount) local frames = self.frames local constraint = skeleton.pathConstraints[self.pathConstraintIndex] - if not constraint.active then return end - + if not constraint.active then return end + if (time < frames[0]) then if blend == MixBlend.setup then constraint.position = constraint.data.position @@ -1491,8 +1489,8 @@ function Animation.PathConstraintSpacingTimeline.new (frameCount) local frames = self.frames local constraint = skeleton.pathConstraints[self.pathConstraintIndex] - if not constraint.active then return end - + if not constraint.active then return end + if (time < frames[0]) then if blend == MixBlend.setup then constraint.spacing = constraint.data.spacing @@ -1556,8 +1554,8 @@ function Animation.PathConstraintMixTimeline.new (frameCount) local frames = self.frames local constraint = skeleton.pathConstraints[self.pathConstraintIndex] - if not constraint.active then return end - + if not constraint.active then return end + if (time < frames[0]) then if blend == MixBlend.setup then constraint.rotateMix = constraint.data.rotateMix diff --git a/spine-lua/AnimationState.lua b/spine-lua/AnimationState.lua index 6174e6f4d..21fd06d32 100644 --- a/spine-lua/AnimationState.lua +++ b/spine-lua/AnimationState.lua @@ -95,7 +95,7 @@ function EventQueue:_end (entry) local objects = self.objects table_insert(objects, EventType._end) table_insert(objects, entry) - self.animationState.animationsChanged = true + self.animationState.animationsChanged = true end function EventQueue:dispose (entry) @@ -163,7 +163,6 @@ function EventQueue:clear () self.objects = {} end - local TrackEntry = {} TrackEntry.__index = TrackEntry @@ -197,7 +196,7 @@ function TrackEntry:getAnimationTime () end function TrackEntry:resetRotationDirections () - self.timelinesRotation = {} + self.timelinesRotation = {} end local AnimationState = {} @@ -287,8 +286,8 @@ function AnimationState:update (delta) end end - current.trackTime = current.trackTime + currentDelta - end + current.trackTime = current.trackTime + currentDelta + end end end end @@ -328,11 +327,11 @@ function AnimationState:apply (skeleton) local tracks = self.tracks local queue = self.queue - local applied = false + local applied = false for i,current in pairs(tracks) do if not (current == nil or current.delay > 0) then - applied = true + applied = true local blend = current.mixBlend if i == 0 then blend = MixBlend.first end @@ -378,7 +377,7 @@ function AnimationState:apply (skeleton) end queue:drain() - return applied + return applied end function AnimationState:applyMixingFrom (to, skeleton, blend) @@ -388,7 +387,7 @@ function AnimationState:applyMixingFrom (to, skeleton, blend) local mix = 0 if to.mixDuration == 0 then -- Single frame mix to undo mixingFrom changes. mix = 1 - if blend == MixBlend.first then blend = MixBlend.setup end + if blend == MixBlend.first then blend = MixBlend.setup end else mix = to.mixTime / to.mixDuration if mix > 1 then mix = 1 end @@ -420,13 +419,13 @@ function AnimationState:applyMixingFrom (to, skeleton, blend) for i,timeline in ipairs(timelines) do local skipSubsequent = false; - local direction = MixDirection.out; + local direction = MixDirection.out; local timelineBlend = MixBlend.setup local alpha = 0 if clearBit(timelineMode[i], NOT_LAST) == SUBSEQUENT then timelineBlend = blend if not attachments and timeline.type == Animation.TimelineType.attachment then - if testBit(timelineMode[i], NOT_LAST) then + if testBit(timelineMode[i], NOT_LAST) then skipSubsequent = true else timelineBlend = MixBlend.setup @@ -451,22 +450,22 @@ function AnimationState:applyMixingFrom (to, skeleton, blend) if timeline.type == Animation.TimelineType.rotate then self:applyRotateTimeline(timeline, skeleton, animationTime, alpha, timelineBlend, timelinesRotation, i * 2, firstFrame) else - if timelineBlend == MixBlend.setup then - if timeline.type == Animation.TimelineType.attachment then - if attachments or testBit(timelineMode[i], NOT_LAST) then direction = MixDirection._in end - elseif timeline.type == Animation.TimelineType.drawOrder then - if drawOrder then direction = MixDirection._in end - end - end + if timelineBlend == MixBlend.setup then + if timeline.type == Animation.TimelineType.attachment then + if attachments or testBit(timelineMode[i], NOT_LAST) then direction = MixDirection._in end + elseif timeline.type == Animation.TimelineType.drawOrder then + if drawOrder then direction = MixDirection._in end + end + end timeline:apply(skeleton, animationLast, animationTime, self.events, alpha, timelineBlend, direction) end end end end - if (to.mixDuration > 0) then - self:queueEvents(from, animationTime) - end + if (to.mixDuration > 0) then + self:queueEvents(from, animationTime) + end self.events = {}; from.nextAnimationLast = animationTime from.nextTrackLast = from.trackTime @@ -480,18 +479,18 @@ function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, bl timelinesRotation[i+1] = 0 end - if alpha == 1 then - timeline:apply(skeleton, 0, time, nil, 1, blend, MixDirection._in) - return - end + if alpha == 1 then + timeline:apply(skeleton, 0, time, nil, 1, blend, MixDirection._in) + return + end - local rotateTimeline = timeline - local frames = rotateTimeline.frames - local bone = skeleton.bones[rotateTimeline.boneIndex] - if not bone.active then return end + local rotateTimeline = timeline + local frames = rotateTimeline.frames + local bone = skeleton.bones[rotateTimeline.boneIndex] + if not bone.active then return end local r1 = 0 local r2 = 0 - if time < frames[0] then + if time < frames[0] then if blend == MixBlend.setup then bone.rotation = bone.data.rotation return @@ -524,138 +523,138 @@ function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, bl end end - -- Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. - local total = 0 - local diff = r2 - r1 + -- Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. + local total = 0 + local diff = r2 - r1 diff = diff - (16384 - math_floor(16384.499999999996 - diff / 360)) * 360 - if diff == 0 then - total = timelinesRotation[i] - else - local lastTotal = 0 - local lastDiff = 0 - if firstFrame then - lastTotal = 0 - lastDiff = diff - else - lastTotal = timelinesRotation[i] -- Angle and direction of mix, including loops. - lastDiff = timelinesRotation[i + 1] -- Difference between bones. - end - local current = diff > 0 - local dir = lastTotal >= 0 - -- Detect cross at 0 (not 180). - if math_signum(lastDiff) ~= math_signum(diff) and math_abs(lastDiff) <= 90 then - -- A cross after a 360 rotation is a loop. - if math_abs(lastTotal) > 180 then lastTotal = lastTotal + 360 * math_signum(lastTotal) end - dir = current - end - total = diff + lastTotal - math_mod(lastTotal, 360) -- FIXME used to be %360, store loops as part of lastTotal. - if dir ~= current then total = total + 360 * math_signum(lastTotal) end - timelinesRotation[i] = total - end - timelinesRotation[i + 1] = diff - r1 = r1 + total * alpha - bone.rotation = r1 - (16384 - math_floor(16384.499999999996 - r1 / 360)) * 360 + if diff == 0 then + total = timelinesRotation[i] + else + local lastTotal = 0 + local lastDiff = 0 + if firstFrame then + lastTotal = 0 + lastDiff = diff + else + lastTotal = timelinesRotation[i] -- Angle and direction of mix, including loops. + lastDiff = timelinesRotation[i + 1] -- Difference between bones. + end + local current = diff > 0 + local dir = lastTotal >= 0 + -- Detect cross at 0 (not 180). + if math_signum(lastDiff) ~= math_signum(diff) and math_abs(lastDiff) <= 90 then + -- A cross after a 360 rotation is a loop. + if math_abs(lastTotal) > 180 then lastTotal = lastTotal + 360 * math_signum(lastTotal) end + dir = current + end + total = diff + lastTotal - math_mod(lastTotal, 360) -- FIXME used to be %360, store loops as part of lastTotal. + if dir ~= current then total = total + 360 * math_signum(lastTotal) end + timelinesRotation[i] = total + end + timelinesRotation[i + 1] = diff + r1 = r1 + total * alpha + bone.rotation = r1 - (16384 - math_floor(16384.499999999996 - r1 / 360)) * 360 end function AnimationState:queueEvents (entry, animationTime) - local animationStart = entry.animationStart - local animationEnd = entry.animationEnd - local duration = animationEnd - animationStart - local trackLastWrapped = entry.trackLast % duration + local animationStart = entry.animationStart + local animationEnd = entry.animationEnd + local duration = animationEnd - animationStart + local trackLastWrapped = entry.trackLast % duration - -- Queue events before complete. - local events = self.events - local queue = self.queue - local i = 1 - local n = #events - while i <= n do - local event = events[i] - if event.time < trackLastWrapped then break end - if not (event.time > animationEnd) then -- Discard events outside animation start/end. - queue:event(entry, event) - end - i = i + 1 - end + -- Queue events before complete. + local events = self.events + local queue = self.queue + local i = 1 + local n = #events + while i <= n do + local event = events[i] + if event.time < trackLastWrapped then break end + if not (event.time > animationEnd) then -- Discard events outside animation start/end. + queue:event(entry, event) + end + i = i + 1 + end - -- Queue complete if completed a loop iteration or the animation. - local queueComplete = false - if entry.loop then - queueComplete = duration == 0 or (trackLastWrapped > entry.trackTime % duration) - else - queueComplete = (animationTime >= animationEnd and entry.animationLast < animationEnd) - end - if queueComplete then - queue:complete(entry) - end + -- Queue complete if completed a loop iteration or the animation. + local queueComplete = false + if entry.loop then + queueComplete = duration == 0 or (trackLastWrapped > entry.trackTime % duration) + else + queueComplete = (animationTime >= animationEnd and entry.animationLast < animationEnd) + end + if queueComplete then + queue:complete(entry) + end - -- Queue events after complete. - while i <= n do - local event = events[i] - if not (event.time < animationStart) then --// Discard events outside animation start/end. - queue:event(entry, event) - end - i = i + 1 - end + -- Queue events after complete. + while i <= n do + local event = events[i] + if not (event.time < animationStart) then --// Discard events outside animation start/end. + queue:event(entry, event) + end + i = i + 1 + end end function AnimationState:clearTracks () - local queue = self.queue - local tracks = self.tracks + local queue = self.queue + local tracks = self.tracks local oldDrainDisabled = queue.drainDisabled - queue.drainDisabled = true; - for i,track in pairs(tracks) do - self:clearTrack(i) - end - tracks = {} - queue.drainDisabled = oldDrainDisabled - queue:drain(); + queue.drainDisabled = true; + for i,track in pairs(tracks) do + self:clearTrack(i) + end + tracks = {} + queue.drainDisabled = oldDrainDisabled + queue:drain(); end function AnimationState:clearTrack (trackIndex) - local tracks = self.tracks - local queue = self.queue - local current = tracks[trackIndex] - if current == nil then return end + local tracks = self.tracks + local queue = self.queue + local current = tracks[trackIndex] + if current == nil then return end - queue:_end(current) + queue:_end(current) - self:disposeNext(current) + self:disposeNext(current) - local entry = current; - while (true) do - local from = entry.mixingFrom - if from == nil then break end - queue:_end(from) - entry.mixingFrom = nil + local entry = current; + while (true) do + local from = entry.mixingFrom + if from == nil then break end + queue:_end(from) + entry.mixingFrom = nil entry.mixingTo = nil - entry = from - end + entry = from + end - tracks[current.trackIndex] = nil + tracks[current.trackIndex] = nil - queue:drain() + queue:drain() end function AnimationState:setCurrent (index, current, interrupt) - local from = self:expandToIndex(index) - local tracks = self.tracks - local queue = self.queue - tracks[index] = current + local from = self:expandToIndex(index) + local tracks = self.tracks + local queue = self.queue + tracks[index] = current - if from then - if interrupt then queue:interrupt(from) end - current.mixingFrom = from + if from then + if interrupt then queue:interrupt(from) end + current.mixingFrom = from from.mixingTo = current - current.mixTime = 0 + current.mixTime = 0 if from.mixingFrom and from.mixDuration > 0 then current.interruptAlpha = current.interruptAlpha * math_min(1, from.mixTime / from.mixDuration) end from.timelinesRotation = {}; - end + end - queue:start(current) + queue:start(current) end function AnimationState:setAnimationByName (trackIndex, animationName, loop) @@ -665,148 +664,148 @@ function AnimationState:setAnimationByName (trackIndex, animationName, loop) end function AnimationState:setAnimation (trackIndex, animation, loop) - if not animation then error("animation cannot be null.") end - local interrupt = true; - local current = self:expandToIndex(trackIndex) - local queue = self.queue - local tracks = self.tracks - if current then - if current.nextTrackLast == -1 then - -- Don't mix from an entry that was never applied. - tracks[trackIndex] = current.mixingFrom - queue:interrupt(current) - queue:_end(current) - self:disposeNext(current) - current = current.mixingFrom - interrupt = false; - else - self:disposeNext(current) - end - end - local entry = self:trackEntry(trackIndex, animation, loop, current) - self:setCurrent(trackIndex, entry, interrupt) - queue:drain() - return entry + if not animation then error("animation cannot be null.") end + local interrupt = true; + local current = self:expandToIndex(trackIndex) + local queue = self.queue + local tracks = self.tracks + if current then + if current.nextTrackLast == -1 then + -- Don't mix from an entry that was never applied. + tracks[trackIndex] = current.mixingFrom + queue:interrupt(current) + queue:_end(current) + self:disposeNext(current) + current = current.mixingFrom + interrupt = false; + else + self:disposeNext(current) + end + end + local entry = self:trackEntry(trackIndex, animation, loop, current) + self:setCurrent(trackIndex, entry, interrupt) + queue:drain() + return entry end function AnimationState:addAnimationByName (trackIndex, animationName, loop, delay) - local animation = self.data.skeletonData:findAnimation(animationName) - if not animation then error("Animation not found: " + animationName) end - return self:addAnimation(trackIndex, animation, loop, delay) + local animation = self.data.skeletonData:findAnimation(animationName) + if not animation then error("Animation not found: " + animationName) end + return self:addAnimation(trackIndex, animation, loop, delay) end function AnimationState:addAnimation (trackIndex, animation, loop, delay) - if not animation then error("animation cannot be null.") end + if not animation then error("animation cannot be null.") end - local last = self:expandToIndex(trackIndex) - if last then - while last.next do - last = last.next - end - end + local last = self:expandToIndex(trackIndex) + if last then + while last.next do + last = last.next + end + end - local entry = self:trackEntry(trackIndex, animation, loop, last) - local queue = self.queue - local data = self.data + local entry = self:trackEntry(trackIndex, animation, loop, last) + local queue = self.queue + local data = self.data - if not last then - self:setCurrent(trackIndex, entry, true) - queue:drain() - else - last.next = entry - if delay <= 0 then - local duration = last.animationEnd - last.animationStart - if duration ~= 0 then + if not last then + self:setCurrent(trackIndex, entry, true) + queue:drain() + else + last.next = entry + if delay <= 0 then + local duration = last.animationEnd - last.animationStart + if duration ~= 0 then if last.loop then delay = delay + duration * (1 + math_floor(last.trackTime / duration)) else delay = delay + math_max(duration, last.trackTime) end - delay = delay - data:getMix(last.animation, animation) - else - delay = last.trackTime - end - end - end + delay = delay - data:getMix(last.animation, animation) + else + delay = last.trackTime + end + end + end - entry.delay = delay - return entry + entry.delay = delay + return entry end function AnimationState:setEmptyAnimation (trackIndex, mixDuration) - local entry = self:setAnimation(trackIndex, EMPTY_ANIMATION, false) - entry.mixDuration = mixDuration - entry.trackEnd = mixDuration - return entry + local entry = self:setAnimation(trackIndex, EMPTY_ANIMATION, false) + entry.mixDuration = mixDuration + entry.trackEnd = mixDuration + return entry end function AnimationState:addEmptyAnimation (trackIndex, mixDuration, delay) - if delay <= 0 then delay = delay - mixDuration end - local entry = self:addAnimation(trackIndex, EMPTY_ANIMATION, false, delay) - entry.mixDuration = mixDuration - entry.trackEnd = mixDuration - return entry + if delay <= 0 then delay = delay - mixDuration end + local entry = self:addAnimation(trackIndex, EMPTY_ANIMATION, false, delay) + entry.mixDuration = mixDuration + entry.trackEnd = mixDuration + return entry end function AnimationState:setEmptyAnimations (mixDuration) - local queue = self.queue + local queue = self.queue local oldDrainDisabled = queue.drainDisabled - queue.drainDisabled = true - for i,current in pairs(self.tracks) do - if current then self:setEmptyAnimation(current.trackIndex, mixDuration) end - end - queue.drainDisabled = oldDrainDisabled - queue:drain() + queue.drainDisabled = true + for i,current in pairs(self.tracks) do + if current then self:setEmptyAnimation(current.trackIndex, mixDuration) end + end + queue.drainDisabled = oldDrainDisabled + queue:drain() end function AnimationState:expandToIndex (index) - return self.tracks[index] + return self.tracks[index] end function AnimationState:trackEntry (trackIndex, animation, loop, last) - local data = self.data - local entry = TrackEntry.new() - entry.trackIndex = trackIndex - entry.animation = animation - entry.loop = loop + local data = self.data + local entry = TrackEntry.new() + entry.trackIndex = trackIndex + entry.animation = animation + entry.loop = loop entry.holdPrevious = false - entry.eventThreshold = 0 - entry.attachmentThreshold = 0 - entry.drawOrderThreshold = 0 + entry.eventThreshold = 0 + entry.attachmentThreshold = 0 + entry.drawOrderThreshold = 0 - entry.animationStart = 0 - entry.animationEnd = animation.duration - entry.animationLast = -1 - entry.nextAnimationLast = -1 + entry.animationStart = 0 + entry.animationEnd = animation.duration + entry.animationLast = -1 + entry.nextAnimationLast = -1 - entry.delay = 0 - entry.trackTime = 0 - entry.trackLast = -1 - entry.nextTrackLast = -1 - entry.trackEnd = 999999999 - entry.timeScale = 1 + entry.delay = 0 + entry.trackTime = 0 + entry.trackLast = -1 + entry.nextTrackLast = -1 + entry.trackEnd = 999999999 + entry.timeScale = 1 - entry.alpha = 1 - entry.interruptAlpha = 1 - entry.mixTime = 0 - if not last then - entry.mixDuration = 0 - else - entry.mixDuration = data:getMix(last.animation, animation) - end + entry.alpha = 1 + entry.interruptAlpha = 1 + entry.mixTime = 0 + if not last then + entry.mixDuration = 0 + else + entry.mixDuration = data:getMix(last.animation, animation) + end entry.mixBlend = MixBlend.replace - return entry + return entry end function AnimationState:disposeNext (entry) - local _next = entry.next - local queue = self.queue - while _next do - queue:dispose(_next) - _next = _next.next - end - entry.next = nil + local _next = entry.next + local queue = self.queue + while _next do + queue:dispose(_next) + _next = _next.next + end + entry.next = nil end function AnimationState:_animationsChanged () @@ -847,7 +846,7 @@ function AnimationState:computeNotLast(entry) local timelinesCount = #entry.animation.timelines local timelineMode = entry.timelineMode local propertyIDs = self.propertyIDs - + local i = 1 while i <= timelinesCount do local timeline = timelines[i] @@ -892,9 +891,9 @@ function AnimationState:computeHold(entry) else propertyIDs[id] = id local timeline = timelines[i] - if to == nil or timeline.type == Animation.TimelineType.attachment - or timeline.type == Animation.TimelineType.drawOrder - or timeline.type == Animation.TimelineType.event + if to == nil or timeline.type == Animation.TimelineType.attachment + or timeline.type == Animation.TimelineType.drawOrder + or timeline.type == Animation.TimelineType.event or not self:hasTimeline(to, id) then timelineMode[i] = FIRST else @@ -927,20 +926,20 @@ function AnimationState:hasTimeline(entry, id) end function AnimationState:getCurrent (trackIndex) - return self.tracks[trackIndex] + return self.tracks[trackIndex] end function AnimationState:clearListeners () - self.onStart = nil - self.onInterrupt = nil - self.onEnd = nil - self.onComplete = nil - self.onDispose = nil - self.onEvent = nil + self.onStart = nil + self.onInterrupt = nil + self.onEnd = nil + self.onComplete = nil + self.onDispose = nil + self.onEvent = nil end function AnimationState:clearListenerNotificatin () - self.queue:clear() + self.queue:clear() end return AnimationState diff --git a/spine-lua/AttachmentLoader.lua b/spine-lua/AttachmentLoader.lua index 4d89d31d6..58f0d4d1a 100644 --- a/spine-lua/AttachmentLoader.lua +++ b/spine-lua/AttachmentLoader.lua @@ -54,11 +54,11 @@ function AttachmentLoader.new () function self:newPathAttachment(skin, name) return PathAttachment.new(name) end - + function self:newPointAttachment(skin, name) return PointAttachment.new(name) end - + function self:newClippingAttachment(skin, name) return ClippingAttachment.new(name) end diff --git a/spine-lua/Bone.lua b/spine-lua/Bone.lua index fad5a7632..a6875670a 100644 --- a/spine-lua/Bone.lua +++ b/spine-lua/Bone.lua @@ -70,7 +70,7 @@ function Bone.new (data, skeleton, parent) a = 0, b = 0, worldX = 0, -- a b x c = 0, d = 0, worldY = 0, -- c d y sorted = false, - active = false + active = false } setmetatable(self, Bone) diff --git a/spine-lua/BoneData.lua b/spine-lua/BoneData.lua index 304341a2f..b1bf13737 100644 --- a/spine-lua/BoneData.lua +++ b/spine-lua/BoneData.lua @@ -47,7 +47,7 @@ function BoneData.new (index, name, parent) shearX = 0, shearY = 0, inheritRotation = true, inheritScale = true, - skinRequired = false + skinRequired = false } return self diff --git a/spine-lua/IkConstraint.lua b/spine-lua/IkConstraint.lua index 3ba7ffc57..3e93c145e 100644 --- a/spine-lua/IkConstraint.lua +++ b/spine-lua/IkConstraint.lua @@ -52,11 +52,11 @@ function IkConstraint.new (data, skeleton) bones = {}, target = nil, mix = data.mix, - softness = data.softness, + softness = data.softness, compress = data.compress, stretch = data.stretch, bendDirection = data.bendDirection, - active = false + active = false } setmetatable(self, IkConstraint) @@ -171,36 +171,36 @@ function IkConstraint:apply2 (parent, child, targetX, targetY, bendDir, stretch, c = pp.c d = pp.d local id = 1 / (a * d - b * c) - local x = cwx - pp.worldX - local y = cwy - pp.worldY - local dx = (x * d - y * b) * id - px - local dy = (y * a - x * c) * id - py - local l1 = math_sqrt(dx * dx + dy * dy) - local l2 = child.data.length * csx - local a1 = 0 - local a2 = 0 - if l1 < 0.0001 then - self:apply1(parent, targetX, targetY, false, stretch, false, alpha) - child:updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY) - return - end - x = targetX - pp.worldX - y = targetY - pp.worldY - local tx = (x * d - y * b) * id - px - local ty = (y * a - x * c) * id - py - local dd = tx * tx + ty * ty - if softness ~= 0 then - softness = softness * (psx * (csx + 1) / 2) - local td = math_sqrt(dd) - local sd = td - l1 - l2 * psx + softness - if sd > 0 then - local p = math_min(1, sd / (softness * 2)) - 1 - p = (sd - softness * (1 - p * p)) / td - tx = tx - p * tx - ty = ty - p * ty - dd = tx * tx + ty * ty - end - end + local x = cwx - pp.worldX + local y = cwy - pp.worldY + local dx = (x * d - y * b) * id - px + local dy = (y * a - x * c) * id - py + local l1 = math_sqrt(dx * dx + dy * dy) + local l2 = child.data.length * csx + local a1 = 0 + local a2 = 0 + if l1 < 0.0001 then + self:apply1(parent, targetX, targetY, false, stretch, false, alpha) + child:updateWorldTransformWith(cx, cy, 0, child.ascaleX, child.ascaleY, child.ashearX, child.ashearY) + return + end + x = targetX - pp.worldX + y = targetY - pp.worldY + local tx = (x * d - y * b) * id - px + local ty = (y * a - x * c) * id - py + local dd = tx * tx + ty * ty + if softness ~= 0 then + softness = softness * (psx * (csx + 1) / 2) + local td = math_sqrt(dd) + local sd = td - l1 - l2 * psx + softness + if sd > 0 then + local p = math_min(1, sd / (softness * 2)) - 1 + p = (sd - softness * (1 - p * p)) / td + tx = tx - p * tx + ty = ty - p * ty + dd = tx * tx + ty * ty + end + end if u then l2 = l2 * psx diff --git a/spine-lua/IkConstraintData.lua b/spine-lua/IkConstraintData.lua index d146d8240..1669bdeb8 100644 --- a/spine-lua/IkConstraintData.lua +++ b/spine-lua/IkConstraintData.lua @@ -34,7 +34,7 @@ function IkConstraintData.new (name) local self = { name = name, order = 0, - skinRequired = false, + skinRequired = false, bones = {}, target = nil, bendDirection = 1, @@ -42,7 +42,7 @@ function IkConstraintData.new (name) stretch = false, uniform = false, mix = 1, - softness = 0 + softness = 0 } return self diff --git a/spine-lua/PathConstraint.lua b/spine-lua/PathConstraint.lua index 5e2df0377..a74d89dc0 100644 --- a/spine-lua/PathConstraint.lua +++ b/spine-lua/PathConstraint.lua @@ -74,7 +74,7 @@ function PathConstraint.new (data, skeleton) curves = {}, lengths = {}, segments = {}, - active = false + active = false } setmetatable(self, PathConstraint) @@ -99,7 +99,7 @@ function PathConstraint:update () local rotate = rotateMix > 0 if not translate and not rotate then return end - local data = self.data; + local data = self.data; local percentSpacing = data.spacingMode == PathConstraintData.SpacingMode.percent local rotateMode = data.rotateMode local tangents = rotateMode == PathConstraintData.RotateMode.tangent @@ -119,10 +119,10 @@ function PathConstraint:update () while i < n do local bone = bones[i + 1]; local setupLength = bone.data.length - if setupLength < PathConstraint.epsilon then - if scale then lengths[i + 1] = 0 end - i = i + 1 - spaces[i + 1] = 0 + if setupLength < PathConstraint.epsilon then + if scale then lengths[i + 1] = 0 end + i = i + 1 + spaces[i + 1] = 0 elseif percentSpacing then if scale then local x = setupLength * bone.a @@ -132,18 +132,18 @@ function PathConstraint:update () end i = i + 1 spaces[i + 1] = spacing - else - local x = setupLength * bone.a - local y = setupLength * bone.c - local length = math_sqrt(x * x + y * y) - if scale then lengths[i + 1] = length end - i = i + 1 - if lengthSpacing then - spaces[i + 1] = (setupLength + spacing) * length / setupLength - else - spaces[i + 1] = spacing * length / setupLength - end - end + else + local x = setupLength * bone.a + local y = setupLength * bone.c + local length = math_sqrt(x * x + y * y) + if scale then lengths[i + 1] = length end + i = i + 1 + if lengthSpacing then + spaces[i + 1] = (setupLength + spacing) * length / setupLength + else + spaces[i + 1] = spacing * length / setupLength + end + end end else local i = 1 @@ -205,7 +205,7 @@ function PathConstraint:update () else r = math_atan2(dy, dx) end - r = r - math_atan2(c, a) + r = r - math_atan2(c, a) if tip then cos = math_cos(r) sin = math_sin(r) @@ -389,7 +389,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc i = i + 1 w = w + 6 end - if percentPosition then + if percentPosition then position = position * pathLength else position = position * pathLength / path.lengths[curveCount]; @@ -533,11 +533,11 @@ end function PathConstraint:addCurvePosition(p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, out, o, tangents) if p == 0 or (p ~= p) then - out[o + 1] = x1 + out[o + 1] = x1 out[o + 2] = y1 out[o + 3] = math_atan2(cy1 - y1, cx1 - x1) return; - end + end local tt = p * p local ttt = tt * p local u = 1 - p @@ -551,13 +551,13 @@ function PathConstraint:addCurvePosition(p, x1, y1, cx1, cy1, cx2, cy2, x2, y2, local y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt out[o + 1] = x out[o + 2] = y - if tangents then - if p < 0.001 then - out[o + 3] = math_atan2(cy1 - y1, cx1 - x1) - else - out[o + 3] = math_atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)) - end - end + if tangents then + if p < 0.001 then + out[o + 3] = math_atan2(cy1 - y1, cx1 - x1) + else + out[o + 3] = math_atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)) + end + end end return PathConstraint diff --git a/spine-lua/PathConstraintData.lua b/spine-lua/PathConstraintData.lua index ab99808dc..a384b8d62 100644 --- a/spine-lua/PathConstraintData.lua +++ b/spine-lua/PathConstraintData.lua @@ -34,7 +34,7 @@ function PathConstraintData.new (name) local self = { name = name, order = 0, - skinRequired = false, + skinRequired = false, bones = {}, target = nil, positionMode = nil, diff --git a/spine-lua/Skeleton.lua b/spine-lua/Skeleton.lua index a4e5ba67f..0763d738c 100644 --- a/spine-lua/Skeleton.lua +++ b/spine-lua/Skeleton.lua @@ -114,21 +114,21 @@ function Skeleton:updateCache () local bones = self.bones for _, bone in ipairs(bones) do - bone.sorted = bone.data.skinRequired + bone.sorted = bone.data.skinRequired bone.active = not bone.sorted end - - if self.skin then - local skinBones = self.skin.bones - for i, boneData in ipairs(skinBones) do - local bone = bones[boneData.index] - while bone do - bone.sorted = false - bone.active = true - bone = bone.parent - end - end - end + + if self.skin then + local skinBones = self.skin.bones + for i, boneData in ipairs(skinBones) do + local bone = bones[boneData.index] + while bone do + bone.sorted = false + bone.active = true + bone = bone.parent + end + end + end local ikConstraints = self.ikConstraints local transformConstraints = self.transformConstraints @@ -137,7 +137,7 @@ function Skeleton:updateCache () local transformCount = #transformConstraints local pathCount = #pathConstraints local constraintCount = ikCount + transformCount + pathCount - + local i = 0 while i < constraintCount do local found = false @@ -151,7 +151,7 @@ function Skeleton:updateCache () end ii = ii + 1 end - + if not found then ii = 1 while ii <= transformCount do @@ -164,7 +164,7 @@ function Skeleton:updateCache () ii = ii + 1 end end - + if not found then ii = 1 while ii <= pathCount do @@ -176,26 +176,26 @@ function Skeleton:updateCache () ii = ii + 1 end end - + i = i + 1 end - + for _, bone in ipairs(self.bones) do self:sortBone(bone) end end function Skeleton:sortIkConstraint (constraint) - constraint.active = constraint.target.active and ((not constraint.data.skinRequired) or (self.skin and utils.arrayContains(self.skin.constraints, constraint))) - if not constraint.active then return end - + constraint.active = constraint.target.active and ((not constraint.data.skinRequired) or (self.skin and utils.arrayContains(self.skin.constraints, constraint))) + if not constraint.active then return end + local target = constraint.target self:sortBone(target) - + local constrained = constraint.bones local parent = constrained[1] self:sortBone(parent) - + if #constrained > 1 then local child = constrained[#constrained] local contains = false @@ -207,17 +207,17 @@ function Skeleton:sortIkConstraint (constraint) end if not contains then table_insert(self.updateCacheReset, child) end end - + table_insert(self._updateCache, constraint) - + self:sortReset(parent.children) constrained[#constrained].sorted = true end function Skeleton:sortPathConstraint(constraint) - constraint.active = constraint.target.bone.active and ((not constraint.data.skinRequired) or (self.skin and utils.arrayContains(self.skin.constraints, constraint))) - if not constraint.active then return end - + constraint.active = constraint.target.bone.active and ((not constraint.data.skinRequired) or (self.skin and utils.arrayContains(self.skin.constraints, constraint))) + if not constraint.active then return end + local slot = constraint.target local slotIndex = slot.data.index local slotBone = slot.bone @@ -228,33 +228,33 @@ function Skeleton:sortPathConstraint(constraint) for _,skin in ipairs(self.data.skins) do self:sortPathConstraintAttachment(skin, slotIndex, slotBone) end - + local attachment = slot.attachment if attachment and attachment.type == AttachmentType.path then self:sortPathConstraintAttachmentWith(attachment, slotBone) end - + local constrained = constraint.bones for _,bone in ipairs(constrained) do self:sortBone(bone) end - + table_insert(self._updateCache, constraint) - + for _,bone in ipairs(constrained) do self:sortReset(bone.children) end - + for _,bone in ipairs(constrained) do bone.sorted = true end end function Skeleton:sortTransformConstraint(constraint) - constraint.active = constraint.target.active and ((not constraint.data.skinRequired) or (self.skin and utils.arrayContains(self.skin.constraints, constraint))) - if not constraint.active then return end - + constraint.active = constraint.target.active and ((not constraint.data.skinRequired) or (self.skin and utils.arrayContains(self.skin.constraints, constraint))) + if not constraint.active then return end + self:sortBone(constraint.target) - - local constrained = constraint.bones + + local constrained = constraint.bones if constraint.data.local_ then for _,bone in ipairs(constrained) do local child = constrained[#constrained] @@ -273,13 +273,13 @@ function Skeleton:sortTransformConstraint(constraint) self:sortBone(bone) end end - + table_insert(self._updateCache, constraint) - + for _,bone in ipairs(constrained) do self:sortReset(bone.children) end - + for _,bone in ipairs(constrained) do bone.sorted = true end @@ -324,10 +324,10 @@ end function Skeleton:sortReset(bones) for _, bone in ipairs(bones) do - if bone.active then - if bone.sorted then self:sortReset(bone.children) end - bone.sorted = false - end + if bone.active then + if bone.sorted then self:sortReset(bone.children) end + bone.sorted = false + end end end @@ -344,7 +344,7 @@ function Skeleton:updateWorldTransform () bone.ashearY = bone.shearY bone.appliedValid = true end - + local updateCache = self._updateCache for _, updatable in ipairs(updateCache) do updatable:update() @@ -363,7 +363,7 @@ function Skeleton:setBonesToSetupPose () for _,ikConstraint in ipairs(self.ikConstraints) do ikConstraint.mix = ikConstraint.data.mix - ikConstraint.softness = ikConstraint.data.softness + ikConstraint.softness = ikConstraint.data.softness ikConstraint.bendDirection = ikConstraint.data.bendDirection ikConstraint.compress = ikConstraint.data.compress ikConstraint.stretch = ikConstraint.data.stretch @@ -438,7 +438,7 @@ function Skeleton:setSkin (skinName) end function Skeleton:setSkinByReference(newSkin) - if (self.skin == newSkin) then return end + if (self.skin == newSkin) then return end if newSkin then if self.skin then newSkin:attachAll(self, self.skin) @@ -456,7 +456,7 @@ function Skeleton:setSkinByReference(newSkin) end end self.skin = newSkin - self:updateCache() + self:updateCache() end function Skeleton:getAttachment (slotName, attachmentName) @@ -518,43 +518,43 @@ function Skeleton:findPathConstraint(constraintName) end function Skeleton:getBounds(offset, size) - if not offset then error("offset cannot be null.", 2) end - if not size then error("size cannot be null.", 2) end - local drawOrder = self.drawOrder; - local minX = 99999999 - local minY = 99999999 - local maxX = -99999999 - local maxY = -99999999 - for _, slot in ipairs(drawOrder) do - if slot.bone.active then - local vertices = {} - local attachment = slot.attachment - if attachment then - if attachment.type == AttachmentType.region then - attachment:computeWorldVertices(slot.bone, vertices, 0, 2) - elseif attachment.type == AttachmentType.mesh then - attachment:computeWorldVertices(slot, 0, attachment.worldVerticesLength, vertices, 0, 2) - end - end - if #vertices > 0 then - local nn = #vertices - local ii = 1 - while ii <= nn do - local x = vertices[ii] - local y = vertices[ii + 1] - minX = math_min(minX, x) - minY = math_min(minY, y) - maxX = math_max(maxX, x) - maxY = math_max(maxY, y) - ii = ii + 2 - end - end - end + if not offset then error("offset cannot be null.", 2) end + if not size then error("size cannot be null.", 2) end + local drawOrder = self.drawOrder; + local minX = 99999999 + local minY = 99999999 + local maxX = -99999999 + local maxY = -99999999 + for _, slot in ipairs(drawOrder) do + if slot.bone.active then + local vertices = {} + local attachment = slot.attachment + if attachment then + if attachment.type == AttachmentType.region then + attachment:computeWorldVertices(slot.bone, vertices, 0, 2) + elseif attachment.type == AttachmentType.mesh then + attachment:computeWorldVertices(slot, 0, attachment.worldVerticesLength, vertices, 0, 2) + end end - offset[1] = minX - offset[2] = minY - size[1] = maxX - minX - size[2] = maxY - minY + if #vertices > 0 then + local nn = #vertices + local ii = 1 + while ii <= nn do + local x = vertices[ii] + local y = vertices[ii + 1] + minX = math_min(minX, x) + minY = math_min(minY, y) + maxX = math_max(maxX, x) + maxY = math_max(maxY, y) + ii = ii + 2 + end + end + end + end + offset[1] = minX + offset[2] = minY + size[1] = maxX - minX + size[2] = maxY - minY end function Skeleton:update (delta) diff --git a/spine-lua/SkeletonBounds.lua b/spine-lua/SkeletonBounds.lua index d59fe5e93..f57e990b8 100644 --- a/spine-lua/SkeletonBounds.lua +++ b/spine-lua/SkeletonBounds.lua @@ -59,28 +59,28 @@ function SkeletonBounds:update (skeleton, updateAabb) local slots = skeleton.slots for _,slot in ipairs(skeleton.slots) do - if (slot.bone.active) then - local attachment = slot.attachment - if attachment and attachment.type == AttachmentType.boundingbox then - local boundingBox = attachment - table_insert(boundingBoxes, boundingBox) + if (slot.bone.active) then + local attachment = slot.attachment + if attachment and attachment.type == AttachmentType.boundingbox then + local boundingBox = attachment + table_insert(boundingBoxes, boundingBox) - local polygon = {} - table_insert(polygons, polygon) + local polygon = {} + table_insert(polygons, polygon) - boundingBox:computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2) - end - end + boundingBox:computeWorldVertices(slot, 0, boundingBox.worldVerticesLength, polygon, 0, 2) + end + end end - if updateAabb then - self:aabbCompute() - else - self.minX = 9999999 - self.minY = 9999999 - self.maxX = -9999999 - self.maxY = -9999999 - end + if updateAabb then + self:aabbCompute() + else + self.minX = 9999999 + self.minY = 9999999 + self.maxX = -9999999 + self.maxY = -9999999 + end end function SkeletonBounds:aabbCompute () diff --git a/spine-lua/SkeletonClipping.lua b/spine-lua/SkeletonClipping.lua index 53a574349..928f63e33 100644 --- a/spine-lua/SkeletonClipping.lua +++ b/spine-lua/SkeletonClipping.lua @@ -48,7 +48,7 @@ function SkeletonClipping.new () clipOutput = {}, clippedVertices = {}, clippedUVs = {}, - clippedTriangles = {}, + clippedTriangles = {}, clipAttachment = nil } setmetatable(self, SkeletonClipping) @@ -59,7 +59,7 @@ end function SkeletonClipping:clipStart(slot, clip) if self.clipAttachment then return 0 end self.clipAttachment = clip - + local n = clip.worldVerticesLength self.clippingPolygon = {} local vertices = self.clippingPolygon @@ -69,7 +69,7 @@ function SkeletonClipping:clipStart(slot, clip) for _,polygon in ipairs(self.clippingPolygons) do self:makeClockwise(polygon) table_insert(polygon, polygon[1]) - table_insert(polygon, polygon[2]) + table_insert(polygon, polygon[2]) end return #self.clippingPolygons end @@ -103,7 +103,7 @@ function SkeletonClipping:clipTriangles(vertices, uvs, triangles, trianglesLengt local polygonsCount = #self.clippingPolygons local index = 1 - + local i = 1 while i <= trianglesLength do local vertexOffset = (triangles[i] - 1) * 2 + 1 @@ -146,7 +146,7 @@ function SkeletonClipping:clipTriangles(vertices, uvs, triangles, trianglesLengt local x = clipOutputItems[ii] local y = clipOutputItems[ii + 1] clippedVerticesItems[s] = x - clippedVerticesItems[s + 1] = y + clippedVerticesItems[s + 1] = y local c0 = x - x3 local c1 = y - y3 local a = (d0 * c0 + d1 * c1) * d @@ -186,7 +186,7 @@ function SkeletonClipping:clipTriangles(vertices, uvs, triangles, trianglesLengt clippedUVsItems[s + 2] = u2 clippedUVsItems[s + 3] = v2 clippedUVsItems[s + 4] = u3 - clippedUVsItems[s + 5] = v3 + clippedUVsItems[s + 5] = v3 s = #clippedTriangles + 1 local clippedTrianglesItems = clippedTriangles @@ -280,7 +280,7 @@ function SkeletonClipping:clip(x1, y1, x2, y2, x3, y3, clippingArea, output) end table_insert(output, inputX2) table_insert(output, inputY2) - end + end if not continue then clipped = true end ii = ii + 2 end diff --git a/spine-lua/SkeletonJson.lua b/spine-lua/SkeletonJson.lua index 7f8a5328d..56d72e3ab 100644 --- a/spine-lua/SkeletonJson.lua +++ b/spine-lua/SkeletonJson.lua @@ -111,7 +111,7 @@ function SkeletonJson.new (attachmentLoader) data.shearX = getValue(boneMap, "shearX", 0); data.shearY = getValue(boneMap, "shearY", 0); data.transformMode = TransformMode[getValue(boneMap, "transform", "normal")] - data.skinRequired = getValue(boneMap, "skin", false) + data.skinRequired = getValue(boneMap, "skin", false) table_insert(skeletonData.bones, data) end @@ -128,18 +128,18 @@ function SkeletonJson.new (attachmentLoader) local color = slotMap["color"] if color then data.color:set(tonumber(color:sub(1, 2), 16) / 255, - tonumber(color:sub(3, 4), 16) / 255, - tonumber(color:sub(5, 6), 16) / 255, - tonumber(color:sub(7, 8), 16) / 255) + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) end local dark = slotMap["dark"] if dark then data.darkColor = Color.newWith(1, 1, 1, 1) data.darkColor:set(tonumber(dark:sub(1, 2), 16) / 255, - tonumber(dark:sub(3, 4), 16) / 255, - tonumber(dark:sub(5, 6), 16) / 255, - 0) + tonumber(dark:sub(3, 4), 16) / 255, + tonumber(dark:sub(5, 6), 16) / 255, + 0) end data.attachmentName = getValue(slotMap, "attachment", nil) @@ -155,7 +155,7 @@ function SkeletonJson.new (attachmentLoader) for _,constraintMap in ipairs(root["ik"]) do local data = IkConstraintData.new(constraintMap["name"]) data.order = getValue(constraintMap, "order", 0) - data.skinRequired = getValue(constraintMap, "skin", false) + data.skinRequired = getValue(constraintMap, "skin", false) for _,boneName in ipairs(constraintMap["bones"]) do local bone = skeletonData:findBone(boneName) @@ -168,15 +168,15 @@ function SkeletonJson.new (attachmentLoader) if not data.target then error("Target bone not found: " .. targetName) end data.mix = getValue(constraintMap, "mix", 1) - data.softness = getValue(constraintMap, "softness", 0) * scale + data.softness = getValue(constraintMap, "softness", 0) * scale if constraintMap["bendPositive"] == nil or constraintMap["bendPositive"] == true then - data.bendDirection = 1 - else - data.bendDirection = -1 - end + data.bendDirection = 1 + else + data.bendDirection = -1 + end if constraintMap["compress"] == nil or constraintMap["compress"] == false then data.compress = false else data.compress = true end - if constraintMap["stretch"] == nil or constraintMap["stretch"] == false then data.stretch = false else data.stretch = true end - if constraintMap["uniform"] == nil or constraintMap["uniform"] == false then data.uniform = false else data.uniform = true end + if constraintMap["stretch"] == nil or constraintMap["stretch"] == false then data.stretch = false else data.stretch = true end + if constraintMap["uniform"] == nil or constraintMap["uniform"] == false then data.uniform = false else data.uniform = true end table_insert(skeletonData.ikConstraints, data) end @@ -187,7 +187,7 @@ function SkeletonJson.new (attachmentLoader) for _,constraintMap in ipairs(root["transform"]) do local data = TransformConstraintData.new(constraintMap.name) data.order = getValue(constraintMap, "order", 0) - data.skinRequired = getValue(constraintMap, "skin", false) + data.skinRequired = getValue(constraintMap, "skin", false) for _,boneName in ipairs(constraintMap.bones) do local bone = skeletonData:findBone(boneName) @@ -220,7 +220,7 @@ function SkeletonJson.new (attachmentLoader) for _,constraintMap in ipairs(root.path) do local data = PathConstraintData.new(constraintMap.name); data.order = getValue(constraintMap, "order", 0) - data.skinRequired = getValue(constraintMap, "skin", false) + data.skinRequired = getValue(constraintMap, "skin", false) for _,boneName in ipairs(constraintMap.bones) do local bone = skeletonData:findBone(boneName) @@ -272,12 +272,12 @@ function SkeletonJson.new (attachmentLoader) if not skin then error("Skin not found: " .. linkedMesh.skin) end local parent = skin:getAttachment(linkedMesh.slotIndex, linkedMesh.parent) if not parent then error("Parent mesh not found: " + linkedMesh.parent) end - if linkedMesh.inheritDeform then - linkedMesh.mesh.deformAttachment = parent - else - linkedMesh.mesh.deformAttachment = linkedMesh.mesh - end - + if linkedMesh.inheritDeform then + linkedMesh.mesh.deformAttachment = parent + else + linkedMesh.mesh.deformAttachment = linkedMesh.mesh + end + linkedMesh.mesh:setParentMesh(parent) linkedMesh.mesh:updateUVs() end @@ -331,9 +331,9 @@ function SkeletonJson.new (attachmentLoader) local color = map["color"] if color then region.color:set(tonumber(color:sub(1, 2), 16) / 255, - tonumber(color:sub(3, 4), 16) / 255, - tonumber(color:sub(5, 6), 16) / 255, - tonumber(color:sub(7, 8), 16) / 255) + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) end region:updateOffset() @@ -346,9 +346,9 @@ function SkeletonJson.new (attachmentLoader) local color = map.color if color then box.color:set(tonumber(color:sub(1, 2), 16) / 255, - tonumber(color:sub(3, 4), 16) / 255, - tonumber(color:sub(5, 6), 16) / 255, - tonumber(color:sub(7, 8), 16) / 255) + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) end return box @@ -360,22 +360,22 @@ function SkeletonJson.new (attachmentLoader) local color = map.color if color then mesh.color:set(tonumber(color:sub(1, 2), 16) / 255, - tonumber(color:sub(3, 4), 16) / 255, - tonumber(color:sub(5, 6), 16) / 255, - tonumber(color:sub(7, 8), 16) / 255) + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) end - - mesh.width = getValue(map, "width", 0) * scale - mesh.height = getValue(map, "height", 0) * scale + + mesh.width = getValue(map, "width", 0) * scale + mesh.height = getValue(map, "height", 0) * scale local parent = map.parent if parent then table_insert(self.linkedMeshes, { - mesh = mesh, - skin = getValue(map, "skin", nil), - slotIndex = slotIndex, - parent = parent, - inheritDeform = getValue(map, "deform", true) + mesh = mesh, + skin = getValue(map, "skin", nil), + slotIndex = slotIndex, + parent = parent, + inheritDeform = getValue(map, "deform", true) }) return mesh end @@ -411,46 +411,46 @@ function SkeletonJson.new (attachmentLoader) local color = map.color if color then path.color:set(tonumber(color:sub(1, 2), 16) / 255, - tonumber(color:sub(3, 4), 16) / 255, - tonumber(color:sub(5, 6), 16) / 255, - tonumber(color:sub(7, 8), 16) / 255) + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) end return path; - + elseif type == AttachmentType.point then local point = self.attachmentLoader:newPointAttachment(skin, name) if not point then return nil end point.x = getValue(map, "x", 0) * scale point.y = getValue(map, "y", 0) * scale point.rotation = getValue(map, "rotation", 0) - + local color = map.color if color then path.color:set(tonumber(color:sub(1, 2), 16) / 255, - tonumber(color:sub(3, 4), 16) / 255, - tonumber(color:sub(5, 6), 16) / 255, - tonumber(color:sub(7, 8), 16) / 255) + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) end return point - + elseif type == AttachmentType.clipping then local clip = attachmentLoader:newClippingAttachment(skin, name) if not clip then return nil end - + local _end = getValue(map, "end", nil) if _end then local slot = skeletonData:findSlot(_end) if not slot then error("Clipping end slot not found: " + _end) end clip.endSlot = slot end - + readVertices(map, clip, map.vertexCount * 2) local color = map.color if color then clip.color:set(tonumber(color:sub(1, 2), 16) / 255, - tonumber(color:sub(3, 4), 16) / 255, - tonumber(color:sub(5, 6), 16) / 255, - tonumber(color:sub(7, 8), 16) / 255) + tonumber(color:sub(3, 4), 16) / 255, + tonumber(color:sub(5, 6), 16) / 255, + tonumber(color:sub(7, 8), 16) / 255) end return clip end @@ -594,10 +594,10 @@ function SkeletonJson.new (attachmentLoader) elseif timelineName == "translate" or timelineName == "scale" or timelineName == "shear" then local timeline local timelineScale = 1 - local defaultValue = 0 + local defaultValue = 0 if timelineName == "scale" then timeline = Animation.ScaleTimeline.new(#values) - defaultValue = 1 + defaultValue = 1 elseif timelineName == "shear" then timeline = Animation.ShearTimeline.new(#values) else @@ -638,9 +638,9 @@ function SkeletonJson.new (attachmentLoader) local frameIndex = 0 for _,valueMap in ipairs(values) do local mix = 1 - local softness = 0 + local softness = 0 if valueMap["mix"] ~= nil then mix = valueMap["mix"] end - if valueMap["softness"] ~= nil then softness = valueMap["softness"] * scale end + if valueMap["softness"] ~= nil then softness = valueMap["softness"] * scale end local bendPositive = 1 if valueMap["bendPositive"] == false then bendPositive = -1 end local stretch = false diff --git a/spine-lua/Skin.lua b/spine-lua/Skin.lua index 01372587f..081dfe3d9 100644 --- a/spine-lua/Skin.lua +++ b/spine-lua/Skin.lua @@ -35,14 +35,14 @@ local SkinEntry = {} SkinEntry.__index = SkinEntry function SkinEntry.new (slotIndex, name, attachment) - local self = { - slotIndex = slotIndex, - name = name, - attachment = attachment - } - setmetatable(self, SkinEntry) - - return self + local self = { + slotIndex = slotIndex, + name = name, + attachment = attachment + } + setmetatable(self, SkinEntry) + + return self end local Skin = {} @@ -54,8 +54,8 @@ function Skin.new (name) local self = { name = name, attachments = {}, - bones = {}, - constraints = {} + bones = {}, + constraints = {} } setmetatable(self, Skin) @@ -69,67 +69,67 @@ function Skin:setAttachment (slotIndex, name, attachment) end function Skin:addSkin (skin) - for i, bone in ipairs(skin.bones) do - local contained = false - for j, otherBone in ipairs(self.bones) do - if otherBone == bone then - contained = true - break - end - end - if not contained then table_insert(self.bones, bone) end - end - - for i, constraint in ipairs(skin.constraints) do - local contained = false - for j, otherConstraint in ipairs(self.constraints) do - if otherConstraint == constraint then - contained = true - break - end - end - if not contained then table_insert(self.constraints, constraint) end - end - - local attachments = skin:getAttachments() - for i, entry in ipairs(attachments) do - self:setAttachment(entry.slotIndex, entry.name, entry.attachment) - end + for i, bone in ipairs(skin.bones) do + local contained = false + for j, otherBone in ipairs(self.bones) do + if otherBone == bone then + contained = true + break + end + end + if not contained then table_insert(self.bones, bone) end + end + + for i, constraint in ipairs(skin.constraints) do + local contained = false + for j, otherConstraint in ipairs(self.constraints) do + if otherConstraint == constraint then + contained = true + break + end + end + if not contained then table_insert(self.constraints, constraint) end + end + + local attachments = skin:getAttachments() + for i, entry in ipairs(attachments) do + self:setAttachment(entry.slotIndex, entry.name, entry.attachment) + end end function Skin:copySkin (skin) - for i, bone in ipairs(skin.bones) do - local contained = false - for j, otherBone in ipairs(self.bones) do - if otherBone == bone then - contained = true - break - end - end - if not contained then table_insert(self.bones, bone) end - end - - for i, constraint in ipairs(skin.constraints) do - local contained = false - for j, otherConstraint in ipairs(self.constraints) do - if otherConstraint == constraint then - contained = true - break - end - end - if not contained then table_insert(self.constraints, constraint) end - end - - local attachments = skin:getAttachments() - for i, entry in ipairs(attachments) do - if entry.attachment.type == AttachmentType.mesh then - entry.attachment = entry.attachment:newLinkedMesh() - self:setAttachment(entry.slotIndex, entry.name, entry.attachment) - else - entry.attachment = entry.attachment:copy() - self:setAttachment(entry.slotIndex, entry.name, entry.attachment) - end - end + for i, bone in ipairs(skin.bones) do + local contained = false + for j, otherBone in ipairs(self.bones) do + if otherBone == bone then + contained = true + break + end + end + if not contained then table_insert(self.bones, bone) end + end + + for i, constraint in ipairs(skin.constraints) do + local contained = false + for j, otherConstraint in ipairs(self.constraints) do + if otherConstraint == constraint then + contained = true + break + end + end + if not contained then table_insert(self.constraints, constraint) end + end + + local attachments = skin:getAttachments() + for i, entry in ipairs(attachments) do + if entry.attachment.type == AttachmentType.mesh then + entry.attachment = entry.attachment:newLinkedMesh() + self:setAttachment(entry.slotIndex, entry.name, entry.attachment) + else + entry.attachment = entry.attachment:copy() + self:setAttachment(entry.slotIndex, entry.name, entry.attachment) + end + end end function Skin:getAttachment (slotIndex, name) @@ -143,43 +143,43 @@ function Skin:getAttachment (slotIndex, name) end function Skin:removeAttachment (slotIndex, name) - local slotAttachments = self.attachments[slotIndex] - if slotAttachments then - slotAttachments[name] = nil - end + local slotAttachments = self.attachments[slotIndex] + if slotAttachments then + slotAttachments[name] = nil + end end function Skin:getAttachments () - local entries = {} - for slotIndex, slotAttachments in pairs(self.attachments) do - if slotAttachments then - for name, attachment in pairs(slotAttachments) do - if attachment then - table_insert(entries, SkinEntry.new(slotIndex, name, attachment)) - end - end - end - end - return entries + local entries = {} + for slotIndex, slotAttachments in pairs(self.attachments) do + if slotAttachments then + for name, attachment in pairs(slotAttachments) do + if attachment then + table_insert(entries, SkinEntry.new(slotIndex, name, attachment)) + end + end + end + end + return entries end function Skin:getAttachmentsForSlot (slotIndex) - local entries = {} - local slotAttachments = self.attachments[slotIndex] - if slotAttachments then - for name, attachment in pairs(slotAttachments) do - if attachment then - table_insert(entries, SkinEntry.new(slotIndex, name, attachment)) - end - end - end - return entries + local entries = {} + local slotAttachments = self.attachments[slotIndex] + if slotAttachments then + for name, attachment in pairs(slotAttachments) do + if attachment then + table_insert(entries, SkinEntry.new(slotIndex, name, attachment)) + end + end + end + return entries end function Skin:clear () - self.attachments = {} - self.bones = {} - self.constraints = {} + self.attachments = {} + self.bones = {} + self.constraints = {} end function Skin:attachAll(skeleton, oldSkin) @@ -194,7 +194,7 @@ function Skin:attachAll(skeleton, oldSkin) local attachment = self:getAttachment(i, key) if attachment then print("Set attachment " .. attachment.name .. " on slot " .. slot.data.name) - slot:setAttachment(attachment) + slot:setAttachment(attachment) end break end diff --git a/spine-lua/Slot.lua b/spine-lua/Slot.lua index a78cd6e21..5672aae34 100644 --- a/spine-lua/Slot.lua +++ b/spine-lua/Slot.lua @@ -46,10 +46,10 @@ function Slot.new (data, bone) attachment = nil, attachmentTime = 0, deform = {} - } + } setmetatable(self, Slot) - + if data.darkColor then self.darkColor = Color.newWith(1, 1, 1, 1) end self:setToSetupPose() diff --git a/spine-lua/TextureAtlas.lua b/spine-lua/TextureAtlas.lua index eebd57aef..3dc1a5751 100644 --- a/spine-lua/TextureAtlas.lua +++ b/spine-lua/TextureAtlas.lua @@ -103,7 +103,7 @@ function TextureAtlas:parse (atlasContent, imageLoader) local readTuple = function () local line = readLine() local idx = line:find(":") - if not idx then + if not idx then error("Invalid line: " .. line, 2) end local i = 1 diff --git a/spine-lua/TransformConstraint.lua b/spine-lua/TransformConstraint.lua index 7ceab01c7..edf2181ca 100644 --- a/spine-lua/TransformConstraint.lua +++ b/spine-lua/TransformConstraint.lua @@ -55,7 +55,7 @@ function TransformConstraint.new (data, skeleton) target = nil, rotateMix = data.rotateMix, translateMix = data.translateMix, scaleMix = data.scaleMix, shearMix = data.shearMix, temp = { 0, 0 }, - active = false + active = false } setmetatable(self, TransformConstraint) @@ -169,7 +169,7 @@ function TransformConstraint:applyAbsoluteWorld () bone.d = math_sin(r) * s modified = true end - + if modified then bone.appliedValid = false end end end @@ -191,7 +191,7 @@ function TransformConstraint:applyRelativeWorld () local bones = self.bones for _, bone in ipairs(bones) do local modified = false - + if rotateMix ~= 0 then local a = bone.a local b = bone.b @@ -248,7 +248,7 @@ function TransformConstraint:applyRelativeWorld () bone.d = math_sin(r) * s modified = true end - + if modified then bone.appliedValid = false end end end @@ -264,7 +264,7 @@ function TransformConstraint:applyAbsoluteLocal () for _, bone in ipairs(bones) do local modified = false if not bone.appliedValid then bone:updateAppliedTransform() end - + local rotation = bone.arotation if rotateMix ~= 0 then local r = target.arotation - rotation + self.data.offsetRotation @@ -305,7 +305,7 @@ function TransformConstraint:applyRelativeLocal () local rotateMix = self.rotateMix local translateMix = self.translateMix local scaleMix = self.scaleMix - local shearMix = self.shearMix + local shearMix = self.shearMix local target = self.target if not target.appliedValid then target:updateAppliedTransform() end local bones = self.bones diff --git a/spine-lua/TransformConstraintData.lua b/spine-lua/TransformConstraintData.lua index 995bee01d..e67e95be7 100644 --- a/spine-lua/TransformConstraintData.lua +++ b/spine-lua/TransformConstraintData.lua @@ -34,7 +34,7 @@ function TransformConstraintData.new (name) local self = { name = name, order = 0, - skinRequired = false, + skinRequired = false, bones = {}, target = nil, rotateMix = 0, translateMix = 0, scaleMix = 0, shearMix = 0, diff --git a/spine-lua/Triangulator.lua b/spine-lua/Triangulator.lua index 1d56f31dd..9a7ac612b 100644 --- a/spine-lua/Triangulator.lua +++ b/spine-lua/Triangulator.lua @@ -111,12 +111,12 @@ function Triangulator:triangulate (verticesArray) end ii = (ii + 1) % vertexCount end - if (not goToHead) then + if (not goToHead) then breakLoop = true break end end - + if breakLoop then break end if _next == 0 then @@ -308,7 +308,7 @@ function Triangulator:decompose(verticesArray, triangles) i = i - 1 end - return convexPolygons; + return convexPolygons; end function Triangulator:isConcave(index, vertexCount, vertices, indices) diff --git a/spine-lua/attachments/Attachment.lua b/spine-lua/attachments/Attachment.lua index 34b315b23..01a41dfe7 100644 --- a/spine-lua/attachments/Attachment.lua +++ b/spine-lua/attachments/Attachment.lua @@ -47,7 +47,7 @@ function Attachment.new (name, attachmentType) end function Attachment:copy () - error("Attachment copy not implemented.") + error("Attachment copy not implemented.") end return Attachment diff --git a/spine-lua/attachments/BoundingBoxAttachment.lua b/spine-lua/attachments/BoundingBoxAttachment.lua index 3144e7098..a8a7b02b8 100644 --- a/spine-lua/attachments/BoundingBoxAttachment.lua +++ b/spine-lua/attachments/BoundingBoxAttachment.lua @@ -45,9 +45,9 @@ function BoundingBoxAttachment.new (name) end function BoundingBoxAttachment:copy () - local copy = BoundingBoxAttachment.new(self.name) - self:copyTo(copy) - copy.color:setFrom(self.color) - return copy + local copy = BoundingBoxAttachment.new(self.name) + self:copyTo(copy) + copy.color:setFrom(self.color) + return copy end return BoundingBoxAttachment diff --git a/spine-lua/attachments/ClippingAttachment.lua b/spine-lua/attachments/ClippingAttachment.lua index 52933141b..f0a28b222 100644 --- a/spine-lua/attachments/ClippingAttachment.lua +++ b/spine-lua/attachments/ClippingAttachment.lua @@ -46,11 +46,11 @@ function ClippingAttachment.new (name) end function ClippingAttachment:copy () - local copy = ClippingAttachment.new(self.name) - self:copyTo(copy) - copy.endSlot = self.endSlot - copy.color:setFrom(self.color) - return copy + local copy = ClippingAttachment.new(self.name) + self:copyTo(copy) + copy.endSlot = self.endSlot + copy.color:setFrom(self.color) + return copy end return ClippingAttachment diff --git a/spine-lua/attachments/MeshAttachment.lua b/spine-lua/attachments/MeshAttachment.lua index 0f9e94dba..2f3eefbd7 100644 --- a/spine-lua/attachments/MeshAttachment.lua +++ b/spine-lua/attachments/MeshAttachment.lua @@ -50,8 +50,8 @@ function MeshAttachment.new (name) self.hullLength = 0 self.parentMesh = nil self.tempColor = Color.newWith(1, 1, 1, 1) - self.width = 0 - self.height = 0 + self.width = 0 + self.height = 0 setmetatable(self, MeshAttachment) return self end @@ -61,11 +61,11 @@ function MeshAttachment:updateUVs () local v = 0 local width = 0 local height = 0 - + local regionUVs = self.regionUVs if not self.uvs or (#self.uvs ~= #regionUVs) then self.uvs = utils.newNumberArray(#regionUVs) end local uvs = self.uvs - + if not self.region then u = 0 v = 0 @@ -75,7 +75,7 @@ function MeshAttachment:updateUVs () local region = self.region local textureWidth = region.page.width local textureHeight = region.page.height - + if region.degrees == 90 then u = region.u - (region.originalHeight - region.offsetY - region.height) / textureWidth v = region.v - (region.originalWidth - region.offsetX - region.width) / textureHeight @@ -141,40 +141,40 @@ function MeshAttachment:setParentMesh (parentMesh) end function MeshAttachment:copy () - if self.parentMesh then return self:newLinkedMesh() end - - local copy = MeshAttachment.new(self.name) - copy.region = self.region - copy.path = self.path - copy.color:setFrom(self.color) + if self.parentMesh then return self:newLinkedMesh() end - self:copyTo(copy) - copy.regionUVs = utils.copy(self.regionUVs) - copy.uvs = utils.copy(self.uvs) - copy.triangles = utils.copy(self.triangles) - copy.hullLength = self.hullLength - if self.edges then - copy.edges = utils.copy(edges) - end - copy.width = self.width - copy.height = self.height - - return copy + local copy = MeshAttachment.new(self.name) + copy.region = self.region + copy.path = self.path + copy.color:setFrom(self.color) + + self:copyTo(copy) + copy.regionUVs = utils.copy(self.regionUVs) + copy.uvs = utils.copy(self.uvs) + copy.triangles = utils.copy(self.triangles) + copy.hullLength = self.hullLength + if self.edges then + copy.edges = utils.copy(edges) + end + copy.width = self.width + copy.height = self.height + + return copy end function MeshAttachment:newLinkedMesh () - local copy = MeshAttachment.new(self.name) - copy.region = self.region - copy.path = self.path - copy.color:setFrom(self.color) - if self.parentMesh then - copy.deformAttachment = self.parentMesh - else - copy.deformAttachment = self - end - copy:setParentMesh(self.parentMesh) - copy:updateUVs() - return copy + local copy = MeshAttachment.new(self.name) + copy.region = self.region + copy.path = self.path + copy.color:setFrom(self.color) + if self.parentMesh then + copy.deformAttachment = self.parentMesh + else + copy.deformAttachment = self + end + copy:setParentMesh(self.parentMesh) + copy:updateUVs() + return copy end return MeshAttachment diff --git a/spine-lua/attachments/PathAttachment.lua b/spine-lua/attachments/PathAttachment.lua index 9b16aede6..c81b552a9 100644 --- a/spine-lua/attachments/PathAttachment.lua +++ b/spine-lua/attachments/PathAttachment.lua @@ -42,20 +42,20 @@ function PathAttachment.new (name) local self = VertexAttachment.new(name, AttachmentType.path) self.lengths = nil self.color = Color.newWith(1, 1, 1, 1) - self.closed = false - self.constantSpeed = false + self.closed = false + self.constantSpeed = false setmetatable(self, PathAttachment) return self end function PathAttachment:copy () - local copy = PathAttachment.new(self.name) - self:copyTo(copy) - copy.length = utils.copy(self.lengths) - copy.closed = self.closed - copy.constantSpeed = self.constantSpeed - copy.color:setFrom(self.color) - return copy + local copy = PathAttachment.new(self.name) + self:copyTo(copy) + copy.length = utils.copy(self.lengths) + copy.closed = self.closed + copy.constantSpeed = self.constantSpeed + copy.color:setFrom(self.color) + return copy end return PathAttachment diff --git a/spine-lua/attachments/PointAttachment.lua b/spine-lua/attachments/PointAttachment.lua index 6c94d6b51..de769c988 100644 --- a/spine-lua/attachments/PointAttachment.lua +++ b/spine-lua/attachments/PointAttachment.lua @@ -65,12 +65,12 @@ function PointAttachment:computeWorldRotation(bone) end function PointAttachment:copy () - local copy = PointAttachment.new(self.name) - copy.x = self.x - copy.y = self.y - copy.rotation = self.rotation - copy.color:setFrom(self.color) - return copy + local copy = PointAttachment.new(self.name) + copy.x = self.x + copy.y = self.y + copy.rotation = self.rotation + copy.color:setFrom(self.color) + return copy end return PointAttachment diff --git a/spine-lua/attachments/RegionAttachment.lua b/spine-lua/attachments/RegionAttachment.lua index 9f8865b8a..37207485f 100644 --- a/spine-lua/attachments/RegionAttachment.lua +++ b/spine-lua/attachments/RegionAttachment.lua @@ -85,7 +85,7 @@ local C4A = 32 local RegionAttachment = {} RegionAttachment.__index = RegionAttachment setmetatable(RegionAttachment, { __index = Attachment }) - + RegionAttachment.OX1 = 1 RegionAttachment.OY1 = 2 RegionAttachment.OX2 = 3 @@ -243,8 +243,8 @@ function RegionAttachment:computeWorldVertices (bone, worldVertices, offset, str end function RegionAttachment:copy () - local copy = RegionAttachment.new(self.name) - copy.x = self.x + local copy = RegionAttachment.new(self.name) + copy.x = self.x copy.y = self.y copy.scaleX = self.scaleX copy.scaleY = self.scaleY @@ -258,7 +258,7 @@ function RegionAttachment:copy () copy.offset = Utils.copy(self.offset) copy.uvs = Utils.copy(self.uvs) copy.tempColor:setFrom(self.tempColor) - return copy + return copy end return RegionAttachment diff --git a/spine-lua/attachments/VertexAttachment.lua b/spine-lua/attachments/VertexAttachment.lua index 2065194bd..e9a461949 100644 --- a/spine-lua/attachments/VertexAttachment.lua +++ b/spine-lua/attachments/VertexAttachment.lua @@ -52,7 +52,7 @@ function VertexAttachment.new (name, attachmentType) nextID = nextID - 65535 end self.id = nextID * SHL_11 - self.deformAttachment = self + self.deformAttachment = self nextID = nextID + 1 setmetatable(self, VertexAttachment) return self @@ -149,20 +149,20 @@ function VertexAttachment:computeWorldVertices (slot, start, count, worldVertice end function VertexAttachment:copyTo (attachment) - if self.bones then - attachment.bones = utils.copy(self.bones) - else - attachment.bones = nil - end - - if self.vertices then - attachment.vertices = utils.copy(self.vertices) - else - attachment.vertices = nil - end - - attachment.worldVerticesLength = self.worldVerticesLength - attachment.deformAttachment = self.deformAttachment + if self.bones then + attachment.bones = utils.copy(self.bones) + else + attachment.bones = nil + end + + if self.vertices then + attachment.vertices = utils.copy(self.vertices) + else + attachment.vertices = nil + end + + attachment.worldVerticesLength = self.worldVerticesLength + attachment.deformAttachment = self.deformAttachment end return VertexAttachment diff --git a/spine-lua/utils.lua b/spine-lua/utils.lua index 1a7c60419..be4d7c5d2 100644 --- a/spine-lua/utils.lua +++ b/spine-lua/utils.lua @@ -130,10 +130,10 @@ function utils.arrayCopy (src, srcOffset, dst, dstOffset, size) end function utils.arrayContains(array, element) - for i, arrayElement in ipairs(array) do - if arrayElement == element then return true end - end - return false + for i, arrayElement in ipairs(array) do + if arrayElement == element then return true end + end + return false end function utils.clamp (value, min, max) @@ -143,23 +143,23 @@ function utils.clamp (value, min, max) end function utils.signum (value) - if value < 0 then - return -1 - elseif value > 0 then - return 1 - else - return 0 - end + if value < 0 then + return -1 + elseif value > 0 then + return 1 + else + return 0 + end end -- Implements Java float modulo function utils.mod(a, b) - if b < 0 then b = -b end - if a < 0 then - return -(-a % b) - else - return a % b - end + if b < 0 then b = -b end + if a < 0 then + return -(-a % b) + else + return a % b + end end function utils.randomTriangular(min, max) @@ -174,21 +174,21 @@ function utils.randomTriangularWith(min, max, mode) end function utils.testBit(value, bit) - return value % (2 * bit) >= bit + return value % (2 * bit) >= bit end function utils.setBit(value, bit) - if value % (2 * bit) >= bit then - return value - end - return value + bit + if value % (2 * bit) >= bit then + return value + end + return value + bit end function utils.clearBit(value, bit) - if value % (2 * bit) >= bit then - return value - bit - end - return value + if value % (2 * bit) >= bit then + return value - bit + end + return value end return utils diff --git a/spine-lua/vertexeffects/SwirlEffect.lua b/spine-lua/vertexeffects/SwirlEffect.lua index 1448ca9ca..826451e77 100644 --- a/spine-lua/vertexeffects/SwirlEffect.lua +++ b/spine-lua/vertexeffects/SwirlEffect.lua @@ -69,7 +69,7 @@ function SwirlEffect:transform (vertex) local x = vertex.x - self.worldX local y = vertex.y - self.worldY local dist = math_sqrt(x * x + y * y) - if (dist < self.radius) then + if (dist < self.radius) then local theta = interpolation.apply(self.interpolation, 0, self.angleRad, (self.radius - dist) / self.radius) local cos = math_cos(theta) local sin = math_sin(theta) diff --git a/spine-sfml/c/src/spine/spine-sfml.cpp b/spine-sfml/c/src/spine/spine-sfml.cpp index 88af45960..08784c79d 100644 --- a/spine-sfml/c/src/spine/spine-sfml.cpp +++ b/spine-sfml/c/src/spine/spine-sfml.cpp @@ -199,37 +199,37 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const { sf::BlendMode blend; if (!usePremultipliedAlpha) { switch (slot->data->blendMode) { - case BLEND_MODE_NORMAL: - blend = normal; - break; - case BLEND_MODE_ADDITIVE: - blend = additive; - break; - case BLEND_MODE_MULTIPLY: - blend = multiply; - break; - case BLEND_MODE_SCREEN: - blend = screen; - break; - default: - blend = normal; + case BLEND_MODE_NORMAL: + blend = normal; + break; + case BLEND_MODE_ADDITIVE: + blend = additive; + break; + case BLEND_MODE_MULTIPLY: + blend = multiply; + break; + case BLEND_MODE_SCREEN: + blend = screen; + break; + default: + blend = normal; } } else { switch (slot->data->blendMode) { - case BLEND_MODE_NORMAL: - blend = normalPma; - break; - case BLEND_MODE_ADDITIVE: - blend = additivePma; - break; - case BLEND_MODE_MULTIPLY: - blend = multiplyPma; - break; - case BLEND_MODE_SCREEN: - blend = screenPma; - break; - default: - blend = normalPma; + case BLEND_MODE_NORMAL: + blend = normalPma; + break; + case BLEND_MODE_ADDITIVE: + blend = additivePma; + break; + case BLEND_MODE_MULTIPLY: + blend = multiplyPma; + break; + case BLEND_MODE_SCREEN: + blend = screenPma; + break; + default: + blend = normalPma; } } diff --git a/spine-sfml/cpp/src/spine/spine-sfml.cpp b/spine-sfml/cpp/src/spine/spine-sfml.cpp index 7e759f00a..70e1dd48d 100644 --- a/spine-sfml/cpp/src/spine/spine-sfml.cpp +++ b/spine-sfml/cpp/src/spine/spine-sfml.cpp @@ -175,37 +175,37 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const { sf::BlendMode blend; if (!usePremultipliedAlpha) { switch (slot.getData().getBlendMode()) { - case BlendMode_Normal: - blend = normal; - break; - case BlendMode_Additive: - blend = additive; - break; - case BlendMode_Multiply: - blend = multiply; - break; - case BlendMode_Screen: - blend = screen; - break; - default: - blend = normal; + case BlendMode_Normal: + blend = normal; + break; + case BlendMode_Additive: + blend = additive; + break; + case BlendMode_Multiply: + blend = multiply; + break; + case BlendMode_Screen: + blend = screen; + break; + default: + blend = normal; } } else { switch (slot.getData().getBlendMode()) { - case BlendMode_Normal: - blend = normalPma; - break; - case BlendMode_Additive: - blend = additivePma; - break; - case BlendMode_Multiply: - blend = multiplyPma; - break; - case BlendMode_Screen: - blend = screenPma; - break; - default: - blend = normalPma; + case BlendMode_Normal: + blend = normalPma; + break; + case BlendMode_Additive: + blend = additivePma; + break; + case BlendMode_Multiply: + blend = multiplyPma; + break; + case BlendMode_Screen: + blend = screenPma; + break; + default: + blend = normalPma; } } diff --git a/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as b/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as index ac7041edf..4611ce37d 100644 --- a/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as +++ b/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as @@ -59,12 +59,12 @@ package spine.starling { static private var _tempMatrix : Matrix = new Matrix(); static private var _tempVertices : Vector. = new Vector.(8); static internal var blendModes : Vector. = new [BlendMode.NORMAL, BlendMode.ADD, BlendMode.MULTIPLY, BlendMode.SCREEN]; - private var _skeleton : Skeleton; + private var _skeleton : Skeleton; private var _smoothing : String = "bilinear"; private var _twoColorTint : Boolean = false; private static var clipper: SkeletonClipping = new SkeletonClipping(); private static var QUAD_INDICES : Vector. = new [0, 1, 2, 2, 3, 0]; - + public var vertexEffect : VertexEffect; private var tempLight : spine.Color = new spine.Color(0, 0, 0); private var tempDark : spine.Color = new spine.Color(0, 0, 0); @@ -73,7 +73,7 @@ package spine.starling { public function SkeletonSprite(skeletonData : SkeletonData) { Bone.yDown = true; _skeleton = new Skeleton(skeletonData); - _skeleton.updateWorldTransform(); + _skeleton.updateWorldTransform(); } override public function render(painter : Painter) : void { @@ -83,7 +83,7 @@ package spine.starling { var r : Number = skeleton.color.r * 255; var g : Number = skeleton.color.g * 255; var b : Number = skeleton.color.b * 255; - var drawOrder : Vector. = skeleton.drawOrder; + var drawOrder : Vector. = skeleton.drawOrder; var ii : int, iii : int; var attachmentColor: spine.Color; var rgb : uint, a : Number; @@ -92,7 +92,7 @@ package spine.starling { var verticesLength : int, verticesCount : int, indicesLength : int; var indexData : IndexData, indices : Vector., vertexData : VertexData; var uvs : Vector.; - + if (vertexEffect != null) vertexEffect.begin(skeleton); for (var i : int = 0, n : int = drawOrder.length; i < n; ++i) { @@ -105,16 +105,16 @@ package spine.starling { verticesLength = 4 * 2; verticesCount = verticesLength >> 1; if (worldVertices.length < verticesLength) worldVertices.length = verticesLength; - region.computeWorldVertices(slot.bone, worldVertices, 0, 2); + region.computeWorldVertices(slot.bone, worldVertices, 0, 2); mesh = region.rendererObject as SkeletonMesh; - indices = QUAD_INDICES; + indices = QUAD_INDICES; if (mesh == null) { if (region.rendererObject is Image) region.rendererObject = mesh = new SkeletonMesh(Image(region.rendererObject).texture); if (region.rendererObject is AtlasRegion) - region.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(region.rendererObject).rendererObject).texture); - if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle()); + region.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(region.rendererObject).rendererObject).texture); + if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle()); indexData = mesh.getIndexData(); for (ii = 0; ii < indices.length; ii++) indexData.setIndex(ii, indices[ii]); @@ -123,23 +123,23 @@ package spine.starling { } indexData = mesh.getIndexData(); attachmentColor = region.color; - uvs = region.uvs; + uvs = region.uvs; } else if (slot.attachment is MeshAttachment) { var meshAttachment : MeshAttachment = MeshAttachment(slot.attachment); verticesLength = meshAttachment.worldVerticesLength; verticesCount = verticesLength >> 1; if (worldVertices.length < verticesLength) worldVertices.length = verticesLength; meshAttachment.computeWorldVertices(slot, 0, meshAttachment.worldVerticesLength, worldVertices, 0, 2); - + mesh = meshAttachment.rendererObject as SkeletonMesh; - indices = meshAttachment.triangles; + indices = meshAttachment.triangles; if (mesh == null) { if (meshAttachment.rendererObject is Image) meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(meshAttachment.rendererObject).texture); if (meshAttachment.rendererObject is AtlasRegion) - meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(meshAttachment.rendererObject).rendererObject).texture); + meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(meshAttachment.rendererObject).rendererObject).texture); if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle()); - + indexData = mesh.getIndexData(); indicesLength = meshAttachment.triangles.length; for (ii = 0; ii < indicesLength; ii++) { @@ -150,7 +150,7 @@ package spine.starling { } indexData = mesh.getIndexData(); attachmentColor = meshAttachment.color; - uvs = meshAttachment.uvs; + uvs = meshAttachment.uvs; } else if (slot.attachment is ClippingAttachment) { var clip : ClippingAttachment = ClippingAttachment(slot.attachment); clipper.clipStart(slot, clip); @@ -158,28 +158,28 @@ package spine.starling { } else { continue; } - + a = slot.color.a * attachmentColor.a; if (a == 0) { - clipper.clipEndWithSlot(slot); - continue; + clipper.clipEndWithSlot(slot); + continue; } rgb = Color.rgb(r * slot.color.r * attachmentColor.r, g * slot.color.g * attachmentColor.g, b * slot.color.b * attachmentColor.b); if (slot.darkColor == null) dark = Color.rgb(0, 0, 0); - else dark = Color.rgb(slot.darkColor.r * 255, slot.darkColor.g * 255, slot.darkColor.b * 255); + else dark = Color.rgb(slot.darkColor.r * 255, slot.darkColor.g * 255, slot.darkColor.b * 255); if (clipper.isClipping()) { clipper.clipTriangles(worldVertices, indices, indices.length, uvs); - - // Need to create a new mesh here, see https://github.com/EsotericSoftware/spine-runtimes/issues/1125 + + // Need to create a new mesh here, see https://github.com/EsotericSoftware/spine-runtimes/issues/1125 mesh = new SkeletonMesh(mesh.texture); - if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle()); + if (_twoColorTint) mesh.setStyle(new TwoColorMeshStyle()); indexData = mesh.getIndexData(); verticesCount = clipper.clippedVertices.length >> 1; worldVertices = clipper.clippedVertices; - uvs = clipper.clippedUvs; - + uvs = clipper.clippedUvs; + indices = clipper.clippedTriangles; indicesLength = indices.length; indexData.numIndices = indicesLength; @@ -190,7 +190,7 @@ package spine.starling { } vertexData = mesh.getVertexData(); - vertexData.numVertices = verticesCount; + vertexData.numVertices = verticesCount; if (vertexEffect != null) { tempLight.r = ((rgb >> 16) & 0xff) / 255.0; tempLight.g = ((rgb >> 8) & 0xff) / 255.0; @@ -209,7 +209,7 @@ package spine.starling { tempVertex.dark.setFromColor(tempDark); vertexEffect.transform(tempVertex); vertexData.colorize("color", Color.rgb(tempVertex.light.r * 255, tempVertex.light.g * 255, tempVertex.light.b * 255), tempVertex.light.a, ii, 1); - if (_twoColorTint) vertexData.colorize("color2", Color.rgb(tempVertex.dark.r * 255, tempVertex.dark.g * 255, tempVertex.dark.b * 255), a, ii, 1); + if (_twoColorTint) vertexData.colorize("color2", Color.rgb(tempVertex.dark.r * 255, tempVertex.dark.g * 255, tempVertex.dark.b * 255), a, ii, 1); mesh.setVertexPosition(ii, tempVertex.x, tempVertex.y); mesh.setTexCoords(ii, tempVertex.u, tempVertex.v); } @@ -219,24 +219,24 @@ package spine.starling { for (ii = 0, iii = 0; ii < verticesCount; ii++, iii += 2) { mesh.setVertexPosition(ii, worldVertices[iii], worldVertices[iii + 1]); mesh.setTexCoords(ii, uvs[iii], uvs[iii + 1]); - } + } } if (indexData.numIndices > 0 && vertexData.numVertices > 0) { painter.state.blendMode = blendModes[slot.data.blendMode.ordinal]; painter.batchMesh(mesh); } - + clipper.clipEndWithSlot(slot); } painter.state.blendMode = originalBlendMode; clipper.clipEnd(); - + if (vertexEffect != null) vertexEffect.end(); } override public function hitTest(localPoint : Point) : DisplayObject { if (!this.visible || !this.touchable) return null; - + var minX : Number = Number.MAX_VALUE, minY : Number = Number.MAX_VALUE; var maxX : Number = -Number.MAX_VALUE, maxY : Number = -Number.MAX_VALUE; var slots : Vector. = skeleton.slots; @@ -318,11 +318,11 @@ package spine.starling { public function set smoothing(smoothing : String) : void { _smoothing = smoothing; } - + public function get twoColorTint() : Boolean { return _twoColorTint; } - + public function set twoColorTint(tint : Boolean) : void { _twoColorTint = tint; } diff --git a/spine-starling/spine-starling/src/spine/starling/StarlingAtlasAttachmentLoader.as b/spine-starling/spine-starling/src/spine/starling/StarlingAtlasAttachmentLoader.as index c8bf9613c..23e20d5ba 100644 --- a/spine-starling/spine-starling/src/spine/starling/StarlingAtlasAttachmentLoader.as +++ b/spine-starling/spine-starling/src/spine/starling/StarlingAtlasAttachmentLoader.as @@ -78,15 +78,15 @@ package spine.starling { tmp = attachment.regionWidth; attachment.regionWidth = attachment.regionHeight; attachment.regionHeight = tmp; - attachment["regionU2"] = 0; - attachment["regionV2"] = 1; - attachment["regionU"] = 1; - attachment["regionV"] = 0; - }else{ - attachment["regionU"] = 0; - attachment["regionV"] = 0; - attachment["regionU2"] = 1; - attachment["regionV2"] = 1; + attachment["regionU2"] = 0; + attachment["regionV2"] = 1; + attachment["regionU"] = 1; + attachment["regionV"] = 0; + } else { + attachment["regionU"] = 0; + attachment["regionV"] = 0; + attachment["regionU2"] = 1; + attachment["regionV2"] = 1; } attachment.setUVs(attachment["regionU"], attachment["regionV"], attachment["regionU2"], attachment["regionV2"], rotated); return attachment; @@ -122,7 +122,7 @@ package spine.starling { attachment.regionWidth = texture.width; attachment.regionHeight = texture.height; attachment.regionOriginalWidth = frame ? frame.width : texture.width; - attachment.regionOriginalHeight = frame ? frame.height : texture.height; + attachment.regionOriginalHeight = frame ? frame.height : texture.height; if (rotated) { var tmp : Number = attachment.regionOriginalWidth; attachment.regionOriginalWidth = attachment.regionOriginalHeight; diff --git a/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as b/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as index 189905c1c..9841506ed 100644 --- a/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as +++ b/spine-starling/spine-starling/src/spine/starling/TwoColorEffect.as @@ -37,7 +37,7 @@ package spine.starling { import starling.rendering.MeshEffect; public class TwoColorEffect extends MeshEffect { - public static const VERTEX_FORMAT : VertexDataFormat = TwoColorMeshStyle.VERTEX_FORMAT; + public static const VERTEX_FORMAT : VertexDataFormat = TwoColorMeshStyle.VERTEX_FORMAT; private static const VECTOR_ONES:Vector. = Vector.([1, 1, 1, 1]); override protected function createProgram() : Program { @@ -45,25 +45,25 @@ package spine.starling { // v1 -> color plus alpha // v2 -> dark color var vertexShader : String = [ - "m44 op, va0, vc0", // 4x4 matrix transform to output clip-space - "mov v0, va1 ", // pass texture coordinates to fragment program - "mul v1, va2, vc4", // multiply alpha (vc4) with color (va2), pass to fp - "mov v2, va3 " // pass dark color to fp + "m44 op, va0, vc0", // 4x4 matrix transform to output clip-space + "mov v0, va1 ", // pass texture coordinates to fragment program + "mul v1, va2, vc4", // multiply alpha (vc4) with color (va2), pass to fp + "mov v2, va3 " // pass dark color to fp ].join("\n"); var fragmentShader : String = [ - tex("ft0", "v0", 0, texture), // ft0 = texture2d(texCoords) - "mul ft1, ft0, v1", // ft1 = texColor * light - "sub ft3.xyz, ft0.www, fc0.xyz", // ft3 = texColor.a - 1 - "sub ft2.xyz, fc0.xyz, ft0.xyz", // ft2.xyz = (1 - texColor.rgb) - "add ft2.xyz, ft2.xyz, ft3.xyz", // ft2.xyz = ((texColor.a - 1.0) + 1.0 - texColor.rgb) - "mul ft2.xyz, ft2.xyz, v2.xyz", // ft2.xyz = ((texColor.a - 1.0) + 1.0 - texColor.rgb) * dark.rgb - "add ft2.xyz, ft2.xyz, ft1.xyz", // ft2.xyz = ((texColor.a - 1.0) + 1.0 - texColor.rgb) * dark.rgb + texColor.rgb * light.rgb - "mov ft2.w, ft1.w", // ft2.w = alpha + tex("ft0", "v0", 0, texture), // ft0 = texture2d(texCoords) + "mul ft1, ft0, v1", // ft1 = texColor * light + "sub ft3.xyz, ft0.www, fc0.xyz", // ft3 = texColor.a - 1 + "sub ft2.xyz, fc0.xyz, ft0.xyz", // ft2.xyz = (1 - texColor.rgb) + "add ft2.xyz, ft2.xyz, ft3.xyz", // ft2.xyz = ((texColor.a - 1.0) + 1.0 - texColor.rgb) + "mul ft2.xyz, ft2.xyz, v2.xyz", // ft2.xyz = ((texColor.a - 1.0) + 1.0 - texColor.rgb) * dark.rgb + "add ft2.xyz, ft2.xyz, ft1.xyz", // ft2.xyz = ((texColor.a - 1.0) + 1.0 - texColor.rgb) * dark.rgb + texColor.rgb * light.rgb + "mov ft2.w, ft1.w", // ft2.w = alpha "mov oc, ft2" ].join("\n"); - return Program.fromSource(vertexShader, fragmentShader); + return Program.fromSource(vertexShader, fragmentShader); } override public function get vertexFormat() : VertexDataFormat { @@ -73,8 +73,8 @@ package spine.starling { override protected function beforeDraw(context : Context3D) : void { super.beforeDraw(context); vertexFormat.setVertexBufferAt(3, vertexBuffer, "color2"); - - // fc0 -> (1, 1, 1, 1) + + // fc0 -> (1, 1, 1, 1) context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, VECTOR_ONES); } diff --git a/spine-threejs/README.md b/spine-threejs/README.md index 4b06f9418..8f69c38bd 100644 --- a/spine-threejs/README.md +++ b/spine-threejs/README.md @@ -1,3 +1,3 @@ # spine-threejs -spine-threejs has been deprecated and is superseded by [spine-ts THREE.JS backend](../spine-ts). \ No newline at end of file +spine-threejs has been replaced by [spine-ts THREE.JS backend](../spine-ts). \ No newline at end of file diff --git a/spine-tk2d/README.md b/spine-tk2d/README.md index 6daacbed0..fbc1e2928 100644 --- a/spine-tk2d/README.md +++ b/spine-tk2d/README.md @@ -1,3 +1,3 @@ # spine-tk2d -The spine-tk2d runtime has been merged into [spine-unity](../spine-unity). You may use spine-unity with [2D Toolkit](http://www.2dtoolkit.com/). +The spine-tk2d runtime has been replaced by [spine-unity](../spine-unity). You may use spine-unity with [2D Toolkit](http://www.2dtoolkit.com/). diff --git a/spine-ts/canvas/src/SkeletonRenderer.ts b/spine-ts/canvas/src/SkeletonRenderer.ts index 12db9c4e7..75d256046 100644 --- a/spine-ts/canvas/src/SkeletonRenderer.ts +++ b/spine-ts/canvas/src/SkeletonRenderer.ts @@ -163,7 +163,7 @@ module spine.canvas { ctx.globalAlpha = color.a; // experimental tinting via compositing, doesn't work // ctx.globalCompositeOperation = "source-atop"; - // ctx.fillStyle = "rgba(" + (color.r * 255 | 0) + ", " + (color.g * 255 | 0) + ", " + (color.b * 255 | 0) + ", " + color.a + ")"; + // ctx.fillStyle = "rgba(" + (color.r * 255 | 0) + ", " + (color.g * 255 | 0) + ", " + (color.b * 255 | 0) + ", " + color.a + ")"; // ctx.fillRect(0, 0, w, h); } @@ -250,9 +250,9 @@ module spine.canvas { let multiplier = pma ? alpha : 1; let color = this.tempColor; color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, - skeletonColor.g * slotColor.g * regionColor.g * multiplier, - skeletonColor.b * slotColor.b * regionColor.b * multiplier, - alpha); + skeletonColor.g * slotColor.g * regionColor.g * multiplier, + skeletonColor.b * slotColor.b * regionColor.b * multiplier, + alpha); region.computeWorldVertices(slot.bone, this.vertices, 0, SkeletonRenderer.VERTEX_SIZE); @@ -299,9 +299,9 @@ module spine.canvas { let multiplier = pma ? alpha : 1; let color = this.tempColor; color.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, - skeletonColor.g * slotColor.g * regionColor.g * multiplier, - skeletonColor.b * slotColor.b * regionColor.b * multiplier, - alpha); + skeletonColor.g * slotColor.g * regionColor.g * multiplier, + skeletonColor.b * slotColor.b * regionColor.b * multiplier, + alpha); let numVertices = mesh.worldVerticesLength / 2; if (this.vertices.length < mesh.worldVerticesLength) { diff --git a/spine-ts/core/src/AnimationState.ts b/spine-ts/core/src/AnimationState.ts index b055b5cbb..90bc1f27a 100644 --- a/spine-ts/core/src/AnimationState.ts +++ b/spine-ts/core/src/AnimationState.ts @@ -162,9 +162,9 @@ module spine { if ((i == 0 && mix == 1) || blend == MixBlend.add) { for (let ii = 0; ii < timelineCount; ii++) { // Fixes issue #302 on IOS9 where mix, blend sometimes became undefined and caused assets - // to sometimes stop rendering when using color correction, as their RGBA values become NaN. - // (https://github.com/pixijs/pixi-spine/issues/302) - Utils.webkit602BugfixHelper(mix, blend); + // to sometimes stop rendering when using color correction, as their RGBA values become NaN. + // (https://github.com/pixijs/pixi-spine/issues/302) + Utils.webkit602BugfixHelper(mix, blend); timelines[ii].apply(skeleton, animationLast, animationTime, events, mix, blend, MixDirection.mixIn); } } else { diff --git a/spine-ts/core/src/AssetManager.ts b/spine-ts/core/src/AssetManager.ts index 5ab3c7f96..85fc785d5 100644 --- a/spine-ts/core/src/AssetManager.ts +++ b/spine-ts/core/src/AssetManager.ts @@ -158,8 +158,9 @@ module spine { } loadTextureAtlas (path: string, - success: (path: string, atlas: TextureAtlas) => void = null, - error: (path: string, error: string) => void = null) { + success: (path: string, atlas: TextureAtlas) => void = null, + error: (path: string, error: string) => void = null + ) { let parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; path = this.pathPrefix + path; this.toLoad++; diff --git a/spine-ts/core/src/SharedAssetManager.ts b/spine-ts/core/src/SharedAssetManager.ts index 2328139ed..1886c1e31 100644 --- a/spine-ts/core/src/SharedAssetManager.ts +++ b/spine-ts/core/src/SharedAssetManager.ts @@ -113,7 +113,7 @@ module spine { path = this.pathPrefix + path; if (!this.queueAsset(clientId, textureLoader, path)) return; - let img = new Image(); + let img = new Image(); img.src = path; img.crossOrigin = "anonymous"; img.onload = (ev) => { diff --git a/spine-ts/player/src/Player.ts b/spine-ts/player/src/Player.ts index 2762ae5ce..3c43ceeae 100644 --- a/spine-ts/player/src/Player.ts +++ b/spine-ts/player/src/Player.ts @@ -327,7 +327,7 @@ module spine { if (!config.alpha) config.alpha = false; if (!config.backgroundColor) config.backgroundColor = "#000000"; if (!config.fullScreenBackgroundColor) config.fullScreenBackgroundColor = config.backgroundColor; - if (typeof config.premultipliedAlpha === "undefined") config.premultipliedAlpha = true; + if (typeof config.premultipliedAlpha === "undefined") config.premultipliedAlpha = true; if (!config.success) config.success = (widget) => {}; if (!config.error) config.error = (widget, msg) => {}; if (!config.debug) config.debug = { @@ -350,11 +350,11 @@ module spine { if (typeof config.debug.meshes === "undefined") config.debug.meshes = false; if (config.animations && config.animation) { - if (config.animations.indexOf(config.animation) < 0) throw new Error("Default animation '" + config.animation + "' is not contained in the list of selectable animations " + escapeHtml(JSON.stringify(this.config.animations)) + "."); + if (config.animations.indexOf(config.animation) < 0) throw new Error("Default animation '" + config.animation + "' is not contained in the list of selectable animations " + escapeHtml(JSON.stringify(this.config.animations)) + "."); } if (config.skins && config.skin) { - if (config.skins.indexOf(config.skin) < 0) throw new Error("Default skin '" + config.skin + "' is not contained in the list of selectable skins " + escapeHtml(JSON.stringify(this.config.skins)) + "."); + if (config.skins.indexOf(config.skin) < 0) throw new Error("Default skin '" + config.skin + "' is not contained in the list of selectable skins " + escapeHtml(JSON.stringify(this.config.skins)) + "."); } if (!config.controlBones) config.controlBones = []; @@ -401,7 +401,7 @@ module spine { try { // Validate the configuration this.config = this.validateConfig(config); - } catch (e) { + } catch (e) { this.showError(e); return dom } @@ -755,7 +755,7 @@ module spine { } let transitionAlpha = ((performance.now() - this.viewportTransitionStart) / 1000) / this.config.viewport.transitionTime; - if (this.previousViewport && transitionAlpha < 1) { + if (this.previousViewport && transitionAlpha < 1) { let oldViewport = { x: this.previousViewport.x - (this.previousViewport.padLeft as number), y: this.previousViewport.y - (this.previousViewport.padBottom as number), @@ -1189,7 +1189,7 @@ module spine { let steps = 100; let stepTime = animation.duration > 0 ? animation.duration / steps : 0; - let minX = 100000000; + let minX = 100000000; let maxX = -100000000; let minY = 100000000; let maxY = -100000000; diff --git a/spine-ts/webgl/src/Matrix4.ts b/spine-ts/webgl/src/Matrix4.ts index 171033897..6f8d69585 100644 --- a/spine-ts/webgl/src/Matrix4.ts +++ b/spine-ts/webgl/src/Matrix4.ts @@ -114,47 +114,47 @@ module spine.webgl { let v = this.values; let t = this.temp; let l_det = v[M30] * v[M21] * v[M12] * v[M03] - v[M20] * v[M31] * v[M12] * v[M03] - v[M30] * v[M11] * v[M22] * v[M03] - + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] - - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] - - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] - + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] - + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] - - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] - - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33]; + + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] + - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] + - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] + + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] + + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] + - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] + - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33]; if (l_det == 0) throw new Error("non-invertible matrix"); let inv_det = 1.0 / l_det; t[M00] = v[M12] * v[M23] * v[M31] - v[M13] * v[M22] * v[M31] + v[M13] * v[M21] * v[M32] - - v[M11] * v[M23] * v[M32] - v[M12] * v[M21] * v[M33] + v[M11] * v[M22] * v[M33]; + - v[M11] * v[M23] * v[M32] - v[M12] * v[M21] * v[M33] + v[M11] * v[M22] * v[M33]; t[M01] = v[M03] * v[M22] * v[M31] - v[M02] * v[M23] * v[M31] - v[M03] * v[M21] * v[M32] - + v[M01] * v[M23] * v[M32] + v[M02] * v[M21] * v[M33] - v[M01] * v[M22] * v[M33]; + + v[M01] * v[M23] * v[M32] + v[M02] * v[M21] * v[M33] - v[M01] * v[M22] * v[M33]; t[M02] = v[M02] * v[M13] * v[M31] - v[M03] * v[M12] * v[M31] + v[M03] * v[M11] * v[M32] - - v[M01] * v[M13] * v[M32] - v[M02] * v[M11] * v[M33] + v[M01] * v[M12] * v[M33]; + - v[M01] * v[M13] * v[M32] - v[M02] * v[M11] * v[M33] + v[M01] * v[M12] * v[M33]; t[M03] = v[M03] * v[M12] * v[M21] - v[M02] * v[M13] * v[M21] - v[M03] * v[M11] * v[M22] - + v[M01] * v[M13] * v[M22] + v[M02] * v[M11] * v[M23] - v[M01] * v[M12] * v[M23]; + + v[M01] * v[M13] * v[M22] + v[M02] * v[M11] * v[M23] - v[M01] * v[M12] * v[M23]; t[M10] = v[M13] * v[M22] * v[M30] - v[M12] * v[M23] * v[M30] - v[M13] * v[M20] * v[M32] - + v[M10] * v[M23] * v[M32] + v[M12] * v[M20] * v[M33] - v[M10] * v[M22] * v[M33]; + + v[M10] * v[M23] * v[M32] + v[M12] * v[M20] * v[M33] - v[M10] * v[M22] * v[M33]; t[M11] = v[M02] * v[M23] * v[M30] - v[M03] * v[M22] * v[M30] + v[M03] * v[M20] * v[M32] - - v[M00] * v[M23] * v[M32] - v[M02] * v[M20] * v[M33] + v[M00] * v[M22] * v[M33]; + - v[M00] * v[M23] * v[M32] - v[M02] * v[M20] * v[M33] + v[M00] * v[M22] * v[M33]; t[M12] = v[M03] * v[M12] * v[M30] - v[M02] * v[M13] * v[M30] - v[M03] * v[M10] * v[M32] - + v[M00] * v[M13] * v[M32] + v[M02] * v[M10] * v[M33] - v[M00] * v[M12] * v[M33]; + + v[M00] * v[M13] * v[M32] + v[M02] * v[M10] * v[M33] - v[M00] * v[M12] * v[M33]; t[M13] = v[M02] * v[M13] * v[M20] - v[M03] * v[M12] * v[M20] + v[M03] * v[M10] * v[M22] - - v[M00] * v[M13] * v[M22] - v[M02] * v[M10] * v[M23] + v[M00] * v[M12] * v[M23]; + - v[M00] * v[M13] * v[M22] - v[M02] * v[M10] * v[M23] + v[M00] * v[M12] * v[M23]; t[M20] = v[M11] * v[M23] * v[M30] - v[M13] * v[M21] * v[M30] + v[M13] * v[M20] * v[M31] - - v[M10] * v[M23] * v[M31] - v[M11] * v[M20] * v[M33] + v[M10] * v[M21] * v[M33]; + - v[M10] * v[M23] * v[M31] - v[M11] * v[M20] * v[M33] + v[M10] * v[M21] * v[M33]; t[M21] = v[M03] * v[M21] * v[M30] - v[M01] * v[M23] * v[M30] - v[M03] * v[M20] * v[M31] - + v[M00] * v[M23] * v[M31] + v[M01] * v[M20] * v[M33] - v[M00] * v[M21] * v[M33]; + + v[M00] * v[M23] * v[M31] + v[M01] * v[M20] * v[M33] - v[M00] * v[M21] * v[M33]; t[M22] = v[M01] * v[M13] * v[M30] - v[M03] * v[M11] * v[M30] + v[M03] * v[M10] * v[M31] - - v[M00] * v[M13] * v[M31] - v[M01] * v[M10] * v[M33] + v[M00] * v[M11] * v[M33]; + - v[M00] * v[M13] * v[M31] - v[M01] * v[M10] * v[M33] + v[M00] * v[M11] * v[M33]; t[M23] = v[M03] * v[M11] * v[M20] - v[M01] * v[M13] * v[M20] - v[M03] * v[M10] * v[M21] - + v[M00] * v[M13] * v[M21] + v[M01] * v[M10] * v[M23] - v[M00] * v[M11] * v[M23]; + + v[M00] * v[M13] * v[M21] + v[M01] * v[M10] * v[M23] - v[M00] * v[M11] * v[M23]; t[M30] = v[M12] * v[M21] * v[M30] - v[M11] * v[M22] * v[M30] - v[M12] * v[M20] * v[M31] - + v[M10] * v[M22] * v[M31] + v[M11] * v[M20] * v[M32] - v[M10] * v[M21] * v[M32]; + + v[M10] * v[M22] * v[M31] + v[M11] * v[M20] * v[M32] - v[M10] * v[M21] * v[M32]; t[M31] = v[M01] * v[M22] * v[M30] - v[M02] * v[M21] * v[M30] + v[M02] * v[M20] * v[M31] - - v[M00] * v[M22] * v[M31] - v[M01] * v[M20] * v[M32] + v[M00] * v[M21] * v[M32]; - t[M32] = v[M02] * v[M11] * v[M30] - v[M01] * v[M12] * v[M30] - v[M02] * v[M10] * v[M31] - + v[M00] * v[M12] * v[M31] + v[M01] * v[M10] * v[M32] - v[M00] * v[M11] * v[M32]; + - v[M00] * v[M22] * v[M31] - v[M01] * v[M20] * v[M32] + v[M00] * v[M21] * v[M32]; + t[M32] = v[M02] * v[M11] * v[M30] - v[M01] * v[M12] * v[M30] - v[M02] * v[M10] * v[M31] + + v[M00] * v[M12] * v[M31] + v[M01] * v[M10] * v[M32] - v[M00] * v[M11] * v[M32]; t[M33] = v[M01] * v[M12] * v[M20] - v[M02] * v[M11] * v[M20] + v[M02] * v[M10] * v[M21] - - v[M00] * v[M12] * v[M21] - v[M01] * v[M10] * v[M22] + v[M00] * v[M11] * v[M22]; + - v[M00] * v[M12] * v[M21] - v[M01] * v[M10] * v[M22] + v[M00] * v[M11] * v[M22]; v[M00] = t[M00] * inv_det; v[M01] = t[M01] * inv_det; v[M02] = t[M02] * inv_det; @@ -177,13 +177,13 @@ module spine.webgl { determinant (): number { let v = this.values; return v[M30] * v[M21] * v[M12] * v[M03] - v[M20] * v[M31] * v[M12] * v[M03] - v[M30] * v[M11] * v[M22] * v[M03] - + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] - - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] - - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] - + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] - + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] - - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] - - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33]; + + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] + - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] + - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] + + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] + + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] + - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] + - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33]; } translate (x: number, y: number, z: number): Matrix4 { diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp index bf1d8d8fb..aa2a2fc65 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp @@ -74,7 +74,7 @@ static void setVertex(FSlateVertex* vertex, float x, float y, float u, float v, } int32 SSpineWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, - int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const { + int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const { SSpineWidget* self = (SSpineWidget*)this; UMaterialInstanceDynamic* MatNow = nullptr; diff --git a/spine-ue4/Source/SpineUE4/MySceneComponent.cpp b/spine-ue4/Source/SpineUE4/MySceneComponent.cpp index 21cbfceb6..3cee3ab57 100644 --- a/spine-ue4/Source/SpineUE4/MySceneComponent.cpp +++ b/spine-ue4/Source/SpineUE4/MySceneComponent.cpp @@ -8,7 +8,7 @@ // Sets default values for this component's properties UMySceneComponent::UMySceneComponent(const FObjectInitializer& ObjectInitializer) : USpineSkeletonRendererComponent(ObjectInitializer) { - // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; } diff --git a/spine-ue4/Source/SpineUE4/SpineboyCppPawn.cpp b/spine-ue4/Source/SpineUE4/SpineboyCppPawn.cpp index 517547600..448329125 100644 --- a/spine-ue4/Source/SpineUE4/SpineboyCppPawn.cpp +++ b/spine-ue4/Source/SpineUE4/SpineboyCppPawn.cpp @@ -8,7 +8,7 @@ // Sets default values ASpineboyCppPawn::ASpineboyCppPawn() { - // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. + // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; } diff --git a/spine-unity/Assets/Spine Examples/Other Examples/Animation Tester/SpineAnimationTesterTool.cs b/spine-unity/Assets/Spine Examples/Other Examples/Animation Tester/SpineAnimationTesterTool.cs index 421210516..52fe5b016 100644 --- a/spine-unity/Assets/Spine Examples/Other Examples/Animation Tester/SpineAnimationTesterTool.cs +++ b/spine-unity/Assets/Spine Examples/Other Examples/Animation Tester/SpineAnimationTesterTool.cs @@ -62,7 +62,7 @@ namespace Spine.Unity.Examples { public bool loop; public KeyCode key; - [Space] + [Space] public bool useCustomMixDuration; public float mixDuration; //public bool useChainToControl; @@ -107,12 +107,12 @@ namespace Spine.Unity.Examples { boundAnimationsStringBuilder.AppendFormat("[{0}] {1}\n", ba.key.ToString(), animationName); } - } + } boundAnimationsText.text = boundAnimationsStringBuilder.ToString(); } - + } void Start () { @@ -135,7 +135,7 @@ namespace Spine.Unity.Examples { TrackEntry trackEntry; if (!string.IsNullOrEmpty(control.animationName)) { trackEntry = animationState.SetAnimation(trackIndex, control.animationName, control.loop); - + } else { float mix = control.useCustomMixDuration ? control.mixDuration : animationState.Data.DefaultMix; trackEntry = animationState.SetEmptyAnimation(trackIndex, mix); @@ -153,7 +153,7 @@ namespace Spine.Unity.Examples { } // Don't parse more than one animation per track. - break; + break; } } } diff --git a/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/BasicPlatformerController.cs b/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/BasicPlatformerController.cs index 13ca01172..e39a764e5 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/BasicPlatformerController.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/BasicPlatformerController.cs @@ -90,7 +90,7 @@ namespace Spine.Unity.Examples { input.x = Input.GetAxis(XAxis); input.y = Input.GetAxis(YAxis); bool inputJumpStop = Input.GetButtonUp(JumpButton); - bool inputJumpStart = Input.GetButtonDown(JumpButton); + bool inputJumpStart = Input.GetButtonDown(JumpButton); bool doCrouch = (isGrounded && input.y < -0.5f) || (forceCrouchEndTime > Time.time); bool doJumpInterrupt = false; bool doJump = false; @@ -116,7 +116,7 @@ namespace Spine.Unity.Examples { // Dummy physics and controller using UnityEngine.CharacterController. Vector3 gravityDeltaVelocity = Physics.gravity * gravityScale * dt; - + if (doJump) { velocity.y = jumpSpeed; minimumJumpEndTime = Time.time + minimumJumpDuration; @@ -132,8 +132,8 @@ namespace Spine.Unity.Examples { velocity.x *= Mathf.Sign(input.x); } } - - + + if (!isGrounded) { if (wasGrounded) { if (velocity.y < 0) @@ -144,7 +144,7 @@ namespace Spine.Unity.Examples { } controller.Move(velocity * dt); wasGrounded = isGrounded; - + // Determine and store character state if (isGrounded) { if (doCrouch) { diff --git a/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs b/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs index 319bc35f0..79f4d4c9d 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Getting Started Scripts/Raptor.cs @@ -47,7 +47,7 @@ namespace Spine.Unity.Examples { StartCoroutine(GunGrabRoutine()); } - IEnumerator GunGrabRoutine () { + IEnumerator GunGrabRoutine () { // Play the walk animation on track 0. skeletonAnimation.AnimationState.SetAnimation(0, walk, true); diff --git a/spine-unity/Assets/Spine Examples/Scripts/Goblins.cs b/spine-unity/Assets/Spine Examples/Scripts/Goblins.cs index b88e88301..6f01e3f7f 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Goblins.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Goblins.cs @@ -39,7 +39,7 @@ namespace Spine.Unity.Examples { [Range(-360, 360)] public float extraRotation; - + public void Start () { skeletonAnimation = GetComponent(); headBone = skeletonAnimation.Skeleton.FindBone("head"); @@ -50,13 +50,13 @@ namespace Spine.Unity.Examples { public void UpdateLocal (ISkeletonAnimation skeletonRenderer) { headBone.Rotation += extraRotation; } - + public void OnMouseDown () { skeletonAnimation.Skeleton.SetSkin(girlSkin ? "goblin" : "goblingirl"); skeletonAnimation.Skeleton.SetSlotsToSetupPose(); - + girlSkin = !girlSkin; - + if (girlSkin) { skeletonAnimation.Skeleton.SetAttachment("right-hand-item", null); skeletonAnimation.Skeleton.SetAttachment("left-hand-item", "spear"); diff --git a/spine-unity/Assets/Spine Examples/Scripts/HurtFlashEffect.cs b/spine-unity/Assets/Spine Examples/Scripts/HurtFlashEffect.cs index e04b0fbc8..26b87d081 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/HurtFlashEffect.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/HurtFlashEffect.cs @@ -49,7 +49,7 @@ public class HurtFlashEffect : MonoBehaviour { if (mpb == null) mpb = new MaterialPropertyBlock(); if (meshRenderer == null) meshRenderer = GetComponent(); meshRenderer.GetPropertyBlock(mpb); - + StartCoroutine(FlashRoutine()); } diff --git a/spine-unity/Assets/Spine Examples/Scripts/MaterialPropertyBlockExample.cs b/spine-unity/Assets/Spine Examples/Scripts/MaterialPropertyBlockExample.cs index 5cc20d800..2f93732c4 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/MaterialPropertyBlockExample.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/MaterialPropertyBlockExample.cs @@ -40,7 +40,7 @@ namespace Spine.Unity.Examples { MaterialPropertyBlock mpb; float timeToNextColor = 0; - + void Start () { mpb = new MaterialPropertyBlock(); } diff --git a/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/DummyMecanimControllerExample.cs b/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/DummyMecanimControllerExample.cs index 74bc659b2..d01879b0a 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/DummyMecanimControllerExample.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/DummyMecanimControllerExample.cs @@ -35,8 +35,8 @@ namespace Spine.Unity.Examples { public class DummyMecanimControllerExample : MonoBehaviour { public Animator logicAnimator; - public SkeletonAnimationHandleExample animationHandle; - + public SkeletonAnimationHandleExample animationHandle; + [Header("Controls")] public KeyCode walkButton = KeyCode.LeftShift; public KeyCode jumpButton = KeyCode.Space; @@ -56,7 +56,7 @@ namespace Spine.Unity.Examples { } void Update () { - float x = Input.GetAxisRaw("Horizontal"); + float x = Input.GetAxisRaw("Horizontal"); if (Input.GetKey(walkButton)) { x *= 0.4f; } @@ -72,7 +72,7 @@ namespace Spine.Unity.Examples { if (isGrounded) StartCoroutine(FakeJump()); } - + logicAnimator.SetFloat(horizontalSpeedProperty, Mathf.Abs(speed.x)); logicAnimator.SetFloat(verticalSpeedProperty, speed.y); logicAnimator.SetBool(groundedProperty, isGrounded); diff --git a/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/MecanimToAnimationHandleExample.cs b/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/MecanimToAnimationHandleExample.cs index 4261ac20e..89c8c4d72 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/MecanimToAnimationHandleExample.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/MecanimToAnimationHandleExample.cs @@ -32,7 +32,7 @@ using System.Collections.Generic; using UnityEngine; namespace Spine.Unity.Examples { - + // This StateMachineBehaviour handles sending the Mecanim state information to the component that handles playing the Spine animations. public class MecanimToAnimationHandleExample : StateMachineBehaviour { SkeletonAnimationHandleExample animationHandle; diff --git a/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/SkeletonAnimationHandleExample.cs b/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/SkeletonAnimationHandleExample.cs index 609fdf386..1276f6054 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/SkeletonAnimationHandleExample.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Mecanim as Logic/SkeletonAnimationHandleExample.cs @@ -88,7 +88,7 @@ namespace Spine.Unity.Examples { PlayAnimationForState(StringToHash(stateShortName), layerIndex); } - /// Plays an animation based on the hash of the state name. + /// Plays an animation based on the hash of the state name. public void PlayAnimationForState (int shortNameHash, int layerIndex) { var foundAnimation = GetAnimationForState(shortNameHash); if (foundAnimation == null) @@ -139,7 +139,7 @@ namespace Spine.Unity.Examples { state.AddAnimation(0, this.TargetAnimation, true, 0f); } - Spine.Animation TryGetTransition (Spine.Animation from, Spine.Animation to) { + Spine.Animation TryGetTransition (Spine.Animation from, Spine.Animation to) { foreach (var transition in transitions) { if (transition.from.Animation == from && transition.to.Animation == to) { return transition.transition.Animation; diff --git a/spine-unity/Assets/Spine Examples/Scripts/Mix and Match Character Customize/EquipButtonExample.cs b/spine-unity/Assets/Spine Examples/Scripts/Mix and Match Character Customize/EquipButtonExample.cs index 8ac0410ff..8a1d23a39 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Mix and Match Character Customize/EquipButtonExample.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Mix and Match Character Customize/EquipButtonExample.cs @@ -54,7 +54,7 @@ namespace Spine.Unity.Examples { var button = GetComponent