Merge branch 'develop' into newRenderer

This commit is contained in:
Ricardo Quesada 2013-12-13 11:54:48 -08:00
commit 524751e56f
51 changed files with 476 additions and 342 deletions

View File

@ -87,7 +87,7 @@ void ActionManager::actionAllocWithHashElement(tHashElement *element)
}
void ActionManager::removeActionAtIndex(int index, tHashElement *element)
void ActionManager::removeActionAtIndex(ssize_t index, tHashElement *element)
{
Action *action = (Action*)element->actions->arr[index];
@ -324,7 +324,7 @@ Action* ActionManager::getActionByTag(int tag, const Node *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
int ActionManager::getNumberOfRunningActionsInTarget(const Node *target) const
ssize_t ActionManager::getNumberOfRunningActionsInTarget(const Node *target) const
{
tHashElement *element = NULL;
HASH_FIND_PTR(_targets, &target, element);

View File

@ -100,10 +100,10 @@ public:
* - 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.
*/
int getNumberOfRunningActionsInTarget(const Node *target) const;
ssize_t getNumberOfRunningActionsInTarget(const Node *target) const;
/** @deprecated use getNumberOfRunningActionsInTarget() instead */
CC_DEPRECATED_ATTRIBUTE inline int numberOfRunningActionsInTarget(Node *target) const { return getNumberOfRunningActionsInTarget(target); }
CC_DEPRECATED_ATTRIBUTE inline ssize_t numberOfRunningActionsInTarget(Node *target) const { return getNumberOfRunningActionsInTarget(target); }
/** Pauses the target: all running actions and newly added actions will be paused.
*/
@ -124,7 +124,7 @@ public:
protected:
// declared in ActionManager.m
void removeActionAtIndex(int index, struct _hashElement *pElement);
void removeActionAtIndex(ssize_t index, struct _hashElement *pElement);
void deleteHashElement(struct _hashElement *pElement);
void actionAllocWithHashElement(struct _hashElement *pElement);
void update(float dt);

View File

@ -612,7 +612,7 @@ void Director::replaceScene(Scene *scene)
CCASSERT(_runningScene, "Use runWithScene: instead to start the director");
CCASSERT(scene != nullptr, "the scene should not be null");
int index = _scenesStack.size();
ssize_t index = _scenesStack.size();
_sendCleanupToScene = true;
_scenesStack.replace(index - 1, scene);
@ -635,7 +635,7 @@ void Director::popScene(void)
CCASSERT(_runningScene != nullptr, "running scene should not null");
_scenesStack.popBack();
int c = _scenesStack.size();
ssize_t c = _scenesStack.size();
if (c == 0)
{
@ -656,7 +656,7 @@ void Director::popToRootScene(void)
void Director::popToSceneStackLevel(int level)
{
CCASSERT(_runningScene != nullptr, "A running Scene is needed");
int c = _scenesStack.size();
ssize_t c = _scenesStack.size();
// level 0? -> end
if (level == 0)

View File

@ -136,12 +136,12 @@ private:
inline std::vector<EventListener*>* getFixedPriorityListeners() const { return _fixedListeners; };
inline std::vector<EventListener*>* getSceneGraphPriorityListeners() const { return _sceneGraphListeners; };
inline int getGt0Index() const { return _gt0Index; };
inline void setGt0Index(int index) { _gt0Index = index; };
inline ssize_t getGt0Index() const { return _gt0Index; };
inline void setGt0Index(ssize_t index) { _gt0Index = index; };
private:
std::vector<EventListener*>* _fixedListeners;
std::vector<EventListener*>* _sceneGraphListeners;
int _gt0Index;
ssize_t _gt0Index;
};
/** Adds event listener with item */

View File

@ -1083,7 +1083,7 @@ void LayerMultiplex::switchToAndReleaseMe(int n)
std::string LayerMultiplex::getDescription() const
{
return StringUtils::format("<LayerMultiplex | Tag = %d, Layers = %d", _tag, _children.size());
return StringUtils::format("<LayerMultiplex | Tag = %d, Layers = %zd", _tag, _children.size());
}
NS_CC_END

View File

@ -396,7 +396,7 @@ void Node::setPositionY(float y)
setPosition(Point(_position.x, y));
}
int Node::getChildrenCount() const
ssize_t Node::getChildrenCount() const
{
return _children.size();
}
@ -684,7 +684,7 @@ void Node::removeChild(Node* child, bool cleanup /* = true */)
return;
}
auto index = _children.getIndex(child);
ssize_t index = _children.getIndex(child);
if( index != CC_INVALID_INDEX )
this->detachChild( child, index, cleanup );
}
@ -742,7 +742,7 @@ void Node::removeAllChildrenWithCleanup(bool cleanup)
}
void Node::detachChild(Node *child, int childIndex, bool doCleanup)
void Node::detachChild(Node *child, ssize_t childIndex, bool doCleanup)
{
// IMPORTANT:
// -1st do onExit
@ -1056,7 +1056,7 @@ Action * Node::getActionByTag(int tag)
return _actionManager->getActionByTag(tag, this);
}
int Node::getNumberOfRunningActions() const
ssize_t Node::getNumberOfRunningActions() const
{
return _actionManager->getNumberOfRunningActionsInTarget(this);
}

View File

@ -621,7 +621,7 @@ public:
*
* @return The amount of children.
*/
int getChildrenCount() const;
ssize_t getChildrenCount() const;
/**
* Sets the parent node
@ -1042,10 +1042,10 @@ public:
*
* @return The number of actions that are running plus the ones that are schedule to run
*/
int getNumberOfRunningActions() const;
ssize_t getNumberOfRunningActions() const;
/** @deprecated Use getNumberOfRunningActions() instead */
CC_DEPRECATED_ATTRIBUTE int numberOfRunningActions() const { return getNumberOfRunningActions(); };
CC_DEPRECATED_ATTRIBUTE ssize_t numberOfRunningActions() const { return getNumberOfRunningActions(); };
/// @} end of Actions
@ -1408,7 +1408,7 @@ protected:
void insertChild(Node* child, int z);
/// Removes a child, call child->onExit(), do cleanup, remove it from children array.
void detachChild(Node *child, int index, bool doCleanup);
void detachChild(Node *child, ssize_t index, bool doCleanup);
/// Convert cocos2d coordinates to UI windows coordinate.
Point convertToWindowSpace(const Point& nodePoint) const;

View File

@ -143,7 +143,7 @@ int NotificationCenter::removeAllObservers(Object *target)
}
_observers->removeObjectsInArray(toRemove);
return toRemove->count();
return static_cast<int>(toRemove->count());
}
void NotificationCenter::registerScriptObserver( Object *target, int handler,const char* name)

View File

@ -429,7 +429,7 @@ void ParticleBatchNode::draw(void)
void ParticleBatchNode::increaseAtlasCapacityTo(int quantity)
void ParticleBatchNode::increaseAtlasCapacityTo(ssize_t quantity)
{
CCLOG("cocos2d: ParticleBatchNode: resizing TextureAtlas capacity from [%lu] to [%lu].",
(long)_textureAtlas->getCapacity(),

View File

@ -129,7 +129,7 @@ public:
private:
void updateAllAtlasIndexes();
void increaseAtlasCapacityTo(int quantity);
void increaseAtlasCapacityTo(ssize_t quantity);
int searchNewPositionInChildrenForZ(int z);
void getCurrentIndex(int* oldIndex, int* newIndex, Node* child, int z);
int addChildHelper(ParticleSystem* child, int z, int aTag);

View File

@ -677,7 +677,7 @@ unsigned int Scheduler::scheduleScriptFunc(unsigned int handler, float interval,
void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)
{
for (int i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
for (ssize_t i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
{
SchedulerScriptHandlerEntry* entry = _scriptHandlerEntries.at(i);
if (entry->getEntryId() == (int)scheduleScriptEntryID)

View File

@ -1149,7 +1149,7 @@ void Sprite::setSpriteFrame(SpriteFrame *spriteFrame)
setTextureRect(spriteFrame->getRect(), _rectRotated, spriteFrame->getOriginalSize());
}
void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex)
void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, ssize_t frameIndex)
{
CCASSERT(animationName.size()>0, "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL");

View File

@ -258,7 +258,7 @@ public:
* Changes the display frame with animation name and index.
* The animation name will be get from the AnimationCache
*/
virtual void setDisplayFrameWithAnimationName(const std::string& animationName, int frameIndex);
virtual void setDisplayFrameWithAnimationName(const std::string& animationName, ssize_t frameIndex);
/// @}
@ -292,13 +292,13 @@ public:
/**
* Returns the index used on the TextureAtlas.
*/
inline int getAtlasIndex(void) const { return _atlasIndex; }
inline ssize_t getAtlasIndex(void) const { return _atlasIndex; }
/**
* Sets the index used on the TextureAtlas.
* @warning Don't modify this value unless you know what you are doing
*/
inline void setAtlasIndex(int atlasIndex) { _atlasIndex = atlasIndex; }
inline void setAtlasIndex(ssize_t atlasIndex) { _atlasIndex = atlasIndex; }
/**
* Returns the rect of the Sprite in points
@ -540,7 +540,7 @@ protected:
// Data used when the sprite is rendered using a SpriteSheet
//
TextureAtlas* _textureAtlas; /// SpriteBatchNode texture atlas (weak reference)
int _atlasIndex; /// Absolute (real) Index on the SpriteSheet
ssize_t _atlasIndex; /// Absolute (real) Index on the SpriteSheet
SpriteBatchNode* _batchNode; /// Used batch node (weak reference)
bool _dirty; /// Whether the sprite needs to be updated

View File

@ -51,7 +51,7 @@ NS_CC_BEGIN
* creation with Texture2D
*/
SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity/* = DEFAULT_CAPACITY*/)
SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, ssize_t capacity/* = DEFAULT_CAPACITY*/)
{
SpriteBatchNode *batchNode = new SpriteBatchNode();
batchNode->initWithTexture(tex, capacity);
@ -64,7 +64,7 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity
* creation with File Image
*/
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, int capacity/* = DEFAULT_CAPACITY*/)
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/)
{
SpriteBatchNode *batchNode = new SpriteBatchNode();
batchNode->initWithFile(fileImage, capacity);
@ -76,7 +76,7 @@ SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, int capacity/* =
/*
* init with Texture2D
*/
bool SpriteBatchNode::initWithTexture(Texture2D *tex, int capacity)
bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity)
{
CCASSERT(capacity>=0, "Capacity must be >= 0");
@ -110,7 +110,7 @@ bool SpriteBatchNode::init()
/*
* init with FileImage
*/
bool SpriteBatchNode::initWithFile(const char* fileImage, int capacity)
bool SpriteBatchNode::initWithFile(const char* fileImage, ssize_t capacity)
{
Texture2D *texture2D = Director::getInstance()->getTextureCache()->addImage(fileImage);
return initWithTexture(texture2D, capacity);
@ -215,7 +215,7 @@ void SpriteBatchNode::removeChild(Node *child, bool cleanup)
Node::removeChild(sprite, cleanup);
}
void SpriteBatchNode::removeChildAtIndex(int index, bool doCleanup)
void SpriteBatchNode::removeChildAtIndex(ssize_t index, bool doCleanup)
{
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
removeChild(_children.at(index), doCleanup);
@ -274,7 +274,7 @@ void SpriteBatchNode::sortAllChildren()
child->sortAllChildren();
});
int index=0;
ssize_t index=0;
//fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
// and at the same time reorder descendants and the quads to the right index
@ -288,12 +288,12 @@ void SpriteBatchNode::sortAllChildren()
}
}
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, ssize_t* curIndex)
{
auto& array = sprite->getChildren();
auto count = array.size();
int oldIndex = 0;
ssize_t oldIndex = 0;
if( count == 0 )
{
@ -354,7 +354,7 @@ void SpriteBatchNode::updateAtlasIndex(Sprite* sprite, int* curIndex)
}
}
void SpriteBatchNode::swap(int oldIndex, int newIndex)
void SpriteBatchNode::swap(ssize_t oldIndex, ssize_t newIndex)
{
CCASSERT(oldIndex>=0 && oldIndex < (int)_descendants.size() && newIndex >=0 && newIndex < (int)_descendants.size(), "Invalid index");
@ -406,9 +406,9 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
// if we're going beyond the current TextureAtlas's capacity,
// all the previously initialized sprites will need to redo their texture coords
// this is likely computationally expensive
int quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
ssize_t quantity = (_textureAtlas->getCapacity() + 1) * 4 / 3;
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%d] to [%d].",
CCLOG("cocos2d: SpriteBatchNode: resizing TextureAtlas capacity from [%zd] to [%zd].",
_textureAtlas->getCapacity(),
quantity);
@ -420,7 +420,7 @@ void SpriteBatchNode::increaseAtlasCapacity(void)
}
}
int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
ssize_t SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, ssize_t index)
{
CCASSERT(index>=0 && index < _children.size(), "Invalid index");
@ -452,7 +452,7 @@ int SpriteBatchNode::rebuildIndexInOrder(Sprite *parent, int index)
return index;
}
int SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
ssize_t SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
{
auto& children = sprite->getChildren();
@ -466,7 +466,7 @@ int SpriteBatchNode::highestAtlasIndexInChild(Sprite *sprite)
}
}
int SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
ssize_t SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
{
auto& children = sprite->getChildren();
@ -480,7 +480,7 @@ int SpriteBatchNode::lowestAtlasIndexInChild(Sprite *sprite)
}
}
int SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
ssize_t SpriteBatchNode::atlasIndexForChild(Sprite *sprite, int nZ)
{
auto& siblings = sprite->getParent()->getChildren();
auto childIndex = siblings.getIndex(sprite);
@ -627,7 +627,7 @@ void SpriteBatchNode::setTexture(Texture2D *texture)
// SpriteSheet Extension
//implementation SpriteSheet (TMXTiledMapExtension)
void SpriteBatchNode::insertQuadFromSprite(Sprite *sprite, int index)
void SpriteBatchNode::insertQuadFromSprite(Sprite *sprite, ssize_t index)
{
CCASSERT( sprite != NULL, "Argument must be non-NULL");
CCASSERT( dynamic_cast<Sprite*>(sprite), "CCSpriteBatchNode only supports Sprites as children");
@ -652,7 +652,7 @@ void SpriteBatchNode::insertQuadFromSprite(Sprite *sprite, int index)
sprite->updateTransform();
}
void SpriteBatchNode::updateQuadFromSprite(Sprite *sprite, int index)
void SpriteBatchNode::updateQuadFromSprite(Sprite *sprite, ssize_t index)
{
CCASSERT(sprite != NULL, "Argument must be non-nil");
CCASSERT(dynamic_cast<Sprite*>(sprite) != NULL, "CCSpriteBatchNode only supports Sprites as children");

View File

@ -68,13 +68,13 @@ public:
/** creates a SpriteBatchNode with a texture2d and capacity of children.
The capacity will be increased in 33% in runtime if it run out of space.
*/
static SpriteBatchNode* createWithTexture(Texture2D* tex, int capacity = DEFAULT_CAPACITY);
static SpriteBatchNode* createWithTexture(Texture2D* tex, ssize_t capacity = DEFAULT_CAPACITY);
/** creates a SpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and 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.
*/
static SpriteBatchNode* create(const char* fileImage, int capacity = DEFAULT_CAPACITY);
static SpriteBatchNode* create(const char* fileImage, ssize_t capacity = DEFAULT_CAPACITY);
/**
* @js ctor
*/
@ -88,14 +88,14 @@ public:
/** 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, int capacity);
bool initWithTexture(Texture2D *tex, ssize_t 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, int capacity);
bool initWithFile(const char* fileImage, ssize_t capacity);
bool init();
/** returns the TextureAtlas object */
@ -121,15 +121,15 @@ public:
/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
@warning Removing a child from a SpriteBatchNode is very slow
*/
void removeChildAtIndex(int index, bool doCleanup);
void removeChildAtIndex(ssize_t index, bool doCleanup);
void appendChild(Sprite* sprite);
void removeSpriteFromAtlas(Sprite *sprite);
int rebuildIndexInOrder(Sprite *parent, int index);
int highestAtlasIndexInChild(Sprite *sprite);
int lowestAtlasIndexInChild(Sprite *sprite);
int atlasIndexForChild(Sprite *sprite, int z);
ssize_t rebuildIndexInOrder(Sprite *parent, ssize_t index);
ssize_t highestAtlasIndexInChild(Sprite *sprite);
ssize_t lowestAtlasIndexInChild(Sprite *sprite);
ssize_t atlasIndexForChild(Sprite *sprite, int z);
/* Sprites use this to start sortChildren, don't call this manually */
void reorderBatch(bool reorder);
@ -137,7 +137,7 @@ public:
// Overrides
//
// TextureProtocol
virtual Texture2D* getTexture(void) const override;
virtual Texture2D* getTexture() const override;
virtual void setTexture(Texture2D *texture) override;
/**
*@code
@ -151,9 +151,9 @@ public:
* @js NA
* @lua NA
*/
virtual const BlendFunc& getBlendFunc(void) const override;
virtual const BlendFunc& getBlendFunc() const override;
virtual void visit(void) override;
virtual void visit() override;
virtual void addChild(Node* child) override{ Node::addChild(child);}
virtual void addChild(Node * child, int zOrder) override { Node::addChild(child, zOrder);}
virtual void addChild(Node * child, int zOrder, int tag) override;
@ -170,19 +170,19 @@ protected:
This method should be called only when you are dealing with very big AtlasSrite and when most of the Sprite won't be updated.
For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont)
*/
void insertQuadFromSprite(Sprite *sprite, int index);
void insertQuadFromSprite(Sprite *sprite, ssize_t index);
/** Updates a quad at a certain index into the texture atlas. The Sprite won't be added into the children array.
This method should be called only when you are dealing with very big AtlasSrite and when most of the Sprite won't be updated.
For example: a tile map (TMXMap) or a label with lots of characters (LabelBMFont)
*/
void updateQuadFromSprite(Sprite *sprite, int index);
void updateQuadFromSprite(Sprite *sprite, ssize_t index);
/* This is the opposite of "addQuadFromSprite.
It add the sprite to the children and descendants array, but it doesn't update add it to the texture atlas
*/
SpriteBatchNode * addSpriteWithoutQuad(Sprite *child, int z, int aTag);
void updateAtlasIndex(Sprite* sprite, int* curIndex);
void swap(int oldIndex, int newIndex);
void updateAtlasIndex(Sprite* sprite, ssize_t* curIndex);
void swap(ssize_t oldIndex, ssize_t newIndex);
void updateBlendFunc();
TextureAtlas *_textureAtlas;

View File

@ -340,8 +340,8 @@ Sprite * TMXLayer::getTileAt(const Point& pos)
tile->setAnchorPoint(Point::ZERO);
tile->setOpacity(_opacity);
unsigned int indexForZ = atlasIndexForExistantZ(z);
this->addSpriteWithoutQuad(tile, indexForZ, z);
ssize_t indexForZ = atlasIndexForExistantZ(z);
this->addSpriteWithoutQuad(tile, static_cast<int>(indexForZ), z);
}
}
@ -379,7 +379,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
setupTileSprite(tile, pos, gid);
// get atlas index
unsigned int indexForZ = atlasIndexForNewZ(static_cast<int>(z));
ssize_t indexForZ = atlasIndexForNewZ(static_cast<int>(z));
// Optimization: add the quad without adding a child
this->insertQuadFromSprite(tile, indexForZ);
@ -393,7 +393,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
Sprite* sp = static_cast<Sprite*>(child);
if (child)
{
int ai = sp->getAtlasIndex();
ssize_t ai = sp->getAtlasIndex();
if ( ai >= indexForZ )
{
sp->setAtlasIndex(ai+1);
@ -416,7 +416,7 @@ Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
setupTileSprite(tile ,pos ,gid);
// get atlas index
unsigned int indexForZ = atlasIndexForExistantZ(z);
ssize_t indexForZ = atlasIndexForExistantZ(z);
tile->setAtlasIndex(indexForZ);
tile->setDirty(true);
tile->updateTransform();
@ -441,7 +441,7 @@ Sprite * TMXLayer::appendTileForGID(unsigned int gid, const Point& pos)
// optimization:
// The difference between appendTileForGID and insertTileforGID is that append is faster, since
// it appends the tile at the end of the texture atlas
unsigned int indexForZ = _atlasIndexArray->num;
ssize_t indexForZ = _atlasIndexArray->num;
// don't add it using the "standard" way.
insertQuadFromSprite(tile, indexForZ);
@ -458,24 +458,24 @@ static inline int compareInts(const void * a, const void * b)
return ((*(int*)a) - (*(int*)b));
}
unsigned int TMXLayer::atlasIndexForExistantZ(unsigned int z)
ssize_t TMXLayer::atlasIndexForExistantZ(unsigned int z)
{
int key=z;
int *item = (int*)bsearch((void*)&key, (void*)&_atlasIndexArray->arr[0], _atlasIndexArray->num, sizeof(void*), compareInts);
CCASSERT(item, "TMX atlas index not found. Shall not happen");
int index = ((size_t)item - (size_t)_atlasIndexArray->arr) / sizeof(void*);
ssize_t index = ((size_t)item - (size_t)_atlasIndexArray->arr) / sizeof(void*);
return index;
}
unsigned int TMXLayer::atlasIndexForNewZ(int z)
ssize_t TMXLayer::atlasIndexForNewZ(int z)
{
// XXX: This can be improved with a sort of binary search
int i=0;
ssize_t i=0;
for (i=0; i< _atlasIndexArray->num ; i++)
{
int val = (size_t) _atlasIndexArray->arr[i];
ssize_t val = (size_t) _atlasIndexArray->arr[i];
if (z < val)
{
break;
@ -558,8 +558,8 @@ void TMXLayer::removeChild(Node* node, bool cleanup)
CCASSERT(_children.contains(sprite), "Tile does not belong to TMXLayer");
unsigned int atlasIndex = sprite->getAtlasIndex();
unsigned int zz = (size_t)_atlasIndexArray->arr[atlasIndex];
ssize_t atlasIndex = sprite->getAtlasIndex();
ssize_t zz = (ssize_t)_atlasIndexArray->arr[atlasIndex];
_tiles[zz] = 0;
ccCArrayRemoveValueAtIndex(_atlasIndexArray, atlasIndex);
SpriteBatchNode::removeChild(sprite, cleanup);
@ -575,7 +575,7 @@ void TMXLayer::removeTileAt(const Point& pos)
if (gid)
{
unsigned int z = (unsigned int)(pos.x + pos.y * _layerSize.width);
unsigned int atlasIndex = atlasIndexForExistantZ(z);
ssize_t atlasIndex = atlasIndexForExistantZ(z);
// remove tile from GID map
_tiles[z] = 0;
@ -598,7 +598,7 @@ void TMXLayer::removeTileAt(const Point& pos)
Sprite* child = static_cast<Sprite*>(obj);
if (child)
{
unsigned int ai = child->getAtlasIndex();
ssize_t ai = child->getAtlasIndex();
if ( ai >= atlasIndex )
{
child->setAtlasIndex(ai-1);
@ -706,7 +706,7 @@ int TMXLayer::getVertexZForPos(const Point& pos)
std::string TMXLayer::getDescription() const
{
return StringUtils::format("<TMXLayer | tag = %d, size = %d,%d>", (int)_tag,_mapTileSize.width, (int)_mapTileSize.height);
return StringUtils::format("<TMXLayer | tag = %d, size = %d,%d>", _tag, (int)_mapTileSize.width, (int)_mapTileSize.height);
}

View File

@ -209,8 +209,8 @@ private:
int getVertexZForPos(const Point& pos);
// index
unsigned int atlasIndexForExistantZ(unsigned int z);
unsigned int atlasIndexForNewZ(int z);
ssize_t atlasIndexForExistantZ(unsigned int z);
ssize_t atlasIndexForNewZ(int z);
protected:
//! name of the layer

View File

@ -246,7 +246,7 @@ Value TMXTiledMap::getPropertiesForGID(int GID) const
std::string TMXTiledMap::getDescription() const
{
return StringUtils::format("<TMXTiledMap | Tag = %d, Layers = %d", _tag, _children.size());
return StringUtils::format("<TMXTiledMap | Tag = %d, Layers = %zd", _tag, _children.size());
}

View File

@ -74,12 +74,12 @@ TextureAtlas::~TextureAtlas()
#endif
}
int TextureAtlas::getTotalQuads() const
ssize_t TextureAtlas::getTotalQuads() const
{
return _totalQuads;
}
int TextureAtlas::getCapacity() const
ssize_t 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, int capacity)
TextureAtlas * TextureAtlas::create(const char* file, ssize_t capacity)
{
TextureAtlas * textureAtlas = new TextureAtlas();
if(textureAtlas && textureAtlas->initWithFile(file, capacity))
@ -122,7 +122,7 @@ TextureAtlas * TextureAtlas::create(const char* file, int capacity)
return NULL;
}
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, int capacity)
TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, ssize_t capacity)
{
TextureAtlas * textureAtlas = new TextureAtlas();
if (textureAtlas && textureAtlas->initWithTexture(texture, capacity))
@ -134,7 +134,7 @@ TextureAtlas * TextureAtlas::createWithTexture(Texture2D *texture, int capacity)
return NULL;
}
bool TextureAtlas::initWithFile(const char * file, int capacity)
bool TextureAtlas::initWithFile(const char * file, ssize_t capacity)
{
// retained in property
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file);
@ -150,7 +150,7 @@ bool TextureAtlas::initWithFile(const char * file, int capacity)
}
}
bool TextureAtlas::initWithTexture(Texture2D *texture, int capacity)
bool TextureAtlas::initWithTexture(Texture2D *texture, ssize_t capacity)
{
CCASSERT(capacity>=0, "Capacity must be >= 0");
@ -224,7 +224,7 @@ void TextureAtlas::listenBackToForeground(Object *obj)
std::string TextureAtlas::getDescription() const
{
return String::createWithFormat("<TextureAtlas | totalQuads = %d>", _totalQuads)->getCString();
return String::createWithFormat("<TextureAtlas | totalQuads = %zd>", _totalQuads)->getCString();
}
@ -317,7 +317,7 @@ void TextureAtlas::mapBuffers()
// TextureAtlas - Update, Insert, Move & Remove
void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, int index)
void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, ssize_t index)
{
CCASSERT( index >= 0 && index < _capacity, "updateQuadWithTexture: Invalid index");
@ -330,7 +330,7 @@ void TextureAtlas::updateQuad(V3F_C4B_T2F_Quad *quad, int index)
}
void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, int index)
void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, ssize_t index)
{
CCASSERT( index>=0 && index<_capacity, "insertQuadWithTexture: Invalid index");
@ -354,7 +354,7 @@ void TextureAtlas::insertQuad(V3F_C4B_T2F_Quad *quad, int index)
}
void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount)
void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, ssize_t index, ssize_t amount)
{
CCASSERT(index>=0 && amount>=0 && index+amount<=_capacity, "insertQuadWithTexture: Invalid index + amount");
@ -375,7 +375,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount)
auto max = index + amount;
int j = 0;
for (int i = index; i < max ; i++)
for (ssize_t i = index; i < max ; i++)
{
_quads[index] = quads[j];
index++;
@ -385,7 +385,7 @@ void TextureAtlas::insertQuads(V3F_C4B_T2F_Quad* quads, int index, int amount)
_dirty = true;
}
void TextureAtlas::insertQuadFromIndex(int oldIndex, int newIndex)
void TextureAtlas::insertQuadFromIndex(ssize_t oldIndex, ssize_t newIndex)
{
CCASSERT( newIndex >= 0 && newIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
CCASSERT( oldIndex >= 0 && oldIndex < _totalQuads, "insertQuadFromIndex:atIndex: Invalid index");
@ -414,7 +414,7 @@ void TextureAtlas::insertQuadFromIndex(int oldIndex, int newIndex)
_dirty = true;
}
void TextureAtlas::removeQuadAtIndex(int index)
void TextureAtlas::removeQuadAtIndex(ssize_t index)
{
CCASSERT( index>=0 && index<_totalQuads, "removeQuadAtIndex: Invalid index");
@ -433,7 +433,7 @@ void TextureAtlas::removeQuadAtIndex(int index)
_dirty = true;
}
void TextureAtlas::removeQuadsAtIndex(int index, int amount)
void TextureAtlas::removeQuadsAtIndex(ssize_t index, ssize_t amount)
{
CCASSERT(index>=0 && amount>=0 && index+amount<=_totalQuads, "removeQuadAtIndex: index + amount out of bounds");
@ -455,7 +455,7 @@ void TextureAtlas::removeAllQuads()
}
// TextureAtlas - Resize
bool TextureAtlas::resizeCapacity(int newCapacity)
bool TextureAtlas::resizeCapacity(ssize_t newCapacity)
{
CCASSERT(newCapacity>=0, "capacity >= 0");
if( newCapacity == _capacity )
@ -529,13 +529,13 @@ bool TextureAtlas::resizeCapacity(int newCapacity)
return true;
}
void TextureAtlas::increaseTotalQuadsWith(int amount)
void TextureAtlas::increaseTotalQuadsWith(ssize_t amount)
{
CCASSERT(amount>=0, "amount >= 0");
_totalQuads += amount;
}
void TextureAtlas::moveQuadsFromIndex(int oldIndex, int amount, int newIndex)
void TextureAtlas::moveQuadsFromIndex(ssize_t oldIndex, ssize_t amount, ssize_t 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(int oldIndex, int amount, int newIndex)
_dirty = true;
}
void TextureAtlas::moveQuadsFromIndex(int index, int newIndex)
void TextureAtlas::moveQuadsFromIndex(ssize_t index, ssize_t 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(int index, int newIndex)
memmove(_quads + newIndex,_quads + index, (_totalQuads - index) * sizeof(_quads[0]));
}
void TextureAtlas::fillWithEmptyQuadsFromIndex(int index, int amount)
void TextureAtlas::fillWithEmptyQuadsFromIndex(ssize_t index, ssize_t amount)
{
CCASSERT(index>=0 && amount>=0, "values must be >= 0");
V3F_C4B_T2F_Quad quad;
memset(&quad, 0, sizeof(quad));
auto to = index + amount;
for (int i = index ; i < to ; i++)
for (ssize_t i = index ; i < to ; i++)
{
_quads[i] = quad;
}
@ -595,13 +595,13 @@ void TextureAtlas::drawQuads()
this->drawNumberOfQuads(_totalQuads, 0);
}
void TextureAtlas::drawNumberOfQuads(int numberOfQuads)
void TextureAtlas::drawNumberOfQuads(ssize_t numberOfQuads)
{
CCASSERT(numberOfQuads>=0, "numberOfQuads must be >= 0");
this->drawNumberOfQuads(numberOfQuads, 0);
}
void TextureAtlas::drawNumberOfQuads(int numberOfQuads, int start)
void TextureAtlas::drawNumberOfQuads(ssize_t numberOfQuads, ssize_t start)
{
CCASSERT(numberOfQuads>=0 && start>=0, "numberOfQuads and start must be >= 0");

View File

@ -59,13 +59,13 @@ public:
/** 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 , int capacity);
static TextureAtlas* create(const char* file , ssize_t 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, int capacity);
static TextureAtlas* createWithTexture(Texture2D *texture, ssize_t capacity);
/**
* @js ctor
*/
@ -81,7 +81,7 @@ public:
*
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
*/
bool initWithFile(const char* file, int capacity);
bool initWithFile(const char* file, ssize_t capacity);
/** initializes a TextureAtlas with a previously initialized Texture2D object, and
* with an initial capacity for Quads.
@ -89,43 +89,43 @@ public:
*
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
*/
bool initWithTexture(Texture2D *texture, int capacity);
bool initWithTexture(Texture2D *texture, ssize_t 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, int index);
void updateQuad(V3F_C4B_T2F_Quad* quad, ssize_t 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, int index);
void insertQuad(V3F_C4B_T2F_Quad* quad, ssize_t 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, int index, int amount);
void insertQuads(V3F_C4B_T2F_Quad* quads, ssize_t index, ssize_t 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(int fromIndex, int newIndex);
void insertQuadFromIndex(ssize_t fromIndex, ssize_t 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(int index);
void removeQuadAtIndex(ssize_t index);
/** removes a amount of quads starting from index
@since 1.1
*/
void removeQuadsAtIndex(int index, int amount);
void removeQuadsAtIndex(ssize_t index, ssize_t 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 @@ public:
* 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(int capacity);
bool resizeCapacity(ssize_t capacity);
/**
Used internally by ParticleBatchNode
don't use this unless you know what you're doing
@since 1.1
*/
void increaseTotalQuadsWith(int amount);
void increaseTotalQuadsWith(ssize_t amount);
/** Moves an amount of quads from oldIndex at newIndex
@since v1.1
*/
void moveQuadsFromIndex(int oldIndex, int amount, int newIndex);
void moveQuadsFromIndex(ssize_t oldIndex, ssize_t amount, ssize_t newIndex);
/**
Moves quads from index till totalQuads to the newIndex
@ -158,26 +158,26 @@ public:
This method doesn't enlarge the array if newIndex + quads to be moved > capacity
@since 1.1
*/
void moveQuadsFromIndex(int index, int newIndex);
void moveQuadsFromIndex(ssize_t index, ssize_t newIndex);
/**
Ensures that after a realloc quads are still empty
Used internally by ParticleBatchNode
@since 1.1
*/
void fillWithEmptyQuadsFromIndex(int index, int amount);
void fillWithEmptyQuadsFromIndex(ssize_t index, ssize_t amount);
/** draws n quads
* n can't be greater than the capacity of the Atlas
*/
void drawNumberOfQuads(int n);
void drawNumberOfQuads(ssize_t 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(int numberOfQuads, int start);
void drawNumberOfQuads(ssize_t numberOfQuads, ssize_t start);
/** draws all the Atlas's Quads
*/
@ -197,10 +197,10 @@ public:
virtual std::string getDescription() const;
/** Gets the quantity of quads that are going to be drawn */
int getTotalQuads() const;
ssize_t getTotalQuads() const;
/** Gets the quantity of quads that can be stored with the current texture atlas size */
int getCapacity() const;
ssize_t getCapacity() const;
/** Gets the texture of the texture atlas */
Texture2D* getTexture() const;
@ -228,9 +228,9 @@ protected:
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 */
int _totalQuads;
ssize_t _totalQuads;
/** quantity of quads that can be stored with the current texture atlas size */
int _capacity;
ssize_t _capacity;
/** Texture of the texture atlas */
Texture2D* _texture;
/** Quads that are going to be rendered */

View File

@ -222,7 +222,7 @@ void TileMapAtlas::updateAtlasValueAt(const Point& pos, const Color3B& value, in
quad->bl.colors = color;
_textureAtlas->setDirty(true);
int totalQuads = _textureAtlas->getTotalQuads();
ssize_t totalQuads = _textureAtlas->getTotalQuads();
if (index + 1 > totalQuads) {
_textureAtlas->increaseTotalQuadsWith(index + 1 - totalQuads);
}

View File

@ -28,10 +28,10 @@ THE SOFTWARE.
NS_CC_BEGIN
const int CC_INVALID_INDEX = -1;
const ssize_t CC_INVALID_INDEX = -1;
/** Allocates and initializes a new array with specified capacity */
ccArray* ccArrayNew(int capacity)
ccArray* ccArrayNew(ssize_t capacity)
{
if (capacity == 0)
capacity = 7;
@ -68,11 +68,11 @@ void ccArrayDoubleCapacity(ccArray *arr)
arr->arr = newArr;
}
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra)
void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra)
{
while (arr->max < arr->num + extra)
{
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%d] to [%d].",
CCLOG("cocos2d: ccCArray: resizing ccArray capacity from [%zd] to [%zd].",
arr->max,
arr->max*2);
@ -82,7 +82,7 @@ void ccArrayEnsureExtraCapacity(ccArray *arr, int extra)
void ccArrayShrink(ccArray *arr)
{
int newSize = 0;
ssize_t newSize = 0;
//only resize when necessary
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
@ -104,11 +104,11 @@ void ccArrayShrink(ccArray *arr)
}
/** Returns index of first occurrence of object, CC_INVALID_INDEX if object not found. */
int ccArrayGetIndexOfObject(ccArray *arr, Object* object)
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Object* object)
{
const auto arrNum = arr->num;
Object** ptr = arr->arr;
for (int i = 0; i < arrNum; ++i, ++ptr)
for (ssize_t i = 0; i < arrNum; ++i, ++ptr)
{
if (*ptr == object)
return i;
@ -143,7 +143,7 @@ void ccArrayAppendObjectWithResize(ccArray *arr, Object* object)
enough capacity. */
void ccArrayAppendArray(ccArray *arr, ccArray *plusArr)
{
for (int i = 0; i < plusArr->num; i++)
for (ssize_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, int index)
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, ssize_t index)
{
CCASSERT(index<=arr->num, "Invalid index. Out of bounds");
CCASSERT(object != NULL, "Invalid parameter!");
ccArrayEnsureExtraCapacity(arr, 1);
int remaining = arr->num - index;
ssize_t remaining = arr->num - index;
if (remaining > 0)
{
memmove((void *)&arr->arr[index+1], (void *)&arr->arr[index], sizeof(Object*) * remaining );
@ -176,7 +176,7 @@ void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, int index)
}
/** Swaps two objects */
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2)
void ccArraySwapObjectsAtIndexes(ccArray *arr, ssize_t index1, ssize_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");
@ -198,7 +198,7 @@ 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, int index, bool bReleaseObj/* = true*/)
void ccArrayRemoveObjectAtIndex(ccArray *arr, ssize_t index, bool bReleaseObj/* = true*/)
{
CCASSERT(arr && arr->num > 0 && index>=0 && index < arr->num, "Invalid index. Out of bounds");
if (bReleaseObj)
@ -208,7 +208,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj/* = tr
arr->num--;
int remaining = arr->num - index;
ssize_t remaining = arr->num - index;
if(remaining>0)
{
memmove((void *)&arr->arr[index], (void *)&arr->arr[index+1], remaining * sizeof(Object*));
@ -218,7 +218,7 @@ void ccArrayRemoveObjectAtIndex(ccArray *arr, int index, bool bReleaseObj/* = tr
/** 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, int index)
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, ssize_t index)
{
CC_SAFE_RELEASE(arr->arr[index]);
auto last = --arr->num;
@ -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 (int i = 0; i < minusArr->num; i++)
for (ssize_t i = 0; i < minusArr->num; i++)
{
ccArrayRemoveObject(arr, minusArr->arr[i]);
}
@ -259,9 +259,9 @@ void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr)
matching instances in arr will be removed. */
void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr)
{
int back = 0;
ssize_t back = 0;
for (int i = 0; i < arr->num; i++)
for (ssize_t i = 0; i < arr->num; i++)
{
if (ccArrayContainsObject(minusArr, arr->arr[i]))
{
@ -281,7 +281,7 @@ 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(int capacity)
ccCArray* ccCArrayNew(ssize_t capacity)
{
if (capacity == 0)
{
@ -316,15 +316,15 @@ void ccCArrayDoubleCapacity(ccCArray *arr)
}
/** Increases array capacity such that max >= num + extra. */
void ccCArrayEnsureExtraCapacity(ccCArray *arr, int extra)
void ccCArrayEnsureExtraCapacity(ccCArray *arr, ssize_t extra)
{
ccArrayEnsureExtraCapacity((ccArray*)arr,extra);
}
/** Returns index of first occurrence of value, CC_INVALID_INDEX if value not found. */
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
ssize_t ccCArrayGetIndexOfValue(ccCArray *arr, void* value)
{
for(int i = 0; i < arr->num; i++)
for(ssize_t i = 0; i < arr->num; i++)
{
if( arr->arr[i] == value )
return i;
@ -339,7 +339,7 @@ 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, int index)
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, ssize_t index)
{
CCASSERT( index < arr->max, "ccCArrayInsertValueAtIndex: invalid index");
@ -384,7 +384,7 @@ void ccCArrayAppendValueWithResize(ccCArray *arr, void* value)
enough capacity. */
void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr)
{
for( int i = 0; i < plusArr->num; i++)
for( ssize_t i = 0; i < plusArr->num; i++)
{
ccCArrayAppendValue(arr, plusArr->arr[i]);
}
@ -407,9 +407,9 @@ void ccCArrayRemoveAllValues(ccCArray *arr)
Behavior undefined if index outside [0, num-1].
@since v0.99.4
*/
void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index)
void ccCArrayRemoveValueAtIndex(ccCArray *arr, ssize_t index)
{
for( int last = --arr->num; index < last; index++)
for( ssize_t last = --arr->num; index < last; index++)
{
arr->arr[index] = arr->arr[index + 1];
}
@ -420,9 +420,9 @@ void ccCArrayRemoveValueAtIndex(ccCArray *arr, int index)
Behavior undefined if index outside [0, num-1].
@since v0.99.4
*/
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, int index)
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, ssize_t index)
{
auto last = --arr->num;
ssize_t last = --arr->num;
arr->arr[index] = arr->arr[last];
}
@ -443,7 +443,7 @@ void ccCArrayRemoveValue(ccCArray *arr, void* value)
*/
void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
{
for(int i = 0; i < minusArr->num; i++)
for(ssize_t i = 0; i < minusArr->num; i++)
{
ccCArrayRemoveValue(arr, minusArr->arr[i]);
}
@ -454,9 +454,9 @@ void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr)
*/
void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
{
int back = 0;
ssize_t back = 0;
for(int i = 0; i < arr->num; i++)
for(ssize_t i = 0; i < arr->num; i++)
{
if( ccCArrayContainsValue(minusArr, arr->arr[i]) )
{

View File

@ -51,20 +51,20 @@ THE SOFTWARE.
NS_CC_BEGIN
extern const int CC_INVALID_INDEX;
extern const ssize_t CC_INVALID_INDEX;
// Easy integration
#define CCARRAYDATA_FOREACH(__array__, __object__) \
__object__=__array__->arr[0]; for(int i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
__object__=__array__->arr[0]; for(ssize_t i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
typedef struct _ccArray {
int num, max;
ssize_t num, max;
Object** arr;
} ccArray;
/** Allocates and initializes a new array with specified capacity */
ccArray* ccArrayNew(int capacity);
ccArray* ccArrayNew(ssize_t capacity);
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
void ccArrayFree(ccArray*& arr);
@ -73,13 +73,13 @@ void ccArrayFree(ccArray*& arr);
void ccArrayDoubleCapacity(ccArray *arr);
/** Increases array capacity such that max >= num + extra. */
void ccArrayEnsureExtraCapacity(ccArray *arr, int extra);
void ccArrayEnsureExtraCapacity(ccArray *arr, ssize_t extra);
/** shrinks the array so the memory footprint corresponds with the number of items */
void ccArrayShrink(ccArray *arr);
/** Returns index of first occurrence of object, NSNotFound if object not found. */
int ccArrayGetIndexOfObject(ccArray *arr, Object* object);
ssize_t ccArrayGetIndexOfObject(ccArray *arr, Object* object);
/** Returns a Boolean value that indicates whether object is present in array. */
bool ccArrayContainsObject(ccArray *arr, Object* object);
@ -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, int index);
void ccArrayInsertObjectAtIndex(ccArray *arr, Object* object, ssize_t index);
/** Swaps two objects */
void ccArraySwapObjectsAtIndexes(ccArray *arr, int index1, int index2);
void ccArraySwapObjectsAtIndexes(ccArray *arr, ssize_t index1, ssize_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, int index, bool bReleaseObj = true);
void ccArrayRemoveObjectAtIndex(ccArray *arr, ssize_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, int index);
void ccArrayFastRemoveObjectAtIndex(ccArray *arr, ssize_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 {
int num, max;
ssize_t num, max;
void** arr;
} ccCArray;
/** Allocates and initializes a new C array with specified capacity */
ccCArray* ccCArrayNew(int capacity);
ccCArray* ccCArrayNew(ssize_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, int extra);
void ccCArrayEnsureExtraCapacity(ccCArray *arr, ssize_t extra);
/** Returns index of first occurrence of value, NSNotFound if value not found. */
int ccCArrayGetIndexOfValue(ccCArray *arr, void* value);
ssize_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, int index);
void ccCArrayInsertValueAtIndex( ccCArray *arr, void* value, ssize_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, int index);
void ccCArrayRemoveValueAtIndex(ccCArray *arr, ssize_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, int index);
void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, ssize_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

View File

@ -196,11 +196,11 @@ bool __Array::initWithArray(__Array* otherArray)
return true;
}
int __Array::getIndexOfObject(Object* object) const
ssize_t __Array::getIndexOfObject(Object* object) const
{
auto it = data.begin();
for (int i = 0; it != data.end(); ++it, ++i)
for (ssize_t i = 0; it != data.end(); ++it, ++i)
{
if (it->get() == object)
{
@ -232,13 +232,13 @@ Object* __Array::getRandomObject()
bool __Array::containsObject(Object* object) const
{
auto i = this->getIndexOfObject(object);
ssize_t i = this->getIndexOfObject(object);
return (i >= 0);
}
bool __Array::isEqualToArray(__Array* otherArray)
{
for (int i = 0; i < this->count(); ++i)
for (ssize_t i = 0; i < this->count(); ++i)
{
if (!this->getObjectAtIndex(i)->isEqual(otherArray->getObjectAtIndex(i)))
{
@ -279,7 +279,7 @@ void __Array::removeObject(Object* object, bool releaseObj /* ignored */)
data.erase(std::remove(data.begin(), data.end(), object));
}
void __Array::removeObjectAtIndex(int index, bool releaseObj /* ignored */)
void __Array::removeObjectAtIndex(ssize_t index, bool releaseObj /* ignored */)
{
auto obj = data[index];
data.erase(data.begin() + index);
@ -307,15 +307,15 @@ void __Array::fastRemoveObject(Object* object)
void __Array::exchangeObject(Object* object1, Object* object2)
{
auto idx1 = getIndexOfObject(object1);
auto idx2 = getIndexOfObject(object2);
ssize_t idx1 = getIndexOfObject(object1);
ssize_t idx2 = getIndexOfObject(object2);
CCASSERT(idx1 >= 0 && idx2 >= 2, "invalid object index");
std::swap(data[idx1], data[idx2]);
}
void __Array::exchangeObjectAtIndex(int index1, int index2)
void __Array::exchangeObjectAtIndex(ssize_t index1, ssize_t index2)
{
std::swap(data[index1], data[index2]);
}
@ -448,7 +448,7 @@ __Array* __Array::createWithArray(__Array* otherArray)
return otherArray->clone();
}
__Array* __Array::createWithCapacity(int capacity)
__Array* __Array::createWithCapacity(ssize_t capacity)
{
CCASSERT(capacity>=0, "Invalid capacity");
@ -539,7 +539,7 @@ bool __Array::initWithObjects(Object* object, ...)
return ret;
}
bool __Array::initWithCapacity(int capacity)
bool __Array::initWithCapacity(ssize_t capacity)
{
CCASSERT(capacity>=0 && !data, "Array cannot be re-initialized");
@ -563,7 +563,7 @@ bool __Array::initWithArray(__Array* otherArray)
return ret;
}
int __Array::getIndexOfObject(Object* object) const
ssize_t __Array::getIndexOfObject(Object* object) const
{
return ccArrayGetIndexOfObject(data, object);
}
@ -614,13 +614,13 @@ void __Array::addObjectsFromArray(__Array* otherArray)
ccArrayAppendArrayWithResize(data, otherArray->data);
}
void __Array::insertObject(Object* object, int index)
void __Array::insertObject(Object* object, ssize_t index)
{
CCASSERT(data, "Array not initialized");
ccArrayInsertObjectAtIndex(data, object, index);
}
void __Array::setObject(Object* object, int index)
void __Array::setObject(Object* object, ssize_t index)
{
CCASSERT(index >= 0 && index < count(), "Invalid index");
@ -643,7 +643,7 @@ void __Array::removeObject(Object* object, bool releaseObj/* = true*/)
ccArrayRemoveObject(data, object, releaseObj);
}
void __Array::removeObjectAtIndex(int index, bool releaseObj)
void __Array::removeObjectAtIndex(ssize_t index, bool releaseObj)
{
ccArrayRemoveObjectAtIndex(data, index, releaseObj);
}
@ -658,7 +658,7 @@ void __Array::removeAllObjects()
ccArrayRemoveAllObjects(data);
}
void __Array::fastRemoveObjectAtIndex(int index)
void __Array::fastRemoveObjectAtIndex(ssize_t index)
{
ccArrayFastRemoveObjectAtIndex(data, index);
}
@ -685,12 +685,12 @@ void __Array::exchangeObject(Object* object1, Object* object2)
ccArraySwapObjectsAtIndexes(data, index1, index2);
}
void __Array::exchangeObjectAtIndex(int index1, int index2)
void __Array::exchangeObjectAtIndex(ssize_t index1, ssize_t index2)
{
ccArraySwapObjectsAtIndexes(data, index1, index2);
}
void __Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject/* = true*/)
void __Array::replaceObjectAtIndex(ssize_t index, Object* object, bool releaseObject/* = true*/)
{
ccArrayInsertObjectAtIndex(data, object, index);
ccArrayRemoveObjectAtIndex(data, index + 1);
@ -701,10 +701,10 @@ void __Array::reverseObjects()
if (data->num > 1)
{
// floorf(), since in the case of an even number, the number of swaps stays the same
auto count = static_cast<int>(floorf(data->num/2.f));
auto maxIndex = data->num - 1;
auto count = static_cast<ssize_t>(floorf(data->num/2.f));
ssize_t maxIndex = data->num - 1;
for (int i = 0; i < count ; ++i)
for (ssize_t i = 0; i < count ; ++i)
{
ccArraySwapObjectsAtIndexes(data, i, maxIndex);
--maxIndex;

View File

@ -250,7 +250,7 @@ public:
/** Create an array with a default capacity
* @js NA
*/
static __Array* createWithCapacity(int capacity);
static __Array* createWithCapacity(ssize_t capacity);
/** Create an array with from an existing array
* @js NA
*/
@ -295,7 +295,7 @@ public:
* @js NA
* @lua NA
*/
bool initWithCapacity(int capacity);
bool initWithCapacity(ssize_t capacity);
/** Initializes an array with an existing array
* @js NA
* @lua NA
@ -307,7 +307,7 @@ public:
/** Returns element count of the array
* @js NA
*/
int count() const
ssize_t count() const
{
#if CC_USE_ARRAY_VECTOR
return data.size();
@ -318,7 +318,7 @@ public:
/** Returns capacity of the array
* @js NA
*/
int capacity() const
ssize_t capacity() const
{
#if CC_USE_ARRAY_VECTOR
return data.capacity();
@ -330,17 +330,17 @@ public:
* @js NA
* @lua NA
*/
int getIndexOfObject(Object* object) const;
ssize_t getIndexOfObject(Object* object) const;
/**
* @js NA
*/
CC_DEPRECATED_ATTRIBUTE int indexOfObject(Object* object) const { return getIndexOfObject(object); }
CC_DEPRECATED_ATTRIBUTE ssize_t indexOfObject(Object* object) const { return getIndexOfObject(object); }
/** Returns an element with a certain index
* @js NA
* @lua NA
*/
Object* getObjectAtIndex(int index)
Object* getObjectAtIndex(ssize_t index)
{
CCASSERT(index>=0 && index < count(), "index out of range in getObjectAtIndex()");
#if CC_USE_ARRAY_VECTOR
@ -349,7 +349,7 @@ public:
return data->arr[index];
#endif
}
CC_DEPRECATED_ATTRIBUTE Object* objectAtIndex(int index) { return getObjectAtIndex(index); }
CC_DEPRECATED_ATTRIBUTE Object* objectAtIndex(ssize_t index) { return getObjectAtIndex(index); }
/** Returns the last element of the array
* @js NA
*/
@ -401,17 +401,17 @@ public:
/** Insert a certain object at a certain index
* @js NA
*/
void insertObject(Object* object, int index);
void insertObject(Object* object, ssize_t index);
/** sets a certain object at a certain index
* @js NA
* @lua NA
*/
void setObject(Object* object, int index);
void setObject(Object* object, ssize_t index);
/** sets a certain object at a certain index without retaining. Use it with caution
* @js NA
* @lua NA
*/
void fastSetObject(Object* object, int index)
void fastSetObject(Object* object, ssize_t index)
{
#if CC_USE_ARRAY_VECTOR
setObject(object, index);
@ -424,7 +424,7 @@ public:
* @js NA
* @lua NA
*/
void swap( int indexOne, int indexTwo )
void swap( ssize_t indexOne, ssize_t indexTwo )
{
CCASSERT(indexOne >=0 && indexOne < count() && indexTwo >= 0 && indexTwo < count(), "Invalid indices");
#if CC_USE_ARRAY_VECTOR
@ -447,7 +447,7 @@ public:
/** Remove an element with a certain index
* @js NA
*/
void removeObjectAtIndex(int index, bool releaseObj = true);
void removeObjectAtIndex(ssize_t index, bool releaseObj = true);
/** Remove all elements
* @js NA
*/
@ -463,7 +463,7 @@ public:
/** Fast way to remove an element with a certain index
* @js NA
*/
void fastRemoveObjectAtIndex(int index);
void fastRemoveObjectAtIndex(ssize_t index);
// Rearranging Content
@ -474,12 +474,12 @@ public:
/** Swap two elements with certain indexes
* @js NA
*/
void exchangeObjectAtIndex(int index1, int index2);
void exchangeObjectAtIndex(ssize_t index1, ssize_t index2);
/** Replace object at index with another object.
* @js NA
*/
void replaceObjectAtIndex(int index, Object* object, bool releaseObject = true);
void replaceObjectAtIndex(ssize_t index, Object* object, bool releaseObject = true);
/** Revers the array
* @js NA

View File

@ -51,7 +51,7 @@ void AutoreleasePool::removeObject(Object* object)
{
for (unsigned int i = 0; i < object->_autoReleaseCount; ++i)
{
_managedObjectArray.erase(object, false);
_managedObjectArray.eraseObject(object, false);
}
}
@ -141,7 +141,7 @@ void PoolManager::pop()
return;
}
int count = _releasePoolStack.size();
ssize_t count = _releasePoolStack.size();
_curReleasePool->clear();

View File

@ -1,26 +1,26 @@
/****************************************************************************
Copyright (c) 2012 - 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
Copyright (c) 2012 - 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCMAP_H__
#define __CCMAP_H__
@ -67,13 +67,13 @@ public:
}
/** Contructor with capacity */
explicit Map<K, V>(int capacity)
explicit Map<K, V>(ssize_t capacity)
: _data()
{
CCLOGINFO("In the constructor with capacity of Map!");
_data.reserve(capacity);
}
/** Copy constructor */
Map<K, V>(const Map<K, V>& other)
{
@ -89,7 +89,7 @@ public:
_data = std::move(other._data);
}
/** Destructor
/** Destructor
* It will release all objects in map.
*/
~Map<K, V>()
@ -97,25 +97,25 @@ public:
CCLOGINFO("In the destructor of Map!");
clear();
}
/** Sets capacity of the map */
void reserve(int capacity)
void reserve(ssize_t capacity)
{
_data.reserve(capacity);
}
/** Returns capacity of the map */
size_t capacity() const
ssize_t capacity() const
{
return _data.capacity();
}
/** The number of elements in the map. */
size_t size() const
ssize_t size() const
{
return _data.size();
}
/** Returns a bool value indicating whether the map container is empty, i.e. whether its size is 0.
* @note This function does not modify the content of the container in any way.
* To clear the content of an array object, member function unordered_map::clear exists.
@ -129,7 +129,7 @@ public:
std::vector<K> keys() const
{
std::vector<K> keys;
if (!_data.empty())
{
for (auto iter = _data.cbegin(); iter != _data.cend(); ++iter)
@ -139,7 +139,7 @@ public:
}
return keys;
}
/** Returns all keys that matches the object */
std::vector<K> keys(V object) const
{
@ -155,7 +155,7 @@ public:
return keys;
}
/** @brief Returns a reference to the mapped value of the element with key k in the map.
* @note If key does not match the key of any element in the container, the function return nullptr.
* @param key Key value of the element whose mapped value is accessed.
@ -206,7 +206,7 @@ public:
_data.insert(std::make_pair(key, object));
object->retain();
}
/** @brief Removes an element with an iterator from the Map<K, V> container.
* @param position Iterator pointing to a single element to be removed from the Map<K, V>.
* Member type const_iterator is a forward iterator type.
@ -267,36 +267,36 @@ public:
{
if (!_data.empty())
{
int randIdx = rand() % _data.size();
ssize_t randIdx = rand() % _data.size();
return (_data.begin() + randIdx)->second;
}
return nullptr;
}
// Don't uses operator since we could not decide whether it needs 'retain'/'release'.
// V& operator[] ( const K& key )
// {
// CCLOG("copy: [] ref");
// return _data[key];
// }
//
// V& operator[] ( K&& key )
// {
// CCLOG("move [] ref");
// return _data[key];
// }
// Don't uses operator since we could not decide whether it needs 'retain'/'release'.
// V& operator[] ( const K& key )
// {
// CCLOG("copy: [] ref");
// return _data[key];
// }
//
// V& operator[] ( K&& key )
// {
// CCLOG("move [] ref");
// return _data[key];
// }
// const V& operator[] ( const K& key ) const
// {
// CCLOG("const copy []");
// return _data.at(key);
// }
//
// const V& operator[] ( K&& key ) const
// {
// CCLOG("const move []");
// return _data.at(key);
// }
// const V& operator[] ( const K& key ) const
// {
// CCLOG("const copy []");
// return _data.at(key);
// }
//
// const V& operator[] ( K&& key ) const
// {
// CCLOG("const move []");
// return _data.at(key);
// }
/** Copy assignment operator */
Map<K, V>& operator= ( const Map<K, V>& other )
@ -307,7 +307,7 @@ public:
addRefForAllObjects();
return *this;
}
/** Move assignment operator */
Map<K, V>& operator= ( Map<K, V>&& other )
{

View File

@ -72,7 +72,7 @@ public:
}
/** Constructor with a capacity */
explicit Vector<T>(int capacity)
explicit Vector<T>(ssize_t capacity)
: _data()
{
CCLOGINFO("In the default constructor with capacity of Vector.");
@ -135,7 +135,7 @@ public:
* If n is greater than the current vector capacity,
* the function causes the container to reallocate its storage increasing its capacity to n (or greater).
*/
void reserve(int n)
void reserve(ssize_t n)
{
_data.reserve(n);
}
@ -145,7 +145,7 @@ public:
* It can be equal or greater, with the extra space allowing to accommodate for growth without the need to reallocate on each insertion.
* @return The size of the currently allocated storage capacity in the vector, measured in terms of the number elements it can hold.
*/
int capacity() const
ssize_t capacity() const
{
return _data.capacity();
}
@ -154,9 +154,9 @@ public:
* @note This is the number of actual objects held in the vector, which is not necessarily equal to its storage capacity.
* @return The number of elements in the container.
*/
int size() const
ssize_t size() const
{
return static_cast<int>(_data.size());
return _data.size();
}
/** @brief Returns whether the vector is empty (i.e. whether its size is 0).
@ -168,13 +168,13 @@ public:
}
/** Returns the maximum number of elements that the vector can hold. */
size_t max_size() const
ssize_t max_size() const
{
return _data.max_size();
}
/** Returns index of a certain object, return UINT_MAX if doesn't contain the object */
int getIndex(T object) const
ssize_t getIndex(T object) const
{
auto iter = std::find(_data.begin(), _data.end(), object);
if (iter != _data.end())
@ -198,7 +198,7 @@ public:
}
/** Returns the element at position 'index' in the vector. */
T at(int index) const
T at(ssize_t index) const
{
CCASSERT( index >= 0 && index < size(), "index out of range in getObjectAtIndex()");
return _data[index];
@ -221,7 +221,7 @@ public:
{
if (!_data.empty())
{
int randIdx = rand() % _data.size();
ssize_t randIdx = rand() % _data.size();
return *(_data.begin() + randIdx);
}
return nullptr;
@ -236,11 +236,11 @@ public:
/** Returns true if the two vectors are equal */
bool equals(const Vector<T> &other)
{
size_t s = this->size();
ssize_t s = this->size();
if (s != other.size())
return false;
for (int i = 0; i < s; i++)
for (ssize_t i = 0; i < s; i++)
{
if (!this->at(i)->isEqual(other.at(i)))
{
@ -279,7 +279,7 @@ public:
* This causes an automatic reallocation of the allocated storage space
* if -and only if- the new vector size surpasses the current vector capacity.
*/
void insert(int index, T object)
void insert(ssize_t index, T object)
{
CCASSERT(index >= 0 && index <= size(), "Invalid index!");
CCASSERT(object != nullptr, "The object should not be nullptr");
@ -304,7 +304,7 @@ public:
* @param object The object to be removed.
* @param toRelease Whether to decrease the referece count of the deleted object.
*/
void erase(T object, bool toRelease = true)
void eraseObject(T object, bool toRelease = true)
{
CCASSERT(object != nullptr, "The object should not be nullptr");
auto iter = std::find(_data.begin(), _data.end(), object);
@ -347,7 +347,7 @@ public:
* @return An iterator pointing to the new location of the element that followed the last element erased by the function call.
* This is the container end if the operation erased the last element in the sequence.
*/
iterator erase(int index)
iterator erase(ssize_t index)
{
CCASSERT(!_data.empty() && index >=0 && index < size(), "Invalid index!");
auto it = std::next( begin(), index );
@ -371,8 +371,8 @@ public:
/** Swap two elements */
void swap(T object1, T object2)
{
auto idx1 = getIndex(object1);
auto idx2 = getIndex(object2);
ssize_t idx1 = getIndex(object1);
ssize_t idx2 = getIndex(object2);
CCASSERT(idx1>=0 && idx2>=0, "invalid object index");
@ -380,7 +380,7 @@ public:
}
/** Swap two elements with certain indexes */
void swap(int index1, int index2)
void swap(ssize_t index1, ssize_t index2)
{
CCASSERT(index1 >=0 && index1 < size() && index2 >= 0 && index2 < size(), "Invalid indices");
@ -388,7 +388,7 @@ public:
}
/** Replace object at index with another object. */
void replace(int index, T object)
void replace(ssize_t index, T object)
{
CCASSERT(index >= 0 && index < size(), "Invalid index!");
CCASSERT(object != nullptr, "The object should not be nullptr");

View File

@ -623,7 +623,7 @@ Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* chann
Vector<FiniteTimeAction*> actions;
auto& keyframes = channel->getKeyframes();
int numKeyframes = keyframes.size();
ssize_t numKeyframes = keyframes.size();
for (long i = 0; i < numKeyframes; ++i)
{
@ -712,7 +712,7 @@ Object* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel)
Vector<FiniteTimeAction*> actions;
auto& keyframes = channel->getKeyframes();
int numKeyframes = keyframes.size();
ssize_t numKeyframes = keyframes.size();
for (int i = 0; i < numKeyframes; ++i)
{
@ -753,7 +753,7 @@ Object* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel)
void CCBAnimationManager::runAction(Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration)
{
auto& keyframes = pSeqProp->getKeyframes();
int numKeyframes = keyframes.size();
ssize_t numKeyframes = keyframes.size();
if (numKeyframes > 1)
{
@ -768,7 +768,7 @@ void CCBAnimationManager::runAction(Node *pNode, CCBSequenceProperty *pSeqProp,
actions.pushBack(DelayTime::create(timeFirst));
}
for (int i = 0; i < numKeyframes - 1; ++i)
for (ssize_t i = 0; i < numKeyframes - 1; ++i)
{
CCBKeyframe *kf0 = keyframes.at(i);
CCBKeyframe *kf1 = keyframes.at(i+1);

View File

@ -970,9 +970,9 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
if (!ownerCallbackNames.empty() && !ownerCallbackNodes.empty())
{
CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(), "");
int nCount = ownerCallbackNames.size();
ssize_t nCount = ownerCallbackNames.size();
for (int i = 0 ; i < nCount; i++)
for (ssize_t i = 0 ; i < nCount; i++)
{
pCCBReader->addOwnerCallbackName(ownerCallbackNames[i].asString());
pCCBReader->addOwnerCallbackNode(ownerCallbackNodes.at(i));
@ -984,9 +984,9 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
if (!ownerOutletNames.empty() && !ownerOutletNodes.empty())
{
CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(), "");
int nCount = ownerOutletNames.size();
ssize_t nCount = ownerOutletNames.size();
for (int i = 0 ; i < nCount; i++)
for (ssize_t i = 0 ; i < nCount; i++)
{
pCCBReader->addOwnerOutletName(ownerOutletNames.at(i).asString());
pCCBReader->addOwnerOutletNode(ownerOutletNodes.at(i));

View File

@ -312,7 +312,7 @@ void Armature::changeBoneParent(Bone *bone, const char *parentName)
if(bone->getParentBone())
{
bone->getParentBone()->getChildren().erase(bone);
bone->getParentBone()->getChildren().eraseObject(bone);
bone->setParentBone(nullptr);
}

View File

@ -335,7 +335,7 @@ void Bone::removeChildBone(Bone *bone, bool recursion)
bone->getDisplayManager()->setCurrentDecorativeDisplay(nullptr);
_children.erase(bone);
_children.eraseObject(bone);
}
}

View File

@ -61,7 +61,7 @@ void SkeletonJson_dispose (SkeletonJson* self) {
void _SkeletonJson_setError (SkeletonJson* self, Json* root, const char* value1, const char* value2) {
char message[256];
int length;
size_t length;
FREE(self->error);
strcpy(message, value1);
length = strlen(value1);

View File

@ -50,10 +50,10 @@ void _setFree (void (*free) (void* ptr)) {
freeFunc = free;
}
char* _readFile (const char* path, int* length) {
char* _readFile (const char* path, ssize_t* length) {
char *data;
FILE *file = fopen(path, "rb");
int readBytes = 0;
ssize_t readBytes = 0;
if (!file) return 0;
fseek(file, 0, SEEK_END);

View File

@ -114,7 +114,7 @@ void _free (void* ptr);
void _setMalloc (void* (*_malloc) (size_t size));
void _setFree (void (*_free) (void* ptr));
char* _readFile (const char* path, int* length);
char* _readFile (const char* path, ssize_t* length);
/**/

View File

@ -129,7 +129,7 @@ public:
return nullptr;
}
/** Get the size of request data back */
inline int getRequestDataSize()
inline ssize_t getRequestDataSize()
{
return _requestData.size();
}

View File

@ -107,7 +107,7 @@ public:
/** Get the http response errorCode
* I know that you want to see http 200 :)
*/
inline int getResponseCode()
inline long getResponseCode()
{
return _responseCode;
}
@ -150,7 +150,7 @@ public:
/** Set the http response errorCode
*/
inline void setResponseCode(int value)
inline void setResponseCode(long value)
{
_responseCode = value;
}
@ -172,7 +172,7 @@ protected:
bool _succeed; /// to indecate if the http reqeust is successful simply
std::vector<char> _responseData; /// the returned raw data. You can also dump it as a string
std::vector<char> _responseHeader; /// the returned raw header data. You can also dump it as a string
int _responseCode; /// the status code returned from libcurl, e.g. 200, 404
long _responseCode; /// the status code returned from libcurl, e.g. 200, 404
std::string _errorBuffer; /// if _responseCode != 200, please read _errorBuffer to find the reason
};

View File

@ -672,7 +672,7 @@ void PhysicsBody::removeShape(PhysicsShape* shape, bool reduceMassAndMoment/* =
// set shape->_body = nullptr make the shape->setBody will not trigger the _body->removeShape function call.
shape->_body = nullptr;
shape->setBody(nullptr);
_shapes.erase(shape);
_shapes.eraseObject(shape);
}
}

View File

@ -714,7 +714,7 @@ void PhysicsWorld::removeBody(PhysicsBody* body)
body->_joints.clear();
removeBodyOrDelay(body);
_bodies.erase(body);
_bodies.eraseObject(body);
body->_world = nullptr;
}
@ -723,7 +723,7 @@ void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
{
if (_delayAddBodies.getIndex(body) != CC_INVALID_INDEX)
{
_delayAddBodies.erase(body);
_delayAddBodies.eraseObject(body);
return;
}

@ -1 +1 @@
Subproject commit a9af1cbc151fdc39a619e92180e43d1f8cf04f83
Subproject commit f4de47ad7f5320151933233d3bcba60c8662586f

View File

@ -533,7 +533,7 @@ JSBool ScriptingCore::runScript(const char *path, JSObject* global, JSContext* c
// a) check jsc file first
std::string byteCodePath = RemoveFileExt(std::string(path)) + BYTE_CODE_FILE_EXT;
long length = 0;
ssize_t length = 0;
unsigned char* data = futil->getFileData(byteCodePath.c_str(),
"rb",
&length);

View File

@ -1 +1 @@
7a245db1098d7ced5947aca62f43e67f06d1492d
6ea6ffc183c8a15eae0641c73c9886b90172266f

View File

@ -248,7 +248,7 @@ public:
}
}
virtual Size tableCellSizeForIndex(TableView *table, long idx)
virtual Size tableCellSizeForIndex(TableView *table, ssize_t idx)
{
jsval ret;
bool ok = callJSDelegate(table, idx, "tableCellSizeForIndex", ret);
@ -268,7 +268,7 @@ public:
}
virtual TableViewCell* tableCellAtIndex(TableView *table, long idx)
virtual TableViewCell* tableCellAtIndex(TableView *table, ssize_t idx)
{
jsval ret;
bool ok = callJSDelegate(table, idx, "tableCellAtIndex", ret);

View File

@ -1 +1 @@
4604aa76ce1cd72165190c09b5eba4faf2efca40
9104cc5ff14c7548ea6924a2785400db7526c1e1

View File

@ -219,6 +219,7 @@ static void tolua_reg_script_handler_mgr_type(lua_State* tolua_S)
tolua_usertype(tolua_S, "ScheduleHandlerDelegate");
tolua_usertype(tolua_S, "ScriptHandlerMgr");
}
/* method: getInstance of class ScriptHandlerMgr */
#ifndef TOLUA_DISABLE_tolua_Cocos2d_ScriptHandlerMgr_getInstance00
static int tolua_Cocos2d_ScriptHandlerMgr_getInstance00(lua_State* tolua_S)
@ -243,6 +244,101 @@ tolua_lerror:
}
#endif //#ifndef TOLUA_DISABLE
/* method: registerScriptHandler of class ScriptHandlerMgr */
static int tolua_Cocos2d_ScriptHandlerMgr_registerScriptHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) ||
!tolua_isusertype(tolua_S, 2, "Object", 0, &tolua_err) ||
!toluafix_isfunction(tolua_S, 3, "LUA_FUNCTION", 0, &tolua_err) ||
!tolua_isnumber(tolua_S, 4, 0, &tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err) )
goto tolua_lerror;
else
#endif
{
cocos2d::ScriptHandlerMgr* scriptHanlderMgr = static_cast<cocos2d::ScriptHandlerMgr*>(tolua_tousertype(tolua_S,1,0));
#ifndef TOLUA_RELEASE
if (nullptr == scriptHanlderMgr)
{
tolua_error(tolua_S,"invalid 'scriptHanlderMgr' in function 'tolua_Cocos2d_ScriptHandlerMgr_registerScriptHandler00'\n", NULL);
return 0;
}
#endif
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,3,0);
ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType)tolua_tonumber(tolua_S, 4, 0);
scriptHanlderMgr->addObjectHandler(tolua_tousertype(tolua_S, 2, 0), handler,handlerType);
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err);
return 0;
#endif
}
/* method: unregisterScriptHandler of class ScriptHandlerMgr */
static int tolua_Cocos2d_ScriptHandlerMgr_unregisterScriptHandler00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) ||
!tolua_isusertype(tolua_S, 2, "Object", 0, &tolua_err) ||
!tolua_isnumber(tolua_S, 3, 0, &tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err) )
goto tolua_lerror;
else
#endif
{
cocos2d::ScriptHandlerMgr* scriptHanlderMgr = static_cast<cocos2d::ScriptHandlerMgr*>(tolua_tousertype(tolua_S,1,0));
#ifndef TOLUA_RELEASE
if (nullptr == scriptHanlderMgr)
{
tolua_error(tolua_S,"invalid 'scriptHanlderMgr' in function 'tolua_Cocos2d_ScriptHandlerMgr_unregisterScriptHandler00'\n", NULL);
return 0;
}
#endif
ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType)tolua_tonumber(tolua_S, 3, 0);
scriptHanlderMgr->removeObjectHandler(tolua_tousertype(tolua_S, 2, 0), handlerType);
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'unregisterScriptHandler'.",&tolua_err);
return 0;
#endif
}
/* method: removeObjectAllHandlers of class ScriptHandlerMgr */
static int tolua_Cocos2d_ScriptHandlerMgr_removeObjectAllHandlers00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) ||
!tolua_isusertype(tolua_S, 2, "Object", 0, &tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err) )
goto tolua_lerror;
else
#endif
{
cocos2d::ScriptHandlerMgr* scriptHanlderMgr = static_cast<cocos2d::ScriptHandlerMgr*>(tolua_tousertype(tolua_S,1,0));
#ifndef TOLUA_RELEASE
if (nullptr == scriptHanlderMgr)
{
tolua_error(tolua_S,"invalid 'scriptHanlderMgr' in function 'tolua_Cocos2d_ScriptHandlerMgr_removeObjectAllHandlers00'\n", NULL);
return 0;
}
#endif
scriptHanlderMgr->removeObjectAllHandlers(tolua_tousertype(tolua_S, 2, 0));
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'removeObjectAllHandlers'.",&tolua_err);
return 0;
#endif
}
TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S)
{
@ -253,6 +349,9 @@ TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S)
tolua_cclass(tolua_S,"ScriptHandlerMgr","ScriptHandlerMgr","",NULL);
tolua_beginmodule(tolua_S, "ScriptHandlerMgr");
tolua_function(tolua_S, "getInstance", tolua_Cocos2d_ScriptHandlerMgr_getInstance00);
tolua_function(tolua_S, "registerScriptHandler", tolua_Cocos2d_ScriptHandlerMgr_registerScriptHandler00);
tolua_function(tolua_S, "unregisterScriptHandler", tolua_Cocos2d_ScriptHandlerMgr_unregisterScriptHandler00);
tolua_function(tolua_S, "removeObjectAllHandlers", tolua_Cocos2d_ScriptHandlerMgr_removeObjectAllHandlers00);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);
return 1;

View File

@ -134,9 +134,6 @@ private:
NS_CC_END
TOLUA_API int tolua_Cocos2d_GLNode_registerScriptDrawHandler00(lua_State* tolua_S);
TOLUA_API int tolua_Cocos2d_GLNode_unregisterScriptDrawHandler00(lua_State* tolua_S);
TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S);
#endif //__LUA_SCRIPT_HANDLER_MGR_H__

View File

@ -288,4 +288,42 @@ cc.ASSETSMANAGER_UNCOMPRESS = 3
cc.ASSETSMANAGER_PROTOCOL_PROGRESS = 0
cc.ASSETSMANAGER_PROTOCOL_SUCCESS = 1
cc.ASSETSMANAGER_PROTOCOL_ERROR = 2
cc.HANDLERTYPE_NODE = 0
cc.HANDLERTYPE_MENU_CLICKED = 1
cc.HANDLERTYPE_NOTIFICATION = 2
cc.HANDLERTYPE_CALLFUNC = 3
cc.HANDLERTYPE_SCHEDULE = 4
cc.HANDLERTYPE_TOUCHES = 5
cc.HANDLERTYPE_KEYPAD = 6
cc.HANDLERTYPE_ACCELEROMETER = 7
cc.HANDLERTYPE_CONTROL_TOUCH_DOWN = 8
cc.HANDLERTYPE_CONTROL_TOUCH_DRAG_INSIDE = 9
cc.HANDLERTYPE_CONTROL_TOUCH_DRAG_OUTSIDE = 10
cc.HANDLERTYPE_CONTROL_TOUCH_DRAG_ENTER = 11
cc.HANDLERTYPE_CONTROL_TOUCH_DRAG_EXIT = 12
cc.HANDLERTYPE_CONTROL_TOUCH_UP_INSIDE = 13
cc.HANDLERTYPE_CONTROL_TOUCH_UP_OUTSIDE = 14
cc.HANDLERTYPE_CONTROL_TOUCH_UP_CANCEL = 15
cc.HANDLERTYPE_CONTROL_VALUE_CHANGED = 16
cc.HANDLERTYPE_WEBSOCKET_OPEN = 17
cc.HANDLERTYPE_WEBSOCKET_MESSAGE = 18
cc.HANDLERTYPE_WEBSOCKET_CLOSE = 19
cc.HANDLERTYPE_WEBSOCKET_ERROR = 20
cc.HANDLERTYPE_GL_NODE_DRAW = 21
cc.HANDLERTYPE_SCROLLVIEW_SCROLL = 22
cc.HANDLERTYPE_SCROLLVIEW_ZOOM = 23
cc.HANDLERTYPE_TABLECELL_TOUCHED = 24
cc.HANDLERTYPE_TABLECELL_HIGHLIGHT = 25
cc.HANDLERTYPE_TABLECELL_UNHIGHLIGHT = 26
cc.HANDLERTYPE_TABLECELL_WILL_RECYCLE = 27
cc.HANDLERTYPE_TABLECELL_SIZE_FOR_INDEX = 28
cc.HANDLERTYPE_TABLECELL_AT_INDEX = 29
cc.HANDLERTYPE_TABLEVIEW_NUMS_OF_CELLS = 30
cc.HANDLERTYPE_XMLHTTPREQUEST_READY_STATE_CHANGE = 31
cc.HANDLERTYPE_ASSETSMANAGER_PROGRESS = 32
cc.HANDLERTYPE_ASSETSMANAGER_SUCCESS = 33
cc.HANDLERTYPE_ASSETSMANAGER_ERROR = 34
cc.HANDLERTYPE_EVENT_LISTENER = 35
cc.HANDLERTYPE_ARMATURE_EVENT = 36

View File

@ -207,7 +207,7 @@ void Control::removeTargetWithActionForControlEvent(Object* target, Handler acti
// Remove the corresponding invocation object
if (shouldBeRemoved)
{
eventInvocationList.erase(invocation, bDeleteObjects);
eventInvocationList.eraseObject(invocation, bDeleteObjects);
}
});
}

View File

@ -51,7 +51,7 @@ bool TableView::initWithViewSize(Size size, Node* container/* = NULL*/)
{
if (ScrollView::initWithViewSize(size,container))
{
_indices = new std::set<long>();
_indices = new std::set<ssize_t>();
_vordering = VerticalFillOrder::BOTTOM_UP;
this->setDirection(Direction::VERTICAL);
@ -123,7 +123,7 @@ void TableView::reloadData()
}
}
TableViewCell *TableView::cellAtIndex(long idx)
TableViewCell *TableView::cellAtIndex(ssize_t idx)
{
if (_indices->find(idx) != _indices->end())
{
@ -139,7 +139,7 @@ TableViewCell *TableView::cellAtIndex(long idx)
return nullptr;
}
void TableView::updateCellAtIndex(long idx)
void TableView::updateCellAtIndex(ssize_t idx)
{
if (idx == CC_INVALID_INDEX)
{
@ -161,7 +161,7 @@ void TableView::updateCellAtIndex(long idx)
this->_addCellIfNecessary(cell);
}
void TableView::insertCellAtIndex(long idx)
void TableView::insertCellAtIndex(ssize_t idx)
{
if (idx == CC_INVALID_INDEX)
{
@ -197,7 +197,7 @@ void TableView::insertCellAtIndex(long idx)
this->_updateContentSize();
}
void TableView::removeCellAtIndex(long idx)
void TableView::removeCellAtIndex(ssize_t idx)
{
if (idx == CC_INVALID_INDEX)
{
@ -210,7 +210,7 @@ void TableView::removeCellAtIndex(long idx)
return;
}
unsigned int newIdx = 0;
ssize_t newIdx = 0;
TableViewCell* cell = this->cellAtIndex(idx);
if (!cell)
@ -226,7 +226,7 @@ void TableView::removeCellAtIndex(long idx)
_indices->erase(idx);
this->_updateCellPositions();
for (int i = _cellsUsed.size()-1; i > newIdx; i--)
for (ssize_t i = _cellsUsed.size()-1; i > newIdx; i--)
{
cell = _cellsUsed.at(i);
this->_setIndexForCell(cell->getIdx()-1, cell);
@ -262,7 +262,7 @@ void TableView::_addCellIfNecessary(TableViewCell * cell)
void TableView::_updateContentSize()
{
Size size = Size::ZERO;
unsigned int cellsCount = _dataSource->numberOfCellsInTableView(this);
ssize_t cellsCount = _dataSource->numberOfCellsInTableView(this);
if (cellsCount > 0)
{
@ -296,7 +296,7 @@ void TableView::_updateContentSize()
}
Point TableView::_offsetFromIndex(long index)
Point TableView::_offsetFromIndex(ssize_t index)
{
Point offset = this->__offsetFromIndex(index);
@ -308,7 +308,7 @@ Point TableView::_offsetFromIndex(long index)
return offset;
}
Point TableView::__offsetFromIndex(long index)
Point TableView::__offsetFromIndex(ssize_t index)
{
Point offset;
Size cellSize;
@ -397,7 +397,7 @@ void TableView::_moveCellOutOfSight(TableViewCell *cell)
}
_cellsFreed.pushBack(cell);
_cellsUsed.erase(cell);
_cellsUsed.eraseObject(cell);
_isUsedCellsDirty = true;
_indices->erase(cell->getIdx());
@ -409,7 +409,7 @@ void TableView::_moveCellOutOfSight(TableViewCell *cell)
}
}
void TableView::_setIndexForCell(long index, TableViewCell *cell)
void TableView::_setIndexForCell(ssize_t index, TableViewCell *cell)
{
cell->setAnchorPoint(Point(0.0f, 0.0f));
cell->setPosition(this->_offsetFromIndex(index));
@ -464,7 +464,7 @@ void TableView::scrollViewDidScroll(ScrollView* view)
_tableViewDelegate->scrollViewDidScroll(this);
}
long startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0;
ssize_t startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0;
Point offset = this->getContentOffset() * -1;
maxIdx = MAX(countOfItems-1, 0);

View File

@ -105,7 +105,7 @@ public:
* @param idx the index of a cell to get a size
* @return size of a cell at given index
*/
virtual Size tableCellSizeForIndex(TableView *table, long idx) {
virtual Size tableCellSizeForIndex(TableView *table, ssize_t idx) {
return cellSizeForTable(table);
};
/**
@ -123,7 +123,7 @@ public:
* @param idx index to search for a cell
* @return cell found at idx
*/
virtual TableViewCell* tableCellAtIndex(TableView *table, long idx) = 0;
virtual TableViewCell* tableCellAtIndex(TableView *table, ssize_t idx) = 0;
/**
* Returns number of cells in a given table view.
*
@ -228,19 +228,19 @@ public:
*
* @param idx index to find a cell
*/
void updateCellAtIndex(long idx);
void updateCellAtIndex(ssize_t idx);
/**
* Inserts a new cell at a given index
*
* @param idx location to insert
*/
void insertCellAtIndex(long idx);
void insertCellAtIndex(ssize_t idx);
/**
* Removes a cell at a given index
*
* @param idx index to find a cell
*/
void removeCellAtIndex(long idx);
void removeCellAtIndex(ssize_t idx);
/**
* reloads data from data source. the view will be refreshed.
*/
@ -258,7 +258,7 @@ public:
* @param idx index
* @return a cell at a given index
*/
TableViewCell *cellAtIndex(long idx);
TableViewCell *cellAtIndex(ssize_t idx);
// Overrides
virtual void scrollViewDidScroll(ScrollView* view) override;
@ -271,11 +271,11 @@ public:
protected:
long __indexFromOffset(Point offset);
long _indexFromOffset(Point offset);
Point __offsetFromIndex(long index);
Point _offsetFromIndex(long index);
Point __offsetFromIndex(ssize_t index);
Point _offsetFromIndex(ssize_t index);
void _moveCellOutOfSight(TableViewCell *cell);
void _setIndexForCell(long index, TableViewCell *cell);
void _setIndexForCell(ssize_t index, TableViewCell *cell);
void _addCellIfNecessary(TableViewCell * cell);
void _updateCellPositions();
@ -290,7 +290,7 @@ protected:
/**
* index set to query the indexes of the cells used.
*/
std::set<long>* _indices;
std::set<ssize_t>* _indices;
/**
* vector with all cell positions

View File

@ -116,7 +116,7 @@ std::string valueToQuotedString( const char *value )
// We have to walk value and escape any special characters.
// Appending to std::string is not efficient, but this should be rare.
// (Note: forward slashes are *not* rare, but I am not escaping them.)
unsigned maxsize = strlen(value)*2 + 3; // allescaped+quotes+NULL
size_t maxsize = strlen(value)*2 + 3; // allescaped+quotes+NULL
std::string result;
result.reserve(maxsize); // to avoid lots of mallocs
result += "\"";