From 63bccb8d2916772b2b857d51226491171a744ec3 Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 3 Dec 2013 14:12:25 +0800 Subject: [PATCH 1/5] change long to int in AtlasNode --- cocos/2d/CCAtlasNode.cpp | 12 ++++++------ cocos/2d/CCAtlasNode.h | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index b756a36193c7..a882bab51517 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -61,7 +61,7 @@ AtlasNode::~AtlasNode() CC_SAFE_RELEASE(_textureAtlas); } -AtlasNode * AtlasNode::create(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender) +AtlasNode * AtlasNode::create(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender) { AtlasNode * pRet = new AtlasNode(); if (pRet->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender)) @@ -73,14 +73,14 @@ AtlasNode * AtlasNode::create(const std::string& tile, long tileWidth, long tile return NULL; } -bool AtlasNode::initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender) +bool AtlasNode::initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender) { CCASSERT(tile.size() > 0, "file size should not be empty"); Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile); return initWithTexture(texture, tileWidth, tileHeight, itemsToRender); } -bool AtlasNode::initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender) +bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender) { _itemWidth = tileWidth; _itemHeight = tileHeight; @@ -245,14 +245,14 @@ TextureAtlas * AtlasNode::getTextureAtlas() const return _textureAtlas; } -long AtlasNode::getQuadsToDraw() const +int AtlasNode::getQuadsToDraw() const { return _quadsToDraw; } -void AtlasNode::setQuadsToDraw(long uQuadsToDraw) +void AtlasNode::setQuadsToDraw(int quadsToDraw) { - _quadsToDraw = uQuadsToDraw; + _quadsToDraw = quadsToDraw; } NS_CC_END diff --git a/cocos/2d/CCAtlasNode.h b/cocos/2d/CCAtlasNode.h index b196f45a1d99..676458360eec 100644 --- a/cocos/2d/CCAtlasNode.h +++ b/cocos/2d/CCAtlasNode.h @@ -52,7 +52,7 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol { public: /** creates a AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ - static AtlasNode * create(const std::string& filename, long tileWidth, long tileHeight, long itemsToRender); + static AtlasNode * create(const std::string& filename, int tileWidth, int tileHeight, int itemsToRender); /** updates the Atlas (indexed vertex array). * Shall be overridden in subclasses @@ -62,8 +62,8 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol void setTextureAtlas(TextureAtlas* textureAtlas); TextureAtlas* getTextureAtlas() const; - void setQuadsToDraw(long quadsToDraw); - long getQuadsToDraw() const; + void setQuadsToDraw(int quadsToDraw); + int getQuadsToDraw() const; // Overrides @@ -95,10 +95,10 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol virtual ~AtlasNode(); /** initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ - bool initWithTileFile(const std::string& tile, long tileWidth, long tileHeight, long itemsToRender); + bool initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender); /** initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/ - bool initWithTexture(Texture2D* texture, long tileWidth, long tileHeight, long itemsToRender); + bool initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender); void calculateMaxItems(); void updateBlendFunc(); @@ -108,14 +108,14 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor); //! chars per row - long _itemsPerRow; + int _itemsPerRow; //! chars per column - long _itemsPerColumn; + int _itemsPerColumn; //! width of each char - long _itemWidth; + int _itemWidth; //! height of each char - long _itemHeight; + int _itemHeight; Color3B _colorUnmodified; @@ -125,7 +125,7 @@ class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol BlendFunc _blendFunc; // quads to draw - long _quadsToDraw; + int _quadsToDraw; // color uniform GLint _uniformColor; // This varible is only used for LabelAtlas FPS display. So plz don't modify its value. From 9887ec59fa40197b48648f7336fd2a29558809cb Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 4 Dec 2013 13:57:37 +0800 Subject: [PATCH 2/5] use size_t in ccCArray --- cocos/2d/ccCArray.cpp | 116 +++++++++++++++++++++--------------------- cocos/2d/ccCArray.h | 32 ++++++------ 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/cocos/2d/ccCArray.cpp b/cocos/2d/ccCArray.cpp index f280bc5787ab..9c008b57d719 100644 --- a/cocos/2d/ccCArray.cpp +++ b/cocos/2d/ccCArray.cpp @@ -28,10 +28,10 @@ THE SOFTWARE. NS_CC_BEGIN -const long CC_INVALID_INDEX = -1; +const size_t CC_INVALID_INDEX = (size_t)(-1); /** Allocates and initializes a new array with specified capacity */ -ccArray* ccArrayNew(long capacity) +ccArray* ccArrayNew(size_t capacity) { if (capacity == 0) capacity = 7; @@ -47,7 +47,7 @@ ccArray* ccArrayNew(long capacity) /** Frees array after removing all remaining objects. Silently ignores NULL arr. */ void ccArrayFree(ccArray*& arr) { - if( arr == NULL ) + if (arr == nullptr) { return; } @@ -56,25 +56,25 @@ void ccArrayFree(ccArray*& arr) free(arr->arr); free(arr); - arr = NULL; + arr = nullptr; } void ccArrayDoubleCapacity(ccArray *arr) { arr->max *= 2; - Object** newArr = (Object**)realloc( arr->arr, arr->max * sizeof(Object*) ); + auto newArr = static_cast(realloc( arr->arr, arr->max * sizeof(Object*))); // will fail when there's not enough memory CCASSERT(newArr != 0, "ccArrayDoubleCapacity failed. Not enough memory"); arr->arr = newArr; } -void ccArrayEnsureExtraCapacity(ccArray *arr, long extra) +void ccArrayEnsureExtraCapacity(ccArray *arr, size_t extra) { while (arr->max < arr->num + extra) { - CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%lu] to [%lu].", - (long) arr->max, - (long) arr->max*2); + CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%zu] to [%zu].", + arr->max, + arr->max*2); ccArrayDoubleCapacity(arr); } @@ -82,7 +82,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, long extra) void ccArrayShrink(ccArray *arr) { - long newSize = 0; + size_t newSize = 0; //only resize when necessary if (arr->max > arr->num && !(arr->num==0 && arr->max==1)) @@ -99,18 +99,18 @@ void ccArrayShrink(ccArray *arr) } arr->arr = (Object**)realloc(arr->arr,newSize * sizeof(Object*) ); - CCASSERT(arr->arr!=NULL,"could not reallocate the memory"); + CCASSERT(arr->arr!=nullptr,"could not reallocate the memory"); } } /** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */ long ccArrayGetIndexOfObject(ccArray *arr, Object* object) { - const long arrNum = arr->num; + const auto arrNum = arr->num; Object** ptr = arr->arr; - for(long i = 0; i < arrNum; ++i, ++ptr) + for (size_t i = 0; i < arrNum; ++i, ++ptr) { - if( *ptr == object ) + if (*ptr == object) return i; } @@ -126,7 +126,7 @@ bool ccArrayContainsObject(ccArray *arr, Object* object) /** Appends an object. Behavior undefined if array doesn't have enough capacity. */ void ccArrayAppendObject(ccArray *arr, Object* object) { - CCASSERT(object != NULL, "Invalid parameter!"); + CCASSERT(object != nullptr, "Invalid parameter!"); object->retain(); arr->arr[arr->num] = object; arr->num++; @@ -143,7 +143,7 @@ void ccArrayAppendObjectWithResize(ccArray *arr, Object* object) enough capacity. */ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr) { - for(long i = 0; i < plusArr->num; i++) + for (size_t i = 0; i < plusArr->num; ++i) { ccArrayAppendObject(arr, plusArr->arr[i]); } @@ -157,14 +157,14 @@ void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr) } /** Inserts an object at index */ -void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, long index) +void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, size_t index) { - CCASSERT(index<=arr->num, "Invalid index. Out of bounds"); - CCASSERT(object != NULL, "Invalid parameter!"); + CCASSERT(index <= arr->num, "Invalid index. Out of bounds"); + CCASSERT(object != nullptr, "Invalid parameter!"); ccArrayEnsureExtraCapacity(arr, 1); - long remaining = arr->num - index; + auto remaining = arr->num - index; if( remaining > 0) { memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Object*) * remaining ); @@ -176,10 +176,10 @@ void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, long index) } /** Swaps two objects */ -void ccArraySwapObjectsAtIndexes(ccArray *arr, long index1, long index2) +void ccArraySwapObjectsAtIndexes(ccArray *arr, size_t index1, size_t index2) { - CCASSERT(index1>=0 && index1 < arr->num, "(1) Invalid index. Out of bounds"); - CCASSERT(index2>=0 && index2 < arr->num, "(2) Invalid index. Out of bounds"); + CCASSERT(index1 >= 0 && index1 < arr->num, "(1) Invalid index. Out of bounds"); + CCASSERT(index2 >= 0 && index2 < arr->num, "(2) Invalid index. Out of bounds"); Object* object1 = arr->arr[index1]; @@ -190,7 +190,7 @@ void ccArraySwapObjectsAtIndexes(ccArray *arr, long index1, long index2) /** Removes all objects from arr */ void ccArrayRemoveAllObjects(ccArray *arr) { - while( arr->num > 0 ) + while (arr->num > 0) { (arr->arr[--arr->num])->release(); } @@ -198,18 +198,18 @@ void ccArrayRemoveAllObjects(ccArray *arr) /** Removes object at specified index and pushes back all subsequent objects. Behavior undefined if index outside [0, num-1]. */ -void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj/* = true*/) +void ccArrayRemoveObjectAtIndex(ccArray *arr, size_t index, bool releaseObj/* = true*/) { CCASSERT(arr && arr->num > 0 && index>=0 && index < arr->num, "Invalid index. Out of bounds"); - if (bReleaseObj) + if (releaseObj) { CC_SAFE_RELEASE(arr->arr[index]); } arr->num--; - long remaining = arr->num - index; - if(remaining>0) + auto remaining = arr->num - index; + if (remaining > 0) { memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Object*)); } @@ -218,16 +218,16 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj/* = t /** Removes object at specified index and fills the gap with the last object, thereby avoiding the need to push back subsequent objects. Behavior undefined if index outside [0, num-1]. */ -void ccArrayFastRemoveObjectAtIndex(ccArray *arr, long index) +void ccArrayFastRemoveObjectAtIndex(ccArray *arr, size_t index) { CC_SAFE_RELEASE(arr->arr[index]); - long last = --arr->num; + auto last = --arr->num; arr->arr[index] = arr->arr[last]; } void ccArrayFastRemoveObject(ccArray *arr, Object* object) { - long index = ccArrayGetIndexOfObject(arr, object); + auto index = ccArrayGetIndexOfObject(arr, object); if (index != CC_INVALID_INDEX) { ccArrayFastRemoveObjectAtIndex(arr, index); @@ -238,7 +238,7 @@ void ccArrayFastRemoveObject(ccArray *arr, Object* object) found the function has no effect. */ void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true*/) { - long index = ccArrayGetIndexOfObject(arr, object); + auto index = ccArrayGetIndexOfObject(arr, object); if (index != CC_INVALID_INDEX) { ccArrayRemoveObjectAtIndex(arr, index, bReleaseObj); @@ -249,7 +249,7 @@ void ccArrayRemoveObject(ccArray *arr, Object* object, bool bReleaseObj/* = true first matching instance in arr will be removed. */ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr) { - for(long i = 0; i < minusArr->num; i++) + for (size_t i = 0; i < minusArr->num; ++i) { ccArrayRemoveObject(arr, minusArr->arr[i]); } @@ -259,12 +259,11 @@ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr) matching instances in arr will be removed. */ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr) { - long back = 0; - long i = 0; + size_t back = 0; - for( i = 0; i < arr->num; i++) + for (size_t i = 0; i < arr->num; ++i) { - if( ccArrayContainsObject(minusArr, arr->arr[i]) ) + if (ccArrayContainsObject(minusArr, arr->arr[i])) { CC_SAFE_RELEASE(arr->arr[i]); back++; @@ -282,16 +281,16 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr) // #pragma mark ccCArray for Values (c structures) /** Allocates and initializes a new C array with specified capacity */ -ccCArray* ccCArrayNew(long capacity) +ccCArray* ccCArrayNew(size_t capacity) { if (capacity == 0) { capacity = 7; } - ccCArray *arr = (ccCArray*)malloc( sizeof(ccCArray) ); + ccCArray *arr = static_cast(malloc( sizeof(ccCArray))); arr->num = 0; - arr->arr = (void**)malloc( capacity * sizeof(void*) ); + arr->arr = static_cast(malloc(capacity * sizeof(void*))); arr->max = capacity; return arr; @@ -300,7 +299,7 @@ ccCArray* ccCArrayNew(long capacity) /** Frees C array after removing all remaining values. Silently ignores NULL arr. */ void ccCArrayFree(ccCArray *arr) { - if( arr == NULL ) + if (arr == nullptr) { return; } @@ -317,17 +316,17 @@ void ccCArrayDoubleCapacity(ccCArray *arr) } /** Increases array capacity such that max >= num + extra. */ -void ccCArrayEnsureExtraCapacity(ccCArray *arr, long extra) +void ccCArrayEnsureExtraCapacity(ccCArray *arr, size_t extra) { ccArrayEnsureExtraCapacity((ccArray*)arr,extra); } /** Returns index of first occurrence of value, CC_INVALID_INDEX if value not found. */ -long ccCArrayGetIndexOfValue(ccCArray *arr, void* value) +size_t ccCArrayGetIndexOfValue(ccCArray *arr, void* value) { - for(long i = 0; i < arr->num; i++) + for (size_t i = 0; i < arr->num; ++i) { - if( arr->arr[i] == value ) + if (arr->arr[i] == value) return i; } return CC_INVALID_INDEX; @@ -340,18 +339,19 @@ bool ccCArrayContainsValue(ccCArray *arr, void* value) } /** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */ -void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, long index) +void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, size_t index) { - CCASSERT( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index"); + CCASSERT(index < arr->max, "ccCArrayInsertValueAtIndex: invalid index"); - long remaining = arr->num - index; + auto remaining = arr->num - index; // make sure it has enough capacity if (arr->num + 1 == arr->max) { ccCArrayDoubleCapacity(arr); } // last Value doesn't need to be moved - if( remaining > 0) { + if (remaining > 0) + { // tex coordinates memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(void*) * remaining ); } @@ -385,7 +385,7 @@ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value) enough capacity. */ void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr) { - for( long i = 0; i < plusArr->num; i++) + for (size_t i = 0; i < plusArr->num; ++i) { ccCArrayAppendValue(arr, plusArr->arr[i]); } @@ -408,9 +408,9 @@ void ccCArrayRemoveAllValues(ccCArray *arr) Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ -void ccCArrayRemoveValueAtIndex(ccCArray *arr, long index) +void ccCArrayRemoveValueAtIndex(ccCArray *arr, size_t index) { - for( long last = --arr->num; index < last; index++) + for (size_t last = --arr->num; index < last; ++index) { arr->arr[index] = arr->arr[index + 1]; } @@ -421,9 +421,9 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, long index) Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ -void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, long index) +void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, size_t index) { - long last = --arr->num; + auto last = --arr->num; arr->arr[index] = arr->arr[last]; } @@ -432,7 +432,7 @@ void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, long index) */ void ccCArrayRemoveValue(ccCArray *arr, void* value) { - long index = ccCArrayGetIndexOfValue(arr, value); + auto index = ccCArrayGetIndexOfValue(arr, value); if (index != CC_INVALID_INDEX) { ccCArrayRemoveValueAtIndex(arr, index); @@ -444,7 +444,7 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value) */ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr) { - for(long i = 0; i < minusArr->num; i++) + for (size_t i = 0; i < minusArr->num; ++i) { ccCArrayRemoveValue(arr, minusArr->arr[i]); } @@ -455,9 +455,9 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr) */ void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr) { - long back = 0; + size_t back = 0; - for(long i = 0; i < arr->num; i++) + for (size_t i = 0; i < arr->num; ++i) { if( ccCArrayContainsValue(minusArr, arr->arr[i]) ) { diff --git a/cocos/2d/ccCArray.h b/cocos/2d/ccCArray.h index 2bfff6224f3e..f691ed5566a9 100644 --- a/cocos/2d/ccCArray.h +++ b/cocos/2d/ccCArray.h @@ -51,20 +51,20 @@ THE SOFTWARE. NS_CC_BEGIN -extern const long CC_INVALID_INDEX; +extern const size_t CC_INVALID_INDEX; // Easy integration #define CCARRAYDATA_FOREACH(__array__, __object__) \ -__object__=__array__->arr[0]; for(long i=0, num=__array__->num; iarr[i]) \ +__object__=__array__->arr[0]; for(size_t i=0, num=__array__->num; iarr[i]) \ typedef struct _ccArray { - long num, max; + size_t num, max; Object** arr; } ccArray; /** Allocates and initializes a new array with specified capacity */ -ccArray* ccArrayNew(long capacity); +ccArray* ccArrayNew(size_t capacity); /** Frees array after removing all remaining objects. Silently ignores nil arr. */ void ccArrayFree(ccArray*& arr); @@ -73,7 +73,7 @@ void ccArrayFree(ccArray*& arr); void ccArrayDoubleCapacity(ccArray *arr); /** Increases array capacity such that max >= num + extra. */ -void ccArrayEnsureExtraCapacity(ccArray *arr, long extra); +void ccArrayEnsureExtraCapacity(ccArray *arr, size_t extra); /** shrinks the array so the memory footprint corresponds with the number of items */ void ccArrayShrink(ccArray *arr); @@ -98,22 +98,22 @@ void ccArrayAppendArray(ccArray *arr, ccArray *plusArr); void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr); /** Inserts an object at index */ -void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, long index); +void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, size_t index); /** Swaps two objects */ -void ccArraySwapObjectsAtIndexes(ccArray *arr, long index1, long index2); +void ccArraySwapObjectsAtIndexes(ccArray *arr, size_t index1, size_t index2); /** Removes all objects from arr */ void ccArrayRemoveAllObjects(ccArray *arr); /** Removes object at specified index and pushes back all subsequent objects. Behavior undefined if index outside [0, num-1]. */ -void ccArrayRemoveObjectAtIndex(ccArray *arr, long index, bool bReleaseObj = true); +void ccArrayRemoveObjectAtIndex(ccArray *arr, size_t index, bool bReleaseObj = true); /** Removes object at specified index and fills the gap with the last object, thereby avoiding the need to push back subsequent objects. Behavior undefined if index outside [0, num-1]. */ -void ccArrayFastRemoveObjectAtIndex(ccArray *arr, long index); +void ccArrayFastRemoveObjectAtIndex(ccArray *arr, size_t index); void ccArrayFastRemoveObject(ccArray *arr, Object* object); @@ -133,12 +133,12 @@ void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr); // #pragma mark ccCArray for Values (c structures) typedef struct _ccCArray { - long num, max; + size_t num, max; void** arr; } ccCArray; /** Allocates and initializes a new C array with specified capacity */ -ccCArray* ccCArrayNew(long capacity); +ccCArray* ccCArrayNew(size_t capacity); /** Frees C array after removing all remaining values. Silently ignores nil arr. */ void ccCArrayFree(ccCArray *arr); @@ -147,16 +147,16 @@ void ccCArrayFree(ccCArray *arr); void ccCArrayDoubleCapacity(ccCArray *arr); /** Increases array capacity such that max >= num + extra. */ -void ccCArrayEnsureExtraCapacity(ccCArray *arr, long extra); +void ccCArrayEnsureExtraCapacity(ccCArray *arr, size_t extra); /** Returns index of first occurrence of value, NSNotFound if value not found. */ -long ccCArrayGetIndexOfValue(ccCArray *arr, void* value); +size_t ccCArrayGetIndexOfValue(ccCArray *arr, void* value); /** Returns a Boolean value that indicates whether value is present in the C array. */ bool ccCArrayContainsValue(ccCArray *arr, void* value); /** Inserts a value at a certain position. Behavior undefined if array doesn't have enough capacity */ -void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, long index); +void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, size_t index); /** Appends an value. Behavior undefined if array doesn't have enough capacity. */ void ccCArrayAppendValue(ccCArray *arr, void* value); @@ -178,14 +178,14 @@ void ccCArrayRemoveAllValues(ccCArray *arr); Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ -void ccCArrayRemoveValueAtIndex(ccCArray *arr, long index); +void ccCArrayRemoveValueAtIndex(ccCArray *arr, size_t index); /** Removes value at specified index and fills the gap with the last value, thereby avoiding the need to push back subsequent values. Behavior undefined if index outside [0, num-1]. @since v0.99.4 */ -void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, long index); +void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, size_t index); /** Searches for the first occurrence of value and removes it. If value is not found the function has no effect. @since v0.99.4 From e744e5188e1b1d534dcd08f23aa153cbee26b8ee Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 4 Dec 2013 14:53:13 +0800 Subject: [PATCH 3/5] change long to size_t or int --- cocos/2d/CCActionInterval.cpp | 8 +- cocos/2d/CCActionManager.cpp | 10 +- cocos/2d/CCActionManager.h | 4 +- cocos/2d/CCFontFreeType.cpp | 2 +- cocos/2d/CCLabelBMFont.cpp | 8 +- cocos/2d/CCTexture2D.cpp | 130 +++++++++--------- cocos/2d/CCTexture2D.h | 76 +++++----- cocos/2d/CCUserDefault.cpp | 2 +- cocos/2d/CCUserDefault.mm | 2 +- cocos/2d/TGAlib.cpp | 2 +- cocos/2d/ZipUtils.cpp | 6 +- cocos/2d/ccCArray.cpp | 2 +- cocos/2d/ccCArray.h | 2 +- cocos/2d/platform/CCFileUtils.cpp | 4 +- cocos/2d/platform/CCFileUtils.h | 2 +- cocos/2d/platform/CCImage.h | 42 +++--- cocos/2d/platform/CCImageCommon_cpp.h | 48 +++---- cocos/2d/platform/CCSAXParser.cpp | 2 +- cocos/base/CCData.cpp | 14 +- cocos/base/CCData.h | 16 +-- cocos/base/CCString.cpp | 2 +- .../editor-support/cocosbuilder/CCBReader.cpp | 2 +- .../cocosbuilder/CCNodeLoader.cpp | 2 +- .../cocostudio/CCDataReaderHelper.cpp | 4 +- .../cocostudio/CCSGUIReader.cpp | 2 +- .../cocostudio/CCSSceneReader.cpp | 6 +- cocos/editor-support/spine/spine-cocos2dx.cpp | 2 +- cocos/physics/CCPhysicsShape.cpp | 6 +- cocos/physics/CCPhysicsShape.h | 8 +- 29 files changed, 208 insertions(+), 208 deletions(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index a2ae6b78241a..abf98c486836 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -203,14 +203,14 @@ Sequence* Sequence::create(Array* arrayOfActions) Sequence* pRet = NULL; do { - long count = arrayOfActions->count(); + auto count = arrayOfActions->count(); CC_BREAK_IF(count == 0); FiniteTimeAction* prev = static_cast(arrayOfActions->getObjectAtIndex(0)); if (count > 1) { - for (long i = 1; i < count; ++i) + for (size_t i = 1; i < count; ++i) { prev = createWithTwoActions(prev, static_cast(arrayOfActions->getObjectAtIndex(i))); } @@ -576,12 +576,12 @@ Spawn* Spawn::create(Array *arrayOfActions) Spawn* pRet = NULL; do { - long count = arrayOfActions->count(); + auto count = arrayOfActions->count(); CC_BREAK_IF(count == 0); FiniteTimeAction* prev = static_cast(arrayOfActions->getObjectAtIndex(0)); if (count > 1) { - for (int i = 1; i < arrayOfActions->count(); ++i) + for (size_t i = 1; i < count; ++i) { prev = createWithTwoActions(prev, static_cast(arrayOfActions->getObjectAtIndex(i))); } diff --git a/cocos/2d/CCActionManager.cpp b/cocos/2d/CCActionManager.cpp index dd2b528bceea..56971d5a7662 100644 --- a/cocos/2d/CCActionManager.cpp +++ b/cocos/2d/CCActionManager.cpp @@ -253,7 +253,7 @@ void ActionManager::removeAction(Action *action) HASH_FIND_PTR(_targets, &target, element); if (element) { - long i = ccArrayGetIndexOfObject(element->actions, action); + auto i = ccArrayGetIndexOfObject(element->actions, action); if (i != CC_INVALID_INDEX) { removeActionAtIndex(i, element); @@ -275,12 +275,12 @@ void ActionManager::removeActionByTag(int tag, Object *target) if (element) { - long limit = element->actions->num; - for (long i = 0; i < limit; ++i) + auto limit = element->actions->num; + for (size_t i = 0; i < limit; ++i) { Action *action = (Action*)element->actions->arr[i]; - if (action->getTag() == (int)tag && action->getOriginalTarget() == target) + if (action->getTag() == tag && action->getOriginalTarget() == target) { removeActionAtIndex(i, element); break; @@ -327,7 +327,7 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const // XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer // and, it is not possible to get the address of a reference -long ActionManager::getNumberOfRunningActionsInTarget(const Object *target) const +size_t ActionManager::getNumberOfRunningActionsInTarget(const Object *target) const { tHashElement *element = NULL; HASH_FIND_PTR(_targets, &target, element); diff --git a/cocos/2d/CCActionManager.h b/cocos/2d/CCActionManager.h index 8a2c077511cf..cd02feb91b07 100644 --- a/cocos/2d/CCActionManager.h +++ b/cocos/2d/CCActionManager.h @@ -102,10 +102,10 @@ class CC_DLL ActionManager : public Object * - If you are running 1 Sequence of 7 actions, it will return 1. * - If you are running 7 Sequences of 2 actions, it will return 7. */ - long getNumberOfRunningActionsInTarget(const Object *target) const; + size_t getNumberOfRunningActionsInTarget(const Object *target) const; /** @deprecated use getNumberOfRunningActionsInTarget() instead */ - CC_DEPRECATED_ATTRIBUTE inline unsigned int numberOfRunningActionsInTarget(Object *target) const { return getNumberOfRunningActionsInTarget(target); } + CC_DEPRECATED_ATTRIBUTE inline size_t numberOfRunningActionsInTarget(Object *target) const { return getNumberOfRunningActionsInTarget(target); } /** Pauses the target: all running actions and newly added actions will be paused. */ diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 25063eb02367..8ae705eadc14 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -99,7 +99,7 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize) { FT_Face face; - long len = 0; + size_t len = 0; _ttfData = FileUtils::getInstance()->getFileData(fontName.c_str(), "rb", &len); if (!_ttfData) return false; diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index 88fb1547707f..46d20bce9a0a 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -917,7 +917,7 @@ void LabelBMFont::updateLabel() { // Step 1: Make multiline vector str_whole = cc_utf16_vec_from_utf16_str(_string); - unsigned int stringLength = str_whole.size(); + size_t stringLength = str_whole.size(); vector multiline_string; multiline_string.reserve( stringLength ); vector last_word; @@ -1068,7 +1068,7 @@ void LabelBMFont::updateLabel() multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end()); - int size = multiline_string.size(); + auto size = multiline_string.size(); unsigned short* str_new = new unsigned short[size + 1]; for (int j = 0; j < size; ++j) @@ -1096,14 +1096,14 @@ void LabelBMFont::updateLabel() if (_string[ctr] == '\n' || _string[ctr] == 0) { float lineWidth = 0.0f; - unsigned int line_length = last_line.size(); + auto line_length = last_line.size(); // if last line is empty we must just increase lineNumber and work with next line if (line_length == 0) { lineNumber++; continue; } - int index = i + line_length - 1 + lineNumber; + int index = static_cast(i + line_length - 1 + lineNumber); if (index < 0) continue; Sprite* lastChar = static_cast( getChildByTag(index) ); diff --git a/cocos/2d/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp index d8c0bfbaf8ce..af21b7c885a0 100644 --- a/cocos/2d/CCTexture2D.cpp +++ b/cocos/2d/CCTexture2D.cpp @@ -119,7 +119,7 @@ static bool _PVRHaveAlphaPremultiplied = false; //conventer function // IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBB -void Texture2D::convertI8ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertI8ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData) { for (int i=0; i < dataLen; ++i) { @@ -130,9 +130,9 @@ void Texture2D::convertI8ToRGB888(const unsigned char* data, long dataLen, unsig } // IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB -void Texture2D::convertAI88ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertAI88ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 1; i < l; i += 2) + for (size_t i = 0, l = dataLen - 1; i < l; i += 2) { *outData++ = data[i]; //R *outData++ = data[i]; //G @@ -141,9 +141,9 @@ void Texture2D::convertAI88ToRGB888(const unsigned char* data, long dataLen, uns } // IIIIIIII -> RRRRRRRRGGGGGGGGGBBBBBBBBAAAAAAAA -void Texture2D::convertI8ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertI8ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0; i < dataLen; ++i) + for (size_t i = 0; i < dataLen; ++i) { *outData++ = data[i]; //R *outData++ = data[i]; //G @@ -153,9 +153,9 @@ void Texture2D::convertI8ToRGBA8888(const unsigned char* data, long dataLen, uns } // IIIIIIIIAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -void Texture2D::convertAI88ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertAI88ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 1; i < l; i += 2) + for (size_t i = 0, l = dataLen - 1; i < l; i += 2) { *outData++ = data[i]; //R *outData++ = data[i]; //G @@ -165,10 +165,10 @@ void Texture2D::convertAI88ToRGBA8888(const unsigned char* data, long dataLen, u } // IIIIIIII -> RRRRRGGGGGGBBBBB -void Texture2D::convertI8ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertI8ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0; i < dataLen; ++i) + for (size_t i = 0; i < dataLen; ++i) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i] & 0x00FC) << 3 //G @@ -177,10 +177,10 @@ void Texture2D::convertI8ToRGB565(const unsigned char* data, long dataLen, unsig } // IIIIIIIIAAAAAAAA -> RRRRRGGGGGGBBBBB -void Texture2D::convertAI88ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertAI88ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0, l = dataLen - 1; i < l; i += 2) + for (size_t i = 0, l = dataLen - 1; i < l; i += 2) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i] & 0x00FC) << 3 //G @@ -189,10 +189,10 @@ void Texture2D::convertAI88ToRGB565(const unsigned char* data, long dataLen, uns } // IIIIIIII -> RRRRGGGGBBBBAAAA -void Texture2D::convertI8ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertI8ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0; i < dataLen; ++i) + for (size_t i = 0; i < dataLen; ++i) { *out16++ = (data[i] & 0x00F0) << 8 //R | (data[i] & 0x00F0) << 4 //G @@ -202,10 +202,10 @@ void Texture2D::convertI8ToRGBA4444(const unsigned char* data, long dataLen, uns } // IIIIIIIIAAAAAAAA -> RRRRGGGGBBBBAAAA -void Texture2D::convertAI88ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertAI88ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0, l = dataLen - 1; i < l; i += 2) + for (size_t i = 0, l = dataLen - 1; i < l; i += 2) { *out16++ = (data[i] & 0x00F0) << 8 //R | (data[i] & 0x00F0) << 4 //G @@ -215,10 +215,10 @@ void Texture2D::convertAI88ToRGBA4444(const unsigned char* data, long dataLen, u } // IIIIIIII -> RRRRRGGGGGBBBBBA -void Texture2D::convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertI8ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0; i < dataLen; ++i) + for (size_t i = 0; i < dataLen; ++i) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i] & 0x00F8) << 3 //G @@ -228,10 +228,10 @@ void Texture2D::convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsig } // IIIIIIIIAAAAAAAA -> RRRRRGGGGGBBBBBA -void Texture2D::convertAI88ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertAI88ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0, l = dataLen - 1; i < l; i += 2) + for (size_t i = 0, l = dataLen - 1; i < l; i += 2) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i] & 0x00F8) << 3 //G @@ -241,10 +241,10 @@ void Texture2D::convertAI88ToRGB5A1(const unsigned char* data, long dataLen, uns } // IIIIIIII -> IIIIIIIIAAAAAAAA -void Texture2D::convertI8ToAI88(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertI8ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0; i < dataLen; ++i) + for (size_t i = 0; i < dataLen; ++i) { *out16++ = 0xFF00 //A | data[i]; //I @@ -252,27 +252,27 @@ void Texture2D::convertI8ToAI88(const unsigned char* data, long dataLen, unsigne } // IIIIIIIIAAAAAAAA -> AAAAAAAA -void Texture2D::convertAI88ToA8(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertAI88ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 1; i < dataLen; i += 2) + for (size_t i = 1; i < dataLen; i += 2) { *outData++ = data[i]; //A } } // IIIIIIIIAAAAAAAA -> IIIIIIII -void Texture2D::convertAI88ToI8(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertAI88ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 1; i < l; i += 2) + for (size_t i = 0, l = dataLen - 1; i < l; i += 2) { *outData++ = data[i]; //R } } // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -void Texture2D::convertRGB888ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGB888ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 2; i < l; i += 3) + for (size_t i = 0, l = dataLen - 2; i < l; i += 3) { *outData++ = data[i]; //R *outData++ = data[i + 1]; //G @@ -282,9 +282,9 @@ void Texture2D::convertRGB888ToRGBA8888(const unsigned char* data, long dataLen, } // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRRRRGGGGGGGGBBBBBBBB -void Texture2D::convertRGBA8888ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGBA8888ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 3; i < l; i += 4) + for (size_t i = 0, l = dataLen - 3; i < l; i += 4) { *outData++ = data[i]; //R *outData++ = data[i + 1]; //G @@ -293,10 +293,10 @@ void Texture2D::convertRGBA8888ToRGB888(const unsigned char* data, long dataLen, } // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGGBBBBB -void Texture2D::convertRGB888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGB888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0, l = dataLen - 2; i < l; i += 3) + for (size_t i = 0, l = dataLen - 2; i < l; i += 3) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i + 1] & 0x00FC) << 3 //G @@ -305,10 +305,10 @@ void Texture2D::convertRGB888ToRGB565(const unsigned char* data, long dataLen, u } // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRRGGGGGGBBBBB -void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0, l = dataLen - 3; i < l; i += 4) + for (size_t i = 0, l = dataLen - 3; i < l; i += 4) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i + 1] & 0x00FC) << 3 //G @@ -317,36 +317,36 @@ void Texture2D::convertRGBA8888ToRGB565(const unsigned char* data, long dataLen, } // RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIII -void Texture2D::convertRGB888ToI8(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGB888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 2; i < l; i += 3) + for (size_t i = 0, l = dataLen - 2; i < l; i += 3) { *outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000 } } // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIII -void Texture2D::convertRGBA8888ToI8(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGBA8888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 3; i < l; i += 4) + for (size_t i = 0, l = dataLen - 3; i < l; i += 4) { *outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000 } } // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> AAAAAAAA -void Texture2D::convertRGBA8888ToA8(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGBA8888ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen -3; i < l; i += 4) + for (size_t i = 0, l = dataLen - 3; i < l; i += 4) { *outData++ = data[i + 3]; //A } } // RRRRRRRRGGGGGGGGBBBBBBBB -> IIIIIIIIAAAAAAAA -void Texture2D::convertRGB888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGB888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 2; i < l; i += 3) + for (size_t i = 0, l = dataLen - 2; i < l; i += 3) { *outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000 *outData++ = 0xFF; @@ -355,9 +355,9 @@ void Texture2D::convertRGB888ToAI88(const unsigned char* data, long dataLen, uns // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> IIIIIIIIAAAAAAAA -void Texture2D::convertRGBA8888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGBA8888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData) { - for (int i = 0, l = dataLen - 3; i < l; i += 4) + for (size_t i = 0, l = dataLen - 3; i < l; i += 4) { *outData++ = (data[i] * 299 + data[i + 1] * 587 + data[i + 2] * 114 + 500) / 1000; //I = (R*299 + G*587 + B*114 + 500) / 1000 *outData++ = data[i + 3]; @@ -365,10 +365,10 @@ void Texture2D::convertRGBA8888ToAI88(const unsigned char* data, long dataLen, u } // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRGGGGBBBBAAAA -void Texture2D::convertRGB888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGB888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0, l = dataLen - 2; i < l; i += 3) + for (size_t i = 0, l = dataLen - 2; i < l; i += 3) { *out16++ = ((data[i] & 0x00F0) << 8 //R | (data[i + 1] & 0x00F0) << 4 //G @@ -378,10 +378,10 @@ void Texture2D::convertRGB888ToRGBA4444(const unsigned char* data, long dataLen, } // RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA -> RRRRGGGGBBBBAAAA -void Texture2D::convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGBA8888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (int i = 0, l = dataLen - 3; i < l; i += 4) + for (size_t i = 0, l = dataLen - 3; i < l; i += 4) { *out16++ = (data[i] & 0x00F0) << 8 //R | (data[i + 1] & 0x00F0) << 4 //G @@ -391,10 +391,10 @@ void Texture2D::convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLe } // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA -void Texture2D::convertRGB888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGB888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (long i = 0, l = dataLen - 2; i < l; i += 3) + for (size_t i = 0, l = dataLen - 2; i < l; i += 3) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i + 1] & 0x00F8) << 3 //G @@ -404,10 +404,10 @@ void Texture2D::convertRGB888ToRGB5A1(const unsigned char* data, long dataLen, u } // RRRRRRRRGGGGGGGGBBBBBBBB -> RRRRRGGGGGBBBBBA -void Texture2D::convertRGBA8888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData) +void Texture2D::convertRGBA8888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData) { unsigned short* out16 = (unsigned short*)outData; - for (long i = 0, l = dataLen - 2; i < l; i += 4) + for (size_t i = 0, l = dataLen - 2; i < l; i += 4) { *out16++ = (data[i] & 0x00F8) << 8 //R | (data[i + 1] & 0x00F8) << 3 //G @@ -427,7 +427,7 @@ Texture2D::Texture2D() , _maxT(0.0) , _hasPremultipliedAlpha(false) , _hasMipmaps(false) -, _shaderProgram(NULL) +, _shaderProgram(nullptr) { } @@ -451,12 +451,12 @@ Texture2D::PixelFormat Texture2D::getPixelFormat() const return _pixelFormat; } -long Texture2D::getPixelsWide() const +int Texture2D::getPixelsWide() const { return _pixelsWide; } -long Texture2D::getPixelsHigh() const +int Texture2D::getPixelsHigh() const { return _pixelsHigh; } @@ -517,7 +517,7 @@ void Texture2D::releaseData(void *data) free(data); } -void* Texture2D::keepData(void *data, unsigned int length) +void* Texture2D::keepData(void *data, size_t length) { CC_UNUSED_PARAM(length); //The texture data mustn't be saved because it isn't a mutable texture. @@ -529,14 +529,14 @@ bool Texture2D::hasPremultipliedAlpha() const return _hasPremultipliedAlpha; } -bool Texture2D::initWithData(const void *data, long dataLen, Texture2D::PixelFormat pixelFormat, long pixelsWide, long pixelsHigh, const Size& contentSize) +bool Texture2D::initWithData(const void *data, size_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize) { - CCASSERT(dataLen>0 && pixelsWide>0 && pixelsHigh>0, "Invalid size"); + CCASSERT((dataLen > 0) && (pixelsWide > 0) && (pixelsHigh > 0), "Invalid size"); //if data has no mipmaps, we will consider it has only one mipmap MipmapInfo mipmap; mipmap.address = (unsigned char*)data; - mipmap.len = dataLen; + mipmap.len = static_cast(dataLen); return initWithMipmaps(&mipmap, 1, pixelFormat, pixelsWide, pixelsHigh); //update information @@ -546,7 +546,7 @@ bool Texture2D::initWithData(const void *data, long dataLen, Texture2D::PixelFor } -bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat pixelFormat, long pixelsWide, long pixelsHigh) +bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat pixelFormat, int pixelsWide, int pixelsHigh) { //the pixelFormat must be a certain value CCASSERT(pixelFormat != PixelFormat::NONE && pixelFormat != PixelFormat::AUTO, "the \"pixelFormat\" param must be a certain value!"); @@ -742,7 +742,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) } unsigned char* outTempData = NULL; - int outTempDataLen = 0; + size_t outTempDataLen = 0; pixelFormat = convertDataToFormat(tempData, tempDataLen, renderFormat, pixelFormat, &outTempData, &outTempDataLen); @@ -774,7 +774,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format) } } -Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen) +Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -823,7 +823,7 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, l return format; } -Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen) +Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -878,7 +878,7 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data, return format; } -Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen) +Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) { @@ -926,7 +926,7 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat return format; } -Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen) +Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (format) @@ -998,7 +998,7 @@ rgb(2) -> 1235678 rgba(1) -> 12345678 */ -Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, long dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, int* outDataLen) +Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, size_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, size_t* outDataLen) { switch (originFormat) { diff --git a/cocos/2d/CCTexture2D.h b/cocos/2d/CCTexture2D.h index 96c861c34183..92c0183c6b87 100644 --- a/cocos/2d/CCTexture2D.h +++ b/cocos/2d/CCTexture2D.h @@ -211,16 +211,16 @@ class CC_DLL Texture2D : public Object * @js NA * @lua NA */ - void* keepData(void *data, unsigned int length); + void* keepData(void *data, size_t length); /** Initializes with a texture2d with data * @js NA * @lua NA */ - bool initWithData(const void *data, long dataLen, Texture2D::PixelFormat pixelFormat, long pixelsWide, long pixelsHigh, const Size& contentSize); + bool initWithData(const void *data, size_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize); /** Initializes with mipmaps */ - bool initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, Texture2D::PixelFormat pixelFormat, long pixelsWide, long pixelsHigh); + bool initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh); /** Drawing extensions to make it easy to draw basic quads using a Texture2D object. @@ -327,10 +327,10 @@ class CC_DLL Texture2D : public Object Texture2D::PixelFormat getPixelFormat() const; /** Gets the width of the texture in pixels */ - long getPixelsWide() const; + int getPixelsWide() const; /** Gets the height of the texture in pixels */ - long getPixelsHigh() const; + int getPixelsHigh() const; /** Gets the texture name */ GLuint getName() const; @@ -361,56 +361,56 @@ class CC_DLL Texture2D : public Object Convert the format to the format param you specified, if the format is PixelFormat::Automatic, it will detect it automatically and convert to the closest format for you. It will return the converted format to you. if the outData != data, you must delete it manually. */ - static PixelFormat convertDataToFormat(const unsigned char* data, long dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, int* outDataLen); + static PixelFormat convertDataToFormat(const unsigned char* data, size_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, size_t* outDataLen); - static PixelFormat convertI8ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen); - static PixelFormat convertAI88ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen); - static PixelFormat convertRGB888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen); - static PixelFormat convertRGBA8888ToFormat(const unsigned char* data, long dataLen, PixelFormat format, unsigned char** outData, int* outDataLen); + static PixelFormat convertI8ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen); + static PixelFormat convertAI88ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen); + static PixelFormat convertRGB888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen); + static PixelFormat convertRGBA8888ToFormat(const unsigned char* data, size_t dataLen, PixelFormat format, unsigned char** outData, size_t* outDataLen); //I8 to XXX - static void convertI8ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertI8ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertI8ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertI8ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertI8ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertI8ToAI88(const unsigned char* data, long dataLen, unsigned char* outData); + static void convertI8ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertI8ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertI8ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertI8ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertI8ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertI8ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData); //AI88 to XXX - static void convertAI88ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertAI88ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertAI88ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertAI88ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertAI88ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertAI88ToA8(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertAI88ToI8(const unsigned char* data, long dataLen, unsigned char* outData); + static void convertAI88ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertAI88ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertAI88ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertAI88ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertAI88ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertAI88ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertAI88ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData); //RGB888 to XXX - static void convertRGB888ToRGBA8888(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGB888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGB888ToI8(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGB888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGB888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGB888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData); + static void convertRGB888ToRGBA8888(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGB888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGB888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGB888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGB888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGB888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData); //RGBA8888 to XXX - static void convertRGBA8888ToRGB888(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGBA8888ToRGB565(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGBA8888ToI8(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGBA8888ToA8(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGBA8888ToAI88(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGBA8888ToRGBA4444(const unsigned char* data, long dataLen, unsigned char* outData); - static void convertRGBA8888ToRGB5A1(const unsigned char* data, long dataLen, unsigned char* outData); + static void convertRGBA8888ToRGB888(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGBA8888ToRGB565(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGBA8888ToI8(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGBA8888ToA8(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGBA8888ToAI88(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGBA8888ToRGBA4444(const unsigned char* data, size_t dataLen, unsigned char* outData); + static void convertRGBA8888ToRGB5A1(const unsigned char* data, size_t dataLen, unsigned char* outData); protected: /** pixel format of the texture */ Texture2D::PixelFormat _pixelFormat; /** width in pixels */ - long _pixelsWide; + int _pixelsWide; /** height in pixels */ - long _pixelsHigh; + int _pixelsHigh; /** texture name */ GLuint _name; diff --git a/cocos/2d/CCUserDefault.cpp b/cocos/2d/CCUserDefault.cpp index 1d40acf46157..c24557d95409 100644 --- a/cocos/2d/CCUserDefault.cpp +++ b/cocos/2d/CCUserDefault.cpp @@ -58,7 +58,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLEle tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; //CCFileData data(UserDefault::getInstance()->getXMLFilePath().c_str(),"rt"); - long nSize; + size_t nSize; char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &nSize); //const char* pXmlBuffer = (const char*)data.getBuffer(); if(NULL == pXmlBuffer) diff --git a/cocos/2d/CCUserDefault.mm b/cocos/2d/CCUserDefault.mm index e64f339b8d86..7d6b952555ca 100644 --- a/cocos/2d/CCUserDefault.mm +++ b/cocos/2d/CCUserDefault.mm @@ -73,7 +73,7 @@ of this software and associated documentation files (the "Software"), to deal { tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; - long size; + size_t size; char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size); //const char* pXmlBuffer = (const char*)data.getBuffer(); if(NULL == pXmlBuffer) diff --git a/cocos/2d/TGAlib.cpp b/cocos/2d/TGAlib.cpp index 9320b887cea4..cc40333274de 100644 --- a/cocos/2d/TGAlib.cpp +++ b/cocos/2d/TGAlib.cpp @@ -272,7 +272,7 @@ tImageTGA* tgaLoadBuffer(unsigned char* buffer, long size) // this is the function to call when we want to load an image tImageTGA * tgaLoad(const char *filename) { - long size = 0; + size_t size = 0; unsigned char* buffer = FileUtils::getInstance()->getFileData(filename, "rb", &size); if (buffer != nullptr) diff --git a/cocos/2d/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp index ebde2f99634b..5912ffe17711 100644 --- a/cocos/2d/ZipUtils.cpp +++ b/cocos/2d/ZipUtils.cpp @@ -306,7 +306,7 @@ bool ZipUtils::isCCZFile(const char *path) // load file into memory unsigned char* compressed = NULL; - long fileLen = 0; + size_t fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(compressed == NULL || fileLen == 0) @@ -338,7 +338,7 @@ bool ZipUtils::isGZipFile(const char *path) // load file into memory unsigned char* compressed = NULL; - long fileLen = 0; + size_t fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(NULL == compressed || 0 == fileLen) @@ -461,7 +461,7 @@ int ZipUtils::inflateCCZFile(const char *path, unsigned char **out) // load file into memory unsigned char* compressed = NULL; - long fileLen = 0; + size_t fileLen = 0; compressed = FileUtils::getInstance()->getFileData(path, "rb", &fileLen); if(NULL == compressed || 0 == fileLen) diff --git a/cocos/2d/ccCArray.cpp b/cocos/2d/ccCArray.cpp index 9c008b57d719..256c65cbea20 100644 --- a/cocos/2d/ccCArray.cpp +++ b/cocos/2d/ccCArray.cpp @@ -104,7 +104,7 @@ void ccArrayShrink(ccArray *arr) } /** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */ -long ccArrayGetIndexOfObject(ccArray *arr, Object* object) +size_t ccArrayGetIndexOfObject(ccArray *arr, Object* object) { const auto arrNum = arr->num; Object** ptr = arr->arr; diff --git a/cocos/2d/ccCArray.h b/cocos/2d/ccCArray.h index f691ed5566a9..d42ee0962c12 100644 --- a/cocos/2d/ccCArray.h +++ b/cocos/2d/ccCArray.h @@ -79,7 +79,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, size_t extra); void ccArrayShrink(ccArray *arr); /** Returns index of first occurrence of object, NSNotFound if object not found. */ -long ccArrayGetIndexOfObject(ccArray *arr, Object* object); +size_t ccArrayGetIndexOfObject(ccArray *arr, Object* object); /** Returns a Boolean value that indicates whether object is present in array. */ bool ccArrayContainsObject(ccArray *arr, Object* object); diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index ddd9c25dfe65..4b68c14aabf0 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -488,7 +488,7 @@ void FileUtils::purgeCachedEntries() _fullPathCache.clear(); } -unsigned char* FileUtils::getFileData(const char* filename, const char* mode, long *size) +unsigned char* FileUtils::getFileData(const char* filename, const char* mode, size_t *size) { unsigned char * buffer = NULL; CCASSERT(filename != NULL && size != NULL && mode != NULL, "Invalid parameters."); @@ -751,7 +751,7 @@ void FileUtils::loadFilenameLookupDictionaryFromFile(const std::string &filename int version = static_cast( metadata->objectForKey("version"))->intValue(); if (version != 1) { - CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %ld. Filename: %s", (long)version, filename.c_str()); + CCLOG("cocos2d: ERROR: Invalid filenameLookup dictionary version: %d. Filename: %s", version, filename.c_str()); return; } setFilenameLookupDictionary( static_cast( dict->objectForKey("filenames")) ); diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index 672e4b723435..060c0961f21e 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -88,7 +88,7 @@ class CC_DLL FileUtils * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned. */ - virtual unsigned char* getFileData(const char* filename, const char* mode, long *size); + virtual unsigned char* getFileData(const char* filename, const char* mode, size_t *size); /** * Gets resource file data from a zip file. diff --git a/cocos/2d/platform/CCImage.h b/cocos/2d/platform/CCImage.h index ba90d380e3f0..0edd0ec153bf 100644 --- a/cocos/2d/platform/CCImage.h +++ b/cocos/2d/platform/CCImage.h @@ -121,10 +121,10 @@ class CC_DLL Image : public Object * @js NA * @lua NA */ - bool initWithImageData(const unsigned char * data, long dataLen); + bool initWithImageData(const unsigned char * data, size_t dataLen); // @warning kFmtRawData only support RGBA8888 - bool initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti = false); + bool initWithRawData(const unsigned char * data, size_t dataLen, int width, int height, int bitsPerComponent, bool preMulti = false); /** @brief Create image with specified string. @@ -198,16 +198,16 @@ class CC_DLL Image : public Object bool saveToFile(const std::string &filename, bool isToRGB = true); protected: - bool initWithJpgData(const unsigned char * data, int dataLen); - bool initWithPngData(const unsigned char * data, int dataLen); - bool initWithTiffData(const unsigned char * data, int dataLen); - bool initWithWebpData(const unsigned char * data, int dataLen); - bool initWithPVRData(const unsigned char * data, int dataLen); - bool initWithPVRv2Data(const unsigned char * data, int dataLen); - bool initWithPVRv3Data(const unsigned char * data, int dataLen); - bool initWithETCData(const unsigned char * data, int dataLen); - bool initWithS3TCData(const unsigned char * data, int dataLen); - bool initWithATITCData(const unsigned char *data, int dataLen); + bool initWithJpgData(const unsigned char * data, size_t dataLen); + bool initWithPngData(const unsigned char * data, size_t dataLen); + bool initWithTiffData(const unsigned char * data, size_t dataLen); + bool initWithWebpData(const unsigned char * data, size_t dataLen); + bool initWithPVRData(const unsigned char * data, size_t dataLen); + bool initWithPVRv2Data(const unsigned char * data, size_t dataLen); + bool initWithPVRv3Data(const unsigned char * data, size_t dataLen); + bool initWithETCData(const unsigned char * data, size_t dataLen); + bool initWithS3TCData(const unsigned char * data, size_t dataLen); + bool initWithATITCData(const unsigned char *data, size_t dataLen); typedef struct sImageTGA tImageTGA; bool initWithTGAData(tImageTGA* tgaData); @@ -248,15 +248,15 @@ class CC_DLL Image : public Object */ bool initWithImageFileThreadSafe(const char *fullpath); - Format detectFormat(const unsigned char * data, int dataLen); - bool isPng(const unsigned char * data, int dataLen); - bool isJpg(const unsigned char * data, int dataLen); - bool isTiff(const unsigned char * data, int dataLen); - bool isWebp(const unsigned char * data, int dataLen); - bool isPvr(const unsigned char * data, int dataLen); - bool isEtc(const unsigned char * data, int dataLen); - bool isS3TC(const unsigned char * data,int dataLen); - bool isATITC(const unsigned char *data, int dataLen); + Format detectFormat(const unsigned char * data, size_t dataLen); + bool isPng(const unsigned char * data, size_t dataLen); + bool isJpg(const unsigned char * data, size_t dataLen); + bool isTiff(const unsigned char * data, size_t dataLen); + bool isWebp(const unsigned char * data, size_t dataLen); + bool isPvr(const unsigned char * data, size_t dataLen); + bool isEtc(const unsigned char * data, size_t dataLen); + bool isS3TC(const unsigned char * data,size_t dataLen); + bool isATITC(const unsigned char *data, size_t dataLen); }; // end of platform group diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index edbf424868d2..35edd5ce1529 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -420,7 +420,7 @@ bool Image::initWithImageFile(const char * strPath) SDL_FreeSurface(iSurf); #else - long bufferLen = 0; + size_t bufferLen = 0; unsigned char* buffer = FileUtils::getInstance()->getFileData(_filePath.c_str(), "rb", &bufferLen); if (buffer != nullptr && bufferLen > 0) @@ -437,7 +437,7 @@ bool Image::initWithImageFile(const char * strPath) bool Image::initWithImageFileThreadSafe(const char *fullpath) { bool ret = false; - long dataLen = 0; + size_t dataLen = 0; _filePath = fullpath; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) FileUtilsAndroid *fileUitls = (FileUtilsAndroid*)FileUtils::getInstance(); @@ -453,7 +453,7 @@ bool Image::initWithImageFileThreadSafe(const char *fullpath) return ret; } -bool Image::initWithImageData(const unsigned char * data, long dataLen) +bool Image::initWithImageData(const unsigned char * data, size_t dataLen) { bool ret = false; @@ -462,7 +462,7 @@ bool Image::initWithImageData(const unsigned char * data, long dataLen) CC_BREAK_IF(! data || dataLen <= 0); unsigned char* unpackedData = nullptr; - int unpackedLen = 0; + size_t unpackedLen = 0; //detecgt and unzip the compress file if (ZipUtils::isCCZBuffer(data, dataLen)) @@ -535,7 +535,7 @@ bool Image::initWithImageData(const unsigned char * data, long dataLen) return ret; } -bool Image::isPng(const unsigned char * data, int dataLen) +bool Image::isPng(const unsigned char * data, size_t dataLen) { if (dataLen <= 8) { @@ -548,13 +548,13 @@ bool Image::isPng(const unsigned char * data, int dataLen) } -bool Image::isEtc(const unsigned char * data, int dataLen) +bool Image::isEtc(const unsigned char * data, size_t dataLen) { return etc1_pkm_is_valid((etc1_byte*)data) ? true : false; } -bool Image::isS3TC(const unsigned char * data, int dataLen) +bool Image::isS3TC(const unsigned char * data, size_t dataLen) { S3TCTexHeader *header = (S3TCTexHeader *)data; @@ -567,7 +567,7 @@ bool Image::isS3TC(const unsigned char * data, int dataLen) return true; } -bool Image::isATITC(const unsigned char *data, int dataLen) +bool Image::isATITC(const unsigned char *data, size_t dataLen) { ATITCTexHeader *header = (ATITCTexHeader *)data; @@ -579,7 +579,7 @@ bool Image::isATITC(const unsigned char *data, int dataLen) return true; } -bool Image::isJpg(const unsigned char * data, int dataLen) +bool Image::isJpg(const unsigned char * data, size_t dataLen) { if (dataLen <= 4) { @@ -591,7 +591,7 @@ bool Image::isJpg(const unsigned char * data, int dataLen) return memcmp(data, JPG_SOI, 2) == 0; } -bool Image::isTiff(const unsigned char * data, int dataLen) +bool Image::isTiff(const unsigned char * data, size_t dataLen) { if (dataLen <= 4) { @@ -605,7 +605,7 @@ bool Image::isTiff(const unsigned char * data, int dataLen) (memcmp(data, TIFF_MM, 2) == 0 && *(static_cast(data) + 2) == 0 && *(static_cast(data) + 3) == 42); } -bool Image::isWebp(const unsigned char * data, int dataLen) +bool Image::isWebp(const unsigned char * data, size_t dataLen) { if (dataLen <= 12) { @@ -619,7 +619,7 @@ bool Image::isWebp(const unsigned char * data, int dataLen) && memcmp(static_cast(data) + 8, WEBP_WEBP, 4) == 0; } -bool Image::isPvr(const unsigned char * data, int dataLen) +bool Image::isPvr(const unsigned char * data, size_t dataLen) { if (static_cast(dataLen) < sizeof(PVRv2TexHeader) || static_cast(dataLen) < sizeof(PVRv3TexHeader)) { @@ -632,7 +632,7 @@ bool Image::isPvr(const unsigned char * data, int dataLen) return memcmp(&headerv2->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203; } -Image::Format Image::detectFormat(const unsigned char * data, int dataLen) +Image::Format Image::detectFormat(const unsigned char * data, size_t dataLen) { if (isPng(data, dataLen)) { @@ -744,7 +744,7 @@ namespace } } -bool Image::initWithJpgData(const unsigned char * data, int dataLen) +bool Image::initWithJpgData(const unsigned char * data, size_t dataLen) { /* these are standard libjpeg structures for reading(decompression) */ struct jpeg_decompress_struct cinfo; @@ -841,7 +841,7 @@ bool Image::initWithJpgData(const unsigned char * data, int dataLen) return bRet; } -bool Image::initWithPngData(const unsigned char * data, int dataLen) +bool Image::initWithPngData(const unsigned char * data, size_t dataLen) { // length of bytes to check if it is a valid png file #define PNGSIGSIZE 8 @@ -1085,7 +1085,7 @@ namespace } } -bool Image::initWithTiffData(const unsigned char * data, int dataLen) +bool Image::initWithTiffData(const unsigned char * data, size_t dataLen) { bool bRet = false; do @@ -1179,7 +1179,7 @@ namespace } } -bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen) +bool Image::initWithPVRv2Data(const unsigned char * data, size_t dataLen) { int dataLength = 0, dataOffset = 0, dataSize = 0; int blockSize = 0, widthBlocks = 0, heightBlocks = 0; @@ -1305,7 +1305,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, int dataLen) return true; } -bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen) +bool Image::initWithPVRv3Data(const unsigned char * data, size_t dataLen) { if (static_cast(dataLen) < sizeof(PVRv3TexHeader)) { @@ -1431,7 +1431,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, int dataLen) return true; } -bool Image::initWithETCData(const unsigned char * data, int dataLen) +bool Image::initWithETCData(const unsigned char * data, size_t dataLen) { const etc1_byte* header = static_cast(data); @@ -1575,7 +1575,7 @@ namespace } } -bool Image::initWithS3TCData(const unsigned char * data, int dataLen) +bool Image::initWithS3TCData(const unsigned char * data, size_t dataLen) { const uint32_t FOURCC_DXT1 = makeFourCC('D', 'X', 'T', '1'); @@ -1697,7 +1697,7 @@ bool Image::initWithS3TCData(const unsigned char * data, int dataLen) } -bool Image::initWithATITCData(const unsigned char *data, int dataLen) +bool Image::initWithATITCData(const unsigned char *data, size_t dataLen) { /* load the .ktx file */ ATITCTexHeader *header = (ATITCTexHeader *)data; @@ -1826,12 +1826,12 @@ bool Image::initWithATITCData(const unsigned char *data, int dataLen) return true; } -bool Image::initWithPVRData(const unsigned char * data, int dataLen) +bool Image::initWithPVRData(const unsigned char * data, size_t dataLen) { return initWithPVRv2Data(data, dataLen) || initWithPVRv3Data(data, dataLen); } -bool Image::initWithWebpData(const unsigned char * data, int dataLen) +bool Image::initWithWebpData(const unsigned char * data, size_t dataLen) { bool bRet = false; do @@ -1866,7 +1866,7 @@ bool Image::initWithWebpData(const unsigned char * data, int dataLen) return bRet; } -bool Image::initWithRawData(const unsigned char * data, long dataLen, long width, long height, long bitsPerComponent, bool preMulti) +bool Image::initWithRawData(const unsigned char * data, size_t dataLen, int width, int height, int bitsPerComponent, bool preMulti) { bool bRet = false; do diff --git a/cocos/2d/platform/CCSAXParser.cpp b/cocos/2d/platform/CCSAXParser.cpp index 056a088826b7..4af437bc201c 100644 --- a/cocos/2d/platform/CCSAXParser.cpp +++ b/cocos/2d/platform/CCSAXParser.cpp @@ -115,7 +115,7 @@ bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength) bool SAXParser::parse(const char *pszFile) { bool ret = false; - long size = 0; + size_t size = 0; char* pBuffer = (char*)FileUtils::getInstance()->getFileData(pszFile, "rt", &size); if (pBuffer != NULL && size > 0) { diff --git a/cocos/base/CCData.cpp b/cocos/base/CCData.cpp index 1c42a12ee59e..bd8716894145 100644 --- a/cocos/base/CCData.cpp +++ b/cocos/base/CCData.cpp @@ -28,18 +28,18 @@ NS_CC_BEGIN -Data::Data(unsigned char *pBytes, const unsigned long nSize) +Data::Data(unsigned char *bytes, const size_t size) { - _size = nSize; + _size = size; _bytes = new unsigned char[_size]; - memcpy(_bytes, pBytes, _size); + memcpy(_bytes, bytes, _size); } -Data::Data(Data *pData) +Data::Data(Data *data) { - _size = pData->_size; + _size = data->_size; _bytes = new unsigned char[_size]; - memcpy(_bytes, pData->_bytes, _size); + memcpy(_bytes, data->_bytes, _size); } Data::~Data() @@ -53,7 +53,7 @@ unsigned char* Data::getBytes() const return _bytes; } -unsigned long Data::getSize() const +size_t Data::getSize() const { return _size; } diff --git a/cocos/base/CCData.h b/cocos/base/CCData.h index 27cb43da6154..49d058e801e5 100644 --- a/cocos/base/CCData.h +++ b/cocos/base/CCData.h @@ -37,7 +37,7 @@ class CC_DLL Data : public Object * @js NA * @lua NA */ - Data(unsigned char *pBytes, const unsigned long nSize); + Data(unsigned char *pBytes, const size_t size); /** * @js NA * @lua NA @@ -52,14 +52,14 @@ class CC_DLL Data : public Object * @js NA * @lua NA */ - static Data* create(unsigned char *pBytes, const unsigned long nSize) + static Data* create(unsigned char *pBytes, const size_t size) { - Data* pRet = new Data(pBytes, nSize); - if (pRet) + auto ret = new Data(pBytes, size); + if (ret) { - pRet->autorelease(); + ret->autorelease(); } - return pRet; + return ret; } /** * @js NA @@ -70,7 +70,7 @@ class CC_DLL Data : public Object * @js NA * @lua NA */ - unsigned long getSize() const; + size_t getSize() const; /** override functions * @js NA @@ -80,7 +80,7 @@ class CC_DLL Data : public Object private: unsigned char* _bytes; - unsigned long _size; + size_t _size; }; NS_CC_END diff --git a/cocos/base/CCString.cpp b/cocos/base/CCString.cpp index 046e8f2e7a1d..c0848f28adc8 100644 --- a/cocos/base/CCString.cpp +++ b/cocos/base/CCString.cpp @@ -255,7 +255,7 @@ String* String::createWithFormat(const char* format, ...) String* String::createWithContentsOfFile(const char* filename) { - long size = 0; + size_t size = 0; unsigned char* data = 0; String* ret = NULL; data = FileUtils::getInstance()->getFileData(filename, "rb", &size); diff --git a/cocos/editor-support/cocosbuilder/CCBReader.cpp b/cocos/editor-support/cocosbuilder/CCBReader.cpp index bf566770fec6..3da2727f8c20 100644 --- a/cocos/editor-support/cocosbuilder/CCBReader.cpp +++ b/cocos/editor-support/cocosbuilder/CCBReader.cpp @@ -244,7 +244,7 @@ Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, } std::string strPath = FileUtils::getInstance()->fullPathForFilename(strCCBFileName.c_str()); - long size = 0; + size_t size = 0; unsigned char * pBytes = FileUtils::getInstance()->getFileData(strPath.c_str(), "rb", &size); Data *data = new Data(pBytes, size); diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp index bf4bd8410604..a5a4aabda417 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp +++ b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp @@ -922,7 +922,7 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader // Load sub file std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName.c_str()); - long size = 0; + size_t size = 0; unsigned char * pBytes = FileUtils::getInstance()->getFileData(path.c_str(), "rb", &size); CCBReader * reader = new CCBReader(pCCBReader); diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 00e1d7f3f435..9784bc9ceff7 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -291,7 +291,7 @@ void DataReaderHelper::addDataFromFile(const char *filePath) size_t startPos = filePathStr.find_last_of("."); std::string str = &filePathStr[startPos]; - long size; + size_t size; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); char *pFileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); @@ -391,7 +391,7 @@ void DataReaderHelper::addDataFromFileAsync(const char *imagePath, const char *p std::string str = &filePathStr[startPos]; std::string fullPath = CCFileUtils::getInstance()->fullPathForFilename(filePath); - long size; + size_t size; // XXX fileContent is being leaked data->fileContent = (char *)CCFileUtils::getInstance()->getFileData(fullPath.c_str() , "r", &size); diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 9cc6348635ce..223b18a788bd 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -128,7 +128,7 @@ UIWidget* GUIReader::widgetFromJsonFile(const char *fileName) jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName); int pos = jsonpath.find_last_of('/'); m_strFilePath = jsonpath.substr(0,pos+1); - long size = 0; + size_t size = 0; des = (char*)(CCFileUtils::getInstance()->getFileData(jsonpath.c_str(),"r" , &size)); if(nullptr == des || strcmp(des, "") == 0) { diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index 385c147e278b..6a1da58fcc2c 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -47,7 +47,7 @@ namespace cocostudio { cocos2d::Node* SceneReader::createNodeWithSceneFile(const char* pszFileName) { - long size = 0; + size_t size = 0; char* pData = 0; cocos2d::Node *pNode = nullptr; do @@ -215,7 +215,7 @@ namespace cocostudio { { file_path = reDir.substr(0, pos+1); } - long size = 0; + size_t size = 0; char *des = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(),"r" , &size)); JsonDictionary *jsonDict = new JsonDictionary(); jsonDict->initWithDescription(des); @@ -285,7 +285,7 @@ namespace cocostudio { if (nResType == 0) { pAttribute = ComAttribute::create(); - long size = 0; + size_t size = 0; char* pData = 0; pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(), "r", &size)); if(pData != nullptr && strcmp(pData, "") != 0) diff --git a/cocos/editor-support/spine/spine-cocos2dx.cpp b/cocos/editor-support/spine/spine-cocos2dx.cpp index 298031aaab62..f711ce39b431 100644 --- a/cocos/editor-support/spine/spine-cocos2dx.cpp +++ b/cocos/editor-support/spine/spine-cocos2dx.cpp @@ -47,7 +47,7 @@ void _AtlasPage_disposeTexture (AtlasPage* self) { } char* _Util_readFile (const char* path, int* length) { - long size; + size_t size; char* data = reinterpret_cast(FileUtils::getInstance()->getFileData( FileUtils::getInstance()->fullPathForFilename(path).c_str(), "r", &size)); *length = size; diff --git a/cocos/physics/CCPhysicsShape.cpp b/cocos/physics/CCPhysicsShape.cpp index b045c433a6fd..976b4abe77a4 100644 --- a/cocos/physics/CCPhysicsShape.cpp +++ b/cocos/physics/CCPhysicsShape.cpp @@ -597,7 +597,7 @@ void PhysicsShapePolygon::getPoints(Point* outPoints) const PhysicsHelper::cpvs2points(((cpPolyShape*)shape)->verts, outPoints, ((cpPolyShape*)shape)->numVerts); } -long PhysicsShapePolygon::getPointsCount() const +size_t PhysicsShapePolygon::getPointsCount() const { return ((cpPolyShape*)_info->getShapes().front())->numVerts; } @@ -712,7 +712,7 @@ Point PhysicsShapeEdgePolygon::getCenter() return _center; } -long PhysicsShapeEdgePolygon::getPointsCount() const +size_t PhysicsShapeEdgePolygon::getPointsCount() const { return _info->getShapes().size() + 1; } @@ -773,7 +773,7 @@ Point PhysicsShapeEdgeChain::getCenter() return _center; } -long PhysicsShapeEdgeChain::getPointsCount() const +size_t PhysicsShapeEdgeChain::getPointsCount() const { return _info->getShapes().size() + 1; } diff --git a/cocos/physics/CCPhysicsShape.h b/cocos/physics/CCPhysicsShape.h index b97bb3cba69b..520b2fff125f 100644 --- a/cocos/physics/CCPhysicsShape.h +++ b/cocos/physics/CCPhysicsShape.h @@ -206,7 +206,7 @@ class PhysicsShapePolygon : public PhysicsShape Point getPoint(int i) const; void getPoints(Point* outPoints) const; - long getPointsCount() const; + size_t getPointsCount() const; virtual Point getCenter() override; protected: bool init(const Point* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Point& offset = Point::ZERO); @@ -249,7 +249,7 @@ class PhysicsShapeEdgeBox : public PhysicsShape static PhysicsShapeEdgeBox* create(const Size& size, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 0, const Point& offset = Point::ZERO); virtual Point getOffset() override { return _offset; } void getPoints(const Point* outPoints) const; - long getPointsCount() const; + int getPointsCount() const; protected: bool init(const Size& size, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1, const Point& offset = Point::ZERO); @@ -271,7 +271,7 @@ class PhysicsShapeEdgePolygon : public PhysicsShape static PhysicsShapeEdgePolygon* create(const Point* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); virtual Point getCenter() override; void getPoints(Point* outPoints) const; - long getPointsCount() const; + size_t getPointsCount() const; protected: bool init(const Point* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); @@ -293,7 +293,7 @@ class PhysicsShapeEdgeChain : public PhysicsShape static PhysicsShapeEdgeChain* create(const Point* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); virtual Point getCenter() override; void getPoints(Point* outPoints) const; - long getPointsCount() const; + size_t getPointsCount() const; protected: bool init(const Point* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); From b16ded6cf01e31e99b6b377ef9ba6322c60f002d Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 4 Dec 2013 16:42:52 +0800 Subject: [PATCH 4/5] replace long to size_t or int --- cocos/2d/CCActionCatmullRom.cpp | 4 +- cocos/2d/CCActionCatmullRom.h | 2 +- cocos/2d/CCActionInterval.cpp | 2 +- cocos/2d/CCActionManager.cpp | 6 +- cocos/2d/CCActionManager.h | 2 +- cocos/2d/CCDirector.cpp | 4 +- cocos/2d/CCDirector.h | 2 +- cocos/2d/CCDrawNode.cpp | 16 ++--- cocos/2d/CCDrawNode.h | 6 +- cocos/2d/CCEventDispatcher.cpp | 6 +- cocos/2d/CCEventDispatcher.h | 6 +- cocos/2d/CCGrid.cpp | 6 +- cocos/2d/CCGrid.h | 2 +- cocos/2d/CCLabelAtlas.cpp | 20 +++--- cocos/2d/CCLabelAtlas.h | 8 +-- cocos/2d/CCLabelBMFont.cpp | 20 +++--- cocos/2d/CCMenuItem.cpp | 20 +++--- cocos/2d/CCMenuItem.h | 20 +++--- cocos/2d/CCNode.cpp | 4 +- cocos/2d/CCNode.h | 4 +- cocos/2d/CCParticleSystem.cpp | 2 +- cocos/2d/CCProfiling.cpp | 2 +- cocos/2d/CCRenderTexture.cpp | 6 +- cocos/2d/CCSpriteBatchNode.cpp | 8 +-- cocos/2d/CCSpriteBatchNode.h | 6 +- cocos/2d/CCTexture2D.cpp | 14 ++--- cocos/2d/CCTextureAtlas.cpp | 62 +++++++++---------- cocos/2d/CCTextureAtlas.h | 42 ++++++------- cocos/2d/CCTextureCache.cpp | 4 +- cocos/2d/CCUserDefault.mm | 2 +- cocos/2d/CCUserDefaultAndroid.cpp | 2 +- cocos/2d/ZipUtils.cpp | 2 +- cocos/2d/ZipUtils.h | 2 +- cocos/2d/ccUtils.cpp | 2 +- cocos/2d/ccUtils.h | 2 +- cocos/2d/platform/CCEGLViewProtocol.cpp | 12 ++-- cocos/2d/platform/CCEGLViewProtocol.h | 10 +-- cocos/2d/platform/CCFileUtils.cpp | 2 +- cocos/2d/platform/CCFileUtils.h | 2 +- cocos/2d/platform/CCThread.cpp | 6 +- cocos/2d/platform/CCThread.h | 4 +- cocos/2d/platform/apple/CCThread.mm | 6 +- cocos/2d/platform/ios/EAGLView.mm | 8 +-- cocos/2d/platform/mac/CCEGLView.mm | 6 +- cocos/2d/platform/mac/EAGLView.mm | 6 +- cocos/base/CCString.cpp | 2 +- cocos/base/CCString.h | 2 +- .../cocosbuilder/CCBAnimationManager.cpp | 4 +- cocos/physics/CCPhysicsContact.h | 2 +- cocos/physics/CCPhysicsWorld.h | 10 +-- external/unzip/unzip.cpp | 2 +- external/unzip/unzip.h | 4 +- 52 files changed, 202 insertions(+), 204 deletions(-) diff --git a/cocos/2d/CCActionCatmullRom.cpp b/cocos/2d/CCActionCatmullRom.cpp index 2ae9a2b77d28..46cbf78c4dd8 100644 --- a/cocos/2d/CCActionCatmullRom.cpp +++ b/cocos/2d/CCActionCatmullRom.cpp @@ -154,7 +154,7 @@ void PointArray::removeControlPointAtIndex(unsigned int index) delete pRemovedPoint; } -unsigned int PointArray::count() const +size_t PointArray::count() const { return _controlPoints->size(); } @@ -177,7 +177,7 @@ PointArray* PointArray::reverse() const void PointArray::reverseInline() { - unsigned long l = _controlPoints->size(); + auto l = _controlPoints->size(); Point *p1 = nullptr; Point *p2 = nullptr; int x, y; diff --git a/cocos/2d/CCActionCatmullRom.h b/cocos/2d/CCActionCatmullRom.h index 7b4452d1bc01..9463bef7ce7c 100644 --- a/cocos/2d/CCActionCatmullRom.h +++ b/cocos/2d/CCActionCatmullRom.h @@ -107,7 +107,7 @@ class CC_DLL PointArray : public Object, public Clonable /** returns the number of objects of the control point array * @js NA */ - unsigned int count() const; + size_t count() const; /** returns a new copy of the array reversed. User is responsible for releasing this copy * @js NA diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index abf98c486836..681fbd02c8eb 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -2100,7 +2100,7 @@ void Animate::update(float t) } Array* frames = _animation->getFrames(); - long numberOfFrames = frames->count(); + auto numberOfFrames = frames->count(); SpriteFrame *frameToDisplay = NULL; for( int i=_nextFrame; i < numberOfFrames; i++ ) { diff --git a/cocos/2d/CCActionManager.cpp b/cocos/2d/CCActionManager.cpp index 56971d5a7662..9d5b12be2024 100644 --- a/cocos/2d/CCActionManager.cpp +++ b/cocos/2d/CCActionManager.cpp @@ -87,7 +87,7 @@ void ActionManager::actionAllocWithHashElement(tHashElement *element) } -void ActionManager::removeActionAtIndex(long index, tHashElement *element) +void ActionManager::removeActionAtIndex(int index, tHashElement *element) { Action *action = (Action*)element->actions->arr[index]; @@ -304,8 +304,8 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const { if (element->actions != NULL) { - long limit = element->actions->num; - for (long i = 0; i < limit; ++i) + auto limit = element->actions->num; + for (size_t i = 0; i < limit; ++i) { Action *action = (Action*)element->actions->arr[i]; diff --git a/cocos/2d/CCActionManager.h b/cocos/2d/CCActionManager.h index cd02feb91b07..9f303c44fc28 100644 --- a/cocos/2d/CCActionManager.h +++ b/cocos/2d/CCActionManager.h @@ -126,7 +126,7 @@ class CC_DLL ActionManager : public Object protected: // declared in ActionManager.m - void removeActionAtIndex(long index, struct _hashElement *pElement); + void removeActionAtIndex(int index, struct _hashElement *pElement); void deleteHashElement(struct _hashElement *pElement); void actionAllocWithHashElement(struct _hashElement *pElement); void update(float dt); diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 36f72c81c560..f737e94ee7c8 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -857,7 +857,7 @@ void Director::calculateMPF() } // returns the FPS image data pointer and len -void Director::getFPSImageData(unsigned char** datapointer, long* length) +void Director::getFPSImageData(unsigned char** datapointer, size_t* length) { // XXX fixed me if it should be used *datapointer = cc_fps_images_png; @@ -880,7 +880,7 @@ void Director::createStatsLabel() Texture2D::PixelFormat currentFormat = Texture2D::getDefaultAlphaPixelFormat(); Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444); unsigned char *data = nullptr; - long dataLength = 0; + size_t dataLength = 0; getFPSImageData(&data, &dataLength); Image* image = new Image(); diff --git a/cocos/2d/CCDirector.h b/cocos/2d/CCDirector.h index 880117a2a3ab..65d3d57ecd74 100644 --- a/cocos/2d/CCDirector.h +++ b/cocos/2d/CCDirector.h @@ -379,7 +379,7 @@ class CC_DLL Director : public Object void showStats(); void createStatsLabel(); void calculateMPF(); - void getFPSImageData(unsigned char** datapointer, long* length); + void getFPSImageData(unsigned char** datapointer, size_t* length); /** calculates delta time since last time it was called */ void calculateDeltaTime(); diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 28da2da3e839..5b5630f60811 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -142,7 +142,7 @@ DrawNode* DrawNode::create() return pRet; } -void DrawNode::ensureCapacity(long count) +void DrawNode::ensureCapacity(int count) { CCASSERT(count>=0, "capacity must be >= 0"); @@ -338,7 +338,7 @@ void DrawNode::drawSegment(const Point &from, const Point &to, float radius, con _dirty = true; } -void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor) +void DrawNode::drawPolygon(Point *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor) { CCASSERT(count >= 0, "invalid count value"); @@ -346,7 +346,7 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f struct ExtrudeVerts* extrude = (struct ExtrudeVerts*)malloc(sizeof(struct ExtrudeVerts)*count); memset(extrude, 0, sizeof(struct ExtrudeVerts)*count); - for (long i = 0; i < count; i++) + for (int i = 0; i < count; i++) { Vertex2F v0 = __v2f(verts[(i-1+count)%count]); Vertex2F v1 = __v2f(verts[i]); @@ -362,15 +362,15 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f bool outline = (borderColor.a > 0.0 && borderWidth > 0.0); - unsigned int triangle_count = 3*count - 2; - unsigned int vertex_count = 3*triangle_count; + int triangle_count = 3*count - 2; + int vertex_count = 3*triangle_count; ensureCapacity(vertex_count); V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount); V2F_C4B_T2F_Triangle *cursor = triangles; float inset = (outline == false ? 0.5 : 0.0); - for (long i = 0; i < count-2; i++) + for (int i = 0; i < count-2; i++) { Vertex2F v0 = v2fsub(__v2f(verts[0 ]), v2fmult(extrude[0 ].offset, inset)); Vertex2F v1 = v2fsub(__v2f(verts[i+1]), v2fmult(extrude[i+1].offset, inset)); @@ -385,9 +385,9 @@ void DrawNode::drawPolygon(Point *verts, long count, const Color4F &fillColor, f *cursor++ = tmp; } - for(long i = 0; i < count; i++) + for(int i = 0; i < count; i++) { - long j = (i+1)%count; + int j = (i+1)%count; Vertex2F v0 = __v2f(verts[i]); Vertex2F v1 = __v2f(verts[j]); diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index 7636cf7326c7..38f899fc7296 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -60,7 +60,7 @@ class CC_DLL DrawNode : public Node * In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor) * @endcode */ - void drawPolygon(Point *verts, long count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor); + void drawPolygon(Point *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor); /** Clear the geometry in the node's buffer. */ void clear(); @@ -92,13 +92,13 @@ class CC_DLL DrawNode : public Node virtual ~DrawNode(); virtual bool init(); - void ensureCapacity(long count); + void ensureCapacity(int count); void render(); GLuint _vao; GLuint _vbo; - long _bufferCapacity; + int _bufferCapacity; GLsizei _bufferCount; V2F_C4B_T2F *_buffer; diff --git a/cocos/2d/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp index 3387e8b3bf65..0b9f4d042d3e 100644 --- a/cocos/2d/CCEventDispatcher.cpp +++ b/cocos/2d/CCEventDispatcher.cpp @@ -491,7 +491,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s auto fixedPriorityListeners = listeners->getFixedPriorityListeners(); auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners(); - long i = 0; + int i = 0; // priority < 0 if (fixedPriorityListeners) { @@ -527,7 +527,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s if (!shouldStopPropagation) { // priority > 0 - for (; i < static_cast(fixedPriorityListeners->size()); ++i) + for (; i < fixedPriorityListeners->size(); ++i) { auto l = fixedPriorityListeners->at(i); @@ -976,7 +976,7 @@ void EventDispatcher::sortEventListenersOfFixedPriority(EventListener::ListenerI }); // FIXME: Should use binary search - long index = 0; + int index = 0; for (auto& listener : *fixedlisteners) { if (listener->getFixedPriority() >= 0) diff --git a/cocos/2d/CCEventDispatcher.h b/cocos/2d/CCEventDispatcher.h index c6127135f24b..b8b1aa8efb6d 100644 --- a/cocos/2d/CCEventDispatcher.h +++ b/cocos/2d/CCEventDispatcher.h @@ -136,12 +136,12 @@ class EventDispatcher : public Object inline std::vector* getFixedPriorityListeners() const { return _fixedListeners; }; inline std::vector* getSceneGraphPriorityListeners() const { return _sceneGraphListeners; }; - inline long getGt0Index() const { return _gt0Index; }; - inline void setGt0Index(long index) { _gt0Index = index; }; + inline int getGt0Index() const { return _gt0Index; }; + inline void setGt0Index(int index) { _gt0Index = index; }; private: std::vector* _fixedListeners; std::vector* _sceneGraphListeners; - long _gt0Index; + int _gt0Index; }; /** Adds event listener with item */ diff --git a/cocos/2d/CCGrid.cpp b/cocos/2d/CCGrid.cpp index 717277eff89f..0fc9dabad062 100644 --- a/cocos/2d/CCGrid.cpp +++ b/cocos/2d/CCGrid.cpp @@ -113,13 +113,13 @@ bool GridBase::initWithSize(const Size& gridSize) Director *pDirector = Director::getInstance(); Size s = pDirector->getWinSizeInPixels(); - unsigned long POTWide = ccNextPOT((unsigned int)s.width); - unsigned long POTHigh = ccNextPOT((unsigned int)s.height); + auto POTWide = ccNextPOT((unsigned int)s.width); + auto POTHigh = ccNextPOT((unsigned int)s.height); // we only use rgba8888 Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888; - long dataLen = POTWide * POTHigh * 4; + size_t dataLen = POTWide * POTHigh * 4; void *data = calloc(dataLen, 1); if (! data) { diff --git a/cocos/2d/CCGrid.h b/cocos/2d/CCGrid.h index 61a8cbbe34f9..7c5f7e03da13 100644 --- a/cocos/2d/CCGrid.h +++ b/cocos/2d/CCGrid.h @@ -95,7 +95,7 @@ class CC_DLL GridBase : public Object protected: bool _active; - long _reuseGrid; + int _reuseGrid; Size _gridSize; Texture2D *_texture; Point _step; diff --git a/cocos/2d/CCLabelAtlas.cpp b/cocos/2d/CCLabelAtlas.cpp index 4c64ca341893..d6592e54e24c 100644 --- a/cocos/2d/CCLabelAtlas.cpp +++ b/cocos/2d/CCLabelAtlas.cpp @@ -42,7 +42,7 @@ NS_CC_BEGIN //CCLabelAtlas - Creation & Init -LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap) +LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) { LabelAtlas *pRet = new LabelAtlas(); if(pRet && pRet->initWithString(string, charMapFile, itemWidth, itemHeight, startCharMap)) @@ -54,15 +54,15 @@ LabelAtlas* LabelAtlas::create(const std::string& string, const std::string& cha return NULL; } -bool LabelAtlas::initWithString(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap) +bool LabelAtlas::initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap) { Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(charMapFile); return initWithString(string, texture, itemWidth, itemHeight, startCharMap); } -bool LabelAtlas::initWithString(const std::string& string, Texture2D* texture, long itemWidth, long itemHeight, long startCharMap) +bool LabelAtlas::initWithString(const std::string& string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap) { - if (AtlasNode::initWithTexture(texture, itemWidth, itemHeight, string.size())) + if (AtlasNode::initWithTexture(texture, itemWidth, itemHeight, static_cast(string.size()))) { _mapStartChar = startCharMap; this->setString(string); @@ -127,9 +127,9 @@ void LabelAtlas::updateAtlasValues() itemHeightInPixels = _itemHeight; } - CCASSERT( static_cast(n) <= _textureAtlas->getCapacity(), "updateAtlasValues: Invalid String length"); + CCASSERT(n <= _textureAtlas->getCapacity(), "updateAtlasValues: Invalid String length"); V3F_C4B_T2F_Quad* quads = _textureAtlas->getQuads(); - for(long i = 0; i < static_cast(n); i++) { + for(size_t i = 0; i < n; i++) { unsigned char a = s[i] - _mapStartChar; float row = (float) (a % _itemsPerRow); @@ -177,8 +177,8 @@ void LabelAtlas::updateAtlasValues() } if (n > 0 ){ _textureAtlas->setDirty(true); - long totalQuads = _textureAtlas->getTotalQuads(); - if (static_cast(n) > totalQuads) { + auto totalQuads = _textureAtlas->getTotalQuads(); + if (n > totalQuads) { _textureAtlas->increaseTotalQuadsWith(n - totalQuads); } } @@ -188,7 +188,7 @@ void LabelAtlas::updateAtlasValues() void LabelAtlas::setString(const std::string &label) { size_t len = label.size(); - if (static_cast(len) > _textureAtlas->getTotalQuads()) + if (len > _textureAtlas->getTotalQuads()) { _textureAtlas->resizeCapacity(len); } @@ -200,7 +200,7 @@ void LabelAtlas::setString(const std::string &label) this->setContentSize(s); - _quadsToDraw = len; + _quadsToDraw = static_cast(len); } const std::string& LabelAtlas::getString(void) const diff --git a/cocos/2d/CCLabelAtlas.h b/cocos/2d/CCLabelAtlas.h index 8fd81b9bdaa3..47adb534a1b0 100644 --- a/cocos/2d/CCLabelAtlas.h +++ b/cocos/2d/CCLabelAtlas.h @@ -67,7 +67,7 @@ class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol } /** creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ - static LabelAtlas * create(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap); + static LabelAtlas * create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); /** creates the LabelAtlas with a string and a configuration file @since v2.0 @@ -75,7 +75,7 @@ class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol static LabelAtlas* create(const std::string& string, const std::string& fntFile); /** initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ - bool initWithString(const std::string& string, const std::string& charMapFile, long itemWidth, long itemHeight, long startCharMap); + bool initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap); /** initializes the LabelAtlas with a string and a configuration file @since v2.0 @@ -83,7 +83,7 @@ class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol bool initWithString(const std::string& string, const std::string& fntFile); /** initializes the LabelAtlas with a string, a texture, the width and height in points of each element and the starting char of the atlas */ - bool initWithString(const std::string& string, Texture2D* texture, long itemWidth, long itemHeight, long startCharMap); + bool initWithString(const std::string& string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap); // super methods virtual void updateAtlasValues(); @@ -99,7 +99,7 @@ class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol // string to render std::string _string; // the first char in the charmap - long _mapStartChar; + int _mapStartChar; }; // end of GUI group diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index 46d20bce9a0a..ff51bd3970f4 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -267,8 +267,8 @@ void CCBMFontConfiguration::parseImageFileName(std::string line, const std::stri ////////////////////////////////////////////////////////////////////////// // page ID. Sanity check - long index = line.find('=')+1; - long index2 = line.find(' ', index); + auto index = line.find('=')+1; + auto index2 = line.find(' ', index); std::string value = line.substr(index, index2-index); CCASSERT(atoi(value.c_str()) == 0, "LabelBMFont file could not be found"); // file @@ -288,8 +288,8 @@ void CCBMFontConfiguration::parseInfoArguments(std::string line) ////////////////////////////////////////////////////////////////////////// // padding - long index = line.find("padding="); - long index2 = line.find(' ', index); + auto index = line.find("padding="); + auto index2 = line.find(' ', index); std::string value = line.substr(index, index2-index); sscanf(value.c_str(), "padding=%d,%d,%d,%d", &_padding.top, &_padding.right, &_padding.bottom, &_padding.left); CCLOG("cocos2d: padding: %d,%d,%d,%d", _padding.left, _padding.top, _padding.right, _padding.bottom); @@ -303,8 +303,8 @@ void CCBMFontConfiguration::parseCommonArguments(std::string line) ////////////////////////////////////////////////////////////////////////// // Height - long index = line.find("lineHeight="); - long index2 = line.find(' ', index); + auto index = line.find("lineHeight="); + auto index2 = line.find(' ', index); std::string value = line.substr(index, index2-index); sscanf(value.c_str(), "lineHeight=%d", &_commonHeight); // scaleW. sanity check @@ -334,8 +334,8 @@ void CCBMFontConfiguration::parseCharacterDefinition(std::string line, ccBMFontD ////////////////////////////////////////////////////////////////////////// // Character ID - long index = line.find("id="); - long index2 = line.find(' ', index); + auto index = line.find("id="); + auto index2 = line.find(' ', index); std::string value = line.substr(index, index2-index); sscanf(value.c_str(), "id=%u", &characterDefinition->charID); @@ -385,8 +385,8 @@ void CCBMFontConfiguration::parseKerningEntry(std::string line) // first int first; - long index = line.find("first="); - long index2 = line.find(' ', index); + auto index = line.find("first="); + auto index2 = line.find(' ', index); std::string value = line.substr(index, index2-index); sscanf(value.c_str(), "first=%d", &first); diff --git a/cocos/2d/CCMenuItem.cpp b/cocos/2d/CCMenuItem.cpp index 89aa7eaba636..6b02030baffe 100644 --- a/cocos/2d/CCMenuItem.cpp +++ b/cocos/2d/CCMenuItem.cpp @@ -42,7 +42,7 @@ THE SOFTWARE. NS_CC_BEGIN -static long _globalFontSize = kItemSize; +static int _globalFontSize = kItemSize; static std::string _globalFontName = "Marker Felt"; static bool _globalFontNameRelease = false; @@ -310,13 +310,13 @@ void MenuItemLabel::setEnabled(bool enabled) //CCMenuItemAtlasFont // -MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap) +MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap) { return MenuItemAtlasFont::create(value, charMapFile, itemWidth, itemHeight, startCharMap, (const ccMenuCallback&)nullptr); } // XXX: deprecated -MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) +MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) { MenuItemAtlasFont *ret = new MenuItemAtlasFont(); ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector); @@ -324,7 +324,7 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const char* value, const char* cha return ret; } -MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback) +MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback) { MenuItemAtlasFont *ret = new MenuItemAtlasFont(); ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, callback); @@ -333,14 +333,14 @@ MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const st } // XXX: deprecated -bool MenuItemAtlasFont::initWithString(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) +bool MenuItemAtlasFont::initWithString(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector) { _target = target; CC_SAFE_RETAIN(_target); return initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, std::bind(selector,target, std::placeholders::_1) ); } -bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback) +bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback) { CCASSERT( value.size() != 0, "value length must be greater than 0"); LabelAtlas *label = new LabelAtlas(); @@ -357,12 +357,12 @@ bool MenuItemAtlasFont::initWithString(const std::string& value, const std::stri //CCMenuItemFont // -void MenuItemFont::setFontSize(long s) +void MenuItemFont::setFontSize(int s) { _globalFontSize = s; } -long MenuItemFont::getFontSize() +int MenuItemFont::getFontSize() { return _globalFontSize; } @@ -449,13 +449,13 @@ void MenuItemFont::recreateLabel() this->setLabel(label); } -void MenuItemFont::setFontSizeObj(long s) +void MenuItemFont::setFontSizeObj(int s) { _fontSize = s; recreateLabel(); } -long MenuItemFont::getFontSizeObj() const +int MenuItemFont::getFontSizeObj() const { return _fontSize; } diff --git a/cocos/2d/CCMenuItem.h b/cocos/2d/CCMenuItem.h index 09de7fe39944..f477cdf4beb5 100644 --- a/cocos/2d/CCMenuItem.h +++ b/cocos/2d/CCMenuItem.h @@ -212,11 +212,11 @@ class CC_DLL MenuItemAtlasFont : public MenuItemLabel { public: /** creates a menu item from a string and atlas with a target/selector */ - static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap); + static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap); /** creates a menu item from a string and atlas. Use it with MenuItemToggle */ - CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char* value, const char* charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE static MenuItemAtlasFont* create(const char* value, const char* charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); /** creates a menu item from a string and atlas. Use it with MenuItemToggle */ - static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback); + static MenuItemAtlasFont* create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback); protected: /** @@ -230,9 +230,9 @@ class CC_DLL MenuItemAtlasFont : public MenuItemLabel virtual ~MenuItemAtlasFont(){} /** initializes a menu item from a string and atlas with a target/selector */ - CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, long itemWidth, long itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); + CC_DEPRECATED_ATTRIBUTE bool initWithString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, Object* target, SEL_MenuHandler selector); /** initializes a menu item from a string and atlas with a target/selector */ - bool initWithString(const std::string& value, const std::string& charMapFile, long itemWidth, long itemHeight, char startCharMap, const ccMenuCallback& callback); + bool initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback); private: CC_DISALLOW_COPY_AND_ASSIGN(MenuItemAtlasFont); @@ -253,9 +253,9 @@ class CC_DLL MenuItemFont : public MenuItemLabel static MenuItemFont * create(const std::string& value, const ccMenuCallback& callback); /** set default font size */ - static void setFontSize(long size); + static void setFontSize(int size); /** get default font size */ - static long getFontSize(); + static int getFontSize(); CC_DEPRECATED_ATTRIBUTE static unsigned int fontSize() { return MenuItemFont::getFontSize(); }; /** set the default font name */ static void setFontName(const std::string& name); @@ -268,12 +268,12 @@ class CC_DLL MenuItemFont : public MenuItemLabel * so change the name to setFontSizeObj * @js setFontSize */ - void setFontSizeObj(long size); + void setFontSizeObj(int size); /** get font size * @js getFontSize */ - long getFontSizeObj() const; + int getFontSizeObj() const; CC_DEPRECATED_ATTRIBUTE unsigned int fontSizeObj() const { return getFontSizeObj(); }; /** set the font name @@ -309,7 +309,7 @@ class CC_DLL MenuItemFont : public MenuItemLabel void recreateLabel(); - long _fontSize; + int _fontSize; std::string _fontName; private: diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index bdff745edf5f..0c1be64b9524 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -404,7 +404,7 @@ void Node::setPositionY(float y) setPosition(Point(_position.x, y)); } -long Node::getChildrenCount() const +size_t Node::getChildrenCount() const { return _children ? _children->count() : 0; } @@ -756,7 +756,7 @@ void Node::removeAllChildrenWithCleanup(bool cleanup) } -void Node::detachChild(Node *child, long childIndex, bool doCleanup) +void Node::detachChild(Node *child, int childIndex, bool doCleanup) { // IMPORTANT: // -1st do onExit diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 617244a40b5e..c581f8d45c17 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -622,7 +622,7 @@ class CC_DLL Node : public Object * * @return The amount of children. */ - long getChildrenCount() const; + size_t getChildrenCount() const; /** * Sets the parent node @@ -1403,7 +1403,7 @@ class CC_DLL Node : public Object void insertChild(Node* child, int z); /// Removes a child, call child->onExit(), do cleanup, remove it from children array. - void detachChild(Node *child, long index, bool doCleanup); + void detachChild(Node *child, int index, bool doCleanup); /// Convert cocos2d coordinates to UI windows coordinate. Point convertToWindowSpace(const Point& nodePoint) const; diff --git a/cocos/2d/CCParticleSystem.cpp b/cocos/2d/CCParticleSystem.cpp index 53fa60625f38..ad772bfc581b 100644 --- a/cocos/2d/CCParticleSystem.cpp +++ b/cocos/2d/CCParticleSystem.cpp @@ -388,7 +388,7 @@ bool ParticleSystem::initWithDictionary(Dictionary *dictionary, const std::strin const char *textureData = dictionary->valueForKey("textureImageData")->getCString(); CCASSERT(textureData, ""); - long dataLen = strlen(textureData); + auto dataLen = strlen(textureData); if(dataLen != 0) { // if it fails, try to get it from the base64-gzipped data diff --git a/cocos/2d/CCProfiling.cpp b/cocos/2d/CCProfiling.cpp index e0878d5f5a0c..cfc75811425f 100644 --- a/cocos/2d/CCProfiling.cpp +++ b/cocos/2d/CCProfiling.cpp @@ -166,7 +166,7 @@ void ProfilingEndTimingBlock(const char *timerName) CCASSERT(timer, "CCProfilingTimer not found"); - long duration = static_cast(chrono::duration_cast(now - timer->_startTime).count()); + auto duration = chrono::duration_cast(now - timer->_startTime).count(); timer->totalTime += duration; timer->_averageTime1 = (timer->_averageTime1 + duration) / 2.0f; diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index a35a564f856c..266aa2a258d7 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -198,8 +198,8 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); // textures must be power of two squared - long powW = 0; - long powH = 0; + int powW = 0; + int powH = 0; if (Configuration::getInstance()->supportsNPOT()) { @@ -212,7 +212,7 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat powH = ccNextPOT(h); } - long dataLen = (long)(powW * powH * 4); + size_t dataLen = powW * powH * 4; data = malloc(dataLen); CC_BREAK_IF(! data); diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 03a71abf1c86..b6b318d8367c 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -64,7 +64,7 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity * creation with File Image */ -SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, long capacity/* = DEFAULT_CAPACITY*/) +SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, int capacity/* = DEFAULT_CAPACITY*/) { SpriteBatchNode *batchNode = new SpriteBatchNode(); batchNode->initWithFile(fileImage, capacity); @@ -76,7 +76,7 @@ SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, long capacity/* /* * init with Texture2D */ -bool SpriteBatchNode::initWithTexture(Texture2D *tex, long capacity) +bool SpriteBatchNode::initWithTexture(Texture2D *tex, int capacity) { CCASSERT(capacity>=0, "Capacity must be >= 0"); @@ -112,7 +112,7 @@ bool SpriteBatchNode::init() /* * init with FileImage */ -bool SpriteBatchNode::initWithFile(const char* fileImage, long capacity) +bool SpriteBatchNode::initWithFile(const char* fileImage, int capacity) { Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage); return initWithTexture(texture2D, capacity); @@ -408,7 +408,7 @@ void SpriteBatchNode::draw(void) CC_PROFILER_STOP("CCSpriteBatchNode - draw"); } -void SpriteBatchNode::increaseAtlasCapacity(void) +void SpriteBatchNode::increaseAtlasCapacity() { // if we're going beyond the current TextureAtlas's capacity, // all the previously initialized sprites will need to redo their texture coords diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index 8d1b93077176..6ba402fe57d4 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -74,7 +74,7 @@ class CC_DLL SpriteBatchNode : public Node, public TextureProtocol The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr. */ - static SpriteBatchNode* create(const char* fileImage, long capacity = DEFAULT_CAPACITY); + static SpriteBatchNode* create(const char* fileImage, int capacity = DEFAULT_CAPACITY); /** * @js ctor */ @@ -88,14 +88,14 @@ class CC_DLL SpriteBatchNode : public Node, public TextureProtocol /** initializes a SpriteBatchNode with a texture2d and capacity of children. The capacity will be increased in 33% in runtime if it run out of space. */ - bool initWithTexture(Texture2D *tex, long capacity); + bool initWithTexture(Texture2D *tex, int capacity); /** initializes a SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr. * @js init * @lua init */ - bool initWithFile(const char* fileImage, long capacity); + bool initWithFile(const char* fileImage, int capacity); bool init(); /** returns the TextureAtlas object */ diff --git a/cocos/2d/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp index af21b7c885a0..c058a4a12e9f 100644 --- a/cocos/2d/CCTexture2D.cpp +++ b/cocos/2d/CCTexture2D.cpp @@ -622,8 +622,8 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat CHECK_GL_ERROR_DEBUG(); // clean possible GL error // Specify OpenGL texture image - long width = pixelsWide; - long height = pixelsHigh; + int width = pixelsWide; + int height = pixelsHigh; for (int i = 0; i < mipmapsNum; ++i) { @@ -641,7 +641,7 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat if (i > 0 && (width != height || ccNextPOT(width) != width )) { - CCLOG("cocos2d: Texture2D. WARNING. Mipmap level %u is not squared. Texture won't render correctly. width=%ld != height=%ld", i, width, height); + CCLOG("cocos2d: Texture2D. WARNING. Mipmap level %u is not squared. Texture won't render correctly. width=%d != height=%d", i, width, height); } GLenum err = glGetError(); @@ -1243,7 +1243,7 @@ void Texture2D::PVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) void Texture2D::generateMipmap() { - CCASSERT( static_cast(_pixelsWide) == ccNextPOT(_pixelsWide) && static_cast(_pixelsHigh) == ccNextPOT(_pixelsHigh), "Mipmap texture only works in POT textures"); + CCASSERT(_pixelsWide == ccNextPOT(_pixelsWide) && _pixelsHigh == ccNextPOT(_pixelsHigh), "Mipmap texture only works in POT textures"); GL::bindTexture2D( _name ); glGenerateMipmap(GL_TEXTURE_2D); _hasMipmaps = true; @@ -1256,8 +1256,8 @@ bool Texture2D::hasMipmaps() const void Texture2D::setTexParameters(const TexParams &texParams) { - CCASSERT( (static_cast(_pixelsWide) == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) && - (static_cast(_pixelsHigh) == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE), + CCASSERT((_pixelsWide == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) && + (_pixelsHigh == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE), "GL_CLAMP_TO_EDGE should be used in NPOT dimensions"); GL::bindTexture2D( _name ); @@ -1347,7 +1347,7 @@ const char* Texture2D::getStringForFormat() const default: CCASSERT(false , "unrecognized pixel format"); - CCLOG("stringForFormat: %ld, cannot give useful result", (long)_pixelFormat); + CCLOG("stringForFormat: %d, cannot give useful result", _pixelFormat); break; } diff --git a/cocos/2d/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp index ec42b9dbfd0b..27affbcb31e2 100644 --- a/cocos/2d/CCTextureAtlas.cpp +++ b/cocos/2d/CCTextureAtlas.cpp @@ -74,12 +74,12 @@ TextureAtlas::~TextureAtlas() #endif } -long TextureAtlas::getTotalQuads() const +int TextureAtlas::getTotalQuads() const { return _totalQuads; } -long TextureAtlas::getCapacity() const +int TextureAtlas::getCapacity() const { return _capacity; } @@ -110,7 +110,7 @@ void TextureAtlas::setQuads(V3F_C4B_T2F_Quad* quads) // TextureAtlas - alloc & init -TextureAtlas * TextureAtlas::create(const char* file, long capacity) +TextureAtlas * TextureAtlas::create(const char* file, int capacity) { TextureAtlas * textureAtlas = new TextureAtlas(); if(textureAtlas && textureAtlas->initWithFile(file, capacity)) @@ -122,7 +122,7 @@ TextureAtlas * TextureAtlas::create(const char* file, long capacity) return NULL; } -TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, long capacity) +TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, int capacity) { TextureAtlas * textureAtlas = new TextureAtlas(); if (textureAtlas && textureAtlas->initWithTexture(texture, capacity)) @@ -134,7 +134,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, long capacity return NULL; } -bool TextureAtlas::initWithFile(const char * file, long capacity) +bool TextureAtlas::initWithFile(const char * file, int capacity) { // retained in property Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file); @@ -150,7 +150,7 @@ bool TextureAtlas::initWithFile(const char * file, long capacity) } } -bool TextureAtlas::initWithTexture(Texture2D *texture, long capacity) +bool TextureAtlas::initWithTexture(Texture2D *texture, int capacity) { CCASSERT(capacity>=0, "Capacity must be >= 0"); @@ -224,7 +224,7 @@ void TextureAtlas::listenBackToForeground(Object *obj) const char* TextureAtlas::description() const { - return String::createWithFormat("", _totalQuads)->getCString(); + return String::createWithFormat("", _totalQuads)->getCString(); } @@ -317,7 +317,7 @@ void TextureAtlas::mapBuffers() // TextureAtlas - Update, Insert, Move & Remove -void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, long index) +void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, int index) { CCASSERT( index >= 0 && index < _capacity, "updateQuadWithTexture: Invalid index"); @@ -330,7 +330,7 @@ void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, long index) } -void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, long index) +void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, int index) { CCASSERT( index>=0 && index<_capacity, "insertQuadWithTexture: Invalid index"); @@ -354,7 +354,7 @@ void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, long index) } -void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount) +void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount) { CCASSERT(index>=0 && amount>=0 && index+amount<=_capacity, "insertQuadWithTexture: Invalid index + amount"); @@ -363,7 +363,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount) CCASSERT( _totalQuads <= _capacity, "invalid totalQuads"); // issue #575. index can be > totalQuads - long remaining = (_totalQuads-1) - index - amount; + int remaining = (_totalQuads-1) - index - amount; // last object doesn't need to be moved if( remaining > 0) @@ -373,9 +373,9 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount) } - long max = index + amount; + int max = index + amount; int j = 0; - for (long i = index; i < max ; i++) + for (int i = index; i < max ; i++) { _quads[index] = quads[j]; index++; @@ -385,7 +385,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount) _dirty = true; } -void TextureAtlas::insertQuadFromIndex(long oldIndex, long newIndex) +void TextureAtlas::insertQuadFromIndex(int oldIndex, int newIndex) { CCASSERT( newIndex >= 0 && newIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index"); CCASSERT( oldIndex >= 0 && oldIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index"); @@ -396,9 +396,9 @@ void TextureAtlas::insertQuadFromIndex(long oldIndex, long newIndex) } // because it is ambiguous in iphone, so we implement abs ourselves // unsigned int howMany = abs( oldIndex - newIndex); - long howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex); - long dst = oldIndex; - long src = oldIndex + 1; + auto howMany = (oldIndex - newIndex) > 0 ? (oldIndex - newIndex) : (newIndex - oldIndex); + auto dst = oldIndex; + auto src = oldIndex + 1; if( oldIndex > newIndex) { dst = newIndex+1; @@ -414,11 +414,11 @@ void TextureAtlas::insertQuadFromIndex(long oldIndex, long newIndex) _dirty = true; } -void TextureAtlas::removeQuadAtIndex(long index) +void TextureAtlas::removeQuadAtIndex(int index) { CCASSERT( index>=0 && index<_totalQuads, "removeQuadAtIndex: Invalid index"); - long remaining = (_totalQuads-1) - index; + auto remaining = (_totalQuads-1) - index; // last object doesn't need to be moved if( remaining ) @@ -433,11 +433,11 @@ void TextureAtlas::removeQuadAtIndex(long index) _dirty = true; } -void TextureAtlas::removeQuadsAtIndex(long index, long amount) +void TextureAtlas::removeQuadsAtIndex(int index, int amount) { CCASSERT(index>=0 && amount>=0 && index+amount<=_totalQuads, "removeQuadAtIndex: index + amount out of bounds"); - long remaining = (_totalQuads) - (index + amount); + auto remaining = (_totalQuads) - (index + amount); _totalQuads -= amount; @@ -455,14 +455,14 @@ void TextureAtlas::removeAllQuads() } // TextureAtlas - Resize -bool TextureAtlas::resizeCapacity(long newCapacity) +bool TextureAtlas::resizeCapacity(int newCapacity) { CCASSERT(newCapacity>=0, "capacity >= 0"); if( newCapacity == _capacity ) { return true; } - long oldCapactiy = _capacity; + auto oldCapactiy = _capacity; // update capacity and totolQuads _totalQuads = MIN(_totalQuads, newCapacity); _capacity = newCapacity; @@ -529,13 +529,13 @@ bool TextureAtlas::resizeCapacity(long newCapacity) return true; } -void TextureAtlas::increaseTotalQuadsWith(long amount) +void TextureAtlas::increaseTotalQuadsWith(int amount) { CCASSERT(amount>=0, "amount >= 0"); _totalQuads += amount; } -void TextureAtlas::moveQuadsFromIndex(long oldIndex, long amount, long newIndex) +void TextureAtlas::moveQuadsFromIndex(int oldIndex, int amount, int newIndex) { CCASSERT(oldIndex>=0 && amount>=0 && newIndex>=0, "values must be >= 0"); CCASSERT(newIndex + amount <= _totalQuads, "insertQuadFromIndex:atIndex: Invalid index"); @@ -567,7 +567,7 @@ void TextureAtlas::moveQuadsFromIndex(long oldIndex, long amount, long newIndex) _dirty = true; } -void TextureAtlas::moveQuadsFromIndex(long index, long newIndex) +void TextureAtlas::moveQuadsFromIndex(int index, int newIndex) { CCASSERT(index>=0 && newIndex>=0, "values must be >= 0"); CCASSERT(newIndex + (_totalQuads - index) <= _capacity, "moveQuadsFromIndex move is out of bounds"); @@ -575,14 +575,14 @@ void TextureAtlas::moveQuadsFromIndex(long index, long newIndex) memmove(_quads + newIndex,_quads + index, (_totalQuads - index) * sizeof(_quads[0])); } -void TextureAtlas::fillWithEmptyQuadsFromIndex(long index, long amount) +void TextureAtlas::fillWithEmptyQuadsFromIndex(int index, int amount) { CCASSERT(index>=0 && amount>=0, "values must be >= 0"); V3F_C4B_T2F_Quad quad; memset(&quad, 0, sizeof(quad)); - long to = index + amount; - for (long i = index ; i < to ; i++) + auto to = index + amount; + for (int i = index ; i < to ; i++) { _quads[i] = quad; } @@ -595,13 +595,13 @@ void TextureAtlas::drawQuads() this->drawNumberOfQuads(_totalQuads, 0); } -void TextureAtlas::drawNumberOfQuads(long numberOfQuads) +void TextureAtlas::drawNumberOfQuads(int numberOfQuads) { CCASSERT(numberOfQuads>=0, "numberOfQuads must be >= 0"); this->drawNumberOfQuads(numberOfQuads, 0); } -void TextureAtlas::drawNumberOfQuads(long numberOfQuads, long start) +void TextureAtlas::drawNumberOfQuads(int numberOfQuads, int start) { CCASSERT(numberOfQuads>=0 && start>=0, "numberOfQuads and start must be >= 0"); diff --git a/cocos/2d/CCTextureAtlas.h b/cocos/2d/CCTextureAtlas.h index 86f0ba209fd6..47a5c1c48468 100644 --- a/cocos/2d/CCTextureAtlas.h +++ b/cocos/2d/CCTextureAtlas.h @@ -59,13 +59,13 @@ class CC_DLL TextureAtlas : public Object /** creates a TextureAtlas with an filename and with an initial capacity for Quads. * The TextureAtlas capacity can be increased in runtime. */ - static TextureAtlas* create(const char* file , long capacity); + static TextureAtlas* create(const char* file , int capacity); /** creates a TextureAtlas with a previously initialized Texture2D object, and * with an initial capacity for n Quads. * The TextureAtlas capacity can be increased in runtime. */ - static TextureAtlas* createWithTexture(Texture2D *texture, long capacity); + static TextureAtlas* createWithTexture(Texture2D *texture, int capacity); /** * @js ctor */ @@ -81,7 +81,7 @@ class CC_DLL TextureAtlas : public Object * * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) */ - bool initWithFile(const char* file, long capacity); + bool initWithFile(const char* file, int capacity); /** initializes a TextureAtlas with a previously initialized Texture2D object, and * with an initial capacity for Quads. @@ -89,43 +89,43 @@ class CC_DLL TextureAtlas : public Object * * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) */ - bool initWithTexture(Texture2D *texture, long capacity); + bool initWithTexture(Texture2D *texture, int capacity); /** updates a Quad (texture, vertex and color) at a certain index * index must be between 0 and the atlas capacity - 1 @since v0.8 */ - void updateQuad(V3F_C4B_T2F_Quad* quad, long index); + void updateQuad(V3F_C4B_T2F_Quad* quad, int index); /** Inserts a Quad (texture, vertex and color) at a certain index index must be between 0 and the atlas capacity - 1 @since v0.8 */ - void insertQuad(V3F_C4B_T2F_Quad* quad, long index); + void insertQuad(V3F_C4B_T2F_Quad* quad, int index); /** Inserts a c array of quads at a given index index must be between 0 and the atlas capacity - 1 this method doesn't enlarge the array when amount + index > totalQuads @since v1.1 */ - void insertQuads(V3F_C4B_T2F_Quad* quads, long index, long amount); + void insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount); /** Removes the quad that is located at a certain index and inserts it at a new index This operation is faster than removing and inserting in a quad in 2 different steps @since v0.7.2 */ - void insertQuadFromIndex(long fromIndex, long newIndex); + void insertQuadFromIndex(int fromIndex, int newIndex); /** removes a quad at a given index number. The capacity remains the same, but the total number of quads to be drawn is reduced in 1 @since v0.7.2 */ - void removeQuadAtIndex(long index); + void removeQuadAtIndex(int index); /** removes a amount of quads starting from index @since 1.1 */ - void removeQuadsAtIndex(long index, long amount); + void removeQuadsAtIndex(int index, int amount); /** removes all Quads. The TextureAtlas capacity remains untouched. No memory is freed. The total number of quads to be drawn will be 0 @@ -138,19 +138,19 @@ class CC_DLL TextureAtlas : public Object * It returns true if the resize was successful. * If it fails to resize the capacity it will return false with a new capacity of 0. */ - bool resizeCapacity(long capacity); + bool resizeCapacity(int capacity); /** Used internally by ParticleBatchNode don't use this unless you know what you're doing @since 1.1 */ - void increaseTotalQuadsWith(long amount); + void increaseTotalQuadsWith(int amount); /** Moves an amount of quads from oldIndex at newIndex @since v1.1 */ - void moveQuadsFromIndex(long oldIndex, long amount, long newIndex); + void moveQuadsFromIndex(int oldIndex, int amount, int newIndex); /** Moves quads from index till totalQuads to the newIndex @@ -158,26 +158,26 @@ class CC_DLL TextureAtlas : public Object This method doesn't enlarge the array if newIndex + quads to be moved > capacity @since 1.1 */ - void moveQuadsFromIndex(long index, long newIndex); + void moveQuadsFromIndex(int index, int newIndex); /** Ensures that after a realloc quads are still empty Used internally by ParticleBatchNode @since 1.1 */ - void fillWithEmptyQuadsFromIndex(long index, long amount); + void fillWithEmptyQuadsFromIndex(int index, int amount); /** draws n quads * n can't be greater than the capacity of the Atlas */ - void drawNumberOfQuads(long n); + void drawNumberOfQuads(int n); /** draws n quads from an index (offset). n + start can't be greater than the capacity of the atlas @since v1.0 */ - void drawNumberOfQuads(long numberOfQuads, long start); + void drawNumberOfQuads(int numberOfQuads, int start); /** draws all the Atlas's Quads */ @@ -197,10 +197,10 @@ class CC_DLL TextureAtlas : public Object const char* description() const; /** Gets the quantity of quads that are going to be drawn */ - long getTotalQuads() const; + int getTotalQuads() const; /** Gets the quantity of quads that can be stored with the current texture atlas size */ - long getCapacity() const; + int getCapacity() const; /** Gets the texture of the texture atlas */ Texture2D* getTexture() const; @@ -226,9 +226,9 @@ class CC_DLL TextureAtlas : public Object GLuint _buffersVBO[2]; //0: vertex 1: indices bool _dirty; //indicates whether or not the array buffer of the VBO needs to be updated /** quantity of quads that are going to be drawn */ - long _totalQuads; + int _totalQuads; /** quantity of quads that can be stored with the current texture atlas size */ - long _capacity; + int _capacity; /** Texture of the texture atlas */ Texture2D* _texture; /** Quads that are going to be rendered */ diff --git a/cocos/2d/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp index a16f85f28d63..42d4e817926e 100644 --- a/cocos/2d/CCTextureCache.cpp +++ b/cocos/2d/CCTextureCache.cpp @@ -446,7 +446,7 @@ void TextureCache::dumpCachedTextureInfo() const Texture2D* tex = it->second; unsigned int bpp = tex->getBitsPerPixelForFormat(); // Each texture takes up width * height * bytesPerPixel bytes. - long bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8; + int bytes = tex->getPixelsWide() * tex->getPixelsHigh() * bpp / 8; totalBytes += bytes; count++; log("cocos2d: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB", @@ -607,7 +607,7 @@ void VolatileTextureMgr::reloadAllTextures() case VolatileTexture::kImageFile: { Image* image = new Image(); - long size = 0; + size_t size = 0; unsigned char* pBuffer = FileUtils::getInstance()->getFileData(vt->_fileName.c_str(), "rb", &size); if (image && image->initWithImageData(pBuffer, size)) diff --git a/cocos/2d/CCUserDefault.mm b/cocos/2d/CCUserDefault.mm index 7d6b952555ca..1e469f7cc401 100644 --- a/cocos/2d/CCUserDefault.mm +++ b/cocos/2d/CCUserDefault.mm @@ -420,7 +420,7 @@ static void deleteNodeByKey(const char *pKey) else { unsigned char *bytes = {0}; - unsigned long size = 0; + size_t size = 0; if (data.length > 0) { bytes = (unsigned char*)data.bytes; diff --git a/cocos/2d/CCUserDefaultAndroid.cpp b/cocos/2d/CCUserDefaultAndroid.cpp index 8f6895f5724f..33fc49861180 100644 --- a/cocos/2d/CCUserDefaultAndroid.cpp +++ b/cocos/2d/CCUserDefaultAndroid.cpp @@ -74,7 +74,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc { tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); *doc = xmlDoc; - long size; + size_t size; char* pXmlBuffer = (char*)FileUtils::getInstance()->getFileData(UserDefault::getInstance()->getXMLFilePath().c_str(), "rb", &size); //const char* pXmlBuffer = (const char*)data.getBuffer(); if(NULL == pXmlBuffer) diff --git a/cocos/2d/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp index 5912ffe17711..97374a6a5236 100644 --- a/cocos/2d/ZipUtils.cpp +++ b/cocos/2d/ZipUtils.cpp @@ -591,7 +591,7 @@ bool ZipFile::fileExists(const std::string &fileName) const return ret; } -unsigned char *ZipFile::getFileData(const std::string &fileName, long *size) +unsigned char *ZipFile::getFileData(const std::string &fileName, size_t *size) { unsigned char * buffer = NULL; if (size) diff --git a/cocos/2d/ZipUtils.h b/cocos/2d/ZipUtils.h index c322f8300a9a..0d4eb895a9ea 100644 --- a/cocos/2d/ZipUtils.h +++ b/cocos/2d/ZipUtils.h @@ -264,7 +264,7 @@ namespace cocos2d * * @since v2.0.5 */ - unsigned char *getFileData(const std::string &fileName, long *size); + unsigned char *getFileData(const std::string &fileName, size_t *size); private: /** Internal data like zip file pointer / file list array and so on */ diff --git a/cocos/2d/ccUtils.cpp b/cocos/2d/ccUtils.cpp index d78324565ba0..e9d6eedf4aab 100644 --- a/cocos/2d/ccUtils.cpp +++ b/cocos/2d/ccUtils.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. namespace cocos2d { -unsigned long ccNextPOT(unsigned long x) +int ccNextPOT(int x) { x = x - 1; x = x | (x >> 1); diff --git a/cocos/2d/ccUtils.h b/cocos/2d/ccUtils.h index f882114b0ff1..3379db33bf82 100644 --- a/cocos/2d/ccUtils.h +++ b/cocos/2d/ccUtils.h @@ -43,7 +43,7 @@ ccNextPOT function is licensed under the same license that is used in Texture2D. @since v0.99.5 */ -unsigned long ccNextPOT( unsigned long value ); +int ccNextPOT(int value); } diff --git a/cocos/2d/platform/CCEGLViewProtocol.cpp b/cocos/2d/platform/CCEGLViewProtocol.cpp index c6623a234f09..73142f280a1c 100644 --- a/cocos/2d/platform/CCEGLViewProtocol.cpp +++ b/cocos/2d/platform/CCEGLViewProtocol.cpp @@ -198,9 +198,9 @@ const std::string& EGLViewProtocol::getViewName() const return _viewName; } -void EGLViewProtocol::handleTouchesBegin(int num, long ids[], float xs[], float ys[]) +void EGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[]) { - long id = 0; + int id = 0; float x = 0.0f; float y = 0.0f; int nUnusedIndex = 0; @@ -248,7 +248,7 @@ void EGLViewProtocol::handleTouchesBegin(int num, long ids[], float xs[], float dispatcher->dispatchEvent(&touchEvent); } -void EGLViewProtocol::handleTouchesMove(int num, long ids[], float xs[], float ys[]) +void EGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float ys[]) { long id = 0; float x = 0.0f; @@ -296,7 +296,7 @@ void EGLViewProtocol::handleTouchesMove(int num, long ids[], float xs[], float y dispatcher->dispatchEvent(&touchEvent); } -void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, long ids[], float xs[], float ys[]) +void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, int ids[], float xs[], float ys[]) { long id = 0; float x = 0.0f; @@ -356,12 +356,12 @@ void EGLViewProtocol::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode } } -void EGLViewProtocol::handleTouchesEnd(int num, long ids[], float xs[], float ys[]) +void EGLViewProtocol::handleTouchesEnd(int num, int ids[], float xs[], float ys[]) { handleTouchesOfEndOrCancel(EventTouch::EventCode::ENDED, num, ids, xs, ys); } -void EGLViewProtocol::handleTouchesCancel(int num, long ids[], float xs[], float ys[]) +void EGLViewProtocol::handleTouchesCancel(int num, int ids[], float xs[], float ys[]) { handleTouchesOfEndOrCancel(EventTouch::EventCode::CANCELLED, num, ids, xs, ys); } diff --git a/cocos/2d/platform/CCEGLViewProtocol.h b/cocos/2d/platform/CCEGLViewProtocol.h index 53f9400dcf3f..f5ed1255f621 100644 --- a/cocos/2d/platform/CCEGLViewProtocol.h +++ b/cocos/2d/platform/CCEGLViewProtocol.h @@ -135,10 +135,10 @@ class CC_DLL EGLViewProtocol const std::string& getViewName() const; /** Touch events are handled by default; if you want to customize your handlers, please override these functions: */ - virtual void handleTouchesBegin(int num, long ids[], float xs[], float ys[]); - virtual void handleTouchesMove(int num, long ids[], float xs[], float ys[]); - virtual void handleTouchesEnd(int num, long ids[], float xs[], float ys[]); - virtual void handleTouchesCancel(int num, long ids[], float xs[], float ys[]); + virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]); + virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]); + virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]); + virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]); /** * Get the opengl view port rectangle. @@ -157,7 +157,7 @@ class CC_DLL EGLViewProtocol protected: - void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, long ids[], float xs[], float ys[]); + void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, int ids[], float xs[], float ys[]); EGLTouchDelegate* _delegate; diff --git a/cocos/2d/platform/CCFileUtils.cpp b/cocos/2d/platform/CCFileUtils.cpp index 4b68c14aabf0..2ef1de67334c 100644 --- a/cocos/2d/platform/CCFileUtils.cpp +++ b/cocos/2d/platform/CCFileUtils.cpp @@ -518,7 +518,7 @@ unsigned char* FileUtils::getFileData(const char* filename, const char* mode, si return buffer; } -unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, long *size) +unsigned char* FileUtils::getFileDataFromZip(const char* zipFilePath, const char* filename, size_t *size) { unsigned char * buffer = NULL; unzFile pFile = NULL; diff --git a/cocos/2d/platform/CCFileUtils.h b/cocos/2d/platform/CCFileUtils.h index 060c0961f21e..6824acccd32c 100644 --- a/cocos/2d/platform/CCFileUtils.h +++ b/cocos/2d/platform/CCFileUtils.h @@ -98,7 +98,7 @@ class CC_DLL FileUtils * @return Upon success, a pointer to the data is returned, otherwise NULL. * @warning Recall: you are responsible for calling free() on any Non-NULL pointer returned. */ - virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, long *size); + virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, size_t *size); /** Returns the fullpath for a given filename. diff --git a/cocos/2d/platform/CCThread.cpp b/cocos/2d/platform/CCThread.cpp index 7d4a23a2160a..a7dfb546095c 100644 --- a/cocos/2d/platform/CCThread.cpp +++ b/cocos/2d/platform/CCThread.cpp @@ -31,7 +31,7 @@ NS_CC_BEGIN std::list>* ThreadHelper::_callbackList = new std::list>(); std::mutex* ThreadHelper::_mutex = new std::mutex; -long ThreadHelper::_callbackNumberPerFrame = 5; +int ThreadHelper::_callbackNumberPerFrame = 5; void* ThreadHelper::createAutoreleasePool() @@ -56,7 +56,7 @@ void ThreadHelper::doCallback() { _mutex->lock(); auto iter = _callbackList->begin(); - long i = 0; + int i = 0; while (iter != _callbackList->end()) { auto f = *iter; @@ -75,7 +75,7 @@ void ThreadHelper::doCallback() _mutex->unlock(); } -void ThreadHelper::setCallbackNumberPerFrame(long callbackNumberPerFrame) +void ThreadHelper::setCallbackNumberPerFrame(int callbackNumberPerFrame) { _callbackNumberPerFrame = callbackNumberPerFrame; } diff --git a/cocos/2d/platform/CCThread.h b/cocos/2d/platform/CCThread.h index b0998eeb5945..144330331275 100644 --- a/cocos/2d/platform/CCThread.h +++ b/cocos/2d/platform/CCThread.h @@ -72,7 +72,7 @@ class CC_DLL ThreadHelper * @lua NA @since v3.0 */ - static void setCallbackNumberPerFrame(long callbackNumberPerFrame); + static void setCallbackNumberPerFrame(int callbackNumberPerFrame); private: // This function will be call by Director to call some call back function on gl thread @@ -81,7 +81,7 @@ class CC_DLL ThreadHelper static std::list> *_callbackList; static std::mutex *_mutex; // How many callback functions invoked per frame - static long _callbackNumberPerFrame; + static int _callbackNumberPerFrame; }; // end of platform group diff --git a/cocos/2d/platform/apple/CCThread.mm b/cocos/2d/platform/apple/CCThread.mm index 4e138fb889bc..f8c84bb77f08 100644 --- a/cocos/2d/platform/apple/CCThread.mm +++ b/cocos/2d/platform/apple/CCThread.mm @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal std::list>* ThreadHelper::_callbackList = new std::list>(); std::mutex* ThreadHelper::_mutex = new std::mutex; -long ThreadHelper::_callbackNumberPerFrame = 5; +int ThreadHelper::_callbackNumberPerFrame = 5; void* ThreadHelper::createAutoreleasePool() { @@ -53,7 +53,7 @@ of this software and associated documentation files (the "Software"), to deal { _mutex->lock(); auto iter = _callbackList->begin(); - long i = 0; + int i = 0; while (iter != _callbackList->end()) { auto f = *iter; @@ -72,7 +72,7 @@ of this software and associated documentation files (the "Software"), to deal _mutex->unlock(); } -void ThreadHelper::setCallbackNumberPerFrame(long callbackNumberPerFrame) +void ThreadHelper::setCallbackNumberPerFrame(int callbackNumberPerFrame) { _callbackNumberPerFrame = callbackNumberPerFrame; } diff --git a/cocos/2d/platform/ios/EAGLView.mm b/cocos/2d/platform/ios/EAGLView.mm index bb00a70c542b..f792282367e8 100644 --- a/cocos/2d/platform/ios/EAGLView.mm +++ b/cocos/2d/platform/ios/EAGLView.mm @@ -413,7 +413,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ++i; } - cocos2d::EGLView::getInstance()->handleTouchesBegin(i, (long*)ids, xs, ys); + cocos2d::EGLView::getInstance()->handleTouchesBegin(i, (int*)ids, xs, ys); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event @@ -433,7 +433,7 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ++i; } - cocos2d::EGLView::getInstance()->handleTouchesMove(i, (long*)ids, xs, ys); + cocos2d::EGLView::getInstance()->handleTouchesMove(i, (int*)ids, xs, ys); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event @@ -454,7 +454,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ++i; } - cocos2d::EGLView::getInstance()->handleTouchesEnd(i, (long*)ids, xs, ys); + cocos2d::EGLView::getInstance()->handleTouchesEnd(i, (int*)ids, xs, ys); } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event @@ -475,7 +475,7 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event ys[i] = [touch locationInView: [touch view]].y * __view.contentScaleFactor;; ++i; } - cocos2d::EGLView::getInstance()->handleTouchesCancel(i, (long*)ids, xs, ys); + cocos2d::EGLView::getInstance()->handleTouchesCancel(i, (int*)ids, xs, ys); } #pragma mark - UIView - Responder diff --git a/cocos/2d/platform/mac/CCEGLView.mm b/cocos/2d/platform/mac/CCEGLView.mm index 5d4f23b28172..580436def93e 100644 --- a/cocos/2d/platform/mac/CCEGLView.mm +++ b/cocos/2d/platform/mac/CCEGLView.mm @@ -206,7 +206,7 @@ of this software and associated documentation files (the "Software"), to deal s_captured = true; if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY))) { - long id = 0; + int id = 0; eglView->handleTouchesBegin(1, &id, &s_mouseX, &s_mouseY); } } @@ -215,7 +215,7 @@ of this software and associated documentation files (the "Software"), to deal s_captured = false; if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,s_mouseY))) { - long id = 0; + int id = 0; eglView->handleTouchesEnd(1, &id, &s_mouseX, &s_mouseY); } } @@ -253,7 +253,7 @@ of this software and associated documentation files (the "Software"), to deal { if (eglView->getViewPortRect().equals(Rect::ZERO) || eglView->getViewPortRect().containsPoint(Point(s_mouseX,eglView->getFrameSize().height - s_mouseY))) { - long id = 0; + int id = 0; eglView->handleTouchesMove(1, &id, &s_mouseX, &s_mouseY); } } diff --git a/cocos/2d/platform/mac/EAGLView.mm b/cocos/2d/platform/mac/EAGLView.mm index 1894440cedfd..8276f8e02c9c 100644 --- a/cocos/2d/platform/mac/EAGLView.mm +++ b/cocos/2d/platform/mac/EAGLView.mm @@ -335,7 +335,7 @@ - (void)mouseDown:(NSEvent *)theEvent xs[0] = x / frameZoomFactor_; ys[0] = y / frameZoomFactor_; - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, (long*)ids, xs, ys); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, (int*)ids, xs, ys); } - (void)mouseMoved:(NSEvent *)theEvent @@ -359,7 +359,7 @@ - (void)mouseDragged:(NSEvent *)theEvent xs[0] = x / frameZoomFactor_; ys[0] = y / frameZoomFactor_; - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(1, (long*)ids, xs, ys); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(1, (int*)ids, xs, ys); } - (void)mouseUp:(NSEvent *)theEvent @@ -378,7 +378,7 @@ - (void)mouseUp:(NSEvent *)theEvent xs[0] = x / frameZoomFactor_; ys[0] = y / frameZoomFactor_; - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, (long*)ids, xs, ys); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, (int*)ids, xs, ys); } - (void)rightMouseDown:(NSEvent *)theEvent { diff --git a/cocos/base/CCString.cpp b/cocos/base/CCString.cpp index c0848f28adc8..f9e445a28b6c 100644 --- a/cocos/base/CCString.cpp +++ b/cocos/base/CCString.cpp @@ -221,7 +221,7 @@ String* String::create(const std::string& str) return ret; } -String* String::createWithData(const unsigned char* data, unsigned long nLen) +String* String::createWithData(const unsigned char* data, size_t nLen) { String* ret = NULL; if (data != NULL) diff --git a/cocos/base/CCString.h b/cocos/base/CCString.h index a6f237a4762b..014596977183 100644 --- a/cocos/base/CCString.h +++ b/cocos/base/CCString.h @@ -164,7 +164,7 @@ class CC_DLL String : public Object, public Clonable * it means that you needn't do a release operation unless you retain it. * @js NA */ - static String* createWithData(const unsigned char* pData, unsigned long nLen); + static String* createWithData(const unsigned char* pData, size_t nLen); /** create a string with a file, * @return A String pointer which is an autorelease object pointer, diff --git a/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp b/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp index df8721de0d41..bf3642ba572a 100644 --- a/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp +++ b/cocos/editor-support/cocosbuilder/CCBAnimationManager.cpp @@ -622,9 +622,9 @@ Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* chann Array *actions = Array::create(); Array *keyframes = channel->getKeyframes(); - long numKeyframes = keyframes->count(); + auto numKeyframes = keyframes->count(); - for (long i = 0; i < numKeyframes; ++i) + for (size_t i = 0; i < numKeyframes; ++i) { CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->getObjectAtIndex(i); diff --git a/cocos/physics/CCPhysicsContact.h b/cocos/physics/CCPhysicsContact.h index 24eb0f4c69d2..5816a7d2a0c5 100644 --- a/cocos/physics/CCPhysicsContact.h +++ b/cocos/physics/CCPhysicsContact.h @@ -44,7 +44,7 @@ typedef Point Vect; typedef struct PhysicsContactData { - static const long POINT_MAX = 4; + static const int POINT_MAX = 4; Point points[POINT_MAX]; int count; Point normal; diff --git a/cocos/physics/CCPhysicsWorld.h b/cocos/physics/CCPhysicsWorld.h index 389cde4f2ca7..3eb04d617cdf 100644 --- a/cocos/physics/CCPhysicsWorld.h +++ b/cocos/physics/CCPhysicsWorld.h @@ -82,11 +82,11 @@ typedef PhysicsRectQueryCallbackFunc PhysicsPointQueryCallbackFunc; class PhysicsWorld { public: - static const long DEBUGDRAW_NONE = 0x00; - static const long DEBUGDRAW_SHAPE = 0x01; - static const long DEBUGDRAW_JOINT = 0x02; - static const long DEBUGDRAW_CONTACT = 0x04; - static const long DEBUGDRAW_ALL = DEBUGDRAW_SHAPE | DEBUGDRAW_JOINT | DEBUGDRAW_CONTACT; + static const int DEBUGDRAW_NONE = 0x00; + static const int DEBUGDRAW_SHAPE = 0x01; + static const int DEBUGDRAW_JOINT = 0x02; + static const int DEBUGDRAW_CONTACT = 0x04; + static const int DEBUGDRAW_ALL = DEBUGDRAW_SHAPE | DEBUGDRAW_JOINT | DEBUGDRAW_CONTACT; public: /** Adds a joint to the physics world.*/ diff --git a/external/unzip/unzip.cpp b/external/unzip/unzip.cpp index 157965d79496..0b2523868ccf 100644 --- a/external/unzip/unzip.cpp +++ b/external/unzip/unzip.cpp @@ -1715,7 +1715,7 @@ ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */ -int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) +int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, int len) { int err=UNZ_OK; uInt iRead = 0; diff --git a/external/unzip/unzip.h b/external/unzip/unzip.h index 54e73a55ea62..de744932008c 100644 --- a/external/unzip/unzip.h +++ b/external/unzip/unzip.h @@ -398,9 +398,7 @@ int CC_DLL unzCloseCurrentFile OF((unzFile file)); Return UNZ_CRCERROR if all the file was read but the CRC is not good */ -int CC_DLL unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); +int CC_DLL unzReadCurrentFile OF((unzFile file,voidp buf, int len)); /* Read bytes from the current file (opened by unzOpenCurrentFile) buf contain buffer where data must be copied From a09a78a235237c7af1458cd072e08b0a1f92dc4d Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 4 Dec 2013 17:44:18 +0800 Subject: [PATCH 5/5] fix bugs on android --- .../2d/platform/android/CCFileUtilsAndroid.cpp | 6 +++--- cocos/2d/platform/android/CCFileUtilsAndroid.h | 6 +++--- cocos/2d/platform/android/nativeactivity.cpp | 17 +++++++---------- .../lua/bindings/Cocos2dxLuaLoader.cpp | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cocos/2d/platform/android/CCFileUtilsAndroid.cpp b/cocos/2d/platform/android/CCFileUtilsAndroid.cpp index af910cfe7119..f5c853d32bca 100644 --- a/cocos/2d/platform/android/CCFileUtilsAndroid.cpp +++ b/cocos/2d/platform/android/CCFileUtilsAndroid.cpp @@ -130,17 +130,17 @@ bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const } -unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, long * size) +unsigned char* FileUtilsAndroid::getFileData(const char* filename, const char* mode, size_t * size) { return doGetFileData(filename, mode, size, false); } -unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, long * pSize) +unsigned char* FileUtilsAndroid::getFileDataForAsync(const char* filename, const char* pszMode, size_t * pSize) { return doGetFileData(filename, pszMode, pSize, true); } -unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* mode, long * size, bool forAsync) +unsigned char* FileUtilsAndroid::doGetFileData(const char* filename, const char* mode, size_t * size, bool forAsync) { unsigned char * data = 0; diff --git a/cocos/2d/platform/android/CCFileUtilsAndroid.h b/cocos/2d/platform/android/CCFileUtilsAndroid.h index 3bee6d2e3925..d8a3bdde0317 100644 --- a/cocos/2d/platform/android/CCFileUtilsAndroid.h +++ b/cocos/2d/platform/android/CCFileUtilsAndroid.h @@ -55,7 +55,7 @@ class CC_DLL FileUtilsAndroid : public FileUtils /* override funtions */ bool init(); - virtual unsigned char* getFileData(const char* filename, const char* mode, long * size); + virtual unsigned char* getFileData(const char* filename, const char* mode, size_t * size); virtual std::string getWritablePath() const; virtual bool isFileExist(const std::string& strFilePath) const; @@ -64,10 +64,10 @@ class CC_DLL FileUtilsAndroid : public FileUtils /** This function is android specific. It is used for TextureCache::addImageAsync(). Don't use it in your codes. */ - unsigned char* getFileDataForAsync(const char* filename, const char* mode, long * size); + unsigned char* getFileDataForAsync(const char* filename, const char* mode, size_t * size); private: - unsigned char* doGetFileData(const char* filename, const char* mode, long * size, bool forAsync); + unsigned char* doGetFileData(const char* filename, const char* mode, size_t * size, bool forAsync); static AAssetManager* assetmanager; }; diff --git a/cocos/2d/platform/android/nativeactivity.cpp b/cocos/2d/platform/android/nativeactivity.cpp index e7eeb1606a7c..287c97f0afd6 100644 --- a/cocos/2d/platform/android/nativeactivity.cpp +++ b/cocos/2d/platform/android/nativeactivity.cpp @@ -296,7 +296,7 @@ static void engine_term_display(struct engine* engine) { /* * Get X, Y positions and ID's for all pointers */ -static void getTouchPos(AInputEvent *event, long ids[], float xs[], float ys[]) { +static void getTouchPos(AInputEvent *event, int ids[], float xs[], float ys[]) { int pointerCount = AMotionEvent_getPointerCount(event); for(int i = 0; i < pointerCount; ++i) { ids[i] = AMotionEvent_getPointerId(event, i); @@ -325,7 +325,7 @@ static int32_t handle_touch_input(AInputEvent *event) { LOG_EVENTS_DEBUG("Event: Action DOWN x=%f y=%f pointerID=%d\n", xP, yP, pointerId); - long pId = pointerId; + int pId = pointerId; float x = xP; float y = yP; @@ -344,11 +344,10 @@ static int32_t handle_touch_input(AInputEvent *event) { LOG_EVENTS_DEBUG("Event: Action POINTER DOWN x=%f y=%f pointerID=%d\n", xP, yP, pointerId); - long pId = pointerId; float x = xP; float y = yP; - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &pId, &x, &y); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &pointerId, &x, &y); return 1; } break; @@ -357,7 +356,7 @@ static int32_t handle_touch_input(AInputEvent *event) { { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_MOVE"); int pointerCount = AMotionEvent_getPointerCount(event); - long ids[pointerCount]; + int ids[pointerCount]; float xs[pointerCount], ys[pointerCount]; getTouchPos(event, ids, xs, ys); cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys); @@ -373,11 +372,10 @@ static int32_t handle_touch_input(AInputEvent *event) { float yP = AMotionEvent_getY(event,0); LOG_EVENTS_DEBUG("Event: Action UP x=%f y=%f pointerID=%d\n", xP, yP, pointerId); - long pId = pointerId; float x = xP; float y = yP; - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &pId, &x, &y); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &pointerId, &x, &y); return 1; } break; @@ -391,11 +389,10 @@ static int32_t handle_touch_input(AInputEvent *event) { float yP = AMotionEvent_getY(event,pointerIndex); LOG_EVENTS_DEBUG("Event: Action POINTER UP x=%f y=%f pointerID=%d\n", xP, yP, pointerIndex); - long pId = pointerId; float x = xP; float y = yP; - cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &pId, &x, &y); + cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &pointerId, &x, &y); return 1; } break; @@ -404,7 +401,7 @@ static int32_t handle_touch_input(AInputEvent *event) { { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_CANCEL"); int pointerCount = AMotionEvent_getPointerCount(event); - long ids[pointerCount]; + int ids[pointerCount]; float xs[pointerCount], ys[pointerCount]; getTouchPos(event, ids, xs, ys); cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys); diff --git a/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp b/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp index fa1f7cb01c91..5819217bc2a1 100644 --- a/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp +++ b/cocos/scripting/lua/bindings/Cocos2dxLuaLoader.cpp @@ -46,7 +46,7 @@ extern "C" } filename.append(".lua"); - long codeBufferSize = 0; + size_t codeBufferSize = 0; unsigned char* codeBuffer = FileUtils::getInstance()->getFileData(filename.c_str(), "rb", &codeBufferSize); if (codeBuffer)