mirror of https://github.com/axmolengine/axmol.git
issue #2050: unsigned int to int
This commit is contained in:
parent
524f2867d8
commit
19e1609c27
|
@ -61,7 +61,7 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
|
|||
texture = Director::getInstance()->getTextureCache()->addImage(tilesetInfo->_sourceImage.c_str());
|
||||
}
|
||||
|
||||
if (SpriteBatchNode::initWithTexture(texture, (unsigned int)capacity))
|
||||
if (SpriteBatchNode::initWithTexture(texture, static_cast<ssize_t>(capacity)))
|
||||
{
|
||||
// layerInfo
|
||||
_layerName = layerInfo->_name;
|
||||
|
@ -85,7 +85,7 @@ bool TMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *la
|
|||
Point offset = this->calculateLayerOffset(layerInfo->_offset);
|
||||
this->setPosition(CC_POINT_PIXELS_TO_POINTS(offset));
|
||||
|
||||
_atlasIndexArray = ccCArrayNew((unsigned int)totalNumberOfTiles);
|
||||
_atlasIndexArray = ccCArrayNew(totalNumberOfTiles);
|
||||
|
||||
this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(Size(_layerSize.width * _mapTileSize.width, _layerSize.height * _mapTileSize.height)));
|
||||
|
||||
|
@ -161,12 +161,12 @@ void TMXLayer::setupTiles()
|
|||
// Parse cocos2d properties
|
||||
this->parseInternalProperties();
|
||||
|
||||
for (unsigned int y=0; y < _layerSize.height; y++)
|
||||
for (int y=0; y < _layerSize.height; y++)
|
||||
{
|
||||
for (unsigned int x=0; x < _layerSize.width; x++)
|
||||
for (int x=0; x < _layerSize.width; x++)
|
||||
{
|
||||
unsigned int pos = (unsigned int)(x + _layerSize.width * y);
|
||||
unsigned int gid = _tiles[ pos ];
|
||||
int pos = (int)(x + _layerSize.width * y);
|
||||
int gid = _tiles[ pos ];
|
||||
|
||||
// gid are stored in little endian.
|
||||
// if host is big endian, then swap
|
||||
|
@ -231,7 +231,7 @@ void TMXLayer::parseInternalProperties()
|
|||
}
|
||||
}
|
||||
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, Point pos, unsigned int gid)
|
||||
void TMXLayer::setupTileSprite(Sprite* sprite, Point pos, int gid)
|
||||
{
|
||||
sprite->setPosition(getPositionAt(pos));
|
||||
sprite->setVertexZ((float)getVertexZForPos(pos));
|
||||
|
@ -252,7 +252,7 @@ void TMXLayer::setupTileSprite(Sprite* sprite, Point pos, unsigned int gid)
|
|||
sprite->setPosition(Point(getPositionAt(pos).x + sprite->getContentSize().height/2,
|
||||
getPositionAt(pos).y + sprite->getContentSize().width/2 ) );
|
||||
|
||||
unsigned int flag = gid & (kTMXTileHorizontalFlag | kTMXTileVerticalFlag );
|
||||
int flag = gid & (kTMXTileHorizontalFlag | kTMXTileVerticalFlag );
|
||||
|
||||
// handle the 4 diagonally flipped states.
|
||||
if (flag == kTMXTileHorizontalFlag)
|
||||
|
@ -319,7 +319,7 @@ Sprite * TMXLayer::getTileAt(const Point& pos)
|
|||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
|
||||
Sprite *tile = nullptr;
|
||||
unsigned int gid = this->getTileGIDAt(pos);
|
||||
int gid = this->getTileGIDAt(pos);
|
||||
|
||||
// if GID == 0, then no tile is present
|
||||
if (gid)
|
||||
|
@ -348,14 +348,14 @@ Sprite * TMXLayer::getTileAt(const Point& pos)
|
|||
return tile;
|
||||
}
|
||||
|
||||
unsigned int TMXLayer::getTileGIDAt(const Point& pos, ccTMXTileFlags* flags/* = nullptr*/)
|
||||
int TMXLayer::getTileGIDAt(const Point& pos, ccTMXTileFlags* flags/* = nullptr*/)
|
||||
{
|
||||
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
|
||||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
|
||||
int idx = (int)(pos.x + pos.y * _layerSize.width);
|
||||
int idx = static_cast<int>((pos.x + pos.y * _layerSize.width));
|
||||
// Bits on the far end of the 32-bit global tile ID are used for tile flags
|
||||
unsigned int tile = _tiles[idx];
|
||||
int tile = _tiles[idx];
|
||||
|
||||
// issue1264, flipped tiles can be changed dynamically
|
||||
if (flags)
|
||||
|
@ -367,7 +367,7 @@ unsigned int TMXLayer::getTileGIDAt(const Point& pos, ccTMXTileFlags* flags/* =
|
|||
}
|
||||
|
||||
// TMXLayer - adding helper methods
|
||||
Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
||||
Sprite * TMXLayer::insertTileForGID(int gid, const Point& pos)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = CC_RECT_PIXELS_TO_POINTS(rect);
|
||||
|
@ -405,7 +405,7 @@ Sprite * TMXLayer::insertTileForGID(unsigned int gid, const Point& pos)
|
|||
return tile;
|
||||
}
|
||||
|
||||
Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
||||
Sprite * TMXLayer::updateTileForGID(int gid, const Point& pos)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = Rect(rect.origin.x / _contentScaleFactor, rect.origin.y / _contentScaleFactor, rect.size.width/ _contentScaleFactor, rect.size.height/ _contentScaleFactor);
|
||||
|
@ -427,7 +427,7 @@ Sprite * TMXLayer::updateTileForGID(unsigned int gid, const Point& pos)
|
|||
|
||||
// used only when parsing the map. useless after the map was parsed
|
||||
// since lot's of assumptions are no longer true
|
||||
Sprite * TMXLayer::appendTileForGID(unsigned int gid, const Point& pos)
|
||||
Sprite * TMXLayer::appendTileForGID(int gid, const Point& pos)
|
||||
{
|
||||
Rect rect = _tileSet->rectForGID(gid);
|
||||
rect = CC_RECT_PIXELS_TO_POINTS(rect);
|
||||
|
@ -458,7 +458,7 @@ static inline int compareInts(const void * a, const void * b)
|
|||
return ((*(int*)a) - (*(int*)b));
|
||||
}
|
||||
|
||||
ssize_t TMXLayer::atlasIndexForExistantZ(unsigned int z)
|
||||
ssize_t TMXLayer::atlasIndexForExistantZ(int z)
|
||||
{
|
||||
int key=z;
|
||||
int *item = (int*)bsearch((void*)&key, (void*)&_atlasIndexArray->arr[0], _atlasIndexArray->num, sizeof(void*), compareInts);
|
||||
|
@ -486,23 +486,23 @@ ssize_t TMXLayer::atlasIndexForNewZ(int z)
|
|||
}
|
||||
|
||||
// TMXLayer - adding / remove tiles
|
||||
void TMXLayer::setTileGID(unsigned int gid, const Point& pos)
|
||||
void TMXLayer::setTileGID(int gid, const Point& pos)
|
||||
{
|
||||
setTileGID(gid, pos, (ccTMXTileFlags)0);
|
||||
}
|
||||
|
||||
void TMXLayer::setTileGID(unsigned int gid, const Point& pos, ccTMXTileFlags flags)
|
||||
void TMXLayer::setTileGID(int gid, const Point& pos, ccTMXTileFlags flags)
|
||||
{
|
||||
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
|
||||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
CCASSERT(gid == 0 || gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" );
|
||||
|
||||
ccTMXTileFlags currentFlags;
|
||||
unsigned int currentGID = getTileGIDAt(pos, ¤tFlags);
|
||||
int currentGID = getTileGIDAt(pos, ¤tFlags);
|
||||
|
||||
if (currentGID != gid || currentFlags != flags)
|
||||
{
|
||||
unsigned gidAndFlags = gid | flags;
|
||||
int gidAndFlags = gid | flags;
|
||||
|
||||
// setting gid=0 is equal to remove the tile
|
||||
if (gid == 0)
|
||||
|
@ -517,7 +517,7 @@ void TMXLayer::setTileGID(unsigned int gid, const Point& pos, ccTMXTileFlags fla
|
|||
// modifying an existing tile with a non-empty tile
|
||||
else
|
||||
{
|
||||
unsigned int z = (unsigned int)(pos.x + pos.y * _layerSize.width);
|
||||
int z = pos.x + pos.y * _layerSize.width;
|
||||
Sprite *sprite = static_cast<Sprite*>(getChildByTag(z));
|
||||
if (sprite)
|
||||
{
|
||||
|
@ -570,11 +570,11 @@ void TMXLayer::removeTileAt(const Point& pos)
|
|||
CCASSERT(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, "TMXLayer: invalid position");
|
||||
CCASSERT(_tiles && _atlasIndexArray, "TMXLayer: the tiles map has been released");
|
||||
|
||||
unsigned int gid = getTileGIDAt(pos);
|
||||
int gid = getTileGIDAt(pos);
|
||||
|
||||
if (gid)
|
||||
{
|
||||
unsigned int z = (unsigned int)(pos.x + pos.y * _layerSize.width);
|
||||
int z = pos.x + pos.y * _layerSize.width;
|
||||
ssize_t atlasIndex = atlasIndexForExistantZ(z);
|
||||
|
||||
// remove tile from GID map
|
||||
|
@ -676,17 +676,17 @@ Point TMXLayer::getPositionForHexAt(const Point& pos)
|
|||
int TMXLayer::getVertexZForPos(const Point& pos)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int maxVal = 0;
|
||||
int maxVal = 0;
|
||||
if (_useAutomaticVertexZ)
|
||||
{
|
||||
switch (_layerOrientation)
|
||||
{
|
||||
case TMXOrientationIso:
|
||||
maxVal = (unsigned int)(_layerSize.width + _layerSize.height);
|
||||
ret = (int)(-(maxVal - (pos.x + pos.y)));
|
||||
maxVal = static_cast<int>(_layerSize.width + _layerSize.height);
|
||||
ret = static_cast<int>(-(maxVal - (pos.x + pos.y)));
|
||||
break;
|
||||
case TMXOrientationOrtho:
|
||||
ret = (int)(-(_layerSize.height-pos.y));
|
||||
ret = static_cast<int>(-(_layerSize.height-pos.y));
|
||||
break;
|
||||
case TMXOrientationHex:
|
||||
CCASSERT(0, "TMX Hexa zOrder not supported");
|
||||
|
|
|
@ -109,8 +109,8 @@ public:
|
|||
/** returns the tile gid at a given tile coordinate. It also returns the tile flags.
|
||||
This method requires the the tile map has not been previously released (eg. don't call [layer releaseMap])
|
||||
*/
|
||||
unsigned int getTileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr);
|
||||
CC_DEPRECATED_ATTRIBUTE unsigned int tileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr){
|
||||
int getTileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr);
|
||||
CC_DEPRECATED_ATTRIBUTE int tileGIDAt(const Point& tileCoordinate, ccTMXTileFlags* flags = nullptr){
|
||||
return getTileGIDAt(tileCoordinate, flags);
|
||||
};
|
||||
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1.
|
||||
If a tile is already placed at that position, then it will be removed.
|
||||
*/
|
||||
void setTileGID(unsigned int gid, const Point& tileCoordinate);
|
||||
void setTileGID(int gid, const Point& tileCoordinate);
|
||||
|
||||
/** sets the tile gid (gid = tile global id) at a given tile coordinate.
|
||||
The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1.
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
Use withFlags if the tile flags need to be changed as well
|
||||
*/
|
||||
|
||||
void setTileGID(unsigned int gid, const Point& tileCoordinate, ccTMXTileFlags flags);
|
||||
void setTileGID(int gid, const Point& tileCoordinate, ccTMXTileFlags flags);
|
||||
|
||||
/** removes a tile at given tile coordinate */
|
||||
void removeTileAt(const Point& tileCoordinate);
|
||||
|
@ -158,8 +158,8 @@ public:
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
inline unsigned int* getTiles() const { return _tiles; };
|
||||
inline void setTiles(unsigned int* tiles) { _tiles = tiles; };
|
||||
inline int* getTiles() const { return _tiles; };
|
||||
inline void setTiles(int* tiles) { _tiles = tiles; };
|
||||
|
||||
/** Tileset information for the layer */
|
||||
inline TMXTilesetInfo* getTileSet() const { return _tileSet; };
|
||||
|
@ -170,8 +170,8 @@ public:
|
|||
};
|
||||
|
||||
/** Layer orientation, which is the same as the map orientation */
|
||||
inline unsigned int getLayerOrientation() const { return _layerOrientation; };
|
||||
inline void setLayerOrientation(unsigned int orientation) { _layerOrientation = orientation; };
|
||||
inline int getLayerOrientation() const { return _layerOrientation; };
|
||||
inline void setLayerOrientation(int orientation) { _layerOrientation = orientation; };
|
||||
|
||||
/** properties from the layer. They can be added using Tiled */
|
||||
inline const ValueMap& getProperties() const { return _properties; };
|
||||
|
@ -198,18 +198,18 @@ private:
|
|||
Point calculateLayerOffset(const Point& offset);
|
||||
|
||||
/* optimization methods */
|
||||
Sprite* appendTileForGID(unsigned int gid, const Point& pos);
|
||||
Sprite* insertTileForGID(unsigned int gid, const Point& pos);
|
||||
Sprite* updateTileForGID(unsigned int gid, const Point& pos);
|
||||
Sprite* appendTileForGID(int gid, const Point& pos);
|
||||
Sprite* insertTileForGID(int gid, const Point& pos);
|
||||
Sprite* updateTileForGID(int gid, const Point& pos);
|
||||
|
||||
/* The layer recognizes some special properties, like cc_vertez */
|
||||
void parseInternalProperties();
|
||||
void setupTileSprite(Sprite* sprite, Point pos, unsigned int gid);
|
||||
void setupTileSprite(Sprite* sprite, Point pos, int gid);
|
||||
Sprite* reusedTileWithRect(Rect rect);
|
||||
int getVertexZForPos(const Point& pos);
|
||||
|
||||
// index
|
||||
ssize_t atlasIndexForExistantZ(unsigned int z);
|
||||
ssize_t atlasIndexForExistantZ(int z);
|
||||
ssize_t atlasIndexForNewZ(int z);
|
||||
|
||||
protected:
|
||||
|
@ -218,8 +218,8 @@ protected:
|
|||
//! TMX Layer supports opacity
|
||||
unsigned char _opacity;
|
||||
|
||||
unsigned int _minGID;
|
||||
unsigned int _maxGID;
|
||||
int _minGID;
|
||||
int _maxGID;
|
||||
|
||||
//! Only used when vertexZ is used
|
||||
int _vertexZvalue;
|
||||
|
@ -237,11 +237,11 @@ protected:
|
|||
/** size of the map's tile (could be different from the tile's size) */
|
||||
Size _mapTileSize;
|
||||
/** pointer to the map of tiles */
|
||||
unsigned int* _tiles;
|
||||
int* _tiles;
|
||||
/** Tileset information for the layer */
|
||||
TMXTilesetInfo* _tileSet;
|
||||
/** Layer orientation, which is the same as the map orientation */
|
||||
unsigned int _layerOrientation;
|
||||
int _layerOrientation;
|
||||
/** properties from the layer. They can be added using Tiled */
|
||||
ValueMap _properties;
|
||||
};
|
||||
|
|
|
@ -83,7 +83,7 @@ TMXTilesetInfo::~TMXTilesetInfo()
|
|||
CCLOGINFO("deallocing TMXTilesetInfo: %p", this);
|
||||
}
|
||||
|
||||
Rect TMXTilesetInfo::rectForGID(unsigned int gid)
|
||||
Rect TMXTilesetInfo::rectForGID(int gid)
|
||||
{
|
||||
Rect rect;
|
||||
rect.size = _tileSize;
|
||||
|
@ -265,7 +265,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
}
|
||||
externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename.c_str());
|
||||
|
||||
_currentFirstGID = (unsigned int)attributeDict["firstgid"].asInt();
|
||||
_currentFirstGID = attributeDict["firstgid"].asInt();
|
||||
|
||||
tmxMapInfo->parseXMLFile(externalTilesetFilename.c_str());
|
||||
}
|
||||
|
@ -275,15 +275,15 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
tileset->_name = attributeDict["name"].asString();
|
||||
if (_currentFirstGID == 0)
|
||||
{
|
||||
tileset->_firstGid = (unsigned int)attributeDict["firstgid"].asInt();
|
||||
tileset->_firstGid = attributeDict["firstgid"].asInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
tileset->_firstGid = _currentFirstGID;
|
||||
_currentFirstGID = 0;
|
||||
}
|
||||
tileset->_spacing = (unsigned int)attributeDict["spacing"].asInt();
|
||||
tileset->_margin = (unsigned int)attributeDict["margin"].asInt();
|
||||
tileset->_spacing = attributeDict["spacing"].asInt();
|
||||
tileset->_margin = attributeDict["margin"].asInt();
|
||||
Size s;
|
||||
s.width = attributeDict["tilewidth"].asFloat();
|
||||
s.height = attributeDict["tileheight"].asFloat();
|
||||
|
@ -299,7 +299,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
{
|
||||
TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
|
||||
Size layerSize = layer->_layerSize;
|
||||
unsigned int gid = (unsigned int)attributeDict["gid"].asInt();
|
||||
int gid = attributeDict["gid"].asInt();
|
||||
int tilesAmount = layerSize.width*layerSize.height;
|
||||
|
||||
do
|
||||
|
@ -435,7 +435,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
|||
tiles[tilesAmount - 1] = tilesAmount - 1;
|
||||
}
|
||||
|
||||
layer->_tiles = (unsigned int*) tiles;
|
||||
layer->_tiles = tiles;
|
||||
}
|
||||
else if (encoding == "base64")
|
||||
{
|
||||
|
@ -678,11 +678,11 @@ void TMXMapInfo::endElement(void *ctx, const char *name)
|
|||
return;
|
||||
}
|
||||
|
||||
layer->_tiles = (unsigned int*) deflated;
|
||||
layer->_tiles = reinterpret_cast<int*>(deflated);
|
||||
}
|
||||
else
|
||||
{
|
||||
layer->_tiles = (unsigned int*) buffer;
|
||||
layer->_tiles = reinterpret_cast<int*>(buffer);
|
||||
}
|
||||
|
||||
tmxMapInfo->setCurrentString("");
|
||||
|
|
|
@ -107,12 +107,12 @@ public:
|
|||
ValueMap _properties;
|
||||
std::string _name;
|
||||
Size _layerSize;
|
||||
unsigned int *_tiles;
|
||||
int *_tiles;
|
||||
bool _visible;
|
||||
unsigned char _opacity;
|
||||
bool _ownTiles;
|
||||
unsigned int _minGID;
|
||||
unsigned int _maxGID;
|
||||
int _minGID;
|
||||
int _maxGID;
|
||||
Point _offset;
|
||||
};
|
||||
|
||||
|
@ -130,14 +130,14 @@ class CC_DLL TMXTilesetInfo : public Object
|
|||
{
|
||||
public:
|
||||
std::string _name;
|
||||
unsigned int _firstGid;
|
||||
Size _tileSize;
|
||||
unsigned int _spacing;
|
||||
unsigned int _margin;
|
||||
int _firstGid;
|
||||
Size _tileSize;
|
||||
int _spacing;
|
||||
int _margin;
|
||||
//! filename containing the tiles (should be spritesheet / texture atlas)
|
||||
std::string _sourceImage;
|
||||
//! size in pixels of the image
|
||||
Size _imageSize;
|
||||
Size _imageSize;
|
||||
public:
|
||||
/**
|
||||
* @js ctor
|
||||
|
@ -148,7 +148,7 @@ public:
|
|||
* @lua NA
|
||||
*/
|
||||
virtual ~TMXTilesetInfo();
|
||||
Rect rectForGID(unsigned int gid);
|
||||
Rect rectForGID(int gid);
|
||||
};
|
||||
|
||||
/** @brief TMXMapInfo contains the information about the map like:
|
||||
|
@ -238,8 +238,8 @@ public:
|
|||
inline void setParentElement(int element) { _parentElement = element; };
|
||||
|
||||
/// parent GID
|
||||
inline unsigned int getParentGID() const { return _parentGID; };
|
||||
inline void setParentGID(unsigned int gid) { _parentGID = gid; };
|
||||
inline int getParentGID() const { return _parentGID; };
|
||||
inline void setParentGID(int gid) { _parentGID = gid; };
|
||||
|
||||
/// layer attribs
|
||||
inline int getLayerAttribs() const { return _layerAttribs; };
|
||||
|
@ -296,7 +296,7 @@ protected:
|
|||
/// parent element
|
||||
int _parentElement;
|
||||
/// parent GID
|
||||
unsigned int _parentGID;
|
||||
int _parentGID;
|
||||
/// layer attribs
|
||||
int _layerAttribs;
|
||||
/// is storing characters?
|
||||
|
@ -312,7 +312,7 @@ protected:
|
|||
std::string _currentString;
|
||||
//! tile properties
|
||||
IntValueMap _tileProperties;
|
||||
unsigned int _currentFirstGID;
|
||||
int _currentFirstGID;
|
||||
};
|
||||
|
||||
// end of tilemap_parallax_nodes group
|
||||
|
|
Loading…
Reference in New Issue