From 5d60c2ca0a3cc1fdec8b92df7952dd2f454ca5bd Mon Sep 17 00:00:00 2001 From: Walzer Date: Tue, 20 Jul 2010 05:49:13 +0000 Subject: [PATCH] issue #7, change the use of NSMutableArray --- cocos2dx/base_nodes/CCAtlasNode.cpp | 36 +++++++----- cocos2dx/base_nodes/CCNode.cpp | 33 ++++++----- cocos2dx/cocoa/NSZone.cpp | 2 +- cocos2dx/cocoa/NSZone.h | 2 +- cocos2dx/effects/CCGrid.h | 1 + cocos2dx/include/CCAtlasNode.h | 58 +++---------------- cocos2dx/include/CCLayer.h | 13 ++--- cocos2dx/include/CCNode.h | 8 ++- cocos2dx/include/CCPVRTexture.h | 2 +- cocos2dx/include/CCScene.h | 1 + cocos2dx/include/CCTextureCache.h | 10 ++-- cocos2dx/include/Cocos2dDefine.h | 13 +++-- .../CCScene.cpp | 21 ++++++- cocos2dx/support/TransformUtils.cpp | 2 +- cocos2dx/textures/CCPVRTexture.cpp | 7 ++- cocos2dx/textures/CCTexture2D.cpp | 10 ++-- cocos2dx/textures/CCTextureAtlas.cpp | 6 +- cocos2dx/textures/CCTextureCache.cpp | 30 +++++----- .../CCTouchDelegateProtocol.h | 2 +- cocos2dx/touch_dispatcher/CCTouchDispatcher.h | 2 +- 20 files changed, 130 insertions(+), 129 deletions(-) diff --git a/cocos2dx/base_nodes/CCAtlasNode.cpp b/cocos2dx/base_nodes/CCAtlasNode.cpp index 9a5e67fc79..bab039eb46 100644 --- a/cocos2dx/base_nodes/CCAtlasNode.cpp +++ b/cocos2dx/base_nodes/CCAtlasNode.cpp @@ -59,7 +59,7 @@ CCAtlasNode * CCAtlasNode::initWithTileFile(std::string &tile, int tileWidth, in m_cOpacity = 255; m_tColor = m_tColorUnmodified = ccWHITE; - m_bOpacityModifyRGB = true; + m_bIsOpacityModifyRGB = true; m_tBlendFunc.src = CC_BLEND_SRC; m_tBlendFunc.dst = CC_BLEND_DST; @@ -135,9 +135,9 @@ void CCAtlasNode::draw() // CCAtlasNode - RGBA protocol -ccColor3B CCAtlasNode:: color() +ccColor3B CCAtlasNode:: getColor() { - if(m_bOpacityModifyRGB) + if(m_bIsOpacityModifyRGB) { return m_tColorUnmodified; } @@ -148,7 +148,7 @@ void CCAtlasNode::setColor(ccColor3B color3) { m_tColor = m_tColorUnmodified = color3; - if( m_bOpacityModifyRGB ) + if( m_bIsOpacityModifyRGB ) { m_tColor.r = color3.r * m_cOpacity/255; m_tColor.g = color3.g * m_cOpacity/255; @@ -156,7 +156,7 @@ void CCAtlasNode::setColor(ccColor3B color3) } } -GLubyte CCAtlasNode::opacity() +GLubyte CCAtlasNode::getOpacity() { return m_cOpacity; } @@ -166,29 +166,39 @@ void CCAtlasNode::setOpacity(GLubyte opacity) m_cOpacity = opacity; // special opacity for premultiplied textures - if( m_bOpacityModifyRGB ) - this->setColor(m_bOpacityModifyRGB ? m_tColorUnmodified : m_tColor); + if( m_bIsOpacityModifyRGB ) + this->setColor(m_bIsOpacityModifyRGB ? m_tColorUnmodified : m_tColor); } -void CCAtlasNode::setOpacityModifyRGB(bool bValue) +void CCAtlasNode::setIsOpacityModifyRGB(bool bValue) { ccColor3B oldColor = this->m_tColor; - m_bOpacityModifyRGB = bValue; + m_bIsOpacityModifyRGB = bValue; this->m_tColor = oldColor; } -bool CCAtlasNode::doesOpacityModifyRGB() +bool CCAtlasNode::getIsOpacityModifyRGB() { - return m_bOpacityModifyRGB; + return m_bIsOpacityModifyRGB; } void CCAtlasNode::updateOpacityModifyRGB() { - m_bOpacityModifyRGB = m_pTextureAtlas->getTexture()->getHasPremultipliedAlpha(); + m_bIsOpacityModifyRGB = m_pTextureAtlas->getTexture()->getHasPremultipliedAlpha(); } // CCAtlasNode - CocosNodeTexture protocol +ccBlendFunc CCAtlasNode::getBlendFunc() +{ + return m_tBlendFunc; +} + +void CCAtlasNode::setBlendFunc(ccBlendFunc blendFunc) +{ + m_tBlendFunc = blendFunc; +} + void CCAtlasNode::updateBlendFunc() { if( ! m_pTextureAtlas->getTexture()->getHasPremultipliedAlpha() ) { @@ -204,7 +214,7 @@ void CCAtlasNode::setTexture(CCTexture2D *texture) this->updateOpacityModifyRGB(); } -CCTexture2D * CCAtlasNode::texture() +CCTexture2D * CCAtlasNode::getTexture() { return m_pTextureAtlas->getTexture(); } diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index c095dbd3e3..4df40d151c 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -75,15 +75,15 @@ CCNode::~CCNode() } -void CCNode::arrayMakeObjectsPerformSelector(NSMutableArray * pArray, callbackFunc func) +void CCNode::arrayMakeObjectsPerformSelector(NSMutableArray * pArray, callbackFunc func) { if(pArray && pArray->count() > 0) { CCNode* pNode; - NSMutableArrayIterator it; + NSMutableArray::NSMutableArrayIterator it; for( it = pArray->begin(); it != pArray->end(); it++) { - pNode = static_cast(*it); + pNode = (*it); if(pNode && func) { @@ -203,7 +203,7 @@ void CCNode::setPosition(CGPoint newPosition) } /// children getter -NSMutableArray * CCNode::getChildren() +NSMutableArray * CCNode::getChildren() { return m_pChildren; } @@ -411,7 +411,7 @@ std::string CCNode::description() // lazy allocs void CCNode::childrenAlloc(void) { - m_pChildren = new NSMutableArray(4); + m_pChildren = new NSMutableArray(4); } CCNode* CCNode::getChildByTag(int aTag) @@ -423,10 +423,10 @@ CCNode* CCNode::getChildByTag(int aTag) if(m_pChildren && m_pChildren->count() > 0) { CCNode* pNode; - NSMutableArrayIterator it; + NSMutableArray::NSMutableArrayIterator it; for( it = m_pChildren->begin(); it != m_pChildren->end(); it++) { - pNode = static_cast(*it); + pNode = (*it); if(pNode && pNode->m_nTag == aTag) return pNode; } @@ -506,7 +506,7 @@ void CCNode::removeAllChildrenWithCleanup(bool cleanup) if ( m_pChildren && m_pChildren->count() > 0 ) { CCNode * pNode; - NSMutableArrayIterator it; + NSMutableArray::NSMutableArrayIterator it; for ( it = m_pChildren->begin(); it!= m_pChildren->end(); it++ ) { pNode = static_cast(*it); @@ -561,10 +561,10 @@ void CCNode::insertChild(CCNode* child, int z) if(m_pChildren && m_pChildren->count() > 0) { CCNode* pNode; - NSMutableArrayIterator it; + NSMutableArray::NSMutableArrayIterator it; for( it = m_pChildren->begin(); it != m_pChildren->end(); it++) { - pNode = static_cast(*it); + pNode = (*it); if ( pNode && pNode->m_nZOrder > z ) { @@ -618,10 +618,10 @@ void CCNode::visit() if(m_pChildren && m_pChildren->count() > 0) { CCNode* pNode; - NSMutableArrayIterator it; + NSMutableArray::NSMutableArrayIterator it; for( it = m_pChildren->begin(); it != m_pChildren->end(); it++) { - pNode = static_cast(*it); + pNode = (*it); if ( pNode && pNode->m_nZOrder < 0 ) { @@ -924,13 +924,14 @@ CGPoint CCNode::convertToWorldSpaceAR(CGPoint nodePoint) nodePoint = ccpAdd(nodePoint, m_tAnchorPointInPixels); return this->convertToWorldSpace(nodePoint); } -/** @todo no declare in .h file +/** @todo CCDirector*/ CGPoint CCNode::convertToWindowSpace(CGPoint nodePoint) { - CGPoint worldPoint = [self convertToWorldSpace:nodePoint]; - return [[CCDirector sharedDirector] convertToUI:worldPoint]; -}*/ + CGPoint worldPoint = this->convertToWorldSpace(nodePoint); + //return [[CCDirector sharedDirector] convertToUI:worldPoint]; + return ccp(0,0); +} // convenience methods which take a UITouch instead of CGPoint /** @todo diff --git a/cocos2dx/cocoa/NSZone.cpp b/cocos2dx/cocoa/NSZone.cpp index e47d999707..2d24ad3dd8 100644 --- a/cocos2dx/cocoa/NSZone.cpp +++ b/cocos2dx/cocoa/NSZone.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #include "NSZone.h" -#include "cocoa/NSObject.h" +#include "../cocoa/NSObject.h" NSZone::NSZone(NSObject *pObject) { diff --git a/cocos2dx/cocoa/NSZone.h b/cocos2dx/cocoa/NSZone.h index bd2392d9fd..ed737804e9 100644 --- a/cocos2dx/cocoa/NSZone.h +++ b/cocos2dx/cocoa/NSZone.h @@ -25,7 +25,7 @@ THE SOFTWARE. #ifndef __NS_ZONE_H__ #define __NS_ZONE_H__ -#include "platform/platform.h" +#include "../platform/platform.h" class NSObject; diff --git a/cocos2dx/effects/CCGrid.h b/cocos2dx/effects/CCGrid.h index 9db4195dfe..f8550b217f 100644 --- a/cocos2dx/effects/CCGrid.h +++ b/cocos2dx/effects/CCGrid.h @@ -44,6 +44,7 @@ public: void afterDraw(CCNode *pobTarget); void blit(void); void reuse(void); + bool isActive(void); public: static CCGridBase* gridWithSize(ccGridSize obGridSize, CCTexture2D *pobTexture, bool bFlipped); diff --git a/cocos2dx/include/CCAtlasNode.h b/cocos2dx/include/CCAtlasNode.h index aa085ebb3f..c323fdb455 100644 --- a/cocos2dx/include/CCAtlasNode.h +++ b/cocos2dx/include/CCAtlasNode.h @@ -59,13 +59,14 @@ protected: ccColor3B m_tColorUnmodified; - // protocol variables - bool m_bOpacityModifyRGB; - ccBlendFunc m_tBlendFunc; - GLubyte m_cOpacity; - ccColor3B m_tColor; CCTextureAtlas * m_pTextureAtlas; + // protocol variables + CCX_PROPERTY(bool, m_bIsOpacityModifyRGB, IsOpacityModifyRGB) + CCX_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc); + CCX_PROPERTY(GLubyte, m_cOpacity, Opacity); + CCX_PROPERTY(ccColor3B, m_tColor, Color); + public: CCAtlasNode(); ~CCAtlasNode(); @@ -83,55 +84,10 @@ public: virtual void draw(); -public: - // CC RGBA protocol - - /** sets Color - @since v0.8 - */ - virtual void setColor(ccColor3B color); - - /** returns the color - @since v0.8 - */ - virtual ccColor3B color(void); - - // returns the opacity - virtual GLubyte opacity(void); - - /** sets the opacity. - @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed. - Values goes from 0 to 255, where 255 means fully opaque. - */ - virtual void setOpacity(GLubyte opacity); - - // optional - - /** sets the premultipliedAlphaOpacity property. - If set to NO then opacity will be applied as: glColor(R,G,B,opacity); - If set to YES then oapcity will be applied as: glColor(opacity, opacity, opacity, opacity ); - Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO - @since v0.8 - */ - virtual void setOpacityModifyRGB(bool bValue); - - /** returns whether or not the opacity will be applied using glColor(R,G,B,opacity) or glColor(opacity, opacity, opacity, opacity); - @since v0.8 - */ - virtual bool doesOpacityModifyRGB(void); - - // CC Blend protocol - - // set the source blending function for the texture - virtual void setBlendFunc(ccBlendFunc blendFunc); - - // returns the blending function used for the texture - virtual ccBlendFunc blendFunc(void); - // CC Texture protocol // returns the used texture - virtual CCTexture2D* texture(void); + virtual CCTexture2D* getTexture(void); // sets a new texture. it will be retained virtual void setTexture(CCTexture2D *texture); diff --git a/cocos2dx/include/CCLayer.h b/cocos2dx/include/CCLayer.h index 16e6c4d390..3398bb3d51 100644 --- a/cocos2dx/include/CCLayer.h +++ b/cocos2dx/include/CCLayer.h @@ -27,9 +27,9 @@ THE SOFTWARE. #include "Cocos2dDefine.h" #include "CCNode.h" -/// @todo CCTexture2D.h -//#include "CCProtocols.h" - +#include "CCTexture2D.h" +#include "CCProtocols.h" +#include "../touch_dispatcher/CCTouchDelegateProtocol.h" // // CCLayer // @@ -40,7 +40,7 @@ All features from CCNode are valid, plus the following new features: - It can receive Accelerometer input */ /// @todo public UIAccelerometerDelegate, public CCStandardTouchDelegate, public CCTargetedTouchDelegate -class CCLayer : public CCNode//, public UIAccelerometerDelegate, public CCStandardTouchDelegate, public CCTargetedTouchDelegate +class CCLayer : public CCNode, public CCStandardTouchDelegate, public CCTargetedTouchDelegate//, public UIAccelerometerDelegate { public: CCLayer(); @@ -83,8 +83,7 @@ All features from CCLayer are valid, plus the following new features: - opacity - RGB colors */ -/// @todo public CCRGBAProtocol, public CCBlendProtocol -class CCColorLayer : public CCLayer //, public CCRGBAProtocol, public CCBlendProtocol +class CCColorLayer : public CCLayer , public CCRGBAProtocol, public CCBlendProtocol { protected: GLfloat m_fSquareVertices[4 * 2]; @@ -137,7 +136,7 @@ class CCMultiplexLayer : public CCLayer { protected: unsigned int m_nEnabledLayer; - NSMutableArray * m_pLayers; + NSMutableArray * m_pLayers; public: CCMultiplexLayer(); diff --git a/cocos2dx/include/CCNode.h b/cocos2dx/include/CCNode.h index 73d8c68630..84d16804cc 100644 --- a/cocos2dx/include/CCNode.h +++ b/cocos2dx/include/CCNode.h @@ -96,7 +96,7 @@ Camera: - Each node has a camera. By default it points to the center of the CCNode. */ -class CCNode : public NSObject, public SelectorProtocol +class CCNode : virtual public NSObject, public SelectorProtocol { // variable property @@ -129,7 +129,7 @@ class CCNode : public NSObject, public SelectorProtocol /** Position (x,y) of the node in OpenGL coordinates. (0,0) is the left-bottom corner. */ CCX_PROPERTY(CGPoint, m_tPosition, Position) - CCX_PROPERTY_READONLY(NSMutableArray *, m_pChildren, Children) + CCX_PROPERTY_READONLY(NSMutableArray *, m_pChildren, Children) /** A CCCamera object that lets you move the node using a gluLookAt */ @@ -211,7 +211,9 @@ private: typedef void (CCNode::*callbackFunc)(void); - void arrayMakeObjectsPerformSelector(NSMutableArray * pArray, callbackFunc func); + void arrayMakeObjectsPerformSelector(NSMutableArray * pArray, callbackFunc func); + + CGPoint convertToWindowSpace(CGPoint nodePoint); public: diff --git a/cocos2dx/include/CCPVRTexture.h b/cocos2dx/include/CCPVRTexture.h index 9486b75d2f..4780a0db3a 100644 --- a/cocos2dx/include/CCPVRTexture.h +++ b/cocos2dx/include/CCPVRTexture.h @@ -40,7 +40,7 @@ THE SOFTWARE. class CCPVRTexture : public NSObject { protected: - NSMutableArray * m_pImageData; + NSMutableArray * m_pImageData; public: diff --git a/cocos2dx/include/CCScene.h b/cocos2dx/include/CCScene.h index 7788f592fb..1152581245 100644 --- a/cocos2dx/include/CCScene.h +++ b/cocos2dx/include/CCScene.h @@ -43,6 +43,7 @@ class CCScene : public CCNode public: CCScene(); virtual ~CCScene(); + bool init(); }; #endif // __CCSCENE_H__ diff --git a/cocos2dx/include/CCTextureCache.h b/cocos2dx/include/CCTextureCache.h index 50f4ae68ba..cd1075d36c 100644 --- a/cocos2dx/include/CCTextureCache.h +++ b/cocos2dx/include/CCTextureCache.h @@ -28,7 +28,9 @@ THE SOFTWARE. #include "../cocoa/NSObject.h" /// @todo #import /// @todo #import +//#include "../platform/uphone/NSLock.h" #include +#include class CCTexture2D; @@ -42,10 +44,10 @@ typedef void (*fpAsyncCallback)(CCTexture2D*, void*); class CCTextureCache : public NSObject { protected: - /** @todo NSMutableDictionary, NSLock - NSMutableDictionary *textures; - NSLock *dictLock; - NSLock *contextLock;*/ + /// @todo hash_map<*,*> + stdext::hash_map textures; + //NSLock *m_pDictLock; + //NSLock *m_pContextLock; public: diff --git a/cocos2dx/include/Cocos2dDefine.h b/cocos2dx/include/Cocos2dDefine.h index 240fa26c77..247300ec37 100644 --- a/cocos2dx/include/Cocos2dDefine.h +++ b/cocos2dx/include/Cocos2dDefine.h @@ -88,13 +88,14 @@ THE SOFTWARE. #define CCX_SAFE_RETAIN(p) if(p) { p->retain(); } #ifdef _DEBUG -#include "assert.h" +#include +#include #define NSAssert(_CONDITION, _TXT)\ - if(! (_CONDITION) ) \ - { \ - printf( (_TXT) ); \ - assert( (_CONDITION) ); \ - } + if(! (_CONDITION) ) \ + { \ + printf( (_TXT) ); \ + assert( (_CONDITION) ); \ + } #else #define NSAssert(_CONDITION, _TXT) #endif diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp index 78046aa582..eb65b9de59 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCScene.cpp @@ -23,14 +23,33 @@ THE SOFTWARE. ****************************************************************************/ #include "CCScene.h" +#include "../support/CGPointExtension.h" +//#include "../CCDirector.h" CCScene::CCScene() { -/// @todo + this->m_bIsRelativeAnchorPoint = false; + m_tAnchorPoint = ccp(0.5f, 0.5f); } CCScene::~CCScene() { /// @todo } + +bool CCScene::init() +{ + /// @todo CCDirector + bool bRet = false; +// do +// { +// CCDirector * pDirector; +// CCX_BREAK_IF( ! (pDirector = CCDirector::getSharedDirector()) ); +// this->setContentSize(pDirector->getWinSize()); +// // success +// bRet = true; +// } while (0); +// + return bRet; +} diff --git a/cocos2dx/support/TransformUtils.cpp b/cocos2dx/support/TransformUtils.cpp index 74f01d524b..65091ec934 100644 --- a/cocos2dx/support/TransformUtils.cpp +++ b/cocos2dx/support/TransformUtils.cpp @@ -23,7 +23,7 @@ THE SOFTWARE. ****************************************************************************/ #include "TransformUtils.h" -#include "cocoa/CGAffineTransform.h" +#include "../cocoa/CGAffineTransform.h" void CGAffineToGL(const CGAffineTransform *t, GLfloat *m) { diff --git a/cocos2dx/textures/CCPVRTexture.cpp b/cocos2dx/textures/CCPVRTexture.cpp index 146fe45432..f7bd3df27c 100644 --- a/cocos2dx/textures/CCPVRTexture.cpp +++ b/cocos2dx/textures/CCPVRTexture.cpp @@ -25,6 +25,9 @@ THE SOFTWARE. #include "CCPVRTexture.h" #include "ccMacros.h" +using namespace std; + + #define PVR_TEXTURE_FLAG_TYPE_MASK 0xff static char* gPVRTexIdentifier[] = {"PVR!"}; @@ -230,7 +233,7 @@ bool CCPVRTexture::createGLTexture() } -CCPVRTexture * CCPVRTexture::initWithContentsOfFile(NSString *path) +CCPVRTexture * CCPVRTexture::initWithContentsOfFile(string & path) { /** @todo if((self = [super init])) @@ -270,7 +273,7 @@ CCPVRTexture * CCPVRTexture::initWithContentsOfFile(NSString *path) }*/ -CCPVRTexture * CCPVRTexture::pvrTextureWithContentsOfFile(NSString * path) +CCPVRTexture * CCPVRTexture::pvrTextureWithContentsOfFile(string & path) { CCPVRTexture * pTexture = new CCPVRTexture(); pTexture->initWithContentsOfFile(path); diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index e5325c88f5..530f5b1238 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -35,9 +35,11 @@ THE SOFTWARE. #include "ccConfig.h" #include "ccMacros.h" #include "CCTexture2D.h" -/// @todo #include "CCPVRTexture.h" +#include "CCPVRTexture.h" #include "../CCConfiguration.h" +using namespace std; + #if CC_FONT_LABEL_SUPPORT // FontLabel support @@ -349,7 +351,7 @@ return self; }*/ // implementation CCTexture2D (Text) -CCTexture2D * CCTexture2D::initWithString(NSString *str, NSString *fontName, GLfloat fontSize) +CCTexture2D * CCTexture2D::initWithString(string & str, string & fontName, GLfloat fontSize) { /** @todo CGSize dim; @@ -365,7 +367,7 @@ CCTexture2D * CCTexture2D::initWithString(NSString *str, NSString *fontName, GLf return [self initWithString:string dimensions:dim alignment:UITextAlignmentCenter fontName:name fontSize:size]; } - - (id) initWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size + - (id) initWithString:(string & )string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(string & )name fontSize:(CGFloat)size { NSUInteger width, height, @@ -516,7 +518,7 @@ CCTexture2D * CCTexture2D::initWithPVRTCData(const void *data, int level, int bp return this; } -CCTexture2D * CCTexture2D::initWithPVRTCFile(NSString* file) +CCTexture2D * CCTexture2D::initWithPVRTCFile(string & file) { /** @todo if( ! [[CCConfiguration sharedConfiguration] supportsPVRTC] ) { diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 3ed7f575e6..ad5e8ea4e4 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -35,6 +35,8 @@ THE SOFTWARE. // implementation CCTextureAtlas +using namespace std; + CCTextureAtlas::CCTextureAtlas() { @@ -87,7 +89,7 @@ void CCTextureAtlas::setQuads(ccV3F_C4B_T2F_Quad *var) // TextureAtlas - alloc & init -CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(NSString *file, UINT32 capacity) +CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(string & file, UINT32 capacity) { CCTextureAtlas * pTextureAtlas = new CCTextureAtlas(); pTextureAtlas->initWithFile(file, capacity); @@ -103,7 +105,7 @@ CCTextureAtlas * CCTextureAtlas::textureAtlasWithTexture(CCTexture2D *tex, UINT3 return pTextureAtlas; } -CCTextureAtlas * CCTextureAtlas::initWithFile(NSString *file, UINT32 capacity) +CCTextureAtlas * CCTextureAtlas::initWithFile(string & file, UINT32 capacity) { // retained in property CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addImage(file); diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 275ba745f7..4590b6b80a 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -33,14 +33,16 @@ THE SOFTWARE. /// @todo EAGLContext static EAGLContext *auxEAGLcontext = NULL; -using namespace std; +using namespace std; + + class CCAsyncObject : NSObject { public: fpAsyncCallback m_pfnCallback; NSObject* m_pTarget; - NSString* m_pData; + std::string * m_pData; public: CCAsyncObject(); ~CCAsyncObject() @@ -142,7 +144,7 @@ sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]]; } /** @todo --(void) addImageAsync: (NSString*) filename target:(id)target selector:(SEL)selector +-(void) addImageAsync: (string & ) filename target:(id)target selector:(SEL)selector { NSAssert(filename != nil, @"TextureCache: fileimage MUST not be nill"); @@ -166,9 +168,9 @@ sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]]; [asyncObject release]; }*/ -CCTexture2D * CCTextureCache::addImage(NSString *path) +CCTexture2D * CCTextureCache::addImage(string & path) { - NSAssert(path != NULL, "TextureCache: fileimage MUST not be nill"); + NSAssert(!path.empty(), "TextureCache: fileimage MUST not be nill"); CCTexture2D * tex = NULL; @@ -182,7 +184,7 @@ CCTexture2D * CCTextureCache::addImage(NSString *path) if( ! tex ) { // Split up directory and filename - NSString *fullpath = [CCFileUtils fullPathFromRelativePath: path ]; + string & fullpath = [CCFileUtils fullPathFromRelativePath: path ]; // all images are handled by UIImage except PVR extension that is handled by our own handler if ( [[path lowercaseString] hasSuffix:@".pvr"] ) @@ -210,10 +212,10 @@ CCTexture2D * CCTextureCache::addImage(NSString *path) return tex; } -CCTexture2D* CCTextureCache::addPVRTCImage(NSString *path, int bpp, bool hasAlpha, int width) +CCTexture2D* CCTextureCache::addPVRTCImage(string & path, int bpp, bool hasAlpha, int width) { - NSAssert(path != NULL, "TextureCache: fileimage MUST not be nill"); + NSAssert(!path.empty(), "TextureCache: fileimage MUST not be nill"); NSAssert( bpp==2 || bpp==4, "TextureCache: bpp must be either 2 or 4"); CCTexture2D * tex; @@ -223,7 +225,7 @@ CCTexture2D* CCTextureCache::addPVRTCImage(NSString *path, int bpp, bool hasAlph } // Split up directory and filename - NSString *fullpath = [CCFileUtils fullPathFromRelativePath:path]; + string & fullpath = [CCFileUtils fullPathFromRelativePath:path]; NSData *nsdata = [[NSData alloc] initWithContentsOfFile:fullpath]; tex = [[CCTexture2D alloc] initWithPVRTCData:[nsdata bytes] level:0 bpp:bpp hasAlpha:alpha length:w]; @@ -238,9 +240,9 @@ CCTexture2D* CCTextureCache::addPVRTCImage(NSString *path, int bpp, bool hasAlph return tex; } -CCTexture2D * CCTextureCache::addPVRTCImage(NSString* fileimage) +CCTexture2D * CCTextureCache::addPVRTCImage(string & fileimage) { - NSAssert(fileimage != NULL, "TextureCache: fileimage MUST not be nill"); + NSAssert(!fileimage.empty(), "TextureCache: fileimage MUST not be nill"); CCTexture2D * tex; /** @todo @@ -259,7 +261,7 @@ CCTexture2D * CCTextureCache::addPVRTCImage(NSString* fileimage) } /** @todo --(CCTexture2D*) addCGImage: (CGImageRef) imageref forKey: (NSString *)key +-(CCTexture2D*) addCGImage: (CGImageRef) imageref forKey: (string & )key { NSAssert(imageref != nil, @"TextureCache: image MUST not be nill"); @@ -315,9 +317,9 @@ void CCTextureCache::removeTexture(CCTexture2D* tex) [textures removeObjectForKey:[keys objectAtIndex:i]];*/ } -void CCTextureCache::removeTextureForKey(NSString* textureKeyName) +void CCTextureCache::removeTextureForKey(string & textureKeyName) { - if( ! textureKeyName ) + if( textureKeyName.empty() ) return; /// @todo [textures removeObjectForKey:textureKeyName]; diff --git a/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h b/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h index a46e64b8e9..c591ee470a 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h +++ b/cocos2dx/touch_dispatcher/CCTouchDelegateProtocol.h @@ -35,7 +35,7 @@ typedef enum { kTargetedTouchDelegate, } eTouchDelegteType; -class CCTouchDelegate : public NSObject +class CCTouchDelegate : virtual public NSObject { public: eTouchDelegteType m_eType; diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.h b/cocos2dx/touch_dispatcher/CCTouchDispatcher.h index 6b218ce925..60114b443a 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.h +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.h @@ -27,7 +27,7 @@ THE SOFTWARE. #include "CCTouchDelegateProtocol.h" #include "../cocoa/NSObject.h" -#include "cocoa/NSMutableArray.h" +#include "../cocoa/NSMutableArray.h" typedef enum {