From 4876f0d00b8b234148a6f358c9969cf97b90f6d5 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 12 Jun 2025 04:25:49 +0200 Subject: [PATCH] [cpp] 4.3 porting WIP --- spine-cpp/spine-cpp/include/spine/Slider.h | 71 +++++++++++ .../spine-cpp/include/spine/SliderData.h | 92 ++++++++++++++ spine-cpp/spine-cpp/include/spine/spine.h | 2 + spine-cpp/spine-cpp/src/spine/Slider.cpp | 112 ++++++++++++++++++ spine-cpp/spine-cpp/src/spine/SliderData.cpp | 106 +++++++++++++++++ 5 files changed, 383 insertions(+) create mode 100644 spine-cpp/spine-cpp/include/spine/Slider.h create mode 100644 spine-cpp/spine-cpp/include/spine/SliderData.h create mode 100644 spine-cpp/spine-cpp/src/spine/Slider.cpp create mode 100644 spine-cpp/spine-cpp/src/spine/SliderData.cpp diff --git a/spine-cpp/spine-cpp/include/spine/Slider.h b/spine-cpp/spine-cpp/include/spine/Slider.h new file mode 100644 index 000000000..fab9977ac --- /dev/null +++ b/spine-cpp/spine-cpp/include/spine/Slider.h @@ -0,0 +1,71 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated April 5, 2025. Replaces all prior versions. + * + * Copyright (c) 2013-2025, 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_Slider_h +#define Spine_Slider_h + +#include +#include +#include + +namespace spine { + class Skeleton; + class Bone; + enum Physics; + + /// Stores the setup pose for a PhysicsConstraint. + /// + /// See https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide. + class SP_API Slider : public Constraint { + friend class Skeleton; + + public: + RTTI_DECL + + Slider(SliderData& data, Skeleton& skeleton); + + /// Creates a copy of this slider for the specified skeleton. + Slider* copy(Skeleton& skeleton); + + /// Updates the slider constraint. + virtual void update(Skeleton& skeleton, Physics physics) override; + + /// Called by Skeleton to sort constraints. + void sort(Skeleton& skeleton); + + Bone* getBone(); + void setBone(Bone* bone); + + private: + Bone* _bone; + static float _offsets[6]; + }; +} + +#endif /* Spine_Slider_h */ \ No newline at end of file diff --git a/spine-cpp/spine-cpp/include/spine/SliderData.h b/spine-cpp/spine-cpp/include/spine/SliderData.h new file mode 100644 index 000000000..cb8100966 --- /dev/null +++ b/spine-cpp/spine-cpp/include/spine/SliderData.h @@ -0,0 +1,92 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated April 5, 2025. Replaces all prior versions. + * + * Copyright (c) 2013-2025, 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_SliderData_h +#define Spine_SliderData_h + +#include +#include +#include + +namespace spine { + class Animation; + class BoneData; + class FromProperty; + class Slider; + class Skeleton; + + /// Stores the setup pose for a PhysicsConstraint. + /// + /// See https://esotericsoftware.com/spine-physics-constraints Physics constraints in the Spine User Guide. + class SP_API SliderData : public ConstraintDataGeneric { + friend class SkeletonBinary; + friend class SkeletonJson; + friend class Slider; + + public: + RTTI_DECL + + explicit SliderData(const String &name); + + /// Creates a slider instance. + virtual Slider* create(Skeleton& skeleton) override; + + Animation* getAnimation(); + void setAnimation(Animation* animation); + + bool getAdditive(); + void setAdditive(bool additive); + + bool getLoop(); + void setLoop(bool loop); + + BoneData* getBone(); + void setBone(BoneData* bone); + + FromProperty* getProperty(); + void setProperty(FromProperty* property); + + float getScale(); + void setScale(float scale); + + bool getLocal(); + void setLocal(bool local); + + private: + Animation* _animation; + bool _additive; + bool _loop; + BoneData* _bone; + FromProperty* _property; + float _scale; + bool _local; + }; +} + +#endif /* Spine_SliderData_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 783cc748b..78a98254a 100644 --- a/spine-cpp/spine-cpp/include/spine/spine.h +++ b/spine-cpp/spine-cpp/include/spine/spine.h @@ -115,6 +115,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/spine-cpp/spine-cpp/src/spine/Slider.cpp b/spine-cpp/spine-cpp/src/spine/Slider.cpp new file mode 100644 index 000000000..4a50f41dc --- /dev/null +++ b/spine-cpp/spine-cpp/src/spine/Slider.cpp @@ -0,0 +1,112 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated April 5, 2025. Replaces all prior versions. + * + * Copyright (c) 2013-2025, 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 +#include +#include +#include +#include +#include +#include +#include + +using namespace spine; + +RTTI_IMPL(Slider, Update) + +float Slider::_offsets[6]; + +Slider::Slider(SliderData& data, Skeleton& skeleton) : Constraint(data), _bone(NULL) { + if (data.getBone() != NULL) { + _bone = skeleton.findBone(data.getBone()->getName()); + } +} + +Slider* Slider::copy(Skeleton& skeleton) { + Slider* copy = new (__FILE__, __LINE__) Slider(_data, skeleton); + copy->_pose.set(_pose); + return copy; +} + +void Slider::update(Skeleton& skeleton, Physics physics) { + SliderPose& p = *_applied; + if (p.getMix() == 0) return; + + Animation* animation = _data.getAnimation(); + if (_bone != NULL) { + if (!_bone->isActive()) return; + if (_data.getLocal()) _bone->getAppliedPose().validateLocalTransform(skeleton); + p.setTime((_data.getProperty()->value(_bone->getAppliedPose(), _data.getLocal(), _offsets) - _data.getProperty()->offset) * _data.getScale()); + if (_data.getLoop()) { + // TODO: Implement when Animation is ported + p.setTime(animation->getDuration() + MathUtil::fmod(p.getTime(), animation->getDuration())); + } else { + p.setTime(MathUtil::max(0.0f, p.getTime())); + } + } + + // TODO: Implement when Animation is ported + // Vector& bones = skeleton.getBones(); + // Vector& indices = animation->getBones(); + // for (size_t i = 0, n = indices.size(); i < n; i++) { + // bones[indices[i]]->getAppliedPose().modifyLocal(skeleton); + // } + + // TODO: Implement when Animation is ported + // animation->apply(skeleton, p.getTime(), p.getTime(), _data.getLoop(), NULL, p.getMix(), + // _data.getAdditive() ? MixBlend_Add : MixBlend_Replace, MixDirection_In); +} + +void Slider::sort(Skeleton& skeleton) { + // TODO: Implement when Animation is ported + // if (_bone != NULL && !_data.getLocal()) skeleton.sortBone(_bone); + skeleton.getUpdateCacheList().add(this); + + // TODO: Implement when Animation is ported + // Vector& bones = skeleton.getBones(); + // Vector& indices = _data.getAnimation()->getBones(); + // for (size_t i = 0, n = indices.size(); i < n; i++) { + // Bone* bone = bones[indices[i]]; + // bone->setSorted(false); + // skeleton.sortReset(bone->getChildren()); + // skeleton.constrained(bone); + // } + + // TODO: Implement when Animation is ported - timeline processing +} + +Bone* Slider::getBone() { + return _bone; +} + +void Slider::setBone(Bone* bone) { + _bone = bone; +} \ No newline at end of file diff --git a/spine-cpp/spine-cpp/src/spine/SliderData.cpp b/spine-cpp/spine-cpp/src/spine/SliderData.cpp new file mode 100644 index 000000000..7dcaf2c53 --- /dev/null +++ b/spine-cpp/spine-cpp/src/spine/SliderData.cpp @@ -0,0 +1,106 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated April 5, 2025. Replaces all prior versions. + * + * Copyright (c) 2013-2025, 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(SliderData, ConstraintData) + +SliderData::SliderData(const String &name) : ConstraintDataGeneric(name), + _animation(NULL), + _additive(false), + _loop(false), + _bone(NULL), + _property(NULL), + _scale(0.0f), + _local(false) { +} + +Slider* SliderData::create(Skeleton& skeleton) { + return new (__FILE__, __LINE__) Slider(*this, skeleton); +} + +Animation* SliderData::getAnimation() { + return _animation; +} + +void SliderData::setAnimation(Animation* animation) { + _animation = animation; +} + +bool SliderData::getAdditive() { + return _additive; +} + +void SliderData::setAdditive(bool additive) { + _additive = additive; +} + +bool SliderData::getLoop() { + return _loop; +} + +void SliderData::setLoop(bool loop) { + _loop = loop; +} + +BoneData* SliderData::getBone() { + return _bone; +} + +void SliderData::setBone(BoneData* bone) { + _bone = bone; +} + +FromProperty* SliderData::getProperty() { + return _property; +} + +void SliderData::setProperty(FromProperty* property) { + _property = property; +} + +float SliderData::getScale() { + return _scale; +} + +void SliderData::setScale(float scale) { + _scale = scale; +} + +bool SliderData::getLocal() { + return _local; +} + +void SliderData::setLocal(bool local) { + _local = local; +} \ No newline at end of file