From cb215bc931d33b40eee2cd6147a714efae350eea Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 29 Nov 2013 11:36:42 +0800 Subject: [PATCH] issue #2790: Vector replaces Array* finished. --- cocos/2d/CCActionInterval.cpp | 2 +- cocos/2d/CCLayer.cpp | 54 +++++++++------------- cocos/2d/CCLayer.h | 50 +++++++++++--------- cocos/2d/CCMenu.cpp | 2 +- cocos/2d/CCTMXTiledMap.cpp | 76 +++++++++++++------------------ cocos/2d/CCTMXTiledMap.h | 9 ++-- cocos/2d/CCTMXXMLParser.cpp | 61 ++++++++++--------------- cocos/2d/CCTMXXMLParser.h | 30 ++++++------ cocos/2d/platform/CCSAXParser.cpp | 2 +- cocos/2d/platform/CCSAXParser.h | 2 +- cocos/base/CCVector.h | 4 +- 11 files changed, 129 insertions(+), 163 deletions(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index 649fa09d51..936c94823a 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -2129,7 +2129,7 @@ Animate* Animate::reverse() const if (oldArray.count() > 0) { - for (auto iter = oldArray.rcbegin(); iter != oldArray.rcend(); ++iter) + for (auto iter = oldArray.crbegin(); iter != oldArray.crend(); ++iter) { AnimationFrame* animFrame = *iter; if (!animFrame) diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index c7c7c6d20d..bd04800a57 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -916,19 +916,14 @@ void LayerGradient::setCompressedInterpolation(bool compress) LayerMultiplex::LayerMultiplex() : _enabledLayer(0) -, _layers(NULL) { } + LayerMultiplex::~LayerMultiplex() { - if (_layers) - { - for (auto& item : *_layers) - { - static_cast(item)->cleanup(); - } - _layers->release(); - } + _layers.forEach([](Layer* layer){ + layer->cleanup(); + }); } LayerMultiplex * LayerMultiplex::create(Layer * layer, ...) @@ -967,7 +962,7 @@ LayerMultiplex* LayerMultiplex::create() return pRet; } -LayerMultiplex* LayerMultiplex::createWithArray(Array* arrayOfLayers) +LayerMultiplex* LayerMultiplex::createWithArray(const Vector& arrayOfLayers) { LayerMultiplex* pRet = new LayerMultiplex(); if (pRet && pRet->initWithArray(arrayOfLayers)) @@ -983,17 +978,13 @@ LayerMultiplex* LayerMultiplex::createWithArray(Array* arrayOfLayers) void LayerMultiplex::addLayer(Layer* layer) { - CCASSERT(_layers, ""); - _layers->addObject(layer); + _layers.addObject(layer); } bool LayerMultiplex::init() { if (Layer::init()) { - _layers = Array::create(); - _layers->retain(); - _enabledLayer = 0; return true; } @@ -1004,34 +995,32 @@ bool LayerMultiplex::initWithLayers(Layer *layer, va_list params) { if (Layer::init()) { - _layers = Array::createWithCapacity(5); - _layers->retain(); - _layers->addObject(layer); + _layers.setCapacity(5); + _layers.addObject(layer); Layer *l = va_arg(params,Layer*); while( l ) { - _layers->addObject(l); + _layers.addObject(l); l = va_arg(params,Layer*); } _enabledLayer = 0; - this->addChild((Node*)_layers->getObjectAtIndex(_enabledLayer)); + this->addChild(_layers[_enabledLayer]); return true; } return false; } -bool LayerMultiplex::initWithArray(Array* arrayOfLayers) +bool LayerMultiplex::initWithArray(const Vector& arrayOfLayers) { if (Layer::init()) { - _layers = Array::createWithCapacity(arrayOfLayers->count()); - _layers->addObjectsFromArray(arrayOfLayers); - _layers->retain(); + _layers.setCapacity(arrayOfLayers.count()); + _layers.addObjectsFromArray(arrayOfLayers); _enabledLayer = 0; - this->addChild((Node*)_layers->getObjectAtIndex(_enabledLayer)); + this->addChild(_layers[_enabledLayer]); return true; } return false; @@ -1039,27 +1028,26 @@ bool LayerMultiplex::initWithArray(Array* arrayOfLayers) void LayerMultiplex::switchTo(int n) { - CCASSERT( n < _layers->count(), "Invalid index in MultiplexLayer switchTo message" ); + CCASSERT( n < _layers.count(), "Invalid index in MultiplexLayer switchTo message" ); - this->removeChild((Node*)_layers->getObjectAtIndex(_enabledLayer), true); + this->removeChild(_layers[_enabledLayer], true); _enabledLayer = n; - this->addChild((Node*)_layers->getObjectAtIndex(n)); + this->addChild(_layers[n]); } void LayerMultiplex::switchToAndReleaseMe(int n) { - CCASSERT( n < _layers->count(), "Invalid index in MultiplexLayer switchTo message" ); + CCASSERT( n < _layers.count(), "Invalid index in MultiplexLayer switchTo message" ); - this->removeChild((Node*)_layers->getObjectAtIndex(_enabledLayer), true); + this->removeChild(_layers[_enabledLayer], true); - //[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]]; - _layers->replaceObjectAtIndex(_enabledLayer, NULL); + _layers.replaceObjectAtIndex(_enabledLayer, nullptr); _enabledLayer = n; - this->addChild((Node*)_layers->getObjectAtIndex(n)); + this->addChild(_layers[n]); } NS_CC_END diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index fe96a5d40a..2284e7bf46 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -412,7 +412,7 @@ public: @since v2.1 * @js NA */ - static LayerMultiplex* createWithArray(Array* arrayOfLayers); + static LayerMultiplex* createWithArray(const Vector& arrayOfLayers); /** creates a LayerMultiplex with one or more layers using a variable argument list. * @code @@ -430,27 +430,7 @@ public: * @lua NA */ static LayerMultiplex * createWithLayer(Layer* layer); - /** - * @js ctor - */ - LayerMultiplex(); - /** - * @js NA - * @lua NA - */ - virtual ~LayerMultiplex(); - virtual bool init(); - /** initializes a MultiplexLayer with one or more layers using a variable argument list. - * @js NA - * @lua NA - */ - bool initWithLayers(Layer* layer, va_list params); - - /** initializes a MultiplexLayer with an array of layers - @since v2.1 - */ - bool initWithArray(Array* arrayOfLayers); void addLayer(Layer* layer); @@ -464,8 +444,34 @@ public: void switchToAndReleaseMe(int n); protected: + + /** + * @js ctor + */ + LayerMultiplex(); + /** + * @js NA + * @lua NA + */ + virtual ~LayerMultiplex(); + + virtual bool init(); + /** initializes a MultiplexLayer with one or more layers using a variable argument list. + * @js NA + * @lua NA + */ + bool initWithLayers(Layer* layer, va_list params); + + /** initializes a MultiplexLayer with an array of layers + @since v2.1 + */ + bool initWithArray(const Vector& arrayOfLayers); + unsigned int _enabledLayer; - Array* _layers; + Vector _layers; + +private: + CC_DISALLOW_COPY_AND_ASSIGN(LayerMultiplex); }; diff --git a/cocos/2d/CCMenu.cpp b/cocos/2d/CCMenu.cpp index 4906702f35..fa44b28630 100644 --- a/cocos/2d/CCMenu.cpp +++ b/cocos/2d/CCMenu.cpp @@ -564,7 +564,7 @@ MenuItem* Menu::itemForTouch(Touch *touch) if (!_children.empty()) { - for (auto iter = _children.rcbegin(); iter != _children.rcend(); ++iter) + for (auto iter = _children.crbegin(); iter != _children.crend(); ++iter) { MenuItem* child = dynamic_cast(*iter); if (child && child->isVisible() && child->isEnabled()) diff --git a/cocos/2d/CCTMXTiledMap.cpp b/cocos/2d/CCTMXTiledMap.cpp index c21fc8666c..4980093eb7 100644 --- a/cocos/2d/CCTMXTiledMap.cpp +++ b/cocos/2d/CCTMXTiledMap.cpp @@ -42,7 +42,7 @@ TMXTiledMap * TMXTiledMap::create(const std::string& tmxFile) return ret; } CC_SAFE_DELETE(ret); - return NULL; + return nullptr; } TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std::string& resourcePath) @@ -54,7 +54,7 @@ TMXTiledMap* TMXTiledMap::createWithXML(const std::string& tmxString, const std: return ret; } CC_SAFE_DELETE(ret); - return NULL; + return nullptr; } bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile) @@ -69,7 +69,7 @@ bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile) { return false; } - CCASSERT( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename."); + CCASSERT( !mapInfo->getTilesets().empty(), "TMXTiledMap: Map not found. Please check the filename."); buildWithMapInfo(mapInfo); return true; @@ -81,7 +81,7 @@ bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& r TMXMapInfo *mapInfo = TMXMapInfo::createWithXML(tmxString, resourcePath); - CCASSERT( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename."); + CCASSERT( !mapInfo->getTilesets().empty(), "TMXTiledMap: Map not found. Please check the filename."); buildWithMapInfo(mapInfo); return true; @@ -90,15 +90,13 @@ bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& r TMXTiledMap::TMXTiledMap() :_mapSize(Size::ZERO) ,_tileSize(Size::ZERO) - ,_objectGroups(NULL) - ,_properties(NULL) - ,_tileProperties(NULL) + ,_properties(nullptr) + ,_tileProperties(nullptr) { } TMXTiledMap::~TMXTiledMap() { CC_SAFE_RELEASE(_properties); - CC_SAFE_RELEASE(_objectGroups); CC_SAFE_RELEASE(_tileProperties); } @@ -118,14 +116,13 @@ TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo) TMXTilesetInfo * TMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo) { Size size = layerInfo->_layerSize; - Array* tilesets = mapInfo->getTilesets(); - if (tilesets && tilesets->count()>0) + auto& tilesets = mapInfo->getTilesets(); + if (tilesets.count()>0) { - TMXTilesetInfo* tileset = NULL; - Object* pObj = NULL; - CCARRAY_FOREACH_REVERSE(tilesets, pObj) + TMXTilesetInfo* tileset = nullptr; + for (auto iter = tilesets.crbegin(); iter != tilesets.crend(); ++iter) { - tileset = static_cast(pObj); + tileset = *iter; if (tileset) { for( unsigned int y=0; y < size.height; y++ ) @@ -157,7 +154,7 @@ TMXTilesetInfo * TMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInf // If all the tiles are 0, return empty tileset CCLOG("cocos2d: Warning: TMX Layer '%s' has no tiles", layerInfo->_name.c_str()); - return NULL; + return nullptr; } void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo) @@ -166,9 +163,7 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo) _tileSize = mapInfo->getTileSize(); _mapOrientation = mapInfo->getOrientation(); - CC_SAFE_RELEASE(_objectGroups); _objectGroups = mapInfo->getObjectGroups(); - CC_SAFE_RETAIN(_objectGroups); CC_SAFE_RELEASE(_properties); _properties = mapInfo->getProperties(); @@ -180,30 +175,22 @@ void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo) int idx=0; - Array* layers = mapInfo->getLayers(); - if (layers && layers->count()>0) - { - TMXLayerInfo* layerInfo = NULL; - Object* pObj = NULL; - CCARRAY_FOREACH(layers, pObj) + mapInfo->getLayers().forEach([&idx, this, &mapInfo](TMXLayerInfo* layerInfo){ + if (layerInfo && layerInfo->_visible) { - layerInfo = static_cast(pObj); - if (layerInfo && layerInfo->_visible) - { - TMXLayer *child = parseLayer(layerInfo, mapInfo); - addChild((Node*)child, idx, idx); - - // update content size with the max size - const Size& childSize = child->getContentSize(); - Size currentSize = this->getContentSize(); - currentSize.width = std::max( currentSize.width, childSize.width ); - currentSize.height = std::max( currentSize.height, childSize.height ); - this->setContentSize(currentSize); - - idx++; - } + TMXLayer *child = parseLayer(layerInfo, mapInfo); + addChild((Node*)child, idx, idx); + + // update content size with the max size + const Size& childSize = child->getContentSize(); + Size currentSize = this->getContentSize(); + currentSize.width = std::max( currentSize.width, childSize.width ); + currentSize.height = std::max( currentSize.height, childSize.height ); + this->setContentSize(currentSize); + + idx++; } - } + }); } // public @@ -231,13 +218,12 @@ TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const { CCASSERT(groupName.size() > 0, "Invalid group name!"); - if (_objectGroups && _objectGroups->count()>0) + if (_objectGroups.count()>0) { - TMXObjectGroup* objectGroup = NULL; - Object* pObj = NULL; - CCARRAY_FOREACH(_objectGroups, pObj) + TMXObjectGroup* objectGroup = nullptr; + for (auto iter = _objectGroups.cbegin(); iter != _objectGroups.cend(); ++iter) { - objectGroup = static_cast(pObj); + objectGroup = *iter; if (objectGroup && objectGroup->getGroupName() == groupName) { return objectGroup; @@ -246,7 +232,7 @@ TMXObjectGroup * TMXTiledMap::getObjectGroup(const std::string& groupName) const } // objectGroup not found - return NULL; + return nullptr; } String* TMXTiledMap::getProperty(const std::string& propertyName) const diff --git a/cocos/2d/CCTMXTiledMap.h b/cocos/2d/CCTMXTiledMap.h index 7148711e56..ac3c3c964a 100644 --- a/cocos/2d/CCTMXTiledMap.h +++ b/cocos/2d/CCTMXTiledMap.h @@ -156,10 +156,9 @@ public: inline void setMapOrientation(int mapOrientation) { _mapOrientation = mapOrientation; }; /** object groups */ - inline Array* getObjectGroups() const { return _objectGroups; }; - inline void setObjectGroups(Array* groups) { - CC_SAFE_RETAIN(groups); - CC_SAFE_RELEASE(_objectGroups); + inline const Vector& getObjectGroups() const { return _objectGroups; }; + inline Vector& getObjectGroups() { return _objectGroups; }; + inline void setObjectGroups(const Vector& groups) { _objectGroups = groups; }; @@ -199,7 +198,7 @@ protected: /** map orientation */ int _mapOrientation; /** object groups */ - Array* _objectGroups; + Vector _objectGroups; /** properties */ Dictionary* _properties; diff --git a/cocos/2d/CCTMXXMLParser.cpp b/cocos/2d/CCTMXXMLParser.cpp index 06a25e3e37..1c273325dd 100644 --- a/cocos/2d/CCTMXXMLParser.cpp +++ b/cocos/2d/CCTMXXMLParser.cpp @@ -50,7 +50,7 @@ static const char* valueForKey(const char *key, std::unordered_mapretain(); - - _layers = Array::create(); - _layers->retain(); - if (tmxFileName.size() > 0) { _TMXFileName = FileUtils::getInstance()->fullPathForFilename(tmxFileName); @@ -154,8 +148,7 @@ void TMXMapInfo::internalInit(const std::string& tmxFileName, const std::string& _resources = resourcePath; } - _objectGroups = Array::createWithCapacity(4); - _objectGroups->retain(); + _objectGroups.setCapacity(4); _properties = new Dictionary(); _properties->init(); @@ -184,13 +177,10 @@ bool TMXMapInfo::initWithTMXFile(const std::string& tmxFile) TMXMapInfo::TMXMapInfo() : _mapSize(Size::ZERO) , _tileSize(Size::ZERO) -, _layers(NULL) -, _tilesets(NULL) -, _objectGroups(NULL) , _layerAttribs(0) , _storingCharacters(false) -, _properties(NULL) -, _tileProperties(NULL) +, _properties(nullptr) +, _tileProperties(nullptr) , _currentFirstGID(0) { } @@ -198,16 +188,13 @@ TMXMapInfo::TMXMapInfo() TMXMapInfo::~TMXMapInfo() { CCLOGINFO("deallocing TMXMapInfo: %p", this); - CC_SAFE_RELEASE(_tilesets); - CC_SAFE_RELEASE(_layers); CC_SAFE_RELEASE(_properties); CC_SAFE_RELEASE(_tileProperties); - CC_SAFE_RELEASE(_objectGroups); } bool TMXMapInfo::parseXMLString(const std::string& xmlString) { - int len = xmlString.size(); + size_t len = xmlString.size(); if (len <= 0) return false; @@ -325,7 +312,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) s.height = (float)atof(valueForKey("tileheight", attributeDict)); tileset->_tileSize = s; - pTMXMapInfo->getTilesets()->addObject(tileset); + pTMXMapInfo->getTilesets().addObject(tileset); tileset->release(); } } @@ -333,7 +320,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) { if (pTMXMapInfo->getParentElement() == TMXPropertyLayer) { - TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject(); + TMXLayerInfo* layer = pTMXMapInfo->getLayers().getLastObject(); Size layerSize = layer->_layerSize; unsigned int gid = (unsigned int)atoi(valueForKey("gid", attributeDict)); int tilesAmount = layerSize.width*layerSize.height; @@ -367,7 +354,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) } else { - TMXTilesetInfo* info = (TMXTilesetInfo*)pTMXMapInfo->getTilesets()->getLastObject(); + TMXTilesetInfo* info = pTMXMapInfo->getTilesets().getLastObject(); Dictionary *dict = new Dictionary(); dict->init(); pTMXMapInfo->setParentGID(info->_firstGid + atoi(valueForKey("id", attributeDict))); @@ -404,7 +391,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) float y = (float)atof(valueForKey("y", attributeDict)); layer->_offset = Point(x,y); - pTMXMapInfo->getLayers()->addObject(layer); + pTMXMapInfo->getLayers().addObject(layer); layer->release(); // The parent element is now "layer" @@ -420,7 +407,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) positionOffset.y = (float)atof(valueForKey("y", attributeDict)) * pTMXMapInfo->getTileSize().height; objectGroup->setPositionOffset(positionOffset); - pTMXMapInfo->getObjectGroups()->addObject(objectGroup); + pTMXMapInfo->getObjectGroups().addObject(objectGroup); objectGroup->release(); // The parent element is now "objectgroup" @@ -429,7 +416,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) } else if (elementName == "image") { - TMXTilesetInfo* tileset = (TMXTilesetInfo*)pTMXMapInfo->getTilesets()->getLastObject(); + TMXTilesetInfo* tileset = pTMXMapInfo->getTilesets().getLastObject(); // build full path std::string imagename = valueForKey("source", attributeDict); @@ -453,7 +440,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) { pTMXMapInfo->setLayerAttribs(pTMXMapInfo->getLayerAttribs() | TMXLayerAttribNone); - TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject(); + TMXLayerInfo* layer = pTMXMapInfo->getLayers().getLastObject(); Size layerSize = layer->_layerSize; int tilesAmount = layerSize.width*layerSize.height; @@ -499,7 +486,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) else if (elementName == "object") { char buffer[32] = {0}; - TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject(); + TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().getLastObject(); // The value for "type" was blank or not a valid class name // Create an instance of TMXObjectInfo to store the object and its properties @@ -572,7 +559,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) else if ( pTMXMapInfo->getParentElement() == TMXPropertyLayer ) { // The parent element is the last layer - TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject(); + TMXLayerInfo* layer = pTMXMapInfo->getLayers().getLastObject(); String *value = new String(valueForKey("value", attributeDict)); std::string key = valueForKey("name", attributeDict); // Add the property to the layer @@ -583,7 +570,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) else if ( pTMXMapInfo->getParentElement() == TMXPropertyObjectGroup ) { // The parent element is the last object group - TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject(); + TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().getLastObject(); String *value = new String(valueForKey("value", attributeDict)); const char* key = valueForKey("name", attributeDict); objectGroup->getProperties()->setObject(value, key); @@ -593,7 +580,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) else if ( pTMXMapInfo->getParentElement() == TMXPropertyObject ) { // The parent element is the last object - TMXObjectGroup* objectGroup = (TMXObjectGroup*)pTMXMapInfo->getObjectGroups()->getLastObject(); + TMXObjectGroup* objectGroup = pTMXMapInfo->getObjectGroups().getLastObject(); Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject(); const char* propertyName = valueForKey("name", attributeDict); @@ -614,7 +601,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) else if (elementName == "polygon") { // find parent object's dict and add polygon-points to it - TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->getLastObject(); + TMXObjectGroup* objectGroup = _objectGroups.getLastObject(); Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject(); // get points value string @@ -667,7 +654,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts) else if (elementName == "polyline") { // find parent object's dict and add polyline-points to it - TMXObjectGroup* objectGroup = (TMXObjectGroup*)_objectGroups->getLastObject(); + TMXObjectGroup* objectGroup = _objectGroups.getLastObject(); Dictionary* dict = (Dictionary*)objectGroup->getObjects()->getLastObject(); // get points value string @@ -739,7 +726,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name) { pTMXMapInfo->setStoringCharacters(false); - TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject(); + TMXLayerInfo* layer = pTMXMapInfo->getLayers().getLastObject(); std::string currentString = pTMXMapInfo->getCurrentString(); unsigned char *buffer; @@ -763,7 +750,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name) inflatedLen = (size_t)&inflatedLen; // XXX: to avoid warnings in compiler free(buffer); - buffer = NULL; + buffer = nullptr; if( ! deflated ) { @@ -782,7 +769,7 @@ void TMXMapInfo::endElement(void *ctx, const char *name) } else if (pTMXMapInfo->getLayerAttribs() & TMXLayerAttribNone) { - TMXLayerInfo* layer = (TMXLayerInfo*)pTMXMapInfo->getLayers()->getLastObject(); + TMXLayerInfo* layer = pTMXMapInfo->getLayers().getLastObject(); Size layerSize = layer->_layerSize; int tilesAmount = layerSize.width * layerSize.height; diff --git a/cocos/2d/CCTMXXMLParser.h b/cocos/2d/CCTMXXMLParser.h index 80afafd1aa..2644f8b413 100644 --- a/cocos/2d/CCTMXXMLParser.h +++ b/cocos/2d/CCTMXXMLParser.h @@ -32,12 +32,15 @@ THE SOFTWARE. #include "CCDictionary.h" #include "CCGeometry.h" #include "platform/CCSAXParser.h" +#include "CCVector.h" #include NS_CC_BEGIN +class TMXLayerInfo; class TMXObjectGroup; +class TMXTilesetInfo; /** @file * Internal TMX parser @@ -213,26 +216,23 @@ public: inline void setTileSize(const Size& tileSize) { _tileSize = tileSize; }; /// Layers - inline Array* getLayers() const { return _layers; }; - inline void setLayers(Array* layers) { - CC_SAFE_RETAIN(layers); - CC_SAFE_RELEASE(_layers); + inline const Vector& getLayers() const { return _layers; }; + inline Vector& getLayers() { return _layers; }; + inline void setLayers(const Vector& layers) { _layers = layers; }; /// tilesets - inline Array* getTilesets() const { return _tilesets; }; - inline void setTilesets(Array* tilesets) { - CC_SAFE_RETAIN(tilesets); - CC_SAFE_RELEASE(_tilesets); + inline const Vector& getTilesets() const { return _tilesets; }; + inline Vector& getTilesets() { return _tilesets; }; + inline void setTilesets(const Vector& tilesets) { _tilesets = tilesets; }; /// ObjectGroups - inline Array* getObjectGroups() const { return _objectGroups; }; - inline void setObjectGroups(Array* groups) { - CC_SAFE_RETAIN(groups); - CC_SAFE_RELEASE(_objectGroups); + inline const Vector& getObjectGroups() const { return _objectGroups; }; + inline Vector& getObjectGroups() { return _objectGroups; }; + inline void setObjectGroups(const Vector& groups) { _objectGroups = groups; }; @@ -293,11 +293,11 @@ protected: /// tiles width & height Size _tileSize; /// Layers - Array* _layers; + Vector _layers; /// tilesets - Array* _tilesets; + Vector _tilesets; /// ObjectGroups - Array* _objectGroups; + Vector _objectGroups; /// parent element int _parentElement; /// parent GID diff --git a/cocos/2d/platform/CCSAXParser.cpp b/cocos/2d/platform/CCSAXParser.cpp index 056a088826..7d40df896f 100644 --- a/cocos/2d/platform/CCSAXParser.cpp +++ b/cocos/2d/platform/CCSAXParser.cpp @@ -102,7 +102,7 @@ bool SAXParser::init(const char *pszEncoding) return true; } -bool SAXParser::parse(const char* pXMLData, unsigned int uDataLength) +bool SAXParser::parse(const char* pXMLData, size_t uDataLength) { tinyxml2::XMLDocument tinyDoc; tinyDoc.Parse(pXMLData, uDataLength); diff --git a/cocos/2d/platform/CCSAXParser.h b/cocos/2d/platform/CCSAXParser.h index 452061776a..e97b55f8de 100644 --- a/cocos/2d/platform/CCSAXParser.h +++ b/cocos/2d/platform/CCSAXParser.h @@ -81,7 +81,7 @@ public: * @js NA * @lua NA */ - bool parse(const char* pXMLData, unsigned int uDataLength); + bool parse(const char* pXMLData, size_t uDataLength); /** * @js NA * @lua NA diff --git a/cocos/base/CCVector.h b/cocos/base/CCVector.h index 6ddd3b9f97..3beb5b19e0 100644 --- a/cocos/base/CCVector.h +++ b/cocos/base/CCVector.h @@ -346,8 +346,8 @@ public: reverse_iterator rend() { return _data.rend(); } const_reverse_iterator rend() const { return _data.rend(); } - const_reverse_iterator rcbegin() const { return _data.crbegin(); } - const_reverse_iterator rcend() const { return _data.crend(); } + const_reverse_iterator crbegin() const { return _data.crbegin(); } + const_reverse_iterator crend() const { return _data.crend(); } protected: std::vector _data;