[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-10 16:19:49 +02:00
parent 33db4555be
commit cf27cb438c
7 changed files with 78 additions and 41 deletions

View File

@ -64,16 +64,25 @@ namespace spine {
Vector<float> _curves; // type, x, y, ... Vector<float> _curves; // type, x, y, ...
}; };
/// The base class for a CurveTimeline that sets one property.
class SP_API CurveTimeline1 : public CurveTimeline { class SP_API CurveTimeline1 : public CurveTimeline {
RTTI_DECL RTTI_DECL
public: public:
/// @param frameCount The number of frames for this timeline.
/// @param bezierCount The maximum number of Bezier curves.
explicit CurveTimeline1(size_t frameCount, size_t bezierCount); explicit CurveTimeline1(size_t frameCount, size_t bezierCount);
virtual ~CurveTimeline1(); virtual ~CurveTimeline1();
size_t getFrameEntries();
/// Sets the time and value for the specified frame.
/// @param frame Between 0 and frameCount, inclusive.
/// @param time The frame time in seconds.
void setFrame(size_t frame, float time, float value); void setFrame(size_t frame, float time, float value);
/// Returns the interpolated value for the specified time.
float getCurveValue(float time); float getCurveValue(float time);
float getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup); float getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup);

View File

@ -33,16 +33,17 @@
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/SpineString.h> #include <spine/SpineString.h>
#include <spine/TextureRegion.h> #include <spine/TextureRegion.h>
#include <spine/RTTI.h>
namespace spine { namespace spine {
class Slot; class SlotPose;
class Attachment; class Attachment;
class SkeletonBinary; class SkeletonBinary;
class SkeletonJson; class SkeletonJson;
class SP_API Sequence : public SpineObject { class SP_API Sequence : public SpineObject {
RTTI_DECL
friend class SkeletonBinary; friend class SkeletonBinary;
friend class SkeletonJson; friend class SkeletonJson;
public: public:
@ -50,12 +51,13 @@ namespace spine {
~Sequence(); ~Sequence();
Sequence *copy(); Sequence* copy();
void apply(Slot *slot, Attachment *attachment); void apply(SlotPose* slot, Attachment* attachment);
String getPath(const String &basePath, int index); String getPath(const String &basePath, int index);
/// Returns a unique ID for this attachment.
int getId() { return _id; } int getId() { return _id; }
void setId(int id) { _id = id; } void setId(int id) { _id = id; }
@ -68,6 +70,7 @@ namespace spine {
void setDigits(int digits) { _digits = digits; } void setDigits(int digits) { _digits = digits; }
/// The index of the region to show for the setup pose.
int getSetupIndex() { return _setupIndex; } int getSetupIndex() { return _setupIndex; }
void setSetupIndex(int setupIndex) { _setupIndex = setupIndex; } void setSetupIndex(int setupIndex) { _setupIndex = setupIndex; }
@ -75,23 +78,24 @@ namespace spine {
Vector<TextureRegion *> &getRegions() { return _regions; } Vector<TextureRegion *> &getRegions() { return _regions; }
private: private:
static int _nextID;
int _id; int _id;
Vector<TextureRegion *> _regions; Vector<TextureRegion *> _regions;
int _start; int _start;
int _digits; int _digits;
int _setupIndex; int _setupIndex;
int getNextID(); static int nextID();
}; };
enum SequenceMode { enum SequenceMode {
hold = 0, SequenceMode_hold = 0,
once = 1, SequenceMode_once = 1,
loop = 2, SequenceMode_loop = 2,
pingpong = 3, SequenceMode_pingpong = 3,
onceReverse = 4, SequenceMode_onceReverse = 4,
loopReverse = 5, SequenceMode_loopReverse = 5,
pingpongReverse = 6 SequenceMode_pingpongReverse = 6
}; };
} }

View File

@ -117,6 +117,7 @@
#include <spine/SliderPose.h> #include <spine/SliderPose.h>
#include <spine/Slot.h> #include <spine/Slot.h>
#include <spine/SlotData.h> #include <spine/SlotData.h>
#include <spine/Sequence.h>
#include <spine/SlotPose.h> #include <spine/SlotPose.h>
#include <spine/SlotTimeline.h> #include <spine/SlotTimeline.h>
#include <spine/SpacingMode.h> #include <spine/SpacingMode.h>

View File

@ -104,6 +104,10 @@ CurveTimeline1::CurveTimeline1(size_t frameCount, size_t bezierCount) : CurveTim
CurveTimeline1::~CurveTimeline1() { CurveTimeline1::~CurveTimeline1() {
} }
size_t CurveTimeline1::getFrameEntries() {
return ENTRIES;
}
void CurveTimeline1::setFrame(size_t frame, float time, float value) { void CurveTimeline1::setFrame(size_t frame, float time, float value) {
frame <<= 1; frame <<= 1;
_frames[frame] = time; _frames[frame] = time;
@ -149,12 +153,11 @@ float CurveTimeline1::getRelativeValue(float time, float alpha, MixBlend blend,
return setup + value * alpha; return setup + value * alpha;
case MixBlend_First: case MixBlend_First:
case MixBlend_Replace: case MixBlend_Replace:
value += setup - current; return current + (value + setup - current) * alpha;
break;
case MixBlend_Add: case MixBlend_Add:
break;
}
return current + value * alpha; return current + value * alpha;
}
return current;
} }
float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup) { float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup) {
@ -169,8 +172,16 @@ float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend,
} }
} }
float value = getCurveValue(time); float value = getCurveValue(time);
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha; switch (blend) {
case MixBlend_Setup:
return setup + (value - setup) * alpha;
case MixBlend_First:
case MixBlend_Replace:
return current + (value - current) * alpha; return current + (value - current) * alpha;
case MixBlend_Add:
return current + value * alpha;
}
return current;
} }
float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup, float value) { float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend, float current, float setup, float value) {
@ -184,8 +195,16 @@ float CurveTimeline1::getAbsoluteValue(float time, float alpha, MixBlend blend,
return current; return current;
} }
} }
if (blend == MixBlend_Setup) return setup + (value - setup) * alpha; switch (blend) {
case MixBlend_Setup:
return setup + (value - setup) * alpha;
case MixBlend_First:
case MixBlend_Replace:
return current + (value - current) * alpha; return current + (value - current) * alpha;
case MixBlend_Add:
return current + value * alpha;
}
return current;
} }
float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, MixDirection direction, float current, float CurveTimeline1::getScaleValue(float time, float alpha, MixBlend blend, MixDirection direction, float current,

View File

@ -29,13 +29,18 @@
#include <spine/Sequence.h> #include <spine/Sequence.h>
#include <spine/Slot.h> #include <spine/Slot.h>
#include <spine/SlotPose.h>
#include <spine/Attachment.h> #include <spine/Attachment.h>
#include <spine/RegionAttachment.h> #include <spine/RegionAttachment.h>
#include <spine/MeshAttachment.h> #include <spine/MeshAttachment.h>
using namespace spine; using namespace spine;
Sequence::Sequence(int count) : _id(Sequence::getNextID()), RTTI_IMPL_NOPARENT(Sequence)
int Sequence::_nextID = 0;
Sequence::Sequence(int count) : _id(nextID()),
_regions(), _regions(),
_start(0), _start(0),
_digits(0), _digits(0),
@ -46,8 +51,8 @@ Sequence::Sequence(int count) : _id(Sequence::getNextID()),
Sequence::~Sequence() { Sequence::~Sequence() {
} }
Sequence *Sequence::copy() { Sequence* Sequence::copy() {
Sequence *copy = new (__FILE__, __LINE__) Sequence((int) _regions.size()); Sequence* copy = new (__FILE__, __LINE__) Sequence((int)_regions.size());
for (size_t i = 0; i < _regions.size(); i++) { for (size_t i = 0; i < _regions.size(); i++) {
copy->_regions[i] = _regions[i]; copy->_regions[i] = _regions[i];
} }
@ -57,7 +62,7 @@ Sequence *Sequence::copy() {
return copy; return copy;
} }
void Sequence::apply(Slot *slot, Attachment *attachment) { void Sequence::apply(SlotPose* slot, Attachment* attachment) {
int index = slot->getSequenceIndex(); int index = slot->getSequenceIndex();
if (index == -1) index = _setupIndex; if (index == -1) index = _setupIndex;
if (index >= (int) _regions.size()) index = (int) _regions.size() - 1; if (index >= (int) _regions.size()) index = (int) _regions.size() - 1;
@ -90,7 +95,6 @@ String Sequence::getPath(const String &basePath, int index) {
return result; return result;
} }
int Sequence::getNextID() { int Sequence::nextID() {
static int _nextID = 0; return _nextID++;
return _nextID;
} }

View File

@ -97,28 +97,28 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec
int index = modeAndIndex >> 4, count = (int) sequence->getRegions().size(); int index = modeAndIndex >> 4, count = (int) sequence->getRegions().size();
int mode = modeAndIndex & 0xf; int mode = modeAndIndex & 0xf;
if (mode != SequenceMode::hold) { if (mode != SequenceMode_hold) {
index += (int) (((time - before) / delay + 0.0001)); index += (int) (((time - before) / delay + 0.0001));
switch (mode) { switch (mode) {
case SequenceMode::once: case SequenceMode_once:
index = MathUtil::min(count - 1, index); index = MathUtil::min(count - 1, index);
break; break;
case SequenceMode::loop: case SequenceMode_loop:
index %= count; index %= count;
break; break;
case SequenceMode::pingpong: { case SequenceMode_pingpong: {
int n = (count << 1) - 2; int n = (count << 1) - 2;
index = n == 0 ? 0 : index % n; index = n == 0 ? 0 : index % n;
if (index >= count) index = n - index; if (index >= count) index = n - index;
break; break;
} }
case SequenceMode::onceReverse: case SequenceMode_onceReverse:
index = MathUtil::max(count - 1 - index, 0); index = MathUtil::max(count - 1 - index, 0);
break; break;
case SequenceMode::loopReverse: case SequenceMode_loopReverse:
index = count - 1 - (index % count); index = count - 1 - (index % count);
break; break;
case SequenceMode::pingpongReverse: { case SequenceMode_pingpongReverse: {
int n = (count << 1) - 2; int n = (count << 1) - 2;
index = n == 0 ? 0 : (index + count - 1) % n; index = n == 0 ? 0 : (index + count - 1) % n;
if (index >= count) index = n - index; if (index >= count) index = n - index;

View File

@ -1476,13 +1476,13 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) {
float time = Json::getFloat(keyMap, "time", 0); float time = Json::getFloat(keyMap, "time", 0);
String modeString = Json::getString(keyMap, "mode", "hold"); String modeString = Json::getString(keyMap, "mode", "hold");
int index = Json::getInt(keyMap, "index", 0); int index = Json::getInt(keyMap, "index", 0);
SequenceMode mode = SequenceMode::hold; SequenceMode mode = SequenceMode_hold;
if (modeString == "once") mode = SequenceMode::once; if (modeString == "once") mode = SequenceMode_once;
if (modeString == "loop") mode = SequenceMode::loop; if (modeString == "loop") mode = SequenceMode_loop;
if (modeString == "pingpong") mode = SequenceMode::pingpong; if (modeString == "pingpong") mode = SequenceMode_pingpong;
if (modeString == "onceReverse") mode = SequenceMode::onceReverse; if (modeString == "onceReverse") mode = SequenceMode_onceReverse;
if (modeString == "loopReverse") mode = SequenceMode::loopReverse; if (modeString == "loopReverse") mode = SequenceMode_loopReverse;
if (modeString == "pingpongReverse") mode = SequenceMode::pingpongReverse; if (modeString == "pingpongReverse") mode = SequenceMode_pingpongReverse;
timeline->setFrame(frame, time, mode, index, delay); timeline->setFrame(frame, time, mode, index, delay);
lastDelay = delay; lastDelay = delay;
} }