fixed #565: upgrade tileMap_parallax_nodes to 1.0.0-rc3

This commit is contained in:
minggo 2011-07-04 14:11:43 +08:00
parent 00ff3dba4d
commit 70ce4f877f
14 changed files with 80 additions and 38 deletions

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -49,9 +50,9 @@ namespace cocos2d {
CCParallaxNode(); CCParallaxNode();
virtual ~CCParallaxNode(); virtual ~CCParallaxNode();
static CCParallaxNode * node(); static CCParallaxNode * node();
virtual void addChild(CCNode * child, int z, CCPoint parallaxRatio, CCPoint positionOffset); virtual void addChild(CCNode * child, unsigned int z, CCPoint parallaxRatio, CCPoint positionOffset);
// super methods // super methods
virtual void addChild(CCNode * child, int zOrder, int tag); virtual void addChild(CCNode * child, unsigned int zOrder, int tag);
virtual void removeChild(CCNode* child, bool cleanup); virtual void removeChild(CCNode* child, bool cleanup);
virtual void removeAllChildrenWithCleanup(bool cleanup); virtual void removeAllChildrenWithCleanup(bool cleanup);
virtual void visit(void); virtual void visit(void);

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -70,7 +71,7 @@ namespace cocos2d {
/** Tilset information for the layer */ /** Tilset information for the layer */
CC_PROPERTY(CCTMXTilesetInfo*, m_pTileSet, TileSet); CC_PROPERTY(CCTMXTilesetInfo*, m_pTileSet, TileSet);
/** Layer orientation, which is the same as the map orientation */ /** Layer orientation, which is the same as the map orientation */
CC_SYNTHESIZE(int, m_nLayerOrientation, LayerOrientation); CC_SYNTHESIZE(unsigned int, m_uLayerOrientation, LayerOrientation);
/** properties from the layer. They can be added using Tiled */ /** properties from the layer. They can be added using Tiled */
CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties); CC_PROPERTY(CCStringToStringDictionary*, m_pProperties, Properties);
public: public:

View File

@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2010 Ricardo Quesada
Copyright (c) 2010 Neophit Copyright (c) 2010 Neophit
Copyright (c) 2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -48,6 +49,7 @@ namespace cocos2d {
TMXLayerAttribNone = 1 << 0, TMXLayerAttribNone = 1 << 0,
TMXLayerAttribBase64 = 1 << 1, TMXLayerAttribBase64 = 1 << 1,
TMXLayerAttribGzip = 1 << 2, TMXLayerAttribGzip = 1 << 2,
TMXLayerAttribZlib = 1 << 3,
}; };
enum { enum {

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -75,7 +76,7 @@ namespace cocos2d {
private: private:
void loadTGAfile(const char *file); void loadTGAfile(const char *file);
void calculateItemsToRender(); void calculateItemsToRender();
void updateAtlasValueAt(ccGridSize pos, ccColor3B value, int index); void updateAtlasValueAt(ccGridSize pos, ccColor3B value, unsigned int index);
void updateAtlasValues(); void updateAtlasValues();
protected: protected:

View File

@ -34,14 +34,13 @@ namespace cocos2d
// Should buffer factor be 1.5 instead of 2 ? // Should buffer factor be 1.5 instead of 2 ?
#define BUFFER_INC_FACTOR (2) #define BUFFER_INC_FACTOR (2)
int ZipUtils::inflateMemory_(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength) int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength, unsigned int outLenghtHint)
{ {
/* ret value */ /* ret value */
int err = Z_OK; int err = Z_OK;
/* 256k initial decompress buffer */ int bufferSize = outLenghtHint;
int bufferSize = 256 * 1024; *out = (unsigned char*) malloc(bufferSize);
*out = new unsigned char[bufferSize];
z_stream d_stream; /* decompression stream */ z_stream d_stream; /* decompression stream */
d_stream.zalloc = (alloc_func)0; d_stream.zalloc = (alloc_func)0;
@ -55,11 +54,10 @@ namespace cocos2d
/* window size to hold 256k */ /* window size to hold 256k */
if( (err = inflateInit2(&d_stream, 15 + 32)) != Z_OK ) if( (err = inflateInit2(&d_stream, 15 + 32)) != Z_OK )
{
return err; return err;
}
for (;;) { for (;;)
{
err = inflate(&d_stream, Z_NO_FLUSH); err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) if (err == Z_STREAM_END)
@ -67,28 +65,30 @@ namespace cocos2d
break; break;
} }
switch (err) { switch (err)
{
case Z_NEED_DICT: case Z_NEED_DICT:
err = Z_DATA_ERROR; err = Z_DATA_ERROR;
case Z_DATA_ERROR: case Z_DATA_ERROR:
case Z_MEM_ERROR: case Z_MEM_ERROR:
inflateEnd(&d_stream); inflateEnd(&d_stream);
return err; return err;
} }
// not enough memory ? // not enough memory ?
if (err != Z_STREAM_END) if (err != Z_STREAM_END)
{ {
delete [] *out; unsigned char *tmp = (unsigned char*)realloc(*out, bufferSize * BUFFER_INC_FACTOR);
*out = new unsigned char[bufferSize * BUFFER_INC_FACTOR];
/* not enough memory, ouch */ /* not enough memory, ouch */
if (! *out ) if (! tmp )
{ {
CCLOG("cocos2d: ZipUtils: realloc failed"); CCLOG("cocos2d: ZipUtils: realloc failed");
inflateEnd(&d_stream); inflateEnd(&d_stream);
return Z_MEM_ERROR; return Z_MEM_ERROR;
} }
/* only assign to *out if tmp is valid. it's not guaranteed that realloc will reuse the memory */
*out = tmp;
d_stream.next_out = *out + bufferSize; d_stream.next_out = *out + bufferSize;
d_stream.avail_out = bufferSize; d_stream.avail_out = bufferSize;
@ -96,16 +96,15 @@ namespace cocos2d
} }
} }
*outLength = bufferSize - d_stream.avail_out; *outLength = bufferSize - d_stream.avail_out;
err = inflateEnd(&d_stream); err = inflateEnd(&d_stream);
return err; return err;
} }
int ZipUtils::ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out) int ZipUtils::ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLengthHint)
{ {
unsigned int outLength = 0; unsigned int outLength = 0;
int err = inflateMemory_(in, inLength, out, &outLength); int err = ccInflateMemoryWithHint(in, inLength, out, &outLength, outLengthHint);
if (err != Z_OK || *out == NULL) { if (err != Z_OK || *out == NULL) {
if (err == Z_MEM_ERROR) if (err == Z_MEM_ERROR)
@ -133,6 +132,12 @@ namespace cocos2d
return outLength; return outLength;
} }
int ZipUtils::ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out)
{
// 256k for hint
return ccInflateMemoryWithHint(in, inLength, out, 256 * 1024);
}
int ZipUtils::ccInflateGZipFile(const char *path, unsigned char **out) int ZipUtils::ccInflateGZipFile(const char *path, unsigned char **out)
{ {
int len; int len;

View File

@ -51,12 +51,25 @@ namespace cocos2d
* Inflates either zlib or gzip deflated memory. The inflated memory is * Inflates either zlib or gzip deflated memory. The inflated memory is
* expected to be freed by the caller. * expected to be freed by the caller.
* *
* It will allocate 256k for the destination buffer. If it is not enought it will multiply the previous buffer size per 2, until there is enough memory.
* @returns the length of the deflated buffer * @returns the length of the deflated buffer
* *
@since v0.8.1 @since v0.8.1
*/ */
static int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out); static int ccInflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out);
/**
* Inflates either zlib or gzip deflated memory. The inflated memory is
* expected to be freed by the caller.
*
* outLenghtHint is assumed to be the needed room to allocate the inflated buffer.
*
* @returns the length of the deflated buffer
*
@since v1.0.0
*/
static int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int outLenghtHint);
/** inflates a GZip file into memory /** inflates a GZip file into memory
* *
* @returns the length of the deflated buffer * @returns the length of the deflated buffer
@ -74,7 +87,8 @@ namespace cocos2d
static int ccInflateCCZFile(const char *filename, unsigned char **out); static int ccInflateCCZFile(const char *filename, unsigned char **out);
private: private:
static int inflateMemory_(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLengh); static int ccInflateMemoryWithHint(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength,
unsigned int outLenghtHint);
}; };
} // end of namespace cocos2d } // end of namespace cocos2d

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -69,14 +70,14 @@ namespace cocos2d {
pRet->autorelease(); pRet->autorelease();
return pRet; return pRet;
} }
void CCParallaxNode::addChild(CCNode * child, int zOrder, int tag) void CCParallaxNode::addChild(CCNode * child, unsigned int zOrder, int tag)
{ {
CC_UNUSED_PARAM(zOrder); CC_UNUSED_PARAM(zOrder);
CC_UNUSED_PARAM(child); CC_UNUSED_PARAM(child);
CC_UNUSED_PARAM(tag); CC_UNUSED_PARAM(tag);
CCAssert(0,"ParallaxNode: use addChild:z:parallaxRatio:positionOffset instead"); CCAssert(0,"ParallaxNode: use addChild:z:parallaxRatio:positionOffset instead");
} }
void CCParallaxNode::addChild(CCNode *child, int z, CCPoint ratio, CCPoint offset) void CCParallaxNode::addChild(CCNode *child, unsigned int z, CCPoint ratio, CCPoint offset)
{ {
CCAssert( child != NULL, "Argument must be non-nil"); CCAssert( child != NULL, "Argument must be non-nil");
CCPointObject *obj = CCPointObject::pointWithCCPoint(ratio, offset); CCPointObject *obj = CCPointObject::pointWithCCPoint(ratio, offset);

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -74,7 +75,7 @@ namespace cocos2d {
// mapInfo // mapInfo
m_tMapTileSize = mapInfo->getTileSize(); m_tMapTileSize = mapInfo->getTileSize();
m_nLayerOrientation = mapInfo->getOrientation(); m_uLayerOrientation = mapInfo->getOrientation();
// offset (after layer orientation is set); // offset (after layer orientation is set);
CCPoint offset = this->calculateLayerOffset(layerInfo->m_tOffset); CCPoint offset = this->calculateLayerOffset(layerInfo->m_tOffset);
@ -519,7 +520,7 @@ namespace cocos2d {
CCPoint CCTMXLayer::calculateLayerOffset(CCPoint pos) CCPoint CCTMXLayer::calculateLayerOffset(CCPoint pos)
{ {
CCPoint ret = CCPointZero; CCPoint ret = CCPointZero;
switch( m_nLayerOrientation ) switch( m_uLayerOrientation )
{ {
case CCTMXOrientationOrtho: case CCTMXOrientationOrtho:
ret = ccp( pos.x * m_tMapTileSize.width, -pos.y *m_tMapTileSize.height); ret = ccp( pos.x * m_tMapTileSize.width, -pos.y *m_tMapTileSize.height);
@ -537,7 +538,7 @@ namespace cocos2d {
CCPoint CCTMXLayer::positionAt(CCPoint pos) CCPoint CCTMXLayer::positionAt(CCPoint pos)
{ {
CCPoint ret = CCPointZero; CCPoint ret = CCPointZero;
switch( m_nLayerOrientation ) switch( m_uLayerOrientation )
{ {
case CCTMXOrientationOrtho: case CCTMXOrientationOrtho:
ret = positionForOrthoAt(pos); ret = positionForOrthoAt(pos);
@ -581,7 +582,7 @@ namespace cocos2d {
unsigned int maxVal = 0; unsigned int maxVal = 0;
if( m_bUseAutomaticVertexZ ) if( m_bUseAutomaticVertexZ )
{ {
switch( m_nLayerOrientation ) switch( m_uLayerOrientation )
{ {
case CCTMXOrientationIso: case CCTMXOrientationIso:
maxVal = (unsigned int)(m_tLayerSize.width + m_tLayerSize.height); maxVal = (unsigned int)(m_tLayerSize.width + m_tLayerSize.height);

View File

@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2010 Ricardo Quesada
Copyright (c) 2010 Neophit Copyright (c) 2010 Neophit
Copyright (c) 2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -154,9 +155,6 @@ namespace cocos2d{
CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo) CCTMXTilesetInfo * CCTMXTiledMap::tilesetForLayer(CCTMXLayerInfo *layerInfo, CCTMXMapInfo *mapInfo)
{ {
CCTMXTilesetInfo *tileset = NULL;
//CFByteOrder o = CFByteOrderGetCurrent();
CCSize size = layerInfo->m_tLayerSize; CCSize size = layerInfo->m_tLayerSize;
CCMutableArray<CCTMXTilesetInfo*>* tilesets = mapInfo->getTilesets(); CCMutableArray<CCTMXTilesetInfo*>* tilesets = mapInfo->getTilesets();
if (tilesets && tilesets->count()>0) if (tilesets && tilesets->count()>0)
@ -197,7 +195,7 @@ namespace cocos2d{
// If all the tiles are 0, return empty tileset // If all the tiles are 0, return empty tileset
CCLOG("cocos2d: Warning: TMX Layer '%@' has no tiles", layerInfo->m_sName.c_str()); CCLOG("cocos2d: Warning: TMX Layer '%@' has no tiles", layerInfo->m_sName.c_str());
return tileset; return NULL;
} }

View File

@ -2,6 +2,7 @@
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2011 Максим Аксенов Copyright (c) 2011 Максим Аксенов
Copyright (c) 2009-2010 Ricardo Quesada Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -391,10 +392,15 @@ namespace cocos2d {
{ {
layerAttribs = pTMXMapInfo->getLayerAttribs(); layerAttribs = pTMXMapInfo->getLayerAttribs();
pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip); pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
} else
if (compression == "zip")
{
layerAttribs = pTMXMapInfo->getLayerAttribs();
pTMXMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
} }
CCAssert( compression == "" || compression == "gzip", "TMX: unsupported compression method" ); CCAssert( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
} }
CCAssert( pTMXMapInfo->getLayerAttribs() != TMXLayerAttribNone, "TMX tile map: Only base64 and/or gzip maps are supported" ); CCAssert( pTMXMapInfo->getLayerAttribs() != TMXLayerAttribNone, "TMX tile map: Only base64 and/or gzip/zlib maps are supported" );
} }
else if(elementName == "object") else if(elementName == "object")
@ -534,17 +540,25 @@ namespace cocos2d {
std::string currentString = pTMXMapInfo->getCurrentString(); std::string currentString = pTMXMapInfo->getCurrentString();
unsigned char *buffer; unsigned char *buffer;
len = base64Decode((unsigned char*)currentString.c_str(), currentString.length(), &buffer); len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
if( ! buffer ) if( ! buffer )
{ {
CCLOG("cocos2d: TiledMap: decode data error"); CCLOG("cocos2d: TiledMap: decode data error");
return; return;
} }
if( pTMXMapInfo->getLayerAttribs() & TMXLayerAttribGzip ) if( pTMXMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib) )
{ {
unsigned char *deflated; unsigned char *deflated;
ZipUtils::ccInflateMemory(buffer, len, &deflated); CCSize s = layer->m_tLayerSize;
// int sizeHint = s.width * s.height * sizeof(uint32_t);
int sizeHint = (int)(s.width * s.height * sizeof(unsigned int));
int inflatedLen = ZipUtils::ccInflateMemoryWithHint(buffer, len, &deflated, sizeHint);
assert(inflatedLen == sizeHint);
inflatedLen = (int)&inflatedLen; // XXX: to avoid warings in compiler
delete [] buffer; delete [] buffer;
buffer = NULL; buffer = NULL;

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -174,7 +175,7 @@ namespace cocos2d {
return value; return value;
} }
void CCTileMapAtlas::updateAtlasValueAt(ccGridSize pos, ccColor3B value, int index) void CCTileMapAtlas::updateAtlasValueAt(ccGridSize pos, ccColor3B value, unsigned int index)
{ {
ccV3F_C4B_T2F_Quad quad; ccV3F_C4B_T2F_Quad quad;