mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Formatting.
This commit is contained in:
parent
11006baa65
commit
13b3b2e011
@ -34,10 +34,9 @@
|
|||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
|
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Cocos2dTextureLoader textureLoader;
|
Cocos2dTextureLoader textureLoader;
|
||||||
|
|
||||||
int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex);
|
int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex);
|
||||||
@ -49,46 +48,45 @@ namespace spine {
|
|||||||
Color4B ColorToColor4B(const Color& color);
|
Color4B ColorToColor4B(const Color& color);
|
||||||
bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex);
|
bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex);
|
||||||
bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex);
|
bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// C Variable length array
|
// C Variable length array
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// VLA not supported, use _malloca
|
// VLA not supported, use _malloca
|
||||||
#define VLA(type, arr, count) \
|
#define VLA(type, arr, count) \
|
||||||
type* arr = static_cast<type*>( _malloca(sizeof(type) * count) )
|
type* arr = static_cast<type*>( _malloca(sizeof(type) * count) )
|
||||||
#define VLA_FREE(arr) do { _freea(arr); } while(false)
|
#define VLA_FREE(arr) do { _freea(arr); } while(false)
|
||||||
#else
|
#else
|
||||||
#define VLA(type, arr, count) \
|
#define VLA(type, arr, count) \
|
||||||
type arr[count]
|
type arr[count]
|
||||||
#define VLA_FREE(arr)
|
#define VLA_FREE(arr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SkeletonRenderer* SkeletonRenderer::createWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) {
|
||||||
SkeletonRenderer* SkeletonRenderer::createWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) {
|
|
||||||
SkeletonRenderer* node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData);
|
SkeletonRenderer* node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer* SkeletonRenderer::createWithData (SkeletonData* skeletonData, bool ownsSkeletonData) {
|
SkeletonRenderer* SkeletonRenderer::createWithData (SkeletonData* skeletonData, bool ownsSkeletonData) {
|
||||||
SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData);
|
SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) {
|
SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) {
|
||||||
SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlas, scale);
|
SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlas, scale);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
||||||
SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlasFile, scale);
|
SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlasFile, scale);
|
||||||
node->autorelease();
|
node->autorelease();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initialize () {
|
void SkeletonRenderer::initialize () {
|
||||||
_clipper = new (__FILE__, __LINE__) SkeletonClipping();
|
_clipper = new (__FILE__, __LINE__) SkeletonClipping();
|
||||||
|
|
||||||
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
||||||
@ -98,9 +96,9 @@ namespace spine {
|
|||||||
|
|
||||||
_skeleton->setToSetupPose();
|
_skeleton->setToSetupPose();
|
||||||
_skeleton->updateWorldTransform();
|
_skeleton->updateWorldTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setupGLProgramState (bool twoColorTintEnabled) {
|
void SkeletonRenderer::setupGLProgramState (bool twoColorTintEnabled) {
|
||||||
if (twoColorTintEnabled) {
|
if (twoColorTintEnabled) {
|
||||||
#if COCOS2D_VERSION < 0x00040000
|
#if COCOS2D_VERSION < 0x00040000
|
||||||
setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState());
|
setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState());
|
||||||
@ -119,8 +117,7 @@ namespace spine {
|
|||||||
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
||||||
MeshAttachment* meshAttachment = static_cast<MeshAttachment*>(attachment);
|
MeshAttachment* meshAttachment = static_cast<MeshAttachment*>(attachment);
|
||||||
texture = static_cast<AttachmentVertices*>(meshAttachment->getRendererObject())->_texture;
|
texture = static_cast<AttachmentVertices*>(meshAttachment->getRendererObject())->_texture;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,60 +128,60 @@ namespace spine {
|
|||||||
#if COCOS2D_VERSION < 0x00040000
|
#if COCOS2D_VERSION < 0x00040000
|
||||||
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, texture));
|
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, texture));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setSkeletonData (SkeletonData *skeletonData, bool ownsSkeletonData) {
|
void SkeletonRenderer::setSkeletonData (SkeletonData *skeletonData, bool ownsSkeletonData) {
|
||||||
_skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
|
_skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
|
||||||
_ownsSkeletonData = ownsSkeletonData;
|
_ownsSkeletonData = ownsSkeletonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer::SkeletonRenderer ()
|
SkeletonRenderer::SkeletonRenderer ()
|
||||||
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer::SkeletonRenderer(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas)
|
SkeletonRenderer::SkeletonRenderer(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas)
|
||||||
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
||||||
initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData, ownsAtlas);
|
initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData, ownsAtlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer::SkeletonRenderer (SkeletonData *skeletonData, bool ownsSkeletonData)
|
SkeletonRenderer::SkeletonRenderer (SkeletonData *skeletonData, bool ownsSkeletonData)
|
||||||
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
||||||
initWithData(skeletonData, ownsSkeletonData);
|
initWithData(skeletonData, ownsSkeletonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, Atlas* atlas, float scale)
|
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, Atlas* atlas, float scale)
|
||||||
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
||||||
initWithJsonFile(skeletonDataFile, atlas, scale);
|
initWithJsonFile(skeletonDataFile, atlas, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
|
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
|
||||||
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
|
||||||
initWithJsonFile(skeletonDataFile, atlasFile, scale);
|
initWithJsonFile(skeletonDataFile, atlasFile, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonRenderer::~SkeletonRenderer () {
|
SkeletonRenderer::~SkeletonRenderer () {
|
||||||
if (_ownsSkeletonData) delete _skeleton->getData();
|
if (_ownsSkeletonData) delete _skeleton->getData();
|
||||||
if (_ownsSkeleton) delete _skeleton;
|
if (_ownsSkeleton) delete _skeleton;
|
||||||
if (_ownsAtlas && _atlas) delete _atlas;
|
if (_ownsAtlas && _atlas) delete _atlas;
|
||||||
if (_attachmentLoader) delete _attachmentLoader;
|
if (_attachmentLoader) delete _attachmentLoader;
|
||||||
delete _clipper;
|
delete _clipper;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) {
|
void SkeletonRenderer::initWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) {
|
||||||
_skeleton = skeleton;
|
_skeleton = skeleton;
|
||||||
_ownsSkeleton = ownsSkeleton;
|
_ownsSkeleton = ownsSkeleton;
|
||||||
_ownsSkeletonData = ownsSkeletonData;
|
_ownsSkeletonData = ownsSkeletonData;
|
||||||
_ownsAtlas = ownsAtlas;
|
_ownsAtlas = ownsAtlas;
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithData (SkeletonData* skeletonData, bool ownsSkeletonData) {
|
void SkeletonRenderer::initWithData (SkeletonData* skeletonData, bool ownsSkeletonData) {
|
||||||
_ownsSkeleton = true;
|
_ownsSkeleton = true;
|
||||||
setSkeletonData(skeletonData, ownsSkeletonData);
|
setSkeletonData(skeletonData, ownsSkeletonData);
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) {
|
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) {
|
||||||
_atlas = atlas;
|
_atlas = atlas;
|
||||||
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
||||||
|
|
||||||
@ -197,9 +194,9 @@ namespace spine {
|
|||||||
setSkeletonData(skeletonData, true);
|
setSkeletonData(skeletonData, true);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
||||||
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
|
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
|
||||||
CCASSERT(_atlas, "Error reading atlas file.");
|
CCASSERT(_atlas, "Error reading atlas file.");
|
||||||
|
|
||||||
@ -215,9 +212,9 @@ namespace spine {
|
|||||||
setSkeletonData(skeletonData, true);
|
setSkeletonData(skeletonData, true);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) {
|
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) {
|
||||||
_atlas = atlas;
|
_atlas = atlas;
|
||||||
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
|
||||||
|
|
||||||
@ -229,9 +226,9 @@ namespace spine {
|
|||||||
setSkeletonData(skeletonData, true);
|
setSkeletonData(skeletonData, true);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
|
||||||
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
|
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
|
||||||
CCASSERT(_atlas, "Error reading atlas file.");
|
CCASSERT(_atlas, "Error reading atlas file.");
|
||||||
|
|
||||||
@ -246,16 +243,16 @@ namespace spine {
|
|||||||
setSkeletonData(skeletonData, true);
|
setSkeletonData(skeletonData, true);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SkeletonRenderer::update (float deltaTime) {
|
void SkeletonRenderer::update (float deltaTime) {
|
||||||
Node::update(deltaTime);
|
Node::update(deltaTime);
|
||||||
if (_ownsSkeleton) _skeleton->update(deltaTime * _timeScale);
|
if (_ownsSkeleton) _skeleton->update(deltaTime * _timeScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
|
void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
|
||||||
// Early exit if the skeleton is invisible
|
// Early exit if the skeleton is invisible.
|
||||||
if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0) {
|
if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -269,14 +266,14 @@ namespace spine {
|
|||||||
VLA(float, worldCoords, coordCount);
|
VLA(float, worldCoords, coordCount);
|
||||||
transformWorldVertices(worldCoords, coordCount, *_skeleton, _startSlotIndex, _endSlotIndex);
|
transformWorldVertices(worldCoords, coordCount, *_skeleton, _startSlotIndex, _endSlotIndex);
|
||||||
|
|
||||||
#if CC_USE_CULLING
|
#if CC_USE_CULLING
|
||||||
const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2);
|
const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2);
|
||||||
|
|
||||||
if (cullRectangle(renderer, transform, bb)) {
|
if (cullRectangle(renderer, transform, bb)) {
|
||||||
VLA_FREE(worldCoords);
|
VLA_FREE(worldCoords);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const float* worldCoordPtr = worldCoords;
|
const float* worldCoordPtr = worldCoords;
|
||||||
SkeletonBatch* batch = SkeletonBatch::getInstance();
|
SkeletonBatch* batch = SkeletonBatch::getInstance();
|
||||||
@ -337,7 +334,7 @@ namespace spine {
|
|||||||
dstTriangleVertices = reinterpret_cast<float*>(trianglesTwoColor.verts);
|
dstTriangleVertices = reinterpret_cast<float*>(trianglesTwoColor.verts);
|
||||||
dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float);
|
dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float);
|
||||||
}
|
}
|
||||||
// Copy world vertices to triangle vertices
|
// Copy world vertices to triangle vertices.
|
||||||
interleaveCoordinates(dstTriangleVertices, worldCoordPtr, 4, dstStride);
|
interleaveCoordinates(dstTriangleVertices, worldCoordPtr, 4, dstStride);
|
||||||
worldCoordPtr += 8;
|
worldCoordPtr += 8;
|
||||||
|
|
||||||
@ -372,7 +369,7 @@ namespace spine {
|
|||||||
dstVertexCount = trianglesTwoColor.vertCount;
|
dstVertexCount = trianglesTwoColor.vertCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy world vertices to triangle vertices
|
// Copy world vertices to triangle vertices.
|
||||||
//assert(dstVertexCount * 2 == attachment->super.worldVerticesLength);
|
//assert(dstVertexCount * 2 == attachment->super.worldVerticesLength);
|
||||||
interleaveCoordinates(dstTriangleVertices, worldCoordPtr, dstVertexCount, dstStride);
|
interleaveCoordinates(dstTriangleVertices, worldCoordPtr, dstVertexCount, dstStride);
|
||||||
worldCoordPtr += dstVertexCount * 2;
|
worldCoordPtr += dstVertexCount * 2;
|
||||||
@ -398,16 +395,14 @@ namespace spine {
|
|||||||
darkColor.a = darkPremultipliedAlpha;
|
darkColor.a = darkPremultipliedAlpha;
|
||||||
|
|
||||||
color.a *= nodeColor.a * _skeleton->getColor().a * slot->getColor().a;
|
color.a *= nodeColor.a * _skeleton->getColor().a * slot->getColor().a;
|
||||||
// skip rendering if the color of this attachment is 0
|
if (color.a == 0) {
|
||||||
if (color.a == 0){
|
|
||||||
_clipper->clipEnd(*slot);
|
_clipper->clipEnd(*slot);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
color.r *= nodeColor.r * _skeleton->getColor().r * slot->getColor().r;
|
color.r *= nodeColor.r * _skeleton->getColor().r * slot->getColor().r;
|
||||||
color.g *= nodeColor.g * _skeleton->getColor().g * slot->getColor().g;
|
color.g *= nodeColor.g * _skeleton->getColor().g * slot->getColor().g;
|
||||||
color.b *= nodeColor.b * _skeleton->getColor().b * slot->getColor().b;
|
color.b *= nodeColor.b * _skeleton->getColor().b * slot->getColor().b;
|
||||||
if (_premultipliedAlpha)
|
if (_premultipliedAlpha) {
|
||||||
{
|
|
||||||
color.r *= color.a;
|
color.r *= color.a;
|
||||||
color.g *= color.a;
|
color.g *= color.a;
|
||||||
color.b *= color.a;
|
color.b *= color.a;
|
||||||
@ -423,7 +418,7 @@ namespace spine {
|
|||||||
_clipper->clipTriangles((float*)&triangles.verts[0].vertices, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, sizeof(cocos2d::V3F_C4B_T2F) / 4);
|
_clipper->clipTriangles((float*)&triangles.verts[0].vertices, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, sizeof(cocos2d::V3F_C4B_T2F) / 4);
|
||||||
batch->deallocateVertices(triangles.vertCount);
|
batch->deallocateVertices(triangles.vertCount);
|
||||||
|
|
||||||
if (_clipper->getClippedTriangles().size() == 0){
|
if (_clipper->getClippedTriangles().size() == 0) {
|
||||||
_clipper->clipEnd(*slot);
|
_clipper->clipEnd(*slot);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -466,7 +461,7 @@ namespace spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Not clipping
|
// Not clipping.
|
||||||
#if COCOS2D_VERSION < 0x00040000
|
#if COCOS2D_VERSION < 0x00040000
|
||||||
cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
|
cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags);
|
||||||
#else
|
#else
|
||||||
@ -489,13 +484,13 @@ namespace spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Two tints
|
// Two color tinting.
|
||||||
|
|
||||||
if (_clipper->isClipping()) {
|
if (_clipper->isClipping()) {
|
||||||
_clipper->clipTriangles((float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, sizeof(V3F_C4B_C4B_T2F) / 4);
|
_clipper->clipTriangles((float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, sizeof(V3F_C4B_C4B_T2F) / 4);
|
||||||
twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount);
|
twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount);
|
||||||
|
|
||||||
if (_clipper->getClippedTriangles().size() == 0){
|
if (_clipper->getClippedTriangles().size() == 0) {
|
||||||
_clipper->clipEnd(*slot);
|
_clipper->clipEnd(*slot);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -572,13 +567,10 @@ namespace spine {
|
|||||||
if (lastTwoColorTrianglesCommand) {
|
if (lastTwoColorTrianglesCommand) {
|
||||||
Node* parent = this->getParent();
|
Node* parent = this->getParent();
|
||||||
|
|
||||||
// We need to decide if we can postpone flushing the current
|
// We need to decide if we can postpone flushing the current batch. We can postpone if the next sibling node is a two color
|
||||||
// batch. We can postpone if the next sibling node is a
|
// tinted skeleton with the same global-z.
|
||||||
// two color tinted skeleton with the same global-z.
|
// The parent->getChildrenCount() > 100 check is a hack as checking for a sibling is an O(n) operation, and if all children
|
||||||
// The parent->getChildrenCount() > 100 check is a hack
|
// of this nodes parent are skeletons, we are in O(n2) territory.
|
||||||
// as checking for a sibling is an O(n) operation, and if
|
|
||||||
// all children of this nodes parent are skeletons, we
|
|
||||||
// are in O(n2) territory.
|
|
||||||
if (!parent || parent->getChildrenCount() > 100 || getChildrenCount() != 0) {
|
if (!parent || parent->getChildrenCount() > 100 || getChildrenCount() != 0) {
|
||||||
lastTwoColorTrianglesCommand->setForceFlush(true);
|
lastTwoColorTrianglesCommand->setForceFlush(true);
|
||||||
} else {
|
} else {
|
||||||
@ -613,10 +605,10 @@ namespace spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VLA_FREE(worldCoords);
|
VLA_FREE(worldCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) {
|
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) {
|
||||||
|
|
||||||
#if !defined(USE_MATRIX_STACK_PROJECTION_ONLY)
|
#if !defined(USE_MATRIX_STACK_PROJECTION_ONLY)
|
||||||
Director* director = Director::getInstance();
|
Director* director = Director::getInstance();
|
||||||
@ -737,9 +729,9 @@ namespace spine {
|
|||||||
#if !defined(USE_MATRIX_STACK_PROJECTION_ONLY)
|
#if !defined(USE_MATRIX_STACK_PROJECTION_ONLY)
|
||||||
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
cocos2d::Rect SkeletonRenderer::getBoundingBox () const {
|
cocos2d::Rect SkeletonRenderer::getBoundingBox () const {
|
||||||
const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex);
|
const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex);
|
||||||
if (coordCount == 0) return { 0, 0, 0, 0 };
|
if (coordCount == 0) return { 0, 0, 0, 0 };
|
||||||
VLA(float, worldCoords, coordCount);
|
VLA(float, worldCoords, coordCount);
|
||||||
@ -747,152 +739,152 @@ namespace spine {
|
|||||||
const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2);
|
const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2);
|
||||||
VLA_FREE(worldCoords);
|
VLA_FREE(worldCoords);
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Convenience methods for Skeleton_* functions.
|
// --- Convenience methods for Skeleton_* functions.
|
||||||
|
|
||||||
void SkeletonRenderer::updateWorldTransform() {
|
void SkeletonRenderer::updateWorldTransform() {
|
||||||
_skeleton->updateWorldTransform();
|
_skeleton->updateWorldTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setToSetupPose () {
|
void SkeletonRenderer::setToSetupPose () {
|
||||||
_skeleton->setToSetupPose();
|
_skeleton->setToSetupPose();
|
||||||
}
|
}
|
||||||
void SkeletonRenderer::setBonesToSetupPose () {
|
void SkeletonRenderer::setBonesToSetupPose () {
|
||||||
_skeleton->setBonesToSetupPose();
|
_skeleton->setBonesToSetupPose();
|
||||||
}
|
}
|
||||||
void SkeletonRenderer::setSlotsToSetupPose () {
|
void SkeletonRenderer::setSlotsToSetupPose () {
|
||||||
_skeleton->setSlotsToSetupPose();
|
_skeleton->setSlotsToSetupPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bone* SkeletonRenderer::findBone (const std::string& boneName) const {
|
Bone* SkeletonRenderer::findBone (const std::string& boneName) const {
|
||||||
return _skeleton->findBone(boneName.c_str());
|
return _skeleton->findBone(boneName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Slot* SkeletonRenderer::findSlot (const std::string& slotName) const {
|
Slot* SkeletonRenderer::findSlot (const std::string& slotName) const {
|
||||||
return _skeleton->findSlot( slotName.c_str());
|
return _skeleton->findSlot( slotName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setSkin (const std::string& skinName) {
|
void SkeletonRenderer::setSkin (const std::string& skinName) {
|
||||||
_skeleton->setSkin(skinName.empty() ? 0 : skinName.c_str());
|
_skeleton->setSkin(skinName.empty() ? 0 : skinName.c_str());
|
||||||
}
|
}
|
||||||
void SkeletonRenderer::setSkin (const char* skinName) {
|
void SkeletonRenderer::setSkin (const char* skinName) {
|
||||||
_skeleton->setSkin(skinName);
|
_skeleton->setSkin(skinName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Attachment* SkeletonRenderer::getAttachment (const std::string& slotName, const std::string& attachmentName) const {
|
Attachment* SkeletonRenderer::getAttachment (const std::string& slotName, const std::string& attachmentName) const {
|
||||||
return _skeleton->getAttachment(slotName.c_str(), attachmentName.c_str());
|
return _skeleton->getAttachment(slotName.c_str(), attachmentName.c_str());
|
||||||
}
|
}
|
||||||
bool SkeletonRenderer::setAttachment (const std::string& slotName, const std::string& attachmentName) {
|
bool SkeletonRenderer::setAttachment (const std::string& slotName, const std::string& attachmentName) {
|
||||||
bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false;
|
bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false;
|
||||||
_skeleton->setAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str());
|
_skeleton->setAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
bool SkeletonRenderer::setAttachment (const std::string& slotName, const char* attachmentName) {
|
bool SkeletonRenderer::setAttachment (const std::string& slotName, const char* attachmentName) {
|
||||||
bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false;
|
bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false;
|
||||||
_skeleton->setAttachment(slotName.c_str(), attachmentName);
|
_skeleton->setAttachment(slotName.c_str(), attachmentName);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setTwoColorTint(bool enabled) {
|
void SkeletonRenderer::setTwoColorTint(bool enabled) {
|
||||||
#if COCOS2D_VERSION >= 0x00040000
|
#if COCOS2D_VERSION >= 0x00040000
|
||||||
_twoColorTint = enabled;
|
_twoColorTint = enabled;
|
||||||
#endif
|
#endif
|
||||||
setupGLProgramState(enabled);
|
setupGLProgramState(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkeletonRenderer::isTwoColorTint() {
|
bool SkeletonRenderer::isTwoColorTint() {
|
||||||
#if COCOS2D_VERSION < 0x00040000
|
#if COCOS2D_VERSION < 0x00040000
|
||||||
return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState();
|
return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState();
|
||||||
#else
|
#else
|
||||||
return _twoColorTint;
|
return _twoColorTint;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setVertexEffect(VertexEffect *effect) {
|
void SkeletonRenderer::setVertexEffect(VertexEffect *effect) {
|
||||||
this->_effect = effect;
|
this->_effect = effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) {
|
void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) {
|
||||||
_startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex;
|
_startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex;
|
||||||
_endSlotIndex = endSlotIndex == -1 ? std::numeric_limits<int>::max() : endSlotIndex;
|
_endSlotIndex = endSlotIndex == -1 ? std::numeric_limits<int>::max() : endSlotIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* SkeletonRenderer::getSkeleton () const {
|
Skeleton* SkeletonRenderer::getSkeleton () const {
|
||||||
return _skeleton;
|
return _skeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setTimeScale (float scale) {
|
void SkeletonRenderer::setTimeScale (float scale) {
|
||||||
_timeScale = scale;
|
_timeScale = scale;
|
||||||
}
|
}
|
||||||
float SkeletonRenderer::getTimeScale () const {
|
float SkeletonRenderer::getTimeScale () const {
|
||||||
return _timeScale;
|
return _timeScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setDebugSlotsEnabled (bool enabled) {
|
void SkeletonRenderer::setDebugSlotsEnabled (bool enabled) {
|
||||||
_debugSlots = enabled;
|
_debugSlots = enabled;
|
||||||
}
|
}
|
||||||
bool SkeletonRenderer::getDebugSlotsEnabled () const {
|
bool SkeletonRenderer::getDebugSlotsEnabled () const {
|
||||||
return _debugSlots;
|
return _debugSlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setDebugBonesEnabled (bool enabled) {
|
void SkeletonRenderer::setDebugBonesEnabled (bool enabled) {
|
||||||
_debugBones = enabled;
|
_debugBones = enabled;
|
||||||
}
|
}
|
||||||
bool SkeletonRenderer::getDebugBonesEnabled () const {
|
bool SkeletonRenderer::getDebugBonesEnabled () const {
|
||||||
return _debugBones;
|
return _debugBones;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setDebugMeshesEnabled (bool enabled) {
|
void SkeletonRenderer::setDebugMeshesEnabled (bool enabled) {
|
||||||
_debugMeshes = enabled;
|
_debugMeshes = enabled;
|
||||||
}
|
}
|
||||||
bool SkeletonRenderer::getDebugMeshesEnabled () const {
|
bool SkeletonRenderer::getDebugMeshesEnabled () const {
|
||||||
return _debugMeshes;
|
return _debugMeshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setDebugBoundingRectEnabled(bool enabled) {
|
void SkeletonRenderer::setDebugBoundingRectEnabled(bool enabled) {
|
||||||
_debugBoundingRect = enabled;
|
_debugBoundingRect = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkeletonRenderer::getDebugBoundingRectEnabled() const {
|
bool SkeletonRenderer::getDebugBoundingRectEnabled() const {
|
||||||
return _debugBoundingRect;
|
return _debugBoundingRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::onEnter () {
|
void SkeletonRenderer::onEnter () {
|
||||||
#if CC_ENABLE_SCRIPT_BINDING
|
#if CC_ENABLE_SCRIPT_BINDING
|
||||||
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return;
|
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return;
|
||||||
#endif
|
#endif
|
||||||
Node::onEnter();
|
Node::onEnter();
|
||||||
scheduleUpdate();
|
scheduleUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::onExit () {
|
void SkeletonRenderer::onExit () {
|
||||||
#if CC_ENABLE_SCRIPT_BINDING
|
#if CC_ENABLE_SCRIPT_BINDING
|
||||||
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit)) return;
|
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit)) return;
|
||||||
#endif
|
#endif
|
||||||
Node::onExit();
|
Node::onExit();
|
||||||
unscheduleUpdate();
|
unscheduleUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- CCBlendProtocol
|
// --- CCBlendProtocol
|
||||||
|
|
||||||
const BlendFunc& SkeletonRenderer::getBlendFunc () const {
|
const BlendFunc& SkeletonRenderer::getBlendFunc () const {
|
||||||
return _blendFunc;
|
return _blendFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setBlendFunc (const BlendFunc &blendFunc) {
|
void SkeletonRenderer::setBlendFunc (const BlendFunc &blendFunc) {
|
||||||
_blendFunc = blendFunc;
|
_blendFunc = blendFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonRenderer::setOpacityModifyRGB (bool value) {
|
void SkeletonRenderer::setOpacityModifyRGB (bool value) {
|
||||||
_premultipliedAlpha = value;
|
_premultipliedAlpha = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkeletonRenderer::isOpacityModifyRGB () const {
|
bool SkeletonRenderer::isOpacityModifyRGB () const {
|
||||||
return _premultipliedAlpha;
|
return _premultipliedAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount) {
|
cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount) {
|
||||||
assert(coords);
|
assert(coords);
|
||||||
assert(vertexCount > 0);
|
assert(vertexCount > 0);
|
||||||
@ -1077,6 +1069,6 @@ namespace spine {
|
|||||||
Color4B ColorToColor4B(const Color& color) {
|
Color4B ColorToColor4B(const Color& color) {
|
||||||
return { (uint8_t)(color.r * 255.f), (uint8_t)(color.g * 255.f), (uint8_t)(color.b * 255.f), (uint8_t)(color.a * 255.f) };
|
return { (uint8_t)(color.r * 255.f), (uint8_t)(color.g * 255.f), (uint8_t)(color.b * 255.f), (uint8_t)(color.a * 255.f) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user