mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[cpp] Removed Vector.begin/end, fixed up vector assignments.
This commit is contained in:
parent
3cf3312180
commit
6d243eca48
@ -49,8 +49,8 @@ namespace Spine {
|
||||
static T* findWithName(Vector<T*>& items, const String& name) {
|
||||
assert(name.length() > 0);
|
||||
|
||||
for (T** i = items.begin(); i != items.end(); ++i) {
|
||||
T* item = (*i);
|
||||
for (size_t i = 0; i < items.size(); ++i) {
|
||||
T* item = items[i];
|
||||
if (item->getName() == name) {
|
||||
return item;
|
||||
}
|
||||
@ -81,8 +81,8 @@ namespace Spine {
|
||||
static T* findWithDataName(Vector<T*>& items, const String& name) {
|
||||
assert(name.length() > 0);
|
||||
|
||||
for (T** i = items.begin(); i != items.end(); ++i) {
|
||||
T* item = (*i);
|
||||
for (size_t i = 0; i < items.size(); ++i) {
|
||||
T* item = items[i];
|
||||
if (item->getData().getName() == name) {
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ namespace Spine {
|
||||
|
||||
T* obtain() {
|
||||
if (_objects.size() > 0) {
|
||||
T** object = _objects.end();
|
||||
T** object = &_objects[_objects.size() - 1];
|
||||
T* ret = *object;
|
||||
_objects.removeAt(_objects.size() - 1);
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ namespace Spine {
|
||||
|
||||
/** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
|
||||
* area, false is returned. The clipping area must duplicate the first vertex at the end of the vertices list. */
|
||||
bool clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector<float>& clippingArea, Vector<float>& output);
|
||||
bool clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector<float>* clippingArea, Vector<float>* output);
|
||||
|
||||
static void makeClockwise(Vector<float>& polygon);
|
||||
};
|
||||
|
||||
@ -157,14 +157,6 @@ namespace Spine {
|
||||
return _buffer[inIndex];
|
||||
}
|
||||
|
||||
T* begin() {
|
||||
return &_buffer[0];
|
||||
}
|
||||
|
||||
T* end() {
|
||||
return &_buffer[_size];
|
||||
}
|
||||
|
||||
friend bool operator==(Vector<T>& lhs, Vector<T>& rhs) {
|
||||
if (lhs.size() != rhs.size()) {
|
||||
return false;
|
||||
@ -188,7 +180,7 @@ namespace Spine {
|
||||
size_t _capacity;
|
||||
T* _buffer;
|
||||
|
||||
T* allocate(size_t n) {
|
||||
inline T* allocate(size_t n) {
|
||||
assert(n > 0);
|
||||
|
||||
T* ptr = SpineExtension::alloc<T>(n, __FILE__, __LINE__);
|
||||
@ -198,20 +190,17 @@ namespace Spine {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void deallocate(T* buffer) {
|
||||
inline void deallocate(T* buffer) {
|
||||
if (_buffer) {
|
||||
SpineExtension::free(buffer, __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
void construct(T* buffer, const T& val) {
|
||||
/// This is a placement new operator
|
||||
/// which basically means we are contructing a new object
|
||||
/// using pre-allocated memory
|
||||
inline void construct(T* buffer, const T& val) {
|
||||
new (buffer) T(val);
|
||||
}
|
||||
|
||||
void destroy(T* buffer) {
|
||||
inline void destroy(T* buffer) {
|
||||
buffer->~T();
|
||||
}
|
||||
};
|
||||
|
||||
@ -248,9 +248,8 @@ namespace Spine {
|
||||
_bendDirection(data.getBendDirection()),
|
||||
_target(skeleton.findBone(data.getTarget()->getName())) {
|
||||
_bones.ensureCapacity(_data.getBones().size());
|
||||
for (BoneData** i = _data.getBones().begin(); i != _data.getBones().end(); ++i) {
|
||||
BoneData* boneData = (*i);
|
||||
|
||||
for (size_t i = 0; i < _data.getBones().size(); i++) {
|
||||
BoneData* boneData = _data.getBones()[i];
|
||||
_bones.add(skeleton.findBone(boneData->getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,9 +59,8 @@ namespace Spine {
|
||||
_rotateMix(data.getRotateMix()),
|
||||
_translateMix(data.getTranslateMix()) {
|
||||
_bones.ensureCapacity(_data.getBones().size());
|
||||
for (BoneData** i = _data.getBones().begin(); i != _data.getBones().end(); ++i) {
|
||||
BoneData* boneData = (*i);
|
||||
|
||||
for (size_t i = 0; i < _data.getBones().size(); i++) {
|
||||
BoneData* boneData = _data.getBones()[i];
|
||||
_bones.add(skeleton.findBone(boneData->getName()));
|
||||
}
|
||||
|
||||
|
||||
@ -63,8 +63,8 @@ namespace Spine {
|
||||
_x(0),
|
||||
_y(0) {
|
||||
_bones.ensureCapacity(_data->getBones().size());
|
||||
for (BoneData** i = _data->getBones().begin(); i != _data->getBones().end(); ++i) {
|
||||
BoneData* data = (*i);
|
||||
for (size_t i = 0; i < _data->getBones().size(); ++i) {
|
||||
BoneData* data = _data->getBones()[i];
|
||||
|
||||
Bone* bone;
|
||||
if (data->getParent() == NULL) {
|
||||
@ -81,8 +81,8 @@ namespace Spine {
|
||||
|
||||
_slots.ensureCapacity(_data->getSlots().size());
|
||||
_drawOrder.ensureCapacity(_data->getSlots().size());
|
||||
for (SlotData** i = _data->getSlots().begin(); i != _data->getSlots().end(); ++i) {
|
||||
SlotData* data = (*i);
|
||||
for (size_t i = 0; i < _data->getSlots().size(); ++i) {
|
||||
SlotData* data = _data->getSlots()[i];
|
||||
|
||||
Bone* bone = _bones[data->getBoneData().getIndex()];
|
||||
Slot* slot = new (__FILE__, __LINE__) Slot(*data, *bone);
|
||||
@ -92,8 +92,8 @@ namespace Spine {
|
||||
}
|
||||
|
||||
_ikConstraints.ensureCapacity(_data->getIkConstraints().size());
|
||||
for (IkConstraintData** i = _data->getIkConstraints().begin(); i != _data->getIkConstraints().end(); ++i) {
|
||||
IkConstraintData* data = (*i);
|
||||
for (size_t i = 0; i < _data->getIkConstraints().size(); ++i) {
|
||||
IkConstraintData* data = _data->getIkConstraints()[i];
|
||||
|
||||
IkConstraint* constraint = new (__FILE__, __LINE__) IkConstraint(*data, *this);
|
||||
|
||||
@ -101,8 +101,8 @@ namespace Spine {
|
||||
}
|
||||
|
||||
_transformConstraints.ensureCapacity(_data->getTransformConstraints().size());
|
||||
for (TransformConstraintData** i = _data->getTransformConstraints().begin(); i != _data->getTransformConstraints().end(); ++i) {
|
||||
TransformConstraintData* data = (*i);
|
||||
for (size_t i = 0; i < _data->getTransformConstraints().size(); ++i) {
|
||||
TransformConstraintData* data = _data->getTransformConstraints()[i];
|
||||
|
||||
TransformConstraint* constraint = new (__FILE__, __LINE__) TransformConstraint(*data, *this);
|
||||
|
||||
@ -110,8 +110,8 @@ namespace Spine {
|
||||
}
|
||||
|
||||
_pathConstraints.ensureCapacity(_data->getPathConstraints().size());
|
||||
for (PathConstraintData** i = _data->getPathConstraints().begin(); i != _data->getPathConstraints().end(); ++i) {
|
||||
PathConstraintData* data = (*i);
|
||||
for (size_t i = 0; i < _data->getPathConstraints().size(); ++i) {
|
||||
PathConstraintData* data = _data->getPathConstraints()[i];
|
||||
|
||||
PathConstraint* constraint = new (__FILE__, __LINE__) PathConstraint(*data, *this);
|
||||
|
||||
@ -403,8 +403,8 @@ namespace Spine {
|
||||
float maxX = std::numeric_limits<float>::min();
|
||||
float maxY = std::numeric_limits<float>::min();
|
||||
|
||||
for (Slot** i = _drawOrder.begin(); i != _drawOrder.end(); ++i) {
|
||||
Slot* slot = (*i);
|
||||
for (size_t i = 0; i < _drawOrder.size(); ++i) {
|
||||
Slot* slot = _drawOrder[i];
|
||||
int verticesLength = 0;
|
||||
Attachment* attachment = slot->getAttachment();
|
||||
|
||||
@ -672,8 +672,8 @@ namespace Spine {
|
||||
}
|
||||
|
||||
void Skeleton::sortReset(Vector<Bone*>& bones) {
|
||||
for (Bone** i = bones.begin(); i != bones.end(); ++i) {
|
||||
Bone* bone = (*i);
|
||||
for (size_t i = 0; i < bones.size(); ++i) {
|
||||
Bone* bone = bones[i];
|
||||
if (bone->_sorted) {
|
||||
sortReset(bone->getChildren());
|
||||
}
|
||||
|
||||
@ -56,8 +56,8 @@ namespace Spine {
|
||||
|
||||
_clippingPolygons = clippingPolygons;
|
||||
|
||||
for (Vector<float>** i = _clippingPolygons.begin(); i != _clippingPolygons.end(); ++i) {
|
||||
Vector<float>* polygonP = (*i);
|
||||
for (size_t i = 0; i < _clippingPolygons.size(); ++i) {
|
||||
Vector<float>* polygonP = _clippingPolygons[i];
|
||||
Vector<float>& polygon = *polygonP;
|
||||
makeClockwise(polygon);
|
||||
polygon.add(polygon[0]);
|
||||
@ -112,7 +112,7 @@ namespace Spine {
|
||||
|
||||
for (int p = 0; p < polygonsCount; p++) {
|
||||
int s = static_cast<int>(clippedVertices.size());
|
||||
if (clip(x1, y1, x2, y2, x3, y3, *polygons[p], clipOutput)) {
|
||||
if (clip(x1, y1, x2, y2, x3, y3, &(*polygons[p]), &clipOutput)) {
|
||||
int clipOutputLength = static_cast<int>(clipOutput.size());
|
||||
if (clipOutputLength == 0) {
|
||||
continue;
|
||||
@ -192,40 +192,40 @@ namespace Spine {
|
||||
return _clippedUVs;
|
||||
}
|
||||
|
||||
bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector<float>& clippingArea, Vector<float>& output) {
|
||||
Vector<float>& originalOutput = output;
|
||||
bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector<float>* clippingArea, Vector<float>* output) {
|
||||
Vector<float>* originalOutput = output;
|
||||
bool clipped = false;
|
||||
|
||||
// Avoid copy at the end.
|
||||
Vector<float> input;
|
||||
if (clippingArea.size() % 4 >= 2) {
|
||||
Vector<float>* input;
|
||||
if (clippingArea->size() % 4 >= 2) {
|
||||
input = output;
|
||||
output = _scratch;
|
||||
output = &_scratch;
|
||||
}
|
||||
else {
|
||||
input = _scratch;
|
||||
input = &_scratch;
|
||||
}
|
||||
|
||||
input.clear();
|
||||
input.add(x1);
|
||||
input.add(y1);
|
||||
input.add(x2);
|
||||
input.add(y2);
|
||||
input.add(x3);
|
||||
input.add(y3);
|
||||
input.add(x1);
|
||||
input.add(y1);
|
||||
output.clear();
|
||||
input->clear();
|
||||
input->add(x1);
|
||||
input->add(y1);
|
||||
input->add(x2);
|
||||
input->add(y2);
|
||||
input->add(x3);
|
||||
input->add(y3);
|
||||
input->add(x1);
|
||||
input->add(y1);
|
||||
output->clear();
|
||||
|
||||
Vector<float>& clippingVertices = clippingArea;
|
||||
int clippingVerticesLast = static_cast<int>(clippingArea.size()) - 4;
|
||||
Vector<float>& clippingVertices = *clippingArea;
|
||||
int clippingVerticesLast = static_cast<int>(clippingArea->size()) - 4;
|
||||
for (int i = 0; ; i += 2) {
|
||||
float edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
|
||||
float edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
|
||||
float deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
|
||||
|
||||
Vector<float>& inputVertices = input;
|
||||
int inputVerticesLength = static_cast<int>(input.size()) - 2, outputStart = static_cast<int>(output.size());
|
||||
Vector<float>& inputVertices = *input;
|
||||
int inputVerticesLength = static_cast<int>(input->size()) - 2, outputStart = static_cast<int>(output->size());
|
||||
for (int ii = 0; ii < inputVerticesLength; ii += 2) {
|
||||
float inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
|
||||
float inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
|
||||
@ -233,54 +233,54 @@ namespace Spine {
|
||||
if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
|
||||
if (side2) {
|
||||
// v1 inside, v2 inside
|
||||
output.add(inputX2);
|
||||
output.add(inputY2);
|
||||
output->add(inputX2);
|
||||
output->add(inputY2);
|
||||
continue;
|
||||
}
|
||||
// v1 inside, v2 outside
|
||||
float c0 = inputY2 - inputY, c2 = inputX2 - inputX;
|
||||
float ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
|
||||
output.add(edgeX + (edgeX2 - edgeX) * ua);
|
||||
output.add(edgeY + (edgeY2 - edgeY) * ua);
|
||||
output->add(edgeX + (edgeX2 - edgeX) * ua);
|
||||
output->add(edgeY + (edgeY2 - edgeY) * ua);
|
||||
}
|
||||
else if (side2) {
|
||||
// v1 outside, v2 inside
|
||||
float c0 = inputY2 - inputY, c2 = inputX2 - inputX;
|
||||
float ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
|
||||
output.add(edgeX + (edgeX2 - edgeX) * ua);
|
||||
output.add(edgeY + (edgeY2 - edgeY) * ua);
|
||||
output.add(inputX2);
|
||||
output.add(inputY2);
|
||||
output->add(edgeX + (edgeX2 - edgeX) * ua);
|
||||
output->add(edgeY + (edgeY2 - edgeY) * ua);
|
||||
output->add(inputX2);
|
||||
output->add(inputY2);
|
||||
}
|
||||
clipped = true;
|
||||
}
|
||||
|
||||
if (outputStart == output.size()) {
|
||||
if (outputStart == output->size()) {
|
||||
// All edges outside.
|
||||
originalOutput.clear();
|
||||
originalOutput->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
output.add(output[0]);
|
||||
output.add(output[1]);
|
||||
output->add((*output)[0]);
|
||||
output->add((*output)[1]);
|
||||
|
||||
if (i == clippingVerticesLast) {
|
||||
break;
|
||||
}
|
||||
Vector<float> temp = output;
|
||||
Vector<float>* temp = output;
|
||||
output = input;
|
||||
output.clear();
|
||||
output->clear();
|
||||
input = temp;
|
||||
}
|
||||
|
||||
if (originalOutput != output) {
|
||||
originalOutput.clear();
|
||||
for (int i = 0, n = static_cast<int>(output.size()) - 2; i < n; ++i) {
|
||||
originalOutput.add(output[i]);
|
||||
originalOutput->clear();
|
||||
for (int i = 0, n = static_cast<int>(output->size()) - 2; i < n; ++i) {
|
||||
originalOutput->add((*output)[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
originalOutput.setSize(originalOutput.size() - 2);
|
||||
originalOutput->setSize(originalOutput->size() - 2);
|
||||
}
|
||||
|
||||
return clipped;
|
||||
|
||||
@ -48,8 +48,8 @@ namespace Spine {
|
||||
_scaleMix(data.getScaleMix()),
|
||||
_shearMix(data.getShearMix()) {
|
||||
_bones.ensureCapacity(_data.getBones().size());
|
||||
for (BoneData** i = _data.getBones().begin(); i != _data.getBones().end(); ++i) {
|
||||
BoneData* boneData = (*i);
|
||||
for (size_t i = 0; i < _data.getBones().size(); ++i) {
|
||||
BoneData* boneData = _data.getBones()[i];
|
||||
|
||||
_bones.add(skeleton.findBone(boneData->getName()));
|
||||
}
|
||||
@ -137,8 +137,8 @@ namespace Spine {
|
||||
float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
|
||||
float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect;
|
||||
|
||||
for (Bone** i = _bones.begin(); i != _bones.end(); ++i) {
|
||||
Bone* item = (*i);
|
||||
for (size_t i = 0; i < _bones.size(); ++i) {
|
||||
Bone* item = _bones[i];
|
||||
Bone& bone = *item;
|
||||
|
||||
bool modified = false;
|
||||
@ -218,8 +218,8 @@ namespace Spine {
|
||||
float ta = target._a, tb = target._b, tc = target._c, td = target._d;
|
||||
float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
|
||||
float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect;
|
||||
for (Bone** i = _bones.begin(); i != _bones.end(); ++i) {
|
||||
Bone* item = (*i);
|
||||
for (size_t i = 0; i < _bones.size(); ++i) {
|
||||
Bone* item = _bones[i];
|
||||
Bone& bone = *item;
|
||||
|
||||
bool modified = false;
|
||||
@ -291,8 +291,8 @@ namespace Spine {
|
||||
target.updateAppliedTransform();
|
||||
}
|
||||
|
||||
for (Bone** i = _bones.begin(); i != _bones.end(); ++i) {
|
||||
Bone* item = (*i);
|
||||
for (size_t i = 0; i < _bones.size(); ++i) {
|
||||
Bone* item = _bones[i];
|
||||
Bone& bone = *item;
|
||||
|
||||
if (!bone._appliedValid) {
|
||||
@ -341,8 +341,8 @@ namespace Spine {
|
||||
target.updateAppliedTransform();
|
||||
}
|
||||
|
||||
for (Bone** i = _bones.begin(); i != _bones.end(); ++i) {
|
||||
Bone* item = (*i);
|
||||
for (size_t i = 0; i < _bones.size(); ++i) {
|
||||
Bone* item = _bones[i];
|
||||
Bone& bone = *item;
|
||||
|
||||
if (!bone._appliedValid) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user