[c][cpp] Port of 4efd63f89cb995cbe4f30358d268a9d0eaf0c9be and 81baef0b5bb181376d15b0208697db8dabce095e

This commit is contained in:
Mario Zechner 2022-06-20 15:39:33 +02:00
parent 5b6c220bf6
commit ca75d3605e
2 changed files with 7 additions and 5 deletions

View File

@ -2042,6 +2042,7 @@ void _spSequenceTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float
if (self->attachment->type == SP_ATTACHMENT_REGION) sequence = ((spRegionAttachment *) self->attachment)->sequence;
if (self->attachment->type == SP_ATTACHMENT_MESH) sequence = ((spMeshAttachment *) self->attachment)->sequence;
if (!sequence) return;
index = modeAndIndex >> 4;
count = sequence->regions->size;
mode = modeAndIndex & 0xf;
@ -2056,7 +2057,7 @@ void _spSequenceTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float
break;
case SP_SEQUENCE_MODE_PINGPONG: {
int n = (count << 1) - 2;
index %= n;
index = n == 0 ? 0 : index % n;
if (index >= count) index = n - index;
break;
}
@ -2068,7 +2069,7 @@ void _spSequenceTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float
break;
case SP_SEQUENCE_MODE_PINGPONGREVERSE: {
int n = (count << 1) - 2;
index = (index + count - 1) % n;
index = n == 0 ? 0 : (index + count - 1) % n;
if (index >= count) index = n - index;
}
}

View File

@ -89,6 +89,7 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec
Sequence *sequence = NULL;
if (_attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequence = ((RegionAttachment *) _attachment)->getSequence();
if (_attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequence = ((MeshAttachment *) _attachment)->getSequence();
if (!sequence) return;
int index = modeAndIndex >> 4, count = (int) sequence->getRegions().size();
int mode = modeAndIndex & 0xf;
if (mode != SequenceMode::hold) {
@ -102,7 +103,7 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec
break;
case SequenceMode::pingpong: {
int n = (count << 1) - 2;
index %= n;
index = n == 0 ? 0 : index % n;
if (index >= count) index = n - index;
break;
}
@ -114,10 +115,10 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec
break;
case SequenceMode::pingpongReverse: {
int n = (count << 1) - 2;
index = (index + count - 1) % n;
index = n == 0 ? 0 : (index + count - 1) % n;
if (index >= count) index = n - index;
}
}
}
slot->setSequenceIndex(index);
}
}