From adbf70a033e9a5a212363cb132dfef52a5995856 Mon Sep 17 00:00:00 2001 From: Walzer Date: Wed, 21 Jul 2010 03:13:32 +0000 Subject: [PATCH] issue #7 , implement .cpp --- cocos2dx/base_nodes/CCNode.cpp | 1 + cocos2dx/include/CCLayer.h | 4 +- cocos2dx/include/CCTextureCache.h | 15 +- .../CCLayer.cpp | 179 ++++++++++-------- .../CCTransition.cpp | 37 ++-- cocos2dx/textures/CCTexture2D.cpp | 50 ++--- cocos2dx/textures/CCTextureAtlas.cpp | 18 +- cocos2dx/textures/CCTextureCache.cpp | 79 ++++---- 8 files changed, 203 insertions(+), 180 deletions(-) diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index a0e9ce7063..815ae5c5bc 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "CCNode.h" #include "support/CGPointExtension.h" #include "cocoa/CGGeometry.h" +//#include "CCDirector.h" using namespace std; diff --git a/cocos2dx/include/CCLayer.h b/cocos2dx/include/CCLayer.h index f21275e2c3..68596bf23c 100644 --- a/cocos2dx/include/CCLayer.h +++ b/cocos2dx/include/CCLayer.h @@ -86,8 +86,8 @@ All features from CCLayer are valid, plus the following new features: class CCColorLayer : public CCLayer , public CCRGBAProtocol, public CCBlendProtocol { protected: - GLfloat m_fSquareVertices[4 * 2]; - GLubyte m_cSquareColors[4 * 4]; + GLfloat m_pSquareVertices[4 * 2]; + GLubyte m_pSquareColors[4 * 4]; public: diff --git a/cocos2dx/include/CCTextureCache.h b/cocos2dx/include/CCTextureCache.h index d331ad6ef7..2f21269aa8 100644 --- a/cocos2dx/include/CCTextureCache.h +++ b/cocos2dx/include/CCTextureCache.h @@ -30,8 +30,7 @@ THE SOFTWARE. /// @todo #import //#include "platform/uphone/NSLock.h" #include -#include - +#include "cocoa/NSMutableDictionary.h" class CCTexture2D; class CCAsyncObject; @@ -44,11 +43,14 @@ typedef void (*fpAsyncCallback)(CCTexture2D*, void*); class CCTextureCache : public NSObject { protected: - /// @todo hash_map<*,*> - stdext::hash_map textures; + NSMutableDictionary * m_pTextures; //NSLock *m_pDictLock; //NSLock *m_pContextLock; +private: + + void addImageWithAsyncObject(CCAsyncObject* async); + public: CCTextureCache(); @@ -80,9 +82,8 @@ public: * Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif * @since v0.8 */ - /// @todo -(void) addImageAsync:(string & ) filename target:(id)target selector:(SEL)selector; - - void addImageWithAsyncObject(CCAsyncObject* async); + /// @todo selector + void addImageAsync(string & filename, NSObject*target, fpAsyncCallback func); /** Returns a Texture2D object given an PVRTC RAW filename * If the file image was not previously loaded, it will create a new CCTexture2D diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index 01dd8a0d32..9940792f48 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -23,12 +23,26 @@ THE SOFTWARE. ****************************************************************************/ #include "CCLayer.h" +#include "touch_dispatcher/CCTouchDispatcher.h" +#include // CCLayer CCLayer::CCLayer() { - /// @todo + /// @todo director +// if( (self=[super init]) ) { +// +// CGSize s = [[CCDirector sharedDirector] winSize]; +// anchorPoint_ = ccp(0.5f, 0.5f); +// [self setContentSize:s]; +// self.isRelativeAnchorPoint = NO; +// +// isTouchEnabled = NO; +// isAccelerometerEnabled = NO; +// } +// +// return self; } CCLayer::~CCLayer() @@ -41,7 +55,7 @@ CCLayer::~CCLayer() void CCLayer::registerWithTouchDispatcher() { - /// @todo [[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0]; + CCTouchDispatcher::getSharedDispatcher()->addStandardDelegate(this,0); } @@ -53,6 +67,23 @@ bool CCLayer::getIsTouchEnabled() /// isTouchEnabled setter void CCLayer::setIsTouchEnabled(bool enabled) { + if (m_bIsTouchEnabled != enabled) + { + m_bIsTouchEnabled = enabled; + if (m_bIsRunning) + { + if (enabled) + { + this->registerWithTouchDispatcher(); + } + else + { + /// @todo param this error + //CCTouchDispatcher::getSharedDispatcher()->removeDelegate(this); + } + } + } + /** @todo if( isTouchEnabled != enabled ) { isTouchEnabled = enabled; @@ -189,30 +220,26 @@ CCColorLayer * CCColorLayer::layerWithColor(ccColor4B color) CCColorLayer* CCColorLayer::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) { - /** @todo - if( (self=[super init]) ) { + // default blend function + m_tBlendFunc.src = CC_BLEND_SRC; + m_tBlendFunc.dst = CC_BLEND_DST; - // default blend function - blendFunc_ = (ccBlendFunc) { CC_BLEND_SRC, CC_BLEND_DST }; + m_tColor.r = color.r; + m_tColor.g = color.g; + m_tColor.b = color.b; + m_cOpacity = color.a; - color_.r = color.r; - color_.g = color.g; - color_.b = color.b; - opacity_ = color.a; + for (UINT32 i=0; iupdateColor(); + this->setContentSize(CGSizeMake(width,height)); + return this; } CCColorLayer * CCColorLayer::initWithColor(ccColor4B color) { - /** @todo + /** @todo director CGSize s = [[CCDirector sharedDirector] winSize]; return [self initWithColor:color width:s.width height:s.height];*/ return NULL; @@ -221,65 +248,63 @@ CCColorLayer * CCColorLayer::initWithColor(ccColor4B color) /// override contentSize void CCColorLayer::setContentSize(CGSize size) { - /** @todo - squareVertices[2] = size.width; - squareVertices[5] = size.height; - squareVertices[6] = size.width; - squareVertices[7] = size.height; + m_pSquareVertices[2] = size.width; + m_pSquareVertices[5] = size.height; + m_pSquareVertices[6] = size.width; + m_pSquareVertices[7] = size.height; - [super setContentSize:size];*/ + this->setContentSize(size); } void CCColorLayer::changeWidthAndHeight(GLfloat w ,GLfloat h) { - /// @todo [self setContentSize:CGSizeMake(w,h)]; + this->setContentSize(CGSizeMake(w, h)); } void CCColorLayer::changeWidth(GLfloat w) { -/// @todo [self setContentSize:CGSizeMake(w,contentSize_.height)]; + this->setContentSize(CGSizeMake(w, m_tContentSize.height)); } void CCColorLayer::changeHeight(GLfloat h) { -/// @todo [self setContentSize:CGSizeMake(contentSize_.width,h)]; + this->setContentSize(CGSizeMake(m_tContentSize.width, h)); } void CCColorLayer::updateColor() { - /** @todo - for( NSUInteger i=0; i < sizeof(squareColors) / sizeof(squareColors[0]);i++ ) + for( UINT32 i=0; i < sizeof(m_pSquareColors) / sizeof(m_pSquareColors[0]); i++ ) { if( i % 4 == 0 ) - squareColors[i] = color_.r; + m_pSquareColors[i] = m_tColor.r; else if( i % 4 == 1) - squareColors[i] = color_.g; + m_pSquareColors[i] = m_tColor.g; else if( i % 4 ==2 ) - squareColors[i] = color_.b; + m_pSquareColors[i] = m_tColor.b; else - squareColors[i] = opacity_; - }*/ + m_pSquareColors[i] = m_cOpacity; + } } void CCColorLayer::draw() { - /** @todo + /** @todo*/ // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY // Needed states: GL_VERTEX_ARRAY, GL_COLOR_ARRAY // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); - glVertexPointer(2, GL_FLOAT, 0, squareVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors); + glVertexPointer(2, GL_FLOAT, 0, m_pSquareVertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, m_pSquareColors); - BOOL newBlend = NO; - if( blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST ) { - newBlend = YES; - glBlendFunc(blendFunc_.src, blendFunc_.dst); + bool newBlend = false; + if( m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST ) { + newBlend = true; + glBlendFunc(m_tBlendFunc.src, m_tBlendFunc.dst); } - else if( opacity_ != 255 ) { - newBlend = YES; + else if( m_cOpacity != 255 ) { + newBlend = true; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } @@ -290,7 +315,7 @@ void CCColorLayer::draw() // restore default GL state glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable(GL_TEXTURE_2D);*/ + glEnable(GL_TEXTURE_2D); } @@ -302,73 +327,63 @@ CCMultiplexLayer::CCMultiplexLayer() } CCMultiplexLayer::~CCMultiplexLayer() { - /// @todo + m_pLayers->release(); } CCMultiplexLayer * CCMultiplexLayer::layerWithLayers(CCLayer * layer, ...) { -/** @todo va_list args; + va_list args; va_start(args,layer); - id s = [[[self alloc] initWithLayers: layer vaList:args] autorelease]; + CCMultiplexLayer * pMultiplexLayer = new CCMultiplexLayer(); + pMultiplexLayer->initWithLayers(layer, args); + pMultiplexLayer->autorelease(); va_end(args); - return s;*/ - return NULL; + return pMultiplexLayer; } CCMultiplexLayer * CCMultiplexLayer::initWithLayers(CCLayer *layer, va_list params) { - /** @todo - if( (self=[super init]) ) { + m_pLayers = new NSMutableArray(5); + m_pLayers->retain(); - layers = [[NSMutableArray arrayWithCapacity:5] retain]; + m_pLayers->addObject(layer); - [layers addObject: layer]; - - CCLayer *l = va_arg(params,CCLayer*); - while( l ) { - [layers addObject: l]; - l = va_arg(params,CCLayer*); - } - - enabledLayer = 0; - [self addChild: [layers objectAtIndex: enabledLayer]]; + CCLayer *l = va_arg(params,CCLayer*); + while( l ) { + m_pLayers->addObject(l); + l = va_arg(params,CCLayer*); } - return self;*/ - return NULL; + m_nEnabledLayer = 0; + this->addChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer)); + + return this; } -/** @todo --(void) dealloc -{ - [layers release]; - [super dealloc]; -}*/ void CCMultiplexLayer::switchTo(unsigned int n) { - /** @todo - NSAssert( n < [layers count], @"Invalid index in MultiplexLayer switchTo message" ); + NSAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" ); - [self removeChild: [layers objectAtIndex:enabledLayer] cleanup:YES]; + this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true); - enabledLayer = n; + m_nEnabledLayer = n; - [self addChild: [layers objectAtIndex:n]]; */ + this->addChild(m_pLayers->getObjectAtIndex(n)); } void CCMultiplexLayer::switchToAndReleaseMe(unsigned int n) { - /** @todo - NSAssert( n < [layers count], @"Invalid index in MultiplexLayer switchTo message" ); + NSAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" ); - [self removeChild: [layers objectAtIndex:enabledLayer] cleanup:YES]; + this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true); - [layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]]; + //[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]]; + m_pLayers->replaceObjectAtIndex(m_nEnabledLayer, NULL); - enabledLayer = n; + m_nEnabledLayer = n; - [self addChild: [layers objectAtIndex:n]]; */ + this->addChild(m_pLayers->getObjectAtIndex(n)); } diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp index 9e5d68b9e1..c2ac2a85af 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp @@ -32,7 +32,6 @@ enum { CCTransitionScene::CCTransitionScene() { - /// @todo } CCTransitionScene::~CCTransitionScene() { @@ -42,7 +41,6 @@ CCTransitionScene::~CCTransitionScene() CCTransitionScene * CCTransitionScene::transitionWithDurationAndScene(ccTime t, CCScene *scene) { -/// @todo return [[[self alloc] initWithDuration:t scene:s] autorelease]; CCTransitionScene * pScene = new CCTransitionScene(); pScene->initWithDurationAndScene(t,scene); pScene->autorelease(); @@ -51,7 +49,7 @@ CCTransitionScene * CCTransitionScene::transitionWithDurationAndScene(ccTime t, CCTransitionScene * CCTransitionScene::initWithDurationAndScene(ccTime t, CCScene *scene) { - /** @todo + /** @todo ccdirector NSAssert( s != nil, @"Argument scene must be non-nil"); if( (self=[super init]) ) { @@ -92,29 +90,30 @@ void CCTransitionScene::draw() void CCTransitionScene::finish() { - /** @todo // clean up -// m_pInScene->setIsVisible(true); -// m_pInScene->setPosition(ccp(0,0)); -// m_pInScene->setScale(1.0f); -// m_pInScene->setRotation(0.0f); -// m_pInScene->getCamera()->restore(); -// -// m_pOutScene->setIsVisible(false); -// m_pOutScene->setPosition(ccp(0,0)); -// m_pOutScene->setScale(1.0f); -// m_pOutScene->setRotation(0.0f); -// m_pOutScene->getCamera()->restore(); + m_pInScene->setIsVisible(true); + m_pInScene->setPosition(ccp(0,0)); + m_pInScene->setScale(1.0f); + m_pInScene->setRotation(0.0f); + m_pInScene->getCamera()->restore(); + + m_pOutScene->setIsVisible(false); + m_pOutScene->setPosition(ccp(0,0)); + m_pOutScene->setScale(1.0f); + m_pOutScene->setRotation(0.0f); + m_pOutScene->getCamera()->restore(); - this->schedule(&CCTransitionScene::setNewScene, 0); -// [self schedule:@selector(setNewScene:) interval:0];*/ + //[self schedule:@selector(setNewScene:) interval:0]; + this->schedule(schedule_selector(CCTransitionScene::setNewScene), 0); } void CCTransitionScene::setNewScene(ccTime dt) { - /** @todo - [self unschedule:_cmd]; + /** @todo CCDirector + + //[self unschedule:_cmd]; + this->unschedule(schedule_selector(CCTransitionScene::setNewScene)); CCDirector *director = [CCDirector sharedDirector]; diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index b27b76c5be..c6f4620449 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -520,35 +520,37 @@ CCTexture2D * CCTexture2D::initWithPVRTCData(const void *data, int level, int bp CCTexture2D * CCTexture2D::initWithPVRTCFile(string & file) { - /** @todo - if( ! [[CCConfiguration sharedConfiguration] supportsPVRTC] ) { - CCLOG(@"cocos2d: WARNING: PVRTC images is not supported"); - [self release]; - return nil; - } + if (! CCConfiguration::sharedConfiguration()->isSupportsPVRTC()) + { + CCLOG("cocos2d: WARNING: PVRTC images is not supported"); + this->release(); + return NULL; + } - if( (self = [super init]) ) { - CCPVRTexture *pvr = [[CCPVRTexture alloc] initWithContentsOfFile:file]; - if( pvr ) { - pvr.retainName = YES; // don't dealloc texture on release + CCPVRTexture *pvr = new CCPVRTexture(); + pvr = pvr->initWithContentsOfFile(file); + if( pvr ) + { + pvr->setRetainName(true); // don't dealloc texture on release - _name = pvr.name; // texture id - _maxS = 1.0f; - _maxT = 1.0f; - _width = pvr.width; // width - _height = pvr.height; // height - _size = CGSizeMake(_width, _height); + m_uName = pvr->getName(); // texture id + m_fMaxS = 1.0f; + m_fMaxT = 1.0f; + m_uPixelsWide = pvr->getWidth(); // width + m_uPixelsHigh = pvr->getHeight(); // height + /// be careful : UINT32 to float + m_tContentSize = CGSizeMake((float)m_uPixelsWide, (float)m_uPixelsHigh); - [pvr release]; + pvr->release(); - [self setAntiAliasTexParameters]; - } else { - - CCLOG(@"cocos2d: Couldn't load PVR image"); - [self release]; - return nil; + this->setAntiAliasTexParameters(); + } + else + { + CCLOG("cocos2d: Couldn't load PVR image"); + this->release(); + return NULL; } - }*/ return this; } diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index ad5e8ea4e4..a63ec48973 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -180,9 +180,9 @@ void CCTextureAtlas::initIndices() #if CC_TEXTURE_ATLAS_USES_VBO glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]); - glBufferData(GL_ARRAY_BUFFER, sizeof(ccV3F_C4B_T2F_Quad) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0]) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); #endif // CC_TEXTURE_ATLAS_USES_VBO @@ -212,7 +212,7 @@ void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, UINT32 index) // last object doesn't need to be moved if( remaining > 0) { // tex coordinates - memmove( &m_pQuads[index+1],&m_pQuads[index], sizeof(ccV3F_C4B_T2F_Quad) * remaining ); + memmove( &m_pQuads[index+1],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining ); } m_pQuads[index] = *quad; @@ -236,7 +236,7 @@ void CCTextureAtlas::insertQuadFromIndex(UINT32 oldIndex, UINT32 newIndex) // tex coordinates ccV3F_C4B_T2F_Quad quadsBackup = m_pQuads[oldIndex]; - memmove( &m_pQuads[dst],&m_pQuads[src], sizeof(ccV3F_C4B_T2F_Quad) * howMany ); + memmove( &m_pQuads[dst],&m_pQuads[src], sizeof(m_pQuads[0]) * howMany ); m_pQuads[newIndex] = quadsBackup; } @@ -250,7 +250,7 @@ void CCTextureAtlas::removeQuadAtIndex(UINT32 index) // last object doesn't need to be moved if( remaining ) { // tex coordinates - memmove( &m_pQuads[index],&m_pQuads[index+1], sizeof(ccV3F_C4B_T2F_Quad) * remaining ); + memmove( &m_pQuads[index],&m_pQuads[index+1], sizeof(m_pQuads[0]) * remaining ); } m_uTotalQuads--; @@ -273,8 +273,8 @@ bool CCTextureAtlas::resizeCapacity(UINT32 newCapacity) m_uTotalQuads = MIN(m_uTotalQuads, newCapacity); m_uCapacity = newCapacity; - void * tmpQuads = realloc( m_pQuads, sizeof(ccV3F_C4B_T2F_Quad) * m_uCapacity ); - void * tmpIndices = realloc( m_pIndices, sizeof(GLushort) * m_uCapacity * 6 ); + void * tmpQuads = realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity ); + void * tmpIndices = realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 ); if( ! ( tmpQuads && tmpIndices) ) { CCLOG("cocos2d: CCTextureAtlas: not enough memory"); @@ -313,14 +313,14 @@ void CCTextureAtlas::drawNumberOfQuads(UINT32 n) { glBindTexture(GL_TEXTURE_2D, m_pTexture->getName()); -#define kQuadSize sizeof(ccV3F_C4B_T2F) +#define kQuadSize sizeof(m_pQuads[0].bl) #if CC_TEXTURE_ATLAS_USES_VBO glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]); // XXX: update is done in draw... perhaps it should be done in a timer - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ccV3F_C4B_T2F_Quad) * n, m_pQuads); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(m_pQuads[0]) * n, m_pQuads); // vertices glVertexPointer(3, GL_FLOAT, kQuadSize, (void*) offsetof( ccV3F_C4B_T2F, vertices)); diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 55b0ad1ba1..283c333972 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -22,9 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "CCTextureCache.h" - - #include "CCTextureCache.h" #include "CCTexture2D.h" #include "ccMacros.h" @@ -69,10 +66,13 @@ CCTextureCache * CCTextureCache::sharedTextureCache() CCTextureCache::CCTextureCache() { NSAssert(sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton."); -/** @todo NSMutableDictionary , NSLock - textures = [[NSMutableDictionary dictionaryWithCapacity: 10] retain]; - dictLock = [[NSLock alloc] init]; - contextLock = [[NSLock alloc] init];*/ + + //textures = [[NSMutableDictionary dictionaryWithCapacity: 10] retain]; + m_pTextures = new NSMutableDictionary(); + m_pTextures->retain(); + /** @todo NSLock + dictLock = [[NSLock alloc] init]; + contextLock = [[NSLock alloc] init];*/ } CCTextureCache::~CCTextureCache() @@ -96,14 +96,12 @@ void CCTextureCache::purgeSharedTextureCache() std::string CCTextureCache::description() { - /** @todo CCMutableDictionary - return [NSString stringWithFormat:@"<%@ = %08X | num of textures = %i>", [self class], self, [textures count]]; + /** @todo CCMutableDictionary::count()*/ char des[100]; - sprintf_s(des, 100, "", m_pTextures->count()); + sprintf_s(des, 100, "", m_pTextures->count()); string ret(des); - return ret;*/ - return NULL; + return ret; } @@ -143,30 +141,35 @@ sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]]; [autoreleasepool release];*/ } -/** @todo --(void) addImageAsync: (string & ) filename target:(id)target selector:(SEL)selector +/** @todo selector*/ +void CCTextureCache::addImageAsync(std::string &filename, NSObject *target, fpAsyncCallback func) { - NSAssert(filename != nil, @"TextureCache: fileimage MUST not be nill"); + NSAssert(!filename.empty() , "TextureCache: fileimage MUST not be nill"); // optimization CCTexture2D * tex; - - if( (tex=[textures objectForKey: filename] ) ) { - [target performSelector:selector withObject:tex]; - return; - } - - // schedule the load - - CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init]; - asyncObject.selector = selector; - asyncObject.target = target; - asyncObject.data = filename; - - [NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject]; - [asyncObject release]; -}*/ +// +// if ( (tex = m_pTextures->objectForKey(filename)) ) +// { +// target-> +// } +// +// if( (tex=[textures objectForKey: filename] ) ) { +// [target performSelector:selector withObject:tex]; +// return; +// } +// +// // schedule the load +// +// CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init]; +// asyncObject.selector = selector; +// asyncObject.target = target; +// asyncObject.data = filename; +// +// [NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject]; +// [asyncObject release]; +} CCTexture2D * CCTextureCache::addImage(string & path) { @@ -245,17 +248,19 @@ CCTexture2D * CCTextureCache::addPVRTCImage(string & fileimage) NSAssert(!fileimage.empty(), "TextureCache: fileimage MUST not be nill"); CCTexture2D * tex; -/** @todo - if( (tex=[textures objectForKey: fileimage] ) ) { +/** @todo*/ + if( (tex = m_pTextures->objectForKey(fileimage )) ) + { return tex; } - tex = [[CCTexture2D alloc] initWithPVRTCFile: fileimage]; + tex = new CCTexture2D(); + tex = tex->initWithPVRTCFile(fileimage); if( tex ) - [textures setObject: tex forKey:fileimage]; + m_pTextures-> setObject( tex, fileimage); else - CCLOG(@"cocos2d: Couldn't add PVRTCImage:%@ in CCTextureCache",fileimage); -*/ + CCLOG("cocos2d: Couldn't add PVRTCImage:%s in CCTextureCache",fileimage); + tex->autorelease(); return tex; }