[cpp] Added Color, fixed up incorrect use of ensureCapacity/setSize of Vector. Fixed bugs in SkeletonBinary.

This commit is contained in:
badlogic 2018-02-21 15:23:35 +01:00
parent 1c21542148
commit 5af3d93403
35 changed files with 330 additions and 500 deletions

View File

@ -31,3 +31,15 @@ add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/goblins/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/goblins) ${CMAKE_CURRENT_LIST_DIR}/../../examples/goblins/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/goblins)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/coin/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/coin)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/tank/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/tank)
add_custom_command(TARGET spine_cpp_unit_test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/../../examples/stretchyman/export $<TARGET_FILE_DIR:spine_cpp_unit_test>/testdata/stretchyman)

View File

@ -33,18 +33,9 @@
#include "TestHarness.h" #include "TestHarness.h"
#define R_JSON "testdata/raptor/raptor-pro.json"
#define R_BINARY "testdata/raptor/raptor-pro.skel"
#define R_ATLAS "testdata/raptor/raptor.atlas"
#define SPINEBOY_JSON "testdata/spineboy/spineboy-pro.json"
#define SPINEBOY_BINARY "testdata/spineboy/spineboy-pro.skel"
#define SPINEBOY_ATLAS "testdata/spineboy/spineboy.atlas"
using namespace Spine; using namespace Spine;
void loadBinary(const char* binaryFile, const char* atlasFile, Atlas* &atlas, SkeletonData* &skeletonData, AnimationStateData* &stateData, Skeleton* &skeleton, AnimationState* &state) { void loadBinary(const String& binaryFile, const String& atlasFile, Atlas* &atlas, SkeletonData* &skeletonData, AnimationStateData* &stateData, Skeleton* &skeleton, AnimationState* &state) {
atlas = new (__FILE__, __LINE__) Atlas(atlasFile, NULL); atlas = new (__FILE__, __LINE__) Atlas(atlasFile, NULL);
assert(atlas != NULL); assert(atlas != NULL);
@ -62,7 +53,7 @@ void loadBinary(const char* binaryFile, const char* atlasFile, Atlas* &atlas, Sk
state = new (__FILE__, __LINE__) AnimationState(stateData); state = new (__FILE__, __LINE__) AnimationState(stateData);
} }
void loadJson(const char* jsonFile, const char* atlasFile, Atlas* &atlas, SkeletonData* &skeletonData, AnimationStateData* &stateData, Skeleton* &skeleton, AnimationState* &state) { void loadJson(const String& jsonFile, const String& atlasFile, Atlas* &atlas, SkeletonData* &skeletonData, AnimationStateData* &stateData, Skeleton* &skeleton, AnimationState* &state) {
atlas = new (__FILE__, __LINE__) Atlas(atlasFile, NULL); atlas = new (__FILE__, __LINE__) Atlas(atlasFile, NULL);
assert(atlas != NULL); assert(atlas != NULL);
@ -88,25 +79,46 @@ void dispose(Atlas* atlas, SkeletonData* skeletonData, AnimationStateData* state
delete atlas; delete atlas;
} }
void reproduceIssue_776() { struct TestData {
Atlas* atlas = NULL; TestData(const String& jsonSkeleton, const String& binarySkeleton, const String& atlas) : _jsonSkeleton(jsonSkeleton), _binarySkeleton(binarySkeleton), _atlas(atlas) { }
SkeletonData* skeletonData = NULL;
AnimationStateData* stateData = NULL;
Skeleton* skeleton = NULL;
AnimationState* state = NULL;
loadJson(R_JSON, R_ATLAS, atlas, skeletonData, stateData, skeleton, state); String _jsonSkeleton;
dispose(atlas, skeletonData, stateData, skeleton, state); String _binarySkeleton;
String _atlas;
};
loadBinary(R_BINARY, R_ATLAS, atlas, skeletonData, stateData, skeleton, state); void testLoading() {
dispose(atlas, skeletonData, stateData, skeleton, state); Vector<TestData> testData;
testData.add(TestData("testdata/coin/coin-pro.json", "testdata/coin/coin-pro.skel", "testdata/coin/coin.atlas"));
testData.add(TestData("testdata/goblins/goblins-pro.json", "testdata/goblins/goblins-pro.skel", "testdata/goblins/goblins.atlas"));
testData.add(TestData("testdata/raptor/raptor-pro.json", "testdata/raptor/raptor-pro.skel", "testdata/raptor/raptor.atlas"));
testData.add(TestData("testdata/spineboy/spineboy-pro.json", "testdata/spineboy/spineboy-pro.skel", "testdata/spineboy/spineboy.atlas"));
testData.add(TestData("testdata/stretchyman/stretchyman-pro.json", "testdata/stretchyman/stretchyman-pro.skel", "testdata/stretchyman/stretchyman.atlas"));
testData.add(TestData("testdata/tank/tank-pro.json", "testdata/tank/tank-pro.skel", "testdata/tank/tank.atlas"));
for (size_t i = 0; i < testData.size(); i++) {
TestData& data = testData[i];
Atlas* atlas = NULL;
SkeletonData* skeletonData = NULL;
AnimationStateData* stateData = NULL;
Skeleton* skeleton = NULL;
AnimationState* state = NULL;
printf("Loading %s\n", data._jsonSkeleton.buffer());
loadJson(data._jsonSkeleton, data._atlas, atlas, skeletonData, stateData, skeleton, state);
dispose(atlas, skeletonData, stateData, skeleton, state);
printf("Loading %s\n", data._binarySkeleton.buffer());
loadBinary(data._binarySkeleton, data._atlas, atlas, skeletonData, stateData, skeleton, state);
dispose(atlas, skeletonData, stateData, skeleton, state);
}
} }
int main (int argc, char** argv) { int main (int argc, char** argv) {
TestSpineExtension* ext = new TestSpineExtension(); TestSpineExtension* ext = new TestSpineExtension();
SpineExtension::setInstance(ext); SpineExtension::setInstance(ext);
reproduceIssue_776(); testLoading();
ext->reportLeaks(); ext->reportLeaks();
} }

View File

@ -98,7 +98,7 @@ namespace Spine {
class Atlas : public SpineObject { class Atlas : public SpineObject {
public: public:
Atlas(const char* path, TextureLoader* textureLoader); Atlas(const String& path, TextureLoader* textureLoader);
Atlas(const char* data, int length, const char* dir, TextureLoader* textureLoader); Atlas(const char* data, int length, const char* dir, TextureLoader* textureLoader);

View File

@ -0,0 +1,67 @@
//
// Created by Mario Zechner on 2/20/18.
//
#ifndef SPINE_COLOR_H
#define SPINE_COLOR_H
#include <spine/MathUtil.h>
namespace Spine {
class Color {
public:
Color() : _r(0), _g(0), _b(0), _a(0) {}
Color(float r, float g, float b, float a) : _r(r), _g(g), _b(b), _a(a) {
clamp();
}
inline Color& set(float r, float g, float b, float a) {
_r = r;
_g = g;
_b = b;
_a = a;
clamp();
return *this;
}
inline Color& set(const Color& other) {
_r = other._r;
_g = other._g;
_b = other._b;
_a = other._a;
clamp();
return *this;
}
inline Color& add(float r, float g, float b, float a) {
_r += r;
_g += g;
_b += b;
_a += a;
clamp();
return *this;
}
inline Color& add(const Color& other) {
_r += other._r;
_g += other._g;
_b += other._b;
_a += other._a;
clamp();
return *this;
}
inline Color& clamp() {
_r = MathUtil::clamp(this->_r, 0, 1);
_g = MathUtil::clamp(this->_g, 0, 1);
_b = MathUtil::clamp(this->_b, 0, 1);
_a = MathUtil::clamp(this->_a, 0, 1);
return *this;
}
float _r, _g, _b, _a;
};
}
#endif //SPINE_COLOR_H

View File

@ -34,6 +34,8 @@
#include <stdlib.h> #include <stdlib.h>
namespace Spine { namespace Spine {
class String;
class SpineExtension { class SpineExtension {
public: public:
template <typename T> static T* alloc(size_t num, const char* file, int line) { template <typename T> static T* alloc(size_t num, const char* file, int line) {
@ -52,7 +54,7 @@ namespace Spine {
getInstance()->_free((void*)ptr, file, line); getInstance()->_free((void*)ptr, file, line);
} }
static char* readFile(const char* path, int* length) { static char* readFile(const String& path, int* length) {
return getInstance()->_readFile(path, length); return getInstance()->_readFile(path, length);
} }
@ -73,7 +75,7 @@ namespace Spine {
/// If you provide a spineAllocFunc, you should also provide a spineFreeFunc /// If you provide a spineAllocFunc, you should also provide a spineFreeFunc
virtual void _free(void* mem, const char* file, int line) = 0; virtual void _free(void* mem, const char* file, int line) = 0;
virtual char* _readFile(const char* path, int* length); virtual char* _readFile(const String& path, int* length) = 0;
SpineExtension(); SpineExtension();
@ -94,6 +96,8 @@ namespace Spine {
virtual void* _realloc(void* ptr, size_t size, const char* file, int line); virtual void* _realloc(void* ptr, size_t size, const char* file, int line);
virtual void _free(void* mem, const char* file, int line); virtual void _free(void* mem, const char* file, int line);
virtual char* _readFile(const String& path, int* length);
}; };
} }

View File

@ -33,6 +33,7 @@
#include <spine/VertexAttachment.h> #include <spine/VertexAttachment.h>
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/Color.h>
namespace Spine { namespace Spine {
@ -64,14 +65,7 @@ namespace Spine {
Vector<short>& getTriangles(); Vector<short>& getTriangles();
void setTriangles(Vector<short>& inValue); void setTriangles(Vector<short>& inValue);
float getR(); Color& getColor();
void setR(float inValue);
float getG();
void setG(float inValue);
float getB();
void setB(float inValue);
float getA();
void setA(float inValue);
const String& getPath(); const String& getPath();
void setPath(const String& inValue); void setPath(const String& inValue);
@ -143,7 +137,7 @@ namespace Spine {
float _regionV2; float _regionV2;
float _width; float _width;
float _height; float _height;
float _r, _g, _b, _a; Color _color;
int _hullLength; int _hullLength;
bool _inheritDeform; bool _inheritDeform;
bool _regionRotate; bool _regionRotate;

View File

@ -32,8 +32,8 @@
#define Spine_RegionAttachment_h #define Spine_RegionAttachment_h
#include <spine/Attachment.h> #include <spine/Attachment.h>
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/Color.h>
#include <string> #include <string>
@ -79,14 +79,7 @@ namespace Spine {
float getHeight(); float getHeight();
void setHeight(float inValue); void setHeight(float inValue);
float getR(); Color& getColor();
void setR(float inValue);
float getG();
void setG(float inValue);
float getB();
void setB(float inValue);
float getA();
void setA(float inValue);
const String& getPath(); const String& getPath();
void setPath(const String& inValue); void setPath(const String& inValue);
@ -134,7 +127,7 @@ namespace Spine {
float _regionV; float _regionV;
float _regionU2; float _regionU2;
float _regionV2; float _regionV2;
float _r, _g, _b, _a; Color _color;
}; };
} }

View File

@ -35,6 +35,7 @@
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/SpineObject.h> #include <spine/SpineObject.h>
#include <spine/String.h> #include <spine/String.h>
#include <spine/Color.h>
namespace Spine { namespace Spine {
class SkeletonData; class SkeletonData;
@ -76,7 +77,7 @@ namespace Spine {
SkeletonData* readSkeletonData(const unsigned char* binary, int length); SkeletonData* readSkeletonData(const unsigned char* binary, int length);
SkeletonData* readSkeletonDataFile(const char* path); SkeletonData* readSkeletonDataFile(const String& path);
private: private:
struct DataInput : public SpineObject { struct DataInput : public SpineObject {
@ -104,7 +105,7 @@ namespace Spine {
int readInt(DataInput* input); int readInt(DataInput* input);
void readColor(DataInput* input, float *r, float *g, float *b, float *a); void readColor(DataInput* input, Color& color);
int readVarint(DataInput* input, bool optimizePositive); int readVarint(DataInput* input, bool optimizePositive);

View File

@ -44,6 +44,7 @@ namespace Spine {
class Atlas; class Atlas;
class AttachmentLoader; class AttachmentLoader;
class LinkedMesh; class LinkedMesh;
class String;
class SkeletonJson : public SpineObject { class SkeletonJson : public SpineObject {
public: public:
@ -53,7 +54,7 @@ namespace Spine {
~SkeletonJson(); ~SkeletonJson();
SkeletonData* readSkeletonDataFile(const char* path); SkeletonData* readSkeletonDataFile(const String& path);
SkeletonData* readSkeletonData(const char* json); SkeletonData* readSkeletonData(const char* json);
@ -72,7 +73,7 @@ namespace Spine {
void readVertices(Json* attachmentMap, VertexAttachment* attachment, int verticesLength); void readVertices(Json* attachmentMap, VertexAttachment* attachment, int verticesLength);
void setError(Json* root, const char* value1, const char* value2); void setError(Json* root, const String& value1, const String& value2);
}; };
} }

View File

@ -33,6 +33,7 @@
#include <spine/Vector.h> #include <spine/Vector.h>
#include <spine/SpineObject.h> #include <spine/SpineObject.h>
#include <spine/Color.h>
#include <string> #include <string>
@ -72,23 +73,11 @@ namespace Spine {
Bone& getBone(); Bone& getBone();
Skeleton& getSkeleton(); Skeleton& getSkeleton();
float getR(); Color& getColor();
void setR(float inValue); Color& getDarkColor();
float getG();
void setG(float inValue);
float getB();
void setB(float inValue);
float getA();
void setA(float inValue);
float getR2(); bool hasDarkColor();
void setR2(float inValue); void setHasDarkColor(bool inValue);
float getG2();
void setG2(float inValue);
float getB2();
void setB2(float inValue);
bool hasSecondColor();
void setHasSecondColor(bool inValue);
/// May be NULL. /// May be NULL.
Attachment* getAttachment(); Attachment* getAttachment();
@ -104,9 +93,9 @@ namespace Spine {
SlotData& _data; SlotData& _data;
Bone& _bone; Bone& _bone;
Skeleton& _skeleton; Skeleton& _skeleton;
float _r, _g, _b, _a; Color _color;
float _r2, _g2, _b2; Color _darkColor;
bool _hasSecondColor; bool _hasDarkColor;
Attachment* _attachment; Attachment* _attachment;
float _attachmentTime; float _attachmentTime;
Vector<float> _attachmentVertices; Vector<float> _attachmentVertices;

View File

@ -34,6 +34,7 @@
#include <spine/BlendMode.h> #include <spine/BlendMode.h>
#include <spine/SpineObject.h> #include <spine/SpineObject.h>
#include <spine/String.h> #include <spine/String.h>
#include <spine/Color.h>
namespace Spine { namespace Spine {
class BoneData; class BoneData;
@ -66,23 +67,11 @@ namespace Spine {
BoneData& getBoneData(); BoneData& getBoneData();
float getR(); Color& getColor();
void setR(float inValue); Color& getDarkColor();
float getG();
void setG(float inValue);
float getB();
void setB(float inValue);
float getA();
void setA(float inValue);
float getR2(); bool hasDarkColor();
void setR2(float inValue); void setHasDarkColor(bool inValue);
float getG2();
void setG2(float inValue);
float getB2();
void setB2(float inValue);
bool hasSecondColor();
void setHasSecondColor(bool inValue);
/// May be empty. /// May be empty.
const String& getAttachmentName(); const String& getAttachmentName();
@ -95,9 +84,10 @@ namespace Spine {
const int _index; const int _index;
String _name; String _name;
BoneData& _boneData; BoneData& _boneData;
float _r, _g, _b, _a; Color _color;
float _r2, _g2, _b2, _a2; Color _darkColor;
bool _hasSecondColor;
bool _hasDarkColor;
String _attachmentName; String _attachmentName;
BlendMode _blendMode; BlendMode _blendMode;
}; };

View File

@ -144,7 +144,7 @@ namespace Spine {
return *this; return *this;
} }
String& operator+ (const String& other) { String& operator+= (const String& other) {
size_t len = other.length(); size_t len = other.length();
size_t thisLen = _length; size_t thisLen = _length;
_length = _length + len; _length = _length + len;
@ -154,6 +154,10 @@ namespace Spine {
return *this; return *this;
} }
friend String operator+ (const String& a, const String& b) {
return String(a) += b;
}
friend bool operator== (const String& a, const String& b) { friend bool operator== (const String& a, const String& b) {
if (a._buffer == b._buffer) return true; if (a._buffer == b._buffer) return true;
if (a._length != b._length) return false; if (a._length != b._length) return false;

View File

@ -45,6 +45,7 @@
#include <spine/BoneData.h> #include <spine/BoneData.h>
#include <spine/BoundingBoxAttachment.h> #include <spine/BoundingBoxAttachment.h>
#include <spine/ClippingAttachment.h> #include <spine/ClippingAttachment.h>
#include <spine/Color.h>
#include <spine/ColorTimeline.h> #include <spine/ColorTimeline.h>
#include <spine/Constraint.h> #include <spine/Constraint.h>
#include <spine/ContainerUtil.h> #include <spine/ContainerUtil.h>

View File

@ -147,10 +147,8 @@ namespace Spine {
int mixingToLast = static_cast<int>(mixingToArray.size()) - 1; int mixingToLast = static_cast<int>(mixingToArray.size()) - 1;
Vector<Timeline*>& timelines = _animation->_timelines; Vector<Timeline*>& timelines = _animation->_timelines;
int timelinesCount = static_cast<int>(timelines.size()); int timelinesCount = static_cast<int>(timelines.size());
_timelineData.ensureCapacity(timelinesCount);
_timelineData.setSize(timelinesCount); _timelineData.setSize(timelinesCount);
_timelineDipMix.clear(); _timelineDipMix.clear();
_timelineDipMix.ensureCapacity(timelinesCount);
_timelineDipMix.setSize(timelinesCount); _timelineDipMix.setSize(timelinesCount);
// outer: // outer:
@ -424,7 +422,6 @@ namespace Spine {
bool firstFrame = current._timelinesRotation.size() == 0; bool firstFrame = current._timelinesRotation.size() == 0;
if (firstFrame) { if (firstFrame) {
current._timelinesRotation.ensureCapacity(timelines.size() << 1);
current._timelinesRotation.setSize(timelines.size() << 1); current._timelinesRotation.setSize(timelines.size() << 1);
} }
Vector<float>& timelinesRotation = current._timelinesRotation; Vector<float>& timelinesRotation = current._timelinesRotation;
@ -780,8 +777,6 @@ namespace Spine {
bool firstFrame = from->_timelinesRotation.size() == 0; bool firstFrame = from->_timelinesRotation.size() == 0;
if (firstFrame) { if (firstFrame) {
// from.timelinesRotation.setSize
from->_timelinesRotation.ensureCapacity(timelines.size() << 1);
from->_timelinesRotation.setSize(timelines.size() << 1); from->_timelinesRotation.setSize(timelines.size() << 1);
} }

View File

@ -37,20 +37,20 @@
#include <cstring> #include <cstring>
namespace Spine { namespace Spine {
Atlas::Atlas(const char* path, TextureLoader* textureLoader) : _textureLoader(textureLoader) { Atlas::Atlas(const String& path, TextureLoader* textureLoader) : _textureLoader(textureLoader) {
int dirLength; int dirLength;
char *dir; char *dir;
int length; int length;
const char* data; const char* data;
/* Get directory from atlas path. */ /* Get directory from atlas path. */
const char* lastForwardSlash = strrchr(path, '/'); const char* lastForwardSlash = strrchr(path.buffer(), '/');
const char* lastBackwardSlash = strrchr(path, '\\'); const char* lastBackwardSlash = strrchr(path.buffer(), '\\');
const char* lastSlash = lastForwardSlash > lastBackwardSlash ? lastForwardSlash : lastBackwardSlash; const char* lastSlash = lastForwardSlash > lastBackwardSlash ? lastForwardSlash : lastBackwardSlash;
if (lastSlash == path) lastSlash++; /* Never drop starting slash. */ if (lastSlash == path) lastSlash++; /* Never drop starting slash. */
dirLength = (int)(lastSlash ? lastSlash - path : 0); dirLength = (int)(lastSlash ? lastSlash - path.buffer() : 0);
dir = SpineExtension::alloc<char>(dirLength + 1, __FILE__, __LINE__); dir = SpineExtension::alloc<char>(dirLength + 1, __FILE__, __LINE__);
memcpy(dir, path, dirLength); memcpy(dir, path.buffer(), dirLength);
dir[dirLength] = '\0'; dir[dirLength] = '\0';
data = SpineExtension::readFile(path, &length); data = SpineExtension::readFile(path, &length);
@ -198,7 +198,6 @@ namespace Spine {
if (count == 4) { if (count == 4) {
/* split is optional */ /* split is optional */
region->splits.ensureCapacity(4);
region->splits.setSize(4); region->splits.setSize(4);
region->splits[0] = toInt(tuple); region->splits[0] = toInt(tuple);
region->splits[1] = toInt(tuple + 1); region->splits[1] = toInt(tuple + 1);
@ -210,7 +209,6 @@ namespace Spine {
if (count == 4) { if (count == 4) {
/* pad is optional, but only present with splits */ /* pad is optional, but only present with splits */
region->pads.ensureCapacity(4);
region->pads.setSize(4); region->pads.setSize(4);
region->pads[0] = toInt(tuple); region->pads[0] = toInt(tuple);
region->pads[1] = toInt(tuple + 1); region->pads[1] = toInt(tuple + 1);

View File

@ -53,7 +53,6 @@ namespace Spine {
const int ColorTimeline::A = 4; const int ColorTimeline::A = 4;
ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0) { ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0) {
_frames.ensureCapacity(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES);
} }
@ -64,17 +63,16 @@ namespace Spine {
SlotData& slotData = slot._data; SlotData& slotData = slot._data;
switch (pose) { switch (pose) {
case MixPose_Setup: case MixPose_Setup:
slot._r = slotData._r; slot.getColor().set(slotData.getColor());
slot._g = slotData._g;
slot._b = slotData._b;
slot._a = slotData._a;
return; return;
case MixPose_Current: case MixPose_Current: {
slot._r += (slot._r - slotData._r) * alpha; Color &color = slot.getColor();
slot._g += (slot._g - slotData._g) * alpha; Color &setup = slot.getData().getColor();
slot._b += (slot._b - slotData._b) * alpha; color.add((setup._r - color._r) * alpha, (setup._g - color._g) * alpha,
slot._a += (slot._a - slotData._a) * alpha; (setup._b - color._b) * alpha,
(setup._a - color._a) * alpha);
return; return;
}
case MixPose_CurrentLayered: case MixPose_CurrentLayered:
default: default:
return; return;
@ -107,29 +105,11 @@ namespace Spine {
} }
if (alpha == 1) { if (alpha == 1) {
slot._r = r; slot.getColor().set(r, g, b, a);
slot._g = g; } else {
slot._b = b; Color& color = slot.getColor();
slot._a = a; if (pose == MixPose_Setup) color.set(slot.getData().getColor());
} color.add((r - color._r) * alpha, (g - color._g) * alpha, (b - color._b) * alpha, (a - color._a) * alpha);
else {
float br, bg, bb, ba;
if (pose == MixPose_Setup) {
br = slot._data._r;
bg = slot._data._g;
bb = slot._data._b;
ba = slot._data._a;
}
else {
br = slot._r;
bg = slot._g;
bb = slot._b;
ba = slot._a;
}
slot._r = br + ((r - br) * alpha);
slot._g = bg + ((g - bg) * alpha);
slot._b = bb + ((b - bb) * alpha);
slot._a = ba + ((a - ba) * alpha);
} }
} }

View File

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

View File

@ -87,7 +87,6 @@ namespace Spine {
} }
// Ensure size and preemptively set count. // Ensure size and preemptively set count.
vertices.ensureCapacity(vertexCount);
vertices.setSize(vertexCount); vertices.setSize(vertexCount);
if (vertexAttachment->_bones.size() == 0) { if (vertexAttachment->_bones.size() == 0) {
@ -111,7 +110,6 @@ namespace Spine {
} }
// Ensure size and preemptively set count. // Ensure size and preemptively set count.
vertices.ensureCapacity(vertexCount);
vertices.setSize(vertexCount); vertices.setSize(vertexCount);
if (time >= _frames[_frames.size() - 1]) { if (time >= _frames[_frames.size() - 1]) {

View File

@ -44,9 +44,6 @@ namespace Spine {
RTTI_IMPL(EventTimeline, Timeline); RTTI_IMPL(EventTimeline, Timeline);
EventTimeline::EventTimeline(int frameCount) : Timeline() { EventTimeline::EventTimeline(int frameCount) : Timeline() {
_frames.ensureCapacity(frameCount);
_events.ensureCapacity(frameCount);
_frames.setSize(frameCount); _frames.setSize(frameCount);
_events.setSize(frameCount); _events.setSize(frameCount);
} }

View File

@ -29,6 +29,7 @@
*****************************************************************************/ *****************************************************************************/
#include <spine/Extension.h> #include <spine/Extension.h>
#include <spine/String.h>
#include <fstream> #include <fstream>
#include <assert.h> #include <assert.h>
@ -53,22 +54,6 @@ namespace Spine {
// Empty // Empty
} }
char* SpineExtension::_readFile(const char* path, int* length) {
char *data;
FILE *file = fopen(path, "rb");
if (!file) return 0;
fseek(file, 0, SEEK_END);
*length = (int)ftell(file);
fseek(file, 0, SEEK_SET);
data = SpineExtension::alloc<char>(*length, __FILE__, __LINE__);
fread(data, 1, *length, file);
fclose(file);
return data;
}
SpineExtension::SpineExtension() { SpineExtension::SpineExtension() {
// Empty // Empty
} }
@ -110,6 +95,22 @@ namespace Spine {
::free(mem); ::free(mem);
} }
char* DefaultSpineExtension::_readFile(const String &path, int *length) {
char *data;
FILE *file = fopen(path.buffer(), "rb");
if (!file) return 0;
fseek(file, 0, SEEK_END);
*length = (int)ftell(file);
fseek(file, 0, SEEK_SET);
data = SpineExtension::alloc<char>(*length, __FILE__, __LINE__);
fread(data, 1, *length, file);
fclose(file);
return data;
}
DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() { DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() {
// Empty // Empty
} }

View File

@ -51,7 +51,6 @@ namespace Spine {
const int IkConstraintTimeline::BEND_DIRECTION = 2; const int IkConstraintTimeline::BEND_DIRECTION = 2;
IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0) { IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0) {
_frames.ensureCapacity(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES);
} }

View File

@ -29,8 +29,9 @@
*****************************************************************************/ *****************************************************************************/
#include <spine/MeshAttachment.h> #include <spine/MeshAttachment.h>
#include <spine/Color.h>
namespace Spine { namespace Spine {
RTTI_IMPL(MeshAttachment, VertexAttachment); RTTI_IMPL(MeshAttachment, VertexAttachment);
MeshAttachment::MeshAttachment(const String& name) : VertexAttachment(name), MeshAttachment::MeshAttachment(const String& name) : VertexAttachment(name),
@ -49,10 +50,7 @@ namespace Spine {
_regionV2(0), _regionV2(0),
_width(0), _width(0),
_height(0), _height(0),
_r(1), _color(1, 1, 1, 1),
_g(1),
_b(1),
_a(1),
_hullLength(0), _hullLength(0),
_inheritDeform(false), _inheritDeform(false),
_regionRotate(false) { _regionRotate(false) {
@ -62,7 +60,6 @@ namespace Spine {
void MeshAttachment::updateUVs() { void MeshAttachment::updateUVs() {
float u = _regionU, v = _regionV, width = _regionU2 - _regionU, height = _regionV2 - _regionV; float u = _regionU, v = _regionV, width = _regionU2 - _regionU, height = _regionV2 - _regionV;
if (_uvs.size() != _regionUVs.size()) { if (_uvs.size() != _regionUVs.size()) {
_uvs.ensureCapacity(_regionUVs.size());
_uvs.setSize(_regionUVs.size()); _uvs.setSize(_regionUVs.size());
} }
@ -116,38 +113,6 @@ namespace Spine {
_triangles = inValue; _triangles = inValue;
} }
float MeshAttachment::getR() {
return _r;
}
void MeshAttachment::setR(float inValue) {
_r = inValue;
}
float MeshAttachment::getG() {
return _g;
}
void MeshAttachment::setG(float inValue) {
_g = inValue;
}
float MeshAttachment::getB() {
return _b;
}
void MeshAttachment::setB(float inValue) {
_b = inValue;
}
float MeshAttachment::getA() {
return _a;
}
void MeshAttachment::setA(float inValue) {
_a = inValue;
}
const String& MeshAttachment::getPath() { const String& MeshAttachment::getPath() {
return _path; return _path;
} }
@ -302,4 +267,8 @@ namespace Spine {
void MeshAttachment::setHeight(float inValue) { void MeshAttachment::setHeight(float inValue) {
_height = inValue; _height = inValue;
} }
Spine::Color& MeshAttachment::getColor() {
return _color;
}
} }

View File

@ -65,7 +65,6 @@ namespace Spine {
_bones.add(skeleton.findBone(boneData->getName())); _bones.add(skeleton.findBone(boneData->getName()));
} }
_segments.ensureCapacity(10);
_segments.setSize(10); _segments.setSize(10);
} }
@ -96,12 +95,10 @@ namespace Spine {
bool tangents = rotateMode == RotateMode_Tangent, scale = rotateMode == RotateMode_ChainScale; bool tangents = rotateMode == RotateMode_Tangent, scale = rotateMode == RotateMode_ChainScale;
size_t boneCount = _bones.size(); size_t boneCount = _bones.size();
int spacesCount = static_cast<int>(tangents ? boneCount : boneCount + 1); int spacesCount = static_cast<int>(tangents ? boneCount : boneCount + 1);
_spaces.ensureCapacity(spacesCount);
_spaces.setSize(spacesCount); _spaces.setSize(spacesCount);
float spacing = _spacing; float spacing = _spacing;
if (scale || lengthSpacing) { if (scale || lengthSpacing) {
if (scale) { if (scale) {
_lengths.ensureCapacity(boneCount);
_lengths.setSize(boneCount); _lengths.setSize(boneCount);
} }
@ -268,7 +265,6 @@ namespace Spine {
Vector<float> PathConstraint::computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing) { Vector<float> PathConstraint::computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing) {
Slot& target = *_target; Slot& target = *_target;
float position = _position; float position = _position;
_positions.ensureCapacity(spacesCount * 3 + 2);
_positions.setSize(spacesCount * 3 + 2); _positions.setSize(spacesCount * 3 + 2);
bool closed = path.isClosed(); bool closed = path.isClosed();
int verticesLength = path.getWorldVerticesLength(); int verticesLength = path.getWorldVerticesLength();
@ -290,7 +286,6 @@ namespace Spine {
} }
} }
_world.ensureCapacity(8);
_world.setSize(8); _world.setSize(8);
for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) { for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
float space = _spaces[i]; float space = _spaces[i];
@ -362,7 +357,6 @@ namespace Spine {
// World vertices. // World vertices.
if (closed) { if (closed) {
verticesLength += 2; verticesLength += 2;
_world.ensureCapacity(verticesLength);
_world.setSize(verticesLength); _world.setSize(verticesLength);
path.computeWorldVertices(target, 2, verticesLength - 4, _world, 0); path.computeWorldVertices(target, 2, verticesLength - 4, _world, 0);
path.computeWorldVertices(target, 0, 2, _world, verticesLength - 4); path.computeWorldVertices(target, 0, 2, _world, verticesLength - 4);
@ -372,13 +366,11 @@ namespace Spine {
else { else {
curveCount--; curveCount--;
verticesLength -= 4; verticesLength -= 4;
_world.ensureCapacity(verticesLength);
_world.setSize(verticesLength); _world.setSize(verticesLength);
path.computeWorldVertices(target, 2, verticesLength, _world, 0); path.computeWorldVertices(target, 2, verticesLength, _world, 0);
} }
// Curve lengths. // Curve lengths.
_curves.ensureCapacity(curveCount);
_curves.setSize(curveCount); _curves.setSize(curveCount);
pathLength = 0; pathLength = 0;
float x1 = _world[0], y1 = _world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0; float x1 = _world[0], y1 = _world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;

View File

@ -51,7 +51,6 @@ namespace Spine {
const int PathConstraintMixTimeline::TRANSLATE = 2; const int PathConstraintMixTimeline::TRANSLATE = 2;
PathConstraintMixTimeline::PathConstraintMixTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) { PathConstraintMixTimeline::PathConstraintMixTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) {
_frames.ensureCapacity(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES);
} }

View File

@ -49,7 +49,6 @@ namespace Spine {
const int PathConstraintPositionTimeline::VALUE = 1; const int PathConstraintPositionTimeline::VALUE = 1;
PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) { PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) {
_frames.ensureCapacity(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES);
} }

View File

@ -35,6 +35,7 @@
#include <spine/MathUtil.h> #include <spine/MathUtil.h>
#include <assert.h> #include <assert.h>
#include <spine/Color.h>
namespace Spine { namespace Spine {
RTTI_IMPL(RegionAttachment, Attachment); RTTI_IMPL(RegionAttachment, Attachment);
@ -68,13 +69,7 @@ namespace Spine {
_regionV(0), _regionV(0),
_regionU2(0), _regionU2(0),
_regionV2(0), _regionV2(0),
_r(0), _color(1, 1, 1, 1) {
_g(0),
_b(0),
_a(0) {
_offset.ensureCapacity(NUM_UVS);
_uvs.ensureCapacity(NUM_UVS);
_offset.setSize(NUM_UVS); _offset.setSize(NUM_UVS);
_uvs.setSize(NUM_UVS); _uvs.setSize(NUM_UVS);
} }
@ -217,38 +212,6 @@ namespace Spine {
_height = inValue; _height = inValue;
} }
float RegionAttachment::getR() {
return _r;
}
void RegionAttachment::setR(float inValue) {
_r = inValue;
}
float RegionAttachment::getG() {
return _g;
}
void RegionAttachment::setG(float inValue) {
_g = inValue;
}
float RegionAttachment::getB() {
return _b;
}
void RegionAttachment::setB(float inValue) {
_b = inValue;
}
float RegionAttachment::getA() {
return _a;
}
void RegionAttachment::setA(float inValue) {
_a = inValue;
}
const String& RegionAttachment::getPath() { const String& RegionAttachment::getPath() {
return _path; return _path;
} }
@ -320,4 +283,8 @@ namespace Spine {
Vector<float>& RegionAttachment::getUVs() { Vector<float>& RegionAttachment::getUVs() {
return _uvs; return _uvs;
} }
Spine::Color& RegionAttachment::getColor() {
return _color;
}
} }

View File

@ -42,7 +42,6 @@ namespace Spine {
RTTI_IMPL(RotateTimeline, CurveTimeline); RTTI_IMPL(RotateTimeline, CurveTimeline);
RotateTimeline::RotateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0) { RotateTimeline::RotateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0) {
_frames.ensureCapacity(frameCount << 1);
_frames.setSize(frameCount << 1); _frames.setSize(frameCount << 1);
} }

View File

@ -416,7 +416,6 @@ namespace Spine {
verticesLength = 8; verticesLength = 8;
if (outVertexBuffer.size() < 8) { if (outVertexBuffer.size() < 8) {
outVertexBuffer.ensureCapacity(8);
outVertexBuffer.setSize(8); outVertexBuffer.setSize(8);
} }
regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0); regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0);
@ -426,7 +425,6 @@ namespace Spine {
verticesLength = mesh->getWorldVerticesLength(); verticesLength = mesh->getWorldVerticesLength();
if (outVertexBuffer.size() < verticesLength) { if (outVertexBuffer.size() < verticesLength) {
outVertexBuffer.ensureCapacity(verticesLength);
outVertexBuffer.setSize(verticesLength); outVertexBuffer.setSize(verticesLength);
} }

View File

@ -116,6 +116,7 @@ namespace Spine {
SkeletonBinary::~SkeletonBinary() { SkeletonBinary::~SkeletonBinary() {
ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes);
_linkedMeshes.clear();
if (_ownsLoader) { if (_ownsLoader) {
delete _attachmentLoader; delete _attachmentLoader;
@ -154,7 +155,6 @@ namespace Spine {
/* Bones. */ /* Bones. */
int bonesCount = readVarint(input, true); int bonesCount = readVarint(input, true);
skeletonData->_bones.ensureCapacity(bonesCount);
skeletonData->_bones.setSize(bonesCount); skeletonData->_bones.setSize(bonesCount);
for (i = 0; i < bonesCount; ++i) { for (i = 0; i < bonesCount; ++i) {
BoneData* data; BoneData* data;
@ -201,7 +201,6 @@ namespace Spine {
/* Slots. */ /* Slots. */
int slotsCount = readVarint(input, true); int slotsCount = readVarint(input, true);
skeletonData->_slots.ensureCapacity(slotsCount);
skeletonData->_slots.setSize(slotsCount); skeletonData->_slots.setSize(slotsCount);
for (i = 0; i < slotsCount; ++i) { for (i = 0; i < slotsCount; ++i) {
int r, g, b, a; int r, g, b, a;
@ -210,15 +209,14 @@ namespace Spine {
SlotData* slotData = new (__FILE__, __LINE__) SlotData(i, String(slotName, true), *boneData); SlotData* slotData = new (__FILE__, __LINE__) SlotData(i, String(slotName, true), *boneData);
readColor(input, &slotData->_r, &slotData->_g, &slotData->_b, &slotData->_a); readColor(input, slotData->getColor());
r = readByte(input); r = readByte(input);
g = readByte(input); g = readByte(input);
b = readByte(input); b = readByte(input);
a = readByte(input); a = readByte(input);
if (!(r == 0xff && g == 0xff && b == 0xff && a == 0xff)) { if (!(r == 0xff && g == 0xff && b == 0xff && a == 0xff)) {
slotData->_r2 = r / 255.0f; slotData->getDarkColor().set(r / 255.0f, g / 255.0f, b / 255.0f, 0);
slotData->_g2 = g / 255.0f; slotData->setHasDarkColor(true);
slotData->_b2 = b / 255.0f;
} }
slotData->_attachmentName.own(readString(input)); slotData->_attachmentName.own(readString(input));
slotData->_blendMode = static_cast<BlendMode>(readVarint(input, true)); slotData->_blendMode = static_cast<BlendMode>(readVarint(input, true));
@ -228,7 +226,6 @@ namespace Spine {
/* IK constraints. */ /* IK constraints. */
int ikConstraintsCount = readVarint(input, true); int ikConstraintsCount = readVarint(input, true);
skeletonData->_ikConstraints.ensureCapacity(ikConstraintsCount);
skeletonData->_ikConstraints.setSize(ikConstraintsCount); skeletonData->_ikConstraints.setSize(ikConstraintsCount);
for (i = 0; i < ikConstraintsCount; ++i) { for (i = 0; i < ikConstraintsCount; ++i) {
const char* name = readString(input); const char* name = readString(input);
@ -238,7 +235,6 @@ namespace Spine {
data->_order = readVarint(input, true); data->_order = readVarint(input, true);
int bonesCount = readVarint(input, true); int bonesCount = readVarint(input, true);
data->_bones.ensureCapacity(bonesCount);
data->_bones.setSize(bonesCount); data->_bones.setSize(bonesCount);
for (ii = 0; ii < bonesCount; ++ii) { for (ii = 0; ii < bonesCount; ++ii) {
data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; data->_bones[ii] = skeletonData->_bones[readVarint(input, true)];
@ -252,7 +248,6 @@ namespace Spine {
/* Transform constraints. */ /* Transform constraints. */
int transformConstraintsCount = readVarint(input, true); int transformConstraintsCount = readVarint(input, true);
skeletonData->_transformConstraints.ensureCapacity(transformConstraintsCount);
skeletonData->_transformConstraints.setSize(transformConstraintsCount); skeletonData->_transformConstraints.setSize(transformConstraintsCount);
for (i = 0; i < transformConstraintsCount; ++i) { for (i = 0; i < transformConstraintsCount; ++i) {
const char* name = readString(input); const char* name = readString(input);
@ -261,7 +256,6 @@ namespace Spine {
data->_order = readVarint(input, true); data->_order = readVarint(input, true);
int bonesCount = readVarint(input, true); int bonesCount = readVarint(input, true);
data->_bones.ensureCapacity(bonesCount);
data->_bones.setSize(bonesCount); data->_bones.setSize(bonesCount);
for (ii = 0; ii < bonesCount; ++ii) { for (ii = 0; ii < bonesCount; ++ii) {
data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; data->_bones[ii] = skeletonData->_bones[readVarint(input, true)];
@ -285,7 +279,6 @@ namespace Spine {
/* Path constraints */ /* Path constraints */
int pathConstraintsCount = readVarint(input, true); int pathConstraintsCount = readVarint(input, true);
skeletonData->_pathConstraints.ensureCapacity(pathConstraintsCount);
skeletonData->_pathConstraints.setSize(pathConstraintsCount); skeletonData->_pathConstraints.setSize(pathConstraintsCount);
for (i = 0; i < pathConstraintsCount; ++i) { for (i = 0; i < pathConstraintsCount; ++i) {
const char* name = readString(input); const char* name = readString(input);
@ -295,7 +288,6 @@ namespace Spine {
data->_order = readVarint(input, true); data->_order = readVarint(input, true);
int bonesCount = readVarint(input, true); int bonesCount = readVarint(input, true);
data->_bones.ensureCapacity(bonesCount);
data->_bones.setSize(bonesCount); data->_bones.setSize(bonesCount);
for (ii = 0; ii < bonesCount; ++ii) { for (ii = 0; ii < bonesCount; ++ii) {
data->_bones[ii] = skeletonData->_bones[readVarint(input, true)]; data->_bones[ii] = skeletonData->_bones[readVarint(input, true)];
@ -328,7 +320,6 @@ namespace Spine {
++skinsCount; ++skinsCount;
} }
skeletonData->_skins.ensureCapacity(skinsCount);
skeletonData->_skins.setSize(skinsCount); skeletonData->_skins.setSize(skinsCount);
if (skeletonData->_defaultSkin) { if (skeletonData->_defaultSkin) {
@ -362,11 +353,11 @@ namespace Spine {
linkedMesh->_mesh->_parentMesh = static_cast<MeshAttachment*>(parent); linkedMesh->_mesh->_parentMesh = static_cast<MeshAttachment*>(parent);
linkedMesh->_mesh->updateUVs(); linkedMesh->_mesh->updateUVs();
} }
ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes);
_linkedMeshes.clear(); _linkedMeshes.clear();
/* Events. */ /* Events. */
int eventsCount = readVarint(input, true); int eventsCount = readVarint(input, true);
skeletonData->_events.ensureCapacity(eventsCount);
skeletonData->_events.setSize(eventsCount); skeletonData->_events.setSize(eventsCount);
for (i = 0; i < eventsCount; ++i) { for (i = 0; i < eventsCount; ++i) {
const char* name = readString(input); const char* name = readString(input);
@ -380,7 +371,6 @@ namespace Spine {
/* Animations. */ /* Animations. */
int animationsCount = readVarint(input, true); int animationsCount = readVarint(input, true);
skeletonData->_animations.ensureCapacity(animationsCount);
skeletonData->_animations.setSize(animationsCount); skeletonData->_animations.setSize(animationsCount);
for (i = 0; i < animationsCount; ++i) { for (i = 0; i < animationsCount; ++i) {
const char* name = readString(input); const char* name = readString(input);
@ -399,12 +389,12 @@ namespace Spine {
return skeletonData; return skeletonData;
} }
SkeletonData* SkeletonBinary::readSkeletonDataFile(const char* path) { SkeletonData* SkeletonBinary::readSkeletonDataFile(const String& path) {
int length; int length;
SkeletonData* skeletonData; SkeletonData* skeletonData;
const char* binary = SpineExtension::readFile(path, &length); const char* binary = SpineExtension::readFile(path.buffer(), &length);
if (length == 0 || !binary) { if (length == 0 || !binary) {
setError("Unable to read skeleton file: ", path); setError("Unable to read skeleton file: ", path.buffer());
return NULL; return NULL;
} }
skeletonData = readSkeletonData((unsigned char*)binary, length); skeletonData = readSkeletonData((unsigned char*)binary, length);
@ -471,11 +461,11 @@ namespace Spine {
return result; return result;
} }
void SkeletonBinary::readColor(DataInput* input, float *r, float *g, float *b, float *a) { void SkeletonBinary::readColor(DataInput* input, Color& color) {
*r = readByte(input) / 255.0f; color._r = readByte(input) / 255.0f;
*g = readByte(input) / 255.0f; color._g = readByte(input) / 255.0f;
*b = readByte(input) / 255.0f; color._b = readByte(input) / 255.0f;
*a = readByte(input) / 255.0f; color._a = readByte(input) / 255.0f;
} }
int SkeletonBinary::readVarint(DataInput* input, bool optimizePositive) { int SkeletonBinary::readVarint(DataInput* input, bool optimizePositive) {
@ -555,7 +545,7 @@ namespace Spine {
region->_scaleY = readFloat(input); region->_scaleY = readFloat(input);
region->_width = readFloat(input) * _scale; region->_width = readFloat(input) * _scale;
region->_height = readFloat(input) * _scale; region->_height = readFloat(input) * _scale;
readColor(input, &region->_r, &region->_g, &region->_b, &region->_a); readColor(input, region->getColor());
region->updateOffset(); region->updateOffset();
if (freeName) { if (freeName) {
@ -587,7 +577,7 @@ namespace Spine {
} }
mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path)); mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path));
mesh->_path = String(path); mesh->_path = String(path);
readColor(input, &mesh->_r, &mesh->_g, &mesh->_b, &mesh->_a); readColor(input, mesh->getColor());
vertexCount = readVarint(input, true); vertexCount = readVarint(input, true);
Vector<float> float_array = readFloatArray(input, vertexCount << 1, 1); Vector<float> float_array = readFloatArray(input, vertexCount << 1, 1);
mesh->setRegionUVs(float_array); mesh->setRegionUVs(float_array);
@ -624,7 +614,7 @@ namespace Spine {
mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path)); mesh = _attachmentLoader->newMeshAttachment(*skin, String(name), String(path));
mesh->_path = path; mesh->_path = path;
readColor(input, &mesh->_r, &mesh->_g, &mesh->_b, &mesh->_a); readColor(input, mesh->getColor());
skinName = readString(input); skinName = readString(input);
parent = readString(input); parent = readString(input);
mesh->_inheritDeform = readBoolean(input); mesh->_inheritDeform = readBoolean(input);
@ -653,7 +643,6 @@ namespace Spine {
vertexCount = readVarint(input, true); vertexCount = readVarint(input, true);
readVertices(input, static_cast<VertexAttachment*>(path), vertexCount); readVertices(input, static_cast<VertexAttachment*>(path), vertexCount);
int lengthsLength = vertexCount / 3; int lengthsLength = vertexCount / 3;
path->_lengths.ensureCapacity(lengthsLength);
path->_lengths.setSize(lengthsLength); path->_lengths.setSize(lengthsLength);
for (i = 0; i < lengthsLength; ++i) { for (i = 0; i < lengthsLength; ++i) {
path->_lengths[i] = readFloat(input) * _scale; path->_lengths[i] = readFloat(input) * _scale;
@ -741,7 +730,6 @@ namespace Spine {
Vector<float> SkeletonBinary::readFloatArray(DataInput *input, int n, float scale) { Vector<float> SkeletonBinary::readFloatArray(DataInput *input, int n, float scale) {
Vector<float> array; Vector<float> array;
array.ensureCapacity(n);
array.setSize(n); array.setSize(n);
int i; int i;
@ -763,7 +751,6 @@ namespace Spine {
int n = readVarint(input, true); int n = readVarint(input, true);
Vector<short> array; Vector<short> array;
array.ensureCapacity(n);
array.setSize(n); array.setSize(n);
int i; int i;
@ -1079,13 +1066,13 @@ namespace Spine {
int offsetCount = readVarint(input, true); int offsetCount = readVarint(input, true);
Vector<int> drawOrder; Vector<int> drawOrder;
drawOrder.ensureCapacity(slotCount); drawOrder.setSize(slotCount);
for (int ii = slotCount - 1; ii >= 0; --ii) { for (int ii = slotCount - 1; ii >= 0; --ii) {
drawOrder[ii] = -1; drawOrder[ii] = -1;
} }
Vector<int> unchanged; Vector<int> unchanged;
unchanged.ensureCapacity(slotCount - offsetCount); unchanged.setSize(slotCount - offsetCount);
int originalIndex = 0, unchangedIndex = 0; int originalIndex = 0, unchangedIndex = 0;
for (int ii = 0; ii < offsetCount; ++ii) { for (int ii = 0; ii < offsetCount; ++ii) {
int slotIndex = readVarint(input, true); int slotIndex = readVarint(input, true);

View File

@ -78,7 +78,7 @@ namespace Spine {
int count = boundingBox->getWorldVerticesLength(); int count = boundingBox->getWorldVerticesLength();
polygon._count = count; polygon._count = count;
if (polygon._vertices.size() < count) { if (polygon._vertices.size() < count) {
polygon._vertices.ensureCapacity(count); polygon._vertices.setSize(count);
} }
boundingBox->computeWorldVertices(*slot, polygon._vertices); boundingBox->computeWorldVertices(*slot, polygon._vertices);
} }

View File

@ -49,7 +49,6 @@ namespace Spine {
_clipAttachment = clip; _clipAttachment = clip;
int n = clip->getWorldVerticesLength(); int n = clip->getWorldVerticesLength();
_clippingPolygon.ensureCapacity(n);
_clippingPolygon.setSize(n); _clippingPolygon.setSize(n);
clip->computeWorldVertices(slot, 0, n, _clippingPolygon, 0, 2); clip->computeWorldVertices(slot, 0, n, _clippingPolygon, 0, 2);
makeClockwise(_clippingPolygon); makeClockwise(_clippingPolygon);
@ -122,9 +121,7 @@ namespace Spine {
float d = 1 / (d0 * d2 + d1 * (y1 - y3)); float d = 1 / (d0 * d2 + d1 * (y1 - y3));
int clipOutputCount = clipOutputLength >> 1; int clipOutputCount = clipOutputLength >> 1;
clippedVertices.ensureCapacity(s + clipOutputCount * 2);
clippedVertices.setSize(s + clipOutputCount * 2); clippedVertices.setSize(s + clipOutputCount * 2);
_clippedUVs.ensureCapacity(s + clipOutputCount * 2);
_clippedUVs.setSize(s + clipOutputCount * 2); _clippedUVs.setSize(s + clipOutputCount * 2);
for (int ii = 0; ii < clipOutputLength; ii += 2) { for (int ii = 0; ii < clipOutputLength; ii += 2) {
float x = clipOutput[ii], y = clipOutput[ii + 1]; float x = clipOutput[ii], y = clipOutput[ii + 1];
@ -140,7 +137,6 @@ namespace Spine {
} }
s = static_cast<int>(clippedTriangles.size()); s = static_cast<int>(clippedTriangles.size());
clippedTriangles.ensureCapacity(s + 3 * (clipOutputCount - 2));
clippedTriangles.setSize(s + 3 * (clipOutputCount - 2)); clippedTriangles.setSize(s + 3 * (clipOutputCount - 2));
clipOutputCount--; clipOutputCount--;
for (int ii = 1; ii < clipOutputCount; ii++) { for (int ii = 1; ii < clipOutputCount; ii++) {
@ -152,9 +148,7 @@ namespace Spine {
index += clipOutputCount + 1; index += clipOutputCount + 1;
} }
else { else {
clippedVertices.ensureCapacity(s + 3 * 2);
clippedVertices.setSize(s + 3 * 2); clippedVertices.setSize(s + 3 * 2);
_clippedUVs.ensureCapacity(s + 3 * 2);
_clippedUVs.setSize(s + 3 * 2); _clippedUVs.setSize(s + 3 * 2);
clippedVertices[s] = x1; clippedVertices[s] = x1;
clippedVertices[s + 1] = y1; clippedVertices[s + 1] = y1;
@ -171,7 +165,6 @@ namespace Spine {
_clippedUVs[s + 5] = v3; _clippedUVs[s + 5] = v3;
s = static_cast<int>(clippedTriangles.size()); s = static_cast<int>(clippedTriangles.size());
clippedTriangles.ensureCapacity(s + 3);
clippedTriangles.setSize(s + 3); clippedTriangles.setSize(s + 3);
clippedTriangles[s] = index; clippedTriangles[s] = index;
clippedTriangles[s + 1] = index + 1; clippedTriangles[s + 1] = index + 1;
@ -287,7 +280,6 @@ namespace Spine {
} }
} }
else { else {
originalOutput.ensureCapacity(originalOutput.size() - 2);
originalOutput.setSize(originalOutput.size() - 2); originalOutput.setSize(originalOutput.size() - 2);
} }

View File

@ -101,7 +101,7 @@ namespace Spine {
} }
} }
SkeletonData* SkeletonJson::readSkeletonDataFile(const char* path) { SkeletonData* SkeletonJson::readSkeletonDataFile(const String& path) {
int length; int length;
SkeletonData* skeletonData; SkeletonData* skeletonData;
const char* json = SpineExtension::readFile(path, &length); const char* json = SpineExtension::readFile(path, &length);
@ -218,19 +218,21 @@ namespace Spine {
color = Json::getString(slotMap, "color", 0); color = Json::getString(slotMap, "color", 0);
if (color) { if (color) {
data->_r = toColor(color, 0); Color& c = data->getColor();
data->_g = toColor(color, 1); c._r = toColor(color, 0);
data->_b = toColor(color, 2); c._g = toColor(color, 1);
data->_a = toColor(color, 3); c._b = toColor(color, 2);
c._a = toColor(color, 3);
} }
dark = Json::getString(slotMap, "dark", 0); dark = Json::getString(slotMap, "dark", 0);
if (dark) { if (dark) {
data->_r2 = toColor(dark, 0); Color& darkColor = data->getDarkColor();
data->_g2 = toColor(dark, 1); darkColor._r = toColor(dark, 0);
data->_b2 = toColor(dark, 2); darkColor._g = toColor(dark, 1);
data->_a2 = toColor(dark, 3); darkColor._b = toColor(dark, 2);
data->_hasSecondColor = true; darkColor._a = toColor(dark, 3);
data->setHasDarkColor(true);
} }
item = Json::getItem(slotMap, "attachment"); item = Json::getItem(slotMap, "attachment");
@ -504,10 +506,10 @@ namespace Spine {
color = Json::getString(attachmentMap, "color", 0); color = Json::getString(attachmentMap, "color", 0);
if (color) { if (color) {
region->_r = toColor(color, 0); region->getColor()._r = toColor(color, 0);
region->_g = toColor(color, 1); region->getColor()._g = toColor(color, 1);
region->_b = toColor(color, 2); region->getColor()._b = toColor(color, 2);
region->_a = toColor(color, 3); region->getColor()._a = toColor(color, 3);
} }
region->updateOffset(); region->updateOffset();
@ -523,10 +525,10 @@ namespace Spine {
color = Json::getString(attachmentMap, "color", 0); color = Json::getString(attachmentMap, "color", 0);
if (color) { if (color) {
mesh->_r = toColor(color, 0); mesh->getColor()._r = toColor(color, 0);
mesh->_g = toColor(color, 1); mesh->getColor()._g = toColor(color, 1);
mesh->_b = toColor(color, 2); mesh->getColor()._b = toColor(color, 2);
mesh->_a = toColor(color, 3); mesh->getColor()._a = toColor(color, 3);
} }
mesh->_width = Json::getFloat(attachmentMap, "width", 32) * _scale; mesh->_width = Json::getFloat(attachmentMap, "width", 32) * _scale;
@ -652,6 +654,7 @@ namespace Spine {
linkedMesh->_mesh->_parentMesh = static_cast<MeshAttachment*>(parent); linkedMesh->_mesh->_parentMesh = static_cast<MeshAttachment*>(parent);
linkedMesh->_mesh->updateUVs(); linkedMesh->_mesh->updateUVs();
} }
ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes);
_linkedMeshes.clear(); _linkedMeshes.clear();
/* Events. */ /* Events. */
@ -1215,16 +1218,8 @@ namespace Spine {
attachment->setBones(bonesAndWeights._bones); attachment->setBones(bonesAndWeights._bones);
} }
void SkeletonJson::setError(Json* root, const char* value1, const char* value2) { void SkeletonJson::setError(Json* root, const String& value1, const String& value2) {
char message[256]; _error = String(value1 + value2);
int length;
strcpy(message, value1);
length = (int)strlen(value1);
if (value2) {
strncat(message + length, value2, 255 - length);
}
_error = String(message);
delete root; delete root;
} }

View File

@ -40,24 +40,16 @@ namespace Spine {
_data(data), _data(data),
_bone(bone), _bone(bone),
_skeleton(bone.getSkeleton()), _skeleton(bone.getSkeleton()),
_r(1), _color(1, 1, 1, 1),
_g(1), _darkColor(0, 0, 0, 0),
_b(1), _hasDarkColor(false),
_a(1),
_r2(0),
_g2(0),
_b2(0),
_hasSecondColor(false),
_attachment(NULL), _attachment(NULL),
_attachmentTime(0) { _attachmentTime(0) {
setToSetupPose(); setToSetupPose();
} }
void Slot::setToSetupPose() { void Slot::setToSetupPose() {
_r = _data.getR(); _color.set(_data.getColor());
_g = _data.getG();
_b = _data.getB();
_a = _data.getA();
const String& attachmentName = _data.getAttachmentName(); const String& attachmentName = _data.getAttachmentName();
if (attachmentName.length() > 0) { if (attachmentName.length() > 0) {
@ -81,68 +73,20 @@ namespace Spine {
return _skeleton; return _skeleton;
} }
float Slot::getR() { Color& Slot::getColor() {
return _r; return _color;
} }
void Slot::setR(float inValue) { Color& Slot::getDarkColor() {
_r = inValue; return _darkColor;
} }
float Slot::getG() { bool Slot::hasDarkColor() {
return _g; return _hasDarkColor;
} }
void Slot::setG(float inValue) { void Slot::setHasDarkColor(bool inValue) {
_g = inValue; _hasDarkColor = inValue;
}
float Slot::getB() {
return _b;
}
void Slot::setB(float inValue) {
_b = inValue;
}
float Slot::getA() {
return _a;
}
void Slot::setA(float inValue) {
_a = inValue;
}
float Slot::getR2() {
return _r2;
}
void Slot::setR2(float inValue) {
_r2 = inValue;
}
float Slot::getG2() {
return _g2;
}
void Slot::setG2(float inValue) {
_g2 = inValue;
}
float Slot::getB2() {
return _b2;
}
void Slot::setB2(float inValue) {
_b2 = inValue;
}
bool Slot::hasSecondColor() {
return _hasSecondColor;
}
void Slot::setHasSecondColor(bool inValue) {
_hasSecondColor = inValue;
} }
Attachment* Slot::getAttachment() { Attachment* Slot::getAttachment() {

View File

@ -37,15 +37,9 @@ namespace Spine {
_index(index), _index(index),
_name(name), _name(name),
_boneData(boneData), _boneData(boneData),
_r(1), _color(1, 1, 1, 1),
_g(1), _darkColor(0, 0, 0, 0),
_b(1), _hasDarkColor(false),
_a(1),
_r2(0),
_g2(0),
_b2(0),
_a2(1),
_hasSecondColor(false),
_attachmentName(), _attachmentName(),
_blendMode(BlendMode_Normal) { _blendMode(BlendMode_Normal) {
assert(_index >= 0); assert(_index >= 0);
@ -64,68 +58,20 @@ namespace Spine {
return _boneData; return _boneData;
} }
float SlotData::getR() { Color& SlotData::getColor() {
return _r; return _color;
} }
void SlotData::setR(float inValue) { Color& SlotData::getDarkColor() {
_r = inValue; return _darkColor;
} }
float SlotData::getG() { bool SlotData::hasDarkColor() {
return _g; return _hasDarkColor;
} }
void SlotData::setG(float inValue) { void SlotData::setHasDarkColor(bool inValue) {
_g = inValue; _hasDarkColor = inValue;
}
float SlotData::getB() {
return _b;
}
void SlotData::setB(float inValue) {
_b = inValue;
}
float SlotData::getA() {
return _a;
}
void SlotData::setA(float inValue) {
_a = inValue;
}
float SlotData::getR2() {
return _r2;
}
void SlotData::setR2(float inValue) {
_r2 = inValue;
}
float SlotData::getG2() {
return _g2;
}
void SlotData::setG2(float inValue) {
_g2 = inValue;
}
float SlotData::getB2() {
return _b2;
}
void SlotData::setB2(float inValue) {
_b2 = inValue;
}
bool SlotData::hasSecondColor() {
return _hasSecondColor;
}
void SlotData::setHasSecondColor(bool inValue) {
_hasSecondColor = inValue;
} }
const String& SlotData::getAttachmentName() { const String& SlotData::getAttachmentName() {

View File

@ -71,23 +71,22 @@ namespace Spine {
// Time is before first frame. // Time is before first frame.
switch (pose) { switch (pose) {
case MixPose_Setup: case MixPose_Setup:
slot._r = slot._data._r; slot.getColor().set(slot.getData().getColor());
slot._g = slot._data._g; slot.getDarkColor().set(slot.getData().getDarkColor());
slot._b = slot._data._b;
slot._a = slot._data._a;
slot._r2 = slot._data._r2;
slot._g2 = slot._data._g2;
slot._b2 = slot._data._b2;
return; return;
case MixPose_Current: case MixPose_Current: {
slot._r += (slot._r - slot._data._r) * alpha; Color& color = slot.getColor();
slot._g += (slot._g - slot._data._g) * alpha; color._r += (color._r - slot._data.getColor()._r) * alpha;
slot._b += (slot._b - slot._data._b) * alpha; color._g += (color._g - slot._data.getColor()._g) * alpha;
slot._a += (slot._a - slot._data._a) * alpha; color._b += (color._b - slot._data.getColor()._b) * alpha;
slot._r2 += (slot._r2 - slot._data._r2) * alpha; color._a += (color._a - slot._data.getColor()._a) * alpha;
slot._g2 += (slot._g2 - slot._data._g2) * alpha;
slot._b2 += (slot._b2 - slot._data._b2) * alpha; Color& darkColor = slot.getDarkColor();
darkColor._r += (darkColor._r - slot._data.getDarkColor()._r) * alpha;
darkColor._g += (darkColor._g - slot._data.getDarkColor()._g) * alpha;
darkColor._b += (darkColor._b - slot._data.getDarkColor()._b) * alpha;
return; return;
}
case MixPose_CurrentLayered: case MixPose_CurrentLayered:
default: default:
return; return;
@ -130,42 +129,51 @@ namespace Spine {
} }
if (alpha == 1) { if (alpha == 1) {
slot._r = r; Color& color = slot.getColor();
slot._g = g; color._r = r;
slot._b = b; color._g = g;
slot._a = a; color._b = b;
slot._r2 = r2; color._a = a;
slot._g2 = g2;
slot._b2 = b2; Color& darkColor = slot.getDarkColor();
darkColor._r = r2;
darkColor._g = g2;
darkColor._b = b2;
} }
else { else {
float br, bg, bb, ba, br2, bg2, bb2; float br, bg, bb, ba, br2, bg2, bb2;
if (pose == MixPose_Setup) { if (pose == MixPose_Setup) {
br = slot._data._r; br = slot._data.getColor()._r;
bg = slot._data._g; bg = slot._data.getColor()._g;
bb = slot._data._b; bb = slot._data.getColor()._b;
ba = slot._data._a; ba = slot._data.getColor()._a;
br2 = slot._data._r2; br2 = slot._data.getDarkColor()._r;
bg2 = slot._data._g2; bg2 = slot._data.getDarkColor()._g;
bb2 = slot._data._b2; bb2 = slot._data.getDarkColor()._b;
} }
else { else {
br = slot._r; Color& color = slot.getColor();
bg = slot._g; br = color._r;
bb = slot._b; bg = color._g;
ba = slot._a; bb = color._b;
br2 = slot._r2; ba = color._a;
bg2 = slot._g2;
bb2 = slot._b2; Color& darkColor = slot.getDarkColor();
br2 = darkColor._r;
bg2 = darkColor._g;
bb2 = darkColor._b;
} }
slot._r = br + ((r - br) * alpha); Color& color = slot.getColor();
slot._g = bg + ((g - bg) * alpha); color._r = br + ((r - br) * alpha);
slot._b = bb + ((b - bb) * alpha); color._g = bg + ((g - bg) * alpha);
slot._a = ba + ((a - ba) * alpha); color._b = bb + ((b - bb) * alpha);
slot._r2 = br2 + ((r2 - br2) * alpha); color._a = ba + ((a - ba) * alpha);
slot._g2 = bg2 + ((g2 - bg2) * alpha);
slot._b2 = bb2 + ((b2 - bb2) * alpha); Color& darkColor = slot.getDarkColor();
darkColor._r = br2 + ((r2 - br2) * alpha);
darkColor._g = bg2 + ((g2 - bg2) * alpha);
darkColor._b = bb2 + ((b2 - bb2) * alpha);
} }
} }