From 120577bfe68a68790e941ae794f33e40f770f6b3 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 4 Apr 2024 15:27:43 +0200 Subject: [PATCH] Formatting --- .../spine-cpp/src/spine/AnimationState.cpp | 26 +- spine-cpp/spine-cpp/src/spine/Bone.cpp | 42 +- spine-cpp/spine-cpp/src/spine/BoneData.cpp | 32 +- .../spine-cpp/src/spine/IkConstraint.cpp | 4 +- .../spine-cpp/src/spine/InheritTimeline.cpp | 31 +- spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp | 24 +- .../spine-cpp/src/spine/PhysicsConstraint.cpp | 168 ++-- .../src/spine/PhysicsConstraintData.cpp | 4 +- spine-cpp/spine-cpp/src/spine/Skeleton.cpp | 936 +++++++++--------- .../spine-cpp/src/spine/SkeletonBinary.cpp | 420 ++++---- .../spine-cpp/src/spine/SkeletonJson.cpp | 270 ++--- spine-sdl/src/spine-sdl-cpp.cpp | 2 +- spine-sfml/cpp/example/main.cpp | 196 ++-- spine-sfml/cpp/src/spine/spine-sfml.cpp | 4 +- spine-ue/Source/SpineUE/MySceneComponent.cpp | 24 +- spine-ue/Source/SpineUE/MySceneComponent.h | 18 +- spine-ue/Source/SpineUE/SpineUEGameMode.cpp | 1 - spine-ue/Source/SpineUE/SpineUEGameMode.h | 2 +- spine-ue/Source/SpineUE/SpineboyCppPawn.cpp | 38 +- spine-ue/Source/SpineUE/SpineboyCppPawn.h | 20 +- 20 files changed, 1131 insertions(+), 1131 deletions(-) diff --git a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp index c6bf6ba3e..ad60bccda 100644 --- a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp +++ b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp @@ -163,9 +163,9 @@ float TrackEntry::getMixDuration() { return _mixDuration; } void TrackEntry::setMixDuration(float inValue) { _mixDuration = inValue; } void TrackEntry::setMixDuration(float mixDuration, float delay) { - _mixDuration = mixDuration; - if (_previous && delay <= 0) delay += _previous->getTrackComplete() - mixDuration; - this->_delay = delay; + _mixDuration = mixDuration; + if (_previous && delay <= 0) delay += _previous->getTrackComplete() - mixDuration; + this->_delay = delay; } TrackEntry *TrackEntry::getMixingFrom() { return _mixingFrom; } @@ -935,15 +935,15 @@ void AnimationState::queueEvents(TrackEntry *entry, float animationTime) { // Queue complete if completed a loop iteration or the animation. bool complete = false; if (entry->_loop) { - if (duration == 0) - complete = true; - else { - int cycles = (int) (entry->_trackTime / duration); - complete = cycles > 0 && cycles > (int) (entry->_trackLast / duration); - } - } else { - complete = animationTime >= animationEnd && entry->_animationLast < animationEnd; - } + if (duration == 0) + complete = true; + else { + int cycles = (int) (entry->_trackTime / duration); + complete = cycles > 0 && cycles > (int) (entry->_trackLast / duration); + } + } else { + complete = animationTime >= animationEnd && entry->_animationLast < animationEnd; + } if (complete) _queue->complete(entry); // Queue events after complete. @@ -998,7 +998,7 @@ TrackEntry *AnimationState::newTrackEntry(size_t trackIndex, Animation *animatio entry._eventThreshold = 0; entry._alphaAttachmentThreshold = 0; - entry._mixAttachmentThreshold = 0; + entry._mixAttachmentThreshold = 0; entry._mixDrawOrderThreshold = 0; entry._animationStart = 0; diff --git a/spine-cpp/spine-cpp/src/spine/Bone.cpp b/spine-cpp/spine-cpp/src/spine/Bone.cpp index ae0b8e2a9..3a8597a9c 100644 --- a/spine-cpp/spine-cpp/src/spine/Bone.cpp +++ b/spine-cpp/spine-cpp/src/spine/Bone.cpp @@ -72,7 +72,7 @@ Bone::Bone(BoneData &data, Skeleton &skeleton, Bone *parent) : Updatable(), _worldY(0), _sorted(false), _active(false), - _inherit(Inherit_Normal){ + _inherit(Inherit_Normal) { setToSetupPose(); } @@ -214,7 +214,7 @@ void Bone::setToSetupPose() { _scaleY = data.getScaleY(); _shearX = data.getShearX(); _shearY = data.getShearY(); - _inherit = data.getInherit(); + _inherit = data.getInherit(); } void Bone::worldToLocal(float worldX, float worldY, float &outLocalX, float &outLocalY) { @@ -232,12 +232,12 @@ void Bone::worldToLocal(float worldX, float worldY, float &outLocalX, float &out } void Bone::worldToParent(float worldX, float worldY, float &outParentX, float &outParentY) { - if (!_parent) { - outParentX = worldX; - outParentY = worldY; - } else { - _parent->worldToLocal(worldX, worldY, outParentX, outParentY); - } + if (!_parent) { + outParentX = worldX; + outParentY = worldY; + } else { + _parent->worldToLocal(worldX, worldY, outParentX, outParentY); + } } void Bone::localToWorld(float localX, float localY, float &outWorldX, float &outWorldY) { @@ -246,24 +246,24 @@ void Bone::localToWorld(float localX, float localY, float &outWorldX, float &out } void Bone::parentToWorld(float worldX, float worldY, float &outX, float &outY) { - if (!_parent) { - outX = worldX; - outY = worldY; - } else { - _parent->localToWorld(worldX, worldY, outX, outY); - } + if (!_parent) { + outX = worldX; + outY = worldY; + } else { + _parent->localToWorld(worldX, worldY, outX, outY); + } } float Bone::worldToLocalRotation(float worldRotation) { - worldRotation *= MathUtil::Deg_Rad; - float sine = MathUtil::sin(worldRotation), cosine = MathUtil::cos(worldRotation); - return MathUtil::atan2Deg(_a * sine - _c * cosine, _d * cosine - _b * sine) + _rotation - _shearX; + worldRotation *= MathUtil::Deg_Rad; + float sine = MathUtil::sin(worldRotation), cosine = MathUtil::cos(worldRotation); + return MathUtil::atan2Deg(_a * sine - _c * cosine, _d * cosine - _b * sine) + _rotation - _shearX; } float Bone::localToWorldRotation(float localRotation) { - localRotation = (localRotation - _rotation - _shearX) * MathUtil::Deg_Rad; - float sine = MathUtil::sin(localRotation), cosine = MathUtil::cos(localRotation); - return MathUtil::atan2Deg(cosine * _c + sine * _d, cosine * _a + sine * _b); + localRotation = (localRotation - _rotation - _shearX) * MathUtil::Deg_Rad; + float sine = MathUtil::sin(localRotation), cosine = MathUtil::cos(localRotation); + return MathUtil::atan2Deg(cosine * _c + sine * _d, cosine * _a + sine * _b); } void Bone::rotateWorld(float degrees) { @@ -540,7 +540,7 @@ void Bone::updateAppliedTransform() { case Inherit_NoScale: case Inherit_NoScaleOrReflection: { float r = _rotation * MathUtil::Deg_Rad; - float cos = MathUtil::cos(r), sin = MathUtil::sin(r); + float cos = MathUtil::cos(r), sin = MathUtil::sin(r); pa = (pa * cos + pb * sin) / _skeleton.getScaleX(); pc = (pc * cos + pd * sin) / _skeleton.getScaleY(); float s = MathUtil::sqrt(pa * pa + pc * pc); diff --git a/spine-cpp/spine-cpp/src/spine/BoneData.cpp b/spine-cpp/spine-cpp/src/spine/BoneData.cpp index 4e7d4a405..e6983463f 100644 --- a/spine-cpp/spine-cpp/src/spine/BoneData.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoneData.cpp @@ -34,21 +34,21 @@ using namespace spine; BoneData::BoneData(int index, const String &name, BoneData *parent) : _index(index), - _name(name), - _parent(parent), - _length(0), - _x(0), - _y(0), - _rotation(0), - _scaleX(1), - _scaleY(1), - _shearX(0), - _shearY(0), - _inherit(Inherit_Normal), - _skinRequired(false), - _color(), - _icon(), - _visible(true) { + _name(name), + _parent(parent), + _length(0), + _x(0), + _y(0), + _rotation(0), + _scaleX(1), + _scaleY(1), + _shearX(0), + _shearY(0), + _inherit(Inherit_Normal), + _skinRequired(false), + _color(), + _icon(), + _visible(true) { assert(index >= 0); assert(_name.length() > 0); } @@ -134,7 +134,7 @@ Inherit BoneData::getInherit() { } void BoneData::setInherit(Inherit inValue) { - _inherit = inValue; + _inherit = inValue; } bool BoneData::isSkinRequired() { diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 7aff7dc75..72904398b 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -109,8 +109,8 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY Bone *pp = parent.getParent(); float tx, ty, dx, dy, dd, l1, l2, a1, a2, r, td, sd, p; float id, x, y; - if (parent._inherit != Inherit_Normal || child._inherit != Inherit_Normal) return; - px = parent._ax; + if (parent._inherit != Inherit_Normal || child._inherit != Inherit_Normal) return; + px = parent._ax; py = parent._ay; psx = parent._ascaleX; psy = parent._ascaleY; diff --git a/spine-cpp/spine-cpp/src/spine/InheritTimeline.cpp b/spine-cpp/spine-cpp/src/spine/InheritTimeline.cpp index e45b9f65c..d9a1ff62a 100644 --- a/spine-cpp/spine-cpp/src/spine/InheritTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/InheritTimeline.cpp @@ -42,8 +42,8 @@ using namespace spine; RTTI_IMPL(InheritTimeline, Timeline) InheritTimeline::InheritTimeline(size_t frameCount, int boneIndex) : Timeline(frameCount, ENTRIES), - _boneIndex(boneIndex) { - PropertyId ids[] = {((PropertyId) Property_Inherit << 32) | boneIndex }; + _boneIndex(boneIndex) { + PropertyId ids[] = {((PropertyId) Property_Inherit << 32) | boneIndex}; setPropertyIds(ids, 1); } @@ -51,27 +51,26 @@ InheritTimeline::~InheritTimeline() { } void InheritTimeline::setFrame(int frame, float time, Inherit inherit) { - frame *= ENTRIES; - _frames[frame] = time; - _frames[frame + INHERIT] = inherit; + frame *= ENTRIES; + _frames[frame] = time; + _frames[frame + INHERIT] = inherit; } void InheritTimeline::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); - SP_UNUSED(alpha); + SP_UNUSED(alpha); - Bone *bone = skeleton.getBones()[_boneIndex]; - if (!bone->isActive()) return; + Bone *bone = skeleton.getBones()[_boneIndex]; + if (!bone->isActive()) return; - if (time < _frames[0]) { - if (blend == MixBlend_Setup || blend == MixBlend_First) bone->_inherit = bone->_data.getInherit(); - return; - } - int idx = Animation::search(_frames, time, ENTRIES) + INHERIT; - bone->_inherit = (Inherit)_frames[idx]; + if (time < _frames[0]) { + if (blend == MixBlend_Setup || blend == MixBlend_First) bone->_inherit = bone->_data.getInherit(); + return; + } + int idx = Animation::search(_frames, time, ENTRIES) + INHERIT; + bone->_inherit = (Inherit) _frames[idx]; } - diff --git a/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp b/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp index 1d716ee08..a0eb7d71f 100644 --- a/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp +++ b/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp @@ -34,19 +34,19 @@ using namespace spine; LinkedMesh::LinkedMesh(MeshAttachment *mesh, const int skinIndex, size_t slotIndex, const String &parent, - bool inheritTimeline) : _mesh(mesh), - _skinIndex(skinIndex), - _skin(""), - _slotIndex(slotIndex), - _parent(parent), - _inheritTimeline(inheritTimeline) { + bool inheritTimeline) : _mesh(mesh), + _skinIndex(skinIndex), + _skin(""), + _slotIndex(slotIndex), + _parent(parent), + _inheritTimeline(inheritTimeline) { } LinkedMesh::LinkedMesh(MeshAttachment *mesh, const String &skin, size_t slotIndex, const String &parent, - bool inheritTimeline) : _mesh(mesh), - _skinIndex(-1), - _skin(skin), - _slotIndex(slotIndex), - _parent(parent), - _inheritTimeline(inheritTimeline) { + bool inheritTimeline) : _mesh(mesh), + _skinIndex(-1), + _skin(skin), + _slotIndex(slotIndex), + _parent(parent), + _inheritTimeline(inheritTimeline) { } diff --git a/spine-cpp/spine-cpp/src/spine/PhysicsConstraint.cpp b/spine-cpp/spine-cpp/src/spine/PhysicsConstraint.cpp index 061fab345..9474fca9d 100644 --- a/spine-cpp/spine-cpp/src/spine/PhysicsConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/PhysicsConstraint.cpp @@ -324,7 +324,7 @@ void PhysicsConstraint::update(Physics physics) { reset(); // Fall through. case Physics::Physics_Update: { - float delta = MathUtil::max(_skeleton.getTime() - _lastTime, 0.0f); + float delta = MathUtil::max(_skeleton.getTime() - _lastTime, 0.0f); _remaining += delta; _lastTime = _skeleton.getTime(); @@ -334,92 +334,94 @@ void PhysicsConstraint::update(Physics physics) { _ux = bx; _uy = by; } else { - float a = _remaining, i = _inertia, q = _data._limit * delta, t = _data._step, f = _skeleton.getData()->getReferenceScale(), d = -1; + float a = _remaining, i = _inertia, q = _data._limit * delta, t = _data._step, f = _skeleton.getData()->getReferenceScale(), d = -1; if (x || y) { - if (x) { - float u = (_ux - bx) * i; - _xOffset += u > q ? q : u < -q ? -q : u; - _ux = bx; - } - if (y) { - float u = (_uy - by) * i; - _yOffset += u > q ? q : u < -q ? -q : u; - _uy = by; - } + if (x) { + float u = (_ux - bx) * i; + _xOffset += u > q ? q : u < -q ? -q + : u; + _ux = bx; + } + if (y) { + float u = (_uy - by) * i; + _yOffset += u > q ? q : u < -q ? -q + : u; + _uy = by; + } if (a >= t) { - d = MathUtil::pow(_damping, 60 * t); - float m = _massInverse * t, e = _strength, w = _wind * f, g = _gravity * f * (Bone::yDown ? -1 : 1); - do { - if (x) { - _xVelocity += (w - _xOffset * e) * m; - _xOffset += _xVelocity * t; - _xVelocity *= d; - } - if (y) { - _yVelocity -= (g + _yOffset * e) * m; - _yOffset += _yVelocity * t; - _yVelocity *= d; - } - a -= t; - } while (a >= t); + d = MathUtil::pow(_damping, 60 * t); + float m = _massInverse * t, e = _strength, w = _wind * f, g = _gravity * f * (Bone::yDown ? -1 : 1); + do { + if (x) { + _xVelocity += (w - _xOffset * e) * m; + _xOffset += _xVelocity * t; + _xVelocity *= d; + } + if (y) { + _yVelocity -= (g + _yOffset * e) * m; + _yOffset += _yVelocity * t; + _yVelocity *= d; + } + a -= t; + } while (a >= t); } if (x) bone->_worldX += _xOffset * mix * _data._x; if (y) bone->_worldY += _yOffset * mix * _data._y; } - if (rotateOrShearX || scaleX) { - float ca = MathUtil::atan2(bone->_c, bone->_a), c, s, mr = 0; - float dx = _cx - bone->_worldX, dy = _cy - bone->_worldY; - if (dx > q) - dx = q; - else if (dx < -q) // - dx = -q; - if (dy > q) - dy = q; - else if (dy < -q) // - dy = -q; - if (rotateOrShearX) { - mr = (_data._rotate + _data._shearX) * mix; - float r = MathUtil::atan2(dy + _ty, dx + _tx) - ca - _rotateOffset * mr; - _rotateOffset += (r - MathUtil::ceil(r * MathUtil::InvPi_2 - 0.5f) * MathUtil::Pi_2) * i; - r = _rotateOffset * mr + ca; - c = MathUtil::cos(r); - s = MathUtil::sin(r); - if (scaleX) { - r = l * bone->getWorldScaleX(); - if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r; - } - } else { - c = MathUtil::cos(ca); - s = MathUtil::sin(ca); - float r = l * bone->getWorldScaleX(); - if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r; - } - a = _remaining; - if (a >= t) { - if (d == -1) d = MathUtil::pow(_damping, 60 * t); - float m = _massInverse * t, e = _strength, w = _wind, g = _gravity, h = l / f; - while (true) { - a -= t; - if (scaleX) { - _scaleVelocity += (w * c - g * s - _scaleOffset * e) * m; - _scaleOffset += _scaleVelocity * t; - _scaleVelocity *= d; - } - if (rotateOrShearX) { - _rotateVelocity -= ((w * s + g * c) * h + _rotateOffset * e) * m; - _rotateOffset += _rotateVelocity * t; - _rotateVelocity *= d; - if (a < t) break; - float r = _rotateOffset * mr + ca; - c = MathUtil::cos(r); - s = MathUtil::sin(r); - } else if (a < t) // - break; - } - } - } - _remaining = a; + if (rotateOrShearX || scaleX) { + float ca = MathUtil::atan2(bone->_c, bone->_a), c, s, mr = 0; + float dx = _cx - bone->_worldX, dy = _cy - bone->_worldY; + if (dx > q) + dx = q; + else if (dx < -q)// + dx = -q; + if (dy > q) + dy = q; + else if (dy < -q)// + dy = -q; + if (rotateOrShearX) { + mr = (_data._rotate + _data._shearX) * mix; + float r = MathUtil::atan2(dy + _ty, dx + _tx) - ca - _rotateOffset * mr; + _rotateOffset += (r - MathUtil::ceil(r * MathUtil::InvPi_2 - 0.5f) * MathUtil::Pi_2) * i; + r = _rotateOffset * mr + ca; + c = MathUtil::cos(r); + s = MathUtil::sin(r); + if (scaleX) { + r = l * bone->getWorldScaleX(); + if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r; + } + } else { + c = MathUtil::cos(ca); + s = MathUtil::sin(ca); + float r = l * bone->getWorldScaleX(); + if (r > 0) _scaleOffset += (dx * c + dy * s) * i / r; + } + a = _remaining; + if (a >= t) { + if (d == -1) d = MathUtil::pow(_damping, 60 * t); + float m = _massInverse * t, e = _strength, w = _wind, g = _gravity, h = l / f; + while (true) { + a -= t; + if (scaleX) { + _scaleVelocity += (w * c - g * s - _scaleOffset * e) * m; + _scaleOffset += _scaleVelocity * t; + _scaleVelocity *= d; + } + if (rotateOrShearX) { + _rotateVelocity -= ((w * s + g * c) * h + _rotateOffset * e) * m; + _rotateOffset += _rotateVelocity * t; + _rotateVelocity *= d; + if (a < t) break; + float r = _rotateOffset * mr + ca; + c = MathUtil::cos(r); + s = MathUtil::sin(r); + } else if (a < t)// + break; + } + } + } + _remaining = a; } _cx = bone->_worldX; @@ -476,9 +478,9 @@ void PhysicsConstraint::update(Physics physics) { } void PhysicsConstraint::rotate(float x, float y, float degrees) { - float r = degrees * MathUtil::Deg_Rad, cos = MathUtil::cos(r), sin = MathUtil::sin(r); - float dx = _cx - x, dy = _cy - y; - translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy); + float r = degrees * MathUtil::Deg_Rad, cos = MathUtil::cos(r), sin = MathUtil::sin(r); + float dx = _cx - x, dy = _cy - y; + translate(dx * cos - dy * sin - dx, dx * sin + dy * cos - dy); } void PhysicsConstraint::translate(float x, float y) { diff --git a/spine-cpp/spine-cpp/src/spine/PhysicsConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/PhysicsConstraintData.cpp index 9fd92f69e..c0f091b65 100644 --- a/spine-cpp/spine-cpp/src/spine/PhysicsConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/PhysicsConstraintData.cpp @@ -95,11 +95,11 @@ float PhysicsConstraintData::getShearX() const { } void PhysicsConstraintData::setLimit(float limit) { - _limit = limit; + _limit = limit; } float PhysicsConstraintData::getLimit() const { - return _limit; + return _limit; } void PhysicsConstraintData::setStep(float step) { diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index a402534ef..2ecf860a2 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -56,457 +56,457 @@ using namespace spine; Skeleton::Skeleton(SkeletonData *skeletonData) - : _data(skeletonData), _skin(NULL), _color(1, 1, 1, 1), _scaleX(1), - _scaleY(1), _x(0), _y(0), _time(0) { - _bones.ensureCapacity(_data->getBones().size()); - for (size_t i = 0; i < _data->getBones().size(); ++i) { - BoneData *data = _data->getBones()[i]; + : _data(skeletonData), _skin(NULL), _color(1, 1, 1, 1), _scaleX(1), + _scaleY(1), _x(0), _y(0), _time(0) { + _bones.ensureCapacity(_data->getBones().size()); + for (size_t i = 0; i < _data->getBones().size(); ++i) { + BoneData *data = _data->getBones()[i]; - Bone *bone; - if (data->getParent() == NULL) { - bone = new (__FILE__, __LINE__) Bone(*data, *this, NULL); - } else { - Bone *parent = _bones[data->getParent()->getIndex()]; - bone = new (__FILE__, __LINE__) Bone(*data, *this, parent); - parent->getChildren().add(bone); - } + Bone *bone; + if (data->getParent() == NULL) { + bone = new (__FILE__, __LINE__) Bone(*data, *this, NULL); + } else { + Bone *parent = _bones[data->getParent()->getIndex()]; + bone = new (__FILE__, __LINE__) Bone(*data, *this, parent); + parent->getChildren().add(bone); + } - _bones.add(bone); - } + _bones.add(bone); + } - _slots.ensureCapacity(_data->getSlots().size()); - _drawOrder.ensureCapacity(_data->getSlots().size()); - for (size_t i = 0; i < _data->getSlots().size(); ++i) { - SlotData *data = _data->getSlots()[i]; + _slots.ensureCapacity(_data->getSlots().size()); + _drawOrder.ensureCapacity(_data->getSlots().size()); + for (size_t i = 0; i < _data->getSlots().size(); ++i) { + SlotData *data = _data->getSlots()[i]; - Bone *bone = _bones[data->getBoneData().getIndex()]; - Slot *slot = new (__FILE__, __LINE__) Slot(*data, *bone); + Bone *bone = _bones[data->getBoneData().getIndex()]; + Slot *slot = new (__FILE__, __LINE__) Slot(*data, *bone); - _slots.add(slot); - _drawOrder.add(slot); - } + _slots.add(slot); + _drawOrder.add(slot); + } - _ikConstraints.ensureCapacity(_data->getIkConstraints().size()); - for (size_t i = 0; i < _data->getIkConstraints().size(); ++i) { - IkConstraintData *data = _data->getIkConstraints()[i]; + _ikConstraints.ensureCapacity(_data->getIkConstraints().size()); + for (size_t i = 0; i < _data->getIkConstraints().size(); ++i) { + IkConstraintData *data = _data->getIkConstraints()[i]; - IkConstraint *constraint = - new (__FILE__, __LINE__) IkConstraint(*data, *this); + IkConstraint *constraint = + new (__FILE__, __LINE__) IkConstraint(*data, *this); - _ikConstraints.add(constraint); - } + _ikConstraints.add(constraint); + } - _transformConstraints.ensureCapacity(_data->getTransformConstraints().size()); - for (size_t i = 0; i < _data->getTransformConstraints().size(); ++i) { - TransformConstraintData *data = _data->getTransformConstraints()[i]; + _transformConstraints.ensureCapacity(_data->getTransformConstraints().size()); + for (size_t i = 0; i < _data->getTransformConstraints().size(); ++i) { + TransformConstraintData *data = _data->getTransformConstraints()[i]; - TransformConstraint *constraint = - new (__FILE__, __LINE__) TransformConstraint(*data, *this); + TransformConstraint *constraint = + new (__FILE__, __LINE__) TransformConstraint(*data, *this); - _transformConstraints.add(constraint); - } + _transformConstraints.add(constraint); + } - _pathConstraints.ensureCapacity(_data->getPathConstraints().size()); - for (size_t i = 0; i < _data->getPathConstraints().size(); ++i) { - PathConstraintData *data = _data->getPathConstraints()[i]; + _pathConstraints.ensureCapacity(_data->getPathConstraints().size()); + for (size_t i = 0; i < _data->getPathConstraints().size(); ++i) { + PathConstraintData *data = _data->getPathConstraints()[i]; - PathConstraint *constraint = - new (__FILE__, __LINE__) PathConstraint(*data, *this); + PathConstraint *constraint = + new (__FILE__, __LINE__) PathConstraint(*data, *this); - _pathConstraints.add(constraint); - } + _pathConstraints.add(constraint); + } - _physicsConstraints.ensureCapacity(_data->getPhysicsConstraints().size()); - for (size_t i = 0; i < _data->getPhysicsConstraints().size(); ++i) { - PhysicsConstraintData *data = _data->getPhysicsConstraints()[i]; + _physicsConstraints.ensureCapacity(_data->getPhysicsConstraints().size()); + for (size_t i = 0; i < _data->getPhysicsConstraints().size(); ++i) { + PhysicsConstraintData *data = _data->getPhysicsConstraints()[i]; - PhysicsConstraint *constraint = - new (__FILE__, __LINE__) PhysicsConstraint(*data, *this); + PhysicsConstraint *constraint = + new (__FILE__, __LINE__) PhysicsConstraint(*data, *this); - _physicsConstraints.add(constraint); - } + _physicsConstraints.add(constraint); + } - updateCache(); + updateCache(); } Skeleton::~Skeleton() { - ContainerUtil::cleanUpVectorOfPointers(_bones); - ContainerUtil::cleanUpVectorOfPointers(_slots); - ContainerUtil::cleanUpVectorOfPointers(_ikConstraints); - ContainerUtil::cleanUpVectorOfPointers(_transformConstraints); - ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); - ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints); + ContainerUtil::cleanUpVectorOfPointers(_bones); + ContainerUtil::cleanUpVectorOfPointers(_slots); + ContainerUtil::cleanUpVectorOfPointers(_ikConstraints); + ContainerUtil::cleanUpVectorOfPointers(_transformConstraints); + ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); + ContainerUtil::cleanUpVectorOfPointers(_physicsConstraints); } void Skeleton::updateCache() { - _updateCache.clear(); + _updateCache.clear(); - for (size_t i = 0, n = _bones.size(); i < n; ++i) { - Bone *bone = _bones[i]; - bone->_sorted = bone->_data.isSkinRequired(); - bone->_active = !bone->_sorted; - } + for (size_t i = 0, n = _bones.size(); i < n; ++i) { + Bone *bone = _bones[i]; + bone->_sorted = bone->_data.isSkinRequired(); + bone->_active = !bone->_sorted; + } - if (_skin) { - Vector &skinBones = _skin->getBones(); - for (size_t i = 0, n = skinBones.size(); i < n; i++) { - Bone *bone = _bones[skinBones[i]->getIndex()]; - do { - bone->_sorted = false; - bone->_active = true; - bone = bone->_parent; - } while (bone); - } - } + if (_skin) { + Vector &skinBones = _skin->getBones(); + for (size_t i = 0, n = skinBones.size(); i < n; i++) { + Bone *bone = _bones[skinBones[i]->getIndex()]; + do { + bone->_sorted = false; + bone->_active = true; + bone = bone->_parent; + } while (bone); + } + } - size_t ikCount = _ikConstraints.size(); - size_t transformCount = _transformConstraints.size(); - size_t pathCount = _pathConstraints.size(); - size_t physicsCount = _physicsConstraints.size(); - size_t constraintCount = ikCount + transformCount + pathCount + physicsCount; + size_t ikCount = _ikConstraints.size(); + size_t transformCount = _transformConstraints.size(); + size_t pathCount = _pathConstraints.size(); + size_t physicsCount = _physicsConstraints.size(); + size_t constraintCount = ikCount + transformCount + pathCount + physicsCount; - size_t i = 0; + size_t i = 0; continue_outer: - for (; i < constraintCount; ++i) { - for (size_t ii = 0; ii < ikCount; ++ii) { - IkConstraint *constraint = _ikConstraints[ii]; - if (constraint->getData().getOrder() == i) { - sortIkConstraint(constraint); - i++; - goto continue_outer; - } - } + for (; i < constraintCount; ++i) { + for (size_t ii = 0; ii < ikCount; ++ii) { + IkConstraint *constraint = _ikConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortIkConstraint(constraint); + i++; + goto continue_outer; + } + } - for (size_t ii = 0; ii < transformCount; ++ii) { - TransformConstraint *constraint = _transformConstraints[ii]; - if (constraint->getData().getOrder() == i) { - sortTransformConstraint(constraint); - i++; - goto continue_outer; - } - } + for (size_t ii = 0; ii < transformCount; ++ii) { + TransformConstraint *constraint = _transformConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortTransformConstraint(constraint); + i++; + goto continue_outer; + } + } - for (size_t ii = 0; ii < pathCount; ++ii) { - PathConstraint *constraint = _pathConstraints[ii]; - if (constraint->getData().getOrder() == i) { - sortPathConstraint(constraint); - i++; - goto continue_outer; - } - } + for (size_t ii = 0; ii < pathCount; ++ii) { + PathConstraint *constraint = _pathConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortPathConstraint(constraint); + i++; + goto continue_outer; + } + } - for (size_t ii = 0; ii < physicsCount; ++ii) { - PhysicsConstraint *constraint = _physicsConstraints[ii]; - if (constraint->getData().getOrder() == i) { - sortPhysicsConstraint(constraint); - i++; - goto continue_outer; - } - } - } + for (size_t ii = 0; ii < physicsCount; ++ii) { + PhysicsConstraint *constraint = _physicsConstraints[ii]; + if (constraint->getData().getOrder() == i) { + sortPhysicsConstraint(constraint); + i++; + goto continue_outer; + } + } + } - size_t n = _bones.size(); - for (i = 0; i < n; ++i) { - sortBone(_bones[i]); - } + size_t n = _bones.size(); + for (i = 0; i < n; ++i) { + sortBone(_bones[i]); + } } void Skeleton::printUpdateCache() { - for (size_t i = 0; i < _updateCache.size(); i++) { - Updatable *updatable = _updateCache[i]; - if (updatable->getRTTI().isExactly(Bone::rtti)) { - printf("bone %s\n", ((Bone *)updatable)->getData().getName().buffer()); - } else if (updatable->getRTTI().isExactly(TransformConstraint::rtti)) { - printf("transform constraint %s\n", - ((TransformConstraint *)updatable)->getData().getName().buffer()); - } else if (updatable->getRTTI().isExactly(IkConstraint::rtti)) { - printf("ik constraint %s\n", - ((IkConstraint *)updatable)->getData().getName().buffer()); - } else if (updatable->getRTTI().isExactly(PathConstraint::rtti)) { - printf("path constraint %s\n", - ((PathConstraint *)updatable)->getData().getName().buffer()); - } else if (updatable->getRTTI().isExactly(PhysicsConstraint::rtti)) { - printf("physics constraint %s\n", - ((PhysicsConstraint *)updatable)->getData().getName().buffer()); - } - } + for (size_t i = 0; i < _updateCache.size(); i++) { + Updatable *updatable = _updateCache[i]; + if (updatable->getRTTI().isExactly(Bone::rtti)) { + printf("bone %s\n", ((Bone *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(TransformConstraint::rtti)) { + printf("transform constraint %s\n", + ((TransformConstraint *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(IkConstraint::rtti)) { + printf("ik constraint %s\n", + ((IkConstraint *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(PathConstraint::rtti)) { + printf("path constraint %s\n", + ((PathConstraint *) updatable)->getData().getName().buffer()); + } else if (updatable->getRTTI().isExactly(PhysicsConstraint::rtti)) { + printf("physics constraint %s\n", + ((PhysicsConstraint *) updatable)->getData().getName().buffer()); + } + } } void Skeleton::updateWorldTransform(Physics physics) { - for (size_t i = 0, n = _bones.size(); i < n; i++) { - Bone *bone = _bones[i]; - bone->_ax = bone->_x; - bone->_ay = bone->_y; - bone->_arotation = bone->_rotation; - bone->_ascaleX = bone->_scaleX; - bone->_ascaleY = bone->_scaleY; - bone->_ashearX = bone->_shearX; - bone->_ashearY = bone->_shearY; - } + for (size_t i = 0, n = _bones.size(); i < n; i++) { + Bone *bone = _bones[i]; + bone->_ax = bone->_x; + bone->_ay = bone->_y; + bone->_arotation = bone->_rotation; + bone->_ascaleX = bone->_scaleX; + bone->_ascaleY = bone->_scaleY; + bone->_ashearX = bone->_shearX; + bone->_ashearY = bone->_shearY; + } - for (size_t i = 0, n = _updateCache.size(); i < n; ++i) { - Updatable *updatable = _updateCache[i]; - updatable->update(physics); - } + for (size_t i = 0, n = _updateCache.size(); i < n; ++i) { + Updatable *updatable = _updateCache[i]; + updatable->update(physics); + } } void Skeleton::updateWorldTransform(Physics physics, Bone *parent) { - // Apply the parent bone transform to the root bone. The root bone always - // inherits scale, rotation and reflection. - Bone *rootBone = getRootBone(); - float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d; - rootBone->_worldX = pa * _x + pb * _y + parent->_worldX; - rootBone->_worldY = pc * _x + pd * _y + parent->_worldY; + // Apply the parent bone transform to the root bone. The root bone always + // inherits scale, rotation and reflection. + Bone *rootBone = getRootBone(); + float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d; + rootBone->_worldX = pa * _x + pb * _y + parent->_worldX; + rootBone->_worldY = pc * _x + pd * _y + parent->_worldY; - float rx = (rootBone->_rotation + rootBone->_shearX) * MathUtil::Deg_Rad; - float ry = (rootBone->_rotation + 90 + rootBone->_shearY) * MathUtil::Deg_Rad; - float la = MathUtil::cos(rx) * rootBone->_scaleX; - float lb = MathUtil::cos(ry) * rootBone->_scaleY; - float lc = MathUtil::sin(rx) * rootBone->_scaleX; - float ld = MathUtil::sin(ry) * rootBone->_scaleY; - rootBone->_a = (pa * la + pb * lc) * _scaleX; - rootBone->_b = (pa * lb + pb * ld) * _scaleX; - rootBone->_c = (pc * la + pd * lc) * _scaleY; - rootBone->_d = (pc * lb + pd * ld) * _scaleY; + float rx = (rootBone->_rotation + rootBone->_shearX) * MathUtil::Deg_Rad; + float ry = (rootBone->_rotation + 90 + rootBone->_shearY) * MathUtil::Deg_Rad; + float la = MathUtil::cos(rx) * rootBone->_scaleX; + float lb = MathUtil::cos(ry) * rootBone->_scaleY; + float lc = MathUtil::sin(rx) * rootBone->_scaleX; + float ld = MathUtil::sin(ry) * rootBone->_scaleY; + rootBone->_a = (pa * la + pb * lc) * _scaleX; + rootBone->_b = (pa * lb + pb * ld) * _scaleX; + rootBone->_c = (pc * la + pd * lc) * _scaleY; + rootBone->_d = (pc * lb + pd * ld) * _scaleY; - // Update everything except root bone. - Bone *rb = getRootBone(); - for (size_t i = 0, n = _updateCache.size(); i < n; i++) { - Updatable *updatable = _updateCache[i]; - if (updatable != rb) - updatable->update(physics); - } + // Update everything except root bone. + Bone *rb = getRootBone(); + for (size_t i = 0, n = _updateCache.size(); i < n; i++) { + Updatable *updatable = _updateCache[i]; + if (updatable != rb) + updatable->update(physics); + } } void Skeleton::setToSetupPose() { - setBonesToSetupPose(); - setSlotsToSetupPose(); + setBonesToSetupPose(); + setSlotsToSetupPose(); } void Skeleton::setBonesToSetupPose() { - for (size_t i = 0, n = _bones.size(); i < n; ++i) { - _bones[i]->setToSetupPose(); - } + for (size_t i = 0, n = _bones.size(); i < n; ++i) { + _bones[i]->setToSetupPose(); + } - for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) { - _ikConstraints[i]->setToSetupPose(); - } + for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) { + _ikConstraints[i]->setToSetupPose(); + } - for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) { - _transformConstraints[i]->setToSetupPose(); - } + for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) { + _transformConstraints[i]->setToSetupPose(); + } - for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) { - _pathConstraints[i]->setToSetupPose(); - } + for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) { + _pathConstraints[i]->setToSetupPose(); + } - for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) { - _physicsConstraints[i]->setToSetupPose(); - } + for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) { + _physicsConstraints[i]->setToSetupPose(); + } } void Skeleton::setSlotsToSetupPose() { - _drawOrder.clear(); - for (size_t i = 0, n = _slots.size(); i < n; ++i) { - _drawOrder.add(_slots[i]); - } + _drawOrder.clear(); + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + _drawOrder.add(_slots[i]); + } - for (size_t i = 0, n = _slots.size(); i < n; ++i) { - _slots[i]->setToSetupPose(); - } + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + _slots[i]->setToSetupPose(); + } } Bone *Skeleton::findBone(const String &boneName) { - return ContainerUtil::findWithDataName(_bones, boneName); + return ContainerUtil::findWithDataName(_bones, boneName); } Slot *Skeleton::findSlot(const String &slotName) { - return ContainerUtil::findWithDataName(_slots, slotName); + return ContainerUtil::findWithDataName(_slots, slotName); } void Skeleton::setSkin(const String &skinName) { - Skin *foundSkin = skinName.isEmpty() ? NULL : _data->findSkin(skinName); - setSkin(foundSkin); + Skin *foundSkin = skinName.isEmpty() ? NULL : _data->findSkin(skinName); + setSkin(foundSkin); } void Skeleton::setSkin(Skin *newSkin) { - if (_skin == newSkin) - return; - if (newSkin != NULL) { - if (_skin != NULL) { - Skeleton &thisRef = *this; - newSkin->attachAll(thisRef, *_skin); - } else { - for (size_t i = 0, n = _slots.size(); i < n; ++i) { - Slot *slotP = _slots[i]; - Slot &slot = *slotP; - const String &name = slot._data.getAttachmentName(); - if (name.length() > 0) { - Attachment *attachment = newSkin->getAttachment(i, name); - if (attachment != NULL) { - slot.setAttachment(attachment); - } - } - } - } - } + if (_skin == newSkin) + return; + if (newSkin != NULL) { + if (_skin != NULL) { + Skeleton &thisRef = *this; + newSkin->attachAll(thisRef, *_skin); + } else { + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + Slot *slotP = _slots[i]; + Slot &slot = *slotP; + const String &name = slot._data.getAttachmentName(); + if (name.length() > 0) { + Attachment *attachment = newSkin->getAttachment(i, name); + if (attachment != NULL) { + slot.setAttachment(attachment); + } + } + } + } + } - _skin = newSkin; - updateCache(); + _skin = newSkin; + updateCache(); } Attachment *Skeleton::getAttachment(const String &slotName, - const String &attachmentName) { - return getAttachment(_data->findSlot(slotName)->getIndex(), attachmentName); + const String &attachmentName) { + return getAttachment(_data->findSlot(slotName)->getIndex(), attachmentName); } Attachment *Skeleton::getAttachment(int slotIndex, - const String &attachmentName) { - if (attachmentName.isEmpty()) - return NULL; + const String &attachmentName) { + if (attachmentName.isEmpty()) + return NULL; - if (_skin != NULL) { - Attachment *attachment = _skin->getAttachment(slotIndex, attachmentName); - if (attachment != NULL) { - return attachment; - } - } + if (_skin != NULL) { + Attachment *attachment = _skin->getAttachment(slotIndex, attachmentName); + if (attachment != NULL) { + return attachment; + } + } - return _data->getDefaultSkin() != NULL - ? _data->getDefaultSkin()->getAttachment(slotIndex, attachmentName) - : NULL; + return _data->getDefaultSkin() != NULL + ? _data->getDefaultSkin()->getAttachment(slotIndex, attachmentName) + : NULL; } void Skeleton::setAttachment(const String &slotName, - const String &attachmentName) { - assert(slotName.length() > 0); + const String &attachmentName) { + assert(slotName.length() > 0); - for (size_t i = 0, n = _slots.size(); i < n; ++i) { - Slot *slot = _slots[i]; - if (slot->_data.getName() == slotName) { - Attachment *attachment = NULL; - if (attachmentName.length() > 0) { - attachment = getAttachment((int)i, attachmentName); + for (size_t i = 0, n = _slots.size(); i < n; ++i) { + Slot *slot = _slots[i]; + if (slot->_data.getName() == slotName) { + Attachment *attachment = NULL; + if (attachmentName.length() > 0) { + attachment = getAttachment((int) i, attachmentName); - assert(attachment != NULL); - } + assert(attachment != NULL); + } - slot->setAttachment(attachment); + slot->setAttachment(attachment); - return; - } - } + return; + } + } - printf("Slot not found: %s", slotName.buffer()); + printf("Slot not found: %s", slotName.buffer()); - assert(false); + assert(false); } IkConstraint *Skeleton::findIkConstraint(const String &constraintName) { - assert(constraintName.length() > 0); + assert(constraintName.length() > 0); - for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) { - IkConstraint *ikConstraint = _ikConstraints[i]; - if (ikConstraint->_data.getName() == constraintName) { - return ikConstraint; - } - } - return NULL; + for (size_t i = 0, n = _ikConstraints.size(); i < n; ++i) { + IkConstraint *ikConstraint = _ikConstraints[i]; + if (ikConstraint->_data.getName() == constraintName) { + return ikConstraint; + } + } + return NULL; } TransformConstraint * Skeleton::findTransformConstraint(const String &constraintName) { - assert(constraintName.length() > 0); + assert(constraintName.length() > 0); - for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) { - TransformConstraint *transformConstraint = _transformConstraints[i]; - if (transformConstraint->_data.getName() == constraintName) { - return transformConstraint; - } - } + for (size_t i = 0, n = _transformConstraints.size(); i < n; ++i) { + TransformConstraint *transformConstraint = _transformConstraints[i]; + if (transformConstraint->_data.getName() == constraintName) { + return transformConstraint; + } + } - return NULL; + return NULL; } PathConstraint *Skeleton::findPathConstraint(const String &constraintName) { - assert(constraintName.length() > 0); + assert(constraintName.length() > 0); - for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) { - PathConstraint *constraint = _pathConstraints[i]; - if (constraint->_data.getName() == constraintName) { - return constraint; - } - } + for (size_t i = 0, n = _pathConstraints.size(); i < n; ++i) { + PathConstraint *constraint = _pathConstraints[i]; + if (constraint->_data.getName() == constraintName) { + return constraint; + } + } - return NULL; + return NULL; } PhysicsConstraint * Skeleton::findPhysicsConstraint(const String &constraintName) { - assert(constraintName.length() > 0); + assert(constraintName.length() > 0); - for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) { - PhysicsConstraint *constraint = _physicsConstraints[i]; - if (constraint->_data.getName() == constraintName) { - return constraint; - } - } + for (size_t i = 0, n = _physicsConstraints.size(); i < n; ++i) { + PhysicsConstraint *constraint = _physicsConstraints[i]; + if (constraint->_data.getName() == constraintName) { + return constraint; + } + } - return NULL; + return NULL; } void Skeleton::getBounds(float &outX, float &outY, float &outWidth, - float &outHeight, Vector &outVertexBuffer) { - float minX = FLT_MAX; - float minY = FLT_MAX; - float maxX = -FLT_MAX; - float maxY = -FLT_MAX; + float &outHeight, Vector &outVertexBuffer) { + float minX = FLT_MAX; + float minY = FLT_MAX; + float maxX = -FLT_MAX; + float maxY = -FLT_MAX; - for (size_t i = 0; i < _drawOrder.size(); ++i) { - Slot *slot = _drawOrder[i]; - if (!slot->_bone._active) - continue; - size_t verticesLength = 0; - Attachment *attachment = slot->getAttachment(); + for (size_t i = 0; i < _drawOrder.size(); ++i) { + Slot *slot = _drawOrder[i]; + if (!slot->_bone._active) + continue; + size_t verticesLength = 0; + Attachment *attachment = slot->getAttachment(); - if (attachment != NULL && - attachment->getRTTI().instanceOf(RegionAttachment::rtti)) { - RegionAttachment *regionAttachment = - static_cast(attachment); + if (attachment != NULL && + attachment->getRTTI().instanceOf(RegionAttachment::rtti)) { + RegionAttachment *regionAttachment = + static_cast(attachment); - verticesLength = 8; - if (outVertexBuffer.size() < 8) { - outVertexBuffer.setSize(8, 0); - } - regionAttachment->computeWorldVertices(*slot, outVertexBuffer, 0); - } else if (attachment != NULL && - attachment->getRTTI().instanceOf(MeshAttachment::rtti)) { - MeshAttachment *mesh = static_cast(attachment); + verticesLength = 8; + if (outVertexBuffer.size() < 8) { + outVertexBuffer.setSize(8, 0); + } + regionAttachment->computeWorldVertices(*slot, outVertexBuffer, 0); + } else if (attachment != NULL && + attachment->getRTTI().instanceOf(MeshAttachment::rtti)) { + MeshAttachment *mesh = static_cast(attachment); - verticesLength = mesh->getWorldVerticesLength(); - if (outVertexBuffer.size() < verticesLength) { - outVertexBuffer.setSize(verticesLength, 0); - } + verticesLength = mesh->getWorldVerticesLength(); + if (outVertexBuffer.size() < verticesLength) { + outVertexBuffer.setSize(verticesLength, 0); + } - mesh->computeWorldVertices(*slot, 0, verticesLength, - outVertexBuffer.buffer(), 0); - } + mesh->computeWorldVertices(*slot, 0, verticesLength, + outVertexBuffer.buffer(), 0); + } - for (size_t ii = 0; ii < verticesLength; ii += 2) { - float vx = outVertexBuffer[ii]; - float vy = outVertexBuffer[ii + 1]; + for (size_t ii = 0; ii < verticesLength; ii += 2) { + float vx = outVertexBuffer[ii]; + float vy = outVertexBuffer[ii + 1]; - minX = MathUtil::min(minX, vx); - minY = MathUtil::min(minY, vy); - maxX = MathUtil::max(maxX, vx); - maxY = MathUtil::max(maxY, vy); - } - } + minX = MathUtil::min(minX, vx); + minY = MathUtil::min(minY, vy); + maxX = MathUtil::max(maxX, vx); + maxY = MathUtil::max(maxY, vy); + } + } - outX = minX; - outY = minY; - outWidth = maxX - minX; - outHeight = maxY - minY; + outX = minX; + outY = minY; + outWidth = maxX - minX; + outHeight = maxY - minY; } Bone *Skeleton::getRootBone() { return _bones.size() == 0 ? NULL : _bones[0]; } @@ -524,15 +524,15 @@ Vector &Skeleton::getDrawOrder() { return _drawOrder; } Vector &Skeleton::getIkConstraints() { return _ikConstraints; } Vector &Skeleton::getPathConstraints() { - return _pathConstraints; + return _pathConstraints; } Vector &Skeleton::getTransformConstraints() { - return _transformConstraints; + return _transformConstraints; } Vector &Skeleton::getPhysicsConstraints() { - return _physicsConstraints; + return _physicsConstraints; } Skin *Skeleton::getSkin() { return _skin; } @@ -540,8 +540,8 @@ Skin *Skeleton::getSkin() { return _skin; } Color &Skeleton::getColor() { return _color; } void Skeleton::setPosition(float x, float y) { - _x = x; - _y = y; + _x = x; + _y = y; } float Skeleton::getX() { return _x; } @@ -561,170 +561,170 @@ float Skeleton::getScaleY() { return _scaleY * (Bone::isYDown() ? -1 : 1); } void Skeleton::setScaleY(float inValue) { _scaleY = inValue; } void Skeleton::sortIkConstraint(IkConstraint *constraint) { - constraint->_active = - constraint->_target->_active && - (!constraint->_data.isSkinRequired() || - (_skin && _skin->_constraints.contains(&constraint->_data))); - if (!constraint->_active) - return; + constraint->_active = + constraint->_target->_active && + (!constraint->_data.isSkinRequired() || + (_skin && _skin->_constraints.contains(&constraint->_data))); + if (!constraint->_active) + return; - Bone *target = constraint->getTarget(); - sortBone(target); + Bone *target = constraint->getTarget(); + sortBone(target); - Vector &constrained = constraint->getBones(); - Bone *parent = constrained[0]; - sortBone(parent); + Vector &constrained = constraint->getBones(); + Bone *parent = constrained[0]; + sortBone(parent); - if (constrained.size() == 1) { - _updateCache.add(constraint); - sortReset(parent->_children); - } else { - Bone *child = constrained[constrained.size() - 1]; - sortBone(child); + if (constrained.size() == 1) { + _updateCache.add(constraint); + sortReset(parent->_children); + } else { + Bone *child = constrained[constrained.size() - 1]; + sortBone(child); - _updateCache.add(constraint); + _updateCache.add(constraint); - sortReset(parent->_children); - child->_sorted = true; - } + sortReset(parent->_children); + child->_sorted = true; + } } void Skeleton::sortPathConstraint(PathConstraint *constraint) { - constraint->_active = - constraint->_target->_bone._active && - (!constraint->_data.isSkinRequired() || - (_skin && _skin->_constraints.contains(&constraint->_data))); - if (!constraint->_active) - return; + constraint->_active = + constraint->_target->_bone._active && + (!constraint->_data.isSkinRequired() || + (_skin && _skin->_constraints.contains(&constraint->_data))); + if (!constraint->_active) + return; - Slot *slot = constraint->getTarget(); - int slotIndex = slot->getData().getIndex(); - Bone &slotBone = slot->getBone(); - if (_skin != NULL) - sortPathConstraintAttachment(_skin, slotIndex, slotBone); - if (_data->_defaultSkin != NULL && _data->_defaultSkin != _skin) - sortPathConstraintAttachment(_data->_defaultSkin, slotIndex, slotBone); - for (size_t ii = 0, nn = _data->_skins.size(); ii < nn; ii++) - sortPathConstraintAttachment(_data->_skins[ii], slotIndex, slotBone); + Slot *slot = constraint->getTarget(); + int slotIndex = slot->getData().getIndex(); + Bone &slotBone = slot->getBone(); + if (_skin != NULL) + sortPathConstraintAttachment(_skin, slotIndex, slotBone); + if (_data->_defaultSkin != NULL && _data->_defaultSkin != _skin) + sortPathConstraintAttachment(_data->_defaultSkin, slotIndex, slotBone); + for (size_t ii = 0, nn = _data->_skins.size(); ii < nn; ii++) + sortPathConstraintAttachment(_data->_skins[ii], slotIndex, slotBone); - Attachment *attachment = slot->getAttachment(); - if (attachment != NULL && - attachment->getRTTI().instanceOf(PathAttachment::rtti)) - sortPathConstraintAttachment(attachment, slotBone); + Attachment *attachment = slot->getAttachment(); + if (attachment != NULL && + attachment->getRTTI().instanceOf(PathAttachment::rtti)) + sortPathConstraintAttachment(attachment, slotBone); - Vector &constrained = constraint->getBones(); - size_t boneCount = constrained.size(); - for (size_t i = 0; i < boneCount; ++i) { - sortBone(constrained[i]); - } + Vector &constrained = constraint->getBones(); + size_t boneCount = constrained.size(); + for (size_t i = 0; i < boneCount; ++i) { + sortBone(constrained[i]); + } - _updateCache.add(constraint); + _updateCache.add(constraint); - for (size_t i = 0; i < boneCount; i++) - sortReset(constrained[i]->getChildren()); - for (size_t i = 0; i < boneCount; i++) - constrained[i]->_sorted = true; + for (size_t i = 0; i < boneCount; i++) + sortReset(constrained[i]->getChildren()); + for (size_t i = 0; i < boneCount; i++) + constrained[i]->_sorted = true; } void Skeleton::sortTransformConstraint(TransformConstraint *constraint) { - constraint->_active = - constraint->_target->_active && - (!constraint->_data.isSkinRequired() || - (_skin && _skin->_constraints.contains(&constraint->_data))); - if (!constraint->_active) - return; + constraint->_active = + constraint->_target->_active && + (!constraint->_data.isSkinRequired() || + (_skin && _skin->_constraints.contains(&constraint->_data))); + if (!constraint->_active) + return; - sortBone(constraint->getTarget()); + sortBone(constraint->getTarget()); - Vector &constrained = constraint->getBones(); - size_t boneCount = constrained.size(); - if (constraint->_data.isLocal()) { - for (size_t i = 0; i < boneCount; i++) { - Bone *child = constrained[i]; - sortBone(child->getParent()); - sortBone(child); - } - } else { - for (size_t i = 0; i < boneCount; ++i) { - sortBone(constrained[i]); - } - } + Vector &constrained = constraint->getBones(); + size_t boneCount = constrained.size(); + if (constraint->_data.isLocal()) { + for (size_t i = 0; i < boneCount; i++) { + Bone *child = constrained[i]; + sortBone(child->getParent()); + sortBone(child); + } + } else { + for (size_t i = 0; i < boneCount; ++i) { + sortBone(constrained[i]); + } + } - _updateCache.add(constraint); + _updateCache.add(constraint); - for (size_t i = 0; i < boneCount; ++i) - sortReset(constrained[i]->getChildren()); - for (size_t i = 0; i < boneCount; ++i) - constrained[i]->_sorted = true; + for (size_t i = 0; i < boneCount; ++i) + sortReset(constrained[i]->getChildren()); + for (size_t i = 0; i < boneCount; ++i) + constrained[i]->_sorted = true; } void Skeleton::sortPhysicsConstraint(PhysicsConstraint *constraint) { - Bone *bone = constraint->getBone(); - constraint->_active = - bone->_active && - (!constraint->_data.isSkinRequired() || - (_skin && _skin->_constraints.contains(&constraint->_data))); - if (!constraint->_active) - return; + Bone *bone = constraint->getBone(); + constraint->_active = + bone->_active && + (!constraint->_data.isSkinRequired() || + (_skin && _skin->_constraints.contains(&constraint->_data))); + if (!constraint->_active) + return; - sortBone(bone); - _updateCache.add(constraint); - sortReset(bone->getChildren()); - bone->_sorted = true; + sortBone(bone); + _updateCache.add(constraint); + sortReset(bone->getChildren()); + bone->_sorted = true; } void Skeleton::sortPathConstraintAttachment(Skin *skin, size_t slotIndex, - Bone &slotBone) { - Skin::AttachmentMap::Entries attachments = skin->getAttachments(); + Bone &slotBone) { + Skin::AttachmentMap::Entries attachments = skin->getAttachments(); - while (attachments.hasNext()) { - Skin::AttachmentMap::Entry entry = attachments.next(); - if (entry._slotIndex == slotIndex) { - Attachment *value = entry._attachment; - sortPathConstraintAttachment(value, slotBone); - } - } + while (attachments.hasNext()) { + Skin::AttachmentMap::Entry entry = attachments.next(); + if (entry._slotIndex == slotIndex) { + Attachment *value = entry._attachment; + sortPathConstraintAttachment(value, slotBone); + } + } } void Skeleton::sortPathConstraintAttachment(Attachment *attachment, - Bone &slotBone) { - if (attachment == NULL || - !attachment->getRTTI().instanceOf(PathAttachment::rtti)) - return; - Vector &pathBones = - static_cast(attachment)->getBones(); - if (pathBones.size() == 0) - sortBone(&slotBone); - else { - for (size_t i = 0, n = pathBones.size(); i < n;) { - size_t nn = pathBones[i++]; - nn += i; - while (i < nn) { - sortBone(_bones[pathBones[i++]]); - } - } - } + Bone &slotBone) { + if (attachment == NULL || + !attachment->getRTTI().instanceOf(PathAttachment::rtti)) + return; + Vector &pathBones = + static_cast(attachment)->getBones(); + if (pathBones.size() == 0) + sortBone(&slotBone); + else { + for (size_t i = 0, n = pathBones.size(); i < n;) { + size_t nn = pathBones[i++]; + nn += i; + while (i < nn) { + sortBone(_bones[pathBones[i++]]); + } + } + } } void Skeleton::sortBone(Bone *bone) { - if (bone->_sorted) - return; - Bone *parent = bone->_parent; - if (parent != NULL) - sortBone(parent); - bone->_sorted = true; - _updateCache.add(bone); + if (bone->_sorted) + return; + Bone *parent = bone->_parent; + if (parent != NULL) + sortBone(parent); + bone->_sorted = true; + _updateCache.add(bone); } void Skeleton::sortReset(Vector &bones) { - for (size_t i = 0, n = bones.size(); i < n; ++i) { - Bone *bone = bones[i]; - if (!bone->_active) - continue; - if (bone->_sorted) - sortReset(bone->getChildren()); - bone->_sorted = false; - } + for (size_t i = 0, n = bones.size(); i < n; ++i) { + Bone *bone = bones[i]; + if (!bone->_active) + continue; + if (bone->_sorted) + sortReset(bone->getChildren()); + bone->_sorted = false; + } } float Skeleton::getTime() { return _time; } @@ -734,13 +734,13 @@ void Skeleton::setTime(float time) { _time = time; } void Skeleton::update(float delta) { _time += delta; } void Skeleton::physicsTranslate(float x, float y) { - for (int i = 0; i < (int)_physicsConstraints.size(); i++) { - _physicsConstraints[i]->translate(x, y); - } + for (int i = 0; i < (int) _physicsConstraints.size(); i++) { + _physicsConstraints[i]->translate(x, y); + } } void Skeleton::physicsRotate(float x, float y, float degrees) { - for (int i = 0; i < (int)_physicsConstraints.size(); i++) { - _physicsConstraints[i]->rotate(x, y, degrees); - } + for (int i = 0; i < (int) _physicsConstraints.size(); i++) { + _physicsConstraints[i]->rotate(x, y, degrees); + } } diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp index af29d00eb..07b491219 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp @@ -132,7 +132,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons skeletonData->_y = readFloat(input); skeletonData->_width = readFloat(input); skeletonData->_height = readFloat(input); - skeletonData->_referenceScale = readFloat(input) * this->_scale; + skeletonData->_referenceScale = readFloat(input) * this->_scale; nonessential = readBoolean(input); @@ -165,8 +165,8 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons data->_skinRequired = readBoolean(input); if (nonessential) { readColor(input, data->getColor()); - data->_icon.own(readString(input)); - data->_visible = readBoolean(input); + data->_icon.own(readString(input)); + data->_visible = readBoolean(input); } skeletonData->_bones[i] = data; } @@ -176,14 +176,14 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons skeletonData->_slots.setSize(slotsCount, 0); for (int i = 0; i < slotsCount; ++i) { String slotName = String(readString(input), true); - String pathName = ""; - if (nonessential) { - int slash = slotName.lastIndexOf('/'); - if (slash != -1) { - pathName = slotName.substring(0, slash); - slotName = slotName.substring(slash + 1); - } - } + String pathName = ""; + if (nonessential) { + int slash = slotName.lastIndexOf('/'); + if (slash != -1) { + pathName = slotName.substring(0, slash); + slotName = slotName.substring(slash + 1); + } + } BoneData *boneData = skeletonData->_bones[readVarint(input, true)]; SlotData *slotData = new (__FILE__, __LINE__) SlotData(i, slotName, *boneData); @@ -198,10 +198,10 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons } slotData->_attachmentName = readStringRef(input, skeletonData); slotData->_blendMode = static_cast(readVarint(input, true)); - if (nonessential) { - slotData->_visible = readBoolean(input); - slotData->_path = pathName; - } + if (nonessential) { + slotData->_visible = readBoolean(input); + slotData->_path = pathName; + } skeletonData->_slots[i] = slotData; } @@ -217,14 +217,14 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons for (int ii = 0; ii < bonesCount; ++ii) data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; data->_target = skeletonData->_bones[readVarint(input, true)]; - int flags = readByte(input); - data->_skinRequired = (flags & 1) != 0; - data->_bendDirection = (flags & 2) != 0 ? 1 : -1; - data->_compress = (flags & 4) != 0; - data->_stretch = (flags & 8) != 0; - data->_uniform = (flags & 16) != 0; - if ((flags & 32) != 0) data->_mix = (flags & 64) != 0 ? readFloat(input) : 1; - if ((flags & 128) != 0) data->_softness = readFloat(input) * _scale; + int flags = readByte(input); + data->_skinRequired = (flags & 1) != 0; + data->_bendDirection = (flags & 2) != 0 ? 1 : -1; + data->_compress = (flags & 4) != 0; + data->_stretch = (flags & 8) != 0; + data->_uniform = (flags & 16) != 0; + if ((flags & 32) != 0) data->_mix = (flags & 64) != 0 ? readFloat(input) : 1; + if ((flags & 128) != 0) data->_softness = readFloat(input) * _scale; skeletonData->_ikConstraints[i] = data; } @@ -241,25 +241,25 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons for (int ii = 0; ii < bonesCount; ++ii) data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; data->_target = skeletonData->_bones[readVarint(input, true)]; - int flags = readByte(input); - data->_skinRequired = (flags & 1) != 0; - data->_local = (flags & 2) != 0; - data->_relative = (flags & 4) != 0; - if ((flags & 8) != 0) data->_offsetRotation = readFloat(input); - if ((flags & 16) != 0) data->_offsetX =readFloat(input) * _scale; - if ((flags & 32) != 0) data->_offsetY = readFloat(input) * _scale; - if ((flags & 64) != 0) data->_offsetScaleX = readFloat(input); - if ((flags & 128) != 0) data->_offsetScaleY = readFloat(input); - flags = readByte(input); - if ((flags & 1) != 0) data->_offsetShearY = readFloat(input); - if ((flags & 2) != 0) data->_mixRotate = readFloat(input); - if ((flags & 4) != 0) data->_mixX = readFloat(input); - if ((flags & 8) != 0) data->_mixY = readFloat(input); - if ((flags & 16) != 0) data->_mixScaleX = readFloat(input); - if ((flags & 32) != 0) data->_mixScaleY = readFloat(input); - if ((flags & 64) != 0) data->_mixShearY = readFloat(input); + int flags = readByte(input); + data->_skinRequired = (flags & 1) != 0; + data->_local = (flags & 2) != 0; + data->_relative = (flags & 4) != 0; + if ((flags & 8) != 0) data->_offsetRotation = readFloat(input); + if ((flags & 16) != 0) data->_offsetX = readFloat(input) * _scale; + if ((flags & 32) != 0) data->_offsetY = readFloat(input) * _scale; + if ((flags & 64) != 0) data->_offsetScaleX = readFloat(input); + if ((flags & 128) != 0) data->_offsetScaleY = readFloat(input); + flags = readByte(input); + if ((flags & 1) != 0) data->_offsetShearY = readFloat(input); + if ((flags & 2) != 0) data->_mixRotate = readFloat(input); + if ((flags & 4) != 0) data->_mixX = readFloat(input); + if ((flags & 8) != 0) data->_mixY = readFloat(input); + if ((flags & 16) != 0) data->_mixScaleX = readFloat(input); + if ((flags & 32) != 0) data->_mixScaleY = readFloat(input); + if ((flags & 64) != 0) data->_mixShearY = readFloat(input); - skeletonData->_transformConstraints[i] = data; + skeletonData->_transformConstraints[i] = data; } /* Path constraints */ @@ -275,11 +275,11 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons for (int ii = 0; ii < bonesCount; ++ii) data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; data->_target = skeletonData->_slots[readVarint(input, true)]; - int flags = readByte(input); - data->_positionMode = (PositionMode)(flags & 1); - data->_spacingMode = (SpacingMode)((flags >> 1) & 3); - data->_rotateMode = (RotateMode)((flags >> 3) & 3); - if ((flags & 128) != 0) data->_offsetRotation = readFloat(input); + int flags = readByte(input); + data->_positionMode = (PositionMode) (flags & 1); + data->_spacingMode = (SpacingMode) ((flags >> 1) & 3); + data->_rotateMode = (RotateMode) ((flags >> 3) & 3); + if ((flags & 128) != 0) data->_offsetRotation = readFloat(input); data->_position = readFloat(input); if (data->_positionMode == PositionMode_Fixed) data->_position *= _scale; data->_spacing = readFloat(input); @@ -291,40 +291,40 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons skeletonData->_pathConstraints[i] = data; } - // Physics constraints. - int physicsConstraintsCount = readVarint(input, true); - skeletonData->_physicsConstraints.setSize(physicsConstraintsCount, 0); - for (int i = 0; i < physicsConstraintsCount; i++) { - const char *name = readString(input); - PhysicsConstraintData *data = new (__FILE__, __LINE__) PhysicsConstraintData(String(name, true)); - data->_order = readVarint(input, true); - data->_bone = skeletonData->_bones[readVarint(input, true)]; - int flags = readByte(input); - data->_skinRequired = (flags & 1) != 0; - if ((flags & 2) != 0) data->_x = readFloat(input); - if ((flags & 4) != 0) data->_y = readFloat(input); - if ((flags & 8) != 0) data->_rotate = readFloat(input); - if ((flags & 16) != 0) data->_scaleX = readFloat(input); - if ((flags & 32) != 0) data->_shearX = readFloat(input); - data->_limit = ((flags & 64) != 0 ? readFloat(input) : 5000) * _scale; - data->_step = 1.f / readByte(input); - data->_inertia = readFloat(input); - data->_strength = readFloat(input); - data->_damping = readFloat(input); - data->_massInverse = (flags & 128) != 0 ? readFloat(input) : 1; - data->_wind = readFloat(input); - data->_gravity = readFloat(input); - flags = readByte(input); - if ((flags & 1) != 0) data->_inertiaGlobal = true; - if ((flags & 2) != 0) data->_strengthGlobal = true; - if ((flags & 4) != 0) data->_dampingGlobal = true; - if ((flags & 8) != 0) data->_massGlobal = true; - if ((flags & 16) != 0) data->_windGlobal = true; - if ((flags & 32) != 0) data->_gravityGlobal = true; - if ((flags & 64) != 0) data->_mixGlobal = true; - data->_mix = (flags & 128) != 0 ? readFloat(input) : 1; - skeletonData->_physicsConstraints[i] = data; - } + // Physics constraints. + int physicsConstraintsCount = readVarint(input, true); + skeletonData->_physicsConstraints.setSize(physicsConstraintsCount, 0); + for (int i = 0; i < physicsConstraintsCount; i++) { + const char *name = readString(input); + PhysicsConstraintData *data = new (__FILE__, __LINE__) PhysicsConstraintData(String(name, true)); + data->_order = readVarint(input, true); + data->_bone = skeletonData->_bones[readVarint(input, true)]; + int flags = readByte(input); + data->_skinRequired = (flags & 1) != 0; + if ((flags & 2) != 0) data->_x = readFloat(input); + if ((flags & 4) != 0) data->_y = readFloat(input); + if ((flags & 8) != 0) data->_rotate = readFloat(input); + if ((flags & 16) != 0) data->_scaleX = readFloat(input); + if ((flags & 32) != 0) data->_shearX = readFloat(input); + data->_limit = ((flags & 64) != 0 ? readFloat(input) : 5000) * _scale; + data->_step = 1.f / readByte(input); + data->_inertia = readFloat(input); + data->_strength = readFloat(input); + data->_damping = readFloat(input); + data->_massInverse = (flags & 128) != 0 ? readFloat(input) : 1; + data->_wind = readFloat(input); + data->_gravity = readFloat(input); + flags = readByte(input); + if ((flags & 1) != 0) data->_inertiaGlobal = true; + if ((flags & 2) != 0) data->_strengthGlobal = true; + if ((flags & 4) != 0) data->_dampingGlobal = true; + if ((flags & 8) != 0) data->_massGlobal = true; + if ((flags & 16) != 0) data->_windGlobal = true; + if ((flags & 32) != 0) data->_gravityGlobal = true; + if ((flags & 64) != 0) data->_mixGlobal = true; + data->_mix = (flags & 128) != 0 ? readFloat(input) : 1; + skeletonData->_physicsConstraints[i] = data; + } /* Default skin. */ Skin *defaultSkin = readSkin(input, true, skeletonData, nonessential); @@ -507,7 +507,7 @@ Skin *SkeletonBinary::readSkin(DataInput *input, bool defaultSkin, SkeletonData } else { skin = new (__FILE__, __LINE__) Skin(String(readString(input), true)); - if (nonessential) readColor(input, skin->getColor()); + if (nonessential) readColor(input, skin->getColor()); for (int i = 0, n = readVarint(input, true); i < n; i++) { int boneIndex = readVarint(input, true); @@ -533,11 +533,11 @@ Skin *SkeletonBinary::readSkin(DataInput *input, bool defaultSkin, SkeletonData skin->getConstraints().add(skeletonData->_pathConstraints[pathIndex]); } - for (int i = 0, n = readVarint(input, true); i < n; i++) { - int physicsIndex = readVarint(input, true); - if (physicsIndex >= (int) skeletonData->_physicsConstraints.size()) return NULL; - skin->getConstraints().add(skeletonData->_physicsConstraints[physicsIndex]); - } + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int physicsIndex = readVarint(input, true); + if (physicsIndex >= (int) skeletonData->_physicsConstraints.size()) return NULL; + skin->getConstraints().add(skeletonData->_physicsConstraints[physicsIndex]); + } slotCount = readVarint(input, true); } @@ -568,16 +568,16 @@ Sequence *SkeletonBinary::readSequence(DataInput *input) { Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slotIndex, const String &attachmentName, SkeletonData *skeletonData, bool nonessential) { - int flags = readByte(input); - String name = (flags & 8) != 0 ? readStringRef(input, skeletonData) : attachmentName; + int flags = readByte(input); + String name = (flags & 8) != 0 ? readStringRef(input, skeletonData) : attachmentName; AttachmentType type = static_cast(flags & 0x7); switch (type) { case AttachmentType_Region: { - String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; - Color color(1, 1, 1, 1); - if ((flags & 32) != 0) readColor(input, color); - Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; - float rotation = (flags & 128) != 0 ? readFloat(input) : 0; + String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; + Color color(1, 1, 1, 1); + if ((flags & 32) != 0) readColor(input, color); + Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; + float rotation = (flags & 128) != 0 ? readFloat(input) : 0; float x = readFloat(input) * _scale; float y = readFloat(input) * _scale; float scaleX = readFloat(input); @@ -627,14 +627,14 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo float height = 0; Vector edges; - String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; - Color color(1, 1, 1, 1); - if ((flags & 32) != 0) readColor(input, color); - Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; + String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; + Color color(1, 1, 1, 1); + if ((flags & 32) != 0) readColor(input, color); + Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; hullLength = readVarint(input, true); - int verticesLength = readVertices(input, vertices, bones, (flags & 128) != 0); - readFloatArray(input, verticesLength, 1, uvs); - readShortArray(input, triangles, (verticesLength - hullLength - 2) * 3); + int verticesLength = readVertices(input, vertices, bones, (flags & 128) != 0); + readFloatArray(input, verticesLength, 1, uvs); + readShortArray(input, triangles, (verticesLength - hullLength - 2) * 3); if (nonessential) { readShortArray(input, edges, readVarint(input, true)); @@ -666,14 +666,14 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo return mesh; } case AttachmentType_Linkedmesh: { - String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; - Color color(1, 1, 1, 1); - if ((flags & 32) != 0) readColor(input, color); - Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; - bool inheritTimelines = (flags & 128) != 0; - int skinIndex = readVarint(input, true); + String path = (flags & 16) != 0 ? readStringRef(input, skeletonData) : name; + Color color(1, 1, 1, 1); + if ((flags & 32) != 0) readColor(input, color); + Sequence *sequence = (flags & 64) != 0 ? readSequence(input) : nullptr; + bool inheritTimelines = (flags & 128) != 0; + int skinIndex = readVarint(input, true); String parent(readStringRef(input, skeletonData)); - float width = 0, height = 0; + float width = 0, height = 0; if (nonessential) { width = readFloat(input) * _scale; height = readFloat(input) * _scale; @@ -756,14 +756,14 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo int SkeletonBinary::readVertices(DataInput *input, Vector &vertices, Vector &bones, bool weighted) { float scale = _scale; - int vertexCount = readVarint(input, true); + int vertexCount = readVarint(input, true); int verticesLength = vertexCount << 1; - if (!weighted) { - readFloatArray(input, verticesLength, scale, vertices); - return verticesLength; - } - vertices.ensureCapacity(verticesLength * 3 * 3); - bones.ensureCapacity(verticesLength * 3); + if (!weighted) { + readFloatArray(input, verticesLength, scale, vertices); + return verticesLength; + } + vertices.ensureCapacity(verticesLength * 3 * 3); + bones.ensureCapacity(verticesLength * 3); for (int i = 0; i < vertexCount; ++i) { int boneCount = readVarint(input, true); bones.add(boneCount); @@ -774,7 +774,7 @@ int SkeletonBinary::readVertices(DataInput *input, Vector &vertices, Vect vertices.add(readFloat(input)); } } - return verticesLength; + return verticesLength; } void SkeletonBinary::readFloatArray(DataInput *input, int n, float scale, Vector &array) { @@ -795,7 +795,7 @@ void SkeletonBinary::readFloatArray(DataInput *input, int n, float scale, Vector void SkeletonBinary::readShortArray(DataInput *input, Vector &array, int n) { array.setSize(n, 0); for (int i = 0; i < n; ++i) { - array[i] = (short)readVarint(input, true); + array[i] = (short) readVarint(input, true); } } @@ -809,7 +809,7 @@ void SkeletonBinary::setBezier(DataInput *input, CurveTimeline *timeline, int be timeline->setBezier(bezier, frame, value, time1, value1, cx1, cy1 * scale, cx2, cy2 * scale, time2, value2); } -void SkeletonBinary::readTimeline(DataInput *input, Vector &timelines, CurveTimeline1 *timeline, float scale) { +void SkeletonBinary::readTimeline(DataInput *input, Vector &timelines, CurveTimeline1 *timeline, float scale) { float time = readFloat(input); float value = readFloat(input) * scale; for (int frame = 0, bezier = 0, frameLast = (int) timeline->getFrameCount() - 1;; frame++) { @@ -827,10 +827,10 @@ void SkeletonBinary::readTimeline(DataInput *input, Vector &timelines time = time2; value = value2; } - timelines.add(timeline); + timelines.add(timeline); } -void SkeletonBinary::readTimeline2(DataInput *input, Vector &timelines, CurveTimeline2 *timeline, float scale) { +void SkeletonBinary::readTimeline2(DataInput *input, Vector &timelines, CurveTimeline2 *timeline, float scale) { float time = readFloat(input); float value1 = readFloat(input) * scale; float value2 = readFloat(input) * scale; @@ -1086,61 +1086,61 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { unsigned char timelineType = readByte(input); int frameCount = readVarint(input, true); - if (timelineType == BONE_INHERIT) { - InheritTimeline *timeline = new (__FILE__, __LINE__) InheritTimeline(frameCount, boneIndex); - for (int frame = 0; frame < frameCount; frame++) { - float time = readFloat(input); - Inherit inherit = (Inherit)readByte(input); - timeline->setFrame(frame, time, inherit); - } - timelines.add(timeline); - continue; - } - int bezierCount = readVarint(input, true); + if (timelineType == BONE_INHERIT) { + InheritTimeline *timeline = new (__FILE__, __LINE__) InheritTimeline(frameCount, boneIndex); + for (int frame = 0; frame < frameCount; frame++) { + float time = readFloat(input); + Inherit inherit = (Inherit) readByte(input); + timeline->setFrame(frame, time, inherit); + } + timelines.add(timeline); + continue; + } + int bezierCount = readVarint(input, true); switch (timelineType) { case BONE_ROTATE: readTimeline(input, timelines, - new (__FILE__, __LINE__) RotateTimeline(frameCount, bezierCount, boneIndex), - 1); + new (__FILE__, __LINE__) RotateTimeline(frameCount, bezierCount, boneIndex), + 1); break; case BONE_TRANSLATE: - readTimeline2(input, timelines,new (__FILE__, __LINE__) TranslateTimeline(frameCount, bezierCount, boneIndex), scale); + readTimeline2(input, timelines, new (__FILE__, __LINE__) TranslateTimeline(frameCount, bezierCount, boneIndex), scale); break; case BONE_TRANSLATEX: readTimeline(input, timelines, new (__FILE__, __LINE__) TranslateXTimeline(frameCount, bezierCount, boneIndex), scale); break; case BONE_TRANSLATEY: - readTimeline(input, timelines, new (__FILE__, __LINE__) TranslateYTimeline(frameCount, bezierCount, boneIndex), scale); + readTimeline(input, timelines, new (__FILE__, __LINE__) TranslateYTimeline(frameCount, bezierCount, boneIndex), scale); break; case BONE_SCALE: readTimeline2(input, timelines, - new (__FILE__, __LINE__) ScaleTimeline(frameCount, bezierCount, boneIndex), - 1); + new (__FILE__, __LINE__) ScaleTimeline(frameCount, bezierCount, boneIndex), + 1); break; case BONE_SCALEX: readTimeline(input, timelines, - new (__FILE__, __LINE__) ScaleXTimeline(frameCount, bezierCount, boneIndex), - 1); + new (__FILE__, __LINE__) ScaleXTimeline(frameCount, bezierCount, boneIndex), + 1); break; case BONE_SCALEY: readTimeline(input, timelines, - new (__FILE__, __LINE__) ScaleYTimeline(frameCount, bezierCount, boneIndex), - 1); + new (__FILE__, __LINE__) ScaleYTimeline(frameCount, bezierCount, boneIndex), + 1); break; case BONE_SHEAR: readTimeline2(input, timelines, - new (__FILE__, __LINE__) ShearTimeline(frameCount, bezierCount, boneIndex), - 1); + new (__FILE__, __LINE__) ShearTimeline(frameCount, bezierCount, boneIndex), + 1); break; case BONE_SHEARX: readTimeline(input, timelines, - new (__FILE__, __LINE__) ShearXTimeline(frameCount, bezierCount, boneIndex), - 1); + new (__FILE__, __LINE__) ShearXTimeline(frameCount, bezierCount, boneIndex), + 1); break; case BONE_SHEARY: readTimeline(input, timelines, - new (__FILE__, __LINE__) ShearYTimeline(frameCount, bezierCount, boneIndex), - 1); + new (__FILE__, __LINE__) ShearYTimeline(frameCount, bezierCount, boneIndex), + 1); break; default: { ContainerUtil::cleanUpVectorOfPointers(timelines); @@ -1158,19 +1158,19 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S int frameLast = frameCount - 1; int bezierCount = readVarint(input, true); IkConstraintTimeline *timeline = new (__FILE__, __LINE__) IkConstraintTimeline(frameCount, bezierCount, index); - int flags = readByte(input); - float time = readFloat(input), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0; - float softness = (flags & 4) != 0 ? readFloat(input) * scale : 0; - for (int frame = 0, bezier = 0;; frame++) { + int flags = readByte(input); + float time = readFloat(input), mix = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0; + float softness = (flags & 4) != 0 ? readFloat(input) * scale : 0; + for (int frame = 0, bezier = 0;; frame++) { timeline->setFrame(frame, time, mix, softness, (flags & 8) != 0 ? 1 : -1, (flags & 16) != 0, (flags & 32) != 0); if (frame == frameLast) break; - flags = readByte(input); - float time2 = readFloat(input), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0; - float softness2 = (flags & 4) != 0 ? readFloat(input) * scale : 0; - if ((flags & 64) != 0) - timeline->setStepped(frame); - else if ((flags & 128) != 0) { - setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1); + flags = readByte(input); + float time2 = readFloat(input), mix2 = (flags & 1) != 0 ? ((flags & 2) != 0 ? readFloat(input) : 1) : 0; + float softness2 = (flags & 4) != 0 ? readFloat(input) * scale : 0; + if ((flags & 64) != 0) + timeline->setStepped(frame); + else if ((flags & 128) != 0) { + setBezier(input, timeline, bezier++, frame, 0, time, time2, mix, mix2, 1); setBezier(input, timeline, bezier++, frame, 1, time, time2, softness, softness2, scale); } time = time2; @@ -1235,21 +1235,21 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S int type = readByte(input); int frameCount = readVarint(input, true); int bezierCount = readVarint(input, true); - switch (type) { + switch (type) { case PATH_POSITION: { readTimeline(input, timelines, new PathConstraintPositionTimeline(frameCount, bezierCount, index), - data->_positionMode == PositionMode_Fixed ? scale : 1); + data->_positionMode == PositionMode_Fixed ? scale : 1); break; } case PATH_SPACING: { readTimeline(input, timelines, - new PathConstraintSpacingTimeline(frameCount, - bezierCount, - index), - data->_spacingMode == SpacingMode_Length || - data->_spacingMode == SpacingMode_Fixed - ? scale - : 1); + new PathConstraintSpacingTimeline(frameCount, + bezierCount, + index), + data->_spacingMode == SpacingMode_Length || + data->_spacingMode == SpacingMode_Fixed + ? scale + : 1); break; } case PATH_MIX: @@ -1284,44 +1284,44 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S } } - // Physics timelines. - for (int i = 0, n = readVarint(input, true); i < n; i++) { - int index = readVarint(input, true) - 1; - for (int ii = 0, nn = readVarint(input, true); ii < nn; ii++) { - int type = readByte(input); - int frameCount = readVarint(input, true); - if (type == PHYSICS_RESET) { - PhysicsConstraintResetTimeline *timeline = new (__FILE__, __LINE__) PhysicsConstraintResetTimeline(frameCount, index); - for (int frame = 0; frame < frameCount; frame++) - timeline->setFrame(frame, readFloat(input)); - timelines.add(timeline); - continue; - } - int bezierCount = readVarint(input, true); - switch (type) { - case PHYSICS_INERTIA: - readTimeline(input, timelines, new PhysicsConstraintInertiaTimeline(frameCount, bezierCount, index), 1); - break; - case PHYSICS_STRENGTH: - readTimeline(input, timelines, new PhysicsConstraintStrengthTimeline(frameCount, bezierCount, index), 1); - break; - case PHYSICS_DAMPING: - readTimeline(input, timelines, new PhysicsConstraintDampingTimeline(frameCount, bezierCount, index), 1); - break; - case PHYSICS_MASS: - readTimeline(input, timelines, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1); - break; - case PHYSICS_WIND: - readTimeline(input, timelines, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), 1); - break; - case PHYSICS_GRAVITY: - readTimeline(input, timelines, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), 1); - break; - case PHYSICS_MIX: - readTimeline(input, timelines, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1); - } - } - } + // Physics timelines. + for (int i = 0, n = readVarint(input, true); i < n; i++) { + int index = readVarint(input, true) - 1; + for (int ii = 0, nn = readVarint(input, true); ii < nn; ii++) { + int type = readByte(input); + int frameCount = readVarint(input, true); + if (type == PHYSICS_RESET) { + PhysicsConstraintResetTimeline *timeline = new (__FILE__, __LINE__) PhysicsConstraintResetTimeline(frameCount, index); + for (int frame = 0; frame < frameCount; frame++) + timeline->setFrame(frame, readFloat(input)); + timelines.add(timeline); + continue; + } + int bezierCount = readVarint(input, true); + switch (type) { + case PHYSICS_INERTIA: + readTimeline(input, timelines, new PhysicsConstraintInertiaTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_STRENGTH: + readTimeline(input, timelines, new PhysicsConstraintStrengthTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_DAMPING: + readTimeline(input, timelines, new PhysicsConstraintDampingTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_MASS: + readTimeline(input, timelines, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_WIND: + readTimeline(input, timelines, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_GRAVITY: + readTimeline(input, timelines, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), 1); + break; + case PHYSICS_MIX: + readTimeline(input, timelines, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1); + } + } + } // Attachment timelines. for (int i = 0, n = readVarint(input, true); i < n; ++i) { @@ -1467,12 +1467,12 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S event->_intValue = readVarint(input, false); event->_floatValue = readFloat(input); const char *event_stringValue = readString(input); - if (event_stringValue == nullptr) { - event->_stringValue = eventData->_stringValue; - } else { - event->_stringValue = String(event_stringValue); - SpineExtension::free(event_stringValue, __FILE__, __LINE__); - } + if (event_stringValue == nullptr) { + event->_stringValue = eventData->_stringValue; + } else { + event->_stringValue = String(event_stringValue); + SpineExtension::free(event_stringValue, __FILE__, __LINE__); + } if (!eventData->_audioPath.isEmpty()) { event->_volume = readFloat(input); diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp index 32bb5e4aa..f9cc6e96a 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp @@ -163,8 +163,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { skeletonData->_y = Json::getFloat(skeleton, "y", 0); skeletonData->_width = Json::getFloat(skeleton, "width", 0); skeletonData->_height = Json::getFloat(skeleton, "height", 0); - skeletonData->_referenceScale = Json::getFloat(skeleton, "referenceScale", 100) * _scale; - skeletonData->_fps = Json::getFloat(skeleton, "fps", 30); + skeletonData->_referenceScale = Json::getFloat(skeleton, "referenceScale", 100) * _scale; + skeletonData->_fps = Json::getFloat(skeleton, "fps", 30); skeletonData->_audioPath = Json::getString(skeleton, "audio", 0); skeletonData->_imagesPath = Json::getString(skeleton, "images", 0); } @@ -214,8 +214,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { const char *color = Json::getString(boneMap, "color", NULL); if (color) toColor(data->getColor(), color, true); - data->_icon = Json::getString(boneMap, "icon", ""); - data->_visible = Json::getBoolean(boneMap, "visible", true); + data->_icon = Json::getString(boneMap, "icon", ""); + data->_visible = Json::getBoolean(boneMap, "visible", true); skeletonData->_bones[i] = data; bonesCount++; @@ -241,13 +241,13 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { return NULL; } - String pathName = ""; - String slotName = String(Json::getString(slotMap, "name", 0)); - int slash = slotName.lastIndexOf('/'); - if (slash != -1) { - pathName = slotName.substring(0, slash); - slotName = slotName.substring(slash + 1); - } + String pathName = ""; + String slotName = String(Json::getString(slotMap, "name", 0)); + int slash = slotName.lastIndexOf('/'); + if (slash != -1) { + pathName = slotName.substring(0, slash); + slotName = slotName.substring(slash + 1); + } data = new (__FILE__, __LINE__) SlotData(i, slotName, *boneData); color = Json::getString(slotMap, "color", 0); @@ -280,8 +280,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { else if (strcmp(item->_valueString, "screen") == 0) data->_blendMode = BlendMode_Screen; } - data->_visible = Json::getBoolean(slotMap, "visible", true); - data->_path = pathName; + data->_visible = Json::getBoolean(slotMap, "visible", true); + data->_path = pathName; skeletonData->_slots[i] = data; } } @@ -457,53 +457,53 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { } } - /* Physics constraints */ - physics = Json::getItem(root, "physics"); - if (physics) { - Json *constraintMap; - skeletonData->_physicsConstraints.ensureCapacity(physics->_size); - skeletonData->_physicsConstraints.setSize(physics->_size, 0); - for (constraintMap = physics->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { - const char *name; + /* Physics constraints */ + physics = Json::getItem(root, "physics"); + if (physics) { + Json *constraintMap; + skeletonData->_physicsConstraints.ensureCapacity(physics->_size); + skeletonData->_physicsConstraints.setSize(physics->_size, 0); + for (constraintMap = physics->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { + const char *name; - PhysicsConstraintData *data = new (__FILE__, __LINE__) PhysicsConstraintData( - Json::getString(constraintMap, "name", 0)); - data->setOrder(Json::getInt(constraintMap, "order", 0)); - data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); + PhysicsConstraintData *data = new (__FILE__, __LINE__) PhysicsConstraintData( + Json::getString(constraintMap, "name", 0)); + data->setOrder(Json::getInt(constraintMap, "order", 0)); + data->setSkinRequired(Json::getBoolean(constraintMap, "skin", false)); - name = Json::getString(constraintMap, "bone", 0); - data->_bone = skeletonData->findBone(name); - if (!data->_bone) { - delete skeletonData; - setError(root, "Physics bone not found: ", name); - return NULL; - } + name = Json::getString(constraintMap, "bone", 0); + data->_bone = skeletonData->findBone(name); + if (!data->_bone) { + delete skeletonData; + setError(root, "Physics bone not found: ", name); + return NULL; + } - data->_x = Json::getFloat(constraintMap, "x", 0); - data->_y = Json::getFloat(constraintMap, "y", 0); - data->_rotate = Json::getFloat(constraintMap, "rotate", 0); - data->_scaleX = Json::getFloat(constraintMap, "scaleX", 0); - data->_shearX = Json::getFloat(constraintMap, "shearX", 0); - data->_limit = Json::getFloat(constraintMap, "limit", 5000) * _scale; - data->_step = 1.0f / Json::getInt(constraintMap, "fps", 60); - data->_inertia = Json::getFloat(constraintMap, "inertia", 1); - data->_strength = Json::getFloat(constraintMap, "strength", 100); - data->_damping = Json::getFloat(constraintMap, "damping", 1); - data->_massInverse = 1.0f / Json::getFloat(constraintMap, "mass", 1); - data->_wind = Json::getFloat(constraintMap, "wind", 0); - data->_gravity = Json::getFloat(constraintMap, "gravity", 0); - data->_mix = Json::getFloat(constraintMap, "mix", 1); - data->_inertiaGlobal = Json::getBoolean(constraintMap, "inertiaGlobal", false); - data->_strengthGlobal = Json::getBoolean(constraintMap, "strengthGlobal", false); - data->_dampingGlobal = Json::getBoolean(constraintMap, "dampingGlobal", false); - data->_massGlobal = Json::getBoolean(constraintMap, "massGlobal", false); - data->_windGlobal = Json::getBoolean(constraintMap, "windGlobal", false); - data->_gravityGlobal = Json::getBoolean(constraintMap, "gravityGlobal", false); - data->_mixGlobal = Json::getBoolean(constraintMap, "mixGlobal", false); + data->_x = Json::getFloat(constraintMap, "x", 0); + data->_y = Json::getFloat(constraintMap, "y", 0); + data->_rotate = Json::getFloat(constraintMap, "rotate", 0); + data->_scaleX = Json::getFloat(constraintMap, "scaleX", 0); + data->_shearX = Json::getFloat(constraintMap, "shearX", 0); + data->_limit = Json::getFloat(constraintMap, "limit", 5000) * _scale; + data->_step = 1.0f / Json::getInt(constraintMap, "fps", 60); + data->_inertia = Json::getFloat(constraintMap, "inertia", 1); + data->_strength = Json::getFloat(constraintMap, "strength", 100); + data->_damping = Json::getFloat(constraintMap, "damping", 1); + data->_massInverse = 1.0f / Json::getFloat(constraintMap, "mass", 1); + data->_wind = Json::getFloat(constraintMap, "wind", 0); + data->_gravity = Json::getFloat(constraintMap, "gravity", 0); + data->_mix = Json::getFloat(constraintMap, "mix", 1); + data->_inertiaGlobal = Json::getBoolean(constraintMap, "inertiaGlobal", false); + data->_strengthGlobal = Json::getBoolean(constraintMap, "strengthGlobal", false); + data->_dampingGlobal = Json::getBoolean(constraintMap, "dampingGlobal", false); + data->_massGlobal = Json::getBoolean(constraintMap, "massGlobal", false); + data->_windGlobal = Json::getBoolean(constraintMap, "windGlobal", false); + data->_gravityGlobal = Json::getBoolean(constraintMap, "gravityGlobal", false); + data->_mixGlobal = Json::getBoolean(constraintMap, "mixGlobal", false); - skeletonData->_physicsConstraints[i] = data; - } - } + skeletonData->_physicsConstraints[i] = data; + } + } /* Skins. */ skins = Json::getItem(root, "skins"); @@ -570,18 +570,18 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { } } - item = Json::getItem(skinMap, "physics"); - if (item) { - for (item = item->_child; item; item = item->_next) { - PhysicsConstraintData *data = skeletonData->findPhysicsConstraint(item->_valueString); - if (!data) { - delete skeletonData; - setError(root, String("Skin physics constraint not found: "), item->_valueString); - return NULL; - } - skin->getConstraints().add(data); - } - } + item = Json::getItem(skinMap, "physics"); + if (item) { + for (item = item->_child; item; item = item->_next) { + PhysicsConstraintData *data = skeletonData->findPhysicsConstraint(item->_valueString); + if (!data) { + delete skeletonData; + setError(root, String("Skin physics constraint not found: "), item->_valueString); + return NULL; + } + skin->getConstraints().add(data); + } + } skeletonData->_skins[skinsIndex++] = skin; if (strcmp(Json::getString(skinMap, "name", ""), "default") == 0) { @@ -956,7 +956,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { Json *ik = Json::getItem(root, "ik"); Json *transform = Json::getItem(root, "transform"); Json *paths = Json::getItem(root, "path"); - Json *physics = Json::getItem(root, "physics"); + Json *physics = Json::getItem(root, "physics"); Json *attachments = Json::getItem(root, "attachments"); Json *drawOrder = Json::getItem(root, "drawOrder"); Json *events = Json::getItem(root, "events"); @@ -1163,26 +1163,26 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { frames, boneIndex); timelines.add(readTimeline(timelineMap->_child, timeline, 0, 1)); } else if (strcmp(timelineMap->_name, "inherit") == 0) { - InheritTimeline *timeline = new (__FILE__, __LINE__) InheritTimeline(frames, boneIndex); - for (frame = 0;; frame++) { - float time = Json::getFloat(keyMap, "time", 0); - const char *value = Json::getString(keyMap, "value", "normal"); - Inherit inherit = Inherit_Normal; - if (strcmp(value, "normal") == 0) inherit = Inherit_Normal; - else if (strcmp(value, "onlyTranslation") == 0) - inherit = Inherit_OnlyTranslation; - else if (strcmp(value, "noRotationOrReflection") == 0) - inherit = Inherit_NoRotationOrReflection; - else if (strcmp(value, "noScale") == 0) - inherit = Inherit_NoScale; - else if (strcmp(value, "noScaleOrReflection") == 0) - inherit = Inherit_NoScaleOrReflection; - timeline->setFrame(frame, time, inherit); - nextMap = keyMap->_next; - if (!nextMap) break; - } - timelines.add(timeline); - }else { + InheritTimeline *timeline = new (__FILE__, __LINE__) InheritTimeline(frames, boneIndex); + for (frame = 0;; frame++) { + float time = Json::getFloat(keyMap, "time", 0); + const char *value = Json::getString(keyMap, "value", "normal"); + Inherit inherit = Inherit_Normal; + if (strcmp(value, "normal") == 0) inherit = Inherit_Normal; + else if (strcmp(value, "onlyTranslation") == 0) + inherit = Inherit_OnlyTranslation; + else if (strcmp(value, "noRotationOrReflection") == 0) + inherit = Inherit_NoRotationOrReflection; + else if (strcmp(value, "noScale") == 0) + inherit = Inherit_NoScale; + else if (strcmp(value, "noScaleOrReflection") == 0) + inherit = Inherit_NoScaleOrReflection; + timeline->setFrame(frame, time, inherit); + nextMap = keyMap->_next; + if (!nextMap) break; + } + timelines.add(timeline); + } else { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Invalid timeline type for a bone: ", timelineMap->_name); return NULL; @@ -1351,53 +1351,53 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) { } } - /** Physics constraint timelines. */ - for (Json *constraintMap = physics ? physics->_child : 0; constraintMap; constraintMap = constraintMap->_next) { - int index = -1; - if (constraintMap->_name && strlen(constraintMap->_name) > 0) { - PhysicsConstraintData *constraint = skeletonData->findPhysicsConstraint(constraintMap->_name); - if (!constraint) { - ContainerUtil::cleanUpVectorOfPointers(timelines); - setError(NULL, "Physics constraint not found: ", constraintMap->_name); - return NULL; - } - index = skeletonData->_physicsConstraints.indexOf(constraint); - } - for (Json *timelineMap = constraintMap->_child; timelineMap; timelineMap = timelineMap->_next) { - keyMap = timelineMap->_child; - if (keyMap == NULL) continue; - const char *timelineName = timelineMap->_name; - int frames = timelineMap->_size; - if (strcmp(timelineName, "reset") == 0) { - PhysicsConstraintResetTimeline *timeline = new (__FILE__, __LINE__) PhysicsConstraintResetTimeline(frames, index); - for (frame = 0; keyMap != nullptr; keyMap = keyMap->_next, frame++) { - timeline->setFrame(frame, Json::getFloat(keyMap, "time", 0)); - } - timelines.add(timeline); - continue; - } + /** Physics constraint timelines. */ + for (Json *constraintMap = physics ? physics->_child : 0; constraintMap; constraintMap = constraintMap->_next) { + int index = -1; + if (constraintMap->_name && strlen(constraintMap->_name) > 0) { + PhysicsConstraintData *constraint = skeletonData->findPhysicsConstraint(constraintMap->_name); + if (!constraint) { + ContainerUtil::cleanUpVectorOfPointers(timelines); + setError(NULL, "Physics constraint not found: ", constraintMap->_name); + return NULL; + } + index = skeletonData->_physicsConstraints.indexOf(constraint); + } + for (Json *timelineMap = constraintMap->_child; timelineMap; timelineMap = timelineMap->_next) { + keyMap = timelineMap->_child; + if (keyMap == NULL) continue; + const char *timelineName = timelineMap->_name; + int frames = timelineMap->_size; + if (strcmp(timelineName, "reset") == 0) { + PhysicsConstraintResetTimeline *timeline = new (__FILE__, __LINE__) PhysicsConstraintResetTimeline(frames, index); + for (frame = 0; keyMap != nullptr; keyMap = keyMap->_next, frame++) { + timeline->setFrame(frame, Json::getFloat(keyMap, "time", 0)); + } + timelines.add(timeline); + continue; + } - CurveTimeline1 *timeline = nullptr; - if (strcmp(timelineName, "inertia") == 0) { - timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index); - } else if (strcmp(timelineName, "strength") == 0) { - timeline = new PhysicsConstraintStrengthTimeline(frames, frames, index); - } else if (strcmp(timelineName, "damping") == 0) { - timeline = new PhysicsConstraintDampingTimeline(frames, frames, index); - } else if (strcmp(timelineName, "mass") == 0) { - timeline = new PhysicsConstraintMassTimeline(frames, frames, index); - } else if (strcmp(timelineName, "wind") == 0) { - timeline = new PhysicsConstraintWindTimeline(frames, frames, index); - } else if (strcmp(timelineName, "gravity") == 0) { - timeline = new PhysicsConstraintGravityTimeline(frames, frames, index); - } else if (strcmp(timelineName, "mix") == 0) { - timeline = new PhysicsConstraintMixTimeline(frames, frames, index); - } else { - continue; - } - timelines.add(readTimeline(keyMap, timeline, 0, 1)); - } - } + CurveTimeline1 *timeline = nullptr; + if (strcmp(timelineName, "inertia") == 0) { + timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index); + } else if (strcmp(timelineName, "strength") == 0) { + timeline = new PhysicsConstraintStrengthTimeline(frames, frames, index); + } else if (strcmp(timelineName, "damping") == 0) { + timeline = new PhysicsConstraintDampingTimeline(frames, frames, index); + } else if (strcmp(timelineName, "mass") == 0) { + timeline = new PhysicsConstraintMassTimeline(frames, frames, index); + } else if (strcmp(timelineName, "wind") == 0) { + timeline = new PhysicsConstraintWindTimeline(frames, frames, index); + } else if (strcmp(timelineName, "gravity") == 0) { + timeline = new PhysicsConstraintGravityTimeline(frames, frames, index); + } else if (strcmp(timelineName, "mix") == 0) { + timeline = new PhysicsConstraintMixTimeline(frames, frames, index); + } else { + continue; + } + timelines.add(readTimeline(keyMap, timeline, 0, 1)); + } + } /** Attachment timelines. */ for (Json *attachmenstMap = attachments ? attachments->_child : NULL; attachmenstMap; attachmenstMap = attachmenstMap->_next) { diff --git a/spine-sdl/src/spine-sdl-cpp.cpp b/spine-sdl/src/spine-sdl-cpp.cpp index 841168656..8bb11661e 100644 --- a/spine-sdl/src/spine-sdl-cpp.cpp +++ b/spine-sdl/src/spine-sdl-cpp.cpp @@ -54,7 +54,7 @@ SkeletonDrawable::~SkeletonDrawable() { void SkeletonDrawable::update(float delta, Physics physics) { animationState->update(delta); animationState->apply(*skeleton); - skeleton->update(delta); + skeleton->update(delta); skeleton->updateWorldTransform(physics); } diff --git a/spine-sfml/cpp/example/main.cpp b/spine-sfml/cpp/example/main.cpp index 51914105c..301b872d0 100644 --- a/spine-sfml/cpp/example/main.cpp +++ b/spine-sfml/cpp/example/main.cpp @@ -612,139 +612,139 @@ void mixAndMatch(SkeletonData *skeletonData, Atlas *atlas) { } void celestialCircus(SkeletonData *skeletonData, Atlas *atlas) { - SP_UNUSED(atlas); + SP_UNUSED(atlas); - SkeletonDrawable drawable(skeletonData); - drawable.timeScale = 1; - drawable.setUsePremultipliedAlpha(true); + SkeletonDrawable drawable(skeletonData); + drawable.timeScale = 1; + drawable.setUsePremultipliedAlpha(true); - Skeleton *skeleton = drawable.skeleton; - skeleton->setPosition(320, 480); - skeleton->updateWorldTransform(Physics_Update); + Skeleton *skeleton = drawable.skeleton; + skeleton->setPosition(320, 480); + skeleton->updateWorldTransform(Physics_Update); - drawable.state->setAnimation(0, "swing", true); + drawable.state->setAnimation(0, "swing", true); - sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - celestial circus"); - window.setFramerateLimit(60); - sf::Event event; - sf::Clock deltaClock; + sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - celestial circus"); + window.setFramerateLimit(60); + sf::Event event; + sf::Clock deltaClock; - while (window.isOpen()) { - while (window.pollEvent(event)) { - if (event.type == sf::Event::Closed) window.close(); - } + while (window.isOpen()) { + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) window.close(); + } - float delta = deltaClock.getElapsedTime().asSeconds(); - deltaClock.restart(); + float delta = deltaClock.getElapsedTime().asSeconds(); + deltaClock.restart(); - drawable.update(delta); + drawable.update(delta); - window.clear(); - window.draw(drawable); - window.display(); - } + window.clear(); + window.draw(drawable); + window.display(); + } } void sack(SkeletonData *skeletonData, Atlas *atlas) { - SP_UNUSED(atlas); + SP_UNUSED(atlas); - SkeletonDrawable drawable(skeletonData); - drawable.timeScale = 1; - drawable.setUsePremultipliedAlpha(true); + SkeletonDrawable drawable(skeletonData); + drawable.timeScale = 1; + drawable.setUsePremultipliedAlpha(true); - Skeleton *skeleton = drawable.skeleton; - skeleton->setPosition(320, 480); - skeleton->updateWorldTransform(Physics_Update); + Skeleton *skeleton = drawable.skeleton; + skeleton->setPosition(320, 480); + skeleton->updateWorldTransform(Physics_Update); - drawable.state->setAnimation(0, "walk", true); + drawable.state->setAnimation(0, "walk", true); - sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - sack"); - window.setFramerateLimit(60); - sf::Event event; - sf::Clock deltaClock; + sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - sack"); + window.setFramerateLimit(60); + sf::Event event; + sf::Clock deltaClock; - while (window.isOpen()) { - while (window.pollEvent(event)) { - if (event.type == sf::Event::Closed) window.close(); - } + while (window.isOpen()) { + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) window.close(); + } - float delta = deltaClock.getElapsedTime().asSeconds(); - deltaClock.restart(); + float delta = deltaClock.getElapsedTime().asSeconds(); + deltaClock.restart(); - drawable.update(delta); + drawable.update(delta); - window.clear(); - window.draw(drawable); - window.display(); - } + window.clear(); + window.draw(drawable); + window.display(); + } } void snowglobe(SkeletonData *skeletonData, Atlas *atlas) { - SP_UNUSED(atlas); + SP_UNUSED(atlas); - SkeletonDrawable drawable(skeletonData); - drawable.timeScale = 1; - drawable.setUsePremultipliedAlpha(true); + SkeletonDrawable drawable(skeletonData); + drawable.timeScale = 1; + drawable.setUsePremultipliedAlpha(true); - Skeleton *skeleton = drawable.skeleton; - skeleton->setPosition(320, 480); - skeleton->updateWorldTransform(Physics_Update); + Skeleton *skeleton = drawable.skeleton; + skeleton->setPosition(320, 480); + skeleton->updateWorldTransform(Physics_Update); - drawable.state->setAnimation(0, "shake", true); + drawable.state->setAnimation(0, "shake", true); - sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - snowglobe"); - window.setFramerateLimit(60); - sf::Event event; - sf::Clock deltaClock; + sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - snowglobe"); + window.setFramerateLimit(60); + sf::Event event; + sf::Clock deltaClock; - while (window.isOpen()) { - while (window.pollEvent(event)) { - if (event.type == sf::Event::Closed) window.close(); - } + while (window.isOpen()) { + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) window.close(); + } - float delta = deltaClock.getElapsedTime().asSeconds(); - deltaClock.restart(); + float delta = deltaClock.getElapsedTime().asSeconds(); + deltaClock.restart(); - drawable.update(delta); + drawable.update(delta); - window.clear(); - window.draw(drawable); - window.display(); - } + window.clear(); + window.draw(drawable); + window.display(); + } } void cloudpot(SkeletonData *skeletonData, Atlas *atlas) { - SP_UNUSED(atlas); + SP_UNUSED(atlas); - SkeletonDrawable drawable(skeletonData); - drawable.timeScale = 1; - drawable.setUsePremultipliedAlpha(true); + SkeletonDrawable drawable(skeletonData); + drawable.timeScale = 1; + drawable.setUsePremultipliedAlpha(true); - Skeleton *skeleton = drawable.skeleton; - skeleton->setPosition(320, 480); - skeleton->updateWorldTransform(Physics_Update); + Skeleton *skeleton = drawable.skeleton; + skeleton->setPosition(320, 480); + skeleton->updateWorldTransform(Physics_Update); - drawable.state->setAnimation(0, "playing-in-the-rain", true); + drawable.state->setAnimation(0, "playing-in-the-rain", true); - sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - cloudpot"); - window.setFramerateLimit(60); - sf::Event event; - sf::Clock deltaClock; + sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - cloudpot"); + window.setFramerateLimit(60); + sf::Event event; + sf::Clock deltaClock; - while (window.isOpen()) { - while (window.pollEvent(event)) { - if (event.type == sf::Event::Closed) window.close(); - } + while (window.isOpen()) { + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) window.close(); + } - float delta = deltaClock.getElapsedTime().asSeconds(); - deltaClock.restart(); + float delta = deltaClock.getElapsedTime().asSeconds(); + deltaClock.restart(); - drawable.update(delta); + drawable.update(delta); - window.clear(); - window.draw(drawable); - window.display(); - } + window.clear(); + window.draw(drawable); + window.display(); + } } /** @@ -772,12 +772,12 @@ DebugExtension dbgExtension(SpineExtension::getInstance()); int main() { SpineExtension::setInstance(&dbgExtension); - testcase(cloudpot, "data/cloud-pot.json", "data/cloud-pot.skel", "data/cloud-pot-pma.atlas", 0.2); - testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f); - testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f); - testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f); - testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.62f); - testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f); + testcase(cloudpot, "data/cloud-pot.json", "data/cloud-pot.skel", "data/cloud-pot-pma.atlas", 0.2); + testcase(sack, "data/sack-pro.json", "data/sack-pro.skel", "data/sack-pma.atlas", 0.2f); + testcase(celestialCircus, "data/celestial-circus-pro.json", "data/celestial-circus-pro.skel", "data/celestial-circus-pma.atlas", 0.2f); + testcase(snowglobe, "data/snowglobe-pro.json", "data/snowglobe-pro.skel", "data/snowglobe-pma.atlas", 0.2f); + testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.62f); + testcase(ikDemo, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy-pma.atlas", 0.6f); testcase(vine, "data/vine-pro.json", "data/vine-pro.skel", "data/vine-pma.atlas", 0.5f); testcase(dragon, "data/dragon-ess.json", "data/dragon-ess.skel", "data/dragon-pma.atlas", 0.6f); testcase(owl, "data/owl-pro.json", "data/owl-pro.skel", "data/owl-pma.atlas", 0.5f); diff --git a/spine-sfml/cpp/src/spine/spine-sfml.cpp b/spine-sfml/cpp/src/spine/spine-sfml.cpp index 5b1884245..77fc7ce80 100644 --- a/spine-sfml/cpp/src/spine/spine-sfml.cpp +++ b/spine-sfml/cpp/src/spine/spine-sfml.cpp @@ -50,7 +50,7 @@ namespace spine { SkeletonDrawable::SkeletonDrawable(SkeletonData *skeletonData, AnimationStateData *stateData) : timeScale(1), vertexArray(new VertexArray(Triangles, skeletonData->getBones().size() * 4)), worldVertices(), clipper(), usePremultipliedAlpha(false) { - Bone::setYDown(true); + Bone::setYDown(true); worldVertices.ensureCapacity(SPINE_MESH_VERTEX_COUNT_MAX); skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData); tempUvs.ensureCapacity(16); @@ -79,7 +79,7 @@ namespace spine { void SkeletonDrawable::update(float deltaTime, Physics physics) { state->update(deltaTime * timeScale); state->apply(*skeleton); - skeleton->update(deltaTime * timeScale); + skeleton->update(deltaTime * timeScale); skeleton->updateWorldTransform(physics); } diff --git a/spine-ue/Source/SpineUE/MySceneComponent.cpp b/spine-ue/Source/SpineUE/MySceneComponent.cpp index 365e43fbd..f37493ceb 100644 --- a/spine-ue/Source/SpineUE/MySceneComponent.cpp +++ b/spine-ue/Source/SpineUE/MySceneComponent.cpp @@ -6,26 +6,26 @@ // 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 off to improve performance if you - // don't need them. - PrimaryComponentTick.bCanEverTick = true; + 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 off to improve performance if you + // don't need them. + PrimaryComponentTick.bCanEverTick = true; } // Called when the game starts void UMySceneComponent::BeginPlay() { - Super::BeginPlay(); + Super::BeginPlay(); - // ... + // ... } // Called every frame void UMySceneComponent::TickComponent( - float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction *ThisTickFunction) { - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction *ThisTickFunction) { + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - // ... + // ... } diff --git a/spine-ue/Source/SpineUE/MySceneComponent.h b/spine-ue/Source/SpineUE/MySceneComponent.h index 5f107a990..c23104252 100644 --- a/spine-ue/Source/SpineUE/MySceneComponent.h +++ b/spine-ue/Source/SpineUE/MySceneComponent.h @@ -9,19 +9,19 @@ UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) class SPINEUE_API UMySceneComponent : public USpineSkeletonRendererComponent { - GENERATED_BODY() + GENERATED_BODY() public: - // Sets default values for this component's properties - UMySceneComponent(const FObjectInitializer &ObjectInitializer); + // Sets default values for this component's properties + UMySceneComponent(const FObjectInitializer &ObjectInitializer); protected: - // Called when the game starts - virtual void BeginPlay() override; + // Called when the game starts + virtual void BeginPlay() override; public: - // Called every frame - virtual void - TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction *ThisTickFunction) override; + // Called every frame + virtual void + TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction *ThisTickFunction) override; }; diff --git a/spine-ue/Source/SpineUE/SpineUEGameMode.cpp b/spine-ue/Source/SpineUE/SpineUEGameMode.cpp index 211bd924d..9d5b6343e 100644 --- a/spine-ue/Source/SpineUE/SpineUEGameMode.cpp +++ b/spine-ue/Source/SpineUE/SpineUEGameMode.cpp @@ -2,4 +2,3 @@ #include "SpineUEGameMode.h" #include "SpineUE.h" - diff --git a/spine-ue/Source/SpineUE/SpineUEGameMode.h b/spine-ue/Source/SpineUE/SpineUEGameMode.h index 4a7321ea9..96c18269e 100644 --- a/spine-ue/Source/SpineUE/SpineUEGameMode.h +++ b/spine-ue/Source/SpineUE/SpineUEGameMode.h @@ -10,5 +10,5 @@ */ UCLASS() class SPINEUE_API ASpineUEGameMode : public AGameMode { - GENERATED_BODY() + GENERATED_BODY() }; diff --git a/spine-ue/Source/SpineUE/SpineboyCppPawn.cpp b/spine-ue/Source/SpineUE/SpineboyCppPawn.cpp index 448fdc3ca..945290b45 100644 --- a/spine-ue/Source/SpineUE/SpineboyCppPawn.cpp +++ b/spine-ue/Source/SpineUE/SpineboyCppPawn.cpp @@ -6,35 +6,35 @@ // 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. - PrimaryActorTick.bCanEverTick = true; + // 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; } // Called when the game starts or when spawned void ASpineboyCppPawn::BeginPlay() { - Super::BeginPlay(); - USpineSkeletonAnimationComponent *animationComponent = - FindComponentByClass(); - animationComponent->SetAnimation(0, FString("walk"), true); + Super::BeginPlay(); + USpineSkeletonAnimationComponent *animationComponent = + FindComponentByClass(); + animationComponent->SetAnimation(0, FString("walk"), true); } // Called every frame void ASpineboyCppPawn::Tick(float DeltaTime) { - Super::Tick(DeltaTime); - USpineSkeletonAnimationComponent *animationComponent = - FindComponentByClass(); - spine::AnimationState *state = animationComponent->GetAnimationState(); - spine::TrackEntry *entry = state->getCurrent(0); - if (entry) { - GEngine->AddOnScreenDebugMessage( - -1, 0.5f, FColor::Yellow, - FString(entry->getAnimation()->getName().buffer())); - } + Super::Tick(DeltaTime); + USpineSkeletonAnimationComponent *animationComponent = + FindComponentByClass(); + spine::AnimationState *state = animationComponent->GetAnimationState(); + spine::TrackEntry *entry = state->getCurrent(0); + if (entry) { + GEngine->AddOnScreenDebugMessage( + -1, 0.5f, FColor::Yellow, + FString(entry->getAnimation()->getName().buffer())); + } } // Called to bind functionality to input void ASpineboyCppPawn::SetupPlayerInputComponent( - UInputComponent *PlayerInputComponent) { - Super::SetupPlayerInputComponent(PlayerInputComponent); + UInputComponent *PlayerInputComponent) { + Super::SetupPlayerInputComponent(PlayerInputComponent); } diff --git a/spine-ue/Source/SpineUE/SpineboyCppPawn.h b/spine-ue/Source/SpineUE/SpineboyCppPawn.h index fac8f08be..ece541bd7 100644 --- a/spine-ue/Source/SpineUE/SpineboyCppPawn.h +++ b/spine-ue/Source/SpineUE/SpineboyCppPawn.h @@ -8,21 +8,21 @@ UCLASS() class SPINEUE_API ASpineboyCppPawn : public APawn { - GENERATED_BODY() + GENERATED_BODY() public: - // Sets default values for this pawn's properties - ASpineboyCppPawn(); + // Sets default values for this pawn's properties + ASpineboyCppPawn(); protected: - // Called when the game starts or when spawned - virtual void BeginPlay() override; + // Called when the game starts or when spawned + virtual void BeginPlay() override; public: - // Called every frame - virtual void Tick(float DeltaTime) override; + // Called every frame + virtual void Tick(float DeltaTime) override; - // Called to bind functionality to input - virtual void SetupPlayerInputComponent( - class UInputComponent *PlayerInputComponent) override; + // Called to bind functionality to input + virtual void SetupPlayerInputComponent( + class UInputComponent *PlayerInputComponent) override; };