mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
[cpp] 4.3 porting WIP
This commit is contained in:
parent
d8ef5b5f0b
commit
4876f0d00b
71
spine-cpp/spine-cpp/include/spine/Slider.h
Normal file
71
spine-cpp/spine-cpp/include/spine/Slider.h
Normal file
@ -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 <spine/Constraint.h>
|
||||||
|
#include <spine/SliderData.h>
|
||||||
|
#include <spine/SliderPose.h>
|
||||||
|
|
||||||
|
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<Slider, SliderData, SliderPose> {
|
||||||
|
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 */
|
||||||
92
spine-cpp/spine-cpp/include/spine/SliderData.h
Normal file
92
spine-cpp/spine-cpp/include/spine/SliderData.h
Normal file
@ -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 <spine/ConstraintData.h>
|
||||||
|
#include <spine/SliderPose.h>
|
||||||
|
#include <spine/SpineString.h>
|
||||||
|
|
||||||
|
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<Slider, SliderPose> {
|
||||||
|
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 */
|
||||||
@ -115,6 +115,8 @@
|
|||||||
#include <spine/SkeletonJson.h>
|
#include <spine/SkeletonJson.h>
|
||||||
#include <spine/SkeletonRenderer.h>
|
#include <spine/SkeletonRenderer.h>
|
||||||
#include <spine/Skin.h>
|
#include <spine/Skin.h>
|
||||||
|
#include <spine/Slider.h>
|
||||||
|
#include <spine/SliderData.h>
|
||||||
#include <spine/SliderPose.h>
|
#include <spine/SliderPose.h>
|
||||||
#include <spine/Slot.h>
|
#include <spine/Slot.h>
|
||||||
#include <spine/SlotData.h>
|
#include <spine/SlotData.h>
|
||||||
|
|||||||
112
spine-cpp/spine-cpp/src/spine/Slider.cpp
Normal file
112
spine-cpp/spine-cpp/src/spine/Slider.cpp
Normal file
@ -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 <spine/Slider.h>
|
||||||
|
#include <spine/Skeleton.h>
|
||||||
|
#include <spine/Bone.h>
|
||||||
|
#include <spine/BoneData.h>
|
||||||
|
#include <spine/Animation.h>
|
||||||
|
#include <spine/Timeline.h>
|
||||||
|
#include <spine/SlotTimeline.h>
|
||||||
|
#include <spine/ConstraintTimeline.h>
|
||||||
|
#include <spine/TransformConstraintData.h>
|
||||||
|
#include <spine/MathUtil.h>
|
||||||
|
|
||||||
|
using namespace spine;
|
||||||
|
|
||||||
|
RTTI_IMPL(Slider, Update)
|
||||||
|
|
||||||
|
float Slider::_offsets[6];
|
||||||
|
|
||||||
|
Slider::Slider(SliderData& data, Skeleton& skeleton) : Constraint<Slider, SliderData, SliderPose>(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<Bone*>& bones = skeleton.getBones();
|
||||||
|
// Vector<size_t>& 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<Bone*>& bones = skeleton.getBones();
|
||||||
|
// Vector<size_t>& 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;
|
||||||
|
}
|
||||||
106
spine-cpp/spine-cpp/src/spine/SliderData.cpp
Normal file
106
spine-cpp/spine-cpp/src/spine/SliderData.cpp
Normal file
@ -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 <spine/SliderData.h>
|
||||||
|
#include <spine/Slider.h>
|
||||||
|
#include <spine/Skeleton.h>
|
||||||
|
|
||||||
|
using namespace spine;
|
||||||
|
|
||||||
|
RTTI_IMPL(SliderData, ConstraintData)
|
||||||
|
|
||||||
|
SliderData::SliderData(const String &name) : ConstraintDataGeneric<Slider, SliderPose>(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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user