[cocos2d-x] Cleaned up #716, added #712 manually to fix shared data rendering

This commit is contained in:
badlogic 2016-10-03 13:57:12 +02:00
parent efe0b55dbb
commit 89d9ee00dc
7 changed files with 24 additions and 15 deletions

View File

@ -44,7 +44,7 @@ Scene* GoblinsExample::scene () {
bool GoblinsExample::init () { bool GoblinsExample::init () {
if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;
skeletonNode = SkeletonAnimation::createWithFile("goblins-mesh.json", "goblins.atlas", 1.5f); skeletonNode = SkeletonAnimation::createWithJsonFile("goblins-mesh.json", "goblins.atlas", 1.5f);
skeletonNode->setAnimation(0, "walk", true); skeletonNode->setAnimation(0, "walk", true);
skeletonNode->setSkin("goblin"); skeletonNode->setSkin("goblin");

View File

@ -44,7 +44,7 @@ Scene* RaptorExample::scene () {
bool RaptorExample::init () { bool RaptorExample::init () {
if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;
skeletonNode = SkeletonAnimation::createWithFile("raptor.json", "raptor.atlas", 0.5f); skeletonNode = SkeletonAnimation::createWithJsonFile("raptor.json", "raptor.atlas", 0.5f);
skeletonNode->setAnimation(0, "walk", true); skeletonNode->setAnimation(0, "walk", true);
skeletonNode->setAnimation(1, "empty", false); skeletonNode->setAnimation(1, "empty", false);
skeletonNode->addAnimation(1, "gungrab", false, 2); skeletonNode->addAnimation(1, "gungrab", false, 2);

View File

@ -44,7 +44,7 @@ Scene* SpineboyExample::scene () {
bool SpineboyExample::init () { bool SpineboyExample::init () {
if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;
skeletonNode = SkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas", 0.6f); skeletonNode = SkeletonAnimation::createWithJsonFile("spineboy.json", "spineboy.atlas", 0.6f);
skeletonNode->setStartListener( [this] (int trackIndex) { skeletonNode->setStartListener( [this] (int trackIndex) {
spTrackEntry* entry = spAnimationState_getCurrent(skeletonNode->getState(), trackIndex); spTrackEntry* entry = spAnimationState_getCurrent(skeletonNode->getState(), trackIndex);

View File

@ -44,7 +44,7 @@ Scene* TankExample::scene () {
bool TankExample::init () { bool TankExample::init () {
if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;
skeletonNode = SkeletonAnimation::createWithFile("tank.json", "tank.atlas", 0.5f); skeletonNode = SkeletonAnimation::createWithJsonFile("tank.json", "tank.atlas", 0.5f);
skeletonNode->setAnimation(0, "drive", true); skeletonNode->setAnimation(0, "drive", true);
skeletonNode->setPosition(Vec2(_contentSize.width / 2 + 400, 20)); skeletonNode->setPosition(Vec2(_contentSize.width / 2 + 400, 20));

View File

@ -80,7 +80,7 @@ SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonDa
SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale) { SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale) {
SkeletonAnimation* node = new SkeletonAnimation(); SkeletonAnimation* node = new SkeletonAnimation();
node->initWithJsonFile(skeletonJsonFile, atlas, scale); node->initWithFile(skeletonJsonFile, atlas, scale);
node->autorelease(); node->autorelease();
return node; return node;
} }
@ -88,14 +88,14 @@ SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& ske
SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) { SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) {
SkeletonAnimation* node = new SkeletonAnimation(); SkeletonAnimation* node = new SkeletonAnimation();
spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
node->initWithJsonFile(skeletonJsonFile, atlas, scale); node->initWithFile(skeletonJsonFile, atlas, scale);
node->autorelease(); node->autorelease();
return node; return node;
} }
SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) { SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) {
SkeletonAnimation* node = new SkeletonAnimation(); SkeletonAnimation* node = new SkeletonAnimation();
node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); node->initWithFile(skeletonBinaryFile, atlas, scale);
node->autorelease(); node->autorelease();
return node; return node;
} }
@ -103,7 +103,7 @@ SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& s
SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale) { SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale) {
SkeletonAnimation* node = new SkeletonAnimation(); SkeletonAnimation* node = new SkeletonAnimation();
spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); node->initWithFile(skeletonBinaryFile, atlas, scale);
node->autorelease(); node->autorelease();
return node; return node;
} }
@ -142,8 +142,8 @@ void SkeletonAnimation::update (float deltaTime) {
void SkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) { void SkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) {
CCASSERT(stateData, "stateData cannot be null."); CCASSERT(stateData, "stateData cannot be null.");
if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data);
spAnimationState_dispose(_state); spAnimationState_dispose(_state);
_ownsAnimationStateData = false; _ownsAnimationStateData = false;
_state = spAnimationState_create(stateData); _state = spAnimationState_create(stateData);

View File

@ -81,15 +81,21 @@ namespace spine {
void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState, void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState,
BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags
) { ) {
_command->triangles->verts = triangles.verts; if (_command->triangles->verts) {
free(_command->triangles->verts);
_command->triangles->verts = NULL;
}
_command->triangles->verts = (V3F_C4B_T2F *)malloc(sizeof(V3F_C4B_T2F) * triangles.vertCount);
memcpy(_command->triangles->verts, triangles.verts, sizeof(V3F_C4B_T2F) * triangles.vertCount);
_command->triangles->vertCount = triangles.vertCount; _command->triangles->vertCount = triangles.vertCount;
_command->triangles->indexCount = triangles.indexCount; _command->triangles->indexCount = triangles.indexCount;
_command->triangles->indices = triangles.indices; _command->triangles->indices = triangles.indices;
_command->trianglesCommand->init(globalZOrder, textureID, glProgramState, blendFunc, *_command->triangles, transform); _command->trianglesCommand->init(globalZOrder, textureID, glProgramState, blendFunc, *_command->triangles, transform);
renderer->addCommand(_command->trianglesCommand); renderer->addCommand(_command->trianglesCommand);
if (!_command->next) _command->next = new Command(); if (!_command->next) _command->next = new Command();
_command = _command->next; _command = _command->next;
} }
@ -102,6 +108,9 @@ namespace spine {
} }
SkeletonBatch::Command::~Command () { SkeletonBatch::Command::~Command () {
if (triangles->verts) {
free(triangles->verts);
}
delete triangles; delete triangles;
delete trianglesCommand; delete trianglesCommand;
} }

View File

@ -111,7 +111,7 @@ CC_CONSTRUCTOR_ACCESS:
void initWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); void initWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
void initWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); void initWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
void initialize (); virtual void initialize ();
protected: protected:
void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData); void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData);