From cb6916c3c34c5de10218182004bda51c4e2c8cf4 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 7 Jun 2025 02:54:51 +0200 Subject: [PATCH] [cpp] 4.3 porting WIP --- spine-cpp/spine-cpp/include/spine/BoneLocal.h | 2 +- spine-cpp/spine-cpp/include/spine/SlotPose.h | 92 ++++++++++++++++++ spine-cpp/spine-cpp/include/spine/spine.h | 1 + spine-cpp/spine-cpp/src/spine/BoneLocal.cpp | 1 - spine-cpp/spine-cpp/src/spine/SlotPose.cpp | 96 +++++++++++++++++++ 5 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 spine-cpp/spine-cpp/include/spine/SlotPose.h create mode 100644 spine-cpp/spine-cpp/src/spine/SlotPose.cpp diff --git a/spine-cpp/spine-cpp/include/spine/BoneLocal.h b/spine-cpp/spine-cpp/include/spine/BoneLocal.h index 47a17499d..2d0c40eb2 100644 --- a/spine-cpp/spine-cpp/include/spine/BoneLocal.h +++ b/spine-cpp/spine-cpp/include/spine/BoneLocal.h @@ -37,7 +37,7 @@ namespace spine { /// Stores a bone's local pose. - class SP_API BoneLocal : public SpineObject, public Pose { + class SP_API BoneLocal : public Pose { RTTI_DECL private: diff --git a/spine-cpp/spine-cpp/include/spine/SlotPose.h b/spine-cpp/spine-cpp/include/spine/SlotPose.h new file mode 100644 index 000000000..d6a0a8562 --- /dev/null +++ b/spine-cpp/spine-cpp/include/spine/SlotPose.h @@ -0,0 +1,92 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2020, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#ifndef SPINE_SLOTPOSE_H_ +#define SPINE_SLOTPOSE_H_ + +#include +#include +#include +#include +#include + +namespace spine { + class Attachment; + class VertexAttachment; + + class SP_API SlotPose : public Pose { + RTTI_DECL + + private: + Color _color; + Color _darkColor; + bool _hasDarkColor; + Attachment* _attachment; + int _sequenceIndex; + Vector _deform; + + public: + SlotPose(); + virtual ~SlotPose(); + + virtual void set(SlotPose& pose) override; + + /// The color used to tint the slot's attachment. If getDarkColor() is set, this is used as the light color for two + /// color tinting. + Color& getColor(); + + /// The dark color used to tint the slot's attachment for two color tinting. The dark + /// color's alpha is not used. + Color& getDarkColor(); + + /// Returns true if this slot has a dark color. + bool hasDarkColor(); + + /// The current attachment for the slot, or null if the slot has no attachment. + Attachment* getAttachment(); + + /// Sets the slot's attachment and, if the attachment changed, resets sequenceIndex and clears the deform. + /// The deform is not cleared if the old attachment has the same VertexAttachment::getTimelineAttachment() as the + /// specified attachment. + void setAttachment(Attachment* attachment); + + /// The index of the texture region to display when the slot's attachment has a Sequence. -1 represents the + /// Sequence::getSetupIndex(). + int getSequenceIndex(); + void setSequenceIndex(int sequenceIndex); + + /// Values to deform the slot's attachment. For an unweighted mesh, the entries are local positions for each vertex. For a + /// weighted mesh, the entries are an offset for each vertex which will be added to the mesh's local vertex positions. + /// + /// See VertexAttachment::computeWorldVertices() and DeformTimeline. + Vector& getDeform(); + }; +} + +#endif /* SPINE_SLOTPOSE_H_ */ \ No newline at end of file diff --git a/spine-cpp/spine-cpp/include/spine/spine.h b/spine-cpp/spine-cpp/include/spine/spine.h index ff04d49cf..dbd8db972 100644 --- a/spine-cpp/spine-cpp/include/spine/spine.h +++ b/spine-cpp/spine-cpp/include/spine/spine.h @@ -108,6 +108,7 @@ #include #include #include +#include #include #include #include diff --git a/spine-cpp/spine-cpp/src/spine/BoneLocal.cpp b/spine-cpp/spine-cpp/src/spine/BoneLocal.cpp index b22c7542d..abcf0b09a 100644 --- a/spine-cpp/spine-cpp/src/spine/BoneLocal.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoneLocal.cpp @@ -28,7 +28,6 @@ *****************************************************************************/ #include -#include using namespace spine; diff --git a/spine-cpp/spine-cpp/src/spine/SlotPose.cpp b/spine-cpp/spine-cpp/src/spine/SlotPose.cpp new file mode 100644 index 000000000..73fae8933 --- /dev/null +++ b/spine-cpp/spine-cpp/src/spine/SlotPose.cpp @@ -0,0 +1,96 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2020, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include +#include +#include + +using namespace spine; + +RTTI_IMPL_NOPARENT(SlotPose) + +SlotPose::SlotPose() : _color(1, 1, 1, 1), _darkColor(0, 0, 0, 0), _hasDarkColor(false), _attachment(nullptr), _sequenceIndex(-1) { +} + +SlotPose::~SlotPose() { +} + +void SlotPose::set(SlotPose& pose) { + _color.set(pose._color); + if (pose._hasDarkColor) _darkColor.set(pose._darkColor); + _hasDarkColor = pose._hasDarkColor; + _attachment = pose._attachment; + _sequenceIndex = pose._sequenceIndex; + _deform.clear(); + _deform.addAll(pose._deform); +} + +Color& SlotPose::getColor() { + return _color; +} + +Color& SlotPose::getDarkColor() { + return _darkColor; +} + +bool SlotPose::hasDarkColor() { + return _hasDarkColor; +} + +Attachment* SlotPose::getAttachment() { + return _attachment; +} + +void SlotPose::setAttachment(Attachment* attachment) { + if (_attachment == attachment) return; + + // Check if we need to clear deform based on timeline attachment + if (!attachment || + !_attachment || + !attachment->getRTTI().instanceOf(VertexAttachment::rtti) || + !_attachment->getRTTI().instanceOf(VertexAttachment::rtti) || + static_cast(attachment)->getTimelineAttachment() != + static_cast(_attachment)->getTimelineAttachment()) { + _deform.clear(); + } + _attachment = attachment; + _sequenceIndex = -1; +} + +int SlotPose::getSequenceIndex() { + return _sequenceIndex; +} + +void SlotPose::setSequenceIndex(int sequenceIndex) { + _sequenceIndex = sequenceIndex; +} + +Vector& SlotPose::getDeform() { + return _deform; +} \ No newline at end of file