From 165cdf7fe62469c8a5305b190fe5f1b7ffda3a58 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 7 Dec 2013 10:48:02 +0800 Subject: [PATCH] issue #2790: Deprecates CCArray. --- cocos/2d/CCDeprecated.h | 2 +- cocos/2d/CCDirector.h | 4 +- cocos/2d/CCScheduler.h | 2 - cocos/base/CCArray.cpp | 170 +++++++++++++++---------------- cocos/base/CCArray.h | 33 +++--- cocos/base/CCDataVisitor.cpp | 4 +- cocos/base/CCDataVisitor.h | 6 +- cocos/base/CCDictionary.h | 16 +-- cocos/base/CCString.h | 2 +- cocos/physics/CCPhysicsBody.cpp | 22 ++-- cocos/physics/CCPhysicsBody.h | 11 +- cocos/physics/CCPhysicsWorld.cpp | 64 +++++------- cocos/physics/CCPhysicsWorld.h | 17 ++-- 13 files changed, 167 insertions(+), 186 deletions(-) diff --git a/cocos/2d/CCDeprecated.h b/cocos/2d/CCDeprecated.h index d7b60f8074..bae29435be 100644 --- a/cocos/2d/CCDeprecated.h +++ b/cocos/2d/CCDeprecated.h @@ -540,7 +540,6 @@ CC_DEPRECATED_ATTRIBUTE typedef Bool CCBool; CC_DEPRECATED_ATTRIBUTE typedef Float CCFloat; CC_DEPRECATED_ATTRIBUTE typedef Double CCDouble; CC_DEPRECATED_ATTRIBUTE typedef Data CCData; -CC_DEPRECATED_ATTRIBUTE typedef Array CCArray; CC_DEPRECATED_ATTRIBUTE typedef Dictionary CCDictionary; CC_DEPRECATED_ATTRIBUTE typedef DataVisitor CCDataVisitor; CC_DEPRECATED_ATTRIBUTE typedef PrettyPrinter CCPrettyPrinter; @@ -1030,6 +1029,7 @@ CC_DEPRECATED_ATTRIBUTE typedef __SetIterator CCSetIterator; CC_DEPRECATED_ATTRIBUTE typedef __Set Set; CC_DEPRECATED_ATTRIBUTE typedef __SetIterator SetIterator; + NS_CC_END diff --git a/cocos/2d/CCDirector.h b/cocos/2d/CCDirector.h index 9ff23333a1..78c2a96114 100644 --- a/cocos/2d/CCDirector.h +++ b/cocos/2d/CCDirector.h @@ -32,7 +32,7 @@ THE SOFTWARE. #include "CCObject.h" #include "ccTypes.h" #include "CCGeometry.h" -#include "CCArray.h" +#include "CCVector.h" #include "CCGL.h" #include "kazmath/mat4.h" #include "CCLabelAtlas.h" @@ -446,7 +446,7 @@ protected: bool _sendCleanupToScene; /* scheduled scenes */ - Array* _scenesStack; + Vector _scenesStack; /* last time the main loop was updated */ struct timeval *_lastUpdate; diff --git a/cocos/2d/CCScheduler.h b/cocos/2d/CCScheduler.h index 64325ae32f..247b773d00 100644 --- a/cocos/2d/CCScheduler.h +++ b/cocos/2d/CCScheduler.h @@ -108,8 +108,6 @@ struct _listEntry; struct _hashSelectorEntry; struct _hashUpdateEntry; -class Array; - /** @brief Scheduler is responsible for triggering the scheduled callbacks. You should not use NSTimer. Instead use this class. diff --git a/cocos/base/CCArray.cpp b/cocos/base/CCArray.cpp index adb09c237a..333183a822 100644 --- a/cocos/base/CCArray.cpp +++ b/cocos/base/CCArray.cpp @@ -36,15 +36,15 @@ NS_CC_BEGIN // std::vector implementation // ---------------------------------------------------------------------------------- -Array::Array() +__Array::Array() : data(NULL) { init(); } -Array* Array::create() +__Array* __Array::create() { - Array* array = new Array(); + __Array* array = new __Array(); if (array && array->initWithCapacity(7)) { @@ -58,9 +58,9 @@ Array* Array::create() return array; } -Array* Array::createWithObject(Object* object) +__Array* __Array::createWithObject(Object* object) { - Array* array = new Array(); + __Array* array = new __Array(); if (array && array->initWithObject(object)) { @@ -74,12 +74,12 @@ Array* Array::createWithObject(Object* object) return array; } -Array* Array::create(Object* object, ...) +__Array* __Array::create(Object* object, ...) { va_list args; va_start(args,object); - Array* array = create(); + __Array* array = create(); if (array && object) { array->addObject(object); @@ -100,16 +100,16 @@ Array* Array::create(Object* object, ...) return array; } -Array* Array::createWithArray(Array* otherArray) +__Array* __Array::createWithArray(__Array* otherArray) { return otherArray->clone(); } -Array* Array::createWithCapacity(int capacity) +__Array* __Array::createWithCapacity(int capacity) { CCASSERT(capacity>=0, "Invalid capacity"); - Array* array = new Array(); + __Array* array = new __Array(); if (array && array->initWithCapacity(capacity)) { @@ -123,9 +123,9 @@ Array* Array::createWithCapacity(int capacity) return array; } -Array* Array::createWithContentsOfFile(const char* fileName) +__Array* __Array::createWithContentsOfFile(const char* fileName) { - Array* ret = Array::createWithContentsOfFileThreadSafe(fileName); + __Array* ret = __Array::createWithContentsOfFileThreadSafe(fileName); if (ret != nullptr) { ret->autorelease(); @@ -133,17 +133,17 @@ Array* Array::createWithContentsOfFile(const char* fileName) return ret; } -Array* Array::createWithContentsOfFileThreadSafe(const char* fileName) +__Array* __Array::createWithContentsOfFileThreadSafe(const char* fileName) { return FileUtils::getInstance()->createArrayWithContentsOfFile(fileName); } -bool Array::init() +bool __Array::init() { return initWithCapacity(7); } -bool Array::initWithObject(Object* object) +bool __Array::initWithObject(Object* object) { bool ret = initWithCapacity(7); if (ret) @@ -154,7 +154,7 @@ bool Array::initWithObject(Object* object) } /** Initializes an array with some objects */ -bool Array::initWithObjects(Object* object, ...) +bool __Array::initWithObjects(Object* object, ...) { bool ret = false; do @@ -182,7 +182,7 @@ bool Array::initWithObjects(Object* object, ...) return ret; } -bool Array::initWithCapacity(int capacity) +bool __Array::initWithCapacity(int capacity) { CCASSERT(capacity>=0, "Invalid capacity"); @@ -190,13 +190,13 @@ bool Array::initWithCapacity(int capacity) return true; } -bool Array::initWithArray(Array* otherArray) +bool __Array::initWithArray(__Array* otherArray) { data = otherArray->data; return true; } -int Array::getIndexOfObject(Object* object) const +int __Array::getIndexOfObject(Object* object) const { auto it = data.begin(); @@ -211,7 +211,7 @@ int Array::getIndexOfObject(Object* object) const return -1; } -Object* Array::getRandomObject() +Object* __Array::getRandomObject() { if (data.size()==0) { @@ -230,13 +230,13 @@ Object* Array::getRandomObject() return data[r].get(); } -bool Array::containsObject(Object* object) const +bool __Array::containsObject(Object* object) const { auto i = this->getIndexOfObject(object); return (i >= 0); } -bool Array::isEqualToArray(Array* otherArray) +bool __Array::isEqualToArray(__Array* otherArray) { for (int i = 0; i < this->count(); ++i) { @@ -248,64 +248,64 @@ bool Array::isEqualToArray(Array* otherArray) return true; } -void Array::addObject(Object* object) +void __Array::addObject(Object* object) { data.push_back(RCPtr(object)); } -void Array::addObjectsFromArray(Array* otherArray) +void __Array::addObjectsFromArray(__Array* otherArray) { data.insert(data.end(), otherArray->data.begin(), otherArray->data.end()); } -void Array::insertObject(Object* object, int index) +void __Array::insertObject(Object* object, int index) { data.insert(std::begin(data) + index, RCPtr(object)); } -void Array::setObject(Object* object, int index) +void __Array::setObject(Object* object, int index) { data[index] = RCPtr(object); } -void Array::removeLastObject(bool releaseObj) +void __Array::removeLastObject(bool releaseObj) { CCASSERT(data.size(), "no objects added"); data.pop_back(); } -void Array::removeObject(Object* object, bool releaseObj /* ignored */) +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(int index, bool releaseObj /* ignored */) { auto obj = data[index]; data.erase(data.begin() + index); } -void Array::removeObjectsInArray(Array* otherArray) +void __Array::removeObjectsInArray(__Array* otherArray) { CCASSERT(false, "not implemented"); } -void Array::removeAllObjects() +void __Array::removeAllObjects() { data.erase(std::begin(data), std::end(data)); } -void Array::fastRemoveObjectAtIndex(int index) +void __Array::fastRemoveObjectAtIndex(int index) { removeObjectAtIndex(index); } -void Array::fastRemoveObject(Object* object) +void __Array::fastRemoveObject(Object* object) { removeObject(object); } -void Array::exchangeObject(Object* object1, Object* object2) +void __Array::exchangeObject(Object* object1, Object* object2) { auto idx1 = getIndexOfObject(object1); auto idx2 = getIndexOfObject(object2); @@ -315,34 +315,34 @@ void Array::exchangeObject(Object* object1, Object* object2) std::swap(data[idx1], data[idx2]); } -void Array::exchangeObjectAtIndex(int index1, int index2) +void __Array::exchangeObjectAtIndex(int index1, int index2) { std::swap(data[index1], data[index2]); } -void Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject /* ignored */) +void __Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject /* ignored */) { data[index] = object; } -void Array::reverseObjects() +void __Array::reverseObjects() { std::reverse(std::begin(data), std::end(data)); } -void Array::reduceMemoryFootprint() +void __Array::reduceMemoryFootprint() { // N/A } -Array::~Array() +__Array::~Array() { CCLOGINFO("deallocing Array: %p - len: %d", this, count() ); } -Array* Array::clone() const +__Array* __Array::clone() const { - Array* ret = new Array(); + __Array* ret = new __Array(); ret->autorelease(); ret->initWithCapacity(this->data.size() > 0 ? this->data.size() : 1); @@ -368,7 +368,7 @@ Array* Array::clone() const return ret; } -void Array::acceptVisitor(DataVisitor &visitor) +void __Array::acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } @@ -379,15 +379,15 @@ void Array::acceptVisitor(DataVisitor &visitor) #else -Array::Array() +__Array::__Array() : data(nullptr) { // init(); } -Array* Array::create() +__Array* __Array::create() { - Array* array = new Array(); + __Array* array = new __Array(); if (array && array->initWithCapacity(7)) { @@ -401,9 +401,9 @@ Array* Array::create() return array; } -Array* Array::createWithObject(Object* object) +__Array* __Array::createWithObject(Object* object) { - Array* array = new Array(); + __Array* array = new __Array(); if (array && array->initWithObject(object)) { @@ -417,12 +417,12 @@ Array* Array::createWithObject(Object* object) return array; } -Array* Array::create(Object* object, ...) +__Array* __Array::create(Object* object, ...) { va_list args; va_start(args,object); - Array* array = create(); + __Array* array = create(); if (array && object) { array->addObject(object); @@ -443,16 +443,16 @@ Array* Array::create(Object* object, ...) return array; } -Array* Array::createWithArray(Array* otherArray) +__Array* __Array::createWithArray(__Array* otherArray) { return otherArray->clone(); } -Array* Array::createWithCapacity(int capacity) +__Array* __Array::createWithCapacity(int capacity) { CCASSERT(capacity>=0, "Invalid capacity"); - Array* array = new Array(); + __Array* array = new __Array(); if (array && array->initWithCapacity(capacity)) { @@ -466,9 +466,9 @@ Array* Array::createWithCapacity(int capacity) return array; } -Array* Array::createWithContentsOfFile(const char* fileName) +__Array* __Array::createWithContentsOfFile(const char* fileName) { - Array* ret = Array::createWithContentsOfFileThreadSafe(fileName); + __Array* ret = __Array::createWithContentsOfFileThreadSafe(fileName); if (ret != nullptr) { ret->autorelease(); @@ -476,11 +476,11 @@ Array* Array::createWithContentsOfFile(const char* fileName) return ret; } -Array* Array::createWithContentsOfFileThreadSafe(const char* fileName) +__Array* __Array::createWithContentsOfFileThreadSafe(const char* fileName) { ValueVector arr = FileUtils::getInstance()->getValueVectorFromFile(fileName); - Array* ret = Array::createWithCapacity(static_cast(arr.size())); + __Array* ret = __Array::createWithCapacity(static_cast(arr.size())); std::for_each(arr.cbegin(), arr.cend(), [&ret](const Value& value){ ret->addObject(String::create(value.asString())); @@ -489,14 +489,14 @@ Array* Array::createWithContentsOfFileThreadSafe(const char* fileName) return ret; } -bool Array::init() +bool __Array::init() { CCASSERT(!data, "Array cannot be re-initialized"); return initWithCapacity(7); } -bool Array::initWithObject(Object* object) +bool __Array::initWithObject(Object* object) { CCASSERT(!data, "Array cannot be re-initialized"); @@ -509,7 +509,7 @@ bool Array::initWithObject(Object* object) } /** Initializes an array with some objects */ -bool Array::initWithObjects(Object* object, ...) +bool __Array::initWithObjects(Object* object, ...) { CCASSERT(!data, "Array cannot be re-initialized"); @@ -539,7 +539,7 @@ bool Array::initWithObjects(Object* object, ...) return ret; } -bool Array::initWithCapacity(int capacity) +bool __Array::initWithCapacity(int capacity) { CCASSERT(capacity>=0 && !data, "Array cannot be re-initialized"); @@ -547,7 +547,7 @@ bool Array::initWithCapacity(int capacity) return true; } -bool Array::initWithArray(Array* otherArray) +bool __Array::initWithArray(__Array* otherArray) { CCASSERT(!data, "Array cannot be re-initialized"); @@ -563,12 +563,12 @@ bool Array::initWithArray(Array* otherArray) return ret; } -int Array::getIndexOfObject(Object* object) const +int __Array::getIndexOfObject(Object* object) const { return ccArrayGetIndexOfObject(data, object); } -Object* Array::getRandomObject() +Object* __Array::getRandomObject() { if (data->num == 0) { @@ -585,12 +585,12 @@ Object* Array::getRandomObject() return data->arr[static_cast(data->num * r)]; } -bool Array::containsObject(Object* object) const +bool __Array::containsObject(Object* object) const { return ccArrayContainsObject(data, object); } -bool Array::isEqualToArray(Array* otherArray) +bool __Array::isEqualToArray(__Array* otherArray) { for (int i = 0; i < this->count(); ++i) { @@ -602,25 +602,25 @@ bool Array::isEqualToArray(Array* otherArray) return true; } -void Array::addObject(Object* object) +void __Array::addObject(Object* object) { CCASSERT(data, "Array not initialized"); ccArrayAppendObjectWithResize(data, object); } -void Array::addObjectsFromArray(Array* otherArray) +void __Array::addObjectsFromArray(__Array* otherArray) { CCASSERT(data, "Array not initialized"); ccArrayAppendArrayWithResize(data, otherArray->data); } -void Array::insertObject(Object* object, int index) +void __Array::insertObject(Object* object, int index) { CCASSERT(data, "Array not initialized"); ccArrayInsertObjectAtIndex(data, object, index); } -void Array::setObject(Object* object, int index) +void __Array::setObject(Object* object, int index) { CCASSERT(index >= 0 && index < count(), "Invalid index"); @@ -632,43 +632,43 @@ void Array::setObject(Object* object, int index) } } -void Array::removeLastObject(bool releaseObj) +void __Array::removeLastObject(bool releaseObj) { CCASSERT(data->num, "no objects added"); ccArrayRemoveObjectAtIndex(data, data->num - 1, releaseObj); } -void Array::removeObject(Object* object, bool releaseObj/* = true*/) +void __Array::removeObject(Object* object, bool releaseObj/* = true*/) { ccArrayRemoveObject(data, object, releaseObj); } -void Array::removeObjectAtIndex(int index, bool releaseObj) +void __Array::removeObjectAtIndex(int index, bool releaseObj) { ccArrayRemoveObjectAtIndex(data, index, releaseObj); } -void Array::removeObjectsInArray(Array* otherArray) +void __Array::removeObjectsInArray(__Array* otherArray) { ccArrayRemoveArray(data, otherArray->data); } -void Array::removeAllObjects() +void __Array::removeAllObjects() { ccArrayRemoveAllObjects(data); } -void Array::fastRemoveObjectAtIndex(int index) +void __Array::fastRemoveObjectAtIndex(int index) { ccArrayFastRemoveObjectAtIndex(data, index); } -void Array::fastRemoveObject(Object* object) +void __Array::fastRemoveObject(Object* object) { ccArrayFastRemoveObject(data, object); } -void Array::exchangeObject(Object* object1, Object* object2) +void __Array::exchangeObject(Object* object1, Object* object2) { auto index1 = ccArrayGetIndexOfObject(data, object1); if (index1 == CC_INVALID_INDEX) @@ -685,18 +685,18 @@ void Array::exchangeObject(Object* object1, Object* object2) ccArraySwapObjectsAtIndexes(data, index1, index2); } -void Array::exchangeObjectAtIndex(int index1, int index2) +void __Array::exchangeObjectAtIndex(int index1, int index2) { ccArraySwapObjectsAtIndexes(data, index1, index2); } -void Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject/* = true*/) +void __Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject/* = true*/) { ccArrayInsertObjectAtIndex(data, object, index); ccArrayRemoveObjectAtIndex(data, index + 1); } -void Array::reverseObjects() +void __Array::reverseObjects() { if (data->num > 1) { @@ -712,21 +712,21 @@ void Array::reverseObjects() } } -void Array::reduceMemoryFootprint() +void __Array::reduceMemoryFootprint() { ccArrayShrink(data); } -Array::~Array() +__Array::~__Array() { CCLOGINFO("deallocing Array: %p - len: %d", this, count() ); ccArrayFree(data); } -Array* Array::clone() const +__Array* __Array::clone() const { - Array* ret = new Array(); + __Array* ret = new __Array(); ret->autorelease(); ret->initWithCapacity(this->data->num > 0 ? this->data->num : 1); @@ -752,7 +752,7 @@ Array* Array::clone() const return ret; } -void Array::acceptVisitor(DataVisitor &visitor) +void __Array::acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } diff --git a/cocos/base/CCArray.h b/cocos/base/CCArray.h index 7f67569faa..d5df307745 100644 --- a/cocos/base/CCArray.h +++ b/cocos/base/CCArray.h @@ -230,7 +230,7 @@ while(false) NS_CC_BEGIN -class CC_DLL Array : public Object, public Clonable +class CC_DLL __Array : public Object, public Clonable { public: @@ -238,30 +238,30 @@ public: * @js NA * @lua NA */ - static Array* create(); + static __Array* create(); /** Create an array with objects * @js NA */ - static Array* create(Object* object, ...) CC_REQUIRES_NULL_TERMINATION; + static __Array* create(Object* object, ...) CC_REQUIRES_NULL_TERMINATION; /** Create an array with one object * @js NA */ - static Array* createWithObject(Object* object); + static __Array* createWithObject(Object* object); /** Create an array with a default capacity * @js NA */ - static Array* createWithCapacity(int capacity); + static __Array* createWithCapacity(int capacity); /** Create an array with from an existing array * @js NA */ - static Array* createWithArray(Array* otherArray); + static __Array* createWithArray(__Array* otherArray); /** @brief Generate a Array pointer by file @param pFileName The file name of *.plist file @return The Array pointer generated from the file * @js NA */ - static Array* createWithContentsOfFile(const char* pFileName); + static __Array* createWithContentsOfFile(const char* pFileName); /* @brief The same meaning as arrayWithContentsOfFile(), but it doesn't call autorelease, so the @@ -269,12 +269,12 @@ public: * @js NA * @lua NA */ - static Array* createWithContentsOfFileThreadSafe(const char* pFileName); + static __Array* createWithContentsOfFileThreadSafe(const char* pFileName); /** * @js NA * @lua NA */ - ~Array(); + ~__Array(); /** Initializes an array * @js NA @@ -300,7 +300,7 @@ public: * @js NA * @lua NA */ - bool initWithArray(Array* otherArray); + bool initWithArray(__Array* otherArray); // Querying an Array @@ -384,7 +384,7 @@ public: /** @since 1.1 * @js NA */ - bool isEqualToArray(Array* otherArray); + bool isEqualToArray(__Array* otherArray); // Adding Objects /** Add a certain object @@ -397,7 +397,7 @@ public: /** Add all elements of an existing array * @js NA */ - void addObjectsFromArray(Array* otherArray); + void addObjectsFromArray(__Array* otherArray); /** Insert a certain object at a certain index * @js NA */ @@ -451,7 +451,7 @@ public: /** Remove all elements * @js NA */ - void removeObjectsInArray(Array* otherArray); + void removeObjectsInArray(__Array* otherArray); /** Remove all objects * @js NA */ @@ -498,7 +498,7 @@ public: * @js NA * @lua NA */ - virtual Array* clone() const; + virtual __Array* clone() const; // ------------------------------------------ // Iterators @@ -546,12 +546,15 @@ public: * @js NA * @lua NA */ - Array(); + __Array(); }; // end of data_structure group /// @} +CC_DEPRECATED_ATTRIBUTE typedef __Array CCArray; +CC_DEPRECATED_ATTRIBUTE typedef __Array Array; + NS_CC_END #endif // __CCARRAY_H__ diff --git a/cocos/base/CCDataVisitor.cpp b/cocos/base/CCDataVisitor.cpp index a62b130cfa..5f7d95203c 100644 --- a/cocos/base/CCDataVisitor.cpp +++ b/cocos/base/CCDataVisitor.cpp @@ -60,7 +60,7 @@ void DataVisitor::visit(const String *value) visitObject(value); } -void DataVisitor::visit(const Array *value) +void DataVisitor::visit(const __Array *value) { visitObject(value); } @@ -136,7 +136,7 @@ void PrettyPrinter::visit(const String *p) _result += p->getCString(); } -void PrettyPrinter::visit(const Array *p) +void PrettyPrinter::visit(const __Array *p) { _result += "\n"; _result += _indentStr; diff --git a/cocos/base/CCDataVisitor.h b/cocos/base/CCDataVisitor.h index ba8b83726f..9abb1f1424 100644 --- a/cocos/base/CCDataVisitor.h +++ b/cocos/base/CCDataVisitor.h @@ -36,7 +36,7 @@ class Integer; class Float; class Double; class String; -class Array; +class __Array; class Dictionary; class __Set; class Data; @@ -77,7 +77,7 @@ public: virtual void visit(const Float *p); virtual void visit(const Double *p); virtual void visit(const String *p); - virtual void visit(const Array *p); + virtual void visit(const __Array *p); virtual void visit(const Dictionary *p); virtual void visit(const __Set *p); virtual void visit(const Data *p); @@ -98,7 +98,7 @@ public: virtual void visit(const Float *p); virtual void visit(const Double *p); virtual void visit(const String *p); - virtual void visit(const Array *p); + virtual void visit(const __Array *p); virtual void visit(const Dictionary *p); virtual void visit(const __Set *p); virtual void visit(const Data *p); diff --git a/cocos/base/CCDictionary.h b/cocos/base/CCDictionary.h index 63082109b3..323241a19c 100644 --- a/cocos/base/CCDictionary.h +++ b/cocos/base/CCDictionary.h @@ -207,7 +207,7 @@ public: * @return The array contains all keys of elements. It's an autorelease object yet. * @js NA */ - Array* allKeys(); + __Array* allKeys(); /** * Get all keys according to the specified object. @@ -215,7 +215,7 @@ public: * @return The array contains all keys for the specified object. It's an autorelease object yet. * @js NA */ - Array* allKeysForObject(Object* object); + __Array* allKeysForObject(Object* object); /** * Get the object according to the specified string key. @@ -302,7 +302,7 @@ public: * Remove an object by the specified string key. * * @param key The string key for searching. - * @see removeObjectForKey(intptr_t), removeObjectsForKeys(Array*), + * @see removeObjectForKey(intptr_t), removeObjectsForKeys(__Array*), * removeObjectForElememt(DictElement*), removeAllObjects(). * @js NA */ @@ -312,7 +312,7 @@ public: * Remove an object by the specified integer key. * * @param key The integer key for searching. - * @see removeObjectForKey(const std::string&), removeObjectsForKeys(Array*), + * @see removeObjectForKey(const std::string&), removeObjectsForKeys(__Array*), * removeObjectForElememt(DictElement*), removeAllObjects(). * @js NA */ @@ -321,19 +321,19 @@ public: /** * Remove objects by an array of keys. * - * @param pKeyArray The array contains keys to be removed. + * @param pKey__Array The array contains keys to be removed. * @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), * removeObjectForElememt(DictElement*), removeAllObjects(). * @js NA */ - void removeObjectsForKeys(Array* pKeyArray); + void removeObjectsForKeys(__Array* pKey__Array); /** * Remove an object by an element. * * @param pElement The element need to be removed. * @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), - * removeObjectsForKeys(Array*), removeAllObjects(). + * removeObjectsForKeys(__Array*), removeAllObjects(). * @js NA * @lua NA */ @@ -343,7 +343,7 @@ public: * Remove all objects in the dictionary. * * @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), - * removeObjectsForKeys(Array*), removeObjectForElememt(DictElement*). + * removeObjectsForKeys(__Array*), removeObjectForElememt(DictElement*). * @js NA */ void removeAllObjects(); diff --git a/cocos/base/CCString.h b/cocos/base/CCString.h index 09d558f827..19af0302e2 100644 --- a/cocos/base/CCString.h +++ b/cocos/base/CCString.h @@ -137,7 +137,7 @@ public: * @js NA * @lua NA */ - Array* componentsSeparatedByString(const char *delimiter); + __Array* componentsSeparatedByString(const char *delimiter); /* override functions * @js NA diff --git a/cocos/physics/CCPhysicsBody.cpp b/cocos/physics/CCPhysicsBody.cpp index d351444abd..7b78ee4664 100644 --- a/cocos/physics/CCPhysicsBody.cpp +++ b/cocos/physics/CCPhysicsBody.cpp @@ -51,7 +51,6 @@ namespace PhysicsBody::PhysicsBody() : _node(nullptr) -, _shapes(nullptr) , _world(nullptr) , _info(nullptr) , _dynamic(true) @@ -251,9 +250,6 @@ bool PhysicsBody::init() { _info = new PhysicsBodyInfo(); CC_BREAK_IF(_info == nullptr); - _shapes = Array::create(); - CC_BREAK_IF(_shapes == nullptr); - _shapes->retain(); _info->setBody(cpBodyNew(PhysicsHelper::float2cpfloat(_mass), PhysicsHelper::float2cpfloat(_moment))); @@ -368,7 +364,7 @@ PhysicsShape* PhysicsBody::addShape(PhysicsShape* shape, bool addMassAndMoment/* if (shape == nullptr) return nullptr; // add shape to body - if (_shapes->getIndexOfObject(shape) == CC_INVALID_INDEX) + if (_shapes.getIndex(shape) == -1) { shape->setBody(this); @@ -386,7 +382,7 @@ PhysicsShape* PhysicsBody::addShape(PhysicsShape* shape, bool addMassAndMoment/* _world->addShape(shape); } - _shapes->addObject(shape); + _shapes.pushBack(shape); if (_group != CP_NO_GROUP && shape->getGroup() == CP_NO_GROUP) { @@ -631,9 +627,8 @@ void PhysicsBody::setMoment(float moment) PhysicsShape* PhysicsBody::getShape(int tag) const { - for (auto child : *_shapes) + for (auto& shape : _shapes) { - PhysicsShape* shape = dynamic_cast(child); if (shape->getTag() == tag) { return shape; @@ -645,9 +640,8 @@ PhysicsShape* PhysicsBody::getShape(int tag) const void PhysicsBody::removeShape(int tag, bool reduceMassAndMoment/* = true*/) { - for (auto child : *_shapes) + for (auto& shape : _shapes) { - PhysicsShape* shape = dynamic_cast(child); if (shape->getTag() == tag) { removeShape(shape, reduceMassAndMoment); @@ -658,7 +652,7 @@ void PhysicsBody::removeShape(int tag, bool reduceMassAndMoment/* = true*/) void PhysicsBody::removeShape(PhysicsShape* shape, bool reduceMassAndMoment/* = true*/) { - if (_shapes->getIndexOfObject(shape) != CC_INVALID_INDEX) + if (_shapes->getIndexOfObject(shape) != -1) { // deduce the area, mass and moment // area must update before mass, because the density changes depend on it. @@ -678,13 +672,13 @@ 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->removeObject(shape); + _shapes.removeObject(shape); } } void PhysicsBody::removeAllShapes(bool reduceMassAndMoment/* = true*/) { - for (auto child : *_shapes) + for (auto& child : _shapes) { PhysicsShape* shape = dynamic_cast(child); @@ -707,7 +701,7 @@ void PhysicsBody::removeAllShapes(bool reduceMassAndMoment/* = true*/) shape->setBody(nullptr); } - _shapes->removeAllObjects(); + _shapes.clear(); } void PhysicsBody::removeFromWorld() diff --git a/cocos/physics/CCPhysicsBody.h b/cocos/physics/CCPhysicsBody.h index bc72aff57b..58145b75d2 100644 --- a/cocos/physics/CCPhysicsBody.h +++ b/cocos/physics/CCPhysicsBody.h @@ -30,11 +30,8 @@ #include "CCObject.h" #include "CCGeometry.h" -#include "CCArray.h" - #include "CCPhysicsShape.h" - -#include +#include "CCVector.h" NS_CC_BEGIN class Sprite; @@ -103,9 +100,9 @@ public: /* remove all shapes */ void removeAllShapes(bool reduceMassAndMoment = true); /* get the body shapes. */ - inline Array* getShapes() const { return _shapes; } + inline const Vector getShapes() const { return _shapes; } /* get the first shape of the body shapes. */ - inline PhysicsShape* getFirstShape() const { return _shapes->count() >= 1 ? dynamic_cast(_shapes->getObjectAtIndex(0)) : nullptr; } + inline PhysicsShape* getFirstShape() const { return _shapes.size() >= 1 ? _shapes.at(0) : nullptr; } /* get the shape of the body. */ PhysicsShape* getShape(int tag) const; @@ -305,7 +302,7 @@ protected: protected: Node* _node; std::vector _joints; - Array* _shapes; + Vector _shapes; PhysicsWorld* _world; PhysicsBodyInfo* _info; bool _dynamic; diff --git a/cocos/physics/CCPhysicsWorld.cpp b/cocos/physics/CCPhysicsWorld.cpp index 41d6f08f9c..96a42c7797 100644 --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -97,7 +97,7 @@ public: static void rayCastCallbackFunc(cpShape *shape, cpFloat t, cpVect n, RayCastCallbackInfo *info); static void queryRectCallbackFunc(cpShape *shape, RectQueryCallbackInfo *info); static void queryPointFunc(cpShape *shape, cpFloat distance, cpVect point, PointQueryCallbackInfo *info); - static void getShapesAtPointFunc(cpShape *shape, cpFloat distance, cpVect point, Array *arr); + static void getShapesAtPointFunc(cpShape *shape, cpFloat distance, cpVect point, Vector* arr); public: static bool continues; @@ -176,13 +176,13 @@ void PhysicsWorldCallback::queryRectCallbackFunc(cpShape *shape, RectQueryCallba PhysicsWorldCallback::continues = info->func(*info->world, *it->second->getShape(), info->data); } -void PhysicsWorldCallback::getShapesAtPointFunc(cpShape *shape, cpFloat distance, cpVect point, Array *arr) +void PhysicsWorldCallback::getShapesAtPointFunc(cpShape *shape, cpFloat distance, cpVect point, Vector* arr) { auto it = PhysicsShapeInfo::getMap().find(shape); CC_ASSERT(it != PhysicsShapeInfo::getMap().end()); - arr->addObject(it->second->getShape()); + arr->pushBack(it->second->getShape()); } void PhysicsWorldCallback::queryPointFunc(cpShape *shape, cpFloat distance, cpVect point, PointQueryCallbackInfo *info) @@ -201,17 +201,17 @@ void PhysicsWorld::debugDraw() _debugDraw = new PhysicsDebugDraw(*this); } - if (_debugDraw && _bodies != nullptr) + if (_debugDraw && !_bodies.empty()) { if (_debugDraw->begin()) { if (_debugDrawMask & DEBUGDRAW_SHAPE) { - for (Object* obj : *_bodies) + for (Object* obj : _bodies) { PhysicsBody* body = dynamic_cast(obj); - for (auto shape : *body->getShapes()) + for (auto& shape : body->getShapes()) { _debugDraw->drawShape(*dynamic_cast(shape)); } @@ -392,16 +392,16 @@ void PhysicsWorld::queryPoint(PhysicsPointQueryCallbackFunc func, const Point& p } } -Array* PhysicsWorld::getShapes(const Point& point) const +Vector PhysicsWorld::getShapes(const Point& point) const { - Array* arr = Array::create(); + Vector arr; cpSpaceNearestPointQuery(this->_info->getSpace(), PhysicsHelper::point2cpv(point), 0, CP_ALL_LAYERS, CP_NO_GROUP, (cpSpaceNearestPointQueryFunc)PhysicsWorldCallback::getShapesAtPointFunc, - arr); + &arr); return arr; } @@ -562,17 +562,8 @@ bool PhysicsWorld::init(Scene& scene) { do { - _delayAddBodies = Array::create(); - _delayRemoveBodies = Array::create(); - CC_BREAK_IF(_delayAddBodies == nullptr || _delayRemoveBodies == nullptr); - _delayAddBodies->retain(); - _delayRemoveBodies->retain(); - _info = new PhysicsWorldInfo(); CC_BREAK_IF(_info == nullptr); - _bodies = Array::create(); - CC_BREAK_IF(_bodies == nullptr); - _bodies->retain(); _scene = &scene; @@ -606,7 +597,7 @@ void PhysicsWorld::addBody(PhysicsBody* body) } addBodyOrDelay(body); - _bodies->addObject(body); + _bodies.pushBack(body); body->_world = this; } @@ -627,7 +618,7 @@ void PhysicsWorld::doAddBody(PhysicsBody* body) } // add shapes to space - for (auto shape : *body->getShapes()) + for (auto& shape : body->getShapes()) { addShape(dynamic_cast(shape)); } @@ -637,17 +628,17 @@ void PhysicsWorld::doAddBody(PhysicsBody* body) void PhysicsWorld::addBodyOrDelay(PhysicsBody* body) { - if (_delayRemoveBodies->getIndexOfObject(body) != CC_INVALID_INDEX) + if (_delayRemoveBodies.getIndex(body) != CC_INVALID_INDEX) { - _delayRemoveBodies->removeObject(body); + _delayRemoveBodies.removeObject(body); return; } if (_info->isLocked()) { - if (_delayAddBodies->getIndexOfObject(body) == CC_INVALID_INDEX) + if (_delayAddBodies.getIndex(body) == CC_INVALID_INDEX) { - _delayAddBodies->addObject(body); + _delayAddBodies.pushBack(body); _delayDirty = true; } }else @@ -663,25 +654,24 @@ void PhysicsWorld::updateBodies() return; } - for (auto body : *_delayAddBodies) + for (auto& body : _delayAddBodies) { - doAddBody(dynamic_cast(body)); + doAddBody(body); } - for (auto body : *_delayRemoveBodies) + for (auto& body : _delayRemoveBodies) { - doRemoveBody(dynamic_cast(body)); + doRemoveBody(body); } - _delayAddBodies->removeAllObjects(); - _delayRemoveBodies->removeAllObjects(); + _delayAddBodies.clear(); + _delayRemoveBodies.clear(); } void PhysicsWorld::removeBody(int tag) { - for (Object* obj : *_bodies) + for (auto& body : _bodies) { - PhysicsBody* body = dynamic_cast(obj); if (body->getTag() == tag) { removeBody(body); @@ -722,24 +712,24 @@ void PhysicsWorld::removeBody(PhysicsBody* body) body->_joints.clear(); removeBodyOrDelay(body); - _bodies->removeObject(body); + _bodies.removeObject(body); body->_world = nullptr; } void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body) { - if (_delayAddBodies->getIndexOfObject(body) != CC_INVALID_INDEX) + if (_delayAddBodies.getIndex(body) != CC_INVALID_INDEX) { - _delayAddBodies->removeObject(body); + _delayAddBodies.removeObject(body); return; } if (_info->isLocked()) { - if (_delayRemoveBodies->getIndexOfObject(body) == CC_INVALID_INDEX) + if (_delayRemoveBodies.getIndex(body) == CC_INVALID_INDEX) { - _delayRemoveBodies->addObject(body); + _delayRemoveBodies.pushBack(body); _delayDirty = true; } }else diff --git a/cocos/physics/CCPhysicsWorld.h b/cocos/physics/CCPhysicsWorld.h index 05999d990d..dfd85e5744 100644 --- a/cocos/physics/CCPhysicsWorld.h +++ b/cocos/physics/CCPhysicsWorld.h @@ -28,12 +28,12 @@ #include "ccConfig.h" #ifdef CC_USE_PHYSICS -#include -#include - +#include "CCVector.h" #include "CCObject.h" #include "CCGeometry.h" +#include + NS_CC_BEGIN class PhysicsBody; @@ -41,7 +41,6 @@ class PhysicsJoint; class PhysicsWorldInfo; class PhysicsShape; class PhysicsContact; -class Array; typedef Point Vect; @@ -104,9 +103,9 @@ public: void rayCast(PhysicsRayCastCallbackFunc func, const Point& point1, const Point& point2, void* data); void queryRect(PhysicsRectQueryCallbackFunc func, const Rect& rect, void* data); void queryPoint(PhysicsPointQueryCallbackFunc func, const Point& point, void* data); - Array* getShapes(const Point& point) const; + Vector getShapes(const Point& point) const; PhysicsShape* getShape(const Point& point) const; - Array* getAllBodies() const; + const Vector& getAllBodies() const; PhysicsBody* getBody(int tag) const; /** Register a listener to receive contact callbacks*/ @@ -156,7 +155,7 @@ protected: float _speed; PhysicsWorldInfo* _info; - Array* _bodies; + Vector _bodies; std::list _joints; Scene* _scene; @@ -165,8 +164,8 @@ protected: int _debugDrawMask; - Array* _delayAddBodies; - Array* _delayRemoveBodies; + Vector _delayAddBodies; + Vector _delayRemoveBodies; std::vector _delayAddJoints; std::vector _delayRemoveJoints;