[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
COMMAND ${CMAKE_COMMAND} -E copy_directory
${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"
#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;
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);
assert(atlas != NULL);
@ -62,7 +53,7 @@ void loadBinary(const char* binaryFile, const char* atlasFile, Atlas* &atlas, Sk
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);
assert(atlas != NULL);
@ -88,25 +79,46 @@ void dispose(Atlas* atlas, SkeletonData* skeletonData, AnimationStateData* state
delete atlas;
}
void reproduceIssue_776() {
Atlas* atlas = NULL;
SkeletonData* skeletonData = NULL;
AnimationStateData* stateData = NULL;
Skeleton* skeleton = NULL;
AnimationState* state = NULL;
struct TestData {
TestData(const String& jsonSkeleton, const String& binarySkeleton, const String& atlas) : _jsonSkeleton(jsonSkeleton), _binarySkeleton(binarySkeleton), _atlas(atlas) { }
loadJson(R_JSON, R_ATLAS, atlas, skeletonData, stateData, skeleton, state);
dispose(atlas, skeletonData, stateData, skeleton, state);
String _jsonSkeleton;
String _binarySkeleton;
String _atlas;
};
loadBinary(R_BINARY, R_ATLAS, atlas, skeletonData, stateData, skeleton, state);
dispose(atlas, skeletonData, stateData, skeleton, state);
void testLoading() {
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) {
TestSpineExtension* ext = new TestSpineExtension();
SpineExtension::setInstance(ext);
reproduceIssue_776();
testLoading();
ext->reportLeaks();
}

View File

@ -98,7 +98,7 @@ namespace Spine {
class Atlas : public SpineObject {
public:
Atlas(const char* path, TextureLoader* textureLoader);
Atlas(const String& path, 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>
namespace Spine {
class String;
class SpineExtension {
public:
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);
}
static char* readFile(const char* path, int* length) {
static char* readFile(const String& path, int* length) {
return getInstance()->_readFile(path, length);
}
@ -73,7 +75,7 @@ namespace Spine {
/// If you provide a spineAllocFunc, you should also provide a spineFreeFunc
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();
@ -94,6 +96,8 @@ namespace Spine {
virtual void* _realloc(void* ptr, size_t size, 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/Vector.h>
#include <spine/Color.h>
namespace Spine {
@ -64,14 +65,7 @@ namespace Spine {
Vector<short>& getTriangles();
void setTriangles(Vector<short>& inValue);
float getR();
void setR(float inValue);
float getG();
void setG(float inValue);
float getB();
void setB(float inValue);
float getA();
void setA(float inValue);
Color& getColor();
const String& getPath();
void setPath(const String& inValue);
@ -143,7 +137,7 @@ namespace Spine {
float _regionV2;
float _width;
float _height;
float _r, _g, _b, _a;
Color _color;
int _hullLength;
bool _inheritDeform;
bool _regionRotate;

View File

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

View File

@ -35,6 +35,7 @@
#include <spine/Vector.h>
#include <spine/SpineObject.h>
#include <spine/String.h>
#include <spine/Color.h>
namespace Spine {
class SkeletonData;
@ -76,7 +77,7 @@ namespace Spine {
SkeletonData* readSkeletonData(const unsigned char* binary, int length);
SkeletonData* readSkeletonDataFile(const char* path);
SkeletonData* readSkeletonDataFile(const String& path);
private:
struct DataInput : public SpineObject {
@ -104,7 +105,7 @@ namespace Spine {
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);

View File

@ -44,6 +44,7 @@ namespace Spine {
class Atlas;
class AttachmentLoader;
class LinkedMesh;
class String;
class SkeletonJson : public SpineObject {
public:
@ -53,7 +54,7 @@ namespace Spine {
~SkeletonJson();
SkeletonData* readSkeletonDataFile(const char* path);
SkeletonData* readSkeletonDataFile(const String& path);
SkeletonData* readSkeletonData(const char* json);
@ -72,7 +73,7 @@ namespace Spine {
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/SpineObject.h>
#include <spine/Color.h>
#include <string>
@ -72,23 +73,11 @@ namespace Spine {
Bone& getBone();
Skeleton& getSkeleton();
float getR();
void setR(float inValue);
float getG();
void setG(float inValue);
float getB();
void setB(float inValue);
float getA();
void setA(float inValue);
float getR2();
void setR2(float inValue);
float getG2();
void setG2(float inValue);
float getB2();
void setB2(float inValue);
bool hasSecondColor();
void setHasSecondColor(bool inValue);
Color& getColor();
Color& getDarkColor();
bool hasDarkColor();
void setHasDarkColor(bool inValue);
/// May be NULL.
Attachment* getAttachment();
@ -104,9 +93,9 @@ namespace Spine {
SlotData& _data;
Bone& _bone;
Skeleton& _skeleton;
float _r, _g, _b, _a;
float _r2, _g2, _b2;
bool _hasSecondColor;
Color _color;
Color _darkColor;
bool _hasDarkColor;
Attachment* _attachment;
float _attachmentTime;
Vector<float> _attachmentVertices;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,6 +29,7 @@
*****************************************************************************/
#include <spine/Extension.h>
#include <spine/String.h>
#include <fstream>
#include <assert.h>
@ -53,22 +54,6 @@ namespace Spine {
// 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() {
// Empty
}
@ -109,6 +94,22 @@ namespace Spine {
void DefaultSpineExtension::_free(void* mem, const char* file, int line) {
::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() {
// Empty

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -35,6 +35,7 @@
#include <spine/MathUtil.h>
#include <assert.h>
#include <spine/Color.h>
namespace Spine {
RTTI_IMPL(RegionAttachment, Attachment);
@ -68,13 +69,7 @@ namespace Spine {
_regionV(0),
_regionU2(0),
_regionV2(0),
_r(0),
_g(0),
_b(0),
_a(0) {
_offset.ensureCapacity(NUM_UVS);
_uvs.ensureCapacity(NUM_UVS);
_color(1, 1, 1, 1) {
_offset.setSize(NUM_UVS);
_uvs.setSize(NUM_UVS);
}
@ -217,38 +212,6 @@ namespace Spine {
_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() {
return _path;
}
@ -320,4 +283,8 @@ namespace Spine {
Vector<float>& RegionAttachment::getUVs() {
return _uvs;
}
Spine::Color& RegionAttachment::getColor() {
return _color;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -49,7 +49,6 @@ namespace Spine {
_clipAttachment = clip;
int n = clip->getWorldVerticesLength();
_clippingPolygon.ensureCapacity(n);
_clippingPolygon.setSize(n);
clip->computeWorldVertices(slot, 0, n, _clippingPolygon, 0, 2);
makeClockwise(_clippingPolygon);
@ -122,9 +121,7 @@ namespace Spine {
float d = 1 / (d0 * d2 + d1 * (y1 - y3));
int clipOutputCount = clipOutputLength >> 1;
clippedVertices.ensureCapacity(s + clipOutputCount * 2);
clippedVertices.setSize(s + clipOutputCount * 2);
_clippedUVs.ensureCapacity(s + clipOutputCount * 2);
_clippedUVs.setSize(s + clipOutputCount * 2);
for (int ii = 0; ii < clipOutputLength; ii += 2) {
float x = clipOutput[ii], y = clipOutput[ii + 1];
@ -140,7 +137,6 @@ namespace Spine {
}
s = static_cast<int>(clippedTriangles.size());
clippedTriangles.ensureCapacity(s + 3 * (clipOutputCount - 2));
clippedTriangles.setSize(s + 3 * (clipOutputCount - 2));
clipOutputCount--;
for (int ii = 1; ii < clipOutputCount; ii++) {
@ -152,9 +148,7 @@ namespace Spine {
index += clipOutputCount + 1;
}
else {
clippedVertices.ensureCapacity(s + 3 * 2);
clippedVertices.setSize(s + 3 * 2);
_clippedUVs.ensureCapacity(s + 3 * 2);
_clippedUVs.setSize(s + 3 * 2);
clippedVertices[s] = x1;
clippedVertices[s + 1] = y1;
@ -171,7 +165,6 @@ namespace Spine {
_clippedUVs[s + 5] = v3;
s = static_cast<int>(clippedTriangles.size());
clippedTriangles.ensureCapacity(s + 3);
clippedTriangles.setSize(s + 3);
clippedTriangles[s] = index;
clippedTriangles[s + 1] = index + 1;
@ -287,7 +280,6 @@ namespace Spine {
}
}
else {
originalOutput.ensureCapacity(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;
SkeletonData* skeletonData;
const char* json = SpineExtension::readFile(path, &length);
@ -218,19 +218,21 @@ namespace Spine {
color = Json::getString(slotMap, "color", 0);
if (color) {
data->_r = toColor(color, 0);
data->_g = toColor(color, 1);
data->_b = toColor(color, 2);
data->_a = toColor(color, 3);
Color& c = data->getColor();
c._r = toColor(color, 0);
c._g = toColor(color, 1);
c._b = toColor(color, 2);
c._a = toColor(color, 3);
}
dark = Json::getString(slotMap, "dark", 0);
if (dark) {
data->_r2 = toColor(dark, 0);
data->_g2 = toColor(dark, 1);
data->_b2 = toColor(dark, 2);
data->_a2 = toColor(dark, 3);
data->_hasSecondColor = true;
Color& darkColor = data->getDarkColor();
darkColor._r = toColor(dark, 0);
darkColor._g = toColor(dark, 1);
darkColor._b = toColor(dark, 2);
darkColor._a = toColor(dark, 3);
data->setHasDarkColor(true);
}
item = Json::getItem(slotMap, "attachment");
@ -504,10 +506,10 @@ namespace Spine {
color = Json::getString(attachmentMap, "color", 0);
if (color) {
region->_r = toColor(color, 0);
region->_g = toColor(color, 1);
region->_b = toColor(color, 2);
region->_a = toColor(color, 3);
region->getColor()._r = toColor(color, 0);
region->getColor()._g = toColor(color, 1);
region->getColor()._b = toColor(color, 2);
region->getColor()._a = toColor(color, 3);
}
region->updateOffset();
@ -523,10 +525,10 @@ namespace Spine {
color = Json::getString(attachmentMap, "color", 0);
if (color) {
mesh->_r = toColor(color, 0);
mesh->_g = toColor(color, 1);
mesh->_b = toColor(color, 2);
mesh->_a = toColor(color, 3);
mesh->getColor()._r = toColor(color, 0);
mesh->getColor()._g = toColor(color, 1);
mesh->getColor()._b = toColor(color, 2);
mesh->getColor()._a = toColor(color, 3);
}
mesh->_width = Json::getFloat(attachmentMap, "width", 32) * _scale;
@ -652,6 +654,7 @@ namespace Spine {
linkedMesh->_mesh->_parentMesh = static_cast<MeshAttachment*>(parent);
linkedMesh->_mesh->updateUVs();
}
ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes);
_linkedMeshes.clear();
/* Events. */
@ -1215,16 +1218,8 @@ namespace Spine {
attachment->setBones(bonesAndWeights._bones);
}
void SkeletonJson::setError(Json* root, const char* value1, const char* value2) {
char message[256];
int length;
strcpy(message, value1);
length = (int)strlen(value1);
if (value2) {
strncat(message + length, value2, 255 - length);
}
_error = String(message);
void SkeletonJson::setError(Json* root, const String& value1, const String& value2) {
_error = String(value1 + value2);
delete root;
}

View File

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

View File

@ -37,15 +37,9 @@ namespace Spine {
_index(index),
_name(name),
_boneData(boneData),
_r(1),
_g(1),
_b(1),
_a(1),
_r2(0),
_g2(0),
_b2(0),
_a2(1),
_hasSecondColor(false),
_color(1, 1, 1, 1),
_darkColor(0, 0, 0, 0),
_hasDarkColor(false),
_attachmentName(),
_blendMode(BlendMode_Normal) {
assert(_index >= 0);
@ -63,69 +57,21 @@ namespace Spine {
BoneData& SlotData::getBoneData() {
return _boneData;
}
float SlotData::getR() {
return _r;
Color& SlotData::getColor() {
return _color;
}
void SlotData::setR(float inValue) {
_r = inValue;
Color& SlotData::getDarkColor() {
return _darkColor;
}
float SlotData::getG() {
return _g;
bool SlotData::hasDarkColor() {
return _hasDarkColor;
}
void SlotData::setG(float inValue) {
_g = 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;
void SlotData::setHasDarkColor(bool inValue) {
_hasDarkColor = inValue;
}
const String& SlotData::getAttachmentName() {

View File

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