Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change long to size_t or int #4429

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cocos/2d/CCActionCatmullRom.cpp
Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCActionCatmullRom.h
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions cocos/2d/CCActionInterval.cpp
Expand Up @@ -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<FiniteTimeAction*>(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<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(i)));
}
Expand Down Expand Up @@ -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<FiniteTimeAction*>(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<FiniteTimeAction*>(arrayOfActions->getObjectAtIndex(i)));
}
Expand Down Expand Up @@ -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++ ) {
Expand Down
16 changes: 8 additions & 8 deletions cocos/2d/CCActionManager.cpp
Expand Up @@ -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];

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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];

Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCActionManager.h
Expand Up @@ -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.
*/
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions cocos/2d/CCAtlasNode.cpp
Expand Up @@ -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))
Expand All @@ -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;
Expand Down Expand Up @@ -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
20 changes: 10 additions & 10 deletions cocos/2d/CCAtlasNode.h
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCDirector.cpp
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCDirector.h
Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions cocos/2d/CCDrawNode.cpp
Expand Up @@ -142,7 +142,7 @@ DrawNode* DrawNode::create()
return pRet;
}

void DrawNode::ensureCapacity(long count)
void DrawNode::ensureCapacity(int count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is capacity size_t is valid.
But int is OK too in this context I guess.

{
CCASSERT(count>=0, "capacity must be >= 0");

Expand Down Expand Up @@ -338,15 +338,15 @@ 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");

struct ExtrudeVerts {Vertex2F offset, n;};
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]);
Expand All @@ -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));
Expand All @@ -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]);

Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCDrawNode.h
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCEventDispatcher.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -527,7 +527,7 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, s
if (!shouldStopPropagation)
{
// priority > 0
for (; i < static_cast<long>(fixedPriorityListeners->size()); ++i)
for (; i < fixedPriorityListeners->size(); ++i)
{
auto l = fixedPriorityListeners->at(i);

Expand Down Expand Up @@ -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)
Expand Down