From 96c0842021c87f350adedc88376a5a41107e9684 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 17 Feb 2023 13:10:23 +0100 Subject: [PATCH] [cpp] Backport of some 4.2 changes to enable Flutter runtime in 4.1 --- .gitignore | 4 + CHANGELOG.md | 3 +- .../src/spine/SkeletonRenderer.cpp | 30 +++--- .../src/spine/spine-cocos2dx.cpp | 2 +- .../src/spine/v4/SkeletonBatch.cpp | 6 +- .../src/spine/v4/SkeletonTwoColorBatch.cpp | 6 +- .../spine-cpp/include/spine/AnimationState.h | 15 ++- spine-cpp/spine-cpp/include/spine/Atlas.h | 6 +- spine-cpp/spine-cpp/include/spine/Bone.h | 12 +-- .../spine-cpp/include/spine/ConstraintData.h | 4 +- spine-cpp/spine-cpp/include/spine/Debug.h | 2 +- .../spine-cpp/include/spine/IkConstraint.h | 3 - .../include/spine/IkConstraintData.h | 2 + spine-cpp/spine-cpp/include/spine/MathUtil.h | 3 + .../spine-cpp/include/spine/MeshAttachment.h | 2 +- .../spine-cpp/include/spine/PathConstraint.h | 19 ++-- .../include/spine/PathConstraintData.h | 3 +- .../include/spine/RegionAttachment.h | 4 +- .../spine-cpp/include/spine/SkeletonBinary.h | 2 +- .../spine-cpp/include/spine/SpineString.h | 9 +- .../include/spine/TransformConstraintData.h | 32 +++++++ .../include/spine/VertexAttachment.h | 4 +- spine-cpp/spine-cpp/include/spine/Vertices.h | 2 +- .../spine-cpp/src/spine/AnimationState.cpp | 30 ++++-- spine-cpp/spine-cpp/src/spine/Atlas.cpp | 14 +-- .../src/spine/AtlasAttachmentLoader.cpp | 2 - spine-cpp/spine-cpp/src/spine/Bone.cpp | 93 +++++++++++++------ .../spine-cpp/src/spine/ConstraintData.cpp | 2 + spine-cpp/spine-cpp/src/spine/Extension.cpp | 4 + .../spine-cpp/src/spine/IkConstraint.cpp | 9 +- .../spine-cpp/src/spine/IkConstraintData.cpp | 2 + .../spine-cpp/src/spine/MeshAttachment.cpp | 4 +- .../src/spine/PathConstraintData.cpp | 2 + .../spine-cpp/src/spine/RegionAttachment.cpp | 3 +- spine-cpp/spine-cpp/src/spine/Sequence.cpp | 2 - spine-cpp/spine-cpp/src/spine/Skeleton.cpp | 6 +- .../spine-cpp/src/spine/SkeletonBinary.cpp | 14 +-- .../spine-cpp/src/spine/SkeletonJson.cpp | 2 +- .../src/spine/TransformConstraintData.cpp | 62 +++++++++++++ .../spine-cpp/src/spine/VertexAttachment.cpp | 4 +- spine-sfml/cpp/src/spine/spine-sfml.cpp | 6 +- 41 files changed, 301 insertions(+), 135 deletions(-) diff --git a/.gitignore b/.gitignore index cee580293..da20c7e5c 100644 --- a/.gitignore +++ b/.gitignore @@ -183,3 +183,7 @@ spine-godot/.clang-format spine-ts/spine-phaser/dist spine-godot/.cache spine-godot/build/compile_commands.json + +spine-flutter/ios/Classes/spine-cpp +spine-flutter/macos/Classes/spine-cpp +spine-flutter/src/spine-cpp \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 98bbd53a5..267853e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * Added CMake parameter `SPINE_SANITIZE` which will enable sanitizers on macOS and Linux. * Added `SPINE_MAJOR_VERSION`, `SPINE_MINOR_VERSION`, and `SPINE_VERSION_STRING`. Parsing skeleton .JSON and .skel files will report an error if the skeleton version does not match the runtime version. * **Breaking changes** + * `RegionAttachment` and `MeshAttachment` no longer implement `HasRendererObject`. * `RegionAttachment` and `MeshAttachment` now contain a `TextureRegion*` instead of encoding region fields directly. * `AttachmentLoader::newRegionAttachment()` and `AttachmentLoader::newMeshAttachment()` now take an additional `Sequence*` parameter. * `MeshAttachment::updateUVs()` was renamed to `MeshAttachment::updateRegion()`. @@ -36,7 +37,7 @@ * `VertexAttachment::getDeformAttachment()` was renamed to `VertexAttachment::getTimelineAttachment()`. * `Skeleton::update()` has been removed. * `Skeleton::getTime()` has been removed. - * `VertexEffect` has been removed. + * `VertexEffect` has been removed. ### Cocos2d-x diff --git a/spine-cocos2dx/spine-cocos2dx/src/spine/SkeletonRenderer.cpp b/spine-cocos2dx/spine-cocos2dx/src/spine/SkeletonRenderer.cpp index be2aff3bb..b4336a41e 100644 --- a/spine-cocos2dx/spine-cocos2dx/src/spine/SkeletonRenderer.cpp +++ b/spine-cocos2dx/spine-cocos2dx/src/spine/SkeletonRenderer.cpp @@ -269,7 +269,7 @@ namespace spine { Color darkColor; const float darkPremultipliedAlpha = _premultipliedAlpha ? 1.f : 0; TwoColorTrianglesCommand *lastTwoColorTrianglesCommand = nullptr; - for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) { + for (int i = 0, n = (int)_skeleton->getSlots().size(); i < n; ++i) { Slot *slot = _skeleton->getDrawOrder()[i]; if (nothingToDraw(*slot, _startSlotIndex, _endSlotIndex)) { @@ -284,7 +284,7 @@ namespace spine { if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) { RegionAttachment *attachment = static_cast(slot->getAttachment()); - texture = (Texture2D*)((AtlasRegion*)attachment->getRegion())->page->getRendererObject(); + texture = (Texture2D*)((AtlasRegion*)attachment->getRegion())->page->texture; float *dstTriangleVertices = nullptr; int dstStride = 0;// in floats @@ -322,7 +322,7 @@ namespace spine { color = attachment->getColor(); } else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment *attachment = (MeshAttachment *) slot->getAttachment(); - texture = (Texture2D*)((AtlasRegion*)attachment->getRegion())->page->getRendererObject(); + texture = (Texture2D*)((AtlasRegion*)attachment->getRegion())->page->texture; float *dstTriangleVertices = nullptr; int dstStride = 0;// in floats @@ -330,8 +330,8 @@ namespace spine { if (hasSingleTint) { triangles.indices = attachment->getTriangles().buffer(); triangles.indexCount = (unsigned short)attachment->getTriangles().size(); - triangles.verts = batch->allocateVertices(attachment->getWorldVerticesLength() / 2); - triangles.vertCount = attachment->getWorldVerticesLength() / 2; + triangles.verts = batch->allocateVertices((int)attachment->getWorldVerticesLength() / 2); + triangles.vertCount = (int)attachment->getWorldVerticesLength() / 2; for (int v = 0, i = 0; v < triangles.vertCount; v++, i += 2) { auto &texCoords = triangles.verts[v].texCoords; texCoords.u = attachment->getUVs()[i]; @@ -343,8 +343,8 @@ namespace spine { } else { trianglesTwoColor.indices = attachment->getTriangles().buffer(); trianglesTwoColor.indexCount = (unsigned short)attachment->getTriangles().size(); - trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachment->getWorldVerticesLength() / 2); - trianglesTwoColor.vertCount = attachment->getWorldVerticesLength() / 2; + trianglesTwoColor.verts = twoColorBatch->allocateVertices((int)attachment->getWorldVerticesLength() / 2); + trianglesTwoColor.vertCount = (int)attachment->getWorldVerticesLength() / 2; for (int v = 0, i = 0; v < trianglesTwoColor.vertCount; v++, i += 2) { auto &texCoords = trianglesTwoColor.verts[v].texCoords; texCoords.u = attachment->getUVs()[i]; @@ -408,9 +408,9 @@ namespace spine { continue; } - triangles.vertCount = _clipper->getClippedVertices().size() / 2; + triangles.vertCount = (int)_clipper->getClippedVertices().size() / 2; triangles.verts = batch->allocateVertices(triangles.vertCount); - triangles.indexCount = _clipper->getClippedTriangles().size(); + triangles.indexCount = (int)_clipper->getClippedTriangles().size(); triangles.indices = batch->allocateIndices(triangles.indexCount); memcpy(triangles.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); @@ -454,9 +454,9 @@ namespace spine { continue; } - trianglesTwoColor.vertCount = _clipper->getClippedVertices().size() / 2; + trianglesTwoColor.vertCount = (int)_clipper->getClippedVertices().size() / 2; trianglesTwoColor.verts = twoColorBatch->allocateVertices(trianglesTwoColor.vertCount); - trianglesTwoColor.indexCount = _clipper->getClippedTriangles().size(); + trianglesTwoColor.indexCount = (int)_clipper->getClippedTriangles().size(); trianglesTwoColor.indices = twoColorBatch->allocateIndices(trianglesTwoColor.indexCount); memcpy(trianglesTwoColor.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); @@ -576,7 +576,7 @@ namespace spine { drawNode->setLineWidth(2.0f); #endif V3F_C4B_T2F_Quad quad; - for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) { + for (int i = 0, n = (int)_skeleton->getSlots().size(); i < n; i++) { Slot *slot = _skeleton->getDrawOrder()[i]; if (!slot->getBone().isActive()) continue; @@ -606,7 +606,7 @@ namespace spine { #else drawNode->setLineWidth(2.0f); #endif - for (int i = 0, n = _skeleton->getBones().size(); i < n; i++) { + for (int i = 0, n = (int)_skeleton->getBones().size(); i < n; i++) { Bone *bone = _skeleton->getBones()[i]; if (!bone->isActive()) continue; float x = bone->getData().getLength() * bone->getA() + bone->getWorldX(); @@ -615,7 +615,7 @@ namespace spine { } // Bone origins. auto color = Color4F::BLUE;// Root bone is blue. - for (int i = 0, n = _skeleton->getBones().size(); i < n; i++) { + for (int i = 0, n = (int)_skeleton->getBones().size(); i < n; i++) { Bone *bone = _skeleton->getBones()[i]; if (!bone->isActive()) continue; drawNode->drawPoint(Vec2(bone->getWorldX(), bone->getWorldY()), 4, color); @@ -630,7 +630,7 @@ namespace spine { #else drawNode->setLineWidth(2.0f); #endif - for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) { + for (int i = 0, n = (int)_skeleton->getSlots().size(); i < n; ++i) { Slot *slot = _skeleton->getDrawOrder()[i]; if (!slot->getBone().isActive()) continue; if (!slot->getAttachment() || !slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) continue; diff --git a/spine-cocos2dx/spine-cocos2dx/src/spine/spine-cocos2dx.cpp b/spine-cocos2dx/spine-cocos2dx/src/spine/spine-cocos2dx.cpp index a52dfd0b8..0a660f9ef 100644 --- a/spine-cocos2dx/spine-cocos2dx/src/spine/spine-cocos2dx.cpp +++ b/spine-cocos2dx/spine-cocos2dx/src/spine/spine-cocos2dx.cpp @@ -114,7 +114,7 @@ void Cocos2dTextureLoader::load(AtlasPage &page, const spine::String &path) { #endif texture->setTexParameters(textureParams); - page.setRendererObject(texture); + page.texture = texture; page.width = texture->getPixelsWide(); page.height = texture->getPixelsHigh(); } diff --git a/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp b/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp index 9a1ca9262..094700a19 100644 --- a/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp +++ b/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonBatch.cpp @@ -132,7 +132,7 @@ namespace spine { unsigned short *SkeletonBatch::allocateIndices(uint32_t numIndices) { if (_indices.getCapacity() - _indices.size() < numIndices) { unsigned short *oldData = _indices.buffer(); - int oldSize = _indices.size(); + int oldSize = (int)_indices.size(); _indices.ensureCapacity(_indices.size() + numIndices); unsigned short *newData = _indices.buffer(); for (uint32_t i = 0; i < this->_nextFreeCommand; i++) { @@ -187,8 +187,8 @@ namespace spine { cocos2d::TrianglesCommand *SkeletonBatch::nextFreeCommand() { if (_commandsPool.size() <= _nextFreeCommand) { - unsigned int newSize = _commandsPool.size() * 2 + 1; - for (int i = _commandsPool.size(); i < newSize; i++) { + unsigned int newSize = (int)_commandsPool.size() * 2 + 1; + for (int i = (int)_commandsPool.size(); i < newSize; i++) { _commandsPool.push_back(createNewTrianglesCommand()); } } diff --git a/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp b/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp index ad5d5f431..5593bb63d 100644 --- a/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp +++ b/spine-cocos2dx/spine-cocos2dx/src/spine/v4/SkeletonTwoColorBatch.cpp @@ -321,7 +321,7 @@ namespace spine { unsigned short *SkeletonTwoColorBatch::allocateIndices(uint32_t numIndices) { if (_indices.getCapacity() - _indices.size() < numIndices) { unsigned short *oldData = _indices.buffer(); - int oldSize = _indices.size(); + int oldSize = (int)_indices.size(); _indices.ensureCapacity(_indices.size() + numIndices); unsigned short *newData = _indices.buffer(); for (uint32_t i = 0; i < this->_nextFreeCommand; i++) { @@ -406,8 +406,8 @@ namespace spine { TwoColorTrianglesCommand *SkeletonTwoColorBatch::nextFreeCommand() { if (_commandsPool.size() <= _nextFreeCommand) { - unsigned int newSize = _commandsPool.size() * 2 + 1; - for (int i = _commandsPool.size(); i < newSize; i++) { + unsigned int newSize = (int)_commandsPool.size() * 2 + 1; + for (int i = (int)_commandsPool.size(); i < newSize; i++) { _commandsPool.push_back(new TwoColorTrianglesCommand()); } } diff --git a/spine-cpp/spine-cpp/include/spine/AnimationState.h b/spine-cpp/spine-cpp/include/spine/AnimationState.h index c8c5a7937..d7acd6363 100644 --- a/spine-cpp/spine-cpp/include/spine/AnimationState.h +++ b/spine-cpp/spine-cpp/include/spine/AnimationState.h @@ -45,7 +45,7 @@ namespace spine { enum EventType { - EventType_Start, + EventType_Start = 0, EventType_Interrupt, EventType_End, EventType_Complete, @@ -311,14 +311,13 @@ namespace spine { private: Vector _eventQueueEntries; AnimationState &_state; - Pool &_trackEntryPool; bool _drainDisabled; - static EventQueue *newEventQueue(AnimationState &state, Pool &trackEntryPool); + static EventQueue *newEventQueue(AnimationState &state); static EventQueueEntry newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event = NULL); - EventQueue(AnimationState &state, Pool &trackEntryPool); + EventQueue(AnimationState &state); ~EventQueue(); @@ -429,6 +428,12 @@ namespace spine { void enableQueue(); + void setManualTrackEntryDisposal(bool inValue); + + bool getManualTrackEntryDisposal(); + + void disposeTrackEntry(TrackEntry *entry); + private: static const int Subsequent = 0; static const int First = 1; @@ -456,6 +461,8 @@ namespace spine { float _timeScale; + bool _manualTrackEntryDisposal; + static Animation *getEmptyAnimation(); static void diff --git a/spine-cpp/spine-cpp/include/spine/Atlas.h b/spine-cpp/spine-cpp/include/spine/Atlas.h index 820609ee3..c65688d6d 100644 --- a/spine-cpp/spine-cpp/include/spine/Atlas.h +++ b/spine-cpp/spine-cpp/include/spine/Atlas.h @@ -73,7 +73,7 @@ namespace spine { TextureWrap_Repeat }; - class SP_API AtlasPage : public SpineObject, public HasRendererObject { + class SP_API AtlasPage : public SpineObject { public: String name; String texturePath; @@ -84,11 +84,13 @@ namespace spine { TextureWrap vWrap; int width, height; bool pma; + int index; + void *texture; explicit AtlasPage(const String &inName) : name(inName), format(Format_RGBA8888), minFilter(TextureFilter_Nearest), magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge), - vWrap(TextureWrap_ClampToEdge), width(0), height(0), pma(false) { + vWrap(TextureWrap_ClampToEdge), width(0), height(0), pma(false), index(0), texture(NULL) { } }; diff --git a/spine-cpp/spine-cpp/include/spine/Bone.h b/spine-cpp/spine-cpp/include/spine/Bone.h index d3643514b..83bd7a391 100644 --- a/spine-cpp/spine-cpp/include/spine/Bone.h +++ b/spine-cpp/spine-cpp/include/spine/Bone.h @@ -113,6 +113,12 @@ namespace spine { void updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY); + /// Computes the individual applied transform values from the world transform. This can be useful to perform processing using + /// the applied transform after the world transform has been modified directly (eg, by a constraint).. + /// + /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. + void updateAppliedTransform(); + void setToSetupPose(); void worldToLocal(float worldX, float worldY, float &outLocalX, float &outLocalY); @@ -260,12 +266,6 @@ namespace spine { float _c, _d, _worldY; bool _sorted; bool _active; - - /// Computes the individual applied transform values from the world transform. This can be useful to perform processing using - /// the applied transform after the world transform has been modified directly (eg, by a constraint).. - /// - /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. - void updateAppliedTransform(); }; } diff --git a/spine-cpp/spine-cpp/include/spine/ConstraintData.h b/spine-cpp/spine-cpp/include/spine/ConstraintData.h index eaee91cf6..dc540ed35 100644 --- a/spine-cpp/spine-cpp/include/spine/ConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/ConstraintData.h @@ -34,9 +34,11 @@ #include namespace spine { -/// The interface for all constraints. + /// The interface for all constraints. class SP_API ConstraintData : public SpineObject { + RTTI_DECL + public: ConstraintData(const String &name); diff --git a/spine-cpp/spine-cpp/include/spine/Debug.h b/spine-cpp/spine-cpp/include/spine/Debug.h index 902845fd8..5b5b63660 100644 --- a/spine-cpp/spine-cpp/include/spine/Debug.h +++ b/spine-cpp/spine-cpp/include/spine/Debug.h @@ -62,7 +62,7 @@ namespace spine { it->second.address); } printf("allocations: %zu, reallocations: %zu, frees: %zu\n", _allocations, _reallocations, _frees); - if (_allocated.empty()) printf("No leaks detected"); + if (_allocated.empty()) printf("No leaks detected\n"); } void clearAllocations() { diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraint.h b/spine-cpp/spine-cpp/include/spine/IkConstraint.h index 477108dfc..c00193fca 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraint.h @@ -64,9 +64,6 @@ namespace spine { IkConstraint(IkConstraintData &data, Skeleton &skeleton); - /// Applies the constraint to the constrained bones. - void apply(); - virtual void update(); virtual int getOrder(); diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraintData.h b/spine-cpp/spine-cpp/include/spine/IkConstraintData.h index 721db504d..664f7c084 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraintData.h @@ -50,6 +50,8 @@ namespace spine { friend class IkConstraintTimeline; public: + RTTI_DECL + explicit IkConstraintData(const String &name); /// The bones that are constrained by this IK Constraint. diff --git a/spine-cpp/spine-cpp/include/spine/MathUtil.h b/spine-cpp/spine-cpp/include/spine/MathUtil.h index ee7318fba..19ebb515c 100644 --- a/spine-cpp/spine-cpp/include/spine/MathUtil.h +++ b/spine-cpp/spine-cpp/include/spine/MathUtil.h @@ -33,6 +33,9 @@ #include #include +// Needed for older MSVC versions +#undef min +#undef max namespace spine { diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index 6961a2dd3..757a85385 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -39,7 +39,7 @@ namespace spine { /// Attachment that displays a texture region using a mesh. - class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject { + class SP_API MeshAttachment : public VertexAttachment { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraint.h b/spine-cpp/spine-cpp/include/spine/PathConstraint.h index f35151419..c9795598a 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraint.h @@ -59,13 +59,18 @@ namespace spine { public: PathConstraint(PathConstraintData &data, Skeleton &skeleton); - /// Applies the constraint to the constrained bones. - void apply(); - virtual void update(); virtual int getOrder(); + PathConstraintData &getData(); + + Vector &getBones(); + + Slot *getTarget(); + + void setTarget(Slot *inValue); + float getPosition(); void setPosition(float inValue); @@ -86,14 +91,6 @@ namespace spine { void setMixY(float inValue); - Vector &getBones(); - - Slot *getTarget(); - - void setTarget(Slot *inValue); - - PathConstraintData &getData(); - bool isActive(); void setActive(bool inValue); diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintData.h b/spine-cpp/spine-cpp/include/spine/PathConstraintData.h index 6045fd669..120c4ab91 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintData.h @@ -57,8 +57,9 @@ namespace spine { friend class PathConstraintPositionTimeline; friend class PathConstraintSpacingTimeline; - public: + RTTI_DECL + explicit PathConstraintData(const String &name); Vector &getBones(); diff --git a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h index bd8cc1827..1003034cc 100644 --- a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h @@ -44,7 +44,7 @@ namespace spine { class Bone; /// Attachment that displays a texture region. - class SP_API RegionAttachment : public Attachment, public HasRendererObject { + class SP_API RegionAttachment : public Attachment { friend class SkeletonBinary; friend class SkeletonJson; @@ -61,7 +61,7 @@ namespace spine { void updateRegion(); /// Transforms the attachment's four vertices to world coordinates. - /// @param bone The parent bone. + /// @param slot The parent slot. /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8. /// @param offset The worldVertices index to begin writing values. /// @param stride The number of worldVertices entries between the value pairs written. diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h b/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h index e5078f1be..abdc05f97 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h @@ -147,7 +147,7 @@ namespace spine { Attachment *readAttachment(DataInput *input, Skin *skin, int slotIndex, const String &attachmentName, SkeletonData *skeletonData, bool nonessential); - void readVertices(DataInput *input, Vector &vertices, Vector &bones, int vertexCount); + void readVertices(DataInput *input, Vector &vertices, Vector &bones, int vertexCount); void readFloatArray(DataInput *input, int n, float scale, Vector &array); diff --git a/spine-cpp/spine-cpp/include/spine/SpineString.h b/spine-cpp/spine-cpp/include/spine/SpineString.h index a0796ddc4..8e709c03e 100644 --- a/spine-cpp/spine-cpp/include/spine/SpineString.h +++ b/spine-cpp/spine-cpp/include/spine/SpineString.h @@ -36,11 +36,6 @@ #include #include -// Required for sprintf on MSVC -#ifdef _MSC_VER -#pragma warning(disable:4996) -#endif - namespace spine { class SP_API String : public SpineObject { public: @@ -170,14 +165,14 @@ namespace spine { String &append(int other) { char str[100]; - sprintf(str, "%i", other); + snprintf(str, 100, "%i", other); append(str); return *this; } String &append(float other) { char str[100]; - sprintf(str, "%f", other); + snprintf(str, 100, "%f", other); append(str); return *this; } diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h b/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h index af430be37..f8fcecfef 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h @@ -50,40 +50,72 @@ namespace spine { friend class TransformConstraintTimeline; public: + RTTI_DECL + explicit TransformConstraintData(const String &name); Vector &getBones(); BoneData *getTarget(); + void setTarget(BoneData *target); + float getMixRotate(); + void setMixRotate(float mixRotate); + float getMixX(); + void setMixX(float mixX); + float getMixY(); + void setMixY(float mixY); + float getMixScaleX(); + void setMixScaleX(float mixScaleX); + float getMixScaleY(); + void setMixScaleY(float mixScaleY); + float getMixShearY(); + void setMixShearY(float mixShearY); + float getOffsetRotation(); + void setOffsetRotation(float offsetRotation); + float getOffsetX(); + void setOffsetX(float offsetX); + float getOffsetY(); + void setOffsetY(float offsetY); + float getOffsetScaleX(); + void setOffsetScaleX(float offsetScaleX); + float getOffsetScaleY(); + void setOffsetScaleY(float offsetScaleY); + float getOffsetShearY(); + void setOffsetShearY(float offsetShearY); + bool isRelative(); + void setRelative(bool isRelative); + bool isLocal(); + void setLocal(bool isLocal); + private: Vector _bones; BoneData *_target; diff --git a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h index 51532c3cf..5a9ddd932 100644 --- a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h @@ -71,7 +71,7 @@ namespace spine { /// Gets a unique ID for this attachment. int getId(); - Vector &getBones(); + Vector &getBones(); Vector &getVertices(); @@ -86,7 +86,7 @@ namespace spine { void copyTo(VertexAttachment *other); protected: - Vector _bones; + Vector _bones; Vector _vertices; size_t _worldVerticesLength; Attachment *_timelineAttachment; diff --git a/spine-cpp/spine-cpp/include/spine/Vertices.h b/spine-cpp/spine-cpp/include/spine/Vertices.h index b83d90329..00a9d09c3 100644 --- a/spine-cpp/spine-cpp/include/spine/Vertices.h +++ b/spine-cpp/spine-cpp/include/spine/Vertices.h @@ -35,7 +35,7 @@ namespace spine { class SP_API Vertices : public SpineObject { public: - Vector _bones; + Vector _bones; Vector _vertices; }; } diff --git a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp index 1ec221c2c..1182d375e 100644 --- a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp +++ b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp @@ -211,17 +211,16 @@ EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry *trackEntry, Ev _event(event) { } -EventQueue *EventQueue::newEventQueue(AnimationState &state, Pool &trackEntryPool) { - return new (__FILE__, __LINE__) EventQueue(state, trackEntryPool); +EventQueue *EventQueue::newEventQueue(AnimationState &state) { + return new (__FILE__, __LINE__) EventQueue(state); } EventQueueEntry EventQueue::newEventQueueEntry(EventType eventType, TrackEntry *entry, Event *event) { return EventQueueEntry(eventType, entry, event); } -EventQueue::EventQueue(AnimationState &state, Pool &trackEntryPool) : _state(state), - _trackEntryPool(trackEntryPool), - _drainDisabled(false) { +EventQueue::EventQueue(AnimationState &state) : _state(state), + _drainDisabled(false) { } EventQueue::~EventQueue() { @@ -295,8 +294,7 @@ void EventQueue::drain() { else state._listenerObject->callback(&state, EventType_Dispose, trackEntry, NULL); - trackEntry->reset(); - _trackEntryPool.free(trackEntry); + if (!_state.getManualTrackEntryDisposal()) _state.disposeTrackEntry(trackEntry); break; case EventType_Event: if (!trackEntry->_listenerObject) @@ -315,12 +313,13 @@ void EventQueue::drain() { } AnimationState::AnimationState(AnimationStateData *data) : _data(data), - _queue(EventQueue::newEventQueue(*this, _trackEntryPool)), + _queue(EventQueue::newEventQueue(*this)), _animationsChanged(false), _listener(dummyOnAnimationEventFunc), _listenerObject(NULL), _unkeyedState(0), - _timeScale(1) { + _timeScale(1), + _manualTrackEntryDisposal(false) { } AnimationState::~AnimationState() { @@ -666,6 +665,19 @@ void AnimationState::enableQueue() { _queue->_drainDisabled = false; } +void AnimationState::setManualTrackEntryDisposal(bool inValue) { + _manualTrackEntryDisposal = inValue; +} + +bool AnimationState::getManualTrackEntryDisposal() { + return _manualTrackEntryDisposal; +} + +void AnimationState::disposeTrackEntry(TrackEntry *entry) { + entry->reset(); + _trackEntryPool.free(entry); +} + Animation *AnimationState::getEmptyAnimation() { static Vector timelines; static Animation ret(String(""), timelines, 0); diff --git a/spine-cpp/spine-cpp/src/spine/Atlas.cpp b/spine-cpp/spine-cpp/src/spine/Atlas.cpp index 6930ef3dc..7b2a03d94 100644 --- a/spine-cpp/spine-cpp/src/spine/Atlas.cpp +++ b/spine-cpp/spine-cpp/src/spine/Atlas.cpp @@ -69,7 +69,7 @@ Atlas::Atlas(const char *data, int length, const char *dir, TextureLoader *textu Atlas::~Atlas() { if (_textureLoader) { for (size_t i = 0, n = _pages.size(); i < n; ++i) { - _textureLoader->unload(_pages[i]->getRendererObject()); + _textureLoader->unload(_pages[i]->texture); } } ContainerUtil::cleanUpVectorOfPointers(_pages); @@ -108,21 +108,21 @@ struct SimpleString { while (isspace((unsigned char) *start) && start < end) start++; if (start == end) { - length = end - start; + length = (int) (end - start); return *this; } end--; while (((unsigned char) *end == '\r') && end >= start) end--; end++; - length = end - start; + length = (int) (end - start); return *this; } int indexOf(char needle) { char *c = start; while (c < end) { - if (*c == needle) return c - start; + if (*c == needle) return (int) (c - start); c++; } return -1; @@ -131,7 +131,7 @@ struct SimpleString { int indexOf(char needle, int at) { char *c = start + at; while (c < end) { - if (*c == needle) return c - start; + if (*c == needle) return (int) (c - start); c++; } return -1; @@ -150,7 +150,7 @@ struct SimpleString { SimpleString result; result.start = start + s; result.end = end; - result.length = result.end - result.start; + result.length = (int) (result.end - result.start); return result; } @@ -286,10 +286,12 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText } else { page->texturePath = String(path, true); } + page->index = (int) _pages.size(); _pages.add(page); } else { AtlasRegion *region = new (__FILE__, __LINE__) AtlasRegion(); region->page = page; + region->rendererObject = page->texture; region->name = String(line->copy(), true); while (true) { line = reader.readLine(); diff --git a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp index 78d56179b..fbd22e9ea 100644 --- a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp @@ -63,7 +63,6 @@ namespace spine { } else { AtlasRegion *region = findRegion(path); if (!region) return NULL; - attachment->setRendererObject(region); attachment->setRegion(region); } return attachment; @@ -78,7 +77,6 @@ namespace spine { } else { AtlasRegion *region = findRegion(path); if (!region) return NULL; - attachment->setRendererObject(region); attachment->setRegion(region); } return attachment; diff --git a/spine-cpp/spine-cpp/src/spine/Bone.cpp b/spine-cpp/spine-cpp/src/spine/Bone.cpp index 4b3bfd98a..be28bd790 100644 --- a/spine-cpp/spine-cpp/src/spine/Bone.cpp +++ b/spine-cpp/spine-cpp/src/spine/Bone.cpp @@ -192,7 +192,6 @@ void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, _b = za * lb + zb * ld; _c = zc * la + zd * lc; _d = zc * lb + zd * ld; - break; } } _a *= _skeleton.getScaleX(); @@ -496,33 +495,75 @@ void Bone::updateAppliedTransform() { _ascaleY = MathUtil::sqrt(_b * _b + _d * _d); _ashearX = 0; _ashearY = MathUtil::atan2(_a * _b + _c * _d, _a * _d - _b * _c) * MathUtil::Rad_Deg; + } + float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d; + float pid = 1 / (pa * pd - pb * pc); + float ia = pd * pid, ib = pb * pid, ic = pc * pid, id = pa * pid; + float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY; + _ax = (dx * ia - dy * ib); + _ay = (dy * id - dx * ic); + + float ra, rb, rc, rd; + if (_data.getTransformMode() == TransformMode_OnlyTranslation) { + ra = _a; + rb = _b; + rc = _c; + rd = _d; } else { - float pa = parent->_a, pb = parent->_b, pc = parent->_c, pd = parent->_d; - float pid = 1 / (pa * pd - pb * pc); - float dx = _worldX - parent->_worldX, dy = _worldY - parent->_worldY; - float ia = pid * pd; - float id = pid * pa; - float ib = pid * pb; - float ic = pid * pc; - float ra = ia * _a - ib * _c; - float rb = ia * _b - ib * _d; - float rc = id * _c - ic * _a; - float rd = id * _d - ic * _b; - _ax = (dx * pd * pid - dy * pb * pid); - _ay = (dy * pa * pid - dx * pc * pid); - _ashearX = 0; - _ascaleX = MathUtil::sqrt(ra * ra + rc * rc); - if (_ascaleX > 0.0001f) { - float det = ra * rd - rb * rc; - _ascaleY = det / _ascaleX; - _ashearY = MathUtil::atan2(ra * rb + rc * rd, det) * MathUtil::Rad_Deg; - _arotation = MathUtil::atan2(rc, ra) * MathUtil::Rad_Deg; - } else { - _ascaleX = 0; - _ascaleY = MathUtil::sqrt(rb * rb + rd * rd); - _ashearY = 0; - _arotation = 90 - MathUtil::atan2(rd, rb) * MathUtil::Rad_Deg; + switch (_data.getTransformMode()) { + case TransformMode_NoRotationOrReflection: { + float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc); + float sa = pa / _skeleton.getScaleX(); + float sc = pc / _skeleton.getScaleY(); + pb = -sc * s * _skeleton.getScaleX(); + pd = sa * s * _skeleton.getScaleY(); + pid = 1 / (pa * pd - pb * pc); + ia = pd * pid; + ib = pb * pid; + break; + } + case TransformMode_NoScale: + case TransformMode_NoScaleOrReflection: { + float cos = MathUtil::cosDeg(_rotation), sin = MathUtil::sinDeg(_rotation); + pa = (pa * cos + pb * sin) / _skeleton.getScaleX(); + pc = (pc * cos + pd * sin) / _skeleton.getScaleY(); + float s = MathUtil::sqrt(pa * pa + pc * pc); + if (s > 0.00001f) s = 1 / s; + pa *= s; + pc *= s; + s = MathUtil::sqrt(pa * pa + pc * pc); + if (_data.getTransformMode() == TransformMode_NoScale && pid < 0 != (_skeleton.getScaleX() < 0 != _skeleton.getScaleY() < 0)) s = -s; + float r = MathUtil::Pi / 2 + MathUtil::atan2(pc, pa); + pb = MathUtil::cos(r) * s; + pd = MathUtil::sin(r) * s; + pid = 1 / (pa * pd - pb * pc); + ia = pd * pid; + ib = pb * pid; + ic = pc * pid; + id = pa * pid; + break; + } + default: + break; } + ra = ia * _a - ib * _c; + rb = ia * _b - ib * _d; + rc = id * _c - ic * _a; + rd = id * _d - ic * _b; + } + + _ashearX = 0; + _ascaleX = MathUtil::sqrt(ra * ra + rc * rc); + if (_ascaleX > 0.0001f) { + float det = ra * rd - rb * rc; + _ascaleY = det / _ascaleX; + _ashearY = -MathUtil::atan2(ra * rb + rc * rd, det) * MathUtil::Rad_Deg; + _arotation = MathUtil::atan2(rc, ra) * MathUtil::Rad_Deg; + } else { + _ascaleX = 0; + _ascaleY = MathUtil::sqrt(rb * rb + rd * rd); + _ashearY = 0; + _arotation = 90 - MathUtil::atan2(rd, rb) * MathUtil::Rad_Deg; } } diff --git a/spine-cpp/spine-cpp/src/spine/ConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/ConstraintData.cpp index 051320899..3f3894dba 100644 --- a/spine-cpp/spine-cpp/src/spine/ConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/ConstraintData.cpp @@ -31,6 +31,8 @@ using namespace spine; +RTTI_IMPL_NOPARENT(ConstraintData) + ConstraintData::ConstraintData(const String &name) : _name(name), _order(0), _skinRequired(false) { } diff --git a/spine-cpp/spine-cpp/src/spine/Extension.cpp b/spine-cpp/spine-cpp/src/spine/Extension.cpp index acdc93a09..17a2539c9 100644 --- a/spine-cpp/spine-cpp/src/spine/Extension.cpp +++ b/spine-cpp/spine-cpp/src/spine/Extension.cpp @@ -104,6 +104,7 @@ void DefaultSpineExtension::_free(void *mem, const char *file, int line) { } char *DefaultSpineExtension::_readFile(const String &path, int *length) { +#ifndef __EMSCRIPTEN__ char *data; FILE *file = fopen(path.buffer(), "rb"); if (!file) return 0; @@ -117,6 +118,9 @@ char *DefaultSpineExtension::_readFile(const String &path, int *length) { fclose(file); return data; +#else + return nullptr; +#endif } DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() { diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index e36bdf18e..8a9af567c 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -154,11 +154,13 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY } x = targetX - pp->_worldX; y = targetY - pp->_worldY; - tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py; + tx = (x * d - y * b) * id - px; + ty = (y * a - x * c) * id - py; dd = tx * tx + ty * ty; if (softness != 0) { softness *= psx * (csx + 1) * 0.5f; - td = MathUtil::sqrt(dd), sd = td - l1 - l2 * psx + softness; + td = MathUtil::sqrt(dd); + sd = td - l1 - l2 * psx + softness; if (sd > 0) { p = MathUtil::min(1.0f, sd / (softness * 2)) - 1; p = (sd - softness * (1 - p * p)) / td; @@ -188,7 +190,8 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY b = l2 * MathUtil::sin(a2); a1 = MathUtil::atan2(ty * a - tx * b, tx * a + ty * b); } else { - a = psx * l2, b = psy * l2; + a = psx * l2; + b = psy * l2; float aa = a * a, bb = b * b, ll = l1 * l1, ta = MathUtil::atan2(ty, tx); float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa; d = c1 * c1 - 4 * c2 * c0; diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp index ec6806598..52f6779a8 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp @@ -33,6 +33,8 @@ using namespace spine; +RTTI_IMPL(IkConstraintData, ConstraintData) + IkConstraintData::IkConstraintData(const String &name) : ConstraintData(name), _target(NULL), _bendDirection(1), diff --git a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp index 44fc15960..57562f508 100644 --- a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp @@ -34,7 +34,7 @@ using namespace spine; RTTI_IMPL(MeshAttachment, VertexAttachment) -MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), HasRendererObject(), +MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), _parentMesh(NULL), _path(), _color(1, 1, 1, 1), @@ -203,7 +203,6 @@ Attachment *MeshAttachment::copy() { if (_parentMesh) return newLinkedMesh(); MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); - copy->setRendererObject(getRendererObject()); copy->setRegion(_region); copy->setSequence(_sequence != NULL ? _sequence->copy() : NULL); copy->_path = _path; @@ -224,7 +223,6 @@ Attachment *MeshAttachment::copy() { MeshAttachment *MeshAttachment::newLinkedMesh() { MeshAttachment *copy = new (__FILE__, __LINE__) MeshAttachment(getName()); - copy->setRendererObject(getRendererObject()); copy->setRegion(_region); copy->_path = _path; copy->_color.set(_color); diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp index 6baf22b9d..a102ee51d 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp @@ -36,6 +36,8 @@ using namespace spine; +RTTI_IMPL(PathConstraintData, ConstraintData) + PathConstraintData::PathConstraintData(const String &name) : ConstraintData(name), _target(NULL), _positionMode(PositionMode_Fixed), diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index 2a9ba7377..09bc78265 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -47,7 +47,7 @@ const int RegionAttachment::URY = 5; const int RegionAttachment::BRX = 6; const int RegionAttachment::BRY = 7; -RegionAttachment::RegionAttachment(const String &name) : Attachment(name), HasRendererObject(), +RegionAttachment::RegionAttachment(const String &name) : Attachment(name), _x(0), _y(0), _rotation(0), @@ -259,7 +259,6 @@ spine::Color &RegionAttachment::getColor() { Attachment *RegionAttachment::copy() { RegionAttachment *copy = new (__FILE__, __LINE__) RegionAttachment(getName()); copy->_region = _region; - copy->setRendererObject(getRendererObject()); copy->_path = _path; copy->_x = _x; copy->_y = _y; diff --git a/spine-cpp/spine-cpp/src/spine/Sequence.cpp b/spine-cpp/spine-cpp/src/spine/Sequence.cpp index f07f1c861..3b4bcf5d1 100644 --- a/spine-cpp/spine-cpp/src/spine/Sequence.cpp +++ b/spine-cpp/spine-cpp/src/spine/Sequence.cpp @@ -66,7 +66,6 @@ void Sequence::apply(Slot *slot, Attachment *attachment) { if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { RegionAttachment *regionAttachment = static_cast(attachment); if (regionAttachment->getRegion() != region) { - regionAttachment->setRendererObject(region); regionAttachment->setRegion(region); regionAttachment->updateRegion(); } @@ -75,7 +74,6 @@ void Sequence::apply(Slot *slot, Attachment *attachment) { if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment *meshAttachment = static_cast(attachment); if (meshAttachment->getRegion() != region) { - meshAttachment->setRendererObject(region); meshAttachment->setRegion(region); meshAttachment->updateRegion(); } diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index 5488eee37..f927e37b0 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -425,8 +425,8 @@ PathConstraint *Skeleton::findPathConstraint(const String &constraintName) { void Skeleton::getBounds(float &outX, float &outY, float &outWidth, float &outHeight, Vector &outVertexBuffer) { float minX = FLT_MAX; float minY = FLT_MAX; - float maxX = FLT_MIN; - float maxY = FLT_MIN; + float maxX = -FLT_MAX; + float maxY = -FLT_MAX; for (size_t i = 0; i < _drawOrder.size(); ++i) { Slot *slot = _drawOrder[i]; @@ -653,7 +653,7 @@ void Skeleton::sortPathConstraintAttachment(Skin *skin, size_t slotIndex, Bone & void Skeleton::sortPathConstraintAttachment(Attachment *attachment, Bone &slotBone) { if (attachment == NULL || !attachment->getRTTI().instanceOf(PathAttachment::rtti)) return; - Vector &pathBones = static_cast(attachment)->getBones(); + Vector &pathBones = static_cast(attachment)->getBones(); if (pathBones.size() == 0) sortBone(&slotBone); else { diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp index 66867789c..fd906bce9 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp @@ -109,9 +109,9 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons int lowHash = readInt(input); int hightHash = readInt(input); String hashString; - sprintf(buffer, "%x", hightHash); + snprintf(buffer, 16, "%x", hightHash); hashString.append(buffer); - sprintf(buffer, "%x", lowHash); + snprintf(buffer, 16, "%x", lowHash); hashString.append(buffer); skeletonData->_hash = hashString; @@ -120,7 +120,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons if (!skeletonData->_version.startsWith(SPINE_VERSION_STRING)) { char errorMsg[255]; - sprintf(errorMsg, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING); + snprintf(errorMsg, 255, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING); setError(errorMsg, ""); return NULL; } @@ -564,7 +564,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo Vector uvs; Vector triangles; Vector vertices; - Vector bones; + Vector bones; int hullLength; Sequence *sequence; float width = 0; @@ -702,7 +702,7 @@ Attachment *SkeletonBinary::readAttachment(DataInput *input, Skin *skin, int slo return NULL; } -void SkeletonBinary::readVertices(DataInput *input, Vector &vertices, Vector &bones, int vertexCount) { +void SkeletonBinary::readVertices(DataInput *input, Vector &vertices, Vector &bones, int vertexCount) { float scale = _scale; int verticesLength = vertexCount << 1; @@ -1249,13 +1249,13 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S setError("Attachment not found: ", attachmentName); return NULL; } - VertexAttachment *attachment = static_cast(baseAttachment); unsigned int timelineType = readByte(input); int frameCount = readVarint(input, true); int frameLast = frameCount - 1; switch (timelineType) { case ATTACHMENT_DEFORM: { + VertexAttachment *attachment = static_cast(baseAttachment); bool weighted = attachment->_bones.size() > 0; Vector &vertices = attachment->_vertices; int deformLength = weighted ? (int) vertices.size() / 3 * 2 : (int) vertices.size(); @@ -1311,7 +1311,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S break; } case ATTACHMENT_SEQUENCE: { - SequenceTimeline *timeline = new (__FILE__, __LINE__) SequenceTimeline(frameCount, slotIndex, attachment); + SequenceTimeline *timeline = new (__FILE__, __LINE__) SequenceTimeline(frameCount, slotIndex, baseAttachment); for (int frame = 0; frame < frameCount; frame++) { float time = readFloat(input); int modeAndIndex = readInt(input); diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp index 80a88c8d0..2c9228db1 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp @@ -152,7 +152,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) { skeletonData->_version = Json::getString(skeleton, "spine", 0); if (!skeletonData->_version.startsWith(SPINE_VERSION_STRING)) { char errorMsg[255]; - sprintf(errorMsg, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING); + snprintf(errorMsg, 255, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING); setError(NULL, errorMsg, ""); return NULL; } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp index 6675d4521..eaa484401 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp @@ -35,6 +35,8 @@ using namespace spine; +RTTI_IMPL(TransformConstraintData, ConstraintData) + TransformConstraintData::TransformConstraintData(const String &name) : ConstraintData(name), _target(NULL), _mixRotate(0), @@ -116,3 +118,63 @@ bool TransformConstraintData::isRelative() { bool TransformConstraintData::isLocal() { return _local; } + +void TransformConstraintData::setTarget(BoneData *target) { + _target = target; +} + +void TransformConstraintData::setMixRotate(float mixRotate) { + _mixRotate = mixRotate; +} + +void TransformConstraintData::setMixX(float mixX) { + _mixX = mixX; +} + +void TransformConstraintData::setMixY(float mixY) { + _mixY = mixY; +} + +void TransformConstraintData::setMixScaleX(float mixScaleX) { + _mixScaleX = mixScaleX; +} + +void TransformConstraintData::setMixScaleY(float mixScaleY) { + _mixScaleY = mixScaleY; +} + +void TransformConstraintData::setMixShearY(float mixShearY) { + _mixShearY = mixShearY; +} + +void TransformConstraintData::setOffsetRotation(float offsetRotation) { + _offsetRotation = offsetRotation; +} + +void TransformConstraintData::setOffsetX(float offsetX) { + _offsetX = offsetX; +} + +void TransformConstraintData::setOffsetY(float offsetY) { + _offsetY = offsetY; +} + +void TransformConstraintData::setOffsetScaleX(float offsetScaleX) { + _offsetScaleX = offsetScaleX; +} + +void TransformConstraintData::setOffsetScaleY(float offsetScaleY) { + _offsetScaleY = offsetScaleY; +} + +void TransformConstraintData::setOffsetShearY(float offsetShearY) { + _offsetShearY = offsetShearY; +} + +void TransformConstraintData::setRelative(bool isRelative) { + _relative = isRelative; +} + +void TransformConstraintData::setLocal(bool isLocal) { + _local = isLocal; +} diff --git a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp index 7141b6cf8..1f8208057 100644 --- a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp @@ -64,7 +64,7 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou Skeleton &skeleton = slot._bone._skeleton; Vector *deformArray = &slot.getDeform(); Vector *vertices = &_vertices; - Vector &bones = _bones; + Vector &bones = _bones; if (bones.size() == 0) { if (deformArray->size() > 0) vertices = deformArray; @@ -130,7 +130,7 @@ int VertexAttachment::getId() { return _id; } -Vector &VertexAttachment::getBones() { +Vector &VertexAttachment::getBones() { return _bones; } diff --git a/spine-sfml/cpp/src/spine/spine-sfml.cpp b/spine-sfml/cpp/src/spine/spine-sfml.cpp index c5c1c3fd1..755f0bed6 100644 --- a/spine-sfml/cpp/src/spine/spine-sfml.cpp +++ b/spine-sfml/cpp/src/spine/spine-sfml.cpp @@ -123,7 +123,7 @@ namespace spine { uvs = ®ionAttachment->getUVs(); indices = &quadIndices; indicesCount = 6; - texture = (Texture *) ((AtlasRegion *) regionAttachment->getRendererObject())->page->getRendererObject(); + texture = (Texture *) ((AtlasRegion *) regionAttachment->getRegion())->page->texture; } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { MeshAttachment *mesh = (MeshAttachment *) attachment; @@ -140,7 +140,7 @@ namespace spine { uvs = &mesh->getUVs(); indices = &mesh->getTriangles(); indicesCount = mesh->getTriangles().size(); - texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); + texture = (Texture *) ((AtlasRegion *) mesh->getRegion())->page->texture; } else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) { ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment(); @@ -241,7 +241,7 @@ namespace spine { if (page.magFilter == TextureFilter_Linear) texture->setSmooth(true); if (page.uWrap == TextureWrap_Repeat && page.vWrap == TextureWrap_Repeat) texture->setRepeated(true); - page.setRendererObject(texture); + page.texture = texture; Vector2u size = texture->getSize(); page.width = size.x; page.height = size.y;