diff --git a/spine-cpp/spine-cpp/include/spine/Bone.h b/spine-cpp/spine-cpp/include/spine/Bone.h index 90f0aced2..7c53435aa 100644 --- a/spine-cpp/spine-cpp/include/spine/Bone.h +++ b/spine-cpp/spine-cpp/include/spine/Bone.h @@ -243,10 +243,6 @@ namespace spine { /// Returns the magnitide (always positive) of the world scale Y. float getWorldScaleY(); - bool isAppliedValid(); - - void setAppliedValid(bool valid); - bool isActive(); void setActive(bool inValue); @@ -260,7 +256,6 @@ namespace spine { Vector _children; float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY; float _ax, _ay, _arotation, _ascaleX, _ascaleY, _ashearX, _ashearY; - bool _appliedValid; float _a, _b, _worldX; float _c, _d, _worldY; bool _sorted; diff --git a/spine-cpp/spine-cpp/src/spine/Bone.cpp b/spine-cpp/spine-cpp/src/spine/Bone.cpp index cf8631afe..8a57b31ad 100644 --- a/spine-cpp/spine-cpp/src/spine/Bone.cpp +++ b/spine-cpp/spine-cpp/src/spine/Bone.cpp @@ -68,7 +68,6 @@ Bone::Bone(BoneData &data, Skeleton &skeleton, Bone *parent) : Updatable(), _ascaleY(0), _ashearX(0), _ashearY(0), - _appliedValid(false), _a(1), _b(0), _worldX(0), @@ -81,7 +80,7 @@ Bone::Bone(BoneData &data, Skeleton &skeleton, Bone *parent) : Updatable(), } void Bone::update() { - updateWorldTransform(_x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY); + updateWorldTransform(_ax, _ay, _arotation, _ascaleX, _ascaleY, _ashearX, _ashearY); } void Bone::updateWorldTransform() { @@ -101,7 +100,6 @@ Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float _ascaleY = scaleY; _ashearX = shearX; _ashearY = shearY; - _appliedValid = true; if (!parent) { /* Root bone. */ float rotationY = rotation + 90 + shearY; @@ -267,8 +265,6 @@ void Bone::rotateWorld(float degrees) { _b = cos * b - sin * d; _c = sin * a + cos * c; _d = sin * b + cos * d; - - _appliedValid = false; } float Bone::getWorldToLocalRotationX() { @@ -495,17 +491,8 @@ float Bone::getWorldScaleY() { return MathUtil::sqrt(_b * _b + _d * _d); } -bool Bone::isAppliedValid() { - return _appliedValid; -} - -void Bone::setAppliedValid(bool valid) { - _appliedValid = valid; -} - void Bone::updateAppliedTransform() { Bone *parent = _parent; - _appliedValid = 1; if (!parent) { _ax = _worldX; _ay = _worldY; diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 1303543bc..de9113eed 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -49,7 +49,6 @@ IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress, boo float pa = p->_a, pb = p->_b, pc = p->_c, pd = p->_d; float rotationIK = -bone._ashearX - bone._arotation; float tx = 0, ty = 0; - if (!bone._appliedValid) bone.updateAppliedTransform(); switch (bone._data.getTransformMode()) { case TransformMode_OnlyTranslation: @@ -105,8 +104,6 @@ IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY, int Bone *pp = parent.getParent(); float tx, ty, dx, dy, dd, l1, l2, a1, a2, r, td, sd, p; float id, x, y; - if (!parent._appliedValid) parent.updateAppliedTransform(); - if (!child._appliedValid) child.updateAppliedTransform(); px = parent._ax; py = parent._ay; psx = parent._ascaleX; diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp index 6f81496ad..1000802e8 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp @@ -220,7 +220,7 @@ void PathConstraint::update() { bone._d = sin * b + cos * d; } - bone._appliedValid = false; + bone.updateAppliedTransform(); } } diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index b0f4050ac..8149fcc14 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -212,6 +212,17 @@ void Skeleton::printUpdateCache() { } void Skeleton::updateWorldTransform() { + 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) { _updateCache[i]->update(); } diff --git a/spine-cpp/spine-cpp/src/spine/Slot.cpp b/spine-cpp/spine-cpp/src/spine/Slot.cpp index f1ee36ea5..4bae667af 100644 --- a/spine-cpp/spine-cpp/src/spine/Slot.cpp +++ b/spine-cpp/spine-cpp/src/spine/Slot.cpp @@ -37,6 +37,7 @@ #include #include #include +#include using namespace spine; @@ -99,9 +100,17 @@ void Slot::setAttachment(Attachment *inValue) { return; } + if (inValue && _attachment) { + if (!(inValue->getRTTI().instanceOf(VertexAttachment::rtti)) || + !(_attachment->getRTTI().instanceOf(VertexAttachment::rtti)) + || (static_cast(inValue)->getDeformAttachment() != + (static_cast(_attachment)->getDeformAttachment()))) { + _deform.clear(); + } + } + _attachment = inValue; _attachmentTime = _skeleton.getTime(); - _deform.clear(); } int Slot::getAttachmentState() { diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp index 16e5f0e2e..c3f9fb046 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp @@ -213,7 +213,7 @@ void TransformConstraint::applyAbsoluteWorld() { bone._d = MathUtil::sin(r) * s; } - bone._appliedValid = false; + bone.updateAppliedTransform(); } } @@ -276,21 +276,18 @@ void TransformConstraint::applyRelativeWorld() { bone._d = MathUtil::sin(r) * s; } - bone._appliedValid = false; + bone.updateAppliedTransform(); } } void TransformConstraint::applyAbsoluteLocal() { float mixRotate = _mixRotate, mixX = _mixX, mixY = _mixY, mixScaleX = _mixScaleX, mixScaleY = _mixScaleY, mixShearY = _mixShearY; Bone &target = *_target; - if (!target._appliedValid) target.updateAppliedTransform(); for (size_t i = 0; i < _bones.size(); ++i) { Bone *item = _bones[i]; Bone &bone = *item; - if (!bone._appliedValid) bone.updateAppliedTransform(); - float rotation = bone._arotation; if (mixRotate != 0) { float r = target._arotation - rotation + _data._offsetRotation; @@ -322,14 +319,11 @@ void TransformConstraint::applyAbsoluteLocal() { void TransformConstraint::applyRelativeLocal() { float mixRotate = _mixRotate, mixX = _mixX, mixY = _mixY, mixScaleX = _mixScaleX, mixScaleY = _mixScaleY, mixShearY = _mixShearY; Bone &target = *_target; - if (!target._appliedValid) target.updateAppliedTransform(); for (size_t i = 0; i < _bones.size(); ++i) { Bone *item = _bones[i]; Bone &bone = *item; - if (!bone._appliedValid) bone.updateAppliedTransform(); - float rotation = bone._arotation + (target._arotation + _data._offsetRotation) * mixRotate; float x = bone._ax + (target._ax + _data._offsetX) * mixX; float y = bone._ay + (target._ay + _data._offsetY) * mixY; diff --git a/spine-sfml/c/example/main.cpp b/spine-sfml/c/example/main.cpp index 86928b869..cbd9d216e 100644 --- a/spine-sfml/c/example/main.cpp +++ b/spine-sfml/c/example/main.cpp @@ -252,7 +252,6 @@ void goblins (spSkeletonData* skeletonData, spAtlas* atlas) { spSkeleton_updateWorldTransform(skeleton); spAnimationState_setAnimationByName(drawable->state, 0, "walk", true); - drawable->update(0.3f); sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - goblins"); window.setFramerateLimit(60); @@ -262,10 +261,10 @@ void goblins (spSkeletonData* skeletonData, spAtlas* atlas) { while (window.pollEvent(event)) if (event.type == sf::Event::Closed) window.close(); - // float delta = deltaClock.getElapsedTime().asSeconds(); + float delta = deltaClock.getElapsedTime().asSeconds(); deltaClock.restart(); - drawable->update(0); + drawable->update(delta); window.clear(); window.draw(*drawable); diff --git a/spine-sfml/cpp/example/main.cpp b/spine-sfml/cpp/example/main.cpp index b74366f83..16620e99a 100644 --- a/spine-sfml/cpp/example/main.cpp +++ b/spine-sfml/cpp/example/main.cpp @@ -223,7 +223,6 @@ void ikDemo (SkeletonData* skeletonData, Atlas* atlas) { crosshair->getParent()->worldToLocal(mouseCoords.x, mouseCoords.y, boneCoordsX, boneCoordsY); crosshair->setX(boneCoordsX); crosshair->setY(boneCoordsY); - crosshair->setAppliedValid(false); // Calculate final world transform with the // crosshair bone set to the mouse cursor @@ -251,8 +250,6 @@ void goblins (SkeletonData* skeletonData, Atlas* atlas) { drawable.state->setAnimation(0, "walk", true); - drawable.update(0.3f); - sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - goblins"); window.setFramerateLimit(60); sf::Event event; @@ -261,10 +258,10 @@ void goblins (SkeletonData* skeletonData, Atlas* atlas) { while (window.pollEvent(event)) if (event.type == sf::Event::Closed) window.close(); - // float delta = deltaClock.getElapsedTime().asSeconds(); + float delta = deltaClock.getElapsedTime().asSeconds(); deltaClock.restart(); - drawable.update(0); + drawable.update(delta); window.clear(); window.draw(drawable);