From a165849d6e42780bfad0a40f53d24fa7ea8ddfc5 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sat, 6 Apr 2013 18:27:51 +0200 Subject: [PATCH] Clean up. --- .../src/spine/spine-cocos2d-iphone.h | 1 - .../src/spine/spine-cocos2d-iphone.m | 3 +-- spine-cocos2dx/src/spine/spine-cocos2dx.cpp | 27 ++++++++++--------- spine-cocos2dx/src/spine/spine-cocos2dx.h | 8 +++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.h b/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.h index b3d7ed8d4..7b247416e 100644 --- a/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.h +++ b/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.h @@ -67,7 +67,6 @@ using namespace spine; @interface CCSkeleton : CCNodeRGBA { @private - bool ownsAtlas; bool ownsSkeleton; bool ownsStateData; Atlas* atlas; diff --git a/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m b/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m index 5035a7598..4d4e73b97 100644 --- a/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m +++ b/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m @@ -215,7 +215,6 @@ char* _Util_readFile (const char* path, int* length) { } CCSkeleton* node = [CCSkeleton create:skeletonData]; node->ownsSkeleton = true; - node->ownsAtlas = true; node->atlas = atlas; return node; } @@ -260,7 +259,7 @@ char* _Util_readFile (const char* path, int* length) { - (void) dealloc { if (ownsSkeleton) Skeleton_dispose(skeleton); if (ownsStateData) AnimationStateData_dispose(state->data); - if (ownsAtlas) Atlas_dispose(atlas); + if (atlas) Atlas_dispose(atlas); AnimationState_dispose(state); [super dealloc]; } diff --git a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp index 72edf0147..326a83e38 100644 --- a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp +++ b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp @@ -34,7 +34,7 @@ void _Cocos2dxAtlasPage_dispose (AtlasPage* page) { _AtlasPage_deinit(SUPER(self)); CC_SAFE_RELEASE_NULL(self->texture); - CC_SAFE_RELEASE_NULL(self->atlas); + CC_SAFE_RELEASE_NULL(self->textureAtlas); FREE(page); } @@ -46,8 +46,8 @@ AtlasPage* AtlasPage_create (const char* name, const char* path) { self->texture = CCTextureCache::sharedTextureCache()->addImage(path); self->texture->retain(); - self->atlas = CCTextureAtlas::createWithTexture(self->texture, 4); - self->atlas->retain(); + self->textureAtlas = CCTextureAtlas::createWithTexture(self->texture, 4); + self->textureAtlas->retain(); return SUPER(self); } @@ -92,7 +92,7 @@ CCSkeleton* CCSkeleton::create (const char* skeletonDataFile, const char* atlasF } CCSkeleton* node = create(skeletonData); node->ownsSkeleton = true; - node->ownsAtlas = true; + node->atlas = atlas; return node; } @@ -122,8 +122,9 @@ CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateDat } CCSkeleton::~CCSkeleton () { - Skeleton_dispose(skeleton); + if (ownsSkeleton) Skeleton_dispose(skeleton); if (ownsStateData) AnimationStateData_dispose(state->data); + if (atlas) Atlas_dispose(atlas); AnimationState_dispose(state); } @@ -147,7 +148,7 @@ void CCSkeleton::draw () { quadCount = 0; for (int i = 0, n = skeleton->slotCount; i < n; i++) if (skeleton->slots[i]->attachment) Attachment_draw(skeleton->slots[i]->attachment, skeleton->slots[i]); - if (atlas) atlas->drawNumberOfQuads(quadCount); + if (textureAtlas) textureAtlas->drawNumberOfQuads(quadCount); if (debugSlots) { // Slots. @@ -224,7 +225,7 @@ int CCSkeleton::findSlotIndex (const char* slotName) const { } bool CCSkeleton::setSkin (const char* skinName) { - return (bool)Skeleton_setSkinByName(skeleton, skinName); + return Skeleton_setSkinByName(skeleton, skinName) ? true : false; } Attachment* CCSkeleton::getAttachment (const char* slotName, const char* attachmentName) const { @@ -234,7 +235,7 @@ Attachment* CCSkeleton::getAttachment (int slotIndex, const char* attachmentName return Skeleton_getAttachmentForSlotIndex(skeleton, slotIndex, attachmentName); } bool CCSkeleton::setAttachment (const char* slotName, const char* attachmentName) { - return (bool)Skeleton_setAttachment(skeleton, slotName, attachmentName); + return Skeleton_setAttachment(skeleton, slotName, attachmentName) ? true : false; } // CCBlendProtocol @@ -291,11 +292,11 @@ void _Cocos2dxRegionAttachment_draw (Attachment* attachment, Slot* slot) { quad->br.vertices.y = offset[6] * slot->bone->m10 + offset[7] * slot->bone->m11 + slot->bone->worldY; // cocos2dx doesn't handle batching for us, so we'll just force a single texture per skeleton. - skeleton->node->atlas = self->atlas; - if (self->atlas->getCapacity() <= skeleton->node->quadCount) { - if (!self->atlas->resizeCapacity(self->atlas->getCapacity() * 2)) return; + skeleton->node->textureAtlas = self->textureAtlas; + if (self->textureAtlas->getCapacity() <= skeleton->node->quadCount) { + if (!self->textureAtlas->resizeCapacity(self->textureAtlas->getCapacity() * 2)) return; } - self->atlas->updateQuad(quad, skeleton->node->quadCount++); + self->textureAtlas->updateQuad(quad, skeleton->node->quadCount++); } RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region) { @@ -305,7 +306,7 @@ RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region VTABLE(Attachment, self) ->draw = _Cocos2dxRegionAttachment_draw; Cocos2dxAtlasPage* page = SUB_CAST(Cocos2dxAtlasPage, region->page); - self->atlas = page->atlas; + self->textureAtlas = page->textureAtlas; const CCSize& size = page->texture->getContentSizeInPixels(); float u = region->x / size.width; float u2 = (region->x + region->width) / size.width; diff --git a/spine-cocos2dx/src/spine/spine-cocos2dx.h b/spine-cocos2dx/src/spine/spine-cocos2dx.h index 7e46c5d4c..764d71e26 100644 --- a/spine-cocos2dx/src/spine/spine-cocos2dx.h +++ b/spine-cocos2dx/src/spine/spine-cocos2dx.h @@ -34,7 +34,7 @@ namespace spine { typedef struct { AtlasPage super; cocos2d::CCTexture2D* texture; - cocos2d::CCTextureAtlas* atlas; + cocos2d::CCTextureAtlas* textureAtlas; } Cocos2dxAtlasPage; /**/ @@ -48,9 +48,9 @@ typedef struct { class CCSkeleton: public cocos2d::CCNodeRGBA, public cocos2d::CCBlendProtocol { private: - bool ownsAtlas; bool ownsSkeleton; bool ownsStateData; + Atlas* atlas; public: Skeleton* const skeleton; @@ -59,7 +59,7 @@ public: bool debugSlots; bool debugBones; - cocos2d::CCTextureAtlas* atlas; // All region attachments for a skeleton must use the same texture. + cocos2d::CCTextureAtlas* textureAtlas; // All region attachments for a skeleton must use the same texture. unsigned int quadCount; static CCSkeleton* create (const char* skeletonDataFile, Atlas* atlas, float scale = 1); @@ -112,7 +112,7 @@ public: typedef struct { RegionAttachment super; cocos2d::ccV3F_C4B_T2F_Quad quad; - cocos2d::CCTextureAtlas* atlas; + cocos2d::CCTextureAtlas* textureAtlas; } Cocos2dxRegionAttachment; }