Clean up.

This commit is contained in:
NathanSweet 2013-04-06 18:27:51 +02:00
parent 8b8896bbeb
commit a165849d6e
4 changed files with 19 additions and 20 deletions

View File

@ -67,7 +67,6 @@ using namespace spine;
@interface CCSkeleton : CCNodeRGBA<CCBlendProtocol> { @interface CCSkeleton : CCNodeRGBA<CCBlendProtocol> {
@private @private
bool ownsAtlas;
bool ownsSkeleton; bool ownsSkeleton;
bool ownsStateData; bool ownsStateData;
Atlas* atlas; Atlas* atlas;

View File

@ -215,7 +215,6 @@ char* _Util_readFile (const char* path, int* length) {
} }
CCSkeleton* node = [CCSkeleton create:skeletonData]; CCSkeleton* node = [CCSkeleton create:skeletonData];
node->ownsSkeleton = true; node->ownsSkeleton = true;
node->ownsAtlas = true;
node->atlas = atlas; node->atlas = atlas;
return node; return node;
} }
@ -260,7 +259,7 @@ char* _Util_readFile (const char* path, int* length) {
- (void) dealloc { - (void) dealloc {
if (ownsSkeleton) Skeleton_dispose(skeleton); if (ownsSkeleton) Skeleton_dispose(skeleton);
if (ownsStateData) AnimationStateData_dispose(state->data); if (ownsStateData) AnimationStateData_dispose(state->data);
if (ownsAtlas) Atlas_dispose(atlas); if (atlas) Atlas_dispose(atlas);
AnimationState_dispose(state); AnimationState_dispose(state);
[super dealloc]; [super dealloc];
} }

View File

@ -34,7 +34,7 @@ void _Cocos2dxAtlasPage_dispose (AtlasPage* page) {
_AtlasPage_deinit(SUPER(self)); _AtlasPage_deinit(SUPER(self));
CC_SAFE_RELEASE_NULL(self->texture); CC_SAFE_RELEASE_NULL(self->texture);
CC_SAFE_RELEASE_NULL(self->atlas); CC_SAFE_RELEASE_NULL(self->textureAtlas);
FREE(page); FREE(page);
} }
@ -46,8 +46,8 @@ AtlasPage* AtlasPage_create (const char* name, const char* path) {
self->texture = CCTextureCache::sharedTextureCache()->addImage(path); self->texture = CCTextureCache::sharedTextureCache()->addImage(path);
self->texture->retain(); self->texture->retain();
self->atlas = CCTextureAtlas::createWithTexture(self->texture, 4); self->textureAtlas = CCTextureAtlas::createWithTexture(self->texture, 4);
self->atlas->retain(); self->textureAtlas->retain();
return SUPER(self); return SUPER(self);
} }
@ -92,7 +92,7 @@ CCSkeleton* CCSkeleton::create (const char* skeletonDataFile, const char* atlasF
} }
CCSkeleton* node = create(skeletonData); CCSkeleton* node = create(skeletonData);
node->ownsSkeleton = true; node->ownsSkeleton = true;
node->ownsAtlas = true; node->atlas = atlas;
return node; return node;
} }
@ -122,8 +122,9 @@ CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateDat
} }
CCSkeleton::~CCSkeleton () { CCSkeleton::~CCSkeleton () {
Skeleton_dispose(skeleton); if (ownsSkeleton) Skeleton_dispose(skeleton);
if (ownsStateData) AnimationStateData_dispose(state->data); if (ownsStateData) AnimationStateData_dispose(state->data);
if (atlas) Atlas_dispose(atlas);
AnimationState_dispose(state); AnimationState_dispose(state);
} }
@ -147,7 +148,7 @@ void CCSkeleton::draw () {
quadCount = 0; quadCount = 0;
for (int i = 0, n = skeleton->slotCount; i < n; i++) 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 (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) { if (debugSlots) {
// Slots. // Slots.
@ -224,7 +225,7 @@ int CCSkeleton::findSlotIndex (const char* slotName) const {
} }
bool CCSkeleton::setSkin (const char* skinName) { 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 { 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); return Skeleton_getAttachmentForSlotIndex(skeleton, slotIndex, attachmentName);
} }
bool CCSkeleton::setAttachment (const char* slotName, const char* 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 // 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; 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. // cocos2dx doesn't handle batching for us, so we'll just force a single texture per skeleton.
skeleton->node->atlas = self->atlas; skeleton->node->textureAtlas = self->textureAtlas;
if (self->atlas->getCapacity() <= skeleton->node->quadCount) { if (self->textureAtlas->getCapacity() <= skeleton->node->quadCount) {
if (!self->atlas->resizeCapacity(self->atlas->getCapacity() * 2)) return; 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) { 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; VTABLE(Attachment, self) ->draw = _Cocos2dxRegionAttachment_draw;
Cocos2dxAtlasPage* page = SUB_CAST(Cocos2dxAtlasPage, region->page); Cocos2dxAtlasPage* page = SUB_CAST(Cocos2dxAtlasPage, region->page);
self->atlas = page->atlas; self->textureAtlas = page->textureAtlas;
const CCSize& size = page->texture->getContentSizeInPixels(); const CCSize& size = page->texture->getContentSizeInPixels();
float u = region->x / size.width; float u = region->x / size.width;
float u2 = (region->x + region->width) / size.width; float u2 = (region->x + region->width) / size.width;

View File

@ -34,7 +34,7 @@ namespace spine {
typedef struct { typedef struct {
AtlasPage super; AtlasPage super;
cocos2d::CCTexture2D* texture; cocos2d::CCTexture2D* texture;
cocos2d::CCTextureAtlas* atlas; cocos2d::CCTextureAtlas* textureAtlas;
} Cocos2dxAtlasPage; } Cocos2dxAtlasPage;
/**/ /**/
@ -48,9 +48,9 @@ typedef struct {
class CCSkeleton: public cocos2d::CCNodeRGBA, public cocos2d::CCBlendProtocol { class CCSkeleton: public cocos2d::CCNodeRGBA, public cocos2d::CCBlendProtocol {
private: private:
bool ownsAtlas;
bool ownsSkeleton; bool ownsSkeleton;
bool ownsStateData; bool ownsStateData;
Atlas* atlas;
public: public:
Skeleton* const skeleton; Skeleton* const skeleton;
@ -59,7 +59,7 @@ public:
bool debugSlots; bool debugSlots;
bool debugBones; 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; unsigned int quadCount;
static CCSkeleton* create (const char* skeletonDataFile, Atlas* atlas, float scale = 1); static CCSkeleton* create (const char* skeletonDataFile, Atlas* atlas, float scale = 1);
@ -112,7 +112,7 @@ public:
typedef struct { typedef struct {
RegionAttachment super; RegionAttachment super;
cocos2d::ccV3F_C4B_T2F_Quad quad; cocos2d::ccV3F_C4B_T2F_Quad quad;
cocos2d::CCTextureAtlas* atlas; cocos2d::CCTextureAtlas* textureAtlas;
} Cocos2dxRegionAttachment; } Cocos2dxRegionAttachment;
} }