Okay, SkeletonBinary is done.

This commit is contained in:
Stephen Gowen 2017-12-03 16:16:02 -05:00
parent 8f28ae1c2d
commit 2b2b34db00
22 changed files with 540 additions and 391 deletions

View File

@ -262,10 +262,12 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con
unsigned char timelineType = readByte(input); unsigned char timelineType = readByte(input);
int frameCount = readVarint(input, 1); int frameCount = readVarint(input, 1);
switch (timelineType) { switch (timelineType) {
case SLOT_ATTACHMENT: { case SLOT_ATTACHMENT:
{
spAttachmentTimeline* timeline = spAttachmentTimeline_create(frameCount); spAttachmentTimeline* timeline = spAttachmentTimeline_create(frameCount);
timeline->slotIndex = slotIndex; timeline->slotIndex = slotIndex;
for (frameIndex = 0; frameIndex < frameCount; ++frameIndex) { for (frameIndex = 0; frameIndex < frameCount; ++frameIndex)
{
float time = readFloat(input); float time = readFloat(input);
const char* attachmentName = readString(input); const char* attachmentName = readString(input);
/* TODO Avoid copying of attachmentName inside */ /* TODO Avoid copying of attachmentName inside */

View File

@ -68,6 +68,8 @@ namespace Spine
public: public:
Animation(std::string name, Vector<Timeline*>& timelines, float duration); Animation(std::string name, Vector<Timeline*>& timelines, float duration);
~Animation();
/// Applies all the animation's timelines to the specified skeleton. /// Applies all the animation's timelines to the specified skeleton.
/// See also Timeline::apply(Skeleton&, float, float, Vector, float, MixPose, MixDirection) /// See also Timeline::apply(Skeleton&, float, float, Vector, float, MixPose, MixDirection)
void apply(Skeleton& skeleton, float lastTime, float time, bool loop, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction); void apply(Skeleton& skeleton, float lastTime, float time, bool loop, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction);

View File

@ -46,6 +46,9 @@ namespace Spine
class AttachmentTimeline : public Timeline class AttachmentTimeline : public Timeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class ColorTimeline : public CurveTimeline class ColorTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -39,6 +39,9 @@ namespace Spine
class DeformTimeline : public CurveTimeline class DeformTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class DrawOrderTimeline : public Timeline class DrawOrderTimeline : public Timeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -40,6 +40,8 @@ namespace Spine
/// Stores the current pose values for an Event. /// Stores the current pose values for an Event.
class Event class Event
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState; friend class AnimationState;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class EventTimeline : public Timeline class EventTimeline : public Timeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class IkConstraintTimeline : public CurveTimeline class IkConstraintTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class PathConstraintMixTimeline : public CurveTimeline class PathConstraintMixTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class PathConstraintPositionTimeline : public CurveTimeline class PathConstraintPositionTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class PathConstraintSpacingTimeline : public PathConstraintPositionTimeline class PathConstraintSpacingTimeline : public PathConstraintPositionTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,8 @@ namespace Spine
{ {
class RotateTimeline : public CurveTimeline class RotateTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState; friend class AnimationState;
RTTI_DECL; RTTI_DECL;

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class ScaleTimeline : public TranslateTimeline class ScaleTimeline : public TranslateTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class ShearTimeline : public TranslateTimeline class ShearTimeline : public TranslateTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -46,6 +46,7 @@ namespace Spine
class Attachment; class Attachment;
class VertexAttachment; class VertexAttachment;
class Animation; class Animation;
class CurveTimeline;
class SkeletonBinary class SkeletonBinary
{ {
@ -128,6 +129,8 @@ namespace Spine
Vector<short> readShortArray(DataInput *input); Vector<short> readShortArray(DataInput *input);
Animation* readAnimation(const char* name, DataInput* input, SkeletonData *skeletonData); Animation* readAnimation(const char* name, DataInput* input, SkeletonData *skeletonData);
void readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline);
}; };
} }

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class TransformConstraintTimeline : public CurveTimeline class TransformConstraintTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -40,6 +40,9 @@ namespace Spine
{ {
class TranslateTimeline : public CurveTimeline class TranslateTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -37,6 +37,9 @@ namespace Spine
{ {
class TwoColorTimeline : public CurveTimeline class TwoColorTimeline : public CurveTimeline
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
RTTI_DECL; RTTI_DECL;
public: public:

View File

@ -42,6 +42,8 @@ namespace Spine
/// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices. /// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices.
class VertexAttachment : public Attachment class VertexAttachment : public Attachment
{ {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class DeformTimeline; friend class DeformTimeline;
RTTI_DECL; RTTI_DECL;

View File

@ -34,6 +34,8 @@
#include <spine/Skeleton.h> #include <spine/Skeleton.h>
#include <spine/Event.h> #include <spine/Event.h>
#include <spine/ContainerUtil.h>
#include <assert.h> #include <assert.h>
#include <math.h> /* fmod */ #include <math.h> /* fmod */
@ -47,6 +49,11 @@ namespace Spine
assert(_name.length() > 0); assert(_name.length() > 0);
} }
Animation::~Animation()
{
ContainerUtil::cleanUpVectorOfPointers(_timelines);
}
void Animation::apply(Skeleton& skeleton, float lastTime, float time, bool loop, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) void Animation::apply(Skeleton& skeleton, float lastTime, float time, bool loop, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{ {
if (loop && _duration != 0) if (loop && _duration != 0)

View File

@ -57,6 +57,24 @@
#include <spine/PointAttachment.h> #include <spine/PointAttachment.h>
#include <spine/ClippingAttachment.h> #include <spine/ClippingAttachment.h>
#include <spine/EventData.h> #include <spine/EventData.h>
#include <spine/AttachmentTimeline.h>
#include <spine/MathUtil.h>
#include <spine/ColorTimeline.h>
#include <spine/TwoColorTimeline.h>
#include <spine/RotateTimeline.h>
#include <spine/TranslateTimeline.h>
#include <spine/ScaleTimeline.h>
#include <spine/ShearTimeline.h>
#include <spine/IkConstraintTimeline.h>
#include <spine/TransformConstraintTimeline.h>
#include <spine/PathConstraintPositionTimeline.h>
#include <spine/PathConstraintSpacingTimeline.h>
#include <spine/PathConstraintPositionTimeline.h>
#include <spine/PathConstraintMixTimeline.h>
#include <spine/DeformTimeline.h>
#include <spine/DrawOrderTimeline.h>
#include <spine/EventTimeline.h>
#include <spine/Event.h>
namespace Spine namespace Spine
{ {
@ -351,7 +369,7 @@ namespace Spine
} }
/* Linked meshes. */ /* Linked meshes. */
for (int i = 0, n = static_cast<int>(_linkedMeshes.size()); i < n; i++) for (int i = 0, n = static_cast<int>(_linkedMeshes.size()); i < n; ++i)
{ {
LinkedMesh* linkedMesh = _linkedMeshes[i]; LinkedMesh* linkedMesh = _linkedMeshes[i];
Skin* skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin); Skin* skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin);
@ -386,7 +404,9 @@ namespace Spine
FREE(name); FREE(name);
eventData->_intValue = readVarint(input, 0); eventData->_intValue = readVarint(input, 0);
eventData->_floatValue = readFloat(input); eventData->_floatValue = readFloat(input);
eventData->_stringValue = readString(input); const char* eventData_stringValue = readString(input);
eventData->_stringValue = std::string(eventData_stringValue);
FREE(eventData_stringValue);
skeletonData->_events[i] = eventData; skeletonData->_events[i] = eventData;
} }
@ -695,6 +715,9 @@ namespace Spine
FREE(name); FREE(name);
} }
FREE(skinName);
FREE(parent);
return mesh; return mesh;
} }
case AttachmentType_Path: case AttachmentType_Path:
@ -847,395 +870,459 @@ namespace Spine
Animation* SkeletonBinary::readAnimation(const char* name, DataInput* input, SkeletonData *skeletonData) Animation* SkeletonBinary::readAnimation(const char* name, DataInput* input, SkeletonData *skeletonData)
{ {
// var timelines = new ExposedList<Timeline>(); Vector<Timeline*> timelines;
// float scale = Scale; float scale = _scale;
// float duration = 0; float duration = 0;
//
// // Slot timelines. // Slot timelines.
// for (int i = 0, n = ReadVarint(input, true); i < n; i++) for (int i = 0, n = readVarint(input, true); i < n; ++i)
// { {
// int slotIndex = ReadVarint(input, true); int slotIndex = readVarint(input, true);
// for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++) for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii)
// { {
// int timelineType = input.ReadByte(); unsigned char timelineType = readByte(input);
// int frameCount = ReadVarint(input, true); int frameCount = readVarint(input, true);
// switch (timelineType) switch (timelineType)
// { {
// case SLOT_ATTACHMENT: case SLOT_ATTACHMENT:
// { {
// AttachmentTimeline timeline = new AttachmentTimeline(frameCount); AttachmentTimeline* timeline = NEW(AttachmentTimeline);
// timeline.slotIndex = slotIndex; new(timeline) AttachmentTimeline(frameCount);
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) timeline->_slotIndex = slotIndex;
// { for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// timeline.SetFrame(frameIndex, ReadFloat(input), ReadString(input)); {
// } const char* attachmentName = readString(input);
// timelines.Add(timeline); timeline->setFrame(frameIndex, readFloat(input), std::string(attachmentName));
// duration = Math.Max(duration, timeline.frames[frameCount - 1]); FREE(attachmentName);
// break; }
// } timelines.push_back(timeline);
// case SLOT_COLOR: duration = MAX(duration, timeline->_frames[frameCount - 1]);
// { break;
// ColorTimeline timeline = new ColorTimeline(frameCount); }
// timeline.slotIndex = slotIndex; case SLOT_COLOR:
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)\ {
// { ColorTimeline* timeline = NEW(ColorTimeline);
// float time = ReadFloat(input); new(timeline) ColorTimeline(frameCount);
// int color = ReadInt(input); timeline->_slotIndex = slotIndex;
// float r = ((color & 0xff000000) >> 24) / 255f; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// float g = ((color & 0x00ff0000) >> 16) / 255f; {
// float b = ((color & 0x0000ff00) >> 8) / 255f; float time = readFloat(input);
// float a = ((color & 0x000000ff)) / 255f; int color = readInt(input);
// timeline.SetFrame(frameIndex, time, r, g, b, a); float r = ((color & 0xff000000) >> 24) / 255.0f;
// if (frameIndex < frameCount - 1) float g = ((color & 0x00ff0000) >> 16) / 255.0f;
// { float b = ((color & 0x0000ff00) >> 8) / 255.0f;
// ReadCurve(input, frameIndex, timeline); float a = ((color & 0x000000ff)) / 255.0f;
// } timeline->setFrame(frameIndex, time, r, g, b, a);
// } if (frameIndex < frameCount - 1)
// timelines.Add(timeline); {
// duration = Math.Max(duration, timeline.frames[(timeline.FrameCount - 1) * ColorTimeline.ENTRIES]); readCurve(input, frameIndex, timeline);
// break; }
// } }
// case SLOT_TWO_COLOR: timelines.push_back(timeline);
// { duration = MAX(duration, timeline->_frames[(frameCount - 1) * ColorTimeline::ENTRIES]);
// TwoColorTimeline timeline = new TwoColorTimeline(frameCount); break;
// timeline.slotIndex = slotIndex; }
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) case SLOT_TWO_COLOR:
// { {
// float time = ReadFloat(input); TwoColorTimeline* timeline = NEW(TwoColorTimeline);
// int color = ReadInt(input); new(timeline) TwoColorTimeline(frameCount);
// float r = ((color & 0xff000000) >> 24) / 255f; timeline->_slotIndex = slotIndex;
// float g = ((color & 0x00ff0000) >> 16) / 255f; for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// float b = ((color & 0x0000ff00) >> 8) / 255f; {
// float a = ((color & 0x000000ff)) / 255f; float time = readFloat(input);
// int color2 = ReadInt(input); // 0x00rrggbb int color = readInt(input);
// float r2 = ((color2 & 0x00ff0000) >> 16) / 255f; float r = ((color & 0xff000000) >> 24) / 255.0f;
// float g2 = ((color2 & 0x0000ff00) >> 8) / 255f; float g = ((color & 0x00ff0000) >> 16) / 255.0f;
// float b2 = ((color2 & 0x000000ff)) / 255f; float b = ((color & 0x0000ff00) >> 8) / 255.0f;
// float a = ((color & 0x000000ff)) / 255.0f;
// timeline.SetFrame(frameIndex, time, r, g, b, a, r2, g2, b2); int color2 = readInt(input); // 0x00rrggbb
// if (frameIndex < frameCount - 1) float r2 = ((color2 & 0x00ff0000) >> 16) / 255.0f;
// { float g2 = ((color2 & 0x0000ff00) >> 8) / 255.0f;
// ReadCurve(input, frameIndex, timeline); float b2 = ((color2 & 0x000000ff)) / 255.0f;
// }
// } timeline->setFrame(frameIndex, time, r, g, b, a, r2, g2, b2);
// timelines.Add(timeline); if (frameIndex < frameCount - 1)
// duration = Math.Max(duration, timeline.frames[(timeline.FrameCount - 1) * TwoColorTimeline.ENTRIES]); {
// break; readCurve(input, frameIndex, timeline);
// } }
// } }
// } timelines.push_back(timeline);
// } duration = MAX(duration, timeline->_frames[(frameCount - 1) * TwoColorTimeline::ENTRIES]);
// break;
// // Bone timelines. }
// for (int i = 0, n = ReadVarint(input, true); i < n; i++) }
// { }
// int boneIndex = ReadVarint(input, true); }
// for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++)
// { // Bone timelines.
// int timelineType = input.ReadByte(); for (int i = 0, n = readVarint(input, true); i < n; ++i)
// int frameCount = ReadVarint(input, true); {
// switch (timelineType) int boneIndex = readVarint(input, true);
// { for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii)
// case BONE_ROTATE: {
// { unsigned char timelineType = readByte(input);
// RotateTimeline timeline = new RotateTimeline(frameCount); int frameCount = readVarint(input, true);
// timeline.boneIndex = boneIndex; switch (timelineType)
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
// { case BONE_ROTATE:
// timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input)); {
// if (frameIndex < frameCount - 1) RotateTimeline* timeline = NEW(RotateTimeline);
// { new(timeline) RotateTimeline(frameCount);
// ReadCurve(input, frameIndex, timeline); timeline->_boneIndex = boneIndex;
// } for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// } {
// timelines.Add(timeline); timeline->setFrame(frameIndex, readFloat(input), readFloat(input));
// duration = Math.Max(duration, timeline.frames[(frameCount - 1) * RotateTimeline.ENTRIES]); if (frameIndex < frameCount - 1)
// break; {
// } readCurve(input, frameIndex, timeline);
// case BONE_TRANSLATE: }
// case BONE_SCALE: }
// case BONE_SHEAR: timelines.push_back(timeline);
// { duration = MAX(duration, timeline->_frames[(frameCount - 1) * RotateTimeline::ENTRIES]);
// TranslateTimeline timeline; break;
// float timelineScale = 1; }
// if (timelineType == BONE_SCALE) case BONE_TRANSLATE:
// { case BONE_SCALE:
// timeline = new ScaleTimeline(frameCount); case BONE_SHEAR:
// } {
// else if (timelineType == BONE_SHEAR) TranslateTimeline* timeline;
// { float timelineScale = 1;
// timeline = new ShearTimeline(frameCount); if (timelineType == BONE_SCALE)
// } {
// else timeline = NEW(ScaleTimeline);
// { new(timeline) ScaleTimeline(frameCount);
// timeline = new TranslateTimeline(frameCount); }
// timelineScale = scale; else if (timelineType == BONE_SHEAR)
// } {
// timeline.boneIndex = boneIndex; timeline = NEW(ShearTimeline);
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) new(timeline) ShearTimeline(frameCount);
// { }
// timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input) * timelineScale, ReadFloat(input) else
// * timelineScale); {
// if (frameIndex < frameCount - 1) timeline = NEW(TranslateTimeline);
// { new(timeline) TranslateTimeline(frameCount);
// ReadCurve(input, frameIndex, timeline); timelineScale = scale;
// } }
// } timeline->_boneIndex = boneIndex;
// timelines.Add(timeline); for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// duration = Math.Max(duration, timeline.frames[(frameCount - 1) * TranslateTimeline.ENTRIES]); {
// break; timeline->setFrame(frameIndex, readFloat(input), readFloat(input) * timelineScale, readFloat(input) * timelineScale);
// } if (frameIndex < frameCount - 1)
// } {
// } readCurve(input, frameIndex, timeline);
// } }
// }
// // IK timelines. timelines.push_back(timeline);
// for (int i = 0, n = ReadVarint(input, true); i < n; i++) duration = MAX(duration, timeline->_frames[(frameCount - 1) * TranslateTimeline::ENTRIES]);
// { break;
// int index = ReadVarint(input, true); }
// int frameCount = ReadVarint(input, true); }
// IkConstraintTimeline timeline = new IkConstraintTimeline(frameCount); }
// timeline.ikConstraintIndex = index; }
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
// { // IK timelines.
// timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input), ReadSByte(input)); for (int i = 0, n = readVarint(input, true); i < n; ++i)
// if (frameIndex < frameCount - 1) {
// { int index = readVarint(input, true);
// ReadCurve(input, frameIndex, timeline); int frameCount = readVarint(input, true);
// } IkConstraintTimeline* timeline = NEW(IkConstraintTimeline);
// } new(timeline) IkConstraintTimeline(frameCount);
// timelines.Add(timeline); timeline->_ikConstraintIndex = index;
// duration = Math.Max(duration, timeline.frames[(frameCount - 1) * IkConstraintTimeline.ENTRIES]); for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// } {
// timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readSByte(input));
// // Transform constraint timelines. if (frameIndex < frameCount - 1)
// for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
// { readCurve(input, frameIndex, timeline);
// int index = ReadVarint(input, true); }
// int frameCount = ReadVarint(input, true); }
// TransformConstraintTimeline timeline = new TransformConstraintTimeline(frameCount); timelines.push_back(timeline);
// timeline.transformConstraintIndex = index; duration = MAX(duration, timeline->_frames[(frameCount - 1) * IkConstraintTimeline::ENTRIES]);
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) }
// {
// timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input), ReadFloat(input), ReadFloat(input), ReadFloat(input)); // Transform constraint timelines.
// if (frameIndex < frameCount - 1) for (int i = 0, n = readVarint(input, true); i < n; ++i)
// { {
// ReadCurve(input, frameIndex, timeline); int index = readVarint(input, true);
// } int frameCount = readVarint(input, true);
// } TransformConstraintTimeline* timeline = NEW(TransformConstraintTimeline);
// timelines.Add(timeline); new(timeline) TransformConstraintTimeline(frameCount);
// duration = Math.Max(duration, timeline.frames[(frameCount - 1) * TransformConstraintTimeline.ENTRIES]); timeline->_transformConstraintIndex = index;
// } for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// {
// // Path constraint timelines. timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readFloat(input), readFloat(input), readFloat(input));
// for (int i = 0, n = ReadVarint(input, true); i < n; i++) if (frameIndex < frameCount - 1)
// { {
// int index = ReadVarint(input, true); readCurve(input, frameIndex, timeline);
// PathConstraintData data = skeletonData.pathConstraints.Items[index]; }
// for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++) }
// { timelines.push_back(timeline);
// int timelineType = ReadSByte(input); duration = MAX(duration, timeline->_frames[(frameCount - 1) * TransformConstraintTimeline::ENTRIES]);
// int frameCount = ReadVarint(input, true); }
// switch(timelineType)
// { // Path constraint timelines.
// case PATH_POSITION: for (int i = 0, n = readVarint(input, true); i < n; ++i)
// case PATH_SPACING: {
// { int index = readVarint(input, true);
// PathConstraintPositionTimeline timeline; PathConstraintData* data = skeletonData->_pathConstraints[index];
// float timelineScale = 1; for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii)
// if (timelineType == PATH_SPACING) {
// { int timelineType = readSByte(input);
// timeline = new PathConstraintSpacingTimeline(frameCount); int frameCount = readVarint(input, true);
// if (data.spacingMode == SpacingMode.Length || data.spacingMode == SpacingMode.Fixed) switch(timelineType)
// { {
// timelineScale = scale; case PATH_POSITION:
// } case PATH_SPACING:
// } {
// else PathConstraintPositionTimeline* timeline;
// { float timelineScale = 1;
// timeline = new PathConstraintPositionTimeline(frameCount); if (timelineType == PATH_SPACING)
// if (data.positionMode == PositionMode.Fixed) {
// { timeline = NEW(PathConstraintSpacingTimeline);
// timelineScale = scale; new(timeline) PathConstraintSpacingTimeline(frameCount);
// }
// } if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed)
// timeline.pathConstraintIndex = index; {
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) timelineScale = scale;
// { }
// timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input) * timelineScale); }
// if (frameIndex < frameCount - 1) else
// { {
// ReadCurve(input, frameIndex, timeline); timeline = NEW(PathConstraintPositionTimeline);
// } new(timeline) PathConstraintPositionTimeline(frameCount);
// }
// timelines.Add(timeline); if (data->_positionMode == PositionMode_Fixed)
// duration = Math.Max(duration, timeline.frames[(frameCount - 1) * PathConstraintPositionTimeline.ENTRIES]); {
// break; timelineScale = scale;
// } }
// case PATH_MIX: }
// { timeline->_pathConstraintIndex = index;
// PathConstraintMixTimeline timeline = new PathConstraintMixTimeline(frameCount); for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// timeline.pathConstraintIndex = index; {
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) timeline->setFrame(frameIndex, readFloat(input), readFloat(input) * timelineScale);
// { if (frameIndex < frameCount - 1)
// timeline.SetFrame(frameIndex, ReadFloat(input), ReadFloat(input), ReadFloat(input)); {
// if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
// { }
// ReadCurve(input, frameIndex, timeline); }
// } timelines.push_back(timeline);
// } duration = MAX(duration, timeline->_frames[(frameCount - 1) * PathConstraintPositionTimeline::ENTRIES]);
// timelines.Add(timeline); break;
// duration = Math.Max(duration, timeline.frames[(frameCount - 1) * PathConstraintMixTimeline.ENTRIES]); }
// break; case PATH_MIX:
// } {
// } PathConstraintMixTimeline* timeline = NEW(PathConstraintMixTimeline);
// } new(timeline) PathConstraintMixTimeline(frameCount);
// }
// timeline->_pathConstraintIndex = index;
// // Deform timelines. for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
// { timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readFloat(input));
// Skin skin = skeletonData.skins.Items[ReadVarint(input, true)]; if (frameIndex < frameCount - 1)
// for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++) {
// { readCurve(input, frameIndex, timeline);
// int slotIndex = ReadVarint(input, true); }
// for (int iii = 0, nnn = ReadVarint(input, true); iii < nnn; iii++) }
// { timelines.push_back(timeline);
// VertexAttachment attachment = (VertexAttachment)skin.GetAttachment(slotIndex, ReadString(input)); duration = MAX(duration, timeline->_frames[(frameCount - 1) * PathConstraintMixTimeline::ENTRIES]);
// bool weighted = attachment.bones != null; break;
// float[] vertices = attachment.vertices; }
// int deformLength = weighted ? vertices.Length / 3 * 2 : vertices.Length; }
// }
// int frameCount = ReadVarint(input, true); }
// DeformTimeline timeline = new DeformTimeline(frameCount);
// timeline.slotIndex = slotIndex; // Deform timelines.
// timeline.attachment = attachment; for (int i = 0, n = readVarint(input, true); i < n; ++i)
// {
// for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) Skin* skin = skeletonData->_skins[readVarint(input, true)];
// { for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii)
// float time = ReadFloat(input); {
// float[] deform; int slotIndex = readVarint(input, true);
// int end = ReadVarint(input, true); for (int iii = 0, nnn = readVarint(input, true); iii < nnn; iii++)
// if (end == 0) {
// { const char* vertexAttachmentName = readString(input);
// deform = weighted ? new float[deformLength] : vertices; VertexAttachment* attachment = static_cast<VertexAttachment*>(skin->getAttachment(slotIndex, std::string(vertexAttachmentName)));
// } FREE(vertexAttachmentName);
// else bool weighted = attachment->_bones.size() > 0;
// { Vector<float>& vertices = attachment->_vertices;
// deform = new float[deformLength]; int deformLength = weighted ? static_cast<int>(vertices.size()) / 3 * 2 : static_cast<int>(vertices.size());
// int start = ReadVarint(input, true);
// end += start; int frameCount = readVarint(input, true);
// if (scale == 1)
// { DeformTimeline* timeline = NEW(DeformTimeline);
// for (int v = start; v < end; v++) new(timeline) DeformTimeline(frameCount);
// {
// deform[v] = ReadFloat(input); timeline->_slotIndex = slotIndex;
// } timeline->_attachment = attachment;
// }
// else for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex)
// { {
// for (int v = start; v < end; v++) float time = readFloat(input);
// { Vector<float> deform;
// deform[v] = ReadFloat(input) * scale; int end = readVarint(input, true);
// } if (end == 0)
// } {
// if (weighted)
// if (!weighted) {
// { deform.reserve(deformLength);
// for (int v = 0, vn = deform.Length; v < vn; v++) }
// { else
// deform[v] += vertices[v]; {
// } deform = vertices;
// } }
// } }
// else
// timeline.SetFrame(frameIndex, time, deform); {
// if (frameIndex < frameCount - 1) deform.reserve(deformLength);
// { int start = readVarint(input, true);
// ReadCurve(input, frameIndex, timeline); end += start;
// } if (scale == 1)
// } {
// for (int v = start; v < end; ++v)
// timelines.Add(timeline); {
// duration = Math.Max(duration, timeline.frames[frameCount - 1]); deform[v] = readFloat(input);
// } }
// } }
// } else
// {
// // Draw order timeline. for (int v = start; v < end; ++v)
// int drawOrderCount = ReadVarint(input, true); {
// if (drawOrderCount > 0) deform[v] = readFloat(input) * scale;
// { }
// DrawOrderTimeline timeline = new DrawOrderTimeline(drawOrderCount); }
// int slotCount = skeletonData.slots.Count;
// for (int i = 0; i < drawOrderCount; i++) if (!weighted)
// { {
// float time = ReadFloat(input); for (int v = 0, vn = static_cast<int>(deform.size()); v < vn; ++v)
// int offsetCount = ReadVarint(input, true); {
// int[] drawOrder = new int[slotCount]; deform[v] += vertices[v];
// for (int ii = slotCount - 1; ii >= 0; ii--) }
// { }
// drawOrder[ii] = -1; }
// }
// int[] unchanged = new int[slotCount - offsetCount]; timeline->setFrame(frameIndex, time, deform);
// int originalIndex = 0, unchangedIndex = 0; if (frameIndex < frameCount - 1)
// for (int ii = 0; ii < offsetCount; ii++) {
// { readCurve(input, frameIndex, timeline);
// int slotIndex = ReadVarint(input, true); }
// // Collect unchanged items. }
// while (originalIndex != slotIndex)
// { timelines.push_back(timeline);
// unchanged[unchangedIndex++] = originalIndex++; duration = MAX(duration, timeline->_frames[frameCount - 1]);
// } }
// // Set changed items. }
// drawOrder[originalIndex + ReadVarint(input, true)] = originalIndex++; }
// }
// // Draw order timeline.
// // Collect remaining unchanged items. int drawOrderCount = readVarint(input, true);
// while (originalIndex < slotCount) if (drawOrderCount > 0)
// { {
// unchanged[unchangedIndex++] = originalIndex++; DrawOrderTimeline* timeline = NEW(DrawOrderTimeline);
// } new(timeline) DrawOrderTimeline(drawOrderCount);
//
// // Fill in unchanged items. int slotCount = static_cast<int>(skeletonData->_slots.size());
// for (int ii = slotCount - 1; ii >= 0; ii--) for (int i = 0; i < drawOrderCount; ++i)
// { {
// if (drawOrder[ii] == -1) float time = readFloat(input);
// { int offsetCount = readVarint(input, true);
// drawOrder[ii] = unchanged[--unchangedIndex];
// } Vector<int> drawOrder;
// } drawOrder.reserve(slotCount);
// timeline.SetFrame(i, time, drawOrder); for (int ii = slotCount - 1; ii >= 0; --ii)
// } {
// timelines.Add(timeline); drawOrder[ii] = -1;
// duration = Math.Max(duration, timeline.frames[drawOrderCount - 1]); }
// }
// Vector<int> unchanged;
// // Event timeline. unchanged.reserve(slotCount - offsetCount);
// int eventCount = ReadVarint(input, true); int originalIndex = 0, unchangedIndex = 0;
// if (eventCount > 0) for (int ii = 0; ii < offsetCount; ++ii)
// { {
// EventTimeline timeline = new EventTimeline(eventCount); int slotIndex = readVarint(input, true);
// for (int i = 0; i < eventCount; i++) // Collect unchanged items.
// { while (originalIndex != slotIndex)
// float time = ReadFloat(input); {
// EventData eventData = skeletonData.events.Items[ReadVarint(input, true)]; unchanged[unchangedIndex++] = originalIndex++;
// Event e = new Event(time, eventData); }
// e.Int = ReadVarint(input, false); // Set changed items.
// e.Float = ReadFloat(input); int index = originalIndex;
// e.String = ReadBoolean(input) ? ReadString(input) : eventData.String; drawOrder[index + readVarint(input, true)] = originalIndex++;
// timeline.SetFrame(i, e); }
// }
// // Collect remaining unchanged items.
// timelines.Add(timeline); while (originalIndex < slotCount)
// duration = Math.Max(duration, timeline.frames[eventCount - 1]); {
// } unchanged[unchangedIndex++] = originalIndex++;
// }
// timelines.TrimExcess();
// // Fill in unchanged items.
for (int ii = slotCount - 1; ii >= 0; --ii)
{
if (drawOrder[ii] == -1)
{
drawOrder[ii] = unchanged[--unchangedIndex];
}
}
timeline->setFrame(i, time, drawOrder);
}
timelines.push_back(timeline);
duration = MAX(duration, timeline->_frames[drawOrderCount - 1]);
}
// Event timeline.
int eventCount = readVarint(input, true);
if (eventCount > 0)
{
EventTimeline* timeline = NEW(EventTimeline);
new(timeline) EventTimeline(eventCount);
for (int i = 0; i < eventCount; ++i)
{
float time = readFloat(input);
EventData* eventData = skeletonData->_events[readVarint(input, true)];
Event* event = NEW(Event);
new(event) Event(time, *eventData);
event->_intValue = readVarint(input, false);
event->_floatValue = readFloat(input);
bool freeString = readBoolean(input);
const char* event_stringValue = freeString ? readString(input) : eventData->_stringValue.c_str();
event->_stringValue = std::string(event_stringValue);
if (freeString)
{
FREE(event_stringValue);
}
timeline->setFrame(i, event);
}
timelines.push_back(timeline);
duration = MAX(duration, timeline->_frames[eventCount - 1]);
}
Animation* ret = NEW(Animation); Animation* ret = NEW(Animation);
// new (ret) Animation(std::string(name), timelines, duration); new (ret) Animation(std::string(name), timelines, duration);
return ret; return ret;
} }
void SkeletonBinary::readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline)
{
switch (readByte(input))
{
case CURVE_STEPPED:
{
timeline->setStepped(frameIndex);
break;
}
case CURVE_BEZIER:
{
float cx1 = readFloat(input);
float cy1 = readFloat(input);
float cx2 = readFloat(input);
float cy2 = readFloat(input);
timeline->setCurve(frameIndex, cx1, cy1, cx2, cy2);
break;
}
}
}
} }