[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, ...
};
/// The base class for a CurveTimeline that sets one property.
class SP_API CurveTimeline1 : public CurveTimeline {
RTTI_DECL
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);
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);
/// Returns the interpolated value for the specified time.
float getCurveValue(float time);
float getRelativeValue(float time, float alpha, MixBlend blend, float current, float setup);

View File

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

View File

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

View File

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

View File

@ -29,13 +29,18 @@
#include <spine/Sequence.h>
#include <spine/Slot.h>
#include <spine/SlotPose.h>
#include <spine/Attachment.h>
#include <spine/RegionAttachment.h>
#include <spine/MeshAttachment.h>
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(),
_start(0),
_digits(0),
@ -46,8 +51,8 @@ Sequence::Sequence(int count) : _id(Sequence::getNextID()),
Sequence::~Sequence() {
}
Sequence *Sequence::copy() {
Sequence *copy = new (__FILE__, __LINE__) Sequence((int) _regions.size());
Sequence* Sequence::copy() {
Sequence* copy = new (__FILE__, __LINE__) Sequence((int)_regions.size());
for (size_t i = 0; i < _regions.size(); i++) {
copy->_regions[i] = _regions[i];
}
@ -57,7 +62,7 @@ Sequence *Sequence::copy() {
return copy;
}
void Sequence::apply(Slot *slot, Attachment *attachment) {
void Sequence::apply(SlotPose* slot, Attachment* attachment) {
int index = slot->getSequenceIndex();
if (index == -1) index = _setupIndex;
if (index >= (int) _regions.size()) index = (int) _regions.size() - 1;
@ -90,7 +95,6 @@ String Sequence::getPath(const String &basePath, int index) {
return result;
}
int Sequence::getNextID() {
static int _nextID = 0;
return _nextID;
int Sequence::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 mode = modeAndIndex & 0xf;
if (mode != SequenceMode::hold) {
if (mode != SequenceMode_hold) {
index += (int) (((time - before) / delay + 0.0001));
switch (mode) {
case SequenceMode::once:
case SequenceMode_once:
index = MathUtil::min(count - 1, index);
break;
case SequenceMode::loop:
case SequenceMode_loop:
index %= count;
break;
case SequenceMode::pingpong: {
case SequenceMode_pingpong: {
int n = (count << 1) - 2;
index = n == 0 ? 0 : index % n;
if (index >= count) index = n - index;
break;
}
case SequenceMode::onceReverse:
case SequenceMode_onceReverse:
index = MathUtil::max(count - 1 - index, 0);
break;
case SequenceMode::loopReverse:
case SequenceMode_loopReverse:
index = count - 1 - (index % count);
break;
case SequenceMode::pingpongReverse: {
case SequenceMode_pingpongReverse: {
int n = (count << 1) - 2;
index = n == 0 ? 0 : (index + count - 1) % n;
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);
String modeString = Json::getString(keyMap, "mode", "hold");
int index = Json::getInt(keyMap, "index", 0);
SequenceMode mode = SequenceMode::hold;
if (modeString == "once") mode = SequenceMode::once;
if (modeString == "loop") mode = SequenceMode::loop;
if (modeString == "pingpong") mode = SequenceMode::pingpong;
if (modeString == "onceReverse") mode = SequenceMode::onceReverse;
if (modeString == "loopReverse") mode = SequenceMode::loopReverse;
if (modeString == "pingpongReverse") mode = SequenceMode::pingpongReverse;
SequenceMode mode = SequenceMode_hold;
if (modeString == "once") mode = SequenceMode_once;
if (modeString == "loop") mode = SequenceMode_loop;
if (modeString == "pingpong") mode = SequenceMode_pingpong;
if (modeString == "onceReverse") mode = SequenceMode_onceReverse;
if (modeString == "loopReverse") mode = SequenceMode_loopReverse;
if (modeString == "pingpongReverse") mode = SequenceMode_pingpongReverse;
timeline->setFrame(frame, time, mode, index, delay);
lastDelay = delay;
}