Got Unit Tests working, but I don't have the fixtures quite configured correctly.

This commit is contained in:
Stephen Gowen 2017-12-07 13:54:41 -05:00
parent 1e6d8b793a
commit ec7ed94525
29 changed files with 156 additions and 36 deletions

View File

@ -105,7 +105,7 @@ namespace Spine
/* Build an object from the text. */
static const char* parseObject(Json *item, const char* value);
static int strcasecmp(const char* s1, const char* s2);
static int json_strcasecmp(const char* s1, const char* s2);
};
}

View File

@ -71,7 +71,7 @@ namespace Spine
friend class TwoColorTimeline;
public:
Skeleton(SkeletonData& data);
Skeleton(SkeletonData& skeletonData);
~Skeleton();

View File

@ -41,18 +41,18 @@ namespace Spine
public:
Vector<int>& triangulate(Vector<float>& vertices);
Vector<Vector<float>* > decompose(Vector<float>& vertices, Vector<int>& triangles);
Vector< Vector<float>* > decompose(Vector<float>& vertices, Vector<int>& triangles);
private:
Vector<Vector<float>* > _convexPolygons;
Vector<Vector<int>* > _convexPolygonsIndices;
Vector< Vector<float>* > _convexPolygons;
Vector< Vector<int>* > _convexPolygonsIndices;
Vector<int> _indices;
Vector<bool> _isConcaveArray;
Vector<int> _triangles;
Pool<Vector<float> > _polygonPool;
Pool<Vector<int> > _polygonIndicesPool;
Pool< Vector<float> > _polygonPool;
Pool< Vector<int> > _polygonIndicesPool;
static bool isConcave(int index, int vertexCount, Vector<float>& vertices, Vector<int>& indices);

View File

@ -192,6 +192,11 @@ namespace Spine
}
}
void setSize(size_t inValue)
{
_size = inValue;
}
T* begin()
{
return &_buffer[0];
@ -243,7 +248,10 @@ namespace Spine
void deallocate(T* buffer)
{
FREE(buffer);
if (_buffer)
{
FREE(buffer);
}
}
void construct(T* buffer, const T& val)

View File

@ -161,8 +161,10 @@ namespace Spine
Vector<Timeline*>& timelines = _animation->_timelines;
int timelinesCount = static_cast<int>(timelines.size());
_timelineData.reserve(timelinesCount);
_timelineData.setSize(timelinesCount);
_timelineDipMix.clear();
_timelineDipMix.reserve(timelinesCount);
_timelineDipMix.setSize(timelinesCount);
// outer:
for (int i = 0; i < timelinesCount; ++i)
@ -491,6 +493,7 @@ namespace Spine
if (firstFrame)
{
current._timelinesRotation.reserve(timelines.size() << 1);
current._timelinesRotation.setSize(timelines.size() << 1);
}
Vector<float>& timelinesRotation = current._timelinesRotation;
@ -906,6 +909,7 @@ namespace Spine
{
// from.timelinesRotation.setSize
from->_timelinesRotation.reserve(timelines.size() << 1);
from->_timelinesRotation.setSize(timelines.size() << 1);
}
Vector<float>& timelinesRotation = from->_timelinesRotation;

View File

@ -119,7 +119,7 @@ namespace Spine
int dirLength = (int)strlen(dir);
int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\';
AtlasPage *page = 0;
AtlasPage *page = NULL;
Str str;
Str tuple[4];
@ -140,7 +140,7 @@ namespace Spine
}
strcpy(path + dirLength + needsSlash, name);
AtlasPage* page = NEW(AtlasPage);
page = NEW(AtlasPage);
new (page) AtlasPage(std::string(name));
FREE(name);
@ -228,6 +228,7 @@ namespace Spine
{
/* split is optional */
region->splits.reserve(4);
region->splits.setSize(4);
region->splits[0] = toInt(tuple);
region->splits[1] = toInt(tuple + 1);
region->splits[2] = toInt(tuple + 2);
@ -240,6 +241,7 @@ namespace Spine
{
/* pad is optional, but only present with splits */
region->pads.reserve(4);
region->pads.setSize(4);
region->pads[0] = toInt(tuple);
region->pads[1] = toInt(tuple + 1);
region->pads[2] = toInt(tuple + 2);

View File

@ -46,6 +46,13 @@ namespace Spine
{
_frames.reserve(frameCount);
_attachmentNames.reserve(frameCount);
_frames.setSize(frameCount);
for (int i = 0; i < frameCount; ++i)
{
_attachmentNames.push_back(std::string(""));
}
}
void AttachmentTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -48,7 +48,7 @@ namespace Spine
_shearY(0),
_transformMode(TransformMode_Normal)
{
assert(index < 0);
assert(index >= 0);
assert(_name.length() > 0);
}

View File

@ -56,6 +56,7 @@ namespace Spine
ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void ColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -46,6 +46,7 @@ namespace Spine
assert(frameCount > 0);
_curves.reserve((frameCount - 1) * BEZIER_SIZE);
_curves.setSize((frameCount - 1) * BEZIER_SIZE);
}
int CurveTimeline::getFrameCount()

View File

@ -48,6 +48,14 @@ namespace Spine
{
_frames.reserve(frameCount);
_frameVertices.reserve(frameCount);
_frames.setSize(frameCount);
for (int i = 0; i < frameCount; ++i)
{
Vector<float> vec;
_frameVertices.push_back(vec);
}
}
void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
@ -90,6 +98,7 @@ namespace Spine
// Ensure size and preemptively set count.
vertices.reserve(vertexCount);
vertices.setSize(vertexCount);
if (vertexAttachment->_bones.size() == 0)
{
@ -117,6 +126,7 @@ namespace Spine
// Ensure size and preemptively set count.
vertices.reserve(vertexCount);
vertices.setSize(vertexCount);
if (time >= _frames[_frames.size() - 1])
{

View File

@ -46,6 +46,14 @@ namespace Spine
{
_frames.reserve(frameCount);
_drawOrders.reserve(frameCount);
_frames.setSize(frameCount);
for (int i = 0; i < frameCount; ++i)
{
Vector<int> vec;
_drawOrders.push_back(vec);
}
}
void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -48,6 +48,9 @@ namespace Spine
{
_frames.reserve(frameCount);
_events.reserve(frameCount);
_frames.setSize(frameCount);
_events.setSize(frameCount);
}
EventTimeline::~EventTimeline()

View File

@ -54,6 +54,7 @@ namespace Spine
IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void IkConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -67,7 +67,7 @@ namespace Spine
Json* Json::getItem(Json *object, const char* string)
{
Json *c = object->_child;
while (c && strcasecmp(c->_name, string))
while (c && json_strcasecmp(c->_name, string))
{
c = c->_next;
}
@ -616,7 +616,7 @@ namespace Spine
return NULL; /* malformed. */
}
int Json::strcasecmp(const char* s1, const char* s2)
int Json::json_strcasecmp(const char* s1, const char* s2)
{
/* TODO we may be able to elide these NULL checks if we can prove
* the graph and input (only callsite is Json_getItem) should not have NULLs

View File

@ -67,9 +67,9 @@ namespace Spine
if (_uvs.size() != _regionUVs.size())
{
_uvs.reserve(_regionUVs.size());
_uvs.setSize(_regionUVs.size());
}
if (_regionRotate)
{
for (size_t i = 0, n = _uvs.size(); i < n; i += 2)

View File

@ -69,6 +69,7 @@ namespace Spine
}
_segments.reserve(10);
_segments.setSize(10);
}
void PathConstraint::apply()
@ -103,12 +104,14 @@ namespace Spine
size_t boneCount = _bones.size();
int spacesCount = static_cast<int>(tangents ? boneCount : boneCount + 1);
_spaces.reserve(spacesCount);
_spaces.setSize(spacesCount);
float spacing = _spacing;
if (scale || lengthSpacing)
{
if (scale)
{
_lengths.reserve(boneCount);
_lengths.setSize(boneCount);
}
for (int i = 0, n = spacesCount - 1; i < n;)
@ -309,6 +312,7 @@ namespace Spine
Slot& target = *_target;
float position = _position;
_positions.reserve(spacesCount * 3 + 2);
_positions.setSize(spacesCount * 3 + 2);
bool closed = path.isClosed();
int verticesLength = path.getWorldVerticesLength();
int curveCount = verticesLength / 6;
@ -334,6 +338,7 @@ namespace Spine
}
_world.reserve(8);
_world.setSize(8);
for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3)
{
float space = _spaces[i];
@ -420,6 +425,7 @@ namespace Spine
{
verticesLength += 2;
_world.reserve(verticesLength);
_world.setSize(verticesLength);
path.computeWorldVertices(target, 2, verticesLength - 4, _world, 0);
path.computeWorldVertices(target, 0, 2, _world, verticesLength - 4);
_world[verticesLength - 2] = _world[0];
@ -430,11 +436,13 @@ namespace Spine
curveCount--;
verticesLength -= 4;
_world.reserve(verticesLength);
_world.setSize(verticesLength);
path.computeWorldVertices(target, 2, verticesLength, _world, 0);
}
// Curve lengths.
_curves.reserve(curveCount);
_curves.setSize(curveCount);
pathLength = 0;
float x1 = _world[0], y1 = _world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy;

View File

@ -54,6 +54,7 @@ namespace Spine
PathConstraintMixTimeline::PathConstraintMixTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void PathConstraintMixTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -52,6 +52,7 @@ namespace Spine
PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void PathConstraintPositionTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -76,6 +76,9 @@ namespace Spine
{
_offset.reserve(NUM_UVS);
_uvs.reserve(NUM_UVS);
_offset.setSize(NUM_UVS);
_uvs.setSize(NUM_UVS);
}
void RegionAttachment::updateOffset()

View File

@ -45,6 +45,7 @@ namespace Spine
RotateTimeline::RotateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0)
{
_frames.reserve(frameCount << 1);
_frames.setSize(frameCount << 1);
}
void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -54,8 +54,8 @@
namespace Spine
{
Skeleton::Skeleton(SkeletonData& data) :
_data(data),
Skeleton::Skeleton(SkeletonData& skeletonData) :
_data(skeletonData),
_skin(NULL),
_r(1),
_g(1),
@ -492,6 +492,7 @@ namespace Spine
if (outVertexBuffer.size() < 8)
{
outVertexBuffer.reserve(8);
outVertexBuffer.setSize(8);
}
regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0);
}
@ -503,6 +504,7 @@ namespace Spine
if (outVertexBuffer.size() < verticesLength)
{
outVertexBuffer.reserve(verticesLength);
outVertexBuffer.setSize(verticesLength);
}
mesh->computeWorldVertices(*slot, 0, verticesLength, outVertexBuffer, 0);

View File

@ -162,6 +162,7 @@ namespace Spine
/* Bones. */
int bonesCount = readVarint(input, 1);
skeletonData->_bones.reserve(bonesCount);
skeletonData->_bones.setSize(bonesCount);
for (i = 0; i < bonesCount; ++i)
{
BoneData* data;
@ -215,6 +216,7 @@ namespace Spine
/* Slots. */
int slotsCount = readVarint(input, 1);
skeletonData->_slots.reserve(slotsCount);
skeletonData->_slots.setSize(slotsCount);
for (i = 0; i < slotsCount; ++i)
{
int r, g, b, a;
@ -247,6 +249,7 @@ namespace Spine
/* IK constraints. */
int ikConstraintsCount = readVarint(input, 1);
skeletonData->_ikConstraints.reserve(ikConstraintsCount);
skeletonData->_ikConstraints.setSize(ikConstraintsCount);
for (i = 0; i < ikConstraintsCount; ++i)
{
const char* name = readString(input);
@ -259,6 +262,7 @@ namespace Spine
FREE(name);
int bonesCount = readVarint(input, 1);
data->_bones.reserve(bonesCount);
data->_bones.setSize(bonesCount);
for (ii = 0; ii < bonesCount; ++ii)
{
data->_bones[ii] = skeletonData->_bones[readVarint(input, 1)];
@ -273,6 +277,7 @@ namespace Spine
/* Transform constraints. */
int transformConstraintsCount = readVarint(input, 1);
skeletonData->_transformConstraints.reserve(transformConstraintsCount);
skeletonData->_transformConstraints.setSize(transformConstraintsCount);
for (i = 0; i < transformConstraintsCount; ++i)
{
const char* name = readString(input);
@ -284,6 +289,7 @@ namespace Spine
FREE(name);
int bonesCount = readVarint(input, 1);
data->_bones.reserve(bonesCount);
data->_bones.setSize(bonesCount);
for (ii = 0; ii < bonesCount; ++ii)
{
data->_bones[ii] = skeletonData->_bones[readVarint(input, 1)];
@ -308,6 +314,7 @@ namespace Spine
/* Path constraints */
int pathConstraintsCount = readVarint(input, 1);
skeletonData->_pathConstraints.reserve(pathConstraintsCount);
skeletonData->_pathConstraints.setSize(pathConstraintsCount);
for (i = 0; i < pathConstraintsCount; ++i)
{
const char* name = readString(input);
@ -320,6 +327,7 @@ namespace Spine
int bonesCount = readVarint(input, 1);
data->_bones.reserve(bonesCount);
data->_bones.setSize(bonesCount);
for (ii = 0; ii < bonesCount; ++ii)
{
data->_bones[ii] = skeletonData->_bones[readVarint(input, 1)];
@ -356,6 +364,7 @@ namespace Spine
}
skeletonData->_skins.reserve(skinsCount);
skeletonData->_skins.setSize(skinsCount);
if (skeletonData->_defaultSkin)
{
@ -398,6 +407,7 @@ namespace Spine
/* Events. */
int eventsCount = readVarint(input, 1);
skeletonData->_events.reserve(eventsCount);
skeletonData->_events.setSize(eventsCount);
for (i = 0; i < eventsCount; ++i)
{
const char* name = readString(input);
@ -415,6 +425,7 @@ namespace Spine
/* Animations. */
int animationsCount = readVarint(input, 1);
skeletonData->_animations.reserve(animationsCount);
skeletonData->_animations.setSize(animationsCount);
for (i = 0; i < animationsCount; ++i)
{
const char* name = readString(input);
@ -732,6 +743,7 @@ namespace Spine
readVertices(input, static_cast<VertexAttachment*>(path), vertexCount);
int lengthsLength = vertexCount / 3;
path->_lengths.reserve(lengthsLength);
path->_lengths.setSize(lengthsLength);
for (i = 0; i < lengthsLength; ++i)
{
path->_lengths[i] = readFloat(input) * _scale;
@ -833,6 +845,7 @@ namespace Spine
{
Vector<float> array;
array.reserve(n);
array.setSize(n);
int i;
if (scale == 1)
@ -859,6 +872,7 @@ namespace Spine
Vector<short> array;
array.reserve(n);
array.setSize(n);
int i;
for (i = 0; i < n; ++i)
@ -1191,6 +1205,10 @@ namespace Spine
if (weighted)
{
deform.reserve(deformLength);
for (int i = 0; i < deformLength; ++i)
{
deform.push_back(0);
}
}
else
{

View File

@ -64,7 +64,7 @@ namespace Spine
ContainerUtil::cleanUpVectorOfPointers(_slots);
ContainerUtil::cleanUpVectorOfPointers(_skins);
delete _defaultSkin;
_defaultSkin = NULL;
ContainerUtil::cleanUpVectorOfPointers(_events);
ContainerUtil::cleanUpVectorOfPointers(_animations);

View File

@ -156,6 +156,8 @@ namespace Spine
/* Bones. */
bones = Json::getItem(root, "bones");
skeletonData->_bones.reserve(bones->_size);
skeletonData->_bones.setSize(bones->_size);
int bonesCount = 0;
for (boneMap = bones->_child, i = 0; boneMap; boneMap = boneMap->_next, ++i)
{
BoneData* data;
@ -175,7 +177,7 @@ namespace Spine
}
data = NEW(BoneData);
new (data) BoneData(static_cast<int>(skeletonData->_bones.size()), Json::getString(boneMap, "name", 0), parent);
new (data) BoneData(bonesCount, Json::getString(boneMap, "name", 0), parent);
data->_length = Json::getFloat(boneMap, "length", 0) * _scale;
data->_x = Json::getFloat(boneMap, "x", 0) * _scale;
@ -209,6 +211,7 @@ namespace Spine
}
skeletonData->_bones[i] = data;
bonesCount++;
}
/* Slots. */
@ -217,6 +220,7 @@ namespace Spine
{
Json *slotMap;
skeletonData->_slots.reserve(slots->_size);
skeletonData->_slots.setSize(slots->_size);
for (slotMap = slots->_child, i = 0; slotMap; slotMap = slotMap->_next, ++i)
{
SlotData* data;
@ -288,6 +292,7 @@ namespace Spine
{
Json *constraintMap;
skeletonData->_ikConstraints.reserve(ik->_size);
skeletonData->_ikConstraints.setSize(ik->_size);
for (constraintMap = ik->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i)
{
const char* targetName;
@ -299,6 +304,7 @@ namespace Spine
boneMap = Json::getItem(constraintMap, "bones");
data->_bones.reserve(boneMap->_size);
data->_bones.setSize(boneMap->_size);
for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii)
{
data->_bones[ii] = skeletonData->findBone(boneMap->_valueString);
@ -332,6 +338,7 @@ namespace Spine
{
Json *constraintMap;
skeletonData->_transformConstraints.reserve(transform->_size);
skeletonData->_transformConstraints.setSize(transform->_size);
for (constraintMap = transform->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i)
{
const char* name;
@ -343,6 +350,7 @@ namespace Spine
boneMap = Json::getItem(constraintMap, "bones");
data->_bones.reserve(boneMap->_size);
data->_bones.setSize(boneMap->_size);
for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii)
{
data->_bones[ii] = skeletonData->findBone(boneMap->_valueString);
@ -387,6 +395,7 @@ namespace Spine
{
Json *constraintMap;
skeletonData->_pathConstraints.reserve(path->_size);
skeletonData->_pathConstraints.setSize(path->_size);
for (constraintMap = path->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i)
{
const char* name;
@ -399,6 +408,7 @@ namespace Spine
boneMap = Json::getItem(constraintMap, "bones");
data->_bones.reserve(boneMap->_size);
data->_bones.setSize(boneMap->_size);
for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii)
{
data->_bones[ii] = skeletonData->findBone(boneMap->_valueString);
@ -481,6 +491,7 @@ namespace Spine
{
Json *skinMap;
skeletonData->_skins.reserve(skins->_size);
skeletonData->_skins.setSize(skins->_size);
int skinsIndex = 0;
for (skinMap = skins->_child, i = 0; skinMap; skinMap = skinMap->_next, ++i)
{
@ -605,6 +616,7 @@ namespace Spine
int verticesLength;
entry = Json::getItem(attachmentMap, "triangles");
mesh->_triangles.reserve(entry->_size);
mesh->_triangles.setSize(entry->_size);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
{
mesh->_triangles[ii] = (unsigned short)entry->_valueInt;
@ -613,6 +625,7 @@ namespace Spine
entry = Json::getItem(attachmentMap, "uvs");
verticesLength = entry->_size;
mesh->_regionUVs.reserve(verticesLength);
mesh->_regionUVs.setSize(verticesLength);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
{
mesh->_regionUVs[ii] = entry->_valueFloat;
@ -628,6 +641,7 @@ namespace Spine
if (entry)
{
mesh->_edges.reserve(entry->_size);
mesh->_edges.setSize(entry->_size);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
{
mesh->_edges[ii] = entry->_valueInt;
@ -666,6 +680,7 @@ namespace Spine
readVertices(attachmentMap, pathAttatchment, vertexCount << 1);
pathAttatchment->_lengths.reserve(vertexCount / 3);
pathAttatchment->_lengths.setSize(vertexCount / 3);
curves = Json::getItem(attachmentMap, "lengths");
for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii)
@ -739,6 +754,7 @@ namespace Spine
{
Json *eventMap;
skeletonData->_events.reserve(events->_size);
skeletonData->_events.setSize(events->_size);
for (eventMap = events->_child, i = 0; eventMap; eventMap = eventMap->_next, ++i)
{
EventData* eventData = NEW(EventData);
@ -746,7 +762,8 @@ namespace Spine
eventData->_intValue = Json::getInt(eventMap, "int", 0);
eventData->_floatValue = Json::getFloat(eventMap, "float", 0);
eventData->_stringValue = Json::getString(eventMap, "string", 0);
const char* stringValue = Json::getString(eventMap, "string", 0);
eventData->_stringValue = std::string(stringValue ? stringValue : "");
skeletonData->_events[i] = eventData;
}
}
@ -757,6 +774,7 @@ namespace Spine
{
Json *animationMap;
skeletonData->_animations.reserve(animations->_size);
skeletonData->_animations.setSize(animations->_size);
int animationsIndex = 0;
for (animationMap = animations->_child; animationMap; animationMap = animationMap->_next)
{
@ -906,11 +924,11 @@ namespace Spine
for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex)
{
Json* name = Json::getItem(valueMap, "name");
std::string attachmentName;
attachmentName = name->_type == Json::JSON_NULL ? "" : std::string(name->_valueString);
std::string attachmentName = name->_type == Json::JSON_NULL ? std::string("") : std::string(name->_valueString);
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), attachmentName);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[timelineMap->_size - 1]);
}
@ -927,7 +945,8 @@ namespace Spine
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), toColor(s, 2), toColor(s, 3));
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * ColorTimeline::ENTRIES]);
}
@ -946,7 +965,8 @@ namespace Spine
toColor(s, 3), toColor(ds, 0), toColor(ds, 1), toColor(ds, 2));
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * TwoColorTimeline::ENTRIES]);
}
else
@ -985,7 +1005,8 @@ namespace Spine
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "angle", 0));
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * RotateTimeline::ENTRIES]);
}
else
@ -1020,7 +1041,8 @@ namespace Spine
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * TranslateTimeline::ENTRIES]);
}
else
@ -1053,7 +1075,8 @@ namespace Spine
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "mix", 1), Json::getInt(valueMap, "bendPositive", 1) ? 1 : -1);
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(constraintMap->_size - 1) * IkConstraintTimeline::ENTRIES]);
}
@ -1077,7 +1100,8 @@ namespace Spine
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "rotateMix", 1), Json::getFloat(valueMap, "translateMix", 1), Json::getFloat(valueMap, "scaleMix", 1), Json::getFloat(valueMap, "shearMix", 1));
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(constraintMap->_size - 1) * TransformConstraintTimeline::ENTRIES]);
}
@ -1138,7 +1162,8 @@ namespace Spine
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, timelineName, 0) * timelineScale);
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintPositionTimeline::ENTRIES]);
}
else if (strcmp(timelineName, "mix") == 0)
@ -1151,7 +1176,8 @@ namespace Spine
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "rotateMix", 1), Json::getFloat(valueMap, "translateMix", 1));
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintMixTimeline::ENTRIES]);
}
}
@ -1186,6 +1212,10 @@ namespace Spine
deformLength = weighted ? static_cast<int>(vertices.size()) / 3 * 2 : static_cast<int>(vertices.size());
Vector<float> tempDeform;
tempDeform.reserve(deformLength);
for (int i = 0; i < deformLength; ++i)
{
tempDeform.push_back(0);
}
timeline = NEW(DeformTimeline);
new (timeline) DeformTimeline(timelineMap->_size);
@ -1240,7 +1270,8 @@ namespace Spine
readCurve(valueMap, timeline, frameIndex);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[timelineMap->_size - 1]);
}
}
@ -1262,9 +1293,11 @@ namespace Spine
Json* offsetMap;
Vector<int> unchanged;
unchanged.reserve(skeletonData->_slots.size() - offsets->_size);
unchanged.setSize(skeletonData->_slots.size() - offsets->_size);
int originalIndex = 0, unchangedIndex = 0;
drawOrder2.reserve(skeletonData->_slots.size());
drawOrder2.setSize(skeletonData->_slots.size());
for (ii = static_cast<int>(skeletonData->_slots.size()) - 1; ii >= 0; --ii)
{
drawOrder2[ii] = -1;
@ -1304,7 +1337,8 @@ namespace Spine
}
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), drawOrder2);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[drawOrder->_size - 1]);
}
@ -1332,7 +1366,8 @@ namespace Spine
event->_stringValue = Json::getString(valueMap, "string", eventData->_stringValue.c_str());
timeline->setFrame(frameIndex, event);
}
timelines[timelinesCount++] = timeline;
timelines.push_back(timeline);
timelinesCount++;
duration = MAX(duration, timeline->_frames[events->_size - 1]);
}
@ -1353,6 +1388,7 @@ namespace Spine
entry = Json::getItem(attachmentMap, "vertices");
entrySize = entry->_size;
vertices.reserve(entrySize);
vertices.setSize(entrySize);
for (entry = entry->_child, i = 0; entry; entry = entry->_next, ++i)
{
vertices[i] = entry->_valueFloat;

View File

@ -58,6 +58,7 @@ namespace Spine
TransformConstraintTimeline::TransformConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _transformConstraintIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void TransformConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -54,6 +54,7 @@ namespace Spine
TranslateTimeline::TranslateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void TranslateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)

View File

@ -41,6 +41,7 @@ namespace Spine
Vector<int>& indices = _indices;
indices.clear();
indices.reserve(vertexCount);
indices.setSize(vertexCount);
for (int i = 0; i < vertexCount; ++i)
{
indices[i] = i;
@ -48,6 +49,7 @@ namespace Spine
Vector<bool>& isConcaveArray = _isConcaveArray;
isConcaveArray.reserve(vertexCount);
isConcaveArray.setSize(vertexCount);
for (int i = 0, n = vertexCount; i < n; ++i)
{
isConcaveArray[i] = isConcave(i, vertexCount, vertices, indices);
@ -137,16 +139,16 @@ namespace Spine
return triangles;
}
Vector<Vector<float>* > Triangulator::decompose(Vector<float>& vertices, Vector<int>& triangles)
Vector< Vector<float>* > Triangulator::decompose(Vector<float>& vertices, Vector<int>& triangles)
{
Vector<Vector<float>* >&convexPolygons = _convexPolygons;
Vector< Vector<float>* >&convexPolygons = _convexPolygons;
for (size_t i = 0, n = convexPolygons.size(); i < n; ++i)
{
_polygonPool.free(convexPolygons[i]);
}
convexPolygons.clear();
Vector<Vector<int>* > convexPolygonsIndices = _convexPolygonsIndices;
Vector< Vector<int>* > convexPolygonsIndices = _convexPolygonsIndices;
for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i)
{
_polygonIndicesPool.free(convexPolygonsIndices[i]);

View File

@ -62,6 +62,7 @@ namespace Spine
TwoColorTimeline::TwoColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0)
{
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void TwoColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)