Browse Source

[cpp] Removed Vector.begin/end, fixed up vector assignments.

badlogic 7 years ago
parent
commit
6d243eca48

+ 4 - 4
spine-cpp/spine-cpp/include/spine/ContainerUtil.h

@@ -49,8 +49,8 @@ namespace Spine {
         static T* findWithName(Vector<T*>& items, const String& name) {
         static T* findWithName(Vector<T*>& items, const String& name) {
             assert(name.length() > 0);
             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) {
                 if (item->getName() == name) {
                     return item;
                     return item;
                 }
                 }
@@ -81,8 +81,8 @@ namespace Spine {
         static T* findWithDataName(Vector<T*>& items, const String& name) {
         static T* findWithDataName(Vector<T*>& items, const String& name) {
             assert(name.length() > 0);
             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) {
                 if (item->getData().getName() == name) {
                     return item;
                     return item;
                 }
                 }

+ 1 - 1
spine-cpp/spine-cpp/include/spine/Pool.h

@@ -49,7 +49,7 @@ namespace Spine {
         
         
         T* obtain() {
         T* obtain() {
             if (_objects.size() > 0) {
             if (_objects.size() > 0) {
-                T** object = _objects.end();
+                T** object = &_objects[_objects.size() - 1];
                 T* ret = *object;
                 T* ret = *object;
                 _objects.removeAt(_objects.size() - 1);
                 _objects.removeAt(_objects.size() - 1);
                 
                 

+ 1 - 1
spine-cpp/spine-cpp/include/spine/SkeletonClipping.h

@@ -69,7 +69,7 @@ namespace Spine {
         
         
         /** Clips the input triangle against the convex, clockwise clipping area. If the triangle lies entirely within the clipping
         /** 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. */
                   * 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);
         static void makeClockwise(Vector<float>& polygon);
     };
     };

+ 4 - 15
spine-cpp/spine-cpp/include/spine/Vector.h

@@ -157,14 +157,6 @@ namespace Spine {
             return _buffer[inIndex];
             return _buffer[inIndex];
         }
         }
 
 
-        T* begin() {
-            return &_buffer[0];
-        }
-
-        T* end() {
-            return &_buffer[_size];
-        }
-
         friend bool operator==(Vector<T>& lhs, Vector<T>& rhs) {
         friend bool operator==(Vector<T>& lhs, Vector<T>& rhs) {
             if (lhs.size() != rhs.size()) {
             if (lhs.size() != rhs.size()) {
                 return false;
                 return false;
@@ -188,7 +180,7 @@ namespace Spine {
         size_t _capacity;
         size_t _capacity;
         T* _buffer;
         T* _buffer;
 
 
-        T* allocate(size_t n) {
+        inline T* allocate(size_t n) {
             assert(n > 0);
             assert(n > 0);
 
 
             T* ptr = SpineExtension::alloc<T>(n, __FILE__, __LINE__);
             T* ptr = SpineExtension::alloc<T>(n, __FILE__, __LINE__);
@@ -198,20 +190,17 @@ namespace Spine {
             return ptr;
             return ptr;
         }
         }
 
 
-        void deallocate(T* buffer) {
+        inline void deallocate(T* buffer) {
             if (_buffer) {
             if (_buffer) {
                 SpineExtension::free(buffer, __FILE__, __LINE__);
                 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);
             new (buffer) T(val);
         }
         }
 
 
-        void destroy(T* buffer) {
+        inline void destroy(T* buffer) {
             buffer->~T();
             buffer->~T();
         }
         }
     };
     };

+ 2 - 3
spine-cpp/spine-cpp/src/spine/IkConstraint.cpp

@@ -248,9 +248,8 @@ namespace Spine {
     _bendDirection(data.getBendDirection()),
     _bendDirection(data.getBendDirection()),
     _target(skeleton.findBone(data.getTarget()->getName())) {
     _target(skeleton.findBone(data.getTarget()->getName())) {
         _bones.ensureCapacity(_data.getBones().size());
         _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()));
             _bones.add(skeleton.findBone(boneData->getName()));
         }
         }
     }
     }

+ 2 - 3
spine-cpp/spine-cpp/src/spine/PathConstraint.cpp

@@ -59,9 +59,8 @@ namespace Spine {
     _rotateMix(data.getRotateMix()),
     _rotateMix(data.getRotateMix()),
     _translateMix(data.getTranslateMix()) {
     _translateMix(data.getTranslateMix()) {
         _bones.ensureCapacity(_data.getBones().size());
         _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()));
             _bones.add(skeleton.findBone(boneData->getName()));
         }
         }
 
 

+ 14 - 14
spine-cpp/spine-cpp/src/spine/Skeleton.cpp

@@ -63,8 +63,8 @@ namespace Spine {
     _x(0),
     _x(0),
     _y(0) {
     _y(0) {
         _bones.ensureCapacity(_data->getBones().size());
         _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;
             Bone* bone;
             if (data->getParent() == NULL) {
             if (data->getParent() == NULL) {
@@ -81,8 +81,8 @@ namespace Spine {
 
 
         _slots.ensureCapacity(_data->getSlots().size());
         _slots.ensureCapacity(_data->getSlots().size());
         _drawOrder.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()];
             Bone* bone = _bones[data->getBoneData().getIndex()];
             Slot* slot = new (__FILE__, __LINE__) Slot(*data, *bone);
             Slot* slot = new (__FILE__, __LINE__) Slot(*data, *bone);
@@ -92,8 +92,8 @@ namespace Spine {
         }
         }
 
 
         _ikConstraints.ensureCapacity(_data->getIkConstraints().size());
         _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);
             IkConstraint* constraint = new (__FILE__, __LINE__) IkConstraint(*data, *this);
 
 
@@ -101,8 +101,8 @@ namespace Spine {
         }
         }
 
 
         _transformConstraints.ensureCapacity(_data->getTransformConstraints().size());
         _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);
             TransformConstraint* constraint = new (__FILE__, __LINE__) TransformConstraint(*data, *this);
 
 
@@ -110,8 +110,8 @@ namespace Spine {
         }
         }
 
 
         _pathConstraints.ensureCapacity(_data->getPathConstraints().size());
         _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);
             PathConstraint* constraint = new (__FILE__, __LINE__) PathConstraint(*data, *this);
 
 
@@ -403,8 +403,8 @@ namespace Spine {
         float maxX = std::numeric_limits<float>::min();
         float maxX = std::numeric_limits<float>::min();
         float maxY = 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;
             int verticesLength = 0;
             Attachment* attachment = slot->getAttachment();
             Attachment* attachment = slot->getAttachment();
             
             
@@ -672,8 +672,8 @@ namespace Spine {
     }
     }
     
     
     void Skeleton::sortReset(Vector<Bone*>& bones) {
     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) {
             if (bone->_sorted) {
                 sortReset(bone->getChildren());
                 sortReset(bone->getChildren());
             }
             }

+ 41 - 41
spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp

@@ -56,8 +56,8 @@ namespace Spine {
         
         
         _clippingPolygons = clippingPolygons;
         _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;
             Vector<float>& polygon = *polygonP;
             makeClockwise(polygon);
             makeClockwise(polygon);
             polygon.add(polygon[0]);
             polygon.add(polygon[0]);
@@ -112,7 +112,7 @@ namespace Spine {
 
 
             for (int p = 0; p < polygonsCount; p++) {
             for (int p = 0; p < polygonsCount; p++) {
                 int s = static_cast<int>(clippedVertices.size());
                 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());
                     int clipOutputLength = static_cast<int>(clipOutput.size());
                     if (clipOutputLength == 0) {
                     if (clipOutputLength == 0) {
                         continue;
                         continue;
@@ -192,40 +192,40 @@ namespace Spine {
         return _clippedUVs;
         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;
         bool clipped = false;
 
 
         // Avoid copy at the end.
         // Avoid copy at the end.
-        Vector<float> input;
-        if (clippingArea.size() % 4 >= 2) {
+        Vector<float>* input;
+        if (clippingArea->size() % 4 >= 2) {
             input = output;
             input = output;
-            output = _scratch;
+            output = &_scratch;
         }
         }
         else {
         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) {
         for (int i = 0; ; i += 2) {
             float edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
             float edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1];
             float edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
             float edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3];
             float deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2;
             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) {
             for (int ii = 0; ii < inputVerticesLength; ii += 2) {
                 float inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
                 float inputX = inputVertices[ii], inputY = inputVertices[ii + 1];
                 float inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
                 float inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3];
@@ -233,54 +233,54 @@ namespace Spine {
                 if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
                 if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) {
                     if (side2) {
                     if (side2) {
                         // v1 inside, v2 inside
                         // v1 inside, v2 inside
-                        output.add(inputX2);
-                        output.add(inputY2);
+                        output->add(inputX2);
+                        output->add(inputY2);
                         continue;
                         continue;
                     }
                     }
                     // v1 inside, v2 outside
                     // v1 inside, v2 outside
                     float c0 = inputY2 - inputY, c2 = inputX2 - inputX;
                     float c0 = inputY2 - inputY, c2 = inputX2 - inputX;
                     float ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
                     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) {
                 else if (side2) {
                     // v1 outside, v2 inside
                     // v1 outside, v2 inside
                     float c0 = inputY2 - inputY, c2 = inputX2 - inputX;
                     float c0 = inputY2 - inputY, c2 = inputX2 - inputX;
                     float ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY));
                     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;
                 clipped = true;
             }
             }
 
 
-            if (outputStart == output.size()) {
+            if (outputStart == output->size()) {
                 // All edges outside.
                 // All edges outside.
-                originalOutput.clear();
+                originalOutput->clear();
                 return true;
                 return true;
             }
             }
 
 
-            output.add(output[0]);
-            output.add(output[1]);
+            output->add((*output)[0]);
+            output->add((*output)[1]);
 
 
             if (i == clippingVerticesLast) {
             if (i == clippingVerticesLast) {
                 break;
                 break;
             }
             }
-            Vector<float> temp = output;
+            Vector<float>* temp = output;
             output = input;
             output = input;
-            output.clear();
+            output->clear();
             input = temp;
             input = temp;
         }
         }
 
 
         if (originalOutput != output) {
         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 {
         else {
-            originalOutput.setSize(originalOutput.size() - 2);
+            originalOutput->setSize(originalOutput->size() - 2);
         }
         }
 
 
         return clipped;
         return clipped;

+ 10 - 10
spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp

@@ -48,8 +48,8 @@ namespace Spine {
     _scaleMix(data.getScaleMix()),
     _scaleMix(data.getScaleMix()),
     _shearMix(data.getShearMix()) {
     _shearMix(data.getShearMix()) {
         _bones.ensureCapacity(_data.getBones().size());
         _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()));
             _bones.add(skeleton.findBone(boneData->getName()));
         }
         }
@@ -137,8 +137,8 @@ namespace Spine {
         float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
         float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
         float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect;
         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;
             Bone& bone = *item;
             
             
             bool modified = false;
             bool modified = false;
@@ -218,8 +218,8 @@ namespace Spine {
         float ta = target._a, tb = target._b, tc = target._c, td = target._d;
         float ta = target._a, tb = target._b, tc = target._c, td = target._d;
         float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
         float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
         float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect;
         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;
             Bone& bone = *item;
             
             
             bool modified = false;
             bool modified = false;
@@ -291,8 +291,8 @@ namespace Spine {
             target.updateAppliedTransform();
             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;
             Bone& bone = *item;
             
             
             if (!bone._appliedValid) {
             if (!bone._appliedValid) {
@@ -341,8 +341,8 @@ namespace Spine {
             target.updateAppliedTransform();
             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;
             Bone& bone = *item;
             
             
             if (!bone._appliedValid) {
             if (!bone._appliedValid) {