issue #7, change the use of NSMutableArray

This commit is contained in:
Walzer 2010-07-20 05:49:13 +00:00
parent c8477d4d16
commit 5d60c2ca0a
20 changed files with 130 additions and 129 deletions

View File

@ -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();
}

View File

@ -75,15 +75,15 @@ CCNode::~CCNode()
}
void CCNode::arrayMakeObjectsPerformSelector(NSMutableArray * pArray, callbackFunc func)
void CCNode::arrayMakeObjectsPerformSelector(NSMutableArray<CCNode*> * pArray, callbackFunc func)
{
if(pArray && pArray->count() > 0)
{
CCNode* pNode;
NSMutableArrayIterator it;
NSMutableArray<CCNode*>::NSMutableArrayIterator it;
for( it = pArray->begin(); it != pArray->end(); it++)
{
pNode = static_cast<CCNode*>(*it);
pNode = (*it);
if(pNode && func)
{
@ -203,7 +203,7 @@ void CCNode::setPosition(CGPoint newPosition)
}
/// children getter
NSMutableArray * CCNode::getChildren()
NSMutableArray<CCNode*> * 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<CCNode*>(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<CCNode*>::NSMutableArrayIterator it;
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
{
pNode = static_cast<CCNode*>(*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<CCNode*>::NSMutableArrayIterator it;
for ( it = m_pChildren->begin(); it!= m_pChildren->end(); it++ )
{
pNode = static_cast<CCNode *>(*it);
@ -561,10 +561,10 @@ void CCNode::insertChild(CCNode* child, int z)
if(m_pChildren && m_pChildren->count() > 0)
{
CCNode* pNode;
NSMutableArrayIterator it;
NSMutableArray<CCNode*>::NSMutableArrayIterator it;
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
{
pNode = static_cast<CCNode*>(*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<CCNode*>::NSMutableArrayIterator it;
for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
{
pNode = static_cast<CCNode*>(*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

View File

@ -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)
{

View File

@ -25,7 +25,7 @@ THE SOFTWARE.
#ifndef __NS_ZONE_H__
#define __NS_ZONE_H__
#include "platform/platform.h"
#include "../platform/platform.h"
class NSObject;

View File

@ -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);

View File

@ -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);

View File

@ -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<CCLayer *> * m_pLayers;
public:
CCMultiplexLayer();

View File

@ -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<CCNode *> *, 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<CCNode*> * pArray, callbackFunc func);
CGPoint convertToWindowSpace(CGPoint nodePoint);
public:

View File

@ -40,7 +40,7 @@ THE SOFTWARE.
class CCPVRTexture : public NSObject
{
protected:
NSMutableArray * m_pImageData;
NSMutableArray<NSData> * m_pImageData;
public:

View File

@ -43,6 +43,7 @@ class CCScene : public CCNode
public:
CCScene();
virtual ~CCScene();
bool init();
};
#endif // __CCSCENE_H__

View File

@ -28,7 +28,9 @@ THE SOFTWARE.
#include "../cocoa/NSObject.h"
/// @todo #import <Foundation/Foundation.h>
/// @todo #import <CoreGraphics/CGImage.h>
//#include "../platform/uphone/NSLock.h"
#include <string>
#include <hash_map>
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<int ,int > textures;
//NSLock *m_pDictLock;
//NSLock *m_pContextLock;
public:

View File

@ -88,7 +88,8 @@ THE SOFTWARE.
#define CCX_SAFE_RETAIN(p) if(p) { p->retain(); }
#ifdef _DEBUG
#include "assert.h"
#include <assert.h>
#include <stdio.h>
#define NSAssert(_CONDITION, _TXT)\
if(! (_CONDITION) ) \
{ \

View File

@ -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;
}

View File

@ -23,7 +23,7 @@ THE SOFTWARE.
****************************************************************************/
#include "TransformUtils.h"
#include "cocoa/CGAffineTransform.h"
#include "../cocoa/CGAffineTransform.h"
void CGAffineToGL(const CGAffineTransform *t, GLfloat *m)
{

View File

@ -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);

View File

@ -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] ) {

View File

@ -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);

View File

@ -35,12 +35,14 @@ THE SOFTWARE.
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];

View File

@ -35,7 +35,7 @@ typedef enum {
kTargetedTouchDelegate,
} eTouchDelegteType;
class CCTouchDelegate : public NSObject
class CCTouchDelegate : virtual public NSObject
{
public:
eTouchDelegteType m_eType;

View File

@ -27,7 +27,7 @@ THE SOFTWARE.
#include "CCTouchDelegateProtocol.h"
#include "../cocoa/NSObject.h"
#include "cocoa/NSMutableArray.h"
#include "../cocoa/NSMutableArray.h"
typedef enum
{